]>
Commit | Line | Data |
---|---|---|
acddc0ed | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
718e3744 | 2 | /* BGP Community list. |
896014f4 | 3 | * Copyright (C) 1999 Kunihiro Ishiguro |
896014f4 | 4 | */ |
718e3744 | 5 | |
00d252cb | 6 | #ifndef _QUAGGA_BGP_CLIST_H |
7 | #define _QUAGGA_BGP_CLIST_H | |
8 | ||
e237b0d2 DS |
9 | #include "jhash.h" |
10 | ||
fee6e4e4 | 11 | /* Master Community-list. */ |
12 | #define COMMUNITY_LIST_MASTER 0 | |
13 | #define EXTCOMMUNITY_LIST_MASTER 1 | |
57d187bc | 14 | #define LARGE_COMMUNITY_LIST_MASTER 2 |
fee6e4e4 | 15 | |
718e3744 | 16 | /* Community-list deny and permit. */ |
17 | #define COMMUNITY_DENY 0 | |
18 | #define COMMUNITY_PERMIT 1 | |
19 | ||
20 | /* Number and string based community-list name. */ | |
21 | #define COMMUNITY_LIST_STRING 0 | |
22 | #define COMMUNITY_LIST_NUMBER 1 | |
23 | ||
2f8cc0e5 DA |
24 | #define COMMUNITY_SEQ_NUMBER_AUTO -1 |
25 | ||
718e3744 | 26 | /* Community-list entry types. */ |
27 | #define COMMUNITY_LIST_STANDARD 0 /* Standard community-list. */ | |
28 | #define COMMUNITY_LIST_EXPANDED 1 /* Expanded community-list. */ | |
fee6e4e4 | 29 | #define EXTCOMMUNITY_LIST_STANDARD 2 /* Standard extcommunity-list. */ |
30 | #define EXTCOMMUNITY_LIST_EXPANDED 3 /* Expanded extcommunity-list. */ | |
57d187bc JS |
31 | #define LARGE_COMMUNITY_LIST_STANDARD 4 /* Standard Large community-list. */ |
32 | #define LARGE_COMMUNITY_LIST_EXPANDED 5 /* Expanded Large community-list. */ | |
718e3744 | 33 | |
34 | /* Community-list. */ | |
d62a17ae | 35 | struct community_list { |
36 | /* Name of the community-list. */ | |
37 | char *name; | |
718e3744 | 38 | |
e237b0d2 DS |
39 | /* Stored hash value of name, to further speed up hash operations */ |
40 | uint32_t name_hash; | |
41 | ||
d62a17ae | 42 | /* String or number. */ |
43 | int sort; | |
718e3744 | 44 | |
d62a17ae | 45 | /* Link to upper list. */ |
46 | struct community_list_list *parent; | |
718e3744 | 47 | |
d62a17ae | 48 | /* Linked list for other community-list. */ |
49 | struct community_list *next; | |
50 | struct community_list *prev; | |
718e3744 | 51 | |
d62a17ae | 52 | /* Community-list entry in this community-list. */ |
53 | struct community_entry *head; | |
54 | struct community_entry *tail; | |
718e3744 | 55 | }; |
56 | ||
57 | /* Each entry in community-list. */ | |
d62a17ae | 58 | struct community_entry { |
59 | struct community_entry *next; | |
60 | struct community_entry *prev; | |
718e3744 | 61 | |
d62a17ae | 62 | /* Permit or deny. */ |
d7c0a89a | 63 | uint8_t direct; |
718e3744 | 64 | |
d62a17ae | 65 | /* Standard or expanded. */ |
d7c0a89a | 66 | uint8_t style; |
718e3744 | 67 | |
d62a17ae | 68 | /* Any match. */ |
d3f6c580 | 69 | bool any; |
718e3744 | 70 | |
2f8cc0e5 DA |
71 | /* Sequence number. */ |
72 | int64_t seq; | |
73 | ||
d62a17ae | 74 | /* Community structure. */ |
75 | union { | |
76 | struct community *com; | |
77 | struct ecommunity *ecom; | |
78 | struct lcommunity *lcom; | |
79 | } u; | |
718e3744 | 80 | |
d62a17ae | 81 | /* Configuration string. */ |
82 | char *config; | |
718e3744 | 83 | |
d62a17ae | 84 | /* Expanded community-list regular expression. */ |
85 | regex_t *reg; | |
718e3744 | 86 | }; |
87 | ||
88 | /* Linked list of community-list. */ | |
d62a17ae | 89 | struct community_list_list { |
90 | struct community_list *head; | |
91 | struct community_list *tail; | |
718e3744 | 92 | }; |
93 | ||
94 | /* Master structure of community-list and extcommunity-list. */ | |
d62a17ae | 95 | struct community_list_master { |
96 | struct community_list_list num; | |
97 | struct community_list_list str; | |
3571a6a2 | 98 | struct hash *hash; |
718e3744 | 99 | }; |
100 | ||
101 | /* Community-list handler. community_list_init() returns this | |
102 | structure as handler. */ | |
d62a17ae | 103 | struct community_list_handler { |
104 | /* Community-list. */ | |
105 | struct community_list_master community_list; | |
718e3744 | 106 | |
d62a17ae | 107 | /* Exteded community-list. */ |
108 | struct community_list_master extcommunity_list; | |
57d187bc | 109 | |
d62a17ae | 110 | /* Large community-list. */ |
111 | struct community_list_master lcommunity_list; | |
718e3744 | 112 | }; |
113 | ||
114 | /* Error code of community-list. */ | |
115 | #define COMMUNITY_LIST_ERR_CANT_FIND_LIST -1 | |
116 | #define COMMUNITY_LIST_ERR_MALFORMED_VAL -2 | |
117 | #define COMMUNITY_LIST_ERR_STANDARD_CONFLICT -3 | |
118 | #define COMMUNITY_LIST_ERR_EXPANDED_CONFLICT -4 | |
119 | ||
120 | /* Handler. */ | |
121 | extern struct community_list_handler *bgp_clist; | |
122 | ||
123 | /* Prototypes. */ | |
d62a17ae | 124 | extern struct community_list_handler *community_list_init(void); |
c99b64ab | 125 | extern void community_list_terminate(struct community_list_handler *ch); |
d62a17ae | 126 | |
127 | extern int community_list_set(struct community_list_handler *ch, | |
2f8cc0e5 DA |
128 | const char *name, const char *str, |
129 | const char *seq, int direct, int style); | |
d62a17ae | 130 | extern int community_list_unset(struct community_list_handler *ch, |
2f8cc0e5 DA |
131 | const char *name, const char *str, |
132 | const char *seq, int direct, int style); | |
d62a17ae | 133 | extern int extcommunity_list_set(struct community_list_handler *ch, |
2f8cc0e5 DA |
134 | const char *name, const char *str, |
135 | const char *seq, int direct, int style); | |
d62a17ae | 136 | extern int extcommunity_list_unset(struct community_list_handler *ch, |
137 | const char *name, const char *str, | |
2f8cc0e5 | 138 | const char *seq, int direct, int style); |
d62a17ae | 139 | extern int lcommunity_list_set(struct community_list_handler *ch, |
2f8cc0e5 DA |
140 | const char *name, const char *str, |
141 | const char *seq, int direct, int style); | |
c850908b | 142 | extern bool lcommunity_list_valid(const char *community, int style); |
d62a17ae | 143 | extern int lcommunity_list_unset(struct community_list_handler *ch, |
2f8cc0e5 DA |
144 | const char *name, const char *str, |
145 | const char *seq, int direct, int style); | |
94f2b392 | 146 | |
147 | extern struct community_list_master * | |
c99b64ab | 148 | community_list_master_lookup(struct community_list_handler *ch, int master); |
718e3744 | 149 | |
94f2b392 | 150 | extern struct community_list * |
e237b0d2 DS |
151 | community_list_lookup(struct community_list_handler *c, const char *name, |
152 | uint32_t name_hash, int master); | |
d62a17ae | 153 | |
c99b64ab DS |
154 | extern bool community_list_match(struct community *com, |
155 | struct community_list *list); | |
156 | extern bool ecommunity_list_match(struct ecommunity *ecom, | |
157 | struct community_list *list); | |
158 | extern bool lcommunity_list_match(struct lcommunity *lcom, | |
159 | struct community_list *list); | |
160 | extern bool community_list_exact_match(struct community *com, | |
161 | struct community_list *list); | |
88f1c947 DA |
162 | extern bool lcommunity_list_exact_match(struct lcommunity *lcom, |
163 | struct community_list *list); | |
c99b64ab DS |
164 | extern struct community * |
165 | community_list_match_delete(struct community *com, struct community_list *list); | |
57d187bc | 166 | extern struct lcommunity * |
d62a17ae | 167 | lcommunity_list_match_delete(struct lcommunity *lcom, |
168 | struct community_list *list); | |
e237b0d2 DS |
169 | |
170 | static inline uint32_t bgp_clist_hash_key(char *name) | |
171 | { | |
a7e046a2 | 172 | return jhash(name, strlen(name), 0xdeadbeaf); |
e237b0d2 DS |
173 | } |
174 | ||
225096bc DA |
175 | extern void bgp_community_list_command_completion_setup(void); |
176 | ||
00d252cb | 177 | #endif /* _QUAGGA_BGP_CLIST_H */ |