Skip to content

Commit

Permalink
bgpd: merge attr vni label with label_tbl
Browse files Browse the repository at this point in the history
No need to have two kinds of labels attr members in memory.

Signed-off-by: Louis Scalbert <[email protected]>
  • Loading branch information
louis-6wind committed Feb 6, 2024
1 parent 582cd89 commit bcb63f4
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 17 deletions.
13 changes: 6 additions & 7 deletions bgpd/bgp_attr.c
Original file line number Diff line number Diff line change
Expand Up @@ -775,9 +775,8 @@ unsigned int attrhash_key_make(const void *p)
attr->aggregator_addr.s_addr);
MIX3(attr->weight, attr->mp_nexthop_global_in.s_addr,
attr->originator_id.s_addr);
MIX3(attr->tag, attr->label, attr->label_index);
MIX3(attr->tag, attr->num_labels, attr->label_index);

MIX(attr->num_labels);
if (attr->num_labels)
key = jhash(&attr->label_tbl, attr->num_labels * sizeof(mpls_label_t), key);
if (attr->aspath)
Expand Down Expand Up @@ -923,7 +922,7 @@ static void attr_show_all_iterator(struct hash_bucket *bucket, struct vty *vty)
"\tflags: %" PRIu64
" distance: %u med: %u local_pref: %u origin: %u weight: %u label: %u sid: %pI6\n",
attr->flag, attr->distance, attr->med, attr->local_pref,
attr->origin, attr->weight, attr->label, sid);
attr->origin, attr->weight, attr->label_tbl[0], sid);
}

