]> git.proxmox.com Git - mirror_frr.git/commitdiff
bgpd: Reuse bgp_attr_set_[l]community() for setting attribute flags
authorDonatas Abraitis <donatas@opensourcerouting.org>
Mon, 11 Apr 2022 15:09:35 +0000 (18:09 +0300)
committerDonatas Abraitis <donatas@opensourcerouting.org>
Tue, 12 Apr 2022 19:09:28 +0000 (22:09 +0300)
Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
bgpd/bgp_attr.c
bgpd/bgp_attr.h
bgpd/bgp_mpath.c
bgpd/bgp_route.c
bgpd/bgp_routemap.c

index 2f246e61d85cdd9be028dbe07b0aee253764eead..310227f33a4e85e5d1146d6d60251a95aeb31840 100644 (file)
@@ -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;
 }
 
index 1f199da1613a73b0bf2b6c63c12d0f94f85311cc..49702a0e31b1cec81184c031ca06d05b51a1c37b 100644 (file)
@@ -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 *
index 6e695d03015bec002ef9d8555c620948a0e43e43..7ff0df74092f1570d29afbdfc376ef791601c5df 100644 (file)
@@ -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;
index a5a57bdc7ffb57cc70f12516d3004282afefc11d..99f92baf01499cf18116e104b702b87249e47a32 100644 (file)
@@ -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,
index 2ed73ddb68835ff3bb3cdfb3ac4bf616c90bbb90..df92a24ce15e4abe6b8d9977a29324c238fd98d6 100644 (file)
@@ -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);
                }
        }