]> git.puffer.fish Git - matthieu/frr.git/commitdiff
bgpd: Handle cluster attribute the same way as others using setters/getters
authorDonatas Abraitis <donatas@opensourcerouting.org>
Thu, 3 Aug 2023 19:44:17 +0000 (22:44 +0300)
committerDonatas Abraitis <donatas@opensourcerouting.org>
Thu, 3 Aug 2023 19:44:17 +0000 (22:44 +0300)
To be consistent and error-safe.

Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
bgpd/bgp_attr.c
bgpd/bgp_attr.h

index e6c44a760ae6b897f324b08129e0f1e07d7b0832..1321ab32c07ba796d154ece7c0bb5331501941e5 100644 (file)
@@ -167,6 +167,9 @@ static struct cluster_list *cluster_intern(struct cluster_list *cluster)
 
 static void cluster_unintern(struct cluster_list **cluster)
 {
+       if (!*cluster)
+               return;
+
        if ((*cluster)->refcnt)
                (*cluster)->refcnt--;
 
@@ -1205,11 +1208,8 @@ void bgp_attr_unintern_sub(struct attr *attr)
        bgp_attr_set_lcommunity(attr, NULL);
 
        cluster = bgp_attr_get_cluster(attr);
-       if (cluster) {
-               cluster_unintern(&cluster);
-               bgp_attr_set_cluster(attr, cluster);
-       }
-       UNSET_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST));
+       cluster_unintern(&cluster);
+       bgp_attr_set_cluster(attr, NULL);
 
        struct transit *transit = bgp_attr_get_transit(attr);
 
@@ -2214,8 +2214,6 @@ bgp_attr_cluster_list(struct bgp_attr_parser_args *args)
        /* XXX: Fix cluster_parse to use stream API and then remove this */
        stream_forward_getp(peer->curr, length);
 
-       attr->flag |= ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST);
-
        return BGP_ATTR_PARSE_PROCEED;
 
 cluster_list_ignore:
index 415df2ce53ed5d693032614286272c5d9e1682f7..f1296af1595457b0985e8d3200a167322a0f00dc 100644 (file)
@@ -606,6 +606,11 @@ static inline void bgp_attr_set_cluster(struct attr *attr,
                                        struct cluster_list *cl)
 {
        attr->cluster1 = cl;
+
+       if (cl)
+               SET_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST));
+       else
+               UNSET_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST));
 }
 
 static inline const struct bgp_route_evpn *