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);
}
if (ecommunity) {
if (ecommunity)
bgp_attr_set_ecommunity(&attr, ecommunity);
attr.flag |= ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES);
}
if (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);
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);
@ -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,
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);
@ -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,
args->total);
attr->flag |= ATTR_FLAG_BIT(BGP_ATTR_IPV6_EXT_COMMUNITIES);
return BGP_ATTR_PARSE_PROCEED;
}

View file

@ -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 *
@ -562,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)

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,
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);
}
/*

View file

@ -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 -

View file

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

View file

@ -2584,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;
}
@ -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() */
bgp_attr_set_ecommunity(path->attr, new_ecom);
path->attr->flag |= ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES);
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 */
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.

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);
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);
}

View file

@ -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