bgpd: Handle cluster attribute the same way as others using setters/getters

To be consistent and error-safe.

Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
This commit is contained in:
Donatas Abraitis 2023-08-03 22:44:17 +03:00
parent 7415f1e120
commit 0a0137da85
2 changed files with 10 additions and 7 deletions

View 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));
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:

View 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 *