]> git.proxmox.com Git - mirror_frr.git/blob - bgpd/bgp_community.h
Merge pull request #12920 from sri-mohan1/sri-mohan-ldp
[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 #if CONFDATE > 20230801
34 CPP_NOTICE("Deprecate COMMUNITY_INTERNET BGP community")
35 #endif
36 #define COMMUNITY_INTERNET 0x0
37 #define COMMUNITY_GSHUT 0xFFFF0000
38 #define COMMUNITY_ACCEPT_OWN 0xFFFF0001
39 #define COMMUNITY_ROUTE_FILTER_TRANSLATED_v4 0xFFFF0002
40 #define COMMUNITY_ROUTE_FILTER_v4 0xFFFF0003
41 #define COMMUNITY_ROUTE_FILTER_TRANSLATED_v6 0xFFFF0004
42 #define COMMUNITY_ROUTE_FILTER_v6 0xFFFF0005
43 #define COMMUNITY_LLGR_STALE 0xFFFF0006
44 #define COMMUNITY_NO_LLGR 0xFFFF0007
45 #define COMMUNITY_ACCEPT_OWN_NEXTHOP 0xFFFF0008
46 #define COMMUNITY_BLACKHOLE 0xFFFF029A
47 #define COMMUNITY_NO_EXPORT 0xFFFFFF01
48 #define COMMUNITY_NO_ADVERTISE 0xFFFFFF02
49 #define COMMUNITY_NO_EXPORT_SUBCONFED 0xFFFFFF03
50 #define COMMUNITY_LOCAL_AS 0xFFFFFF03
51 #define COMMUNITY_NO_PEER 0xFFFFFF04
52
53 #define COMMUNITY_SIZE 4
54
55 /* Macros of community attribute. */
56 #define com_length(X) ((X)->size * COMMUNITY_SIZE)
57 #define com_lastval(X) ((X)->val + (X)->size - 1)
58 #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 {
106 struct community *old_com = bgp_attr_get_community(attr);
107 struct community *new_com = NULL;
108 uint32_t val = COMMUNITY_ACCEPT_OWN;
109
110 if (old_com && community_include(old_com, val)) {
111 new_com = community_dup(old_com);
112 val = htonl(val);
113 community_del_val(new_com, &val);
114
115 if (!old_com->refcnt)
116 community_free(&old_com);
117
118 if (!new_com->size) {
119 community_free(&new_com);
120 bgp_attr_set_community(attr, NULL);
121 } else {
122 bgp_attr_set_community(attr, new_com);
123 }
124 }
125 }
126
127 #endif /* _QUAGGA_BGP_COMMUNITY_H */