Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bgpd: fix labels static-analyser (backport #16655) #16670

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions bgpd/bgp_bmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1221,7 +1221,7 @@ static bool bmp_wrsync(struct bmp *bmp, struct pullwr *pullwr)
(safi == SAFI_MPLS_VPN))
prd = (struct prefix_rd *)bgp_dest_get_prefix(bmp->syncrdpos);

bpi_num_labels = bgp_path_info_num_labels(bpi);
bpi_num_labels = BGP_PATH_INFO_NUM_LABELS(bpi);

if (bpi && CHECK_FLAG(bpi->flags, BGP_PATH_SELECTED) &&
CHECK_FLAG(bmp->targets->afimon[afi][safi], BMP_MON_LOC_RIB)) {
Expand Down Expand Up @@ -1356,7 +1356,7 @@ static bool bmp_wrqueue_locrib(struct bmp *bmp, struct pullwr *pullwr)
break;
}

bpi_num_labels = bgp_path_info_num_labels(bpi);
bpi_num_labels = BGP_PATH_INFO_NUM_LABELS(bpi);

bmp_monitor(bmp, peer, 0, BMP_PEER_TYPE_LOC_RIB_INSTANCE, &bqe->p, prd,
bpi ? bpi->attr : NULL, afi, safi,
Expand Down Expand Up @@ -1434,7 +1434,7 @@ static bool bmp_wrqueue(struct bmp *bmp, struct pullwr *pullwr)
break;
}

bpi_num_labels = bgp_path_info_num_labels(bpi);
bpi_num_labels = BGP_PATH_INFO_NUM_LABELS(bpi);

