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: cleanup for path_info extra labels #15307

Closed
wants to merge 9 commits into from
6 changes: 3 additions & 3 deletions bgpd/bgp_attr.c
Original file line number Diff line number Diff line change
Expand Up @@ -4128,7 +4128,7 @@ size_t bgp_packet_mpattr_start(struct stream *s, struct peer *peer, afi_t afi,
void bgp_packet_mpattr_prefix(struct stream *s, afi_t afi, safi_t safi,
const struct prefix *p,
const struct prefix_rd *prd, mpls_label_t *label,
uint32_t num_labels, bool addpath_capable,
uint8_t num_labels, bool addpath_capable,
uint32_t addpath_tx_id, struct attr *attr)
{
switch (safi) {
Expand Down Expand Up @@ -4341,7 +4341,7 @@ bgp_size_t bgp_packet_attribute(struct bgp *bgp, struct peer *peer,
struct bpacket_attr_vec_arr *vecarr,
struct prefix *p, afi_t afi, safi_t safi,
struct peer *from, struct prefix_rd *prd,
mpls_label_t *label, uint32_t num_labels,
mpls_label_t *label, uint8_t num_labels,
bool addpath_capable, uint32_t addpath_tx_id,
struct bgp_path_info *bpi)
{
Expand Down Expand Up @@ -4921,7 +4921,7 @@ size_t bgp_packet_mpunreach_start(struct stream *s, afi_t afi, safi_t safi)
void bgp_packet_mpunreach_prefix(struct stream *s, const struct prefix *p,
afi_t afi, safi_t safi,
const struct prefix_rd *prd,
mpls_label_t *label, uint32_t num_labels,
mpls_label_t *label, uint8_t num_labels,
bool addpath_capable, uint32_t addpath_tx_id,
struct attr *attr)
{
Expand Down
6 changes: 3 additions & 3 deletions bgpd/bgp_attr.h
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ extern bgp_size_t bgp_packet_attribute(
struct bgp *bgp, struct peer *peer, struct stream *s, struct attr *attr,
struct bpacket_attr_vec_arr *vecarr, struct prefix *p, afi_t afi,
safi_t safi, struct peer *from, struct prefix_rd *prd,
mpls_label_t *label, uint32_t num_labels, bool addpath_capable,
mpls_label_t *label, uint8_t num_labels, bool addpath_capable,
uint32_t addpath_tx_id, struct bgp_path_info *bpi);
extern void bgp_dump_routes_attr(struct stream *s, struct bgp_path_info *bpi,
const struct prefix *p);
Expand Down Expand Up @@ -451,7 +451,7 @@ extern size_t bgp_packet_mpattr_start(struct stream *s, struct peer *peer,
extern void bgp_packet_mpattr_prefix(struct stream *s, afi_t afi, safi_t safi,
const struct prefix *p,
const struct prefix_rd *prd,
mpls_label_t *label, uint32_t num_labels,
mpls_label_t *label, uint8_t num_labels,
bool addpath_capable,
uint32_t addpath_tx_id, struct attr *);
extern size_t bgp_packet_mpattr_prefix_size(afi_t afi, safi_t safi,
Expand All @@ -462,7 +462,7 @@ extern size_t bgp_packet_mpunreach_start(struct stream *s, afi_t afi,
safi_t safi);
extern void bgp_packet_mpunreach_prefix(
struct stream *s, const struct prefix *p, afi_t afi, safi_t safi,
const struct prefix_rd *prd, mpls_label_t *label, uint32_t num_labels,
const struct prefix_rd *prd, mpls_label_t *label, uint8_t num_labels,
bool addpath_capable, uint32_t addpath_tx_id, struct attr *attr);
extern void bgp_packet_mpunreach_end(struct stream *s, size_t attrlen_pnt);

Expand Down
2 changes: 1 addition & 1 deletion bgpd/bgp_debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -2722,7 +2722,7 @@ bool bgp_debug_zebra(const struct prefix *p)
const char *bgp_debug_rdpfxpath2str(afi_t afi, safi_t safi,
const struct prefix_rd *prd,
union prefixconstptr pu,
mpls_label_t *label, uint32_t num_labels,
mpls_label_t *label, uint8_t num_labels,
int addpath_valid, uint32_t addpath_id,
struct bgp_route_evpn *overlay_index,
char *str, int size)
Expand Down
2 changes: 1 addition & 1 deletion bgpd/bgp_debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ extern bool bgp_debug_zebra(const struct prefix *p);

extern const char *bgp_debug_rdpfxpath2str(
afi_t afi, safi_t safi, const struct prefix_rd *prd,
union prefixconstptr pu, mpls_label_t *label, uint32_t num_labels,
union prefixconstptr pu, mpls_label_t *label, uint8_t num_labels,
int addpath_valid, uint32_t addpath_id,
struct bgp_route_evpn *overlay_index, char *str, int size);
const char *bgp_notify_admin_message(char *buf, size_t bufsz, uint8_t *data,
Expand Down
14 changes: 7 additions & 7 deletions bgpd/bgp_evpn.c
Original file line number Diff line number Diff line change
Expand Up @@ -1882,7 +1882,7 @@ static int update_evpn_route_entry(struct bgp *bgp, struct bgpevpn *vpn,
struct attr *attr_new;
struct attr local_attr;
mpls_label_t label[BGP_MAX_LABELS];
uint32_t num_labels = 1;
uint8_t num_labels = 1;
int route_change = 1;
uint8_t sticky = 0;
const struct prefix_evpn *evp;
Expand Down Expand Up @@ -2896,7 +2896,7 @@ bgp_create_evpn_bgp_path_info(struct bgp_path_info *parent_pi,
if (parent_pi->extra) {
memcpy(&pi->extra->label, &parent_pi->extra->label,
sizeof(pi->extra->label));
pi->extra->num_labels = parent_pi->extra->num_labels;
pi->extra->num_labels = bgp_path_info_num_labels(parent_pi);
pi->extra->igpmetric = parent_pi->extra->igpmetric;
}

Expand Down Expand Up @@ -4612,7 +4612,7 @@ static int process_type2_route(struct peer *peer, afi_t afi, safi_t safi,
uint8_t macaddr_len;
/* holds the VNI(s) as in packet */
mpls_label_t label[BGP_MAX_LABELS] = {};
uint32_t num_labels = 0;
uint8_t num_labels = 0;
uint32_t eth_tag;
int ret = 0;

Expand Down Expand Up @@ -4955,7 +4955,7 @@ static int process_type5_route(struct peer *peer, afi_t afi, safi_t safi,

static void evpn_mpattr_encode_type5(struct stream *s, const struct prefix *p,
const struct prefix_rd *prd,
mpls_label_t *label, uint32_t num_labels,
mpls_label_t *label, uint8_t num_labels,
struct attr *attr)
{
int len;
Expand Down Expand Up @@ -5745,7 +5745,7 @@ int bgp_evpn_uninstall_routes(struct bgp *bgp, struct bgpevpn *vpn)
/*
* TODO: Hardcoded for a maximum of 2 VNIs right now
*/
char *bgp_evpn_label2str(mpls_label_t *label, uint32_t num_labels, char *buf,
char *bgp_evpn_label2str(mpls_label_t *label, uint8_t num_labels, char *buf,
int len)
{
vni_t vni1, vni2;
Expand Down Expand Up @@ -5829,7 +5829,7 @@ void bgp_evpn_route2json(const struct prefix_evpn *p, json_object *json)
*/
void bgp_evpn_encode_prefix(struct stream *s, const struct prefix *p,
const struct prefix_rd *prd, mpls_label_t *label,
uint32_t num_labels, struct attr *attr,
uint8_t num_labels, struct attr *attr,
bool addpath_capable, uint32_t addpath_tx_id)
{
struct prefix_evpn *evp = (struct prefix_evpn *)p;
Expand Down Expand Up @@ -7659,7 +7659,7 @@ void bgp_evpn_handle_resolve_overlay_index_unset(struct hash_bucket *bucket,
*
*/
mpls_label_t *bgp_evpn_path_info_labels_get_l3vni(mpls_label_t *labels,
uint32_t num_labels)
uint8_t num_labels)
{
if (!labels)
return NULL;
Expand Down
6 changes: 3 additions & 3 deletions bgpd/bgp_evpn.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,12 @@ extern void bgp_evpn_advertise_type5_routes(struct bgp *bgp_vrf, afi_t afi,
safi_t safi);
extern void bgp_evpn_vrf_delete(struct bgp *bgp_vrf);
extern void bgp_evpn_handle_router_id_update(struct bgp *bgp, int withdraw);
extern char *bgp_evpn_label2str(mpls_label_t *label, uint32_t num_labels,
extern char *bgp_evpn_label2str(mpls_label_t *label, uint8_t num_labels,
char *buf, int len);
extern void bgp_evpn_route2json(const struct prefix_evpn *p, json_object *json);
extern void bgp_evpn_encode_prefix(struct stream *s, const struct prefix *p,
const struct prefix_rd *prd,
mpls_label_t *label, uint32_t num_labels,
mpls_label_t *label, uint8_t num_labels,
struct attr *attr, bool addpath_capable,
uint32_t addpath_tx_id);
extern int bgp_nlri_parse_evpn(struct peer *peer, struct attr *attr,
Expand Down Expand Up @@ -177,7 +177,7 @@ extern void
bgp_evpn_handle_resolve_overlay_index_unset(struct hash_bucket *bucket,
void *arg);
extern mpls_label_t *bgp_evpn_path_info_labels_get_l3vni(mpls_label_t *labels,
uint32_t num_labels);
uint8_t num_labels);
extern vni_t bgp_evpn_path_info_get_l3vni(const struct bgp_path_info *pi);
extern bool bgp_evpn_mpath_has_dvni(const struct bgp *bgp_vrf,
struct bgp_path_info *mpinfo);
Expand Down
7 changes: 4 additions & 3 deletions bgpd/bgp_label.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ 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 = pi->extra ? pi->extra->label[0] : MPLS_INVALID_LABEL;
remote_label = bgp_path_info_num_labels(pi) ? pi->extra->label[0]
: MPLS_INVALID_LABEL;
from = pi->peer;
reflect =
((from->sort == BGP_PEER_IBGP) && (to->sort == BGP_PEER_IBGP));
Expand Down Expand Up @@ -471,8 +472,8 @@ int bgp_nlri_parse_label(struct peer *peer, struct attr *attr,
return BGP_NLRI_PARSE_OK;
}

bool bgp_labels_same(const mpls_label_t *tbl_a, const uint32_t num_labels_a,
const mpls_label_t *tbl_b, const uint32_t num_labels_b)
bool bgp_labels_same(const mpls_label_t *tbl_a, const uint8_t num_labels_a,
const mpls_label_t *tbl_b, const uint8_t num_labels_b)
{
uint32_t i;

Expand Down
4 changes: 2 additions & 2 deletions bgpd/bgp_label.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ extern mpls_label_t bgp_adv_label(struct bgp_dest *dest,
extern int bgp_nlri_parse_label(struct peer *peer, struct attr *attr,
struct bgp_nlri *packet);
extern bool bgp_labels_same(const mpls_label_t *tbl_a,
const uint32_t num_labels_a,
const uint8_t num_labels_a,
const mpls_label_t *tbl_b,
const uint32_t num_labels_b);
const uint8_t num_labels_b);

static inline int bgp_labeled_safi(safi_t safi)
{
Expand Down
10 changes: 4 additions & 6 deletions bgpd/bgp_mac.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ static void bgp_process_mac_rescan_table(struct bgp *bgp, struct peer *peer,
{
struct bgp_dest *pdest, *dest;
struct bgp_path_info *pi;
uint8_t num_labels;
mpls_label_t *label_pnt;

for (pdest = bgp_table_top(table); pdest;
pdest = bgp_route_next(pdest)) {
Expand All @@ -140,8 +142,6 @@ static void bgp_process_mac_rescan_table(struct bgp *bgp, struct peer *peer,
const struct prefix *p = bgp_dest_get_prefix(dest);
struct prefix_evpn *pevpn = (struct prefix_evpn *)dest;
struct prefix_rd prd;
uint32_t num_labels = 0;
mpls_label_t *label_pnt = NULL;
struct bgp_route_evpn *evpn;

if (pevpn->family == AF_EVPN
Expand Down Expand Up @@ -169,10 +169,8 @@ static void bgp_process_mac_rescan_table(struct bgp *bgp, struct peer *peer,
&& !dest_affected)
continue;

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

prd.family = AF_UNSPEC;
prd.prefixlen = 64;
Expand Down
58 changes: 21 additions & 37 deletions bgpd/bgp_mplsvpn.c
Original file line number Diff line number Diff line change
Expand Up @@ -957,27 +957,12 @@ void transpose_sid(struct in6_addr *sid, uint32_t label, uint8_t offset,
}
}

static bool labels_same(struct bgp_path_info *bpi, mpls_label_t *label,
uint32_t n)
{
if (!bpi->extra) {
if (!n)
return true;
else
return false;
}

return bgp_labels_same((const mpls_label_t *)bpi->extra->label,
bpi->extra->num_labels,
(const mpls_label_t *)label, n);
}

/*
* make encoded route labels match specified encoded label set
*/
static void setlabels(struct bgp_path_info *bpi,
mpls_label_t *label, /* array of labels */
uint32_t num_labels)
uint8_t num_labels)
{
if (num_labels)
assert(label);
Expand All @@ -990,7 +975,7 @@ static void setlabels(struct bgp_path_info *bpi,
}

struct bgp_path_info_extra *extra = bgp_path_info_extra_get(bpi);
uint32_t i;
uint8_t i;

for (i = 0; i < num_labels; ++i) {
extra->label[i] = label[i];
Expand Down Expand Up @@ -1079,7 +1064,7 @@ static struct bgp_path_info *
leak_update(struct bgp *to_bgp, struct bgp_dest *bn,
struct attr *new_attr, /* already interned */
afi_t afi, safi_t safi, struct bgp_path_info *source_bpi,
mpls_label_t *label, uint32_t num_labels, struct bgp *bgp_orig,
mpls_label_t *label, uint8_t num_labels, struct bgp *bgp_orig,
struct prefix *nexthop_orig, int nexthop_self_flag, int debug)
{
const struct prefix *p = bgp_dest_get_prefix(bn);
Expand Down Expand Up @@ -1122,7 +1107,8 @@ leak_update(struct bgp *to_bgp, struct bgp_dest *bn,
}

if (bpi) {
bool labelssame = labels_same(bpi, label, num_labels);
bool labelssame = bgp_path_info_labels_same(bpi, label,
num_labels);

if (CHECK_FLAG(source_bpi->flags, BGP_PATH_REMOVED)
&& CHECK_FLAG(bpi->flags, BGP_PATH_REMOVED)) {
Expand Down Expand Up @@ -2086,8 +2072,8 @@ static void vpn_leak_to_vrf_update_onevrf(struct bgp *to_bgp, /* to */
safi_t safi = SAFI_UNICAST;
const char *debugmsg;
struct prefix nexthop_orig;
mpls_label_t *pLabels = NULL;
uint32_t num_labels = 0;
mpls_label_t *label_pnt = NULL;
uint8_t num_labels = 0;
int nexthop_self_flag = 1;
struct bgp_path_info *bpi_ultimate = NULL;
struct bgp_path_info *bpi;
Expand Down Expand Up @@ -2332,21 +2318,16 @@ static void vpn_leak_to_vrf_update_onevrf(struct bgp *to_bgp, /* to */
origin_local = 1;
}

/* copy labels */
if (!origin_local && path_vpn->extra
&& path_vpn->extra->num_labels) {
num_labels = path_vpn->extra->num_labels;
if (num_labels > BGP_MAX_LABELS)
num_labels = BGP_MAX_LABELS;
pLabels = path_vpn->extra->label;
}
num_labels = origin_local ? 0
: bgp_path_info_num_labels(path_vpn);
label_pnt = num_labels ? path_vpn->extra->label : NULL;
}

if (debug)
zlog_debug("%s: pfx %pBD: num_labels %d", __func__,
path_vpn->net, num_labels);

if (!leak_update(to_bgp, bn, new_attr, afi, safi, path_vpn, pLabels,
if (!leak_update(to_bgp, bn, new_attr, afi, safi, path_vpn, label_pnt,
num_labels, src_vrf, &nexthop_orig, nexthop_self_flag,
debug))
bgp_dest_unlock_node(bn);
Expand Down Expand Up @@ -3976,7 +3957,7 @@ static void bgp_mplsvpn_nh_label_bind_send_nexthop_label(
struct bgp_mplsvpn_nh_label_bind_cache *bmnc, int cmd)
{
struct prefix pfx_nh, *p = NULL;
uint32_t num_labels = 0, lsp_num_labels;
uint8_t num_labels = 0, lsp_num_labels;
mpls_label_t label[MPLS_MAX_LABELS];
struct nexthop *nh;
ifindex_t ifindex = IFINDEX_INTERNAL;
Expand Down Expand Up @@ -4111,7 +4092,7 @@ bool bgp_mplsvpn_path_uses_valid_mpls_label(struct bgp_path_info *pi)
/* prefix_sid attribute */
return false;

if (!pi->extra || !bgp_is_valid_label(&pi->extra->label[0]))
if (!bgp_path_info_has_valid_label(pi))
/* invalid MPLS label */
return false;
return true;
Expand Down Expand Up @@ -4218,14 +4199,17 @@ void bgp_mplsvpn_nh_label_bind_register_local_label(struct bgp *bgp,
{
struct bgp_mplsvpn_nh_label_bind_cache *bmnc;
struct bgp_mplsvpn_nh_label_bind_cache_head *tree;
mpls_label_t label;

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

tree = &bgp->mplsvpn_nh_label_bind;
bmnc = bgp_mplsvpn_nh_label_bind_find(
tree, &pi->nexthop->prefix, decode_label(&pi->extra->label[0]));
bmnc = bgp_mplsvpn_nh_label_bind_find(tree, &pi->nexthop->prefix, label);
if (!bmnc) {
bmnc = bgp_mplsvpn_nh_label_bind_new(
tree, &pi->nexthop->prefix,
decode_label(&pi->extra->label[0]));
bmnc = bgp_mplsvpn_nh_label_bind_new(tree, &pi->nexthop->prefix,
label);
bmnc->bgp_vpn = bgp;
bmnc->allocation_in_progress = true;
bgp_lp_get(LP_TYPE_BGP_L3VPN_BIND, bmnc,
Expand Down
12 changes: 6 additions & 6 deletions bgpd/bgp_nht.c
Original file line number Diff line number Diff line change
Expand Up @@ -494,8 +494,8 @@ int bgp_find_or_add_nexthop(struct bgp *bgp_route, struct bgp *bgp_nexthop,
if (bgp_route->inst_type == BGP_INSTANCE_TYPE_VIEW)
return 1;
else if (safi == SAFI_UNICAST && pi &&
pi->sub_type == BGP_ROUTE_IMPORTED && pi->extra &&
pi->extra->num_labels && !bnc->is_evpn_gwip_nexthop)
pi->sub_type == BGP_ROUTE_IMPORTED &&
bgp_path_info_num_labels(pi) && !bnc->is_evpn_gwip_nexthop)
return bgp_isvalid_nexthop_for_mpls(bnc, pi);
else if (safi == SAFI_MPLS_VPN && pi &&
pi->sub_type != BGP_ROUTE_IMPORTED)
Expand Down Expand Up @@ -1290,10 +1290,10 @@ void evaluate_paths(struct bgp_nexthop_cache *bnc)
bool bnc_is_valid_nexthop = false;
bool path_valid = false;

if (safi == SAFI_UNICAST && path->sub_type == BGP_ROUTE_IMPORTED
&& path->extra && path->extra->num_labels
&& (path->attr->evpn_overlay.type
!= OVERLAY_INDEX_GATEWAY_IP)) {
if (safi == SAFI_UNICAST &&
path->sub_type == BGP_ROUTE_IMPORTED &&
bgp_path_info_num_labels(path) &&
(path->attr->evpn_overlay.type != OVERLAY_INDEX_GATEWAY_IP)) {
bnc_is_valid_nexthop =
bgp_isvalid_nexthop_for_mpls(bnc, path) ? true
: false;
Expand Down
Loading
Loading