diff options
| author | Louis Scalbert <louis.scalbert@6wind.com> | 2024-02-14 17:32:06 +0100 | 
|---|---|---|
| committer | Louis Scalbert <louis.scalbert@6wind.com> | 2024-06-05 11:08:46 +0200 | 
| commit | 7a513e3361eb879a6a0ea64939c68cd949e8fd76 (patch) | |
| tree | 454152de06ff9a2677989d2be72f78e4fad739f5 /bgpd/bgp_route.c | |
| parent | 747da057e814258533ea149da804adfdb4219f27 (diff) | |
bgpd: add bgp_path_info_has_valid_label()
Add bgp_path_has_valid_label to check that a path_info has a valid
label.
Signed-off-by: Louis Scalbert <louis.scalbert@6wind.com>
Diffstat (limited to 'bgpd/bgp_route.c')
| -rw-r--r-- | bgpd/bgp_route.c | 26 | 
1 files changed, 16 insertions, 10 deletions
diff --git a/bgpd/bgp_route.c b/bgpd/bgp_route.c index af440fce47..3db883fc08 100644 --- a/bgpd/bgp_route.c +++ b/bgpd/bgp_route.c @@ -324,6 +324,16 @@ struct bgp_path_info_extra *bgp_path_info_extra_get(struct bgp_path_info *pi)  	return pi->extra;  } +bool bgp_path_info_has_valid_label(const struct bgp_path_info *path) +{ +	if (!path->extra) +		return false; +	if (!path->extra->num_labels) +		return false; + +	return bgp_is_valid_label(&path->extra->label[0]); +} +  /* Free bgp route information. */  void bgp_path_info_free_with_caller(const char *name,  				    struct bgp_path_info *path) @@ -1361,10 +1371,8 @@ int bgp_path_info_cmp(struct bgp *bgp, struct bgp_path_info *new,  		 */  		bool new_label_valid, exist_label_valid; -		new_label_valid = new->extra && new->extra->num_labels && -				    bgp_is_valid_label(&new->extra->label[0]); -		exist_label_valid = exist->extra && exist->extra->num_labels && -				    bgp_is_valid_label(&exist->extra->label[0]); +		new_label_valid = bgp_path_info_has_valid_label(new); +		exist_label_valid = bgp_path_info_has_valid_label(exist);  		if (new_label_valid != exist_label_valid) {  			if (debug) @@ -3450,8 +3458,7 @@ static bool bgp_lu_need_null_label(struct bgp *bgp,  	    || new_select->sub_type == BGP_ROUTE_AGGREGATE  	    || new_select->sub_type == BGP_ROUTE_REDISTRIBUTE)  		goto need_null_label; -	else if (new_select->extra && new_select->extra->num_labels && -		 bgp_is_valid_label(&new_select->extra->label[0])) +	else if (bgp_path_info_has_valid_label(new_select))  		return false;  need_null_label:  	if (label == NULL) @@ -10064,8 +10071,7 @@ void route_vty_out_tag(struct vty *vty, const struct prefix *p,  		}  	} -	if (path->extra->num_labels && -	    bgp_is_valid_label(&path->extra->label[0])) { +	if (bgp_path_info_has_valid_label(path)) {  		label = decode_label(&path->extra->label[0]);  		if (json) {  			json_object_int_add(json_out, "notag", label); @@ -11270,8 +11276,8 @@ void route_vty_out_detail(struct vty *vty, struct bgp *bgp, struct bgp_dest *bn,  		bgp_damp_info_vty(vty, bgp, path, afi, safi, json_path);  	/* Remote Label */ -	if (path->extra && bgp_is_valid_label(&path->extra->label[0]) -	    && (safi != SAFI_EVPN && !is_route_parent_evpn(path))) { +	if (bgp_path_info_has_valid_label(path) && +	    (safi != SAFI_EVPN && !is_route_parent_evpn(path))) {  		mpls_lse_decode(path->extra->label[0], &label, &ttl, &exp,  				&bos);  | 
