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 7, 2024
1 parent e1dd62c commit 285551d
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 16 deletions.
13 changes: 6 additions & 7 deletions bgpd/bgp_attr.c
Original file line number Diff line number Diff line change
Expand Up @@ -776,9 +776,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);
Expand Down Expand Up @@ -926,7 +925,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 @@ -1083,7 +1082,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->flag |= ATTR_FLAG_BIT(BGP_ATTR_NEXT_HOP);
attr->mp_nexthop_len = IPV6_MAX_BYTELEN;
attr->local_pref = bgp->default_local_pref;
Expand Down Expand Up @@ -1143,7 +1141,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.weight = BGP_ATTR_DEFAULT_WEIGHT;
attr.mp_nexthop_len = IPV6_MAX_BYTELEN;
if (!aggregate->as_set || atomic_aggregate)
Expand Down Expand Up @@ -3253,7 +3250,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 @@ -4851,12 +4849,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 @@ -2147,7 +2147,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 @@ -2416,7 +2417,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 @@ -2243,7 +2243,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
4 changes: 2 additions & 2 deletions bgpd/bgp_route.c
Original file line number Diff line number Diff line change
Expand Up @@ -10984,11 +10984,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 285551d

Please sign in to comment.