bmp_monitor(bmp, peer, BMP_PEER_FLAG_L,
BMP_PEER_TYPE_GLOBAL_INSTANCE, &bqe->p, prd,
Expand Down
2 changes: 1 addition & 1 deletion bgpd/bgp_evpn.c
Original file line number Diff line number Diff line change
Expand Up @@ -3002,7 +3002,7 @@ bgp_create_evpn_bgp_path_info(struct bgp_path_info *parent_pi,
if (parent_pi->extra)
pi->extra->igpmetric = parent_pi->extra->igpmetric;

if (bgp_path_info_num_labels(parent_pi))
if (BGP_PATH_INFO_NUM_LABELS(parent_pi))
pi->extra->labels = bgp_labels_intern(parent_pi->extra->labels);

bgp_path_info_add(dest, pi);
Expand Down
2 changes: 1 addition & 1 deletion bgpd/bgp_label.c
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ mpls_label_t bgp_adv_label(struct bgp_dest *dest, struct bgp_path_info *pi,
if (!dest || !pi || !to)
return MPLS_INVALID_LABEL;

remote_label = bgp_path_info_num_labels(pi)
remote_label = BGP_PATH_INFO_NUM_LABELS(pi)
? pi->extra->labels->label[0]
: MPLS_INVALID_LABEL;
from = pi->peer;
Expand Down
2 changes: 1 addition & 1 deletion bgpd/bgp_mac.c
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ static void bgp_process_mac_rescan_table(struct bgp *bgp, struct peer *peer,
&& !dest_affected)
continue;

num_labels = bgp_path_info_num_labels(pi);
num_labels = BGP_PATH_INFO_NUM_LABELS(pi);
label_pnt = num_labels ? &pi->extra->labels->label[0]
: NULL;

Expand Down
4 changes: 2 additions & 2 deletions bgpd/bgp_mplsvpn.c
Original file line number Diff line number Diff line change
Expand Up @@ -2318,7 +2318,7 @@ static void vpn_leak_to_vrf_update_onevrf(struct bgp *to_bgp, /* to */
}

num_labels = origin_local ? 0
: bgp_path_info_num_labels(path_vpn);
: BGP_PATH_INFO_NUM_LABELS(path_vpn);
label_pnt = num_labels ? path_vpn->extra->labels->label : NULL;
}

Expand Down Expand Up @@ -4208,7 +4208,7 @@ void bgp_mplsvpn_nh_label_bind_register_local_label(struct bgp *bgp,
struct bgp_mplsvpn_nh_label_bind_cache_head *tree;
mpls_label_t label;

label = bgp_path_info_num_labels(pi)
label = BGP_PATH_INFO_NUM_LABELS(pi)
? decode_label(&pi->extra->labels->label[0])
: MPLS_INVALID_LABEL;

Expand Down
7 changes: 6 additions & 1 deletion bgpd/bgp_nht.c
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ int bgp_find_or_add_nexthop(struct bgp *bgp_route, struct bgp *bgp_nexthop,
return 1;
else if (safi == SAFI_UNICAST && pi &&
pi->sub_type == BGP_ROUTE_IMPORTED &&
bgp_path_info_num_labels(pi) && !bnc->is_evpn_gwip_nexthop)
BGP_PATH_INFO_NUM_LABELS(pi) && !bnc->is_evpn_gwip_nexthop)
return bgp_isvalid_nexthop_for_l3vpn(bnc, pi);
else if (safi == SAFI_MPLS_VPN && pi &&
pi->sub_type != BGP_ROUTE_IMPORTED)
Expand Down Expand Up @@ -1303,8 +1303,13 @@ void evaluate_paths(struct bgp_nexthop_cache *bnc)

if (safi == SAFI_UNICAST &&
path->sub_type == BGP_ROUTE_IMPORTED &&
<<<<<<< HEAD
bgp_path_info_num_labels(path) &&
(path->attr->evpn_overlay.type != OVERLAY_INDEX_GATEWAY_IP)) {
=======
BGP_PATH_INFO_NUM_LABELS(path) &&
!(bre && bre->type == OVERLAY_INDEX_GATEWAY_IP)) {
>>>>>>> a152692f5a (bgpd: fix labels static-analyser)
bnc_is_valid_nexthop =
bgp_isvalid_nexthop_for_l3vpn(bnc, path)
? true
Expand Down
24 changes: 5 additions & 19 deletions bgpd/bgp_route.c
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ struct bgp_path_info_extra *bgp_path_info_extra_get(struct bgp_path_info *pi)

bool bgp_path_info_has_valid_label(const struct bgp_path_info *path)
{
if (!bgp_path_info_num_labels(path))
if (!BGP_PATH_INFO_NUM_LABELS(path))
return false;

return bgp_is_valid_label(&path->extra->labels->label[0]);
Expand All @@ -339,27 +339,13 @@ bool bgp_path_info_labels_same(const struct bgp_path_info *bpi,
uint8_t bpi_num_labels;
const mpls_label_t *bpi_label;

bpi_num_labels = bgp_path_info_num_labels(bpi);
bpi_num_labels = BGP_PATH_INFO_NUM_LABELS(bpi);
bpi_label = bpi_num_labels ? bpi->extra->labels->label : NULL;

return bgp_labels_same(bpi_label, bpi_num_labels,
(const mpls_label_t *)label, n);
}

uint8_t bgp_path_info_num_labels(const struct bgp_path_info *pi)
{
if (!pi)
return 0;

if (!pi->extra)
return 0;

if (!pi->extra->labels)
return 0;

return pi->extra->labels->num_labels;
}

/* Free bgp route information. */
void bgp_path_info_free_with_caller(const char *name,
struct bgp_path_info *path)
Expand Down Expand Up @@ -2249,7 +2235,7 @@ bool subgroup_announce_check(struct bgp_dest *dest, struct bgp_path_info *pi,
* off box as that the RT and RD created are localy
* significant and globaly useless.
*/
if (safi == SAFI_MPLS_VPN && bgp_path_info_num_labels(pi) &&
if (safi == SAFI_MPLS_VPN && BGP_PATH_INFO_NUM_LABELS(pi) &&
pi->extra->labels->label[0] == BGP_PREVENT_VRF_2_VRF_LEAK)
return false;

Expand Down Expand Up @@ -6842,7 +6828,7 @@ void bgp_static_update(struct bgp *bgp, const struct prefix *p,
bgp, p, pi);
}
} else {
if (bgp_path_info_num_labels(pi))
if (BGP_PATH_INFO_NUM_LABELS(pi))
label = decode_label(
&pi->extra->labels->label[0]);
}
Expand Down Expand Up @@ -10514,7 +10500,7 @@ void route_vty_out_detail(struct vty *vty, struct bgp *bgp, struct bgp_dest *bn,
json_nexthop_global = json_object_new_object();
}

if (bgp_path_info_num_labels(path)) {
if (BGP_PATH_INFO_NUM_LABELS(path)) {
bgp_evpn_label2str(path->extra->labels->label,
path->extra->labels->num_labels, vni_buf,
sizeof(vni_buf));
Expand Down
6 changes: 5 additions & 1 deletion bgpd/bgp_route.h
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,11 @@ struct bgp_aggregate {
/* path PREFIX (addpath rxid NUMBER) */
#define PATH_ADDPATH_STR_BUFFER PREFIX2STR_BUFFER + 32

#define BGP_PATH_INFO_NUM_LABELS(pi) \
((pi) && (pi)->extra && (pi)->extra->labels \
? (pi)->extra->labels->num_labels \
: 0)

enum bgp_path_type {
BGP_PATH_SHOW_ALL,
BGP_PATH_SHOW_BESTPATH,
Expand Down Expand Up @@ -748,7 +753,6 @@ extern void bgp_path_info_delete(struct bgp_dest *dest,
extern struct bgp_path_info_extra *
bgp_path_info_extra_get(struct bgp_path_info *path);
extern bool bgp_path_info_has_valid_label(const struct bgp_path_info *path);
extern uint8_t bgp_path_info_num_labels(const struct bgp_path_info *pi);
extern void bgp_path_info_set_flag(struct bgp_dest *dest,
struct bgp_path_info *path, uint32_t flag);
extern void bgp_path_info_unset_flag(struct bgp_dest *dest,
Expand Down
2 changes: 1 addition & 1 deletion bgpd/bgp_routemap.c
Original file line number Diff line number Diff line change
Expand Up @@ -1082,7 +1082,7 @@ route_match_vni(void *rule, const struct prefix *prefix, void *object)
return RMAP_NOOP;

for (label_cnt = 0; label_cnt < BGP_MAX_LABELS &&
label_cnt < bgp_path_info_num_labels(path);
label_cnt < BGP_PATH_INFO_NUM_LABELS(path);
label_cnt++) {
if (vni == label2vni(&path->extra->labels->label[label_cnt]))
return RMAP_MATCH;
Expand Down
2 changes: 1 addition & 1 deletion bgpd/bgp_rpki.c
Original file line number Diff line number Diff line change
Expand Up @@ -666,7 +666,7 @@ static void revalidate_bgp_node(struct bgp_dest *bgp_dest, afi_t afi,
struct bgp_path_info *path =
bgp_dest_get_bgp_path_info(bgp_dest);

num_labels = bgp_path_info_num_labels(path);
num_labels = BGP_PATH_INFO_NUM_LABELS(path);
label = num_labels ? path->extra->labels->label : NULL;

(void)bgp_update(ain->peer, bgp_dest_get_prefix(bgp_dest),
Expand Down
2 changes: 1 addition & 1 deletion bgpd/bgp_updgrp_packet.c
Original file line number Diff line number Diff line change
Expand Up @@ -815,7 +815,7 @@ struct bpacket *subgroup_update_packet(struct update_subgroup *subgrp)
label_pnt = &label;
num_labels = 1;
} else {
num_labels = bgp_path_info_num_labels(path);
num_labels = BGP_PATH_INFO_NUM_LABELS(path);
label_pnt =
num_labels
? &path->extra->labels->label[0]
Expand Down
4 changes: 2 additions & 2 deletions bgpd/bgp_zebra.c
Original file line number Diff line number Diff line change
Expand Up @@ -1336,7 +1336,7 @@ static void bgp_zebra_announce_parse_nexthop(
api_nh->srte_color = bgp_attr_get_color(info->attr);

if (bgp_debug_zebra(&api->prefix)) {
if (bgp_path_info_num_labels(mpinfo)) {
if (BGP_PATH_INFO_NUM_LABELS(mpinfo)) {
zlog_debug("%s: p=%pFX, bgp_is_valid_label: %d",
__func__, p,
bgp_is_valid_label(
Expand Down Expand Up @@ -1409,7 +1409,7 @@ static void bgp_zebra_announce_parse_nexthop(
mpinfo->peer->sort == BGP_PEER_CONFED))
*allow_recursion = true;

num_labels = bgp_path_info_num_labels(mpinfo);
num_labels = BGP_PATH_INFO_NUM_LABELS(mpinfo);
labels = num_labels ? mpinfo->extra->labels->label : NULL;

if (num_labels && (is_evpn || bgp_is_valid_label(&labels[0]))) {
Expand Down
4 changes: 2 additions & 2 deletions bgpd/rfapi/rfapi_import.c
Original file line number Diff line number Diff line change
Expand Up @@ -1272,7 +1272,7 @@ rfapiRouteInfo2NextHopEntry(struct rfapi_ip_prefix *rprefix,

/* label comes from MP_REACH_NLRI label */
vo->v.l2addr.label =
bgp_path_info_num_labels(bpi)
BGP_PATH_INFO_NUM_LABELS(bpi)
? decode_label(&bpi->extra->labels->label[0])
: MPLS_INVALID_LABEL;

Expand Down Expand Up @@ -4167,7 +4167,7 @@ static void rfapiBgpTableFilteredImport(struct bgp *bgp,
BGP_PATH_REMOVED))
continue;

if (bgp_path_info_num_labels(bpi))
if (BGP_PATH_INFO_NUM_LABELS(bpi))
label = decode_label(
&bpi->extra->labels
->label[0]);
Expand Down
2 changes: 1 addition & 1 deletion bgpd/rfapi/rfapi_rib.c
Original file line number Diff line number Diff line change
Expand Up @@ -692,7 +692,7 @@ static void rfapiRibBi2Ri(struct bgp_path_info *bpi, struct rfapi_info *ri,

/* label comes from MP_REACH_NLRI label */
vo->v.l2addr.label =
bgp_path_info_num_labels(bpi)
BGP_PATH_INFO_NUM_LABELS(bpi)
? decode_label(&bpi->extra->labels->label[0])
: MPLS_INVALID_LABEL;

Expand Down
6 changes: 3 additions & 3 deletions bgpd/rfapi/rfapi_vty.c
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ void rfapi_vty_out_vncinfo(struct vty *vty, const struct prefix *p,
XFREE(MTYPE_ECOMMUNITY_STR, s);
}

if (bgp_path_info_num_labels(bpi)) {
if (BGP_PATH_INFO_NUM_LABELS(bpi)) {
if (bpi->extra->labels->label[0] == BGP_PREVENT_VRF_2_VRF_LEAK)
vty_out(vty, " label=VRF2VRF");
else
Expand Down Expand Up @@ -1052,7 +1052,7 @@ static int rfapiPrintRemoteRegBi(struct bgp *bgp, void *stream,
snprintf(buf_un, sizeof(buf_un), "%s",
inet_ntop(pfx_vn.family, &pfx_vn.u.prefix, buf_ntop,
sizeof(buf_ntop)));
if (bgp_path_info_num_labels(bpi)) {
if (BGP_PATH_INFO_NUM_LABELS(bpi)) {
uint32_t l = decode_label(&bpi->extra->labels->label[0]);
snprintf(buf_vn, sizeof(buf_vn), "Label: %d", l);
} else /* should never happen */
Expand Down Expand Up @@ -1161,7 +1161,7 @@ static int rfapiPrintRemoteRegBi(struct bgp *bgp, void *stream,
}
}
}
if (tun_type != BGP_ENCAP_TYPE_MPLS && bgp_path_info_num_labels(bpi)) {
if (tun_type != BGP_ENCAP_TYPE_MPLS && BGP_PATH_INFO_NUM_LABELS(bpi)) {
uint32_t l = decode_label(&bpi->extra->labels->label[0]);

if (!MPLS_LABEL_IS_NULL(l)) {
Expand Down
18 changes: 9 additions & 9 deletions bgpd/rfapi/vnc_import_bgp.c
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ static void vnc_import_bgp_add_route_mode_resolve_nve_one_bi(
if (bgp_attr_get_ecommunity(bpi->attr))
ecommunity_merge(new_ecom, bgp_attr_get_ecommunity(bpi->attr));

if (bgp_path_info_num_labels(bpi))
if (BGP_PATH_INFO_NUM_LABELS(bpi))
label = decode_label(&bpi->extra->labels->label[0]);
else
label = MPLS_INVALID_LABEL;
Expand Down Expand Up @@ -1704,7 +1704,7 @@ static void vnc_import_bgp_exterior_add_route_it(
else
prd = NULL;

if (bgp_path_info_num_labels(bpi_interior))
if (BGP_PATH_INFO_NUM_LABELS(bpi_interior))
label = decode_label(
&bpi_interior->extra->labels
->label[0]);
Expand Down Expand Up @@ -1878,7 +1878,7 @@ void vnc_import_bgp_exterior_del_route(
else
prd = NULL;

if (bgp_path_info_num_labels(bpi_interior))
if (BGP_PATH_INFO_NUM_LABELS(bpi_interior))
label = decode_label(
&bpi_interior->extra->labels
->label[0]);
Expand Down Expand Up @@ -2030,7 +2030,7 @@ void vnc_import_bgp_exterior_add_route_interior(
else
prd = NULL;

if (bgp_path_info_num_labels(bpi_interior))
if (BGP_PATH_INFO_NUM_LABELS(bpi_interior))
label = decode_label(
&bpi_interior->extra->labels->label[0]);
else
Expand Down Expand Up @@ -2147,7 +2147,7 @@ void vnc_import_bgp_exterior_add_route_interior(
else
prd = NULL;

if (bgp_path_info_num_labels(bpi))
if (BGP_PATH_INFO_NUM_LABELS(bpi))
label = decode_label(
&bpi->extra->labels
->label[0]);
Expand All @@ -2174,7 +2174,7 @@ void vnc_import_bgp_exterior_add_route_interior(
else
prd = NULL;

if (bgp_path_info_num_labels(bpi_interior))
if (BGP_PATH_INFO_NUM_LABELS(bpi_interior))
label = decode_label(
&bpi_interior->extra->labels
->label[0]);
Expand Down Expand Up @@ -2297,7 +2297,7 @@ void vnc_import_bgp_exterior_add_route_interior(
else
prd = NULL;

if (bgp_path_info_num_labels(bpi_interior))
if (BGP_PATH_INFO_NUM_LABELS(bpi_interior))
label = decode_label(
&bpi_interior->extra->labels->label[0]);
else
Expand Down Expand Up @@ -2409,7 +2409,7 @@ void vnc_import_bgp_exterior_del_route_interior(
else
prd = NULL;

if (bgp_path_info_num_labels(bpi_interior))
if (BGP_PATH_INFO_NUM_LABELS(bpi_interior))
label = decode_label(
&bpi_interior->extra->labels->label[0]);
else
Expand Down Expand Up @@ -2491,7 +2491,7 @@ void vnc_import_bgp_exterior_del_route_interior(
else
prd = NULL;

if (bgp_path_info_num_labels(bpi))
if (BGP_PATH_INFO_NUM_LABELS(bpi))
label = decode_label(
&bpi->extra->labels->label[0]);
else
Expand Down
Loading