diff options
author | Donatas Abraitis <donatas.abraitis@gmail.com> | 2022-02-23 08:05:47 +0100 |
---|---|---|
committer | Donatas Abraitis <donatas.abraitis@gmail.com> | 2022-02-25 09:02:30 +0100 |
commit | 9a706b42fb968795a9e2aeed53a2b164de846c77 (patch) | |
tree | 361794995dc88698b00d9a834e1de33d89f4f930 | |
parent | Merge pull request #10615 from mobash-rasool/fixes (diff) | |
download | frr-9a706b42fb968795a9e2aeed53a2b164de846c77.tar.xz frr-9a706b42fb968795a9e2aeed53a2b164de846c77.zip |
bgpd: Reuse get/set helpers for attr->community
Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
-rw-r--r-- | bgpd/bgp_attr.c | 69 | ||||
-rw-r--r-- | bgpd/bgp_attr.h | 11 | ||||
-rw-r--r-- | bgpd/bgp_community.c | 3 | ||||
-rw-r--r-- | bgpd/bgp_debug.c | 2 | ||||
-rw-r--r-- | bgpd/bgp_evpn_vty.c | 14 | ||||
-rw-r--r-- | bgpd/bgp_fsm.c | 12 | ||||
-rw-r--r-- | bgpd/bgp_mpath.c | 14 | ||||
-rw-r--r-- | bgpd/bgp_route.c | 181 | ||||
-rw-r--r-- | bgpd/bgp_routemap.c | 24 | ||||
-rw-r--r-- | bgpd/bgp_zebra.c | 3 | ||||
-rw-r--r-- | bgpd/rfapi/rfapi_vty.c | 7 |
11 files changed, 198 insertions, 142 deletions
diff --git a/bgpd/bgp_attr.c b/bgpd/bgp_attr.c index 21f92c353..a96b63cac 100644 --- a/bgpd/bgp_attr.c +++ b/bgpd/bgp_attr.c @@ -669,9 +669,8 @@ unsigned int attrhash_key_make(const void *p) if (attr->aspath) MIX(aspath_key_make(attr->aspath)); - if (attr->community) - MIX(community_hash_make(attr->community)); - + if (bgp_attr_get_community(attr)) + MIX(community_hash_make(bgp_attr_get_community(attr))); if (bgp_attr_get_lcommunity(attr)) MIX(lcommunity_hash_make(bgp_attr_get_lcommunity(attr))); if (bgp_attr_get_ecommunity(attr)) @@ -713,7 +712,9 @@ bool attrhash_cmp(const void *p1, const void *p2) if (attr1->flag == attr2->flag && attr1->origin == attr2->origin && attr1->nexthop.s_addr == attr2->nexthop.s_addr && attr1->aspath == attr2->aspath - && attr1->community == attr2->community && attr1->med == attr2->med + && bgp_attr_get_community(attr1) + == bgp_attr_get_community(attr2) + && attr1->med == attr2->med && attr1->local_pref == attr2->local_pref && attr1->rmap_change_flags == attr2->rmap_change_flags) { if (attr1->aggregator_as == attr2->aggregator_as @@ -844,6 +845,7 @@ struct attr *bgp_attr_intern(struct attr *attr) struct ecommunity *ecomm = NULL; struct ecommunity *ipv6_ecomm = NULL; struct lcommunity *lcomm = NULL; + struct community *comm = NULL; /* Intern referenced strucutre. */ if (attr->aspath) { @@ -852,11 +854,13 @@ struct attr *bgp_attr_intern(struct attr *attr) else attr->aspath->refcnt++; } - if (attr->community) { - if (!attr->community->refcnt) - attr->community = community_intern(attr->community); + + comm = bgp_attr_get_community(attr); + if (comm) { + if (!comm->refcnt) + bgp_attr_set_community(attr, community_intern(comm)); else - attr->community->refcnt++; + comm->refcnt++; } ecomm = bgp_attr_get_ecommunity(attr); @@ -1003,7 +1007,7 @@ struct attr *bgp_attr_aggregate_intern( community_del_val(community, &gshut); } - attr.community = community; + bgp_attr_set_community(&attr, community); attr.flag |= ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES); } @@ -1084,14 +1088,16 @@ void bgp_attr_unintern_sub(struct attr *attr) struct ecommunity *ipv6_ecomm = NULL; struct cluster_list *cluster; struct lcommunity *lcomm = NULL; + struct community *comm = NULL; /* aspath refcount shoud be decrement. */ aspath_unintern(&attr->aspath); UNSET_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_AS_PATH)); - if (attr->community) - community_unintern(&attr->community); + 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); ecommunity_unintern(&ecomm); @@ -1171,21 +1177,27 @@ void bgp_attr_flush(struct attr *attr) struct ecommunity *ipv6_ecomm; struct cluster_list *cluster; struct lcommunity *lcomm; + struct community *comm; if (attr->aspath && !attr->aspath->refcnt) { aspath_free(attr->aspath); attr->aspath = NULL; } - if (attr->community && !attr->community->refcnt) - community_free(&attr->community); + comm = bgp_attr_get_community(attr); + if (comm && !comm->refcnt) + community_free(&comm); + bgp_attr_set_community(attr, NULL); + ecomm = bgp_attr_get_ecommunity(attr); if (ecomm && !ecomm->refcnt) ecommunity_free(&ecomm); bgp_attr_set_ecommunity(attr, NULL); + ipv6_ecomm = bgp_attr_get_ipv6_ecommunity(attr); if (ipv6_ecomm && !ipv6_ecomm->refcnt) ecommunity_free(&ipv6_ecomm); bgp_attr_set_ipv6_ecommunity(attr, NULL); + lcomm = bgp_attr_get_lcommunity(attr); if (lcomm && !lcomm->refcnt) lcommunity_free(&lcomm); @@ -1932,13 +1944,14 @@ bgp_attr_community(struct bgp_attr_parser_args *args) const bgp_size_t length = args->length; if (length == 0) { - attr->community = NULL; + bgp_attr_set_community(attr, NULL); return bgp_attr_malformed(args, BGP_NOTIFY_UPDATE_OPT_ATTR_ERR, args->total); } - attr->community = - community_parse((uint32_t *)stream_pnt(peer->curr), length); + bgp_attr_set_community( + attr, + community_parse((uint32_t *)stream_pnt(peer->curr), length)); /* XXX: fix community_parse to use stream API and remove this */ stream_forward_getp(peer->curr, length); @@ -1946,7 +1959,7 @@ bgp_attr_community(struct bgp_attr_parser_args *args) /* The Community attribute SHALL be considered malformed if its * length is not a non-zero multiple of 4. */ - if (!attr->community) + if (!bgp_attr_get_community(attr)) return bgp_attr_malformed(args, BGP_NOTIFY_UPDATE_OPT_ATTR_ERR, args->total); @@ -4075,20 +4088,23 @@ bgp_size_t bgp_packet_attribute(struct bgp *bgp, struct peer *peer, /* Community attribute. */ if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_SEND_COMMUNITY) && (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES))) { - if (attr->community->size * 4 > 255) { + struct community *comm = NULL; + + comm = bgp_attr_get_community(attr); + if (comm->size * 4 > 255) { stream_putc(s, BGP_ATTR_FLAG_OPTIONAL | BGP_ATTR_FLAG_TRANS | BGP_ATTR_FLAG_EXTLEN); stream_putc(s, BGP_ATTR_COMMUNITIES); - stream_putw(s, attr->community->size * 4); + stream_putw(s, comm->size * 4); } else { stream_putc(s, BGP_ATTR_FLAG_OPTIONAL | BGP_ATTR_FLAG_TRANS); stream_putc(s, BGP_ATTR_COMMUNITIES); - stream_putc(s, attr->community->size * 4); + stream_putc(s, comm->size * 4); } - stream_put(s, attr->community->val, attr->community->size * 4); + stream_put(s, comm->val, comm->size * 4); } /* @@ -4525,20 +4541,23 @@ void bgp_dump_routes_attr(struct stream *s, struct attr *attr, /* Community attribute. */ if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES)) { - if (attr->community->size * 4 > 255) { + struct community *comm = NULL; + + comm = bgp_attr_get_community(attr); + if (comm->size * 4 > 255) { stream_putc(s, BGP_ATTR_FLAG_OPTIONAL | BGP_ATTR_FLAG_TRANS | BGP_ATTR_FLAG_EXTLEN); stream_putc(s, BGP_ATTR_COMMUNITIES); - stream_putw(s, attr->community->size * 4); + stream_putw(s, comm->size * 4); } else { stream_putc(s, BGP_ATTR_FLAG_OPTIONAL | BGP_ATTR_FLAG_TRANS); stream_putc(s, BGP_ATTR_COMMUNITIES); - stream_putc(s, attr->community->size * 4); + stream_putc(s, comm->size * 4); } - stream_put(s, attr->community->val, attr->community->size * 4); + stream_put(s, comm->val, comm->size * 4); } /* Large Community attribute. */ diff --git a/bgpd/bgp_attr.h b/bgpd/bgp_attr.h index 16eb956b3..1f199da16 100644 --- a/bgpd/bgp_attr.h +++ b/bgpd/bgp_attr.h @@ -530,6 +530,17 @@ static inline void bgp_attr_set_lcommunity(struct attr *attr, attr->lcommunity = lcomm; } +static inline struct community *bgp_attr_get_community(const struct attr *attr) +{ + return attr->community; +} + +static inline void bgp_attr_set_community(struct attr *attr, + struct community *comm) +{ + attr->community = comm; +} + static inline struct ecommunity * bgp_attr_get_ipv6_ecommunity(const struct attr *attr) { diff --git a/bgpd/bgp_community.c b/bgpd/bgp_community.c index a5dafd775..6e6a3cd58 100644 --- a/bgpd/bgp_community.c +++ b/bgpd/bgp_community.c @@ -497,6 +497,9 @@ void community_unintern(struct community **com) { struct community *ret; + if (!*com) + return; + if ((*com)->refcnt) (*com)->refcnt--; diff --git a/bgpd/bgp_debug.c b/bgpd/bgp_debug.c index 82e05dc53..5d14ff0fa 100644 --- a/bgpd/bgp_debug.c +++ b/bgpd/bgp_debug.c @@ -411,7 +411,7 @@ bool bgp_dump_attr(struct attr *attr, char *buf, size_t size) if (CHECK_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES))) snprintf(buf + strlen(buf), size - strlen(buf), ", community %s", - community_str(attr->community, false)); + community_str(bgp_attr_get_community(attr), false)); if (CHECK_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_LARGE_COMMUNITIES))) snprintf(buf + strlen(buf), size - strlen(buf), diff --git a/bgpd/bgp_evpn_vty.c b/bgpd/bgp_evpn_vty.c index caf044485..d56f4f207 100644 --- a/bgpd/bgp_evpn_vty.c +++ b/bgpd/bgp_evpn_vty.c @@ -1236,6 +1236,10 @@ static int bgp_show_ethernet_vpn(struct vty *vty, struct prefix_rd *prd, no_display = 0; for (; pi; pi = pi->next) { + struct community *picomm = NULL; + + picomm = bgp_attr_get_community(pi->attr); + total_count++; if (type == bgp_show_type_neighbor) { struct peer *peer = output_arg; @@ -1268,17 +1272,15 @@ static int bgp_show_ethernet_vpn(struct vty *vty, struct prefix_rd *prd, if (type == bgp_show_type_community) { struct community *com = output_arg; - if (!pi->attr->community || - !community_match( - pi->attr->community, com)) + if (!picomm || + !community_match(picomm, com)) continue; } if (type == bgp_show_type_community_exact) { struct community *com = output_arg; - if (!pi->attr->community || - !community_cmp( - pi->attr->community, com)) + if (!picomm || + !community_cmp(picomm, com)) continue; } if (header) { diff --git a/bgpd/bgp_fsm.c b/bgpd/bgp_fsm.c index 672fa4512..c161946ca 100644 --- a/bgpd/bgp_fsm.c +++ b/bgpd/bgp_fsm.c @@ -727,9 +727,10 @@ static void bgp_set_llgr_stale(struct peer *peer, afi_t afi, safi_t safi) if (pi->peer != peer) continue; - if (pi->attr->community && + if (bgp_attr_get_community(pi->attr) && community_include( - pi->attr->community, + bgp_attr_get_community( + pi->attr), COMMUNITY_NO_LLGR)) continue; @@ -755,9 +756,10 @@ static void bgp_set_llgr_stale(struct peer *peer, afi_t afi, safi_t safi) if (pi->peer != peer) continue; - if (pi->attr->community && - community_include(pi->attr->community, - COMMUNITY_NO_LLGR)) + if (bgp_attr_get_community(pi->attr) && + community_include( + bgp_attr_get_community(pi->attr), + COMMUNITY_NO_LLGR)) continue; if (bgp_debug_neighbor_events(peer)) diff --git a/bgpd/bgp_mpath.c b/bgpd/bgp_mpath.c index 774953f6f..6e695d030 100644 --- a/bgpd/bgp_mpath.c +++ b/bgpd/bgp_mpath.c @@ -842,7 +842,9 @@ void bgp_path_info_mpath_aggregate_update(struct bgp_path_info *new_best, aspath = aspath_dup(attr.aspath); origin = attr.origin; community = - attr.community ? community_dup(attr.community) : NULL; + bgp_attr_get_community(&attr) + ? community_dup(bgp_attr_get_community(&attr)) + : NULL; ecomm = (bgp_attr_get_ecommunity(&attr)) ? ecommunity_dup(bgp_attr_get_ecommunity(&attr)) : NULL; @@ -860,17 +862,19 @@ void bgp_path_info_mpath_aggregate_update(struct bgp_path_info *new_best, if (origin < mpinfo->attr->origin) origin = mpinfo->attr->origin; - if (mpinfo->attr->community) { + if (bgp_attr_get_community(mpinfo->attr)) { if (community) { commerge = community_merge( community, - mpinfo->attr->community); + bgp_attr_get_community( + mpinfo->attr)); community = community_uniq_sort(commerge); community_free(&commerge); } else community = community_dup( - mpinfo->attr->community); + bgp_attr_get_community( + mpinfo->attr)); } if (bgp_attr_get_ecommunity(mpinfo->attr)) { @@ -902,7 +906,7 @@ void bgp_path_info_mpath_aggregate_update(struct bgp_path_info *new_best, attr.aspath = aspath; attr.origin = origin; if (community) { - attr.community = community; + bgp_attr_set_community(&attr, community); attr.flag |= ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES); } if (ecomm) { diff --git a/bgpd/bgp_route.c b/bgpd/bgp_route.c index 8311cb207..537324695 100644 --- a/bgpd/bgp_route.c +++ b/bgpd/bgp_route.c @@ -641,8 +641,9 @@ static int bgp_path_info_cmp(struct bgp *bgp, struct bgp_path_info *new, * below). See the Risks of Depreferencing Routes section (Section 5.2) * for a discussion of potential risks inherent in doing this. */ - if (newattr->community && - community_include(newattr->community, COMMUNITY_LLGR_STALE)) { + if (bgp_attr_get_community(newattr) && + community_include(bgp_attr_get_community(newattr), + COMMUNITY_LLGR_STALE)) { if (debug) zlog_debug( "%s: %s wins over %s due to LLGR_STALE community", @@ -650,8 +651,9 @@ static int bgp_path_info_cmp(struct bgp *bgp, struct bgp_path_info *new, return 0; } - if (existattr->community && - community_include(existattr->community, COMMUNITY_LLGR_STALE)) { + if (bgp_attr_get_community(existattr) && + community_include(bgp_attr_get_community(existattr), + COMMUNITY_LLGR_STALE)) { if (debug) zlog_debug( "%s: %s loses to %s due to LLGR_STALE community", @@ -1522,20 +1524,22 @@ done: /* If community attribute includes no_export then return 1. */ static bool bgp_community_filter(struct peer *peer, struct attr *attr) { - if (attr->community) { + if (bgp_attr_get_community(attr)) { /* NO_ADVERTISE check. */ - if (community_include(attr->community, COMMUNITY_NO_ADVERTISE)) + if (community_include(bgp_attr_get_community(attr), + COMMUNITY_NO_ADVERTISE)) return true; /* NO_EXPORT check. */ - if (peer->sort == BGP_PEER_EBGP - && community_include(attr->community, COMMUNITY_NO_EXPORT)) + if (peer->sort == BGP_PEER_EBGP && + community_include(bgp_attr_get_community(attr), + COMMUNITY_NO_EXPORT)) return true; /* NO_EXPORT_SUBCONFED check. */ if (peer->sort == BGP_PEER_EBGP || peer->sort == BGP_PEER_CONFED) - if (community_include(attr->community, + if (community_include(bgp_attr_get_community(attr), COMMUNITY_NO_EXPORT_SUBCONFED)) return true; } @@ -1745,7 +1749,7 @@ void bgp_attr_add_llgr_community(struct attr *attr) struct community *merge; struct community *llgr; - old = attr->community; + old = bgp_attr_get_community(attr); llgr = community_str2com("llgr-stale"); assert(llgr); @@ -1764,7 +1768,7 @@ void bgp_attr_add_llgr_community(struct attr *attr) community_free(&llgr); - attr->community = new; + bgp_attr_set_community(attr, new); attr->flag |= ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES); } @@ -1775,7 +1779,7 @@ void bgp_attr_add_gshut_community(struct attr *attr) struct community *merge; struct community *gshut; - old = attr->community; + old = bgp_attr_get_community(attr); gshut = community_str2com("graceful-shutdown"); assert(gshut); @@ -1793,7 +1797,7 @@ void bgp_attr_add_gshut_community(struct attr *attr) } community_free(&gshut); - attr->community = new; + bgp_attr_set_community(attr, new); attr->flag |= ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES); /* When we add the graceful-shutdown community we must also @@ -2262,8 +2266,9 @@ bool subgroup_announce_check(struct bgp_dest *dest, struct bgp_path_info *pi, * The route SHOULD NOT be advertised to any neighbor from which the * Long-lived Graceful Restart Capability has not been received. */ - if (attr->community && - community_include(attr->community, COMMUNITY_LLGR_STALE) && + if (bgp_attr_get_community(attr) && + community_include(bgp_attr_get_community(attr), + COMMUNITY_LLGR_STALE) && !CHECK_FLAG(peer->cap, PEER_CAP_LLGR_RCV) && !CHECK_FLAG(peer->cap, PEER_CAP_LLGR_ADV)) return false; @@ -3680,7 +3685,7 @@ static void bgp_attr_add_no_export_community(struct attr *attr) struct community *merge; struct community *no_export; - old = attr->community; + old = bgp_attr_get_community(attr); no_export = community_str2com("no-export"); assert(no_export); @@ -3699,7 +3704,7 @@ static void bgp_attr_add_no_export_community(struct attr *attr) community_free(&no_export); - attr->community = new; + bgp_attr_set_community(attr, new); attr->flag |= ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES); } @@ -3909,15 +3914,16 @@ int bgp_update(struct peer *peer, const struct prefix *p, uint32_t addpath_id, * propagation SHOULD be chosen according to the operator's * routing policy. */ - if (new_attr.community - && community_include(new_attr.community, - COMMUNITY_BLACKHOLE)) + if (bgp_attr_get_community(&new_attr) && + community_include(bgp_attr_get_community(&new_attr), + COMMUNITY_BLACKHOLE)) bgp_attr_add_no_export_community(&new_attr); /* If we receive the graceful-shutdown community from an eBGP * peer we must lower local-preference */ - if (new_attr.community - && community_include(new_attr.community, COMMUNITY_GSHUT)) { + if (bgp_attr_get_community(&new_attr) && + community_include(bgp_attr_get_community(&new_attr), + COMMUNITY_GSHUT)) { new_attr.flag |= ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF); new_attr.local_pref = BGP_GSHUT_LOCAL_PREF; @@ -5376,9 +5382,10 @@ void bgp_clear_stale_route(struct peer *peer, afi_t afi, safi_t safi) if (CHECK_FLAG( peer->af_sflags[afi][safi], PEER_STATUS_LLGR_WAIT) && - pi->attr->community && + bgp_attr_get_community(pi->attr) && !community_include( - pi->attr->community, + bgp_attr_get_community( + pi->attr), COMMUNITY_NO_LLGR)) break; if (!CHECK_FLAG(pi->flags, @@ -5409,9 +5416,10 @@ void bgp_clear_stale_route(struct peer *peer, afi_t afi, safi_t safi) continue; if (CHECK_FLAG(peer->af_sflags[afi][safi], PEER_STATUS_LLGR_WAIT) && - pi->attr->community && - !community_include(pi->attr->community, - COMMUNITY_NO_LLGR)) + bgp_attr_get_community(pi->attr) && + !community_include( + bgp_attr_get_community(pi->attr), + COMMUNITY_NO_LLGR)) break; if (!CHECK_FLAG(pi->flags, BGP_PATH_STALE)) break; @@ -7055,7 +7063,7 @@ static bool bgp_aggregate_info_same(struct bgp_path_info *pi, uint8_t origin, if (!aspath_cmp(pi->attr->aspath, (aspath) ? aspath : ae)) return false; - if (!community_cmp(pi->attr->community, comm)) + if (!community_cmp(bgp_attr_get_community(pi->attr), comm)) return false; if (!ecommunity_cmp(bgp_attr_get_ecommunity(pi->attr), ecomm)) @@ -7474,10 +7482,10 @@ void bgp_aggregate_route(struct bgp *bgp, const struct prefix *p, afi_t afi, /* Compute aggregate route's community. */ - if (pi->attr->community) + if (bgp_attr_get_community(pi->attr)) bgp_compute_aggregate_community_hash( - aggregate, - pi->attr->community); + aggregate, + bgp_attr_get_community(pi->attr)); /* Compute aggregate route's extended community. */ @@ -7596,12 +7604,13 @@ void bgp_aggregate_delete(struct bgp *bgp, const struct prefix *p, afi_t afi, aggregate, pi->attr->aspath); - if (pi->attr->community) + if (bgp_attr_get_community(pi->attr)) /* Remove community from aggregate. */ bgp_remove_comm_from_aggregate_hash( - aggregate, - pi->attr->community); + aggregate, + bgp_attr_get_community( + pi->attr)); if (bgp_attr_get_ecommunity(pi->attr)) /* Remove ecommunity from aggregate. @@ -7716,10 +7725,9 @@ static void bgp_add_route_to_aggregate(struct bgp *bgp, /* Compute aggregate route's community. */ - if (pinew->attr->community) + if (bgp_attr_get_community(pinew->attr)) bgp_compute_aggregate_community( - aggregate, - pinew->attr->community); + aggregate, bgp_attr_get_community(pinew->attr)); /* Compute aggregate route's extended community. */ @@ -7819,12 +7827,11 @@ static void bgp_remove_route_from_aggregate(struct bgp *bgp, afi_t afi, bgp_remove_aspath_from_aggregate(aggregate, pi->attr->aspath); - if (pi->attr->community) + if (bgp_attr_get_community(pi->attr)) /* Remove community from aggregate. */ bgp_remove_community_from_aggregate( - aggregate, - pi->attr->community); + aggregate, bgp_attr_get_community(pi->attr)); if (bgp_attr_get_ecommunity(pi->attr)) /* Remove ecommunity from aggregate. @@ -10503,14 +10510,16 @@ void route_vty_out_detail(struct vty *vty, struct bgp *bgp, struct bgp_dest *bn, /* Line 4 display Community */ if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES)) { if (json_paths) { - if (!attr->community->json) - community_str(attr->community, true); - json_object_lock(attr->community->json); - json_object_object_add(json_path, "community", - attr->community->json); + if (!bgp_attr_get_community(attr)->json) + community_str(bgp_attr_get_community(attr), + true); + json_object_lock(bgp_attr_get_community(attr)->json); + json_object_object_add( + json_path, "community", + bgp_attr_get_community(attr)->json); } else { vty_out(vty, " Community: %s\n", - attr->community->str); + bgp_attr_get_community(attr)->str); } } @@ -10755,8 +10764,10 @@ void route_vty_out_detail(struct vty *vty, struct bgp *bgp, struct bgp_dest *bn, gr_remaining); } - if (path->peer->t_llgr_stale[afi][safi] && attr->community && - community_include(attr->community, COMMUNITY_LLGR_STALE)) { + if (path->peer->t_llgr_stale[afi][safi] && + bgp_attr_get_community(attr) && + community_include(bgp_attr_get_community(attr), + COMMUNITY_LLGR_STALE)) { unsigned long llgr_remaining = thread_timer_remain_second( path->peer->t_llgr_stale[afi][safi]); @@ -10894,6 +10905,10 @@ static int bgp_show_table(struct vty *vty, struct bgp *bgp, safi_t safi, json_paths = NULL; for (; pi; pi = pi->next) { + struct community *picomm = NULL; + + picomm = bgp_attr_get_community(pi->attr); + total_count++; if (type == bgp_show_type_prefix_version) { @@ -10909,9 +10924,9 @@ static int bgp_show_table(struct vty *vty, struct bgp *bgp, safi_t safi, int num; bool found = false; - if (pi->attr->community) { - frrstr_split(pi->attr->community->str, - " ", &communities, &num); + if (picomm) { + frrstr_split(picomm->str, " ", + &communities, &num); for (int i = 0; i < num; i++) { const char *com2alias = bgp_community2alias( @@ -11035,36 +11050,31 @@ static int bgp_show_table(struct vty *vty, struct bgp *bgp, safi_t safi, continue; } if (type == bgp_show_type_community_all) { - if (!pi->attr->community) + if (!picomm) continue; } if (type == bgp_show_type_community) { struct community *com = output_arg; - if (!pi->attr->community - || !community_match(pi->attr->community, - com)) + if (!picomm || !community_match(picomm, com)) continue; } if (type == bgp_show_type_community_exact) { struct community *com = output_arg; - if (!pi->attr->community - || !community_cmp(pi->attr->community, com)) + if (!picomm || !community_cmp(picomm, com)) continue; } if (type == bgp_show_type_community_list) { struct community_list *list = output_arg; - if (!community_list_match(pi->attr->community, - list)) + if (!community_list_match(picomm, list)) continue; } if (type == bgp_show_type_community_list_exact) { struct community_list *list = output_arg; - if (!community_list_exact_match( - pi->attr->community, list)) + if (!community_list_exact_match(picomm, list)) continue; } if (type == bgp_show_type_lcommunity) { @@ -11482,44 +11492,43 @@ void route_vty_out_detail_header(struct vty *vty, struct bgp *bgp, vty_out(vty, "not allocated\n"); for (pi = bgp_dest_get_bgp_path_info(dest); pi; pi = pi->next) { + struct community *picomm = NULL; + + picomm = bgp_attr_get_community(pi->attr); + count++; if (CHECK_FLAG(pi->flags, BGP_PATH_SELECTED)) { best = count; if (bgp_path_suppressed(pi)) suppress = 1; - if (pi->attr->community == NULL) + if (!picomm) continue; no_advertise += community_include( - pi->attr->community, COMMUNITY_NO_ADVERTISE); - no_export += community_include(pi->attr->community, - COMMUNITY_NO_EXPORT); - local_as += community_include(pi->attr->community, - COMMUNITY_LOCAL_AS); - accept_own += community_include(pi->attr->community, - COMMUNITY_ACCEPT_OWN); + picomm, COMMUNITY_NO_ADVERTISE); + no_export += + community_include(picomm, COMMUNITY_NO_EXPORT); + local_as += + community_include(picomm, COMMUNITY_LOCAL_AS); + accept_own += + community_include(picomm, COMMUNITY_ACCEPT_OWN); route_filter_translated_v4 += community_include( - pi->attr->community, - COMMUNITY_ROUTE_FILTER_TRANSLATED_v4); + picomm, COMMUNITY_ROUTE_FILTER_TRANSLATED_v4); route_filter_translated_v6 += community_include( - pi->attr->community, - COMMUNITY_ROUTE_FILTER_TRANSLATED_v6); + picomm, COMMUNITY_ROUTE_FILTER_TRANSLATED_v6); route_filter_v4 += community_include( - pi->attr->community, COMMUNITY_ROUTE_FILTER_v4); + picomm, COMMUNITY_ROUTE_FILTER_v4); route_filter_v6 += community_include( - pi->attr->community, COMMUNITY_ROUTE_FILTER_v6); - llgr_stale += community_include(pi->attr->community, - COMMUNITY_LLGR_STALE); - no_llgr += community_include(pi->attr->community, - COMMUNITY_NO_LLGR); - accept_own_nexthop += - community_include(pi->attr->community, - COMMUNITY_ACCEPT_OWN_NEXTHOP); - blackhole += community_include(pi->attr->community, - COMMUNITY_BLACKHOLE); - no_peer += community_include(pi->attr->community, - COMMUNITY_NO_PEER); + picomm, COMMUNITY_ROUTE_FILTER_v6); + llgr_stale += + community_include(picomm, COMMUNITY_LLGR_STALE); + no_llgr += community_include(picomm, COMMUNITY_NO_LLGR); + accept_own_nexthop += community_include( + picomm, COMMUNITY_ACCEPT_OWN_NEXTHOP); + blackhole += + community_include(picomm, COMMUNITY_BLACKHOLE); + no_peer += community_include(picomm, COMMUNITY_NO_PEER); } } diff --git a/bgpd/bgp_routemap.c b/bgpd/bgp_routemap.c index efb7f9eb7..b6f31cc86 100644 --- a/bgpd/bgp_routemap.c +++ b/bgpd/bgp_routemap.c @@ -1246,10 +1246,10 @@ route_match_alias(void *rule, const struct prefix *prefix, void *object) int num; bool found; - if (path->attr->community) { + if (bgp_attr_get_community(path->attr)) { found = false; - frrstr_split(path->attr->community->str, " ", &communities, - &num); + frrstr_split(bgp_attr_get_community(path->attr)->str, " ", + &communities, &num); for (int i = 0; i < num; i++) { const char *com2alias = bgp_community2alias(communities[i]); @@ -1441,10 +1441,12 @@ route_match_community(void *rule, const struct prefix *prefix, void *object) return RMAP_NOMATCH; if (rcom->exact) { - if (community_list_exact_match(path->attr->community, list)) + if (community_list_exact_match( + bgp_attr_get_community(path->attr), list)) return RMAP_MATCH; } else { - if (community_list_match(path->attr->community, list)) + if (community_list_match(bgp_attr_get_community(path->attr), + list)) return RMAP_MATCH; } @@ -2193,12 +2195,12 @@ route_set_community(void *rule, const struct prefix *prefix, void *object) rcs = rule; path = object; attr = path->attr; - old = attr->community; + old = bgp_attr_get_community(attr); /* "none" case. */ if (rcs->none) { attr->flag &= ~(ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES)); - attr->community = NULL; + bgp_attr_set_community(attr, NULL); /* See the longer comment down below. */ if (old && old->refcnt == 0) community_free(&old); @@ -2223,7 +2225,7 @@ route_set_community(void *rule, const struct prefix *prefix, void *object) community_free(&old); /* will be interned by caller if required */ - attr->community = new; + bgp_attr_set_community(attr, new); attr->flag |= ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES); @@ -2507,7 +2509,7 @@ route_set_community_delete(void *rule, const struct prefix *prefix, path = object; list = community_list_lookup(bgp_clist, rcom->name, rcom->name_hash, COMMUNITY_LIST_MASTER); - old = path->attr->community; + old = bgp_attr_get_community(path->attr); if (list && old) { merge = community_list_match_delete(community_dup(old), list); @@ -2523,12 +2525,12 @@ route_set_community_delete(void *rule, const struct prefix *prefix, community_free(&old); if (new->size == 0) { - path->attr->community = NULL; + bgp_attr_set_community(path->attr, NULL); path->attr->flag &= ~ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES); community_free(&new); } else { - path->attr->community = new; + bgp_attr_set_community(path->attr, new); path->attr->flag |= ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES); } } diff --git a/bgpd/bgp_zebra.c b/bgpd/bgp_zebra.c index 6691dc56c..92c8d54b5 100644 --- a/bgpd/bgp_zebra.c +++ b/bgpd/bgp_zebra.c @@ -1497,7 +1497,8 @@ void bgp_zebra_announce(struct bgp_dest *dest, const struct prefix *p, sizeof(bzo.aspath)); if (info->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES)) - strlcpy(bzo.community, info->attr->community->str, + strlcpy(bzo.community, + bgp_attr_get_community(info->attr)->str, sizeof(bzo.community)); if (info->attr->flag diff --git a/bgpd/rfapi/rfapi_vty.c b/bgpd/rfapi/rfapi_vty.c index 174fadc23..b95bace0d 100644 --- a/bgpd/rfapi/rfapi_vty.c +++ b/bgpd/rfapi/rfapi_vty.c @@ -468,6 +468,7 @@ void rfapiPrintAttrPtrs(void *stream, struct attr *attr) struct cluster_list *cluster; char buf[BUFSIZ]; struct ecommunity *ecomm; + struct community *comm; if (rfapiStream2Vty(stream, &fp, &vty, &out, &vty_newline) == 0) return; @@ -482,8 +483,10 @@ void rfapiPrintAttrPtrs(void *stream, struct attr *attr) fp(out, " aspath=%p, refcnt=%d%s", attr->aspath, (attr->aspath ? attr->aspath->refcnt : 0), HVTYNL); - fp(out, " community=%p, refcnt=%d%s", attr->community, - (attr->community ? attr->community->refcnt : 0), HVTYNL); + + comm = bgp_attr_get_community(attr); + fp(out, " community=%p, refcnt=%d%s", comm, (comm ? comm->refcnt : 0), + HVTYNL); ecomm = bgp_attr_get_ecommunity(attr); fp(out, " ecommunity=%p, refcnt=%d%s", ecomm, |