From 2a3f51cf6ba298ab42b7b51a2d879b46baa2ee31 Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Mon, 2 Nov 2020 10:52:40 -0500 Subject: [PATCH] bgpd: Add accessor for bgp_attr.pmsi_tnl_type Add an accessor for the bgp_attr.pmsi_tnl_type to allow us to abstract where it is. Every attribute is paying the price of this bit of data as part of `struct bgp_attr` In the future we'll move it elsewhere. Signed-off-by: Donald Sharp --- bgpd/bgp_attr.c | 4 ++-- bgpd/bgp_attr.h | 12 ++++++++++++ bgpd/bgp_debug.c | 2 +- bgpd/bgp_evpn.c | 18 ++++++++++-------- bgpd/bgp_route.c | 6 +++--- 5 files changed, 28 insertions(+), 14 deletions(-) diff --git a/bgpd/bgp_attr.c b/bgpd/bgp_attr.c index a804968605..ab1173ba8d 100644 --- a/bgpd/bgp_attr.c +++ b/bgpd/bgp_attr.c @@ -2785,7 +2785,7 @@ bgp_attr_pmsi_tunnel(struct bgp_attr_parser_args *args) } attr->flag |= ATTR_FLAG_BIT(BGP_ATTR_PMSI_TUNNEL); - attr->pmsi_tnl_type = tnl_type; + bgp_attr_set_pmsi_tnl_type(attr, tnl_type); stream_get(&attr->label, peer->curr, BGP_LABEL_BYTES); /* Forward read pointer of input stream. */ @@ -4110,7 +4110,7 @@ bgp_size_t bgp_packet_attribute(struct bgp *bgp, struct peer *peer, stream_putc(s, BGP_ATTR_PMSI_TUNNEL); stream_putc(s, 9); // Length stream_putc(s, 0); // Flags - stream_putc(s, attr->pmsi_tnl_type); + stream_putc(s, bgp_attr_get_pmsi_tnl_type(attr)); stream_put(s, &(attr->label), BGP_LABEL_BYTES); // MPLS Label / VXLAN VNI stream_put_ipv4(s, attr->nexthop.s_addr); diff --git a/bgpd/bgp_attr.h b/bgpd/bgp_attr.h index ef0e74344a..6ce5d18942 100644 --- a/bgpd/bgp_attr.h +++ b/bgpd/bgp_attr.h @@ -457,4 +457,16 @@ static inline uint32_t mac_mobility_seqnum(struct attr *attr) { return (attr) ? attr->mm_seqnum : 0; } + +static inline enum pta_type bgp_attr_get_pmsi_tnl_type(struct attr *attr) +{ + return attr->pmsi_tnl_type; +} + +static inline void bgp_attr_set_pmsi_tnl_type(struct attr *attr, + enum pta_type pmsi_tnl_type) +{ + attr->pmsi_tnl_type = pmsi_tnl_type; +} + #endif /* _QUAGGA_BGP_ATTR_H */ diff --git a/bgpd/bgp_debug.c b/bgpd/bgp_debug.c index c2c2d17a24..811634e8e0 100644 --- a/bgpd/bgp_debug.c +++ b/bgpd/bgp_debug.c @@ -440,7 +440,7 @@ bool bgp_dump_attr(struct attr *attr, char *buf, size_t size) if (CHECK_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_PMSI_TUNNEL))) snprintf(buf + strlen(buf), size - strlen(buf), - ", pmsi tnltype %u", attr->pmsi_tnl_type); + ", pmsi tnltype %u", bgp_attr_get_pmsi_tnl_type(attr)); if (CHECK_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_AS_PATH))) snprintf(buf + strlen(buf), size - strlen(buf), ", path %s", diff --git a/bgpd/bgp_evpn.c b/bgpd/bgp_evpn.c index 67d0a95cb6..21eb371ec6 100644 --- a/bgpd/bgp_evpn.c +++ b/bgpd/bgp_evpn.c @@ -980,7 +980,7 @@ static int evpn_zebra_install(struct bgp *bgp, struct bgpevpn *vpn, } else if (p->prefix.route_type == BGP_EVPN_AD_ROUTE) { ret = bgp_evpn_remote_es_evi_add(bgp, vpn, p); } else { - switch (pi->attr->pmsi_tnl_type) { + switch (bgp_attr_get_pmsi_tnl_type(pi->attr)) { case PMSI_TNLTYPE_INGR_REPL: flood_control = VXLAN_FLOOD_HEAD_END_REPL; break; @@ -1711,7 +1711,7 @@ static int update_evpn_route(struct bgp *bgp, struct bgpevpn *vpn, /* PMSI is only needed for type-3 routes */ if (p->prefix.route_type == BGP_EVPN_IMET_ROUTE) { attr.flag |= ATTR_FLAG_BIT(BGP_ATTR_PMSI_TUNNEL); - attr.pmsi_tnl_type = PMSI_TNLTYPE_INGR_REPL; + bgp_attr_set_pmsi_tnl_type(&attr, PMSI_TNLTYPE_INGR_REPL); } if (bgp_debug_zebra(NULL)) { @@ -3738,12 +3738,14 @@ static int process_type3_route(struct peer *peer, afi_t afi, safi_t safi, */ if (attr && (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_PMSI_TUNNEL))) { - if (attr->pmsi_tnl_type != PMSI_TNLTYPE_INGR_REPL && - attr->pmsi_tnl_type != PMSI_TNLTYPE_PIM_SM) { - flog_warn(EC_BGP_EVPN_PMSI_PRESENT, - "%u:%s - Rx EVPN Type-3 NLRI with unsupported PTA %d", - peer->bgp->vrf_id, peer->host, - attr->pmsi_tnl_type); + enum pta_type pmsi_tnl_type = bgp_attr_get_pmsi_tnl_type(attr); + + if (pmsi_tnl_type != PMSI_TNLTYPE_INGR_REPL + && pmsi_tnl_type != PMSI_TNLTYPE_PIM_SM) { + flog_warn( + EC_BGP_EVPN_PMSI_PRESENT, + "%u:%s - Rx EVPN Type-3 NLRI with unsupported PTA %d", + peer->bgp->vrf_id, peer->host, pmsi_tnl_type); } } diff --git a/bgpd/bgp_route.c b/bgpd/bgp_route.c index 9873057fa2..82989b6764 100644 --- a/bgpd/bgp_route.c +++ b/bgpd/bgp_route.c @@ -10221,9 +10221,9 @@ void route_vty_out_detail(struct vty *vty, struct bgp *bgp, /* Line 10 display PMSI tunnel attribute, if present */ if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_PMSI_TUNNEL)) { - const char *str = - lookup_msg(bgp_pmsi_tnltype_str, attr->pmsi_tnl_type, - PMSI_TNLTYPE_STR_DEFAULT); + const char *str = lookup_msg(bgp_pmsi_tnltype_str, + bgp_attr_get_pmsi_tnl_type(attr), + PMSI_TNLTYPE_STR_DEFAULT); if (json_paths) { json_pmsi = json_object_new_object(); -- 2.39.5