bgpd: Use bgp_attr_[sg]et_ecommunity for struct ecommunity

This is an extra work before moving attr->ecommunity to attra_extra struct.

Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
This commit is contained in:
Donatas Abraitis 2022-02-04 15:56:20 +02:00
parent a89a78236c
commit b53e67a389
19 changed files with 288 additions and 211 deletions

View file

@ -684,8 +684,8 @@ unsigned int attrhash_key_make(const void *p)
if (attr->lcommunity)
MIX(lcommunity_hash_make(attr->lcommunity));
if (attr->ecommunity)
MIX(ecommunity_hash_make(attr->ecommunity));
if (bgp_attr_get_ecommunity(attr))
MIX(ecommunity_hash_make(bgp_attr_get_ecommunity(attr)));
if (bgp_attr_get_ipv6_ecommunity(attr))
MIX(ecommunity_hash_make(bgp_attr_get_ipv6_ecommunity(attr)));
if (bgp_attr_get_cluster(attr))
@ -733,7 +733,8 @@ bool attrhash_cmp(const void *p1, const void *p2)
&& attr1->tag == attr2->tag
&& attr1->label_index == attr2->label_index
&& attr1->mp_nexthop_len == attr2->mp_nexthop_len
&& attr1->ecommunity == attr2->ecommunity
&& bgp_attr_get_ecommunity(attr1)
== bgp_attr_get_ecommunity(attr2)
&& bgp_attr_get_ipv6_ecommunity(attr1)
== bgp_attr_get_ipv6_ecommunity(attr2)
&& attr1->lcommunity == attr2->lcommunity
@ -850,7 +851,8 @@ static void *bgp_attr_hash_alloc(void *p)
struct attr *bgp_attr_intern(struct attr *attr)
{
struct attr *find;
struct ecommunity *ecomm;
struct ecommunity *ecomm = NULL;
struct ecommunity *ipv6_ecomm = NULL;
/* Intern referenced strucutre. */
if (attr->aspath) {
@ -866,22 +868,23 @@ struct attr *bgp_attr_intern(struct attr *attr)
attr->community->refcnt++;
}
if (attr->ecommunity) {
if (!attr->ecommunity->refcnt)
attr->ecommunity = ecommunity_intern(attr->ecommunity);
else
attr->ecommunity->refcnt++;
}
ecomm = bgp_attr_get_ipv6_ecommunity(attr);
ecomm = bgp_attr_get_ecommunity(attr);
if (ecomm) {
if (!ecomm->refcnt)
bgp_attr_set_ipv6_ecommunity(attr,
ecommunity_intern(ecomm));
bgp_attr_set_ecommunity(attr, ecommunity_intern(ecomm));
else
ecomm->refcnt++;
}
ipv6_ecomm = bgp_attr_get_ipv6_ecommunity(attr);
if (ipv6_ecomm) {
if (!ipv6_ecomm->refcnt)
bgp_attr_set_ipv6_ecommunity(
attr, ecommunity_intern(ipv6_ecomm));
else
ipv6_ecomm->refcnt++;
}
if (attr->lcommunity) {
if (!attr->lcommunity->refcnt)
attr->lcommunity = lcommunity_intern(attr->lcommunity);
@ -1013,7 +1016,7 @@ struct attr *bgp_attr_aggregate_intern(
}
if (ecommunity) {
attr.ecommunity = ecommunity;
bgp_attr_set_ecommunity(&attr, ecommunity);
attr.flag |= ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES);
}
@ -1085,7 +1088,8 @@ struct attr *bgp_attr_aggregate_intern(
/* Unintern just the sub-components of the attr, but not the attr */
void bgp_attr_unintern_sub(struct attr *attr)
{
struct ecommunity *ecomm;
struct ecommunity *ecomm = NULL;
struct ecommunity *ipv6_ecomm = NULL;
struct cluster_list *cluster;
/* aspath refcount shoud be decrement. */
@ -1097,11 +1101,13 @@ void bgp_attr_unintern_sub(struct attr *attr)
community_unintern(&attr->community);
UNSET_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES));
ecommunity_unintern(&attr->ecommunity);
UNSET_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES));
ecomm = bgp_attr_get_ipv6_ecommunity(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);
@ -1155,14 +1161,16 @@ void bgp_attr_unintern_sub(struct attr *attr)
*/
void bgp_attr_undup(struct attr *new, struct attr *old)
{
struct ecommunity *ecomm = bgp_attr_get_ecommunity(new);
if (new->aspath != old->aspath)
aspath_free(new->aspath);
if (new->community != old->community)
community_free(&new->community);
if (new->ecommunity != old->ecommunity)
ecommunity_free(&new->ecommunity);
if (ecomm != bgp_attr_get_ecommunity(old))
ecommunity_free(&ecomm);
if (new->lcommunity != old->lcommunity)
lcommunity_free(&new->lcommunity);
@ -1205,6 +1213,7 @@ void bgp_attr_unintern(struct attr **pattr)
void bgp_attr_flush(struct attr *attr)
{
struct ecommunity *ecomm;
struct ecommunity *ipv6_ecomm;
struct cluster_list *cluster;
if (attr->aspath && !attr->aspath->refcnt) {
@ -1213,11 +1222,13 @@ void bgp_attr_flush(struct attr *attr)
}
if (attr->community && !attr->community->refcnt)
community_free(&attr->community);
if (attr->ecommunity && !attr->ecommunity->refcnt)
ecommunity_free(&attr->ecommunity);
ecomm = bgp_attr_get_ipv6_ecommunity(attr);
ecomm = bgp_attr_get_ecommunity(attr);
if (ecomm && !ecomm->refcnt)
ecommunity_free(&ecomm);
bgp_attr_set_ecommunity(attr, NULL);
ipv6_ecomm = bgp_attr_get_ipv6_ecommunity(attr);
if (ipv6_ecomm && !ipv6_ecomm->refcnt)
ecommunity_free(&ipv6_ecomm);
bgp_attr_set_ipv6_ecommunity(attr, NULL);
if (attr->lcommunity && !attr->lcommunity->refcnt)
lcommunity_free(&attr->lcommunity);
@ -2325,25 +2336,27 @@ bgp_attr_ext_communities(struct bgp_attr_parser_args *args)
const bgp_size_t length = args->length;
uint8_t sticky = 0;
bool proxy = false;
struct ecommunity *ecomm;
if (length == 0) {
attr->ecommunity = NULL;
bgp_attr_set_ecommunity(attr, NULL);
/* Empty extcomm doesn't seem to be invalid per se */
return bgp_attr_malformed(args, BGP_NOTIFY_UPDATE_OPT_ATTR_ERR,
args->total);
}
attr->ecommunity = ecommunity_parse(
ecomm = ecommunity_parse(
stream_pnt(peer->curr), length,
CHECK_FLAG(peer->flags,
PEER_FLAG_DISABLE_LINK_BW_ENCODING_IEEE));
bgp_attr_set_ecommunity(attr, ecomm);
/* XXX: fix ecommunity_parse to use stream API */
stream_forward_getp(peer->curr, length);
/* The Extended Community attribute SHALL be considered malformed if
* its length is not a non-zero multiple of 8.
*/
if (!attr->ecommunity)
if (!bgp_attr_get_ecommunity(attr))
return bgp_attr_malformed(args, BGP_NOTIFY_UPDATE_OPT_ATTR_ERR,
args->total);
@ -2384,7 +2397,8 @@ bgp_attr_ext_communities(struct bgp_attr_parser_args *args)
(bgp_encap_types *)&attr->encap_tunneltype);
/* Extract link bandwidth, if any. */
(void)ecommunity_linkbw_present(attr->ecommunity, &attr->link_bw);
(void)ecommunity_linkbw_present(bgp_attr_get_ecommunity(attr),
&attr->link_bw);
return BGP_ATTR_PARSE_PROCEED;
}
@ -3584,7 +3598,7 @@ void bgp_attr_extcom_tunnel_type(struct attr *attr,
if (!attr)
return;
ecom = attr->ecommunity;
ecom = bgp_attr_get_ecommunity(attr);
if (!ecom || !ecom->size)
return;
@ -4185,32 +4199,33 @@ bgp_size_t bgp_packet_attribute(struct bgp *bgp, struct peer *peer,
/* Extended Communities attribute. */
if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_SEND_EXT_COMMUNITY)
&& (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES))) {
struct ecommunity *ecomm = bgp_attr_get_ecommunity(attr);
if (peer->sort == BGP_PEER_IBGP
|| peer->sort == BGP_PEER_CONFED) {
if (attr->ecommunity->size * 8 > 255) {
if (ecomm->size * 8 > 255) {
stream_putc(s,
BGP_ATTR_FLAG_OPTIONAL
| BGP_ATTR_FLAG_TRANS
| BGP_ATTR_FLAG_EXTLEN);
stream_putc(s, BGP_ATTR_EXT_COMMUNITIES);
stream_putw(s, attr->ecommunity->size * 8);
stream_putw(s, ecomm->size * 8);
} else {
stream_putc(s,
BGP_ATTR_FLAG_OPTIONAL
| BGP_ATTR_FLAG_TRANS);
stream_putc(s, BGP_ATTR_EXT_COMMUNITIES);
stream_putc(s, attr->ecommunity->size * 8);
stream_putc(s, ecomm->size * 8);
}
stream_put(s, attr->ecommunity->val,
attr->ecommunity->size * 8);
stream_put(s, ecomm->val, ecomm->size * 8);
} else {
uint8_t *pnt;
int tbit;
int ecom_tr_size = 0;
uint32_t i;
for (i = 0; i < attr->ecommunity->size; i++) {
pnt = attr->ecommunity->val + (i * 8);
for (i = 0; i < ecomm->size; i++) {
pnt = ecomm->val + (i * 8);
tbit = *pnt;
if (CHECK_FLAG(tbit,
@ -4240,8 +4255,8 @@ bgp_size_t bgp_packet_attribute(struct bgp *bgp, struct peer *peer,
stream_putc(s, ecom_tr_size * 8);
}
for (i = 0; i < attr->ecommunity->size; i++) {
pnt = attr->ecommunity->val + (i * 8);
for (i = 0; i < ecomm->size; i++) {
pnt = ecomm->val + (i * 8);
tbit = *pnt;
if (CHECK_FLAG(

View file

@ -514,6 +514,18 @@ static inline void bgp_attr_set_pmsi_tnl_type(struct attr *attr,
attr->pmsi_tnl_type = pmsi_tnl_type;
}
static inline struct ecommunity *
bgp_attr_get_ecommunity(const struct attr *attr)
{
return attr->ecommunity;
}
static inline void bgp_attr_set_ecommunity(struct attr *attr,
struct ecommunity *ecomm)
{
attr->ecommunity = ecomm;
}
static inline struct ecommunity *
bgp_attr_get_ipv6_ecommunity(const struct attr *attr)
{

View file

@ -47,15 +47,16 @@ bool bgp_route_evpn_same(const struct bgp_route_evpn *e1,
void bgp_add_routermac_ecom(struct attr *attr, struct ethaddr *routermac)
{
struct ecommunity_val routermac_ecom;
struct ecommunity *ecomm = bgp_attr_get_ecommunity(attr);
memset(&routermac_ecom, 0, sizeof(struct ecommunity_val));
routermac_ecom.val[0] = ECOMMUNITY_ENCODE_EVPN;
routermac_ecom.val[1] = ECOMMUNITY_EVPN_SUBTYPE_ROUTERMAC;
memcpy(&routermac_ecom.val[2], routermac->octet, ETH_ALEN);
if (!attr->ecommunity)
attr->ecommunity = ecommunity_new();
ecommunity_add_val(attr->ecommunity, &routermac_ecom, false, false);
ecommunity_str(attr->ecommunity);
if (!ecomm)
bgp_attr_set_ecommunity(attr, ecommunity_new());
ecommunity_add_val(ecomm, &routermac_ecom, false, false);
ecommunity_str(ecomm);
}
/* converts to an esi
@ -100,7 +101,7 @@ bool bgp_attr_rmac(struct attr *attr, struct ethaddr *rmac)
uint32_t i = 0;
struct ecommunity *ecom;
ecom = attr->ecommunity;
ecom = bgp_attr_get_ecommunity(attr);
if (!ecom || !ecom->size)
return false;
@ -132,7 +133,7 @@ uint8_t bgp_attr_default_gw(struct attr *attr)
struct ecommunity *ecom;
uint32_t i;
ecom = attr->ecommunity;
ecom = bgp_attr_get_ecommunity(attr);
if (!ecom || !ecom->size)
return 0;
@ -165,7 +166,7 @@ uint16_t bgp_attr_df_pref_from_ec(struct attr *attr, uint8_t *alg)
uint16_t df_pref = 0;
*alg = EVPN_MH_DF_ALG_SERVICE_CARVING;
ecom = attr->ecommunity;
ecom = bgp_attr_get_ecommunity(attr);
if (!ecom || !ecom->size)
return 0;
@ -201,7 +202,7 @@ uint32_t bgp_attr_mac_mobility_seqnum(struct attr *attr, uint8_t *sticky)
uint32_t i;
uint8_t flags = 0;
ecom = attr->ecommunity;
ecom = bgp_attr_get_ecommunity(attr);
if (!ecom || !ecom->size)
return 0;
@ -248,7 +249,7 @@ void bgp_attr_evpn_na_flag(struct attr *attr,
uint32_t i;
uint8_t val;
ecom = attr->ecommunity;
ecom = bgp_attr_get_ecommunity(attr);
if (!ecom || !ecom->size)
return;

View file

@ -420,7 +420,8 @@ bool bgp_dump_attr(struct attr *attr, char *buf, size_t size)
if (CHECK_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES)))
snprintf(buf + strlen(buf), size - strlen(buf),
", extcommunity %s", ecommunity_str(attr->ecommunity));
", extcommunity %s",
ecommunity_str(bgp_attr_get_ecommunity(attr)));
if (CHECK_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE)))
snprintf(buf + strlen(buf), size - strlen(buf),

View file

@ -736,26 +736,28 @@ static void build_evpn_type5_route_extcomm(struct bgp *bgp_vrf,
ecom_encap.val = (uint8_t *)eval.val;
/* Add Encap */
if (attr->ecommunity) {
old_ecom = attr->ecommunity;
if (bgp_attr_get_ecommunity(attr)) {
old_ecom = bgp_attr_get_ecommunity(attr);
ecom = ecommunity_merge(ecommunity_dup(old_ecom), &ecom_encap);
if (!old_ecom->refcnt)
ecommunity_free(&old_ecom);
} else
ecom = ecommunity_dup(&ecom_encap);
attr->ecommunity = ecom;
bgp_attr_set_ecommunity(attr, ecom);
attr->encap_tunneltype = tnl_type;
/* Add the export RTs for L3VNI/VRF */
vrf_export_rtl = bgp_vrf->vrf_export_rtl;
for (ALL_LIST_ELEMENTS(vrf_export_rtl, node, nnode, ecom))
attr->ecommunity =
ecommunity_merge(attr->ecommunity, ecom);
bgp_attr_set_ecommunity(
attr,
ecommunity_merge(bgp_attr_get_ecommunity(attr), ecom));
/* add the router mac extended community */
if (!is_zero_mac(&attr->rmac)) {
encode_rmac_extcomm(&eval_rmac, &attr->rmac);
ecommunity_add_val(attr->ecommunity, &eval_rmac, true, true);
ecommunity_add_val(bgp_attr_get_ecommunity(attr), &eval_rmac,
true, true);
}
attr->flag |= ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES);
@ -800,12 +802,14 @@ static void build_evpn_route_extcomm(struct bgpevpn *vpn, struct attr *attr,
ecom_encap.val = (uint8_t *)eval.val;
/* Add Encap */
attr->ecommunity = ecommunity_dup(&ecom_encap);
bgp_attr_set_ecommunity(attr, ecommunity_dup(&ecom_encap));
attr->encap_tunneltype = tnl_type;
/* Add the export RTs for L2VNI */
for (ALL_LIST_ELEMENTS(vpn->export_rtl, node, nnode, ecom))
attr->ecommunity = ecommunity_merge(attr->ecommunity, ecom);
bgp_attr_set_ecommunity(
attr,
ecommunity_merge(bgp_attr_get_ecommunity(attr), ecom));
/* Add the export RTs for L3VNI if told to - caller determines
* when this should be done.
@ -815,8 +819,11 @@ static void build_evpn_route_extcomm(struct bgpevpn *vpn, struct attr *attr,
if (vrf_export_rtl && !list_isempty(vrf_export_rtl)) {
for (ALL_LIST_ELEMENTS(vrf_export_rtl, node, nnode,
ecom))
attr->ecommunity = ecommunity_merge(
attr->ecommunity, ecom);
bgp_attr_set_ecommunity(
attr,
ecommunity_merge(
bgp_attr_get_ecommunity(attr),
ecom));
}
}
@ -828,14 +835,16 @@ static void build_evpn_route_extcomm(struct bgpevpn *vpn, struct attr *attr,
ecom_sticky.size = 1;
ecom_sticky.unit_size = ECOMMUNITY_SIZE;
ecom_sticky.val = (uint8_t *)eval_sticky.val;
attr->ecommunity =
ecommunity_merge(attr->ecommunity, &ecom_sticky);
bgp_attr_set_ecommunity(
attr, ecommunity_merge(bgp_attr_get_ecommunity(attr),
&ecom_sticky));
}
/* Add RMAC, if told to. */
if (add_l3_ecomm) {
encode_rmac_extcomm(&eval_rmac, &attr->rmac);
ecommunity_add_val(attr->ecommunity, &eval_rmac, true, true);
ecommunity_add_val(bgp_attr_get_ecommunity(attr), &eval_rmac,
true, true);
}
/* Add default gateway, if needed. */
@ -845,8 +854,9 @@ static void build_evpn_route_extcomm(struct bgpevpn *vpn, struct attr *attr,
ecom_default_gw.size = 1;
ecom_default_gw.unit_size = ECOMMUNITY_SIZE;
ecom_default_gw.val = (uint8_t *)eval_default_gw.val;
attr->ecommunity =
ecommunity_merge(attr->ecommunity, &ecom_default_gw);
bgp_attr_set_ecommunity(
attr, ecommunity_merge(bgp_attr_get_ecommunity(attr),
&ecom_default_gw));
}
proxy = !!(attr->es_flags & ATTR_ES_PROXY_ADVERT);
@ -856,8 +866,9 @@ static void build_evpn_route_extcomm(struct bgpevpn *vpn, struct attr *attr,
ecom_na.size = 1;
ecom_na.unit_size = ECOMMUNITY_SIZE;
ecom_na.val = (uint8_t *)eval_na.val;
attr->ecommunity = ecommunity_merge(attr->ecommunity,
&ecom_na);
bgp_attr_set_ecommunity(
attr, ecommunity_merge(bgp_attr_get_ecommunity(attr),
&ecom_na));
}
attr->flag |= ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES);
@ -875,6 +886,7 @@ static void add_mac_mobility_to_attr(uint32_t seq_num, struct attr *attr)
uint8_t *pnt;
int type = 0;
int sub_type = 0;
struct ecommunity *ecomm = bgp_attr_get_ecommunity(attr);
/* Build MM */
encode_mac_mobility_extcomm(0, seq_num, &eval);
@ -882,10 +894,9 @@ static void add_mac_mobility_to_attr(uint32_t seq_num, struct attr *attr)
/* Find current MM ecommunity */
ecom_val_ptr = NULL;
if (attr->ecommunity) {
for (i = 0; i < attr->ecommunity->size; i++) {
pnt = attr->ecommunity->val +
(i * attr->ecommunity->unit_size);
if (ecomm) {
for (i = 0; i < ecomm->size; i++) {
pnt = ecomm->val + (i * ecomm->unit_size);
type = *pnt++;
sub_type = *pnt++;
@ -893,8 +904,7 @@ static void add_mac_mobility_to_attr(uint32_t seq_num, struct attr *attr)
&& sub_type
== ECOMMUNITY_EVPN_SUBTYPE_MACMOBILITY) {
ecom_val_ptr =
(attr->ecommunity->val +
(i * attr->ecommunity->unit_size));
(ecomm->val + (i * ecomm->unit_size));
break;
}
}
@ -902,8 +912,7 @@ static void add_mac_mobility_to_attr(uint32_t seq_num, struct attr *attr)
/* Update the existing MM ecommunity */
if (ecom_val_ptr) {
memcpy(ecom_val_ptr, eval.val, sizeof(char)
* attr->ecommunity->unit_size);
memcpy(ecom_val_ptr, eval.val, sizeof(char) * ecomm->unit_size);
}
/* Add MM to existing */
else {
@ -912,11 +921,12 @@ static void add_mac_mobility_to_attr(uint32_t seq_num, struct attr *attr)
ecom_tmp.unit_size = ECOMMUNITY_SIZE;
ecom_tmp.val = (uint8_t *)eval.val;
if (attr->ecommunity)
attr->ecommunity =
ecommunity_merge(attr->ecommunity, &ecom_tmp);
if (ecomm)
bgp_attr_set_ecommunity(
attr, ecommunity_merge(ecomm, &ecom_tmp));
else
attr->ecommunity = ecommunity_dup(&ecom_tmp);
bgp_attr_set_ecommunity(attr,
ecommunity_dup(&ecom_tmp));
}
}
@ -2823,7 +2833,7 @@ static int is_route_matching_for_vrf(struct bgp *bgp_vrf,
if (!(attr->flag & ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES)))
return 0;
ecom = attr->ecommunity;
ecom = bgp_attr_get_ecommunity(attr);
if (!ecom || !ecom->size)
return 0;
@ -2890,7 +2900,7 @@ static int is_route_matching_for_vni(struct bgp *bgp, struct bgpevpn *vpn,
if (!(attr->flag & ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES)))
return 0;
ecom = attr->ecommunity;
ecom = bgp_attr_get_ecommunity(attr);
if (!ecom || !ecom->size)
return 0;
@ -3374,7 +3384,7 @@ static int bgp_evpn_install_uninstall_table(struct bgp *bgp, afi_t afi,
if (evp->prefix.route_type == BGP_EVPN_AD_ROUTE)
evp = evpn_type1_prefix_vni_copy(&ad_evp, evp, attr->nexthop);
ecom = attr->ecommunity;
ecom = bgp_attr_get_ecommunity(attr);
if (!ecom || !ecom->size)
return -1;

View file

@ -598,7 +598,7 @@ static void bgp_evpn_type4_route_extcomm_build(struct bgp_evpn_es *es,
ecom_encap.size = 1;
ecom_encap.unit_size = ECOMMUNITY_SIZE;
ecom_encap.val = (uint8_t *)eval.val;
attr->ecommunity = ecommunity_dup(&ecom_encap);
bgp_attr_set_ecommunity(attr, ecommunity_dup(&ecom_encap));
/* ES import RT */
memset(&mac, 0, sizeof(struct ethaddr));
@ -608,15 +608,18 @@ static void bgp_evpn_type4_route_extcomm_build(struct bgp_evpn_es *es,
ecom_es_rt.size = 1;
ecom_es_rt.unit_size = ECOMMUNITY_SIZE;
ecom_es_rt.val = (uint8_t *)eval_es_rt.val;
attr->ecommunity =
ecommunity_merge(attr->ecommunity, &ecom_es_rt);
bgp_attr_set_ecommunity(
attr,
ecommunity_merge(bgp_attr_get_ecommunity(attr), &ecom_es_rt));
/* DF election extended community */
memset(&ecom_df, 0, sizeof(ecom_df));
encode_df_elect_extcomm(&eval_df, es->df_pref);
ecom_df.size = 1;
ecom_df.val = (uint8_t *)eval_df.val;
attr->ecommunity = ecommunity_merge(attr->ecommunity, &ecom_df);
bgp_attr_set_ecommunity(
attr,
ecommunity_merge(bgp_attr_get_ecommunity(attr), &ecom_df));
attr->flag |= ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES);
}
@ -861,7 +864,7 @@ static void bgp_evpn_type1_es_route_extcomm_build(struct bgp_evpn_es *es,
ecom_encap.size = 1;
ecom_encap.unit_size = ECOMMUNITY_SIZE;
ecom_encap.val = (uint8_t *)eval.val;
attr->ecommunity = ecommunity_dup(&ecom_encap);
bgp_attr_set_ecommunity(attr, ecommunity_dup(&ecom_encap));
/* ESI label */
encode_esi_label_extcomm(&eval_esi_label,
@ -869,8 +872,9 @@ static void bgp_evpn_type1_es_route_extcomm_build(struct bgp_evpn_es *es,
ecom_esi_label.size = 1;
ecom_esi_label.unit_size = ECOMMUNITY_SIZE;
ecom_esi_label.val = (uint8_t *)eval_esi_label.val;
attr->ecommunity =
ecommunity_merge(attr->ecommunity, &ecom_esi_label);
bgp_attr_set_ecommunity(attr,
ecommunity_merge(bgp_attr_get_ecommunity(attr),
&ecom_esi_label));
/* Add export RTs for all L2-VNIs associated with this ES */
/* XXX - suppress EAD-ES advertisment if there are no EVIs associated
@ -882,8 +886,10 @@ static void bgp_evpn_type1_es_route_extcomm_build(struct bgp_evpn_es *es,
continue;
for (ALL_LIST_ELEMENTS_RO(es_evi->vpn->export_rtl,
rt_node, ecom))
attr->ecommunity = ecommunity_merge(attr->ecommunity,
ecom);
bgp_attr_set_ecommunity(
attr,
ecommunity_merge(bgp_attr_get_ecommunity(attr),
ecom));
}
attr->flag |= ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES);
@ -906,11 +912,13 @@ static void bgp_evpn_type1_evi_route_extcomm_build(struct bgp_evpn_es *es,
ecom_encap.size = 1;
ecom_encap.unit_size = ECOMMUNITY_SIZE;
ecom_encap.val = (uint8_t *)eval.val;
attr->ecommunity = ecommunity_dup(&ecom_encap);
bgp_attr_set_ecommunity(attr, ecommunity_dup(&ecom_encap));
/* Add export RTs for the L2-VNI */
for (ALL_LIST_ELEMENTS_RO(vpn->export_rtl, rt_node, ecom))
attr->ecommunity = ecommunity_merge(attr->ecommunity, ecom);
bgp_attr_set_ecommunity(
attr,
ecommunity_merge(bgp_attr_get_ecommunity(attr), ecom));
attr->flag |= ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES);
}

View file

@ -170,9 +170,10 @@ int bgp_nlri_parse_flowspec(struct peer *peer, struct attr *attr,
afi);
snprintf(ec_string, sizeof(ec_string),
"EC{none}");
if (attr && attr->ecommunity) {
s = ecommunity_ecom2str(attr->ecommunity,
ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
if (attr && bgp_attr_get_ecommunity(attr)) {
s = ecommunity_ecom2str(
bgp_attr_get_ecommunity(attr),
ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
snprintf(ec_string, sizeof(ec_string),
"EC{%s}",
s == NULL ? "none" : s);

View file

@ -303,12 +303,13 @@ void route_vty_out_flowspec(struct vty *vty, const struct prefix *p,
if (path->attr)
ipv6_ecomm = bgp_attr_get_ipv6_ecommunity(path->attr);
if (path->attr && (path->attr->ecommunity || ipv6_ecomm)) {
if (path->attr && (bgp_attr_get_ecommunity(path->attr) || ipv6_ecomm)) {
/* Print attribute */
attr = path->attr;
if (attr->ecommunity)
s1 = ecommunity_ecom2str(attr->ecommunity,
ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
if (bgp_attr_get_ecommunity(attr))
s1 = ecommunity_ecom2str(bgp_attr_get_ecommunity(attr),
ECOMMUNITY_FORMAT_ROUTE_MAP,
0);
if (ipv6_ecomm)
s2 = ecommunity_ecom2str(
ipv6_ecomm, ECOMMUNITY_FORMAT_ROUTE_MAP, 0);

View file

@ -624,7 +624,8 @@ void bgp_path_info_mpath_update(struct bgp *bgp, struct bgp_dest *dest,
prev_mpath = cur_mpath;
mpath_count++;
if (ecommunity_linkbw_present(
cur_mpath->attr->ecommunity,
bgp_attr_get_ecommunity(
cur_mpath->attr),
&bwval))
cum_bw += bwval;
else
@ -714,7 +715,8 @@ void bgp_path_info_mpath_update(struct bgp *bgp, struct bgp_dest *dest,
mpath_changed = 1;
mpath_count++;
if (ecommunity_linkbw_present(
new_mpath->attr->ecommunity,
bgp_attr_get_ecommunity(
new_mpath->attr),
&bwval))
cum_bw += bwval;
else
@ -737,9 +739,9 @@ void bgp_path_info_mpath_update(struct bgp *bgp, struct bgp_dest *dest,
if (new_best) {
bgp_path_info_mpath_count_set(new_best, mpath_count - 1);
if (mpath_count <= 1
|| !ecommunity_linkbw_present(new_best->attr->ecommunity,
&bwval))
if (mpath_count <= 1 ||
!ecommunity_linkbw_present(
bgp_attr_get_ecommunity(new_best->attr), &bwval))
all_paths_lb = false;
else
cum_bw += bwval;
@ -841,8 +843,9 @@ void bgp_path_info_mpath_aggregate_update(struct bgp_path_info *new_best,
origin = attr.origin;
community =
attr.community ? community_dup(attr.community) : NULL;
ecomm = (attr.ecommunity) ? ecommunity_dup(attr.ecommunity)
: NULL;
ecomm = (bgp_attr_get_ecommunity(&attr))
? ecommunity_dup(bgp_attr_get_ecommunity(&attr))
: NULL;
lcomm = (attr.lcommunity) ? lcommunity_dup(attr.lcommunity)
: NULL;
@ -869,16 +872,17 @@ void bgp_path_info_mpath_aggregate_update(struct bgp_path_info *new_best,
mpinfo->attr->community);
}
if (mpinfo->attr->ecommunity) {
if (bgp_attr_get_ecommunity(mpinfo->attr)) {
if (ecomm) {
ecommerge = ecommunity_merge(
ecomm,
mpinfo->attr->ecommunity);
ecomm, bgp_attr_get_ecommunity(
mpinfo->attr));
ecomm = ecommunity_uniq_sort(ecommerge);
ecommunity_free(&ecommerge);
} else
ecomm = ecommunity_dup(
mpinfo->attr->ecommunity);
bgp_attr_get_ecommunity(
mpinfo->attr));
}
if (mpinfo->attr->lcommunity) {
if (lcomm) {
@ -900,7 +904,7 @@ void bgp_path_info_mpath_aggregate_update(struct bgp_path_info *new_best,
attr.flag |= ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES);
}
if (ecomm) {
attr.ecommunity = ecomm;
bgp_attr_set_ecommunity(&attr, ecomm);
attr.flag |= ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES);
}
if (lcomm) {

View file

@ -1053,9 +1053,10 @@ void vpn_leak_from_vrf_update(struct bgp *bgp_vpn, /* to */
if (debug)
zlog_debug("%s: from vrf %s", __func__, bgp_vrf->name_pretty);
if (debug && path_vrf->attr->ecommunity) {
char *s = ecommunity_ecom2str(path_vrf->attr->ecommunity,
ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
if (debug && bgp_attr_get_ecommunity(path_vrf->attr)) {
char *s = ecommunity_ecom2str(
bgp_attr_get_ecommunity(path_vrf->attr),
ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
zlog_debug("%s: %s path_vrf->type=%d, EC{%s}", __func__,
bgp_vrf->name, path_vrf->type, s);
@ -1111,9 +1112,10 @@ void vpn_leak_from_vrf_update(struct bgp *bgp_vpn, /* to */
}
}
if (debug && static_attr.ecommunity) {
char *s = ecommunity_ecom2str(static_attr.ecommunity,
ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
if (debug && bgp_attr_get_ecommunity(&static_attr)) {
char *s = ecommunity_ecom2str(
bgp_attr_get_ecommunity(&static_attr),
ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
zlog_debug("%s: post route map static_attr.ecommunity{%s}",
__func__, s);
@ -1128,7 +1130,7 @@ void vpn_leak_from_vrf_update(struct bgp *bgp_vpn, /* to */
/* Export with the 'from' instance's export RTs. */
/* If doing VRF-to-VRF leaking, strip existing RTs first. */
old_ecom = static_attr.ecommunity;
old_ecom = bgp_attr_get_ecommunity(&static_attr);
if (old_ecom) {
new_ecom = ecommunity_dup(old_ecom);
if (CHECK_FLAG(bgp_vrf->af_flags[afi][SAFI_UNICAST],
@ -1144,12 +1146,13 @@ void vpn_leak_from_vrf_update(struct bgp *bgp_vpn, /* to */
bgp_vrf->vpn_policy[afi]
.rtlist[BGP_VPN_POLICY_DIR_TOVPN]);
}
static_attr.ecommunity = new_ecom;
bgp_attr_set_ecommunity(&static_attr, new_ecom);
SET_FLAG(static_attr.flag, ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES));
if (debug && static_attr.ecommunity) {
char *s = ecommunity_ecom2str(static_attr.ecommunity,
ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
if (debug && bgp_attr_get_ecommunity(&static_attr)) {
char *s = ecommunity_ecom2str(
bgp_attr_get_ecommunity(&static_attr),
ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
zlog_debug("%s: post merge static_attr.ecommunity{%s}",
__func__, s);
@ -1261,8 +1264,8 @@ void vpn_leak_from_vrf_update(struct bgp *bgp_vpn, /* to */
&static_attr); /* hashed refcounted everything */
bgp_attr_flush(&static_attr); /* free locally-allocated parts */
if (debug && new_attr->ecommunity) {
char *s = ecommunity_ecom2str(new_attr->ecommunity,
if (debug && bgp_attr_get_ecommunity(new_attr)) {
char *s = ecommunity_ecom2str(bgp_attr_get_ecommunity(new_attr),
ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
zlog_debug("%s: new_attr->ecommunity{%s}", __func__, s);
@ -1481,7 +1484,7 @@ vpn_leak_to_vrf_update_onevrf(struct bgp *bgp_vrf, /* to */
/* Check for intersection of route targets */
if (!ecom_intersect(
bgp_vrf->vpn_policy[afi].rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
path_vpn->attr->ecommunity)) {
bgp_attr_get_ecommunity(path_vpn->attr))) {
if (debug)
zlog_debug(
"from vpn to vrf %s, skipping after no intersection of route targets",
@ -1500,18 +1503,18 @@ vpn_leak_to_vrf_update_onevrf(struct bgp *bgp_vrf, /* to */
struct ecommunity *new_ecom;
/* If doing VRF-to-VRF leaking, strip RTs. */
old_ecom = static_attr.ecommunity;
old_ecom = bgp_attr_get_ecommunity(&static_attr);
if (old_ecom && CHECK_FLAG(bgp_vrf->af_flags[afi][safi],
BGP_CONFIG_VRF_TO_VRF_IMPORT)) {
new_ecom = ecommunity_dup(old_ecom);
ecommunity_strip_rts(new_ecom);
static_attr.ecommunity = new_ecom;
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);
static_attr.ecommunity = NULL;
bgp_attr_set_ecommunity(&static_attr, NULL);
}
if (!old_ecom->refcnt)
@ -1728,7 +1731,7 @@ void vpn_leak_to_vrf_withdraw(struct bgp *bgp_vpn, /* from */
/* Check for intersection of route targets */
if (!ecom_intersect(bgp->vpn_policy[afi]
.rtlist[BGP_VPN_POLICY_DIR_FROMVPN],
path_vpn->attr->ecommunity)) {
bgp_attr_get_ecommunity(path_vpn->attr))) {
continue;
}

View file

@ -770,8 +770,8 @@ int bgp_pbr_build_and_validate_entry(const struct prefix *p,
if (ret < 0)
return -1;
/* extract actiosn from flowspec ecom list */
if (path && path->attr->ecommunity) {
ecom = path->attr->ecommunity;
if (path && bgp_attr_get_ecommunity(path->attr)) {
ecom = bgp_attr_get_ecommunity(path->attr);
for (i = 0; i < ecom->size; i++) {
ecom_eval = (struct ecommunity_val *)
(ecom->val + (i * ECOMMUNITY_SIZE));

View file

@ -2374,10 +2374,13 @@ bool subgroup_announce_check(struct bgp_dest *dest, struct bgp_path_info *pi,
bgp_path_info_mpath_chkwtd(bgp, pi) &&
(cum_bw = bgp_path_info_mpath_cumbw(pi)) != 0 &&
!CHECK_FLAG(attr->rmap_change_flags, BATTR_RMAP_LINK_BW_SET))
attr->ecommunity = ecommunity_replace_linkbw(
bgp->as, attr->ecommunity, cum_bw,
CHECK_FLAG(peer->flags,
PEER_FLAG_DISABLE_LINK_BW_ENCODING_IEEE));
bgp_attr_set_ecommunity(
attr,
ecommunity_replace_linkbw(
bgp->as, bgp_attr_get_ecommunity(attr), cum_bw,
CHECK_FLAG(
peer->flags,
PEER_FLAG_DISABLE_LINK_BW_ENCODING_IEEE)));
return true;
}
@ -4118,16 +4121,19 @@ int bgp_update(struct peer *peer, const struct prefix *p, uint32_t addpath_id,
& ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES))) {
int cmp;
cmp = ecommunity_cmp(pi->attr->ecommunity,
attr_new->ecommunity);
cmp = ecommunity_cmp(
bgp_attr_get_ecommunity(pi->attr),
bgp_attr_get_ecommunity(attr_new));
if (!cmp) {
if (bgp_debug_update(peer, p, NULL, 1))
zlog_debug(
"Change in EXT-COMM, existing %s new %s",
ecommunity_str(
pi->attr->ecommunity),
bgp_attr_get_ecommunity(
pi->attr)),
ecommunity_str(
attr_new->ecommunity));
bgp_attr_get_ecommunity(
attr_new)));
if (safi == SAFI_EVPN)
bgp_evpn_unimport_route(
bgp, afi, safi, p, pi);
@ -7032,7 +7038,7 @@ static bool bgp_aggregate_info_same(struct bgp_path_info *pi, uint8_t origin,
if (!community_cmp(pi->attr->community, comm))
return false;
if (!ecommunity_cmp(pi->attr->ecommunity, ecomm))
if (!ecommunity_cmp(bgp_attr_get_ecommunity(pi->attr), ecomm))
return false;
if (!lcommunity_cmp(pi->attr->lcommunity, lcomm))
@ -7455,10 +7461,10 @@ void bgp_aggregate_route(struct bgp *bgp, const struct prefix *p, afi_t afi,
/* Compute aggregate route's extended community.
*/
if (pi->attr->ecommunity)
if (bgp_attr_get_ecommunity(pi->attr))
bgp_compute_aggregate_ecommunity_hash(
aggregate,
pi->attr->ecommunity);
aggregate,
bgp_attr_get_ecommunity(pi->attr));
/* Compute aggregate route's large community.
*/
@ -7577,12 +7583,13 @@ void bgp_aggregate_delete(struct bgp *bgp, const struct prefix *p, afi_t afi,
aggregate,
pi->attr->community);
if (pi->attr->ecommunity)
if (bgp_attr_get_ecommunity(pi->attr))
/* Remove ecommunity from aggregate.
*/
bgp_remove_ecomm_from_aggregate_hash(
aggregate,
pi->attr->ecommunity);
aggregate,
bgp_attr_get_ecommunity(
pi->attr));
if (pi->attr->lcommunity)
/* Remove lcommunity from aggregate.
@ -7695,10 +7702,10 @@ static void bgp_add_route_to_aggregate(struct bgp *bgp,
/* Compute aggregate route's extended community.
*/
if (pinew->attr->ecommunity)
if (bgp_attr_get_ecommunity(pinew->attr))
bgp_compute_aggregate_ecommunity(
aggregate,
pinew->attr->ecommunity);
aggregate,
bgp_attr_get_ecommunity(pinew->attr));
/* Compute aggregate route's large community.
*/
@ -7798,12 +7805,11 @@ static void bgp_remove_route_from_aggregate(struct bgp *bgp, afi_t afi,
aggregate,
pi->attr->community);
if (pi->attr->ecommunity)
if (bgp_attr_get_ecommunity(pi->attr))
/* Remove ecommunity from aggregate.
*/
bgp_remove_ecommunity_from_aggregate(
aggregate,
pi->attr->ecommunity);
aggregate, bgp_attr_get_ecommunity(pi->attr));
if (pi->attr->lcommunity)
/* Remove lcommunity from aggregate.
@ -9130,9 +9136,9 @@ void route_vty_out(struct vty *vty, const struct prefix *p,
if (safi == SAFI_EVPN &&
attr->flag & ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES)) {
json_ext_community = json_object_new_object();
json_object_string_add(json_ext_community,
"string",
attr->ecommunity->str);
json_object_string_add(
json_ext_community, "string",
bgp_attr_get_ecommunity(attr)->str);
json_object_object_add(json_path,
"extendedCommunity",
json_ext_community);
@ -9185,7 +9191,8 @@ void route_vty_out(struct vty *vty, const struct prefix *p,
if (attr->flag &
ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES)) {
vty_out(vty, "%*s", 20, " ");
vty_out(vty, "%s\n", attr->ecommunity->str);
vty_out(vty, "%s\n",
bgp_attr_get_ecommunity(attr)->str);
}
}
@ -9518,10 +9525,10 @@ void route_vty_out_overlay(struct vty *vty, const struct prefix *p,
else
json_object_string_add(json_overlay, "gw", buf);
if (attr->ecommunity) {
if (bgp_attr_get_ecommunity(attr)) {
char *mac = NULL;
struct ecommunity_val *routermac = ecommunity_lookup(
attr->ecommunity, ECOMMUNITY_ENCODE_EVPN,
bgp_attr_get_ecommunity(attr), ECOMMUNITY_ENCODE_EVPN,
ECOMMUNITY_EVPN_SUBTYPE_ROUTERMAC);
if (routermac)
@ -10491,13 +10498,14 @@ void route_vty_out_detail(struct vty *vty, struct bgp *bgp, struct bgp_dest *bn,
if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES)) {
if (json_paths) {
json_ext_community = json_object_new_object();
json_object_string_add(json_ext_community, "string",
attr->ecommunity->str);
json_object_string_add(
json_ext_community, "string",
bgp_attr_get_ecommunity(attr)->str);
json_object_object_add(json_path, "extendedCommunity",
json_ext_community);
} else {
vty_out(vty, " Extended Community: %s\n",
attr->ecommunity->str);
bgp_attr_get_ecommunity(attr)->str);
}
}

View file

@ -1589,7 +1589,7 @@ route_match_ecommunity(void *rule, const struct prefix *prefix, void *object)
if (!list)
return RMAP_NOMATCH;
if (ecommunity_list_match(path->attr->ecommunity, list))
if (ecommunity_list_match(bgp_attr_get_ecommunity(path->attr), list))
return RMAP_MATCH;
return RMAP_NOMATCH;
@ -2590,7 +2590,7 @@ route_set_ecommunity(void *rule, const struct prefix *prefix, void *object)
if (rcs->none) {
attr->flag &= ~(ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES));
attr->ecommunity = NULL;
bgp_attr_set_ecommunity(attr, NULL);
return RMAP_OKAY;
}
@ -2598,7 +2598,7 @@ route_set_ecommunity(void *rule, const struct prefix *prefix, void *object)
return RMAP_OKAY;
/* We assume additive for Extended Community. */
old_ecom = path->attr->ecommunity;
old_ecom = bgp_attr_get_ecommunity(path->attr);
if (old_ecom) {
new_ecom =
@ -2614,7 +2614,7 @@ route_set_ecommunity(void *rule, const struct prefix *prefix, void *object)
new_ecom = ecommunity_dup(rcs->ecom);
/* will be intern()'d or attr_flush()'d by bgp_update_main() */
path->attr->ecommunity = new_ecom;
bgp_attr_set_ecommunity(path->attr, new_ecom);
path->attr->flag |= ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES);
@ -2764,7 +2764,7 @@ route_set_ecommunity_lb(void *rule, const struct prefix *prefix, void *object)
PEER_FLAG_DISABLE_LINK_BW_ENCODING_IEEE));
/* add to route or merge with existing */
old_ecom = path->attr->ecommunity;
old_ecom = bgp_attr_get_ecommunity(path->attr);
if (old_ecom) {
new_ecom = ecommunity_dup(old_ecom);
ecommunity_add_val(new_ecom, &lb_eval, true, true);
@ -2778,7 +2778,7 @@ 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 */
path->attr->ecommunity = 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

View file

@ -800,8 +800,8 @@ void add_vnc_route(struct rfapi_descriptor *rfd, /* cookie, VPN UN addr, peer */
*/
attr.ecommunity = ecommunity_new();
assert(attr.ecommunity);
bgp_attr_set_ecommunity(&attr, ecommunity_new());
assert(bgp_attr_get_ecommunity(&attr));
if (TunnelType != BGP_ENCAP_TYPE_MPLS
&& TunnelType != BGP_ENCAP_TYPE_RESERVED) {
@ -817,25 +817,28 @@ void add_vnc_route(struct rfapi_descriptor *rfd, /* cookie, VPN UN addr, peer */
beec.val[1] = ECOMMUNITY_OPAQUE_SUBTYPE_ENCAP;
beec.val[6] = ((TunnelType) >> 8) & 0xff;
beec.val[7] = (TunnelType)&0xff;
ecommunity_add_val(attr.ecommunity, &beec, false, false);
ecommunity_add_val(bgp_attr_get_ecommunity(&attr), &beec, false,
false);
}
/*
* Add extended community attributes to match rt export list
*/
if (rt_export_list) {
attr.ecommunity =
ecommunity_merge(attr.ecommunity, rt_export_list);
bgp_attr_set_ecommunity(
&attr, ecommunity_merge(bgp_attr_get_ecommunity(&attr),
rt_export_list));
}
if (attr.ecommunity->size) {
struct ecommunity *ecomm = bgp_attr_get_ecommunity(&attr);
if (ecomm->size) {
attr.flag |= ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES);
} else {
ecommunity_free(&attr.ecommunity);
attr.ecommunity = NULL;
ecommunity_free(&ecomm);
bgp_attr_set_ecommunity(&attr, NULL);
}
vnc_zlog_debug_verbose("%s: attr.ecommunity=%p", __func__,
attr.ecommunity);
vnc_zlog_debug_verbose("%s: attr.ecommunity=%p", __func__, ecomm);
/*

View file

@ -1292,10 +1292,11 @@ rfapiRouteInfo2NextHopEntry(struct rfapi_ip_prefix *rprefix,
memcpy(&vo->v.l2addr.macaddr, &p->u.prefix_eth.octet, ETH_ALEN);
/* only low 3 bytes of this are significant */
(void)rfapiEcommunityGetLNI(bpi->attr->ecommunity,
(void)rfapiEcommunityGetLNI(bgp_attr_get_ecommunity(bpi->attr),
&vo->v.l2addr.logical_net_id);
(void)rfapiEcommunityGetEthernetTag(bpi->attr->ecommunity,
&vo->v.l2addr.tag_id);
(void)rfapiEcommunityGetEthernetTag(
bgp_attr_get_ecommunity(bpi->attr),
&vo->v.l2addr.tag_id);
/* local_nve_id comes from lower byte of RD type */
vo->v.l2addr.local_nve_id = bpi->extra->vnc.import.rd.val[1];
@ -2946,7 +2947,7 @@ static void rfapiBgpInfoFilteredImportEncap(
* On a withdraw, peer and RD are sufficient to determine if
* we should act.
*/
if (!attr || !attr->ecommunity) {
if (!attr || !bgp_attr_get_ecommunity(attr)) {
vnc_zlog_debug_verbose(
"%s: attr, extra, or ecommunity missing, not importing",
@ -2954,15 +2955,17 @@ static void rfapiBgpInfoFilteredImportEncap(
return;
}
#ifdef RFAPI_REQUIRE_ENCAP_BEEC
if (!rfapiEcommunitiesMatchBeec(attr->ecommunity)) {
if (!rfapiEcommunitiesMatchBeec(
bgp_attr_get_ecommunity(attr))) {
vnc_zlog_debug_verbose(
"%s: it=%p: no match for BGP Encapsulation ecommunity",
__func__, import_table);
return;
}
#endif
if (!rfapiEcommunitiesIntersect(import_table->rt_import_list,
attr->ecommunity)) {
if (!rfapiEcommunitiesIntersect(
import_table->rt_import_list,
bgp_attr_get_ecommunity(attr))) {
vnc_zlog_debug_verbose(
"%s: it=%p: no ecommunity intersection",
@ -3407,16 +3410,17 @@ void rfapiBgpInfoFilteredImportVPN(
* we should act.
*/
if (action == FIF_ACTION_UPDATE) {
if (!attr || !attr->ecommunity) {
if (!attr || !bgp_attr_get_ecommunity(attr)) {
vnc_zlog_debug_verbose(
"%s: attr, extra, or ecommunity missing, not importing",
__func__);
return;
}
if ((import_table != bgp->rfapi->it_ce)
&& !rfapiEcommunitiesIntersect(import_table->rt_import_list,
attr->ecommunity)) {
if ((import_table != bgp->rfapi->it_ce) &&
!rfapiEcommunitiesIntersect(
import_table->rt_import_list,
bgp_attr_get_ecommunity(attr))) {
vnc_zlog_debug_verbose(
"%s: it=%p: no ecommunity intersection",
@ -3891,7 +3895,7 @@ void rfapiProcessUpdate(struct peer *peer,
* Find rt containing LNI (Logical Network ID), which
* _should_ always be present when mac address is present
*/
rc = rfapiEcommunityGetLNI(attr->ecommunity, &lni);
rc = rfapiEcommunityGetLNI(bgp_attr_get_ecommunity(attr), &lni);
vnc_zlog_debug_verbose(
"%s: rfapiEcommunityGetLNI returned %d, lni=%d, attr=%p",

View file

@ -682,10 +682,11 @@ static void rfapiRibBi2Ri(struct bgp_path_info *bpi, struct rfapi_info *ri,
memcpy(&vo->v.l2addr.macaddr, bpi->extra->vnc.import.rd.val + 2,
ETH_ALEN);
(void)rfapiEcommunityGetLNI(bpi->attr->ecommunity,
(void)rfapiEcommunityGetLNI(bgp_attr_get_ecommunity(bpi->attr),
&vo->v.l2addr.logical_net_id);
(void)rfapiEcommunityGetEthernetTag(bpi->attr->ecommunity,
&vo->v.l2addr.tag_id);
(void)rfapiEcommunityGetEthernetTag(
bgp_attr_get_ecommunity(bpi->attr),
&vo->v.l2addr.tag_id);
/* local_nve_id comes from RD */
vo->v.l2addr.local_nve_id = bpi->extra->vnc.import.rd.val[1];

View file

@ -417,8 +417,8 @@ void rfapi_vty_out_vncinfo(struct vty *vty, const struct prefix *p,
}
}
if (bpi->attr->ecommunity) {
s = ecommunity_ecom2str(bpi->attr->ecommunity,
if (bgp_attr_get_ecommunity(bpi->attr)) {
s = ecommunity_ecom2str(bgp_attr_get_ecommunity(bpi->attr),
ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
vty_out(vty, " EC{%s}", s);
XFREE(MTYPE_ECOMMUNITY_STR, s);
@ -467,6 +467,7 @@ void rfapiPrintAttrPtrs(void *stream, struct attr *attr)
struct transit *transit;
struct cluster_list *cluster;
char buf[BUFSIZ];
struct ecommunity *ecomm = bgp_attr_get_ecommunity(attr);
if (rfapiStream2Vty(stream, &fp, &vty, &out, &vty_newline) == 0)
return;
@ -484,8 +485,8 @@ void rfapiPrintAttrPtrs(void *stream, struct attr *attr)
fp(out, " community=%p, refcnt=%d%s", attr->community,
(attr->community ? attr->community->refcnt : 0), HVTYNL);
fp(out, " ecommunity=%p, refcnt=%d%s", attr->ecommunity,
(attr->ecommunity ? attr->ecommunity->refcnt : 0), HVTYNL);
fp(out, " ecommunity=%p, refcnt=%d%s", ecomm,
(ecomm ? ecomm->refcnt : 0), HVTYNL);
cluster = bgp_attr_get_cluster(attr);
fp(out, " cluster=%p, refcnt=%d%s", cluster,
@ -623,8 +624,8 @@ void rfapiPrintBi(void *stream, struct bgp_path_info *bpi)
}
/* RT list */
if (bpi->attr->ecommunity) {
s = ecommunity_ecom2str(bpi->attr->ecommunity,
if (bgp_attr_get_ecommunity(bpi->attr)) {
s = ecommunity_ecom2str(bgp_attr_get_ecommunity(bpi->attr),
ECOMMUNITY_FORMAT_ROUTE_MAP, 0);
r = snprintf(p, REMAIN, " %s", s);
INCP;

View file

@ -136,8 +136,9 @@ static int getce(struct bgp *bgp, struct attr *attr, struct prefix *pfx_ce)
uint8_t *ecp;
uint32_t i;
uint16_t localadmin = bgp->rfapi_cfg->resolve_nve_roo_local_admin;
struct ecommunity *ecomm = bgp_attr_get_ecommunity(attr);
for (ecp = attr->ecommunity->val, i = 0; i < attr->ecommunity->size;
for (ecp = ecomm->val, i = 0; i < ecomm->size;
++i, ecp += ECOMMUNITY_SIZE) {
if (VNC_DEBUG(EXPORT_BGP_GETCE)) {
@ -640,12 +641,14 @@ encap_attr_export(struct attr *new, struct attr *orig,
/* TBD use lcom for IPv6 */
ecom_ro = vnc_route_origin_ecom_single(&use_nexthop->u.prefix4);
}
if (new->ecommunity) {
if (bgp_attr_get_ecommunity(new)) {
if (ecom_ro)
new->ecommunity =
ecommunity_merge(ecom_ro, new->ecommunity);
bgp_attr_set_ecommunity(
new,
ecommunity_merge(ecom_ro,
bgp_attr_get_ecommunity(new)));
} else {
new->ecommunity = ecom_ro;
bgp_attr_set_ecommunity(new, ecom_ro);
}
if (ecom_ro) {
new->flag |= ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES);

View file

@ -373,8 +373,8 @@ static int process_unicast_route(struct bgp *bgp, /* in */
*/
rfapiUnicastNexthop2Prefix(afi, &hattr, unicast_nexthop);
if (hattr.ecommunity)
*ecom = ecommunity_dup(hattr.ecommunity);
if (bgp_attr_get_ecommunity(&hattr))
*ecom = ecommunity_dup(bgp_attr_get_ecommunity(&hattr));
else
*ecom = ecommunity_new();
@ -480,8 +480,8 @@ static void vnc_import_bgp_add_route_mode_resolve_nve_one_bi(
struct ecommunity *new_ecom = ecommunity_dup(ecom);
if (bpi->attr->ecommunity)
ecommunity_merge(new_ecom, bpi->attr->ecommunity);
if (bgp_attr_get_ecommunity(bpi->attr))
ecommunity_merge(new_ecom, bgp_attr_get_ecommunity(bpi->attr));
if (bpi->extra)
label = decode_label(&bpi->extra->label[0]);
@ -818,8 +818,8 @@ static void vnc_import_bgp_add_route_mode_plain(struct bgp *bgp,
memset(&prd, 0, sizeof(prd));
rfapi_set_autord_from_vn(&prd, &vnaddr);
if (iattr && iattr->ecommunity)
ecom = ecommunity_dup(iattr->ecommunity);
if (iattr && bgp_attr_get_ecommunity(iattr))
ecom = ecommunity_dup(bgp_attr_get_ecommunity(iattr));
}
local_pref = calc_local_pref(iattr, peer);
@ -1015,8 +1015,9 @@ static void vnc_import_bgp_add_route_mode_nvegroup(
else
ecom = ecommunity_new();
if (iattr && iattr->ecommunity)
ecom = ecommunity_merge(ecom, iattr->ecommunity);
if (iattr && bgp_attr_get_ecommunity(iattr))
ecom = ecommunity_merge(ecom,
bgp_attr_get_ecommunity(iattr));
}
local_pref = calc_local_pref(iattr, peer);