forked from Mirror/frr
bgpd: Convert attr->transit to use accessor functions
Convert the `struct attr`->transit variable to use accessor functions. Signed-off-by: Donald Sharp <sharpd@nvidia.com>
This commit is contained in:
parent
d04ac434f0
commit
04fb21e22e
|
@ -667,8 +667,8 @@ unsigned int attrhash_key_make(const void *p)
|
||||||
MIX(ecommunity_hash_make(bgp_attr_get_ipv6_ecommunity(attr)));
|
MIX(ecommunity_hash_make(bgp_attr_get_ipv6_ecommunity(attr)));
|
||||||
if (attr->cluster)
|
if (attr->cluster)
|
||||||
MIX(cluster_hash_key_make(attr->cluster));
|
MIX(cluster_hash_key_make(attr->cluster));
|
||||||
if (attr->transit)
|
if (bgp_attr_get_transit(attr))
|
||||||
MIX(transit_hash_key_make(attr->transit));
|
MIX(transit_hash_key_make(bgp_attr_get_transit(attr)));
|
||||||
if (attr->encap_subtlvs)
|
if (attr->encap_subtlvs)
|
||||||
MIX(encap_hash_key_make(attr->encap_subtlvs));
|
MIX(encap_hash_key_make(attr->encap_subtlvs));
|
||||||
#ifdef ENABLE_BGP_VNC
|
#ifdef ENABLE_BGP_VNC
|
||||||
|
@ -707,7 +707,8 @@ bool attrhash_cmp(const void *p1, const void *p2)
|
||||||
== bgp_attr_get_ipv6_ecommunity(attr2)
|
== bgp_attr_get_ipv6_ecommunity(attr2)
|
||||||
&& attr1->lcommunity == attr2->lcommunity
|
&& attr1->lcommunity == attr2->lcommunity
|
||||||
&& attr1->cluster == attr2->cluster
|
&& attr1->cluster == attr2->cluster
|
||||||
&& attr1->transit == attr2->transit
|
&& bgp_attr_get_transit(attr1)
|
||||||
|
== bgp_attr_get_transit(attr2)
|
||||||
&& attr1->rmap_table_id == attr2->rmap_table_id
|
&& attr1->rmap_table_id == attr2->rmap_table_id
|
||||||
&& (attr1->encap_tunneltype == attr2->encap_tunneltype)
|
&& (attr1->encap_tunneltype == attr2->encap_tunneltype)
|
||||||
&& encap_same(attr1->encap_subtlvs, attr2->encap_subtlvs)
|
&& encap_same(attr1->encap_subtlvs, attr2->encap_subtlvs)
|
||||||
|
@ -859,11 +860,14 @@ struct attr *bgp_attr_intern(struct attr *attr)
|
||||||
else
|
else
|
||||||
attr->cluster->refcnt++;
|
attr->cluster->refcnt++;
|
||||||
}
|
}
|
||||||
if (attr->transit) {
|
|
||||||
if (!attr->transit->refcnt)
|
struct transit *transit = bgp_attr_get_transit(attr);
|
||||||
attr->transit = transit_intern(attr->transit);
|
|
||||||
|
if (transit) {
|
||||||
|
if (!transit->refcnt)
|
||||||
|
bgp_attr_set_transit(attr, transit_intern(transit));
|
||||||
else
|
else
|
||||||
attr->transit->refcnt++;
|
transit->refcnt++;
|
||||||
}
|
}
|
||||||
if (attr->encap_subtlvs) {
|
if (attr->encap_subtlvs) {
|
||||||
if (!attr->encap_subtlvs->refcnt)
|
if (!attr->encap_subtlvs->refcnt)
|
||||||
|
@ -1066,8 +1070,12 @@ void bgp_attr_unintern_sub(struct attr *attr)
|
||||||
cluster_unintern(&attr->cluster);
|
cluster_unintern(&attr->cluster);
|
||||||
UNSET_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST));
|
UNSET_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST));
|
||||||
|
|
||||||
if (attr->transit)
|
struct transit *transit = bgp_attr_get_transit(attr);
|
||||||
transit_unintern(&attr->transit);
|
|
||||||
|
if (transit) {
|
||||||
|
transit_unintern(&transit);
|
||||||
|
bgp_attr_set_transit(attr, transit);
|
||||||
|
}
|
||||||
|
|
||||||
if (attr->encap_subtlvs)
|
if (attr->encap_subtlvs)
|
||||||
encap_unintern(&attr->encap_subtlvs, ENCAP_SUBTLV_TYPE);
|
encap_unintern(&attr->encap_subtlvs, ENCAP_SUBTLV_TYPE);
|
||||||
|
@ -1154,9 +1162,12 @@ void bgp_attr_flush(struct attr *attr)
|
||||||
cluster_free(attr->cluster);
|
cluster_free(attr->cluster);
|
||||||
attr->cluster = NULL;
|
attr->cluster = NULL;
|
||||||
}
|
}
|
||||||
if (attr->transit && !attr->transit->refcnt) {
|
|
||||||
transit_free(attr->transit);
|
struct transit *transit = bgp_attr_get_transit(attr);
|
||||||
attr->transit = NULL;
|
|
||||||
|
if (transit && !transit->refcnt) {
|
||||||
|
transit_free(transit);
|
||||||
|
bgp_attr_set_transit(attr, NULL);
|
||||||
}
|
}
|
||||||
if (attr->encap_subtlvs && !attr->encap_subtlvs->refcnt) {
|
if (attr->encap_subtlvs && !attr->encap_subtlvs->refcnt) {
|
||||||
encap_free(attr->encap_subtlvs);
|
encap_free(attr->encap_subtlvs);
|
||||||
|
@ -2848,10 +2859,9 @@ static bgp_attr_parse_ret_t bgp_attr_unknown(struct bgp_attr_parser_args *args)
|
||||||
SET_FLAG(*startp, BGP_ATTR_FLAG_PARTIAL);
|
SET_FLAG(*startp, BGP_ATTR_FLAG_PARTIAL);
|
||||||
|
|
||||||
/* Store transitive attribute to the end of attr->transit. */
|
/* Store transitive attribute to the end of attr->transit. */
|
||||||
if (!attr->transit)
|
transit = bgp_attr_get_transit(attr);
|
||||||
attr->transit = XCALLOC(MTYPE_TRANSIT, sizeof(struct transit));
|
if (!transit)
|
||||||
|
transit = XCALLOC(MTYPE_TRANSIT, sizeof(struct transit));
|
||||||
transit = attr->transit;
|
|
||||||
|
|
||||||
if (transit->val)
|
if (transit->val)
|
||||||
transit->val = XREALLOC(MTYPE_TRANSIT_VAL, transit->val,
|
transit->val = XREALLOC(MTYPE_TRANSIT_VAL, transit->val,
|
||||||
|
@ -2861,6 +2871,7 @@ static bgp_attr_parse_ret_t bgp_attr_unknown(struct bgp_attr_parser_args *args)
|
||||||
|
|
||||||
memcpy(transit->val + transit->length, startp, total);
|
memcpy(transit->val + transit->length, startp, total);
|
||||||
transit->length += total;
|
transit->length += total;
|
||||||
|
bgp_attr_set_transit(attr, transit);
|
||||||
|
|
||||||
return BGP_ATTR_PARSE_PROCEED;
|
return BGP_ATTR_PARSE_PROCEED;
|
||||||
}
|
}
|
||||||
|
@ -2933,6 +2944,7 @@ bgp_attr_parse_ret_t bgp_attr_parse(struct peer *peer, struct attr *attr,
|
||||||
struct aspath *as4_path = NULL;
|
struct aspath *as4_path = NULL;
|
||||||
as_t as4_aggregator = 0;
|
as_t as4_aggregator = 0;
|
||||||
struct in_addr as4_aggregator_addr = {.s_addr = 0};
|
struct in_addr as4_aggregator_addr = {.s_addr = 0};
|
||||||
|
struct transit *transit;
|
||||||
|
|
||||||
/* Initialize bitmap. */
|
/* Initialize bitmap. */
|
||||||
memset(seen, 0, BGP_ATTR_BITMAP_SIZE);
|
memset(seen, 0, BGP_ATTR_BITMAP_SIZE);
|
||||||
|
@ -3298,10 +3310,11 @@ done:
|
||||||
aspath_unintern(&as4_path);
|
aspath_unintern(&as4_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
transit = bgp_attr_get_transit(attr);
|
||||||
if (ret != BGP_ATTR_PARSE_ERROR) {
|
if (ret != BGP_ATTR_PARSE_ERROR) {
|
||||||
/* Finally intern unknown attribute. */
|
/* Finally intern unknown attribute. */
|
||||||
if (attr->transit)
|
if (transit)
|
||||||
attr->transit = transit_intern(attr->transit);
|
bgp_attr_set_transit(attr, transit_intern(transit));
|
||||||
if (attr->encap_subtlvs)
|
if (attr->encap_subtlvs)
|
||||||
attr->encap_subtlvs = encap_intern(attr->encap_subtlvs,
|
attr->encap_subtlvs = encap_intern(attr->encap_subtlvs,
|
||||||
ENCAP_SUBTLV_TYPE);
|
ENCAP_SUBTLV_TYPE);
|
||||||
|
@ -3311,17 +3324,18 @@ done:
|
||||||
VNC_SUBTLV_TYPE);
|
VNC_SUBTLV_TYPE);
|
||||||
#endif
|
#endif
|
||||||
} else {
|
} else {
|
||||||
if (attr->transit) {
|
if (transit) {
|
||||||
transit_free(attr->transit);
|
transit_free(transit);
|
||||||
attr->transit = NULL;
|
bgp_attr_set_transit(attr, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
bgp_attr_flush_encap(attr);
|
bgp_attr_flush_encap(attr);
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Sanity checks */
|
/* Sanity checks */
|
||||||
if (attr->transit)
|
transit = bgp_attr_get_transit(attr);
|
||||||
assert(attr->transit->refcnt > 0);
|
if (transit)
|
||||||
|
assert(transit->refcnt > 0);
|
||||||
if (attr->encap_subtlvs)
|
if (attr->encap_subtlvs)
|
||||||
assert(attr->encap_subtlvs->refcnt > 0);
|
assert(attr->encap_subtlvs->refcnt > 0);
|
||||||
#ifdef ENABLE_BGP_VNC
|
#ifdef ENABLE_BGP_VNC
|
||||||
|
@ -4131,8 +4145,10 @@ bgp_size_t bgp_packet_attribute(struct bgp *bgp, struct peer *peer,
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Unknown transit attribute. */
|
/* Unknown transit attribute. */
|
||||||
if (attr->transit)
|
struct transit *transit = bgp_attr_get_transit(attr);
|
||||||
stream_put(s, attr->transit->val, attr->transit->length);
|
|
||||||
|
if (transit)
|
||||||
|
stream_put(s, transit->val, transit->length);
|
||||||
|
|
||||||
/* Return total size of attribute. */
|
/* Return total size of attribute. */
|
||||||
return stream_get_endp(s) - cp;
|
return stream_get_endp(s) - cp;
|
||||||
|
|
|
@ -481,4 +481,14 @@ static inline void bgp_attr_set_ipv6_ecommunity(struct attr *attr,
|
||||||
attr->ipv6_ecommunity = ipv6_ecomm;
|
attr->ipv6_ecommunity = ipv6_ecomm;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline struct transit *bgp_attr_get_transit(const struct attr *attr)
|
||||||
|
{
|
||||||
|
return attr->transit;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void bgp_attr_set_transit(struct attr *attr,
|
||||||
|
struct transit *transit)
|
||||||
|
{
|
||||||
|
attr->transit = transit;
|
||||||
|
}
|
||||||
#endif /* _QUAGGA_BGP_ATTR_H */
|
#endif /* _QUAGGA_BGP_ATTR_H */
|
||||||
|
|
|
@ -456,7 +456,7 @@ void rfapiPrintAttrPtrs(void *stream, struct attr *attr)
|
||||||
struct vty *vty;
|
struct vty *vty;
|
||||||
void *out;
|
void *out;
|
||||||
const char *vty_newline;
|
const char *vty_newline;
|
||||||
|
struct transit *transit;
|
||||||
char buf[BUFSIZ];
|
char buf[BUFSIZ];
|
||||||
|
|
||||||
if (rfapiStream2Vty(stream, &fp, &vty, &out, &vty_newline) == 0)
|
if (rfapiStream2Vty(stream, &fp, &vty, &out, &vty_newline) == 0)
|
||||||
|
@ -479,8 +479,10 @@ void rfapiPrintAttrPtrs(void *stream, struct attr *attr)
|
||||||
(attr->ecommunity ? attr->ecommunity->refcnt : 0), HVTYNL);
|
(attr->ecommunity ? attr->ecommunity->refcnt : 0), HVTYNL);
|
||||||
fp(out, " cluster=%p, refcnt=%d%s", attr->cluster,
|
fp(out, " cluster=%p, refcnt=%d%s", attr->cluster,
|
||||||
(attr->cluster ? attr->cluster->refcnt : 0), HVTYNL);
|
(attr->cluster ? attr->cluster->refcnt : 0), HVTYNL);
|
||||||
fp(out, " transit=%p, refcnt=%d%s", attr->transit,
|
|
||||||
(attr->transit ? attr->transit->refcnt : 0), HVTYNL);
|
transit = bgp_attr_get_transit(attr);
|
||||||
|
fp(out, " transit=%p, refcnt=%d%s", transit,
|
||||||
|
(transit ? transit->refcnt : 0), HVTYNL);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
Loading…
Reference in a new issue