diff --git a/bgpd/bgp_attr.c b/bgpd/bgp_attr.c index 3e890ca417..e1ee027700 100644 --- a/bgpd/bgp_attr.c +++ b/bgpd/bgp_attr.c @@ -1012,18 +1012,13 @@ struct attr *bgp_attr_aggregate_intern( } bgp_attr_set_community(&attr, community); - attr.flag |= ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES); } - if (ecommunity) { + if (ecommunity) bgp_attr_set_ecommunity(&attr, ecommunity); - attr.flag |= ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES); - } - if (lcommunity) { + if (lcommunity) bgp_attr_set_lcommunity(&attr, lcommunity); - attr.flag |= ATTR_FLAG_BIT(BGP_ATTR_LARGE_COMMUNITIES); - } if (bgp_in_graceful_shutdown(bgp)) bgp_attr_add_gshut_community(&attr); @@ -1100,22 +1095,18 @@ void bgp_attr_unintern_sub(struct attr *attr) comm = bgp_attr_get_community(attr); community_unintern(&comm); - UNSET_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES)); bgp_attr_set_community(attr, NULL); ecomm = bgp_attr_get_ecommunity(attr); ecommunity_unintern(&ecomm); - UNSET_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES)); bgp_attr_set_ecommunity(attr, NULL); ipv6_ecomm = bgp_attr_get_ipv6_ecommunity(attr); ecommunity_unintern(&ipv6_ecomm); - UNSET_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_IPV6_EXT_COMMUNITIES)); bgp_attr_set_ipv6_ecommunity(attr, NULL); lcomm = bgp_attr_get_lcommunity(attr); lcommunity_unintern(&lcomm); - UNSET_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_LARGE_COMMUNITIES)); bgp_attr_set_lcommunity(attr, NULL); cluster = bgp_attr_get_cluster(attr); @@ -1969,8 +1960,6 @@ bgp_attr_community(struct bgp_attr_parser_args *args) return bgp_attr_malformed(args, BGP_NOTIFY_UPDATE_OPT_ATTR_ERR, args->total); - attr->flag |= ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES); - return BGP_ATTR_PARSE_PROCEED; } @@ -2300,8 +2289,6 @@ bgp_attr_large_community(struct bgp_attr_parser_args *args) return bgp_attr_malformed(args, BGP_NOTIFY_UPDATE_OPT_ATTR_ERR, args->total); - attr->flag |= ATTR_FLAG_BIT(BGP_ATTR_LARGE_COMMUNITIES); - return BGP_ATTR_PARSE_PROCEED; } @@ -2338,8 +2325,6 @@ bgp_attr_ext_communities(struct bgp_attr_parser_args *args) return bgp_attr_malformed(args, BGP_NOTIFY_UPDATE_OPT_ATTR_ERR, args->total); - attr->flag |= ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES); - /* Extract DF election preference and mobility sequence number */ attr->df_pref = bgp_attr_df_pref_from_ec(attr, &attr->df_alg); @@ -2409,8 +2394,6 @@ bgp_attr_ipv6_ext_communities(struct bgp_attr_parser_args *args) return bgp_attr_malformed(args, BGP_NOTIFY_UPDATE_OPT_ATTR_ERR, args->total); - attr->flag |= ATTR_FLAG_BIT(BGP_ATTR_IPV6_EXT_COMMUNITIES); - return BGP_ATTR_PARSE_PROCEED; } diff --git a/bgpd/bgp_attr.h b/bgpd/bgp_attr.h index 1837781032..ac5734ede6 100644 --- a/bgpd/bgp_attr.h +++ b/bgpd/bgp_attr.h @@ -516,6 +516,11 @@ static inline void bgp_attr_set_ecommunity(struct attr *attr, struct ecommunity *ecomm) { attr->ecommunity = ecomm; + + if (ecomm) + SET_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES)); + else + UNSET_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES)); } static inline struct lcommunity * @@ -528,6 +533,12 @@ static inline void bgp_attr_set_lcommunity(struct attr *attr, struct lcommunity *lcomm) { attr->lcommunity = lcomm; + + if (lcomm) + SET_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_LARGE_COMMUNITIES)); + else + UNSET_FLAG(attr->flag, + ATTR_FLAG_BIT(BGP_ATTR_LARGE_COMMUNITIES)); } static inline struct community *bgp_attr_get_community(const struct attr *attr) @@ -539,6 +550,11 @@ static inline void bgp_attr_set_community(struct attr *attr, struct community *comm) { attr->community = comm; + + if (comm) + SET_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES)); + else + UNSET_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES)); } static inline struct ecommunity * @@ -551,6 +567,13 @@ static inline void bgp_attr_set_ipv6_ecommunity(struct attr *attr, struct ecommunity *ipv6_ecomm) { attr->ipv6_ecommunity = ipv6_ecomm; + + if (ipv6_ecomm) + SET_FLAG(attr->flag, + ATTR_FLAG_BIT(BGP_ATTR_IPV6_EXT_COMMUNITIES)); + else + UNSET_FLAG(attr->flag, + ATTR_FLAG_BIT(BGP_ATTR_IPV6_EXT_COMMUNITIES)); } static inline struct transit *bgp_attr_get_transit(const struct attr *attr) diff --git a/bgpd/bgp_evpn.c b/bgpd/bgp_evpn.c index 9f3f8389ad..3224c1a2b0 100644 --- a/bgpd/bgp_evpn.c +++ b/bgpd/bgp_evpn.c @@ -759,8 +759,6 @@ static void build_evpn_type5_route_extcomm(struct bgp *bgp_vrf, ecommunity_add_val(bgp_attr_get_ecommunity(attr), &eval_rmac, true, true); } - - attr->flag |= ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES); } /* @@ -870,8 +868,6 @@ static void build_evpn_route_extcomm(struct bgpevpn *vpn, struct attr *attr, attr, ecommunity_merge(bgp_attr_get_ecommunity(attr), &ecom_na)); } - - attr->flag |= ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES); } /* diff --git a/bgpd/bgp_evpn_mh.c b/bgpd/bgp_evpn_mh.c index f6516d220c..d3460674be 100644 --- a/bgpd/bgp_evpn_mh.c +++ b/bgpd/bgp_evpn_mh.c @@ -622,8 +622,6 @@ static void bgp_evpn_type4_route_extcomm_build(struct bgp_evpn_es *es, bgp_attr_set_ecommunity( attr, ecommunity_merge(bgp_attr_get_ecommunity(attr), &ecom_df)); - - attr->flag |= ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES); } /* Create or update local type-4 route */ @@ -904,8 +902,6 @@ bgp_evpn_type1_es_route_extcomm_build(struct bgp_evpn_es_frag *es_frag, ecom)); } } - - attr->flag |= ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES); } /* Extended communities associated with EAD-per-EVI */ @@ -932,8 +928,6 @@ static void bgp_evpn_type1_evi_route_extcomm_build(struct bgp_evpn_es *es, bgp_attr_set_ecommunity( attr, ecommunity_merge(bgp_attr_get_ecommunity(attr), ecom)); - - attr->flag |= ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES); } /* Update EVPN EAD (type-1) route - diff --git a/bgpd/bgp_mpath.c b/bgpd/bgp_mpath.c index 6e695d0301..6cd6ddd9dd 100644 --- a/bgpd/bgp_mpath.c +++ b/bgpd/bgp_mpath.c @@ -905,18 +905,12 @@ void bgp_path_info_mpath_aggregate_update(struct bgp_path_info *new_best, attr.aspath = aspath; attr.origin = origin; - if (community) { + if (community) bgp_attr_set_community(&attr, community); - attr.flag |= ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES); - } - if (ecomm) { + if (ecomm) bgp_attr_set_ecommunity(&attr, ecomm); - attr.flag |= ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES); - } - if (lcomm) { + if (lcomm) bgp_attr_set_lcommunity(&attr, lcomm); - attr.flag |= ATTR_FLAG_BIT(BGP_ATTR_LARGE_COMMUNITIES); - } /* Zap multipath attr nexthop so we set nexthop to self */ attr.nexthop.s_addr = INADDR_ANY; diff --git a/bgpd/bgp_mplsvpn.c b/bgpd/bgp_mplsvpn.c index 5200fe33de..0074d5daac 100644 --- a/bgpd/bgp_mplsvpn.c +++ b/bgpd/bgp_mplsvpn.c @@ -1147,7 +1147,6 @@ void vpn_leak_from_vrf_update(struct bgp *bgp_vpn, /* to */ .rtlist[BGP_VPN_POLICY_DIR_TOVPN]); } bgp_attr_set_ecommunity(&static_attr, new_ecom); - SET_FLAG(static_attr.flag, ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES)); if (debug && bgp_attr_get_ecommunity(&static_attr)) { char *s = ecommunity_ecom2str( @@ -1511,8 +1510,6 @@ vpn_leak_to_vrf_update_onevrf(struct bgp *bgp_vrf, /* to */ bgp_attr_set_ecommunity(&static_attr, new_ecom); if (new_ecom->size == 0) { - UNSET_FLAG(static_attr.flag, - ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES)); ecommunity_free(&new_ecom); bgp_attr_set_ecommunity(&static_attr, NULL); } diff --git a/bgpd/bgp_route.c b/bgpd/bgp_route.c index abf5bd2bdd..abf14778d7 100644 --- a/bgpd/bgp_route.c +++ b/bgpd/bgp_route.c @@ -1769,7 +1769,6 @@ void bgp_attr_add_llgr_community(struct attr *attr) community_free(&llgr); bgp_attr_set_community(attr, new); - attr->flag |= ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES); } void bgp_attr_add_gshut_community(struct attr *attr) @@ -1798,7 +1797,6 @@ void bgp_attr_add_gshut_community(struct attr *attr) community_free(&gshut); bgp_attr_set_community(attr, new); - attr->flag |= ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES); /* When we add the graceful-shutdown community we must also * lower the local-preference */ @@ -3711,7 +3709,6 @@ static void bgp_attr_add_no_export_community(struct attr *attr) community_free(&no_export); bgp_attr_set_community(attr, new); - attr->flag |= ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES); } int bgp_update(struct peer *peer, const struct prefix *p, uint32_t addpath_id, diff --git a/bgpd/bgp_routemap.c b/bgpd/bgp_routemap.c index 2ed73ddb68..6ab753f476 100644 --- a/bgpd/bgp_routemap.c +++ b/bgpd/bgp_routemap.c @@ -2199,7 +2199,6 @@ route_set_community(void *rule, const struct prefix *prefix, void *object) /* "none" case. */ if (rcs->none) { - attr->flag &= ~(ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES)); bgp_attr_set_community(attr, NULL); /* See the longer comment down below. */ if (old && old->refcnt == 0) @@ -2227,8 +2226,6 @@ route_set_community(void *rule, const struct prefix *prefix, void *object) /* will be interned by caller if required */ bgp_attr_set_community(attr, new); - attr->flag |= ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES); - return RMAP_OKAY; } @@ -2313,7 +2310,6 @@ route_set_lcommunity(void *rule, const struct prefix *prefix, void *object) /* "none" case. */ if (rcs->none) { - attr->flag &= ~(ATTR_FLAG_BIT(BGP_ATTR_LARGE_COMMUNITIES)); bgp_attr_set_lcommunity(attr, NULL); /* See the longer comment down below. */ @@ -2341,8 +2337,6 @@ route_set_lcommunity(void *rule, const struct prefix *prefix, void *object) /* will be intern()'d or attr_flush()'d by bgp_update_main() */ bgp_attr_set_lcommunity(attr, new); - attr->flag |= ATTR_FLAG_BIT(BGP_ATTR_LARGE_COMMUNITIES); - return RMAP_OKAY; } @@ -2438,13 +2432,9 @@ route_set_lcommunity_delete(void *rule, const struct prefix *pfx, void *object) if (new->size == 0) { bgp_attr_set_lcommunity(path->attr, NULL); - path->attr->flag &= - ~ATTR_FLAG_BIT(BGP_ATTR_LARGE_COMMUNITIES); lcommunity_free(&new); } else { bgp_attr_set_lcommunity(path->attr, new); - path->attr->flag |= - ATTR_FLAG_BIT(BGP_ATTR_LARGE_COMMUNITIES); } } @@ -2526,12 +2516,9 @@ route_set_community_delete(void *rule, const struct prefix *prefix, if (new->size == 0) { bgp_attr_set_community(path->attr, NULL); - path->attr->flag &= - ~ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES); community_free(&new); } else { bgp_attr_set_community(path->attr, new); - path->attr->flag |= ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES); } } @@ -2597,7 +2584,6 @@ route_set_ecommunity(void *rule, const struct prefix *prefix, void *object) attr = path->attr; if (rcs->none) { - attr->flag &= ~(ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES)); bgp_attr_set_ecommunity(attr, NULL); return RMAP_OKAY; } @@ -2624,8 +2610,6 @@ route_set_ecommunity(void *rule, const struct prefix *prefix, void *object) /* will be intern()'d or attr_flush()'d by bgp_update_main() */ bgp_attr_set_ecommunity(path->attr, new_ecom); - path->attr->flag |= ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES); - return RMAP_OKAY; } @@ -2787,7 +2771,6 @@ route_set_ecommunity_lb(void *rule, const struct prefix *prefix, void *object) /* new_ecom will be intern()'d or attr_flush()'d in call stack */ bgp_attr_set_ecommunity(path->attr, new_ecom); - path->attr->flag |= ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES); /* Mark that route-map has set link bandwidth; used in attribute * setting decisions. diff --git a/bgpd/rfapi/rfapi.c b/bgpd/rfapi/rfapi.c index c96c321d76..3aa8868374 100644 --- a/bgpd/rfapi/rfapi.c +++ b/bgpd/rfapi/rfapi.c @@ -832,9 +832,7 @@ void add_vnc_route(struct rfapi_descriptor *rfd, /* cookie, VPN UN addr, peer */ struct ecommunity *ecomm = bgp_attr_get_ecommunity(&attr); - if (ecomm->size) { - attr.flag |= ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES); - } else { + if (!ecomm->size) { ecommunity_free(&ecomm); bgp_attr_set_ecommunity(&attr, NULL); } diff --git a/bgpd/rfapi/vnc_export_bgp.c b/bgpd/rfapi/vnc_export_bgp.c index f4f2e11391..c479b4d65a 100644 --- a/bgpd/rfapi/vnc_export_bgp.c +++ b/bgpd/rfapi/vnc_export_bgp.c @@ -650,9 +650,6 @@ encap_attr_export(struct attr *new, struct attr *orig, } else { bgp_attr_set_ecommunity(new, ecom_ro); } - if (ecom_ro) { - new->flag |= ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES); - } /* * Set MED