/src/frr/bgpd/bgp_community.h
Line | Count | Source (jump to first uncovered line) |
1 | | // SPDX-License-Identifier: GPL-2.0-or-later |
2 | | /* Community attribute related functions. |
3 | | * Copyright (C) 1998 Kunihiro Ishiguro |
4 | | */ |
5 | | |
6 | | #ifndef _QUAGGA_BGP_COMMUNITY_H |
7 | | #define _QUAGGA_BGP_COMMUNITY_H |
8 | | |
9 | | #include "lib/json.h" |
10 | | #include "bgpd/bgp_route.h" |
11 | | #include "bgpd/bgp_attr.h" |
12 | | |
13 | | /* Communities attribute. */ |
14 | | struct community { |
15 | | /* Reference count of communities value. */ |
16 | | unsigned long refcnt; |
17 | | |
18 | | /* Communities value size. */ |
19 | | int size; |
20 | | |
21 | | /* Communities value. */ |
22 | | uint32_t *val; |
23 | | |
24 | | /* Communities as a json object */ |
25 | | json_object *json; |
26 | | |
27 | | /* String of community attribute. This sring is used by vty output |
28 | | and expanded community-list for regular expression match. */ |
29 | | char *str; |
30 | | }; |
31 | | |
32 | | /* Well-known communities value. */ |
33 | | #if CONFDATE > 20230801 |
34 | | CPP_NOTICE("Deprecate COMMUNITY_INTERNET BGP community") |
35 | | #endif |
36 | 40 | #define COMMUNITY_INTERNET 0x0 |
37 | 1.16k | #define COMMUNITY_GSHUT 0xFFFF0000 |
38 | 2 | #define COMMUNITY_ACCEPT_OWN 0xFFFF0001 |
39 | 4 | #define COMMUNITY_ROUTE_FILTER_TRANSLATED_v4 0xFFFF0002 |
40 | 0 | #define COMMUNITY_ROUTE_FILTER_v4 0xFFFF0003 |
41 | 0 | #define COMMUNITY_ROUTE_FILTER_TRANSLATED_v6 0xFFFF0004 |
42 | 0 | #define COMMUNITY_ROUTE_FILTER_v6 0xFFFF0005 |
43 | 0 | #define COMMUNITY_LLGR_STALE 0xFFFF0006 |
44 | 0 | #define COMMUNITY_NO_LLGR 0xFFFF0007 |
45 | 0 | #define COMMUNITY_ACCEPT_OWN_NEXTHOP 0xFFFF0008 |
46 | 1.15k | #define COMMUNITY_BLACKHOLE 0xFFFF029A |
47 | 375 | #define COMMUNITY_NO_EXPORT 0xFFFFFF01 |
48 | 2 | #define COMMUNITY_NO_ADVERTISE 0xFFFFFF02 |
49 | 0 | #define COMMUNITY_NO_EXPORT_SUBCONFED 0xFFFFFF03 |
50 | 6 | #define COMMUNITY_LOCAL_AS 0xFFFFFF03 |
51 | 2 | #define COMMUNITY_NO_PEER 0xFFFFFF04 |
52 | | |
53 | 7.91k | #define COMMUNITY_SIZE 4 |
54 | | |
55 | | /* Macros of community attribute. */ |
56 | | #define com_length(X) ((X)->size * COMMUNITY_SIZE) |
57 | 6.00k | #define com_lastval(X) ((X)->val + (X)->size - 1) |
58 | 331k | #define com_nthval(X,n) ((X)->val + (n)) |
59 | | |
60 | | /* Prototypes of communities attribute functions. */ |
61 | | extern void community_init(void); |
62 | | extern void community_finish(void); |
63 | | extern void community_free(struct community **comm); |
64 | | extern struct community *community_uniq_sort(struct community *com); |
65 | | extern struct community *community_parse(uint32_t *pnt, unsigned short length); |
66 | | extern struct community *community_intern(struct community *com); |
67 | | extern void community_unintern(struct community **com); |
68 | | extern char *community_str(struct community *com, bool make_json, |
69 | | bool translate_alias); |
70 | | extern unsigned int community_hash_make(const struct community *com); |
71 | | extern struct community *community_str2com(const char *str); |
72 | | extern bool community_match(const struct community *com1, |
73 | | const struct community *com2); |
74 | | extern bool community_cmp(const struct community *c1, |
75 | | const struct community *c2); |
76 | | extern struct community *community_merge(struct community *com1, |
77 | | struct community *com2); |
78 | | extern struct community *community_delete(struct community *com1, |
79 | | struct community *com2); |
80 | | extern struct community *community_dup(struct community *com); |
81 | | extern bool community_include(struct community *com, uint32_t val); |
82 | | extern void community_add_val(struct community *com, uint32_t val); |
83 | | extern void community_del_val(struct community *com, uint32_t *val); |
84 | | extern unsigned long community_count(void); |
85 | | extern struct hash *community_hash(void); |
86 | | extern uint32_t community_val_get(struct community *com, int i); |
87 | | extern void bgp_compute_aggregate_community(struct bgp_aggregate *aggregate, |
88 | | struct community *community); |
89 | | |
90 | | extern void bgp_compute_aggregate_community_val( |
91 | | struct bgp_aggregate *aggregate); |
92 | | extern void bgp_compute_aggregate_community_hash( |
93 | | struct bgp_aggregate *aggregate, |
94 | | struct community *community); |
95 | | extern void bgp_remove_community_from_aggregate(struct bgp_aggregate *aggregate, |
96 | | struct community *community); |
97 | | extern void bgp_remove_comm_from_aggregate_hash(struct bgp_aggregate *aggregate, |
98 | | struct community *community); |
99 | | extern void bgp_aggr_community_remove(void *arg); |
100 | | |
101 | | /* This implies that when propagating routes into a VRF, the ACCEPT_OWN |
102 | | * community SHOULD NOT be propagated. |
103 | | */ |
104 | | static inline void community_strip_accept_own(struct attr *attr) |
105 | 0 | { |
106 | 0 | struct community *old_com = bgp_attr_get_community(attr); |
107 | 0 | struct community *new_com = NULL; |
108 | 0 | uint32_t val = COMMUNITY_ACCEPT_OWN; |
109 | |
|
110 | 0 | if (old_com && community_include(old_com, val)) { |
111 | 0 | new_com = community_dup(old_com); |
112 | 0 | val = htonl(val); |
113 | 0 | community_del_val(new_com, &val); |
114 | |
|
115 | 0 | if (!old_com->refcnt) |
116 | 0 | community_free(&old_com); |
117 | |
|
118 | 0 | if (!new_com->size) { |
119 | 0 | community_free(&new_com); |
120 | 0 | bgp_attr_set_community(attr, NULL); |
121 | 0 | } else { |
122 | 0 | bgp_attr_set_community(attr, new_com); |
123 | 0 | } |
124 | 0 | } |
125 | 0 | } Unexecuted instantiation: bgp_attr.c:community_strip_accept_own Unexecuted instantiation: bgp_clist.c:community_strip_accept_own Unexecuted instantiation: bgp_community.c:community_strip_accept_own Unexecuted instantiation: bgp_debug.c:community_strip_accept_own Unexecuted instantiation: bgp_evpn_vty.c:community_strip_accept_own Unexecuted instantiation: bgp_fsm.c:community_strip_accept_own Unexecuted instantiation: bgp_mpath.c:community_strip_accept_own Unexecuted instantiation: bgp_mplsvpn.c:community_strip_accept_own Unexecuted instantiation: bgp_packet.c:community_strip_accept_own Unexecuted instantiation: bgp_route.c:community_strip_accept_own Unexecuted instantiation: bgp_routemap.c:community_strip_accept_own Unexecuted instantiation: bgp_vty.c:community_strip_accept_own Unexecuted instantiation: bgp_zebra.c:community_strip_accept_own Unexecuted instantiation: bgpd.c:community_strip_accept_own Unexecuted instantiation: rfapi_vty.c:community_strip_accept_own |
126 | | |
127 | | #endif /* _QUAGGA_BGP_COMMUNITY_H */ |