Skip to content

Commit

Permalink
bgpd: store number of labels with 8 bits
Browse files Browse the repository at this point in the history
8 bits are sufficient to store the number of labels because the current
maximum is 2.

Signed-off-by: Louis Scalbert <louis.scalbert@6wind.com>
  • Loading branch information
louis-6wind committed Feb 27, 2024
1 parent e440de5 commit 863bd28
Show file tree
Hide file tree
Showing 16 changed files with 44 additions and 45 deletions.
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
12 changes: 6 additions & 6 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 @@ -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
4 changes: 2 additions & 2 deletions bgpd/bgp_label.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

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
2 changes: 1 addition & 1 deletion bgpd/bgp_mac.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 5 additions & 5 deletions bgpd/bgp_mplsvpn.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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];
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
14 changes: 7 additions & 7 deletions bgpd/bgp_route.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
Expand Down Expand Up @@ -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 };
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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);

Expand Down
8 changes: 4 additions & 4 deletions bgpd/bgp_route.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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 */
Expand Down
2 changes: 1 addition & 1 deletion bgpd/bgp_rpki.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
4 changes: 2 additions & 2 deletions bgpd/bgp_updgrp_packet.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
5 changes: 2 additions & 3 deletions bgpd/bgp_zebra.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion bgpd/bgp_zebra.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 863bd28

Please sign in to comment.