bgpd: Reuse bgp_attr_set_ecommunity() for setting attribute flags

Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
This commit is contained in:
Donatas Abraitis 2022-04-12 11:06:52 +03:00
parent 9d34440bf8
commit 58cf5c088a
9 changed files with 15 additions and 35 deletions

View file

@ -1010,10 +1010,8 @@ struct attr *bgp_attr_aggregate_intern(
bgp_attr_set_community(&attr, community); bgp_attr_set_community(&attr, community);
} }
if (ecommunity) { if (ecommunity)
bgp_attr_set_ecommunity(&attr, 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); bgp_attr_set_lcommunity(&attr, lcommunity);
@ -1097,12 +1095,10 @@ void bgp_attr_unintern_sub(struct attr *attr)
ecomm = bgp_attr_get_ecommunity(attr); ecomm = bgp_attr_get_ecommunity(attr);
ecommunity_unintern(&ecomm); ecommunity_unintern(&ecomm);
UNSET_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES));
bgp_attr_set_ecommunity(attr, NULL); bgp_attr_set_ecommunity(attr, NULL);
ipv6_ecomm = bgp_attr_get_ipv6_ecommunity(attr); ipv6_ecomm = bgp_attr_get_ipv6_ecommunity(attr);
ecommunity_unintern(&ipv6_ecomm); ecommunity_unintern(&ipv6_ecomm);
UNSET_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_IPV6_EXT_COMMUNITIES));
bgp_attr_set_ipv6_ecommunity(attr, NULL); bgp_attr_set_ipv6_ecommunity(attr, NULL);
lcomm = bgp_attr_get_lcommunity(attr); lcomm = bgp_attr_get_lcommunity(attr);
@ -2323,8 +2319,6 @@ bgp_attr_ext_communities(struct bgp_attr_parser_args *args)
return bgp_attr_malformed(args, BGP_NOTIFY_UPDATE_OPT_ATTR_ERR, return bgp_attr_malformed(args, BGP_NOTIFY_UPDATE_OPT_ATTR_ERR,
args->total); args->total);
attr->flag |= ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES);
/* Extract DF election preference and mobility sequence number */ /* Extract DF election preference and mobility sequence number */
attr->df_pref = bgp_attr_df_pref_from_ec(attr, &attr->df_alg); attr->df_pref = bgp_attr_df_pref_from_ec(attr, &attr->df_alg);
@ -2394,8 +2388,6 @@ bgp_attr_ipv6_ext_communities(struct bgp_attr_parser_args *args)
return bgp_attr_malformed(args, BGP_NOTIFY_UPDATE_OPT_ATTR_ERR, return bgp_attr_malformed(args, BGP_NOTIFY_UPDATE_OPT_ATTR_ERR,
args->total); args->total);
attr->flag |= ATTR_FLAG_BIT(BGP_ATTR_IPV6_EXT_COMMUNITIES);
return BGP_ATTR_PARSE_PROCEED; return BGP_ATTR_PARSE_PROCEED;
} }

View file

