From ce567a7ee47af45bb35d24b3a1f1012e37dd7615 Mon Sep 17 00:00:00 2001 From: Louis Scalbert Date: Mon, 5 Feb 2024 14:42:05 +0100 Subject: [PATCH] bgpd: merge attr vni label with label_tbl No need to have two kinds of labels attr members in memory. Signed-off-by: Louis Scalbert --- bgpd/bgp_attr.c | 13 ++++++------- bgpd/bgp_attr.h | 3 --- bgpd/bgp_evpn.c | 7 +++++-- bgpd/bgp_evpn_mh.c | 3 ++- bgpd/bgp_packet.c | 1 - bgpd/bgp_route.c | 5 ++--- 6 files changed, 15 insertions(+), 17 deletions(-) diff --git a/bgpd/bgp_attr.c b/bgpd/bgp_attr.c index 5a1050609540..2009d020b63d 100644 --- a/bgpd/bgp_attr.c +++ b/bgpd/bgp_attr.c @@ -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) @@ -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) @@ -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; @@ -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; @@ -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); @@ -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 diff --git a/bgpd/bgp_attr.h b/bgpd/bgp_attr.h index 90578b7a26a7..d3d5ac09ea67 100644 --- a/bgpd/bgp_attr.h +++ b/bgpd/bgp_attr.h @@ -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; diff --git a/bgpd/bgp_evpn.c b/bgpd/bgp_evpn.c index 6d1f6e6c46ed..f90ac3ec0247 100644 --- a/bgpd/bgp_evpn.c +++ b/bgpd/bgp_evpn.c @@ -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 @@ -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. */ diff --git a/bgpd/bgp_evpn_mh.c b/bgpd/bgp_evpn_mh.c index b8b07ee8a3ee..db01b2f15666 100644 --- a/bgpd/bgp_evpn_mh.c +++ b/bgpd/bgp_evpn_mh.c @@ -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); diff --git a/bgpd/bgp_packet.c b/bgpd/bgp_packet.c index f94b64d0bda4..e978fdfb3944 100644 --- a/bgpd/bgp_packet.c +++ b/bgpd/bgp_packet.c @@ -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; diff --git a/bgpd/bgp_route.c b/bgpd/bgp_route.c index bff4df4f1d2e..fb8a12cad217 100644 --- a/bgpd/bgp_route.c +++ b/bgpd/bgp_route.c @@ -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); @@ -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 &&