1 /* Community attribute related functions.
2 * Copyright (C) 1998, 2001 Kunihiro Ishiguro
4 * This file is part of GNU Zebra.
6 * GNU Zebra is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2, or (at your option) any
11 * GNU Zebra is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; see the file COPYING; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
29 #include "bgpd/bgp_memory.h"
30 #include "bgpd/bgp_community.h"
31 #include "bgpd/bgp_community_alias.h"
33 /* Hash of community attribute. */
34 static struct hash
*comhash
;
36 /* Allocate a new communities value. */
37 static struct community
*community_new(void)
39 return XCALLOC(MTYPE_COMMUNITY
, sizeof(struct community
));
42 /* Free communities value. */
43 void community_free(struct community
**com
)
48 XFREE(MTYPE_COMMUNITY_VAL
, (*com
)->val
);
49 XFREE(MTYPE_COMMUNITY_STR
, (*com
)->str
);
52 json_object_free((*com
)->json
);
56 XFREE(MTYPE_COMMUNITY
, (*com
));
59 /* Add one community value to the community. */
60 void community_add_val(struct community
*com
, uint32_t val
)
63 com
->val
= XREALLOC(MTYPE_COMMUNITY_VAL
, com
->val
, com_length(com
));
66 memcpy(com_lastval(com
), &val
, sizeof(uint32_t));
69 /* Delete one community. */
70 void community_del_val(struct community
*com
, uint32_t *val
)
78 while (i
< com
->size
) {
79 if (memcmp(com
->val
+ i
, val
, sizeof(uint32_t)) == 0) {
80 c
= com
->size
- i
- 1;
83 memmove(com
->val
+ i
, com
->val
+ (i
+ 1),
89 com
->val
= XREALLOC(MTYPE_COMMUNITY_VAL
,
90 com
->val
, com_length(com
));
92 XFREE(MTYPE_COMMUNITY_VAL
, com
->val
);
100 /* Delete all communities listed in com2 from com1 */
101 struct community
*community_delete(struct community
*com1
,
102 struct community
*com2
)
106 while (i
< com2
->size
) {
107 community_del_val(com1
, com2
->val
+ i
);
114 /* Callback function from qsort(). */
115 static int community_compare(const void *a1
, const void *a2
)
120 memcpy(&v1
, a1
, sizeof(uint32_t));
121 memcpy(&v2
, a2
, sizeof(uint32_t));
132 bool community_include(struct community
*com
, uint32_t val
)
138 for (i
= 0; i
< com
->size
; i
++)
139 if (memcmp(&val
, com_nthval(com
, i
), sizeof(uint32_t)) == 0)
144 uint32_t community_val_get(struct community
*com
, int i
)
149 p
= (uint8_t *)com
->val
;
150 p
+= (i
* COMMUNITY_SIZE
);
152 memcpy(&val
, p
, sizeof(uint32_t));
157 /* Sort and uniq given community. */
158 struct community
*community_uniq_sort(struct community
*com
)
161 struct community
*new;
167 new = community_new();
170 for (i
= 0; i
< com
->size
; i
++) {
171 val
= community_val_get(com
, i
);
173 if (!community_include(new, val
))
174 community_add_val(new, val
);
177 qsort(new->val
, new->size
, sizeof(uint32_t), community_compare
);
182 /* Convert communities attribute to string.
184 For Well-known communities value, below keyword is used.
187 0xFFFF0000 "graceful-shutdown"
188 0xFFFF0001 "accept-own"
189 0xFFFF0002 "route-filter-translated-v4"
190 0xFFFF0003 "route-filter-v4"
191 0xFFFF0004 "route-filter-translated-v6"
192 0xFFFF0005 "route-filter-v6"
193 0xFFFF0006 "llgr-stale"
195 0xFFFF0008 "accept-own-nexthop"
196 0xFFFF029A "blackhole"
197 0xFFFFFF01 "no-export"
198 0xFFFFFF02 "no-advertise"
199 0xFFFFFF03 "local-AS"
202 For other values, "AS:VAL" format is used. */
203 static void set_community_string(struct community
*com
, bool make_json
,
204 bool translate_alias
)
213 json_object
*json_community_list
= NULL
;
214 json_object
*json_string
= NULL
;
220 com
->json
= json_object_new_object();
221 json_community_list
= json_object_new_array();
224 /* When communities attribute is empty. */
225 if (com
->size
== 0) {
226 str
= XMALLOC(MTYPE_COMMUNITY_STR
, 1);
230 json_object_string_add(com
->json
, "string", "");
231 json_object_object_add(com
->json
, "list",
232 json_community_list
);
238 /* Memory allocation is time consuming work. So we calculate
239 required string length first. */
242 for (i
= 0; i
< com
->size
; i
++) {
243 memcpy(&comval
, com_nthval(com
, i
), sizeof(uint32_t));
244 comval
= ntohl(comval
);
247 case COMMUNITY_INTERNET
:
248 len
+= strlen(" internet");
250 case COMMUNITY_GSHUT
:
251 len
+= strlen(" graceful-shutdown");
253 case COMMUNITY_ACCEPT_OWN
:
254 len
+= strlen(" accept-own");
256 case COMMUNITY_ROUTE_FILTER_TRANSLATED_v4
:
257 len
+= strlen(" route-filter-translated-v4");
259 case COMMUNITY_ROUTE_FILTER_v4
:
260 len
+= strlen(" route-filter-v4");
262 case COMMUNITY_ROUTE_FILTER_TRANSLATED_v6
:
263 len
+= strlen(" route-filter-translated-v6");
265 case COMMUNITY_ROUTE_FILTER_v6
:
266 len
+= strlen(" route-filter-v6");
268 case COMMUNITY_LLGR_STALE
:
269 len
+= strlen(" llgr-stale");
271 case COMMUNITY_NO_LLGR
:
272 len
+= strlen(" no-llgr");
274 case COMMUNITY_ACCEPT_OWN_NEXTHOP
:
275 len
+= strlen(" accept-own-nexthop");
277 case COMMUNITY_BLACKHOLE
:
278 len
+= strlen(" blackhole");
280 case COMMUNITY_NO_EXPORT
:
281 len
+= strlen(" no-export");
283 case COMMUNITY_NO_ADVERTISE
:
284 len
+= strlen(" no-advertise");
286 case COMMUNITY_LOCAL_AS
:
287 len
+= strlen(" local-AS");
289 case COMMUNITY_NO_PEER
:
290 len
+= strlen(" no-peer");
298 /* Allocate memory. */
299 str
= XCALLOC(MTYPE_COMMUNITY_STR
, len
);
302 /* Fill in string. */
303 for (i
= 0; i
< com
->size
; i
++) {
304 memcpy(&comval
, com_nthval(com
, i
), sizeof(uint32_t));
305 comval
= ntohl(comval
);
310 strlcat(str
, " ", len
);
313 case COMMUNITY_INTERNET
:
314 strlcat(str
, "internet", len
);
317 json_object_new_string("internet");
318 json_object_array_add(json_community_list
,
322 case COMMUNITY_GSHUT
:
323 strlcat(str
, "graceful-shutdown", len
);
325 json_string
= json_object_new_string(
327 json_object_array_add(json_community_list
,
331 case COMMUNITY_ACCEPT_OWN
:
332 strlcat(str
, "accept-own", len
);
334 json_string
= json_object_new_string(
336 json_object_array_add(json_community_list
,
340 case COMMUNITY_ROUTE_FILTER_TRANSLATED_v4
:
341 strlcat(str
, "route-filter-translated-v4", len
);
343 json_string
= json_object_new_string(
344 "routeFilterTranslatedV4");
345 json_object_array_add(json_community_list
,
349 case COMMUNITY_ROUTE_FILTER_v4
:
350 strlcat(str
, "route-filter-v4", len
);
352 json_string
= json_object_new_string(
354 json_object_array_add(json_community_list
,
358 case COMMUNITY_ROUTE_FILTER_TRANSLATED_v6
:
359 strlcat(str
, "route-filter-translated-v6", len
);
361 json_string
= json_object_new_string(
362 "routeFilterTranslatedV6");
363 json_object_array_add(json_community_list
,
367 case COMMUNITY_ROUTE_FILTER_v6
:
368 strlcat(str
, "route-filter-v6", len
);
370 json_string
= json_object_new_string(
372 json_object_array_add(json_community_list
,
376 case COMMUNITY_LLGR_STALE
:
377 strlcat(str
, "llgr-stale", len
);
379 json_string
= json_object_new_string(
381 json_object_array_add(json_community_list
,
385 case COMMUNITY_NO_LLGR
:
386 strlcat(str
, "no-llgr", len
);
388 json_string
= json_object_new_string(
390 json_object_array_add(json_community_list
,
394 case COMMUNITY_ACCEPT_OWN_NEXTHOP
:
395 strlcat(str
, "accept-own-nexthop", len
);
397 json_string
= json_object_new_string(
399 json_object_array_add(json_community_list
,
403 case COMMUNITY_BLACKHOLE
:
404 strlcat(str
, "blackhole", len
);
406 json_string
= json_object_new_string(
408 json_object_array_add(json_community_list
,
412 case COMMUNITY_NO_EXPORT
:
413 strlcat(str
, "no-export", len
);
416 json_object_new_string("noExport");
417 json_object_array_add(json_community_list
,
421 case COMMUNITY_NO_ADVERTISE
:
422 strlcat(str
, "no-advertise", len
);
425 json_object_new_string("noAdvertise");
426 json_object_array_add(json_community_list
,
430 case COMMUNITY_LOCAL_AS
:
431 strlcat(str
, "local-AS", len
);
433 json_string
= json_object_new_string("localAs");
434 json_object_array_add(json_community_list
,
438 case COMMUNITY_NO_PEER
:
439 strlcat(str
, "no-peer", len
);
441 json_string
= json_object_new_string("noPeer");
442 json_object_array_add(json_community_list
,
447 as
= (comval
>> 16) & 0xFFFF;
448 val
= comval
& 0xFFFF;
450 snprintf(buf
, sizeof(buf
), "%u:%d", as
, val
);
451 const char *com2alias
=
452 translate_alias
? bgp_community2alias(buf
)
455 strlcat(str
, com2alias
, len
);
457 json_string
= json_object_new_string(com2alias
);
458 json_object_array_add(json_community_list
,
466 json_object_string_add(com
->json
, "string", str
);
467 json_object_object_add(com
->json
, "list", json_community_list
);
472 /* Intern communities attribute. */
473 struct community
*community_intern(struct community
*com
)
475 struct community
*find
;
477 /* Assert this community structure is not interned. */
478 assert(com
->refcnt
== 0);
480 /* Lookup community hash. */
481 find
= (struct community
*)hash_get(comhash
, com
, hash_alloc_intern
);
483 /* Arguemnt com is allocated temporary. So when it is not used in
484 hash, it should be freed. */
486 community_free(&com
);
488 /* Increment refrence counter. */
493 set_community_string(find
, false, true);
498 /* Free community attribute. */
499 void community_unintern(struct community
**com
)
501 struct community
*ret
;
509 /* Pull off from hash. */
510 if ((*com
)->refcnt
== 0) {
511 /* Community value com must exist in hash. */
512 ret
= (struct community
*)hash_release(comhash
, *com
);
519 /* Create new community attribute. */
520 struct community
*community_parse(uint32_t *pnt
, unsigned short length
)
522 struct community tmp
;
523 struct community
*new;
525 /* If length is malformed return NULL. */
526 if (length
% COMMUNITY_SIZE
)
529 /* Make temporary community for hash look up. */
530 tmp
.size
= length
/ COMMUNITY_SIZE
;
533 new = community_uniq_sort(&tmp
);
535 return community_intern(new);
538 struct community
*community_dup(struct community
*com
)
540 struct community
*new;
542 new = XCALLOC(MTYPE_COMMUNITY
, sizeof(struct community
));
543 new->size
= com
->size
;
545 new->val
= XMALLOC(MTYPE_COMMUNITY_VAL
,
546 com
->size
* COMMUNITY_SIZE
);
547 memcpy(new->val
, com
->val
, com
->size
* COMMUNITY_SIZE
);
553 /* Return string representation of communities attribute. */
554 char *community_str(struct community
*com
, bool make_json
, bool translate_alias
)
559 if (make_json
&& !com
->json
&& com
->str
)
560 XFREE(MTYPE_COMMUNITY_STR
, com
->str
);
563 set_community_string(com
, make_json
, translate_alias
);
567 /* Make hash value of community attribute. This function is used by
569 unsigned int community_hash_make(const struct community
*com
)
571 uint32_t *pnt
= com
->val
;
573 return jhash2(pnt
, com
->size
, 0x43ea96c1);
576 bool community_match(const struct community
*com1
, const struct community
*com2
)
581 if (com1
== NULL
&& com2
== NULL
)
584 if (com1
== NULL
|| com2
== NULL
)
587 if (com1
->size
< com2
->size
)
590 /* Every community on com2 needs to be on com1 for this to match */
591 while (i
< com1
->size
&& j
< com2
->size
) {
592 if (memcmp(com1
->val
+ i
, com2
->val
+ j
, sizeof(uint32_t)) == 0)
603 bool community_cmp(const struct community
*com1
, const struct community
*com2
)
605 if (com1
== NULL
&& com2
== NULL
)
607 if (com1
== NULL
|| com2
== NULL
)
610 if (com1
->size
== com2
->size
)
611 if (memcmp(com1
->val
, com2
->val
, com1
->size
* COMMUNITY_SIZE
)
617 /* Add com2 to the end of com1. */
618 struct community
*community_merge(struct community
*com1
,
619 struct community
*com2
)
621 com1
->val
= XREALLOC(MTYPE_COMMUNITY_VAL
, com1
->val
,
622 (com1
->size
+ com2
->size
) * COMMUNITY_SIZE
);
624 memcpy(com1
->val
+ com1
->size
, com2
->val
, com2
->size
* COMMUNITY_SIZE
);
625 com1
->size
+= com2
->size
;
630 /* Community token enum. */
631 enum community_token
{
633 community_token_gshut
,
634 community_token_accept_own
,
635 community_token_route_filter_translated_v4
,
636 community_token_route_filter_v4
,
637 community_token_route_filter_translated_v6
,
638 community_token_route_filter_v6
,
639 community_token_llgr_stale
,
640 community_token_no_llgr
,
641 community_token_accept_own_nexthop
,
642 community_token_blackhole
,
643 community_token_no_export
,
644 community_token_no_advertise
,
645 community_token_local_as
,
646 community_token_no_peer
,
647 community_token_unknown
650 /* Helper to check if a given community is valid */
651 static bool community_valid(const char *community
)
658 frrstr_split(community
, ":", &splits
, &num
);
660 for (int i
= 0; i
< num
; i
++) {
661 if (strtoul(splits
[i
], NULL
, 10) > UINT16_MAX
)
664 if (strlen(splits
[i
]) == 0)
668 XFREE(MTYPE_TMP
, splits
[i
]);
670 XFREE(MTYPE_TMP
, splits
);
672 return (octets
< 2 || invalid
) ? false : true;
675 /* Get next community token from string. */
677 community_gettoken(const char *buf
, enum community_token
*token
, uint32_t *val
)
681 /* Skip white space. */
682 while (isspace((unsigned char)*p
))
685 /* Check the end of the line. */
689 /* Well known community string check. */
690 if (isalpha((unsigned char)*p
)) {
691 if (strncmp(p
, "internet", strlen("internet")) == 0) {
692 *val
= COMMUNITY_INTERNET
;
693 *token
= community_token_no_export
;
694 p
+= strlen("internet");
697 if (strncmp(p
, "graceful-shutdown", strlen("graceful-shutdown"))
699 *val
= COMMUNITY_GSHUT
;
700 *token
= community_token_gshut
;
701 p
+= strlen("graceful-shutdown");
704 if (strncmp(p
, "accept-own-nexthop",
705 strlen("accept-own-nexthop"))
707 *val
= COMMUNITY_ACCEPT_OWN_NEXTHOP
;
708 *token
= community_token_accept_own_nexthop
;
709 p
+= strlen("accept-own-nexthop");
712 if (strncmp(p
, "accept-own", strlen("accept-own"))
714 *val
= COMMUNITY_ACCEPT_OWN
;
715 *token
= community_token_accept_own
;
716 p
+= strlen("accept-own");
719 if (strncmp(p
, "route-filter-translated-v4",
720 strlen("route-filter-translated-v4"))
722 *val
= COMMUNITY_ROUTE_FILTER_TRANSLATED_v4
;
723 *token
= community_token_route_filter_translated_v4
;
724 p
+= strlen("route-filter-translated-v4");
727 if (strncmp(p
, "route-filter-v4", strlen("route-filter-v4"))
729 *val
= COMMUNITY_ROUTE_FILTER_v4
;
730 *token
= community_token_route_filter_v4
;
731 p
+= strlen("route-filter-v4");
734 if (strncmp(p
, "route-filter-translated-v6",
735 strlen("route-filter-translated-v6"))
737 *val
= COMMUNITY_ROUTE_FILTER_TRANSLATED_v6
;
738 *token
= community_token_route_filter_translated_v6
;
739 p
+= strlen("route-filter-translated-v6");
742 if (strncmp(p
, "route-filter-v6", strlen("route-filter-v6"))
744 *val
= COMMUNITY_ROUTE_FILTER_v6
;
745 *token
= community_token_route_filter_v6
;
746 p
+= strlen("route-filter-v6");
749 if (strncmp(p
, "llgr-stale", strlen("llgr-stale"))
751 *val
= COMMUNITY_LLGR_STALE
;
752 *token
= community_token_llgr_stale
;
753 p
+= strlen("llgr-stale");
756 if (strncmp(p
, "no-llgr", strlen("no-llgr"))
758 *val
= COMMUNITY_NO_LLGR
;
759 *token
= community_token_no_llgr
;
760 p
+= strlen("no-llgr");
763 if (strncmp(p
, "blackhole", strlen("blackhole"))
765 *val
= COMMUNITY_BLACKHOLE
;
766 *token
= community_token_blackhole
;
767 p
+= strlen("blackhole");
770 if (strncmp(p
, "no-export", strlen("no-export")) == 0) {
771 *val
= COMMUNITY_NO_EXPORT
;
772 *token
= community_token_no_export
;
773 p
+= strlen("no-export");
776 if (strncmp(p
, "no-advertise", strlen("no-advertise")) == 0) {
777 *val
= COMMUNITY_NO_ADVERTISE
;
778 *token
= community_token_no_advertise
;
779 p
+= strlen("no-advertise");
782 if (strncmp(p
, "local-AS", strlen("local-AS")) == 0) {
783 *val
= COMMUNITY_LOCAL_AS
;
784 *token
= community_token_local_as
;
785 p
+= strlen("local-AS");
788 if (strncmp(p
, "no-peer", strlen("no-peer")) == 0) {
789 *val
= COMMUNITY_NO_PEER
;
790 *token
= community_token_no_peer
;
791 p
+= strlen("no-peer");
795 /* Unknown string. */
796 *token
= community_token_unknown
;
800 /* Community value. */
801 if (isdigit((unsigned char)*p
)) {
804 uint32_t community_low
= 0;
805 uint32_t community_high
= 0;
807 if (!community_valid(p
)) {
808 *token
= community_token_unknown
;
812 while (isdigit((unsigned char)*p
) || *p
== ':') {
815 *token
= community_token_unknown
;
821 if (community_low
> UINT16_MAX
) {
823 community_token_unknown
;
827 community_high
= community_low
<< 16;
833 community_low
+= (*p
- '0');
838 *token
= community_token_unknown
;
842 *val
= community_high
+ community_low
;
843 *token
= community_token_val
;
846 *token
= community_token_unknown
;
850 /* convert string to community structure */
851 struct community
*community_str2com(const char *str
)
853 struct community
*com
= NULL
;
854 struct community
*com_sort
= NULL
;
856 enum community_token token
= community_token_unknown
;
859 str
= community_gettoken(str
, &token
, &val
);
862 case community_token_val
:
863 case community_token_gshut
:
864 case community_token_accept_own
:
865 case community_token_route_filter_translated_v4
:
866 case community_token_route_filter_v4
:
867 case community_token_route_filter_translated_v6
:
868 case community_token_route_filter_v6
:
869 case community_token_llgr_stale
:
870 case community_token_no_llgr
:
871 case community_token_accept_own_nexthop
:
872 case community_token_blackhole
:
873 case community_token_no_export
:
874 case community_token_no_advertise
:
875 case community_token_local_as
:
876 case community_token_no_peer
:
878 com
= community_new();
881 community_add_val(com
, val
);
883 case community_token_unknown
:
885 community_free(&com
);
890 com_sort
= community_uniq_sort(com
);
891 community_free(&com
);
896 /* Return communities hash entry count. */
897 unsigned long community_count(void)
899 return comhash
->count
;
902 /* Return communities hash. */
903 struct hash
*community_hash(void)
908 /* Initialize comminity related hash. */
909 void community_init(void)
912 hash_create((unsigned int (*)(const void *))community_hash_make
,
913 (bool (*)(const void *, const void *))community_cmp
,
914 "BGP Community Hash");
917 static void community_hash_free(void *data
)
919 struct community
*com
= data
;
921 community_free(&com
);
924 void community_finish(void)
926 hash_clean(comhash
, community_hash_free
);
931 static struct community
*bgp_aggr_community_lookup(
932 struct bgp_aggregate
*aggregate
,
933 struct community
*community
)
935 return hash_lookup(aggregate
->community_hash
, community
);
938 static void *bgp_aggr_community_hash_alloc(void *p
)
940 struct community
*ref
= (struct community
*)p
;
941 struct community
*community
= NULL
;
943 community
= community_dup(ref
);
947 static void bgp_aggr_community_prepare(struct hash_bucket
*hb
, void *arg
)
949 struct community
*hb_community
= hb
->data
;
950 struct community
**aggr_community
= arg
;
953 *aggr_community
= community_merge(*aggr_community
,
956 *aggr_community
= community_dup(hb_community
);
959 void bgp_aggr_community_remove(void *arg
)
961 struct community
*community
= arg
;
963 community_free(&community
);
966 void bgp_compute_aggregate_community(struct bgp_aggregate
*aggregate
,
967 struct community
*community
)
969 bgp_compute_aggregate_community_hash(aggregate
, community
);
970 bgp_compute_aggregate_community_val(aggregate
);
974 void bgp_compute_aggregate_community_hash(struct bgp_aggregate
*aggregate
,
975 struct community
*community
)
977 struct community
*aggr_community
= NULL
;
979 if ((aggregate
== NULL
) || (community
== NULL
))
982 /* Create hash if not already created.
984 if (aggregate
->community_hash
== NULL
)
985 aggregate
->community_hash
= hash_create(
986 (unsigned int (*)(const void *))community_hash_make
,
987 (bool (*)(const void *, const void *))community_cmp
,
988 "BGP Aggregator community hash");
990 aggr_community
= bgp_aggr_community_lookup(aggregate
, community
);
991 if (aggr_community
== NULL
) {
992 /* Insert community into hash.
994 aggr_community
= hash_get(aggregate
->community_hash
, community
,
995 bgp_aggr_community_hash_alloc
);
998 /* Increment reference counter.
1000 aggr_community
->refcnt
++;
1003 void bgp_compute_aggregate_community_val(struct bgp_aggregate
*aggregate
)
1005 struct community
*commerge
= NULL
;
1007 if (aggregate
== NULL
)
1010 /* Re-compute aggregate's community.
1012 if (aggregate
->community
)
1013 community_free(&aggregate
->community
);
1014 if (aggregate
->community_hash
&&
1015 aggregate
->community_hash
->count
) {
1016 hash_iterate(aggregate
->community_hash
,
1017 bgp_aggr_community_prepare
,
1018 &aggregate
->community
);
1019 commerge
= aggregate
->community
;
1020 aggregate
->community
= community_uniq_sort(commerge
);
1022 community_free(&commerge
);
1028 void bgp_remove_community_from_aggregate(struct bgp_aggregate
*aggregate
,
1029 struct community
*community
)
1031 struct community
*aggr_community
= NULL
;
1032 struct community
*ret_comm
= NULL
;
1035 || (!aggregate
->community_hash
)
1039 /* Look-up the community in the hash.
1041 aggr_community
= bgp_aggr_community_lookup(aggregate
, community
);
1042 if (aggr_community
) {
1043 aggr_community
->refcnt
--;
1045 if (aggr_community
->refcnt
== 0) {
1046 ret_comm
= hash_release(aggregate
->community_hash
,
1048 community_free(&ret_comm
);
1050 bgp_compute_aggregate_community_val(aggregate
);
1055 void bgp_remove_comm_from_aggregate_hash(struct bgp_aggregate
*aggregate
,
1056 struct community
*community
)
1059 struct community
*aggr_community
= NULL
;
1060 struct community
*ret_comm
= NULL
;
1063 || (!aggregate
->community_hash
)
1067 /* Look-up the community in the hash.
1069 aggr_community
= bgp_aggr_community_lookup(aggregate
, community
);
1070 if (aggr_community
) {
1071 aggr_community
->refcnt
--;
1073 if (aggr_community
->refcnt
== 0) {
1074 ret_comm
= hash_release(aggregate
->community_hash
,
1076 community_free(&ret_comm
);