From: Donald Sharp Date: Mon, 2 Nov 2020 17:35:20 +0000 (-0500) Subject: bgpd: Abstract attr->cluster to accessor/set functions X-Git-Tag: base_7.6~280^2~2 X-Git-Url: https://git.puffer.fish/?a=commitdiff_plain;h=779fee9303e24223711c27065f000faa629dc9fa;p=mirror%2Ffrr.git bgpd: Abstract attr->cluster to accessor/set functions Abstract the access of `attr->cluster` to appropriate accessor/set functionality. Future commits will allow us to move this data around to make `struct attr` smaller. Signed-off-by: Donald Sharp --- diff --git a/bgpd/bgp_attr.c b/bgpd/bgp_attr.c index c632cdc009..002d078d55 100644 --- a/bgpd/bgp_attr.c +++ b/bgpd/bgp_attr.c @@ -665,8 +665,8 @@ unsigned int attrhash_key_make(const void *p) MIX(ecommunity_hash_make(attr->ecommunity)); if (bgp_attr_get_ipv6_ecommunity(attr)) MIX(ecommunity_hash_make(bgp_attr_get_ipv6_ecommunity(attr))); - if (attr->cluster) - MIX(cluster_hash_key_make(attr->cluster)); + if (bgp_attr_get_cluster(attr)) + MIX(cluster_hash_key_make(bgp_attr_get_cluster(attr))); if (bgp_attr_get_transit(attr)) MIX(transit_hash_key_make(bgp_attr_get_transit(attr))); if (attr->encap_subtlvs) @@ -706,7 +706,8 @@ bool attrhash_cmp(const void *p1, const void *p2) && bgp_attr_get_ipv6_ecommunity(attr1) == bgp_attr_get_ipv6_ecommunity(attr2) && attr1->lcommunity == attr2->lcommunity - && attr1->cluster == attr2->cluster + && bgp_attr_get_cluster(attr1) + == bgp_attr_get_cluster(attr2) && bgp_attr_get_transit(attr1) == bgp_attr_get_transit(attr2) && attr1->rmap_table_id == attr2->rmap_table_id @@ -854,11 +855,14 @@ struct attr *bgp_attr_intern(struct attr *attr) else attr->lcommunity->refcnt++; } - if (attr->cluster) { - if (!attr->cluster->refcnt) - attr->cluster = cluster_intern(attr->cluster); + + struct cluster_list *cluster = bgp_attr_get_cluster(attr); + + if (cluster) { + if (!cluster->refcnt) + bgp_attr_set_cluster(attr, cluster_intern(cluster)); else - attr->cluster->refcnt++; + cluster->refcnt++; } struct transit *transit = bgp_attr_get_transit(attr); @@ -1044,6 +1048,7 @@ struct attr *bgp_attr_aggregate_intern( void bgp_attr_unintern_sub(struct attr *attr) { struct ecommunity *ecomm; + struct cluster_list *cluster; /* aspath refcount shoud be decrement. */ if (attr->aspath) @@ -1066,8 +1071,11 @@ void bgp_attr_unintern_sub(struct attr *attr) lcommunity_unintern(&attr->lcommunity); UNSET_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_LARGE_COMMUNITIES)); - if (attr->cluster) - cluster_unintern(&attr->cluster); + 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)); struct transit *transit = bgp_attr_get_transit(attr); @@ -1143,6 +1151,7 @@ void bgp_attr_unintern(struct attr **pattr) void bgp_attr_flush(struct attr *attr) { struct ecommunity *ecomm; + struct cluster_list *cluster; if (attr->aspath && !attr->aspath->refcnt) { aspath_free(attr->aspath); @@ -1158,9 +1167,11 @@ void bgp_attr_flush(struct attr *attr) bgp_attr_set_ipv6_ecommunity(attr, NULL); if (attr->lcommunity && !attr->lcommunity->refcnt) lcommunity_free(&attr->lcommunity); - if (attr->cluster && !attr->cluster->refcnt) { - cluster_free(attr->cluster); - attr->cluster = NULL; + + cluster = bgp_attr_get_cluster(attr); + if (cluster && !cluster->refcnt) { + cluster_free(cluster); + bgp_attr_set_cluster(attr, NULL); } struct transit *transit = bgp_attr_get_transit(attr); @@ -1949,8 +1960,9 @@ bgp_attr_cluster_list(struct bgp_attr_parser_args *args) args->total); } - attr->cluster = - cluster_parse((struct in_addr *)stream_pnt(peer->curr), length); + bgp_attr_set_cluster( + attr, cluster_parse((struct in_addr *)stream_pnt(peer->curr), + length)); /* XXX: Fix cluster_parse to use stream API and then remove this */ stream_forward_getp(peer->curr, length); @@ -3918,6 +3930,8 @@ bgp_size_t bgp_packet_attribute(struct bgp *bgp, struct peer *peer, /* Route Reflector. */ if (peer->sort == BGP_PEER_IBGP && from && from->sort == BGP_PEER_IBGP) { + struct cluster_list *cluster = bgp_attr_get_cluster(attr); + /* Originator ID. */ stream_putc(s, BGP_ATTR_FLAG_OPTIONAL); stream_putc(s, BGP_ATTR_ORIGINATOR_ID); @@ -3932,16 +3946,15 @@ bgp_size_t bgp_packet_attribute(struct bgp *bgp, struct peer *peer, stream_putc(s, BGP_ATTR_FLAG_OPTIONAL); stream_putc(s, BGP_ATTR_CLUSTER_LIST); - if (attr->cluster) { - stream_putc(s, attr->cluster->length + 4); + if (cluster) { + stream_putc(s, cluster->length + 4); /* If this peer configuration's parent BGP has * cluster_id. */ if (bgp->config & BGP_CONFIG_CLUSTER_ID) stream_put_in_addr(s, &bgp->cluster_id); else stream_put_in_addr(s, &bgp->router_id); - stream_put(s, attr->cluster->list, - attr->cluster->length); + stream_put(s, cluster->list, cluster->length); } else { stream_putc(s, 4); /* If this peer configuration's parent BGP has diff --git a/bgpd/bgp_attr.h b/bgpd/bgp_attr.h index 6f6dcf3a34..cfbf5d2534 100644 --- a/bgpd/bgp_attr.h +++ b/bgpd/bgp_attr.h @@ -185,7 +185,7 @@ struct attr { struct lcommunity *lcommunity; /* Route-Reflector Cluster attribute */ - struct cluster_list *cluster; + struct cluster_list *cluster1; /* Unknown transitive attribute. */ struct transit *transit; @@ -331,7 +331,7 @@ struct transit { #define BGP_CLUSTER_LIST_LENGTH(attr) \ (((attr)->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST)) \ - ? (attr)->cluster->length \ + ? bgp_attr_get_cluster((attr))->length \ : 0) typedef enum { @@ -491,4 +491,15 @@ static inline void bgp_attr_set_transit(struct attr *attr, { attr->transit = transit; } + +static inline struct cluster_list *bgp_attr_get_cluster(const struct attr *attr) +{ + return attr->cluster1; +} + +static inline void bgp_attr_set_cluster(struct attr *attr, + struct cluster_list *cl) +{ + attr->cluster1 = cl; +} #endif /* _QUAGGA_BGP_ATTR_H */ diff --git a/bgpd/bgp_debug.c b/bgpd/bgp_debug.c index 811634e8e0..2c076fb80b 100644 --- a/bgpd/bgp_debug.c +++ b/bgpd/bgp_debug.c @@ -429,13 +429,16 @@ bool bgp_dump_attr(struct attr *attr, char *buf, size_t size) ", originator %pI4", &attr->originator_id); if (CHECK_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))) { + struct cluster_list *cluster; int i; snprintf(buf + strlen(buf), size - strlen(buf), ", clusterlist"); - for (i = 0; i < attr->cluster->length / 4; i++) + + cluster = bgp_attr_get_cluster(attr); + for (i = 0; i < cluster->length / 4; i++) snprintfrr(buf + strlen(buf), size - strlen(buf), - " %pI4", &attr->cluster->list[i]); + " %pI4", &cluster->list[i]); } if (CHECK_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_PMSI_TUNNEL))) diff --git a/bgpd/bgp_route.c b/bgpd/bgp_route.c index 82989b6764..d9a1280d4c 100644 --- a/bgpd/bgp_route.c +++ b/bgpd/bgp_route.c @@ -1439,14 +1439,15 @@ static bool bgp_community_filter(struct peer *peer, struct attr *attr) static bool bgp_cluster_filter(struct peer *peer, struct attr *attr) { struct in_addr cluster_id; + struct cluster_list *cluster = bgp_attr_get_cluster(attr); - if (attr->cluster) { + if (cluster) { if (peer->bgp->config & BGP_CONFIG_CLUSTER_ID) cluster_id = peer->bgp->cluster_id; else cluster_id = peer->bgp->router_id; - if (cluster_loop_check(attr->cluster, cluster_id)) + if (cluster_loop_check(cluster, cluster_id)) return true; } return false; @@ -10056,6 +10057,8 @@ void route_vty_out_detail(struct vty *vty, struct bgp *bgp, } if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST)) { + struct cluster_list *cluster = + bgp_attr_get_cluster(attr); int i; if (json_paths) { @@ -10063,13 +10066,11 @@ void route_vty_out_detail(struct vty *vty, struct bgp *bgp, json_cluster_list_list = json_object_new_array(); - for (i = 0; i < attr->cluster->length / 4; - i++) { + for (i = 0; i < cluster->length / 4; i++) { json_string = json_object_new_string( - inet_ntop( - AF_INET, - &attr->cluster->list[i], - buf, sizeof(buf))); + inet_ntop(AF_INET, + &cluster->list[i], + buf, sizeof(buf))); json_object_array_add( json_cluster_list_list, json_string); @@ -10081,7 +10082,7 @@ void route_vty_out_detail(struct vty *vty, struct bgp *bgp, * do. Add this someday if someone asks * for it. * json_object_string_add(json_cluster_list, - * "string", attr->cluster->str); + * "string", cluster->str); */ json_object_object_add(json_cluster_list, "list", @@ -10091,10 +10092,9 @@ void route_vty_out_detail(struct vty *vty, struct bgp *bgp, } else { vty_out(vty, ", Cluster list: "); - for (i = 0; i < attr->cluster->length / 4; - i++) { + for (i = 0; i < cluster->length / 4; i++) { vty_out(vty, "%pI4 ", - &attr->cluster->list[i]); + &cluster->list[i]); } } } diff --git a/bgpd/rfapi/rfapi_vty.c b/bgpd/rfapi/rfapi_vty.c index c926b38c5a..7daaa01d90 100644 --- a/bgpd/rfapi/rfapi_vty.c +++ b/bgpd/rfapi/rfapi_vty.c @@ -457,6 +457,7 @@ void rfapiPrintAttrPtrs(void *stream, struct attr *attr) void *out; const char *vty_newline; struct transit *transit; + struct cluster_list *cluster; char buf[BUFSIZ]; if (rfapiStream2Vty(stream, &fp, &vty, &out, &vty_newline) == 0) @@ -477,8 +478,10 @@ void rfapiPrintAttrPtrs(void *stream, struct attr *attr) fp(out, " ecommunity=%p, refcnt=%d%s", attr->ecommunity, (attr->ecommunity ? attr->ecommunity->refcnt : 0), HVTYNL); - fp(out, " cluster=%p, refcnt=%d%s", attr->cluster, - (attr->cluster ? attr->cluster->refcnt : 0), HVTYNL); + + cluster = bgp_attr_get_cluster(attr); + fp(out, " cluster=%p, refcnt=%d%s", cluster, + (cluster ? cluster->refcnt : 0), HVTYNL); transit = bgp_attr_get_transit(attr); fp(out, " transit=%p, refcnt=%d%s", transit,