@ -516,6 +516,11 @@ static inline void bgp_attr_set_ecommunity(struct attr *attr,
struct ecommunity *ecomm) struct ecommunity *ecomm)
{ {
attr->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 * static inline struct lcommunity *
@ -562,6 +567,13 @@ static inline void bgp_attr_set_ipv6_ecommunity(struct attr *attr,
struct ecommunity *ipv6_ecomm) struct ecommunity *ipv6_ecomm)
{ {
attr->ipv6_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) static inline struct transit *bgp_attr_get_transit(const struct attr *attr)

View file

@ -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, ecommunity_add_val(bgp_attr_get_ecommunity(attr), &eval_rmac,
true, true); 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), attr, ecommunity_merge(bgp_attr_get_ecommunity(attr),
&ecom_na)); &ecom_na));
} }
attr->flag |= ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES);
} }
/* /*

View file

@ -622,8 +622,6 @@ static void bgp_evpn_type4_route_extcomm_build(struct bgp_evpn_es *es,
bgp_attr_set_ecommunity( bgp_attr_set_ecommunity(
attr, attr,
ecommunity_merge(bgp_attr_get_ecommunity(attr), &ecom_df)); 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 */ /* 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)); ecom));
} }
} }
attr->flag |= ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES);
} }
/* Extended communities associated with EAD-per-EVI */ /* 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( bgp_attr_set_ecommunity(
attr, attr,
ecommunity_merge(bgp_attr_get_ecommunity(attr), ecom)); ecommunity_merge(bgp_attr_get_ecommunity(attr), ecom));
attr->flag |= ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES);
} }
/* Update EVPN EAD (type-1) route - /* Update EVPN EAD (type-1) route -

View file

@ -908,10 +908,8 @@ void bgp_path_info_mpath_aggregate_update(struct bgp_path_info *new_best,
if (community) { if (community) {
bgp_attr_set_community(&attr, community); bgp_attr_set_community(&attr, community);
} }
if (ecomm) { if (ecomm)
bgp_attr_set_ecommunity(&attr, 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); bgp_attr_set_lcommunity(&attr, lcomm);

View file

@ -1147,7 +1147,6 @@ void vpn_leak_from_vrf_update(struct bgp *bgp_vpn, /* to */
.rtlist[BGP_VPN_POLICY_DIR_TOVPN]); .rtlist[BGP_VPN_POLICY_DIR_TOVPN]);
} }
bgp_attr_set_ecommunity(&static_attr, new_ecom); 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)) { if (debug && bgp_attr_get_ecommunity(&static_attr)) {
char *s = ecommunity_ecom2str( 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); bgp_attr_set_ecommunity(&static_attr, new_ecom);
if (new_ecom->size == 0) { if (new_ecom->size == 0) {
UNSET_FLAG(static_attr.flag,
ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES));
ecommunity_free(&new_ecom); ecommunity_free(&new_ecom);
bgp_attr_set_ecommunity(&static_attr, NULL); bgp_attr_set_ecommunity(&static_attr, NULL);
} }

View file

@ -2584,7 +2584,6 @@ route_set_ecommunity(void *rule, const struct prefix *prefix, void *object)
attr = path->attr; attr = path->attr;
if (rcs->none) { if (rcs->none) {
attr->flag &= ~(ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES));
bgp_attr_set_ecommunity(attr, NULL); bgp_attr_set_ecommunity(attr, NULL);
return RMAP_OKAY; return RMAP_OKAY;
} }
@ -2611,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() */ /* will be intern()'d or attr_flush()'d by bgp_update_main() */
bgp_attr_set_ecommunity(path->attr, new_ecom); bgp_attr_set_ecommunity(path->attr, new_ecom);
path->attr->flag |= ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES);
return RMAP_OKAY; return RMAP_OKAY;
} }
@ -2774,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 */ /* new_ecom will be intern()'d or attr_flush()'d in call stack */
bgp_attr_set_ecommunity(path->attr, new_ecom); 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 /* Mark that route-map has set link bandwidth; used in attribute
* setting decisions. * setting decisions.

View file

@ -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); struct ecommunity *ecomm = bgp_attr_get_ecommunity(&attr);
if (ecomm->size) { if (!ecomm->size) {
attr.flag |= ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES);
} else {
ecommunity_free(&ecomm); ecommunity_free(&ecomm);
bgp_attr_set_ecommunity(&attr, NULL); bgp_attr_set_ecommunity(&attr, NULL);
} }

View file

@ -650,9 +650,6 @@ encap_attr_export(struct attr *new, struct attr *orig,
} else { } else {
bgp_attr_set_ecommunity(new, ecom_ro); bgp_attr_set_ecommunity(new, ecom_ro);
} }
if (ecom_ro) {
new->flag |= ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES);
}
/* /*
* Set MED * Set MED