void attr_show_all(struct vty *vty)
Expand Down Expand Up @@ -1082,7 +1081,6 @@ struct attr *bgp_attr_default_set(struct attr *attr, struct bgp *bgp,
attr->weight = BGP_ATTR_DEFAULT_WEIGHT;
attr->tag = 0;
attr->label_index = BGP_INVALID_LABEL_INDEX;
attr->label = MPLS_INVALID_LABEL;
attr->num_labels = 0;
for (i = 0; i < BGP_MAX_LABELS; i++)
attr->label_tbl[i] = MPLS_INVALID_LABEL;
Expand Down Expand Up @@ -1146,7 +1144,6 @@ struct attr *bgp_attr_aggregate_intern(
bgp_attr_add_gshut_community(&attr);

attr.label_index = BGP_INVALID_LABEL_INDEX;
attr.label = MPLS_INVALID_LABEL;
attr.num_labels = 0;
for (i = 0; i < BGP_MAX_LABELS; i++)
attr.label_tbl[i] = MPLS_INVALID_LABEL;
Expand Down Expand Up @@ -3260,7 +3257,8 @@ bgp_attr_pmsi_tunnel(struct bgp_attr_parser_args *args)

attr->flag |= ATTR_FLAG_BIT(BGP_ATTR_PMSI_TUNNEL);
bgp_attr_set_pmsi_tnl_type(attr, tnl_type);
stream_get(&attr->label, peer->curr, BGP_LABEL_BYTES);
stream_get(&attr->label_tbl[0], peer->curr, BGP_LABEL_BYTES);
attr->num_labels = 1;

/* Forward read pointer of input stream. */
stream_forward_getp(peer->curr, length - attr_parse_len);
Expand Down Expand Up @@ -4858,12 +4856,13 @@ bgp_size_t bgp_packet_attribute(struct bgp *bgp, struct peer *peer,

/* PMSI Tunnel */
if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_PMSI_TUNNEL)) {
mpls_label_t label = attr->num_labels ? attr->label_tbl[0] : MPLS_INVALID_LABEL;
stream_putc(s, BGP_ATTR_FLAG_OPTIONAL | BGP_ATTR_FLAG_TRANS);
stream_putc(s, BGP_ATTR_PMSI_TUNNEL);
stream_putc(s, 9); // Length
stream_putc(s, 0); // Flags
stream_putc(s, bgp_attr_get_pmsi_tnl_type(attr));
stream_put(s, &(attr->label),
stream_put(s, &label,
BGP_LABEL_BYTES); // MPLS Label / VXLAN VNI
stream_put_ipv4(s, attr->nexthop.s_addr);
// Unicast tunnel endpoint IP address
Expand Down
3 changes: 0 additions & 3 deletions bgpd/bgp_attr.h
Original file line number Diff line number Diff line change
Expand Up @@ -220,9 +220,6 @@ struct attr {
/* ifIndex corresponding to mp_nexthop_local. */
ifindex_t nh_lla_ifindex;

/* MPLS label (VNI) */
mpls_label_t label;

/* Extended Communities attribute. */
struct ecommunity *ecommunity;

Expand Down
7 changes: 5 additions & 2 deletions bgpd/bgp_evpn.c
Original file line number Diff line number Diff line change
Expand Up @@ -2149,7 +2149,8 @@ static int update_evpn_route(struct bgp *bgp, struct bgpevpn *vpn,
esi_to_str(esi, buf3, sizeof(buf3)));
}

vni2label(vpn->vni, &(attr.label));
vni2label(vpn->vni, &(attr.label_tbl[0]));
attr.num_labels = 1;

/* Include L3 VNI related RTs and RMAC for type-2 routes, if they're
* IPv4 or IPv6 global addresses and we're advertising L3VNI with
Expand Down Expand Up @@ -2418,7 +2419,9 @@ void bgp_evpn_update_type2_route_entry(struct bgp *bgp, struct bgpevpn *vpn,
memcpy(&attr.esi, &local_pi->attr->esi, sizeof(esi_t));
bgp_evpn_get_rmac_nexthop(vpn, &evp, &attr,
local_pi->extra->evpn->af_flags);
vni2label(vpn->vni, &(attr.label));
vni2label(vpn->vni, &(attr.label_tbl[0]));
attr.num_labels = 1;

/* Add L3 VNI RTs and RMAC for non IPv6 link-local if
* using L3 VNI for type-2 routes also.
*/
Expand Down
3 changes: 2 additions & 1 deletion bgpd/bgp_evpn_mh.c
Original file line number Diff line number Diff line change
Expand Up @@ -960,7 +960,8 @@ static int bgp_evpn_type1_route_update(struct bgp *bgp, struct bgp_evpn_es *es,
if (vpn) {
/* EAD-EVI route update */
/* MPLS label */
vni2label(vpn->vni, &(attr.label));
vni2label(vpn->vni, &(attr.label_tbl[0]));
attr.num_labels = 1;

/* Set up extended community */
bgp_evpn_type1_evi_route_extcomm_build(es, vpn, &attr);
Expand Down
1 change: 0 additions & 1 deletion bgpd/bgp_packet.c
Original file line number Diff line number Diff line change
Expand Up @@ -2242,7 +2242,6 @@ static int bgp_update_receive(struct peer_connection *connection,
/* Set initial values. */
memset(&attr, 0, sizeof(attr));
attr.label_index = BGP_INVALID_LABEL_INDEX;
attr.label = MPLS_INVALID_LABEL;
memset(&nlris, 0, sizeof(nlris));
memset(peer->rcvd_attr_str, 0, BUFSIZ);
peer->rcvd_attr_printed = 0;
Expand Down
5 changes: 2 additions & 3 deletions bgpd/bgp_route.c
Original file line number Diff line number Diff line change
Expand Up @@ -4208,7 +4208,6 @@ void bgp_update(struct peer *peer, const struct prefix *p, uint32_t addpath_id,

memset(&new_attr, 0, sizeof(new_attr));
new_attr.label_index = BGP_INVALID_LABEL_INDEX;
new_attr.label = MPLS_INVALID_LABEL;

bgp = peer->bgp;
dest = bgp_afi_node_get(bgp->rib[afi][safi], afi, safi, p, prd);
Expand Down Expand Up @@ -10992,11 +10991,11 @@ void route_vty_out_detail(struct vty *vty, struct bgp *bgp, struct bgp_dest *bn,
json_pmsi = json_object_new_object();
json_object_string_add(json_pmsi, "tunnelType", str);
json_object_int_add(json_pmsi, "label",
label2vni(&attr->label));
label2vni(&attr->label_tbl[0]));
json_object_object_add(json_path, "pmsi", json_pmsi);
} else
vty_out(vty, " PMSI Tunnel Type: %s, label: %d\n",
str, label2vni(&attr->label));
str, label2vni(&attr->label_tbl[0]));
}

if (path->peer->connection->t_gr_restart &&
Expand Down

0 comments on commit bcb63f4

Please sign in to comment.