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: move labels from extra to attr structure #13740

Closed
wants to merge 16 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions bgpd/bgp_attr.c
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,14 @@ void bgp_attr_flush_encap(struct attr *attr)
#endif
}

static bool labels_same(const struct attr *attr1, const struct attr *attr2)
{
return bgp_labels_same((const mpls_label_t *)attr1->label_tbl,
attr1->num_labels,
(const mpls_label_t *)attr2->label_tbl,
attr2->num_labels);
}

/*
* Compare encap sub-tlv chains
*
Expand Down Expand Up @@ -768,8 +776,11 @@ 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);

if (attr->num_labels)
key = jhash(&attr->label_tbl,
attr->num_labels * sizeof(mpls_label_t), key);
if (attr->aspath)
MIX(aspath_key_make(attr->aspath));
if (bgp_attr_get_community(attr))
Expand Down Expand Up @@ -871,6 +882,7 @@ bool attrhash_cmp(const void *p1, const void *p2)
attr1->srte_color == attr2->srte_color &&
attr1->nh_type == attr2->nh_type &&
attr1->bh_type == attr2->bh_type &&
labels_same(attr1, attr2) &&
attr1->otc == attr2->otc)
return true;
}
Expand Down Expand Up @@ -913,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 @@ -1070,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 @@ -1130,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 @@ -3240,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 @@ -4838,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
12 changes: 8 additions & 4 deletions bgpd/bgp_attr.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "mpls.h"
#include "bgp_attr_evpn.h"
#include "bgpd/bgp_encap_types.h"
#include "bgpd/bgp_label.h"
#include "srte.h"

/* Simple bit mapping. */
Expand Down Expand Up @@ -219,9 +220,6 @@ struct attr {
/* ifIndex corresponding to mp_nexthop_local. */
ifindex_t nh_lla_ifindex;

/* MPLS label */
mpls_label_t label;

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

Expand Down Expand Up @@ -266,9 +264,12 @@ struct attr {
/* route tag */
route_tag_t tag;

/* Label index */
/* Prefix SID - Label index */
uint32_t label_index;

/* MPLS label table */
mpls_label_t label_tbl[BGP_MAX_LABELS];

/* SRv6 VPN SID */
struct bgp_attr_srv6_vpn *srv6_vpn;

Expand Down Expand Up @@ -307,6 +308,9 @@ struct attr {
/* EVPN ES */
esi_t esi;

/* number of labels in MPLS label table */
uint8_t num_labels;

/* SR-TE Color */
uint32_t srte_color;

Expand Down
Loading
Loading