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
)
64 com
->val
= XREALLOC(MTYPE_COMMUNITY_VAL
, com
->val
,
67 com
->val
= XMALLOC(MTYPE_COMMUNITY_VAL
, com_length(com
));
70 memcpy(com_lastval(com
), &val
, sizeof(uint32_t));
73 /* Delete one community. */
74 void community_del_val(struct community
*com
, uint32_t *val
)
82 while (i
< com
->size
) {
83 if (memcmp(com
->val
+ i
, val
, sizeof(uint32_t)) == 0) {
84 c
= com
->size
- i
- 1;
87 memmove(com
->val
+ i
, com
->val
+ (i
+ 1),
93 com
->val
= XREALLOC(MTYPE_COMMUNITY_VAL
,
94 com
->val
, com_length(com
));
96 XFREE(MTYPE_COMMUNITY_VAL
, com
->val
);
104 /* Delete all communities listed in com2 from com1 */
105 struct community
*community_delete(struct community
*com1
,
106 struct community
*com2
)
110 while (i
< com2
->size
) {
111 community_del_val(com1
, com2
->val
+ i
);
118 /* Callback function from qsort(). */
119 static int community_compare(const void *a1
, const void *a2
)
124 memcpy(&v1
, a1
, sizeof(uint32_t));
125 memcpy(&v2
, a2
, sizeof(uint32_t));
136 bool community_include(struct community
*com
, uint32_t val
)
142 for (i
= 0; i
< com
->size
; i
++)
143 if (memcmp(&val
, com_nthval(com
, i
), sizeof(uint32_t)) == 0)
148 uint32_t community_val_get(struct community
*com
, int i
)
153 p
= (uint8_t *)com
->val
;
154 p
+= (i
* COMMUNITY_SIZE
);
156 memcpy(&val
, p
, sizeof(uint32_t));
161 /* Sort and uniq given community. */
162 struct community
*community_uniq_sort(struct community
*com
)
165 struct community
*new;
171 new = community_new();
174 for (i
= 0; i
< com
->size
; i
++) {
175 val
= community_val_get(com
, i
);
177 if (!community_include(new, val
))
178 community_add_val(new, val
);
181 qsort(new->val
, new->size
, sizeof(uint32_t), community_compare
);
186 /* Convert communities attribute to string.
188 For Well-known communities value, below keyword is used.
191 0xFFFF0000 "graceful-shutdown"
192 0xFFFF0001 "accept-own"
193 0xFFFF0002 "route-filter-translated-v4"
194 0xFFFF0003 "route-filter-v4"
195 0xFFFF0004 "route-filter-translated-v6"
196 0xFFFF0005 "route-filter-v6"
197 0xFFFF0006 "llgr-stale"
199 0xFFFF0008 "accept-own-nexthop"
200 0xFFFF029A "blackhole"
201 0xFFFFFF01 "no-export"
202 0xFFFFFF02 "no-advertise"
203 0xFFFFFF03 "local-AS"
206 For other values, "AS:VAL" format is used. */
207 static void set_community_string(struct community
*com
, bool make_json
)
216 json_object
*json_community_list
= NULL
;
217 json_object
*json_string
= NULL
;
223 com
->json
= json_object_new_object();
224 json_community_list
= json_object_new_array();
227 /* When communities attribute is empty. */
228 if (com
->size
== 0) {
229 str
= XMALLOC(MTYPE_COMMUNITY_STR
, 1);
233 json_object_string_add(com
->json
, "string", "");
234 json_object_object_add(com
->json
, "list",
235 json_community_list
);
241 /* Memory allocation is time consuming work. So we calculate
242 required string length first. */
245 for (i
= 0; i
< com
->size
; i
++) {
246 memcpy(&comval
, com_nthval(com
, i
), sizeof(uint32_t));
247 comval
= ntohl(comval
);
250 case COMMUNITY_INTERNET
:
251 len
+= strlen(" internet");
253 case COMMUNITY_GSHUT
:
254 len
+= strlen(" graceful-shutdown");
256 case COMMUNITY_ACCEPT_OWN
:
257 len
+= strlen(" accept-own");
259 case COMMUNITY_ROUTE_FILTER_TRANSLATED_v4
:
260 len
+= strlen(" route-filter-translated-v4");
262 case COMMUNITY_ROUTE_FILTER_v4
:
263 len
+= strlen(" route-filter-v4");
265 case COMMUNITY_ROUTE_FILTER_TRANSLATED_v6
:
266 len
+= strlen(" route-filter-translated-v6");
268 case COMMUNITY_ROUTE_FILTER_v6
:
269 len
+= strlen(" route-filter-v6");
271 case COMMUNITY_LLGR_STALE
:
272 len
+= strlen(" llgr-stale");
274 case COMMUNITY_NO_LLGR
:
275 len
+= strlen(" no-llgr");
277 case COMMUNITY_ACCEPT_OWN_NEXTHOP
:
278 len
+= strlen(" accept-own-nexthop");
280 case COMMUNITY_BLACKHOLE
:
281 len
+= strlen(" blackhole");
283 case COMMUNITY_NO_EXPORT
:
284 len
+= strlen(" no-export");
286 case COMMUNITY_NO_ADVERTISE
:
287 len
+= strlen(" no-advertise");
289 case COMMUNITY_LOCAL_AS
:
290 len
+= strlen(" local-AS");
292 case COMMUNITY_NO_PEER
:
293 len
+= strlen(" no-peer");
301 /* Allocate memory. */
302 str
= XCALLOC(MTYPE_COMMUNITY_STR
, len
);
305 /* Fill in string. */
306 for (i
= 0; i
< com
->size
; i
++) {
307 memcpy(&comval
, com_nthval(com
, i
), sizeof(uint32_t));
308 comval
= ntohl(comval
);
313 strlcat(str
, " ", len
);
316 case COMMUNITY_INTERNET
:
317 strlcat(str
, "internet", len
);
320 json_object_new_string("internet");
321 json_object_array_add(json_community_list
,
325 case COMMUNITY_GSHUT
:
326 strlcat(str
, "graceful-shutdown", len
);
328 json_string
= json_object_new_string(
330 json_object_array_add(json_community_list
,
334 case COMMUNITY_ACCEPT_OWN
:
335 strlcat(str
, "accept-own", len
);
337 json_string
= json_object_new_string(
339 json_object_array_add(json_community_list
,
343 case COMMUNITY_ROUTE_FILTER_TRANSLATED_v4
:
344 strlcat(str
, "route-filter-translated-v4", len
);
346 json_string
= json_object_new_string(
347 "routeFilterTranslatedV4");
348 json_object_array_add(json_community_list
,
352 case COMMUNITY_ROUTE_FILTER_v4
:
353 strlcat(str
, "route-filter-v4", len
);
355 json_string
= json_object_new_string(
357 json_object_array_add(json_community_list
,
361 case COMMUNITY_ROUTE_FILTER_TRANSLATED_v6
:
362 strlcat(str
, "route-filter-translated-v6", len
);
364 json_string
= json_object_new_string(
365 "routeFilterTranslatedV6");
366 json_object_array_add(json_community_list
,
370 case COMMUNITY_ROUTE_FILTER_v6
:
371 strlcat(str
, "route-filter-v6", len
);
373 json_string
= json_object_new_string(
375 json_object_array_add(json_community_list
,
379 case COMMUNITY_LLGR_STALE
:
380 strlcat(str
, "llgr-stale", len
);
382 json_string
= json_object_new_string(
384 json_object_array_add(json_community_list
,
388 case COMMUNITY_NO_LLGR
:
389 strlcat(str
, "no-llgr", len
);
391 json_string
= json_object_new_string(
393 json_object_array_add(json_community_list
,
397 case COMMUNITY_ACCEPT_OWN_NEXTHOP
:
398 strlcat(str
, "accept-own-nexthop", len
);
400 json_string
= json_object_new_string(
402 json_object_array_add(json_community_list
,
406 case COMMUNITY_BLACKHOLE
:
407 strlcat(str
, "blackhole", len
);
409 json_string
= json_object_new_string(
411 json_object_array_add(json_community_list
,
415 case COMMUNITY_NO_EXPORT
:
416 strlcat(str
, "no-export", len
);
419 json_object_new_string("noExport");
420 json_object_array_add(json_community_list
,
424 case COMMUNITY_NO_ADVERTISE
:
425 strlcat(str
, "no-advertise", len
);
428 json_object_new_string("noAdvertise");
429 json_object_array_add(json_community_list
,
433 case COMMUNITY_LOCAL_AS
:
434 strlcat(str
, "local-AS", len
);
436 json_string
= json_object_new_string("localAs");
437 json_object_array_add(json_community_list
,
441 case COMMUNITY_NO_PEER
:
442 strlcat(str
, "no-peer", len
);
444 json_string
= json_object_new_string("noPeer");
445 json_object_array_add(json_community_list
,
450 as
= (comval
>> 16) & 0xFFFF;
451 val
= comval
& 0xFFFF;
453 snprintf(buf
, sizeof(buf
), "%u:%d", as
, val
);
454 strlcat(str
, bgp_community2alias(buf
), len
);
456 json_string
= json_object_new_string(buf
);
457 json_object_array_add(json_community_list
,
465 json_object_string_add(com
->json
, "string", str
);
466 json_object_object_add(com
->json
, "list", json_community_list
);
471 /* Intern communities attribute. */
472 struct community
*community_intern(struct community
*com
)
474 struct community
*find
;
476 /* Assert this community structure is not interned. */
477 assert(com
->refcnt
== 0);
479 /* Lookup community hash. */
480 find
= (struct community
*)hash_get(comhash
, com
, hash_alloc_intern
);
482 /* Arguemnt com is allocated temporary. So when it is not used in
483 hash, it should be freed. */
485 community_free(&com
);
487 /* Increment refrence counter. */
492 set_community_string(find
, false);
497 /* Free community attribute. */
498 void community_unintern(struct community
**com
)
500 struct community
*ret
;
505 /* Pull off from hash. */
506 if ((*com
)->refcnt
== 0) {
507 /* Community value com must exist in hash. */
508 ret
= (struct community
*)hash_release(comhash
, *com
);
515 /* Create new community attribute. */
516 struct community
*community_parse(uint32_t *pnt
, unsigned short length
)
518 struct community tmp
;
519 struct community
*new;
521 /* If length is malformed return NULL. */
522 if (length
% COMMUNITY_SIZE
)
525 /* Make temporary community for hash look up. */
526 tmp
.size
= length
/ COMMUNITY_SIZE
;
529 new = community_uniq_sort(&tmp
);
531 return community_intern(new);
534 struct community
*community_dup(struct community
*com
)
536 struct community
*new;
538 new = XCALLOC(MTYPE_COMMUNITY
, sizeof(struct community
));
539 new->size
= com
->size
;
541 new->val
= XMALLOC(MTYPE_COMMUNITY_VAL
,
542 com
->size
* COMMUNITY_SIZE
);
543 memcpy(new->val
, com
->val
, com
->size
* COMMUNITY_SIZE
);
549 /* Retrun string representation of communities attribute. */
550 char *community_str(struct community
*com
, bool make_json
)
555 if (make_json
&& !com
->json
&& com
->str
)
556 XFREE(MTYPE_COMMUNITY_STR
, com
->str
);
559 set_community_string(com
, make_json
);
563 /* Make hash value of community attribute. This function is used by
565 unsigned int community_hash_make(const struct community
*com
)
567 uint32_t *pnt
= com
->val
;
569 return jhash2(pnt
, com
->size
, 0x43ea96c1);
572 bool community_match(const struct community
*com1
, const struct community
*com2
)
577 if (com1
== NULL
&& com2
== NULL
)
580 if (com1
== NULL
|| com2
== NULL
)
583 if (com1
->size
< com2
->size
)
586 /* Every community on com2 needs to be on com1 for this to match */
587 while (i
< com1
->size
&& j
< com2
->size
) {
588 if (memcmp(com1
->val
+ i
, com2
->val
+ j
, sizeof(uint32_t)) == 0)
599 /* If two aspath have same value then return 1 else return 0. This
600 function is used by hash package. */
601 bool community_cmp(const struct community
*com1
, const struct community
*com2
)
603 if (com1
== NULL
&& com2
== NULL
)
605 if (com1
== NULL
|| com2
== NULL
)
608 if (com1
->size
== com2
->size
)
609 if (memcmp(com1
->val
, com2
->val
, com1
->size
* COMMUNITY_SIZE
)
615 /* Add com2 to the end of com1. */
616 struct community
*community_merge(struct community
*com1
,
617 struct community
*com2
)
621 XREALLOC(MTYPE_COMMUNITY_VAL
, com1
->val
,
622 (com1
->size
+ com2
->size
) * COMMUNITY_SIZE
);
624 com1
->val
= XMALLOC(MTYPE_COMMUNITY_VAL
,
625 (com1
->size
+ com2
->size
) * COMMUNITY_SIZE
);
627 memcpy(com1
->val
+ com1
->size
, com2
->val
, com2
->size
* COMMUNITY_SIZE
);
628 com1
->size
+= com2
->size
;
633 /* Community token enum. */
634 enum community_token
{
636 community_token_gshut
,
637 community_token_accept_own
,
638 community_token_route_filter_translated_v4
,
639 community_token_route_filter_v4
,
640 community_token_route_filter_translated_v6
,
641 community_token_route_filter_v6
,
642 community_token_llgr_stale
,
643 community_token_no_llgr
,
644 community_token_accept_own_nexthop
,
645 community_token_blackhole
,
646 community_token_no_export
,
647 community_token_no_advertise
,
648 community_token_local_as
,
649 community_token_no_peer
,
650 community_token_unknown
653 /* Helper to check if a given community is valid */
654 static bool community_valid(const char *community
)
661 frrstr_split(community
, ":", &splits
, &num
);
663 for (int i
= 0; i
< num
; i
++) {
664 if (strtoul(splits
[i
], NULL
, 10) > UINT16_MAX
)
667 if (strlen(splits
[i
]) == 0)
671 XFREE(MTYPE_TMP
, splits
[i
]);
673 XFREE(MTYPE_TMP
, splits
);
675 return (octets
< 2 || invalid
) ? false : true;
678 /* Get next community token from string. */
680 community_gettoken(const char *buf
, enum community_token
*token
, uint32_t *val
)
684 /* Skip white space. */
685 while (isspace((unsigned char)*p
))
688 /* Check the end of the line. */
692 /* Well known community string check. */
693 if (isalpha((unsigned char)*p
)) {
694 if (strncmp(p
, "internet", strlen("internet")) == 0) {
695 *val
= COMMUNITY_INTERNET
;
696 *token
= community_token_no_export
;
697 p
+= strlen("internet");
700 if (strncmp(p
, "graceful-shutdown", strlen("graceful-shutdown"))
702 *val
= COMMUNITY_GSHUT
;
703 *token
= community_token_gshut
;
704 p
+= strlen("graceful-shutdown");
707 if (strncmp(p
, "accept-own-nexthop",
708 strlen("accept-own-nexthop"))
710 *val
= COMMUNITY_ACCEPT_OWN_NEXTHOP
;
711 *token
= community_token_accept_own_nexthop
;
712 p
+= strlen("accept-own-nexthop");
715 if (strncmp(p
, "accept-own", strlen("accept-own"))
717 *val
= COMMUNITY_ACCEPT_OWN
;
718 *token
= community_token_accept_own
;
719 p
+= strlen("accept-own");
722 if (strncmp(p
, "route-filter-translated-v4",
723 strlen("route-filter-translated-v4"))
725 *val
= COMMUNITY_ROUTE_FILTER_TRANSLATED_v4
;
726 *token
= community_token_route_filter_translated_v4
;
727 p
+= strlen("route-filter-translated-v4");
730 if (strncmp(p
, "route-filter-v4", strlen("route-filter-v4"))
732 *val
= COMMUNITY_ROUTE_FILTER_v4
;
733 *token
= community_token_route_filter_v4
;
734 p
+= strlen("route-filter-v4");
737 if (strncmp(p
, "route-filter-translated-v6",
738 strlen("route-filter-translated-v6"))
740 *val
= COMMUNITY_ROUTE_FILTER_TRANSLATED_v6
;
741 *token
= community_token_route_filter_translated_v6
;
742 p
+= strlen("route-filter-translated-v6");
745 if (strncmp(p
, "route-filter-v6", strlen("route-filter-v6"))
747 *val
= COMMUNITY_ROUTE_FILTER_v6
;
748 *token
= community_token_route_filter_v6
;
749 p
+= strlen("route-filter-v6");
752 if (strncmp(p
, "llgr-stale", strlen("llgr-stale"))
754 *val
= COMMUNITY_LLGR_STALE
;
755 *token
= community_token_llgr_stale
;
756 p
+= strlen("llgr-stale");
759 if (strncmp(p
, "no-llgr", strlen("no-llgr"))
761 *val
= COMMUNITY_NO_LLGR
;
762 *token
= community_token_no_llgr
;
763 p
+= strlen("no-llgr");
766 if (strncmp(p
, "blackhole", strlen("blackhole"))
768 *val
= COMMUNITY_BLACKHOLE
;
769 *token
= community_token_blackhole
;
770 p
+= strlen("blackhole");
773 if (strncmp(p
, "no-export", strlen("no-export")) == 0) {
774 *val
= COMMUNITY_NO_EXPORT
;
775 *token
= community_token_no_export
;
776 p
+= strlen("no-export");
779 if (strncmp(p
, "no-advertise", strlen("no-advertise")) == 0) {
780 *val
= COMMUNITY_NO_ADVERTISE
;
781 *token
= community_token_no_advertise
;
782 p
+= strlen("no-advertise");
785 if (strncmp(p
, "local-AS", strlen("local-AS")) == 0) {
786 *val
= COMMUNITY_LOCAL_AS
;
787 *token
= community_token_local_as
;
788 p
+= strlen("local-AS");
791 if (strncmp(p
, "no-peer", strlen("no-peer")) == 0) {
792 *val
= COMMUNITY_NO_PEER
;
793 *token
= community_token_no_peer
;
794 p
+= strlen("no-peer");
798 /* Unknown string. */
799 *token
= community_token_unknown
;
803 /* Community value. */
804 if (isdigit((unsigned char)*p
)) {
807 uint32_t community_low
= 0;
808 uint32_t community_high
= 0;
810 if (!community_valid(p
)) {
811 *token
= community_token_unknown
;
815 while (isdigit((unsigned char)*p
) || *p
== ':') {
818 *token
= community_token_unknown
;
824 if (community_low
> UINT16_MAX
) {
826 community_token_unknown
;
830 community_high
= community_low
<< 16;
836 community_low
+= (*p
- '0');
841 *token
= community_token_unknown
;
845 *val
= community_high
+ community_low
;
846 *token
= community_token_val
;
849 *token
= community_token_unknown
;
853 /* convert string to community structure */
854 struct community
*community_str2com(const char *str
)
856 struct community
*com
= NULL
;
857 struct community
*com_sort
= NULL
;
859 enum community_token token
= community_token_unknown
;
862 str
= community_gettoken(str
, &token
, &val
);
865 case community_token_val
:
866 case community_token_gshut
:
867 case community_token_accept_own
:
868 case community_token_route_filter_translated_v4
:
869 case community_token_route_filter_v4
:
870 case community_token_route_filter_translated_v6
:
871 case community_token_route_filter_v6
:
872 case community_token_llgr_stale
:
873 case community_token_no_llgr
:
874 case community_token_accept_own_nexthop
:
875 case community_token_blackhole
:
876 case community_token_no_export
:
877 case community_token_no_advertise
:
878 case community_token_local_as
:
879 case community_token_no_peer
:
881 com
= community_new();
884 community_add_val(com
, val
);
886 case community_token_unknown
:
888 community_free(&com
);
893 com_sort
= community_uniq_sort(com
);
894 community_free(&com
);
899 /* Return communities hash entry count. */
900 unsigned long community_count(void)
902 return comhash
->count
;
905 /* Return communities hash. */
906 struct hash
*community_hash(void)
911 /* Initialize comminity related hash. */
912 void community_init(void)
915 hash_create((unsigned int (*)(const void *))community_hash_make
,
916 (bool (*)(const void *, const void *))community_cmp
,
917 "BGP Community Hash");
920 void community_finish(void)
926 static struct community
*bgp_aggr_community_lookup(
927 struct bgp_aggregate
*aggregate
,
928 struct community
*community
)
930 return hash_lookup(aggregate
->community_hash
, community
);
933 static void *bgp_aggr_communty_hash_alloc(void *p
)
935 struct community
*ref
= (struct community
*)p
;
936 struct community
*community
= NULL
;
938 community
= community_dup(ref
);
942 static void bgp_aggr_community_prepare(struct hash_bucket
*hb
, void *arg
)
944 struct community
*hb_community
= hb
->data
;
945 struct community
**aggr_community
= arg
;
948 *aggr_community
= community_merge(*aggr_community
,
951 *aggr_community
= community_dup(hb_community
);
954 void bgp_aggr_community_remove(void *arg
)
956 struct community
*community
= arg
;
958 community_free(&community
);
961 void bgp_compute_aggregate_community(struct bgp_aggregate
*aggregate
,
962 struct community
*community
)
964 bgp_compute_aggregate_community_hash(aggregate
, community
);
965 bgp_compute_aggregate_community_val(aggregate
);
969 void bgp_compute_aggregate_community_hash(struct bgp_aggregate
*aggregate
,
970 struct community
*community
)
972 struct community
*aggr_community
= NULL
;
974 if ((aggregate
== NULL
) || (community
== NULL
))
977 /* Create hash if not already created.
979 if (aggregate
->community_hash
== NULL
)
980 aggregate
->community_hash
= hash_create(
981 (unsigned int (*)(const void *))community_hash_make
,
982 (bool (*)(const void *, const void *))community_cmp
,
983 "BGP Aggregator community hash");
985 aggr_community
= bgp_aggr_community_lookup(aggregate
, community
);
986 if (aggr_community
== NULL
) {
987 /* Insert community into hash.
989 aggr_community
= hash_get(aggregate
->community_hash
, community
,
990 bgp_aggr_communty_hash_alloc
);
993 /* Increment reference counter.
995 aggr_community
->refcnt
++;
998 void bgp_compute_aggregate_community_val(struct bgp_aggregate
*aggregate
)
1000 struct community
*commerge
= NULL
;
1002 if (aggregate
== NULL
)
1005 /* Re-compute aggregate's community.
1007 if (aggregate
->community
)
1008 community_free(&aggregate
->community
);
1009 if (aggregate
->community_hash
&&
1010 aggregate
->community_hash
->count
) {
1011 hash_iterate(aggregate
->community_hash
,
1012 bgp_aggr_community_prepare
,
1013 &aggregate
->community
);
1014 commerge
= aggregate
->community
;
1015 aggregate
->community
= community_uniq_sort(commerge
);
1017 community_free(&commerge
);
1023 void bgp_remove_community_from_aggregate(struct bgp_aggregate
*aggregate
,
1024 struct community
*community
)
1026 struct community
*aggr_community
= NULL
;
1027 struct community
*ret_comm
= NULL
;
1030 || (!aggregate
->community_hash
)
1034 /* Look-up the community in the hash.
1036 aggr_community
= bgp_aggr_community_lookup(aggregate
, community
);
1037 if (aggr_community
) {
1038 aggr_community
->refcnt
--;
1040 if (aggr_community
->refcnt
== 0) {
1041 ret_comm
= hash_release(aggregate
->community_hash
,
1043 community_free(&ret_comm
);
1045 bgp_compute_aggregate_community_val(aggregate
);
1050 void bgp_remove_comm_from_aggregate_hash(struct bgp_aggregate
*aggregate
,
1051 struct community
*community
)
1054 struct community
*aggr_community
= NULL
;
1055 struct community
*ret_comm
= NULL
;
1058 || (!aggregate
->community_hash
)
1062 /* Look-up the community in the hash.
1064 aggr_community
= bgp_aggr_community_lookup(aggregate
, community
);
1065 if (aggr_community
) {
1066 aggr_community
->refcnt
--;
1068 if (aggr_community
->refcnt
== 0) {
1069 ret_comm
= hash_release(aggregate
->community_hash
,
1071 community_free(&ret_comm
);