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