summaryrefslogtreecommitdiffstats
path: root/bgpd/bgp_attr.c
diff options
context:
space:
mode:
authorIgor Ryzhov <iryzhov@nfware.com>2022-02-10 13:35:21 +0100
committerGitHub <noreply@github.com>2022-02-10 13:35:21 +0100
commite49889387ef4cf8fdb69ca33867506f68116939b (patch)
tree9c2ad0eaf24972c06001a9d6a327f01e7aafb78b /bgpd/bgp_attr.c
parentMerge pull request #10549 from idryzhov/bgp-coverity (diff)
parentbgpd: Use get/set helpers for attr->lcommunity (diff)
downloadfrr-e49889387ef4cf8fdb69ca33867506f68116939b.tar.xz
frr-e49889387ef4cf8fdb69ca33867506f68116939b.zip
Merge pull request #10545 from ton31337/feature/get_set_for_lcommunity
bgpd: Use get/set helpers for attr->lcommunity
Diffstat (limited to 'bgpd/bgp_attr.c')
-rw-r--r--bgpd/bgp_attr.c63
1 files changed, 38 insertions, 25 deletions
diff --git a/bgpd/bgp_attr.c b/bgpd/bgp_attr.c
index 97ff4caca..008998c8b 100644
--- a/bgpd/bgp_attr.c
+++ b/bgpd/bgp_attr.c
@@ -682,8 +682,8 @@ unsigned int attrhash_key_make(const void *p)
if (attr->community)
MIX(community_hash_make(attr->community));
- if (attr->lcommunity)
- MIX(lcommunity_hash_make(attr->lcommunity));
+ if (bgp_attr_get_lcommunity(attr))
+ MIX(lcommunity_hash_make(bgp_attr_get_lcommunity(attr)));
if (bgp_attr_get_ecommunity(attr))
MIX(ecommunity_hash_make(bgp_attr_get_ecommunity(attr)));
if (bgp_attr_get_ipv6_ecommunity(attr))
@@ -737,7 +737,8 @@ bool attrhash_cmp(const void *p1, const void *p2)
== bgp_attr_get_ecommunity(attr2)
&& bgp_attr_get_ipv6_ecommunity(attr1)
== bgp_attr_get_ipv6_ecommunity(attr2)
- && attr1->lcommunity == attr2->lcommunity
+ && bgp_attr_get_lcommunity(attr1)
+ == bgp_attr_get_lcommunity(attr2)
&& bgp_attr_get_cluster(attr1)
== bgp_attr_get_cluster(attr2)
&& bgp_attr_get_transit(attr1)
@@ -853,6 +854,7 @@ struct attr *bgp_attr_intern(struct attr *attr)
struct attr *find;
struct ecommunity *ecomm = NULL;
struct ecommunity *ipv6_ecomm = NULL;
+ struct lcommunity *lcomm = NULL;
/* Intern referenced strucutre. */
if (attr->aspath) {
@@ -885,11 +887,12 @@ struct attr *bgp_attr_intern(struct attr *attr)
ipv6_ecomm->refcnt++;
}
- if (attr->lcommunity) {
- if (!attr->lcommunity->refcnt)
- attr->lcommunity = lcommunity_intern(attr->lcommunity);
+ lcomm = bgp_attr_get_lcommunity(attr);
+ if (lcomm) {
+ if (!lcomm->refcnt)
+ bgp_attr_set_lcommunity(attr, lcommunity_intern(lcomm));
else
- attr->lcommunity->refcnt++;
+ lcomm->refcnt++;
}
struct cluster_list *cluster = bgp_attr_get_cluster(attr);
@@ -1021,7 +1024,7 @@ struct attr *bgp_attr_aggregate_intern(
}
if (lcommunity) {
- attr.lcommunity = lcommunity;
+ bgp_attr_set_lcommunity(&attr, lcommunity);
attr.flag |= ATTR_FLAG_BIT(BGP_ATTR_LARGE_COMMUNITIES);
}
@@ -1091,6 +1094,7 @@ void bgp_attr_unintern_sub(struct attr *attr)
struct ecommunity *ecomm = NULL;
struct ecommunity *ipv6_ecomm = NULL;
struct cluster_list *cluster;
+ struct lcommunity *lcomm = NULL;
/* aspath refcount shoud be decrement. */
if (attr->aspath)
@@ -1111,9 +1115,10 @@ void bgp_attr_unintern_sub(struct attr *attr)
UNSET_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_IPV6_EXT_COMMUNITIES));
bgp_attr_set_ipv6_ecommunity(attr, NULL);
- if (attr->lcommunity)
- lcommunity_unintern(&attr->lcommunity);
+ 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);
if (cluster) {
@@ -1177,6 +1182,7 @@ void bgp_attr_flush(struct attr *attr)
struct ecommunity *ecomm;
struct ecommunity *ipv6_ecomm;
struct cluster_list *cluster;
+ struct lcommunity *lcomm;
if (attr->aspath && !attr->aspath->refcnt) {
aspath_free(attr->aspath);
@@ -1192,8 +1198,10 @@ void bgp_attr_flush(struct attr *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);
+ lcomm = bgp_attr_get_lcommunity(attr);
+ if (lcomm && !lcomm->refcnt)
+ lcommunity_free(&lcomm);
+ bgp_attr_set_lcommunity(attr, NULL);
cluster = bgp_attr_get_cluster(attr);
if (cluster && !cluster->refcnt) {
@@ -2271,17 +2279,18 @@ bgp_attr_large_community(struct bgp_attr_parser_args *args)
* Large community follows new attribute format.
*/
if (length == 0) {
- attr->lcommunity = NULL;
+ bgp_attr_set_lcommunity(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->lcommunity = lcommunity_parse(stream_pnt(peer->curr), length);
+ bgp_attr_set_lcommunity(
+ attr, lcommunity_parse(stream_pnt(peer->curr), length));
/* XXX: fix ecommunity_parse to use stream API */
stream_forward_getp(peer->curr, length);
- if (!attr->lcommunity)
+ if (!bgp_attr_get_lcommunity(attr))
return bgp_attr_malformed(args, BGP_NOTIFY_UPDATE_OPT_ATTR_ERR,
args->total);
@@ -4103,21 +4112,23 @@ bgp_size_t bgp_packet_attribute(struct bgp *bgp, struct peer *peer,
if (CHECK_FLAG(peer->af_flags[afi][safi],
PEER_FLAG_SEND_LARGE_COMMUNITY)
&& (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_LARGE_COMMUNITIES))) {
- if (lcom_length(attr->lcommunity) > 255) {
+ if (lcom_length(bgp_attr_get_lcommunity(attr)) > 255) {
stream_putc(s,
BGP_ATTR_FLAG_OPTIONAL | BGP_ATTR_FLAG_TRANS
| BGP_ATTR_FLAG_EXTLEN);
stream_putc(s, BGP_ATTR_LARGE_COMMUNITIES);
- stream_putw(s, lcom_length(attr->lcommunity));
+ stream_putw(s,
+ lcom_length(bgp_attr_get_lcommunity(attr)));
} else {
stream_putc(s,
BGP_ATTR_FLAG_OPTIONAL
| BGP_ATTR_FLAG_TRANS);
stream_putc(s, BGP_ATTR_LARGE_COMMUNITIES);
- stream_putc(s, lcom_length(attr->lcommunity));
+ stream_putc(s,
+ lcom_length(bgp_attr_get_lcommunity(attr)));
}
- stream_put(s, attr->lcommunity->val,
- lcom_length(attr->lcommunity));
+ stream_put(s, bgp_attr_get_lcommunity(attr)->val,
+ lcom_length(bgp_attr_get_lcommunity(attr)));
}
/* Route Reflector. */
@@ -4547,22 +4558,24 @@ void bgp_dump_routes_attr(struct stream *s, struct attr *attr,
/* Large Community attribute. */
if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_LARGE_COMMUNITIES)) {
- if (lcom_length(attr->lcommunity) > 255) {
+ if (lcom_length(bgp_attr_get_lcommunity(attr)) > 255) {
stream_putc(s,
BGP_ATTR_FLAG_OPTIONAL | BGP_ATTR_FLAG_TRANS
| BGP_ATTR_FLAG_EXTLEN);
stream_putc(s, BGP_ATTR_LARGE_COMMUNITIES);
- stream_putw(s, lcom_length(attr->lcommunity));
+ stream_putw(s,
+ lcom_length(bgp_attr_get_lcommunity(attr)));
} else {
stream_putc(s,
BGP_ATTR_FLAG_OPTIONAL
| BGP_ATTR_FLAG_TRANS);
stream_putc(s, BGP_ATTR_LARGE_COMMUNITIES);
- stream_putc(s, lcom_length(attr->lcommunity));
+ stream_putc(s,
+ lcom_length(bgp_attr_get_lcommunity(attr)));
}
- stream_put(s, attr->lcommunity->val,
- lcom_length(attr->lcommunity));
+ stream_put(s, bgp_attr_get_lcommunity(attr)->val,
+ lcom_length(bgp_attr_get_lcommunity(attr)));
}
/* Add a MP_NLRI attribute to dump the IPv6 next hop */