From 863bd2834ee93eda317b4fbc3caaf058f86ea5b9 Mon Sep 17 00:00:00 2001 From: Louis Scalbert Date: Mon, 26 Feb 2024 18:11:09 +0100 Subject: [PATCH] bgpd: store number of labels with 8 bits 8 bits are sufficient to store the number of labels because the current maximum is 2. Signed-off-by: Louis Scalbert --- bgpd/bgp_attr.c | 6 +++--- bgpd/bgp_attr.h | 6 +++--- bgpd/bgp_debug.c | 2 +- bgpd/bgp_debug.h | 2 +- bgpd/bgp_evpn.c | 12 ++++++------ bgpd/bgp_evpn.h | 6 +++--- bgpd/bgp_label.c | 4 ++-- bgpd/bgp_label.h | 4 ++-- bgpd/bgp_mac.c | 2 +- bgpd/bgp_mplsvpn.c | 10 +++++----- bgpd/bgp_route.c | 14 +++++++------- bgpd/bgp_route.h | 8 ++++---- bgpd/bgp_rpki.c | 2 +- bgpd/bgp_updgrp_packet.c | 4 ++-- bgpd/bgp_zebra.c | 5 ++--- bgpd/bgp_zebra.h | 2 +- 16 files changed, 44 insertions(+), 45 deletions(-) diff --git a/bgpd/bgp_attr.c b/bgpd/bgp_attr.c index 0dec8ea4e4c9..3ec94644b945 100644 --- a/bgpd/bgp_attr.c +++ b/bgpd/bgp_attr.c @@ -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) { @@ -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) { @@ -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) { diff --git a/bgpd/bgp_attr.h b/bgpd/bgp_attr.h index 5386f24a0bac..a580f478a43f 100644 --- a/bgpd/bgp_attr.h +++ b/bgpd/bgp_attr.h @@ -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); @@ -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, @@ -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); diff --git a/bgpd/bgp_debug.c b/bgpd/bgp_debug.c index 3ecdc0d3cf10..e4548ce0030f 100644 --- a/bgpd/bgp_debug.c +++ b/bgpd/bgp_debug.c @@ -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) diff --git a/bgpd/bgp_debug.h b/bgpd/bgp_debug.h index 5b0950185265..b78fa567579c 100644 --- a/bgpd/bgp_debug.h +++ b/bgpd/bgp_debug.h @@ -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, diff --git a/bgpd/bgp_evpn.c b/bgpd/bgp_evpn.c index 63d5810acbed..46192feed128 100644 --- a/bgpd/bgp_evpn.c +++ b/bgpd/bgp_evpn.c @@ -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; @@ -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; @@ -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; @@ -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; @@ -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; @@ -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; diff --git a/bgpd/bgp_evpn.h b/bgpd/bgp_evpn.h index 840389758723..8aa24f63354b 100644 --- a/bgpd/bgp_evpn.h +++ b/bgpd/bgp_evpn.h @@ -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, @@ -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); diff --git a/bgpd/bgp_label.c b/bgpd/bgp_label.c index 473006df2b4b..4f9bc0a19056 100644 --- a/bgpd/bgp_label.c +++ b/bgpd/bgp_label.c @@ -472,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; diff --git a/bgpd/bgp_label.h b/bgpd/bgp_label.h index b54403ee89b0..704d1b49585f 100644 --- a/bgpd/bgp_label.h +++ b/bgpd/bgp_label.h @@ -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) { diff --git a/bgpd/bgp_mac.c b/bgpd/bgp_mac.c index aa793e999d84..1f70ad797012 100644 --- a/bgpd/bgp_mac.c +++ b/bgpd/bgp_mac.c @@ -125,7 +125,7 @@ static void bgp_process_mac_rescan_table(struct bgp *bgp, struct peer *peer, { struct bgp_dest *pdest, *dest; struct bgp_path_info *pi; - uint32_t num_labels; + uint8_t num_labels; mpls_label_t *label_pnt; for (pdest = bgp_table_top(table); pdest; diff --git a/bgpd/bgp_mplsvpn.c b/bgpd/bgp_mplsvpn.c index 42cd7e9bc21f..e5e2ad5225d2 100644 --- a/bgpd/bgp_mplsvpn.c +++ b/bgpd/bgp_mplsvpn.c @@ -962,7 +962,7 @@ void transpose_sid(struct in6_addr *sid, uint32_t label, uint8_t offset, */ 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); @@ -975,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]; @@ -1064,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); @@ -2073,7 +2073,7 @@ static void vpn_leak_to_vrf_update_onevrf(struct bgp *to_bgp, /* to */ const char *debugmsg; struct prefix nexthop_orig; mpls_label_t *label_pnt = NULL; - uint32_t num_labels = 0; + uint8_t num_labels = 0; int nexthop_self_flag = 1; struct bgp_path_info *bpi_ultimate = NULL; struct bgp_path_info *bpi; @@ -3957,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; diff --git a/bgpd/bgp_route.c b/bgpd/bgp_route.c index d5e0bd21f037..f3998d16c1d7 100644 --- a/bgpd/bgp_route.c +++ b/bgpd/bgp_route.c @@ -294,7 +294,7 @@ bool bgp_path_info_has_valid_label(const struct bgp_path_info *path) bool bgp_path_info_labels_same(const struct bgp_path_info *bpi, const mpls_label_t *label, uint32_t n) { - uint32_t bpi_num_labels; + uint8_t bpi_num_labels; const mpls_label_t *bpi_label; bpi_num_labels = bgp_path_info_num_labels(bpi); @@ -304,7 +304,7 @@ bool bgp_path_info_labels_same(const struct bgp_path_info *bpi, (const mpls_label_t *)label, n); } -uint32_t bgp_path_info_num_labels(const struct bgp_path_info *pi) +uint8_t bgp_path_info_num_labels(const struct bgp_path_info *pi) { if (!pi) return 0; @@ -1782,7 +1782,7 @@ static bool bgp_check_role_applicability(afi_t afi, safi_t safi) static int bgp_input_modifier(struct peer *peer, const struct prefix *p, struct attr *attr, afi_t afi, safi_t safi, const char *rmap_name, mpls_label_t *label, - uint32_t num_labels, struct bgp_dest *dest) + uint8_t num_labels, struct bgp_dest *dest) { struct bgp_filter *filter; struct bgp_path_info rmap_path = { 0 }; @@ -4206,7 +4206,7 @@ static bool bgp_accept_own(struct peer *peer, afi_t afi, safi_t safi, void bgp_update(struct peer *peer, const struct prefix *p, uint32_t addpath_id, struct attr *attr, afi_t afi, safi_t safi, int type, int sub_type, struct prefix_rd *prd, mpls_label_t *label, - uint32_t num_labels, int soft_reconfig, + uint8_t num_labels, int soft_reconfig, struct bgp_route_evpn *evpn) { int ret; @@ -5119,7 +5119,7 @@ void bgp_update(struct peer *peer, const struct prefix *p, uint32_t addpath_id, void bgp_withdraw(struct peer *peer, const struct prefix *p, uint32_t addpath_id, afi_t afi, safi_t safi, int type, int sub_type, struct prefix_rd *prd, mpls_label_t *label, - uint32_t num_labels, struct bgp_route_evpn *evpn) + uint8_t num_labels, struct bgp_route_evpn *evpn) { struct bgp *bgp; char pfx_buf[BGP_PRD_PATH_STRLEN]; @@ -5346,7 +5346,7 @@ static void bgp_soft_reconfig_table_update(struct peer *peer, safi_t safi, struct prefix_rd *prd) { struct bgp_path_info *pi; - uint32_t num_labels; + uint8_t num_labels; mpls_label_t *label_pnt; struct bgp_route_evpn evpn; @@ -6367,7 +6367,7 @@ void bgp_static_update(struct bgp *bgp, const struct prefix *p, int vnc_implicit_withdraw = 0; mpls_label_t label = MPLS_INVALID_LABEL; #endif - uint32_t num_labels = 0; + uint8_t num_labels = 0; assert(bgp_static); diff --git a/bgpd/bgp_route.h b/bgpd/bgp_route.h index 57bfaaf6aac3..e0fec75d8d1c 100644 --- a/bgpd/bgp_route.h +++ b/bgpd/bgp_route.h @@ -238,7 +238,7 @@ struct bgp_path_info_extra { /* MPLS label(s) - VNI(s) for EVPN-VxLAN */ mpls_label_t label[BGP_MAX_LABELS]; - uint32_t num_labels; + uint8_t num_labels; /* timestamp of the rib installation */ time_t bgp_rib_uptime; @@ -751,7 +751,7 @@ 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 uint32_t bgp_path_info_num_labels(const struct bgp_path_info *pi); +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, @@ -796,12 +796,12 @@ extern void bgp_update(struct peer *peer, const struct prefix *p, uint32_t addpath_id, struct attr *attr, afi_t afi, safi_t safi, int type, int sub_type, struct prefix_rd *prd, mpls_label_t *label, - uint32_t num_labels, int soft_reconfig, + uint8_t num_labels, int soft_reconfig, struct bgp_route_evpn *evpn); extern void bgp_withdraw(struct peer *peer, const struct prefix *p, uint32_t addpath_id, afi_t afi, safi_t safi, int type, int sub_type, struct prefix_rd *prd, - mpls_label_t *label, uint32_t num_labels, + mpls_label_t *label, uint8_t num_labels, struct bgp_route_evpn *evpn); /* for bgp_nexthop and bgp_damp */ diff --git a/bgpd/bgp_rpki.c b/bgpd/bgp_rpki.c index d030806da76c..73f560412f3c 100644 --- a/bgpd/bgp_rpki.c +++ b/bgpd/bgp_rpki.c @@ -657,7 +657,7 @@ static void revalidate_bgp_node(struct bgp_dest *bgp_dest, afi_t afi, { struct bgp_adj_in *ain; mpls_label_t *label; - uint32_t num_labels; + uint8_t num_labels; for (ain = bgp_dest->adj_in; ain; ain = ain->next) { struct bgp_path_info *path = diff --git a/bgpd/bgp_updgrp_packet.c b/bgpd/bgp_updgrp_packet.c index 568090e3e878..eadc3b3a0740 100644 --- a/bgpd/bgp_updgrp_packet.c +++ b/bgpd/bgp_updgrp_packet.c @@ -665,7 +665,7 @@ struct bpacket *subgroup_update_packet(struct update_subgroup *subgrp) uint32_t addpath_tx_id = 0; struct prefix_rd *prd = NULL; mpls_label_t label = MPLS_INVALID_LABEL, *label_pnt = NULL; - uint32_t num_labels = 0; + uint8_t num_labels = 0; if (!subgrp) return NULL; @@ -1082,7 +1082,7 @@ void subgroup_default_update_packet(struct update_subgroup *subgrp, struct bpacket_attr_vec_arr vecarr; bool addpath_capable = false; mpls_label_t label = MPLS_LABEL_IMPLICIT_NULL; - uint32_t num_labels = 0; + uint8_t num_labels = 0; if (DISABLE_BGP_ANNOUNCE) return; diff --git a/bgpd/bgp_zebra.c b/bgpd/bgp_zebra.c index c2bab42f2ad5..5a637575b37d 100644 --- a/bgpd/bgp_zebra.c +++ b/bgpd/bgp_zebra.c @@ -1243,7 +1243,7 @@ static void bgp_zebra_announce_parse_nexthop( struct bgp_path_info local_info; struct bgp_path_info *mpinfo_cp = &local_info; mpls_label_t *labels; - uint32_t num_labels = 0; + uint8_t num_labels = 0; mpls_label_t nh_label; int nh_othervrf = 0; bool nh_updated = false; @@ -3904,8 +3904,7 @@ int bgp_zebra_srv6_manager_release_locator_chunk(const char *name) void bgp_zebra_send_nexthop_label(int cmd, mpls_label_t label, ifindex_t ifindex, vrf_id_t vrf_id, enum lsp_types_t ltype, struct prefix *p, - uint32_t num_labels, - mpls_label_t out_labels[]) + uint8_t num_labels, mpls_label_t out_labels[]) { struct zapi_labels zl = {}; struct zapi_nexthop *znh; diff --git a/bgpd/bgp_zebra.h b/bgpd/bgp_zebra.h index 396c8335f8cc..eff956dddca8 100644 --- a/bgpd/bgp_zebra.h +++ b/bgpd/bgp_zebra.h @@ -122,7 +122,7 @@ extern int bgp_zebra_srv6_manager_release_locator_chunk(const char *name); extern void bgp_zebra_send_nexthop_label(int cmd, mpls_label_t label, ifindex_t index, vrf_id_t vrfid, enum lsp_types_t ltype, - struct prefix *p, uint32_t num_labels, + struct prefix *p, uint8_t num_labels, mpls_label_t out_labels[]); extern bool bgp_zebra_request_label_range(uint32_t base, uint32_t chunk_size, bool label_auto);