summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDonatas Abraitis <donatas@opensourcerouting.org>2022-04-11 18:09:35 +0300
committerDonatas Abraitis <donatas@opensourcerouting.org>2022-04-12 22:09:28 +0300
commit9d34440bf811a14d9dd47972b1c24428f18ff6b4 (patch)
tree3a04e82903a1c182f2ceceb10625eee5bd361679
parent695c24c3b0fed1e3dc5d0ccd6bc91cc98301ee89 (diff)
bgpd: Reuse bgp_attr_set_[l]community() for setting attribute flags
Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
-rw-r--r--bgpd/bgp_attr.c11
-rw-r--r--bgpd/bgp_attr.h11
-rw-r--r--bgpd/bgp_mpath.c5
-rw-r--r--bgpd/bgp_route.c3
-rw-r--r--bgpd/bgp_routemap.c13
5 files changed, 13 insertions, 30 deletions
diff --git a/bgpd/bgp_attr.c b/bgpd/bgp_attr.c
index 2f246e61d8..310227f33a 100644
--- a/bgpd/bgp_attr.c
+++ b/bgpd/bgp_attr.c
@@ -1008,7 +1008,6 @@ struct attr *bgp_attr_aggregate_intern(
}
bgp_attr_set_community(&attr, community);
- attr.flag |= ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES);
}
if (ecommunity) {
@@ -1016,10 +1015,8 @@ struct attr *bgp_attr_aggregate_intern(
attr.flag |= ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES);
}
- if (lcommunity) {
+ if (lcommunity)
bgp_attr_set_lcommunity(&attr, lcommunity);
- attr.flag |= ATTR_FLAG_BIT(BGP_ATTR_LARGE_COMMUNITIES);
- }
if (bgp_in_graceful_shutdown(bgp))
bgp_attr_add_gshut_community(&attr);
@@ -1096,7 +1093,6 @@ void bgp_attr_unintern_sub(struct attr *attr)
comm = bgp_attr_get_community(attr);
community_unintern(&comm);
- UNSET_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES));
bgp_attr_set_community(attr, NULL);
ecomm = bgp_attr_get_ecommunity(attr);
@@ -1111,7 +1107,6 @@ void bgp_attr_unintern_sub(struct attr *attr)
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);
@@ -1963,8 +1958,6 @@ bgp_attr_community(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_COMMUNITIES);
-
return BGP_ATTR_PARSE_PROCEED;
}
@@ -2294,8 +2287,6 @@ bgp_attr_large_community(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_LARGE_COMMUNITIES);
-
return BGP_ATTR_PARSE_PROCEED;
}
diff --git a/bgpd/bgp_attr.h b/bgpd/bgp_attr.h
index 1f199da161..49702a0e31 100644
--- a/bgpd/bgp_attr.h
+++ b/bgpd/bgp_attr.h
@@ -528,6 +528,12 @@ static inline void bgp_attr_set_lcommunity(struct attr *attr,
struct lcommunity *lcomm)
{
attr->lcommunity = lcomm;
+
+ if (lcomm)
+ SET_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_LARGE_COMMUNITIES));
+ else
+ UNSET_FLAG(attr->flag,
+ ATTR_FLAG_BIT(BGP_ATTR_LARGE_COMMUNITIES));
}
static inline struct community *bgp_attr_get_community(const struct attr *attr)
@@ -539,6 +545,11 @@ static inline void bgp_attr_set_community(struct attr *attr,
struct community *comm)
{
attr->community = comm;
+
+ if (comm)
+ SET_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES));
+ else
+ UNSET_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES));
}
static inline struct ecommunity *
diff --git a/bgpd/bgp_mpath.c b/bgpd/bgp_mpath.c
index 6e695d0301..7ff0df7409 100644
--- a/bgpd/bgp_mpath.c
+++ b/bgpd/bgp_mpath.c
@@ -907,16 +907,13 @@ void bgp_path_info_mpath_aggregate_update(struct bgp_path_info *new_best,
attr.origin = origin;
if (community) {
bgp_attr_set_community(&attr, community);
- attr.flag |= ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES);
}
if (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);
- attr.flag |= ATTR_FLAG_BIT(BGP_ATTR_LARGE_COMMUNITIES);
- }
/* Zap multipath attr nexthop so we set nexthop to self */
attr.nexthop.s_addr = INADDR_ANY;
diff --git a/bgpd/bgp_route.c b/bgpd/bgp_route.c
index a5a57bdc7f..99f92baf01 100644
--- a/bgpd/bgp_route.c
+++ b/bgpd/bgp_route.c
@@ -1769,7 +1769,6 @@ void bgp_attr_add_llgr_community(struct attr *attr)
community_free(&llgr);
bgp_attr_set_community(attr, new);
- attr->flag |= ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES);
}
void bgp_attr_add_gshut_community(struct attr *attr)
@@ -1798,7 +1797,6 @@ void bgp_attr_add_gshut_community(struct attr *attr)
community_free(&gshut);
bgp_attr_set_community(attr, new);
- attr->flag |= ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES);
/* When we add the graceful-shutdown community we must also
* lower the local-preference */
@@ -3711,7 +3709,6 @@ static void bgp_attr_add_no_export_community(struct attr *attr)
community_free(&no_export);
bgp_attr_set_community(attr, new);
- attr->flag |= ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES);
}
int bgp_update(struct peer *peer, const struct prefix *p, uint32_t addpath_id,
diff --git a/bgpd/bgp_routemap.c b/bgpd/bgp_routemap.c
index 2ed73ddb68..df92a24ce1 100644
--- a/bgpd/bgp_routemap.c
+++ b/bgpd/bgp_routemap.c
@@ -2199,7 +2199,6 @@ route_set_community(void *rule, const struct prefix *prefix, void *object)
/* "none" case. */
if (rcs->none) {
- attr->flag &= ~(ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES));
bgp_attr_set_community(attr, NULL);
/* See the longer comment down below. */
if (old && old->refcnt == 0)
@@ -2227,8 +2226,6 @@ route_set_community(void *rule, const struct prefix *prefix, void *object)
/* will be interned by caller if required */
bgp_attr_set_community(attr, new);
- attr->flag |= ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES);
-
return RMAP_OKAY;
}
@@ -2313,7 +2310,6 @@ route_set_lcommunity(void *rule, const struct prefix *prefix, void *object)
/* "none" case. */
if (rcs->none) {
- attr->flag &= ~(ATTR_FLAG_BIT(BGP_ATTR_LARGE_COMMUNITIES));
bgp_attr_set_lcommunity(attr, NULL);
/* See the longer comment down below. */
@@ -2341,8 +2337,6 @@ route_set_lcommunity(void *rule, const struct prefix *prefix, void *object)
/* will be intern()'d or attr_flush()'d by bgp_update_main() */
bgp_attr_set_lcommunity(attr, new);
- attr->flag |= ATTR_FLAG_BIT(BGP_ATTR_LARGE_COMMUNITIES);
-
return RMAP_OKAY;
}
@@ -2438,13 +2432,9 @@ route_set_lcommunity_delete(void *rule, const struct prefix *pfx, void *object)
if (new->size == 0) {
bgp_attr_set_lcommunity(path->attr, NULL);
- path->attr->flag &=
- ~ATTR_FLAG_BIT(BGP_ATTR_LARGE_COMMUNITIES);
lcommunity_free(&new);
} else {
bgp_attr_set_lcommunity(path->attr, new);
- path->attr->flag |=
- ATTR_FLAG_BIT(BGP_ATTR_LARGE_COMMUNITIES);
}
}
@@ -2526,12 +2516,9 @@ route_set_community_delete(void *rule, const struct prefix *prefix,
if (new->size == 0) {
bgp_attr_set_community(path->attr, NULL);
- path->attr->flag &=
- ~ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES);
community_free(&new);
} else {
bgp_attr_set_community(path->attr, new);
- path->attr->flag |= ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES);
}
}