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"
32 /* Hash of community attribute. */
33 static struct hash
*comhash
;
35 /* Allocate a new communities value. */
36 static struct community
*community_new(void)
38 return XCALLOC(MTYPE_COMMUNITY
, sizeof(struct community
));
41 /* Free communities value. */
42 void community_free(struct community
**com
)
47 XFREE(MTYPE_COMMUNITY_VAL
, (*com
)->val
);
48 XFREE(MTYPE_COMMUNITY_STR
, (*com
)->str
);
51 json_object_free((*com
)->json
);
55 XFREE(MTYPE_COMMUNITY
, (*com
));
58 /* Add one community value to the community. */
59 static void community_add_val(struct community
*com
, uint32_t val
)
63 com
->val
= XREALLOC(MTYPE_COMMUNITY_VAL
, com
->val
,
66 com
->val
= XMALLOC(MTYPE_COMMUNITY_VAL
, com_length(com
));
69 memcpy(com_lastval(com
), &val
, sizeof(uint32_t));
72 /* Delete one community. */
73 void community_del_val(struct community
*com
, uint32_t *val
)
81 while (i
< com
->size
) {
82 if (memcmp(com
->val
+ i
, val
, sizeof(uint32_t)) == 0) {
83 c
= com
->size
- i
- 1;
86 memmove(com
->val
+ i
, com
->val
+ (i
+ 1),
92 com
->val
= XREALLOC(MTYPE_COMMUNITY_VAL
,
93 com
->val
, com_length(com
));
95 XFREE(MTYPE_COMMUNITY_VAL
, com
->val
);
103 /* Delete all communities listed in com2 from com1 */
104 struct community
*community_delete(struct community
*com1
,
105 struct community
*com2
)
109 while (i
< com2
->size
) {
110 community_del_val(com1
, com2
->val
+ i
);
117 /* Callback function from qsort(). */
118 static int community_compare(const void *a1
, const void *a2
)
123 memcpy(&v1
, a1
, sizeof(uint32_t));
124 memcpy(&v2
, a2
, sizeof(uint32_t));
135 bool community_include(struct community
*com
, uint32_t val
)
141 for (i
= 0; i
< com
->size
; i
++)
142 if (memcmp(&val
, com_nthval(com
, i
), sizeof(uint32_t)) == 0)
147 uint32_t community_val_get(struct community
*com
, int i
)
152 p
= (uint8_t *)com
->val
;
153 p
+= (i
* COMMUNITY_SIZE
);
155 memcpy(&val
, p
, sizeof(uint32_t));
160 /* Sort and uniq given community. */
161 struct community
*community_uniq_sort(struct community
*com
)
164 struct community
*new;
170 new = community_new();
173 for (i
= 0; i
< com
->size
; i
++) {
174 val
= community_val_get(com
, i
);
176 if (!community_include(new, val
))
177 community_add_val(new, val
);
180 qsort(new->val
, new->size
, sizeof(uint32_t), community_compare
);
185 /* Convert communities attribute to string.
187 For Well-known communities value, below keyword is used.
190 0xFFFF0000 "graceful-shutdown"
191 0xFFFF0001 "accept-own"
192 0xFFFF0002 "route-filter-translated-v4"
193 0xFFFF0003 "route-filter-v4"
194 0xFFFF0004 "route-filter-translated-v6"
195 0xFFFF0005 "route-filter-v6"
196 0xFFFF0006 "llgr-stale"
198 0xFFFF0008 "accept-own-nexthop"
199 0xFFFF029A "blackhole"
200 0xFFFFFF01 "no-export"
201 0xFFFFFF02 "no-advertise"
202 0xFFFFFF03 "local-AS"
205 For other values, "AS:VAL" format is used. */
206 static void set_community_string(struct community
*com
, bool make_json
)
215 json_object
*json_community_list
= NULL
;
216 json_object
*json_string
= NULL
;
222 com
->json
= json_object_new_object();
223 json_community_list
= json_object_new_array();
226 /* When communities attribute is empty. */
227 if (com
->size
== 0) {
228 str
= XMALLOC(MTYPE_COMMUNITY_STR
, 1);
232 json_object_string_add(com
->json
, "string", "");
233 json_object_object_add(com
->json
, "list",
234 json_community_list
);
240 /* Memory allocation is time consuming work. So we calculate
241 required string length first. */
244 for (i
= 0; i
< com
->size
; i
++) {
245 memcpy(&comval
, com_nthval(com
, i
), sizeof(uint32_t));
246 comval
= ntohl(comval
);
249 case COMMUNITY_INTERNET
:
250 len
+= strlen(" internet");
252 case COMMUNITY_GSHUT
:
253 len
+= strlen(" graceful-shutdown");
255 case COMMUNITY_ACCEPT_OWN
:
256 len
+= strlen(" accept-own");
258 case COMMUNITY_ROUTE_FILTER_TRANSLATED_v4
:
259 len
+= strlen(" route-filter-translated-v4");
261 case COMMUNITY_ROUTE_FILTER_v4
:
262 len
+= strlen(" route-filter-v4");
264 case COMMUNITY_ROUTE_FILTER_TRANSLATED_v6
:
265 len
+= strlen(" route-filter-translated-v6");
267 case COMMUNITY_ROUTE_FILTER_v6
:
268 len
+= strlen(" route-filter-v6");
270 case COMMUNITY_LLGR_STALE
:
271 len
+= strlen(" llgr-stale");
273 case COMMUNITY_NO_LLGR
:
274 len
+= strlen(" no-llgr");
276 case COMMUNITY_ACCEPT_OWN_NEXTHOP
:
277 len
+= strlen(" accept-own-nexthop");
279 case COMMUNITY_BLACKHOLE
:
280 len
+= strlen(" blackhole");
282 case COMMUNITY_NO_EXPORT
:
283 len
+= strlen(" no-export");
285 case COMMUNITY_NO_ADVERTISE
:
286 len
+= strlen(" no-advertise");
288 case COMMUNITY_LOCAL_AS
:
289 len
+= strlen(" local-AS");
291 case COMMUNITY_NO_PEER
:
292 len
+= strlen(" no-peer");
295 len
+= strlen(" 65536:65535");
300 /* Allocate memory. */
301 str
= XCALLOC(MTYPE_COMMUNITY_STR
, len
);
304 /* Fill in string. */
305 for (i
= 0; i
< com
->size
; i
++) {
306 memcpy(&comval
, com_nthval(com
, i
), sizeof(uint32_t));
307 comval
= ntohl(comval
);
312 strlcat(str
, " ", len
);
315 case COMMUNITY_INTERNET
:
316 strlcat(str
, "internet", len
);
319 json_object_new_string("internet");
320 json_object_array_add(json_community_list
,
324 case COMMUNITY_GSHUT
:
325 strlcat(str
, "graceful-shutdown", len
);
327 json_string
= json_object_new_string(
329 json_object_array_add(json_community_list
,
333 case COMMUNITY_ACCEPT_OWN
:
334 strlcat(str
, "accept-own", len
);
336 json_string
= json_object_new_string(
338 json_object_array_add(json_community_list
,
342 case COMMUNITY_ROUTE_FILTER_TRANSLATED_v4
:
343 strlcat(str
, "route-filter-translated-v4", len
);
345 json_string
= json_object_new_string(
346 "routeFilterTranslatedV4");
347 json_object_array_add(json_community_list
,
351 case COMMUNITY_ROUTE_FILTER_v4
:
352 strlcat(str
, "route-filter-v4", len
);
354 json_string
= json_object_new_string(
356 json_object_array_add(json_community_list
,
360 case COMMUNITY_ROUTE_FILTER_TRANSLATED_v6
:
361 strlcat(str
, "route-filter-translated-v6", len
);
363 json_string
= json_object_new_string(
364 "routeFilterTranslatedV6");
365 json_object_array_add(json_community_list
,
369 case COMMUNITY_ROUTE_FILTER_v6
:
370 strlcat(str
, "route-filter-v6", len
);
372 json_string
= json_object_new_string(
374 json_object_array_add(json_community_list
,
378 case COMMUNITY_LLGR_STALE
:
379 strlcat(str
, "llgr-stale", len
);
381 json_string
= json_object_new_string(
383 json_object_array_add(json_community_list
,
387 case COMMUNITY_NO_LLGR
:
388 strlcat(str
, "no-llgr", len
);
390 json_string
= json_object_new_string(
392 json_object_array_add(json_community_list
,
396 case COMMUNITY_ACCEPT_OWN_NEXTHOP
:
397 strlcat(str
, "accept-own-nexthop", len
);
399 json_string
= json_object_new_string(
401 json_object_array_add(json_community_list
,
405 case COMMUNITY_BLACKHOLE
:
406 strlcat(str
, "blackhole", len
);
408 json_string
= json_object_new_string(
410 json_object_array_add(json_community_list
,
414 case COMMUNITY_NO_EXPORT
:
415 strlcat(str
, "no-export", len
);
418 json_object_new_string("noExport");
419 json_object_array_add(json_community_list
,
423 case COMMUNITY_NO_ADVERTISE
:
424 strlcat(str
, "no-advertise", len
);
427 json_object_new_string("noAdvertise");
428 json_object_array_add(json_community_list
,
432 case COMMUNITY_LOCAL_AS
:
433 strlcat(str
, "local-AS", len
);
435 json_string
= json_object_new_string("localAs");
436 json_object_array_add(json_community_list
,
440 case COMMUNITY_NO_PEER
:
441 strlcat(str
, "no-peer", len
);
443 json_string
= json_object_new_string("noPeer");
444 json_object_array_add(json_community_list
,
449 as
= (comval
>> 16) & 0xFFFF;
450 val
= comval
& 0xFFFF;
452 snprintf(buf
, sizeof(buf
), "%u:%d", as
, val
);
453 strlcat(str
, buf
, len
);
455 json_string
= json_object_new_string(buf
);
456 json_object_array_add(json_community_list
,
464 json_object_string_add(com
->json
, "string", str
);
465 json_object_object_add(com
->json
, "list", json_community_list
);
470 /* Intern communities attribute. */
471 struct community
*community_intern(struct community
*com
)
473 struct community
*find
;
475 /* Assert this community structure is not interned. */
476 assert(com
->refcnt
== 0);
478 /* Lookup community hash. */
479 find
= (struct community
*)hash_get(comhash
, com
, hash_alloc_intern
);
481 /* Arguemnt com is allocated temporary. So when it is not used in
482 hash, it should be freed. */
484 community_free(&com
);
486 /* Increment refrence counter. */
491 set_community_string(find
, false);
496 /* Free community attribute. */
497 void community_unintern(struct community
**com
)
499 struct community
*ret
;
504 /* Pull off from hash. */
505 if ((*com
)->refcnt
== 0) {
506 /* Community value com must exist in hash. */
507 ret
= (struct community
*)hash_release(comhash
, *com
);
514 /* Create new community attribute. */
515 struct community
*community_parse(uint32_t *pnt
, unsigned short length
)
517 struct community tmp
;
518 struct community
*new;
520 /* If length is malformed return NULL. */
521 if (length
% COMMUNITY_SIZE
)
524 /* Make temporary community for hash look up. */
525 tmp
.size
= length
/ COMMUNITY_SIZE
;
528 new = community_uniq_sort(&tmp
);
530 return community_intern(new);
533 struct community
*community_dup(struct community
*com
)
535 struct community
*new;
537 new = XCALLOC(MTYPE_COMMUNITY
, sizeof(struct community
));
538 new->size
= com
->size
;
540 new->val
= XMALLOC(MTYPE_COMMUNITY_VAL
,
541 com
->size
* COMMUNITY_SIZE
);
542 memcpy(new->val
, com
->val
, com
->size
* COMMUNITY_SIZE
);
548 /* Retrun string representation of communities attribute. */
549 char *community_str(struct community
*com
, bool make_json
)
554 if (make_json
&& !com
->json
&& com
->str
)
555 XFREE(MTYPE_COMMUNITY_STR
, com
->str
);
558 set_community_string(com
, make_json
);
562 /* Make hash value of community attribute. This function is used by
564 unsigned int community_hash_make(const struct community
*com
)
566 uint32_t *pnt
= com
->val
;
568 return jhash2(pnt
, com
->size
, 0x43ea96c1);
571 bool community_match(const struct community
*com1
, const struct community
*com2
)
576 if (com1
== NULL
&& com2
== NULL
)
579 if (com1
== NULL
|| com2
== NULL
)
582 if (com1
->size
< com2
->size
)
585 /* Every community on com2 needs to be on com1 for this to match */
586 while (i
< com1
->size
&& j
< com2
->size
) {
587 if (memcmp(com1
->val
+ i
, com2
->val
+ j
, sizeof(uint32_t)) == 0)
598 /* If two aspath have same value then return 1 else return 0. This
599 function is used by hash package. */
600 bool community_cmp(const struct community
*com1
, const struct community
*com2
)
602 if (com1
== NULL
&& com2
== NULL
)
604 if (com1
== NULL
|| com2
== NULL
)
607 if (com1
->size
== com2
->size
)
608 if (memcmp(com1
->val
, com2
->val
, com1
->size
* COMMUNITY_SIZE
)
614 /* Add com2 to the end of com1. */
615 struct community
*community_merge(struct community
*com1
,
616 struct community
*com2
)
620 XREALLOC(MTYPE_COMMUNITY_VAL
, com1
->val
,
621 (com1
->size
+ com2
->size
) * COMMUNITY_SIZE
);
623 com1
->val
= XMALLOC(MTYPE_COMMUNITY_VAL
,
624 (com1
->size
+ com2
->size
) * COMMUNITY_SIZE
);
626 memcpy(com1
->val
+ com1
->size
, com2
->val
, com2
->size
* COMMUNITY_SIZE
);
627 com1
->size
+= com2
->size
;
632 /* Community token enum. */
633 enum community_token
{
635 community_token_gshut
,
636 community_token_accept_own
,
637 community_token_route_filter_translated_v4
,
638 community_token_route_filter_v4
,
639 community_token_route_filter_translated_v6
,
640 community_token_route_filter_v6
,
641 community_token_llgr_stale
,
642 community_token_no_llgr
,
643 community_token_accept_own_nexthop
,
644 community_token_blackhole
,
645 community_token_no_export
,
646 community_token_no_advertise
,
647 community_token_local_as
,
648 community_token_no_peer
,
649 community_token_unknown
652 /* Helper to check if a given community is valid */
653 static bool community_valid(const char *community
)
660 frrstr_split(community
, ":", &splits
, &num
);
662 for (int i
= 0; i
< num
; i
++) {
663 if (strtoul(splits
[i
], NULL
, 10) > UINT16_MAX
)
666 if (strlen(splits
[i
]) == 0)
670 XFREE(MTYPE_TMP
, splits
[i
]);
672 XFREE(MTYPE_TMP
, splits
);
674 return (octets
< 2 || invalid
) ? false : true;
677 /* Get next community token from string. */
679 community_gettoken(const char *buf
, enum community_token
*token
, uint32_t *val
)
683 /* Skip white space. */
684 while (isspace((unsigned char)*p
))
687 /* Check the end of the line. */
691 /* Well known community string check. */
692 if (isalpha((unsigned char)*p
)) {
693 if (strncmp(p
, "internet", strlen("internet")) == 0) {
694 *val
= COMMUNITY_INTERNET
;
695 *token
= community_token_no_export
;
696 p
+= strlen("internet");
699 if (strncmp(p
, "graceful-shutdown", strlen("graceful-shutdown"))
701 *val
= COMMUNITY_GSHUT
;
702 *token
= community_token_gshut
;
703 p
+= strlen("graceful-shutdown");
706 if (strncmp(p
, "accept-own-nexthop",
707 strlen("accept-own-nexthop"))
709 *val
= COMMUNITY_ACCEPT_OWN_NEXTHOP
;
710 *token
= community_token_accept_own_nexthop
;
711 p
+= strlen("accept-own-nexthop");
714 if (strncmp(p
, "accept-own", strlen("accept-own"))
716 *val
= COMMUNITY_ACCEPT_OWN
;
717 *token
= community_token_accept_own
;
718 p
+= strlen("accept-own");
721 if (strncmp(p
, "route-filter-translated-v4",
722 strlen("route-filter-translated-v4"))
724 *val
= COMMUNITY_ROUTE_FILTER_TRANSLATED_v4
;
725 *token
= community_token_route_filter_translated_v4
;
726 p
+= strlen("route-filter-translated-v4");
729 if (strncmp(p
, "route-filter-v4", strlen("route-filter-v4"))
731 *val
= COMMUNITY_ROUTE_FILTER_v4
;
732 *token
= community_token_route_filter_v4
;
733 p
+= strlen("route-filter-v4");
736 if (strncmp(p
, "route-filter-translated-v6",
737 strlen("route-filter-translated-v6"))
739 *val
= COMMUNITY_ROUTE_FILTER_TRANSLATED_v6
;
740 *token
= community_token_route_filter_translated_v6
;
741 p
+= strlen("route-filter-translated-v6");
744 if (strncmp(p
, "route-filter-v6", strlen("route-filter-v6"))
746 *val
= COMMUNITY_ROUTE_FILTER_v6
;
747 *token
= community_token_route_filter_v6
;
748 p
+= strlen("route-filter-v6");
751 if (strncmp(p
, "llgr-stale", strlen("llgr-stale"))
753 *val
= COMMUNITY_LLGR_STALE
;
754 *token
= community_token_llgr_stale
;
755 p
+= strlen("llgr-stale");
758 if (strncmp(p
, "no-llgr", strlen("no-llgr"))
760 *val
= COMMUNITY_NO_LLGR
;
761 *token
= community_token_no_llgr
;
762 p
+= strlen("no-llgr");
765 if (strncmp(p
, "blackhole", strlen("blackhole"))
767 *val
= COMMUNITY_BLACKHOLE
;
768 *token
= community_token_blackhole
;
769 p
+= strlen("blackhole");
772 if (strncmp(p
, "no-export", strlen("no-export")) == 0) {
773 *val
= COMMUNITY_NO_EXPORT
;
774 *token
= community_token_no_export
;
775 p
+= strlen("no-export");
778 if (strncmp(p
, "no-advertise", strlen("no-advertise")) == 0) {
779 *val
= COMMUNITY_NO_ADVERTISE
;
780 *token
= community_token_no_advertise
;
781 p
+= strlen("no-advertise");
784 if (strncmp(p
, "local-AS", strlen("local-AS")) == 0) {
785 *val
= COMMUNITY_LOCAL_AS
;
786 *token
= community_token_local_as
;
787 p
+= strlen("local-AS");
790 if (strncmp(p
, "no-peer", strlen("no-peer")) == 0) {
791 *val
= COMMUNITY_NO_PEER
;
792 *token
= community_token_no_peer
;
793 p
+= strlen("no-peer");
797 /* Unknown string. */
798 *token
= community_token_unknown
;
802 /* Community value. */
803 if (isdigit((unsigned char)*p
)) {
806 uint32_t community_low
= 0;
807 uint32_t community_high
= 0;
809 if (!community_valid(p
)) {
810 *token
= community_token_unknown
;
814 while (isdigit((unsigned char)*p
) || *p
== ':') {
817 *token
= community_token_unknown
;
823 if (community_low
> UINT16_MAX
) {
825 community_token_unknown
;
829 community_high
= community_low
<< 16;
835 community_low
+= (*p
- '0');
840 *token
= community_token_unknown
;
844 *val
= community_high
+ community_low
;
845 *token
= community_token_val
;
848 *token
= community_token_unknown
;
852 /* convert string to community structure */
853 struct community
*community_str2com(const char *str
)
855 struct community
*com
= NULL
;
856 struct community
*com_sort
= NULL
;
858 enum community_token token
= community_token_unknown
;
861 str
= community_gettoken(str
, &token
, &val
);
864 case community_token_val
:
865 case community_token_gshut
:
866 case community_token_accept_own
:
867 case community_token_route_filter_translated_v4
:
868 case community_token_route_filter_v4
:
869 case community_token_route_filter_translated_v6
:
870 case community_token_route_filter_v6
:
871 case community_token_llgr_stale
:
872 case community_token_no_llgr
:
873 case community_token_accept_own_nexthop
:
874 case community_token_blackhole
:
875 case community_token_no_export
:
876 case community_token_no_advertise
:
877 case community_token_local_as
:
878 case community_token_no_peer
:
880 com
= community_new();
883 community_add_val(com
, val
);
885 case community_token_unknown
:
887 community_free(&com
);
892 com_sort
= community_uniq_sort(com
);
893 community_free(&com
);
898 /* Return communities hash entry count. */
899 unsigned long community_count(void)
901 return comhash
->count
;
904 /* Return communities hash. */
905 struct hash
*community_hash(void)
910 /* Initialize comminity related hash. */
911 void community_init(void)
914 hash_create((unsigned int (*)(const void *))community_hash_make
,
915 (bool (*)(const void *, const void *))community_cmp
,
916 "BGP Community Hash");
919 void community_finish(void)
925 static struct community
*bgp_aggr_community_lookup(
926 struct bgp_aggregate
*aggregate
,
927 struct community
*community
)
929 return hash_lookup(aggregate
->community_hash
, community
);
932 static void *bgp_aggr_communty_hash_alloc(void *p
)
934 struct community
*ref
= (struct community
*)p
;
935 struct community
*community
= NULL
;
937 community
= community_dup(ref
);
941 static void bgp_aggr_community_prepare(struct hash_bucket
*hb
, void *arg
)
943 struct community
*hb_community
= hb
->data
;
944 struct community
**aggr_community
= arg
;
947 *aggr_community
= community_merge(*aggr_community
,
950 *aggr_community
= community_dup(hb_community
);
953 void bgp_aggr_community_remove(void *arg
)
955 struct community
*community
= arg
;
957 community_free(&community
);
960 void bgp_compute_aggregate_community(struct bgp_aggregate
*aggregate
,
961 struct community
*community
)
963 bgp_compute_aggregate_community_hash(aggregate
, community
);
964 bgp_compute_aggregate_community_val(aggregate
);
968 void bgp_compute_aggregate_community_hash(struct bgp_aggregate
*aggregate
,
969 struct community
*community
)
971 struct community
*aggr_community
= NULL
;
973 if ((aggregate
== NULL
) || (community
== NULL
))
976 /* Create hash if not already created.
978 if (aggregate
->community_hash
== NULL
)
979 aggregate
->community_hash
= hash_create(
980 (unsigned int (*)(const void *))community_hash_make
,
981 (bool (*)(const void *, const void *))community_cmp
,
982 "BGP Aggregator community hash");
984 aggr_community
= bgp_aggr_community_lookup(aggregate
, community
);
985 if (aggr_community
== NULL
) {
986 /* Insert community into hash.
988 aggr_community
= hash_get(aggregate
->community_hash
, community
,
989 bgp_aggr_communty_hash_alloc
);
992 /* Increment reference counter.
994 aggr_community
->refcnt
++;
997 void bgp_compute_aggregate_community_val(struct bgp_aggregate
*aggregate
)
999 struct community
*commerge
= NULL
;
1001 if (aggregate
== NULL
)
1004 /* Re-compute aggregate's community.
1006 if (aggregate
->community
)
1007 community_free(&aggregate
->community
);
1008 if (aggregate
->community_hash
&&
1009 aggregate
->community_hash
->count
) {
1010 hash_iterate(aggregate
->community_hash
,
1011 bgp_aggr_community_prepare
,
1012 &aggregate
->community
);
1013 commerge
= aggregate
->community
;
1014 aggregate
->community
= community_uniq_sort(commerge
);
1016 community_free(&commerge
);
1022 void bgp_remove_community_from_aggregate(struct bgp_aggregate
*aggregate
,
1023 struct community
*community
)
1025 struct community
*aggr_community
= NULL
;
1026 struct community
*ret_comm
= NULL
;
1029 || (!aggregate
->community_hash
)
1033 /* Look-up the community in the hash.
1035 aggr_community
= bgp_aggr_community_lookup(aggregate
, community
);
1036 if (aggr_community
) {
1037 aggr_community
->refcnt
--;
1039 if (aggr_community
->refcnt
== 0) {
1040 ret_comm
= hash_release(aggregate
->community_hash
,
1042 community_free(&ret_comm
);
1044 bgp_compute_aggregate_community_val(aggregate
);
1049 void bgp_remove_comm_from_aggregate_hash(struct bgp_aggregate
*aggregate
,
1050 struct community
*community
)
1053 struct community
*aggr_community
= NULL
;
1054 struct community
*ret_comm
= NULL
;
1057 || (!aggregate
->community_hash
)
1061 /* Look-up the community in the hash.
1063 aggr_community
= bgp_aggr_community_lookup(aggregate
, community
);
1064 if (aggr_community
) {
1065 aggr_community
->refcnt
--;
1067 if (aggr_community
->refcnt
== 0) {
1068 ret_comm
= hash_release(aggregate
->community_hash
,
1070 community_free(&ret_comm
);