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