]> git.proxmox.com Git - mirror_frr.git/blob - bgpd/bgp_community.h
Merge pull request #12830 from anlancs/fix/doc-ripd-rst
[mirror_frr.git] / bgpd / bgp_community.h
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 #define COMMUNITY_INTERNET 0x0
34 #define COMMUNITY_GSHUT 0xFFFF0000
35 #define COMMUNITY_ACCEPT_OWN 0xFFFF0001
36 #define COMMUNITY_ROUTE_FILTER_TRANSLATED_v4 0xFFFF0002
37 #define COMMUNITY_ROUTE_FILTER_v4 0xFFFF0003
38 #define COMMUNITY_ROUTE_FILTER_TRANSLATED_v6 0xFFFF0004
39 #define COMMUNITY_ROUTE_FILTER_v6 0xFFFF0005
40 #define COMMUNITY_LLGR_STALE 0xFFFF0006
41 #define COMMUNITY_NO_LLGR 0xFFFF0007
42 #define COMMUNITY_ACCEPT_OWN_NEXTHOP 0xFFFF0008
43 #define COMMUNITY_BLACKHOLE 0xFFFF029A
44 #define COMMUNITY_NO_EXPORT 0xFFFFFF01
45 #define COMMUNITY_NO_ADVERTISE 0xFFFFFF02
46 #define COMMUNITY_NO_EXPORT_SUBCONFED 0xFFFFFF03
47 #define COMMUNITY_LOCAL_AS 0xFFFFFF03
48 #define COMMUNITY_NO_PEER 0xFFFFFF04
49
50 #define COMMUNITY_SIZE 4
51
52 /* Macros of community attribute. */
53 #define com_length(X) ((X)->size * COMMUNITY_SIZE)
54 #define com_lastval(X) ((X)->val + (X)->size - 1)
55 #define com_nthval(X,n) ((X)->val + (n))
56
57 /* Prototypes of communities attribute functions. */
58 extern void community_init(void);
59 extern void community_finish(void);
60 extern void community_free(struct community **comm);
61 extern struct community *community_uniq_sort(struct community *com);
62 extern struct community *community_parse(uint32_t *pnt, unsigned short length);
63 extern struct community *community_intern(struct community *com);
64 extern void community_unintern(struct community **com);
65 extern char *community_str(struct community *com, bool make_json,
66 bool translate_alias);
67 extern unsigned int community_hash_make(const struct community *com);
68 extern struct community *community_str2com(const char *str);
69 extern bool community_match(const struct community *com1,
70 const struct community *com2);
71 extern bool community_cmp(const struct community *c1,
72 const struct community *c2);
73 extern struct community *community_merge(struct community *com1,
74 struct community *com2);
75 extern struct community *community_delete(struct community *com1,
76 struct community *com2);
77 extern struct community *community_dup(struct community *com);
78 extern bool community_include(struct community *com, uint32_t val);
79 extern void community_add_val(struct community *com, uint32_t val);
80 extern void community_del_val(struct community *com, uint32_t *val);
81 extern unsigned long community_count(void);
82 extern struct hash *community_hash(void);
83 extern uint32_t community_val_get(struct community *com, int i);
84 extern void bgp_compute_aggregate_community(struct bgp_aggregate *aggregate,
85 struct community *community);
86
87 extern void bgp_compute_aggregate_community_val(
88 struct bgp_aggregate *aggregate);
89 extern void bgp_compute_aggregate_community_hash(
90 struct bgp_aggregate *aggregate,
91 struct community *community);
92 extern void bgp_remove_community_from_aggregate(struct bgp_aggregate *aggregate,
93 struct community *community);
94 extern void bgp_remove_comm_from_aggregate_hash(struct bgp_aggregate *aggregate,
95 struct community *community);
96 extern void bgp_aggr_community_remove(void *arg);
97
98 /* This implies that when propagating routes into a VRF, the ACCEPT_OWN
99 * community SHOULD NOT be propagated.
100 */
101 static inline void community_strip_accept_own(struct attr *attr)
102 {
103 struct community *old_com = bgp_attr_get_community(attr);
104 struct community *new_com = NULL;
105 uint32_t val = COMMUNITY_ACCEPT_OWN;
106
107 if (old_com && community_include(old_com, val)) {
108 new_com = community_dup(old_com);
109 val = htonl(val);
110 community_del_val(new_com, &val);
111
112 if (!old_com->refcnt)
113 community_free(&old_com);
114
115 if (!new_com->size) {
116 community_free(&new_com);
117 bgp_attr_set_community(attr, NULL);
118 } else {
119 bgp_attr_set_community(attr, new_com);
120 }
121 }
122 }
123
124 #endif /* _QUAGGA_BGP_COMMUNITY_H */