]>
Commit | Line | Data |
---|---|---|
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 | /* Community-list entry types. */ | |
40 | #define COMMUNITY_LIST_STANDARD 0 /* Standard community-list. */ | |
41 | #define COMMUNITY_LIST_EXPANDED 1 /* Expanded community-list. */ | |
42 | #define EXTCOMMUNITY_LIST_STANDARD 2 /* Standard extcommunity-list. */ | |
43 | #define EXTCOMMUNITY_LIST_EXPANDED 3 /* Expanded extcommunity-list. */ | |
44 | #define LARGE_COMMUNITY_LIST_STANDARD 4 /* Standard Large community-list. */ | |
45 | #define LARGE_COMMUNITY_LIST_EXPANDED 5 /* Expanded Large community-list. */ | |
46 | ||
47 | /* Community-list. */ | |
48 | struct community_list { | |
49 | /* Name of the community-list. */ | |
50 | char *name; | |
51 | ||
52 | /* Stored hash value of name, to further speed up hash operations */ | |
53 | uint32_t name_hash; | |
54 | ||
55 | /* String or number. */ | |
56 | int sort; | |
57 | ||
58 | /* Link to upper list. */ | |
59 | struct community_list_list *parent; | |
60 | ||
61 | /* Linked list for other community-list. */ | |
62 | struct community_list *next; | |
63 | struct community_list *prev; | |
64 | ||
65 | /* Community-list entry in this community-list. */ | |
66 | struct community_entry *head; | |
67 | struct community_entry *tail; | |
68 | }; | |
69 | ||
70 | /* Each entry in community-list. */ | |
71 | struct community_entry { | |
72 | struct community_entry *next; | |
73 | struct community_entry *prev; | |
74 | ||
75 | /* Permit or deny. */ | |
76 | uint8_t direct; | |
77 | ||
78 | /* Standard or expanded. */ | |
79 | uint8_t style; | |
80 | ||
81 | /* Any match. */ | |
82 | uint8_t any; | |
83 | ||
84 | /* Community structure. */ | |
85 | union { | |
86 | struct community *com; | |
87 | struct ecommunity *ecom; | |
88 | struct lcommunity *lcom; | |
89 | } u; | |
90 | ||
91 | /* Configuration string. */ | |
92 | char *config; | |
93 | ||
94 | /* Expanded community-list regular expression. */ | |
95 | regex_t *reg; | |
96 | }; | |
97 | ||
98 | /* Linked list of community-list. */ | |
99 | struct community_list_list { | |
100 | struct community_list *head; | |
101 | struct community_list *tail; | |
102 | }; | |
103 | ||
104 | /* Master structure of community-list and extcommunity-list. */ | |
105 | struct community_list_master { | |
106 | struct community_list_list num; | |
107 | struct community_list_list str; | |
108 | struct hash *hash; | |
109 | }; | |
110 | ||
111 | /* Community-list handler. community_list_init() returns this | |
112 | structure as handler. */ | |
113 | struct community_list_handler { | |
114 | /* Community-list. */ | |
115 | struct community_list_master community_list; | |
116 | ||
117 | /* Exteded community-list. */ | |
118 | struct community_list_master extcommunity_list; | |
119 | ||
120 | /* Large community-list. */ | |
121 | struct community_list_master lcommunity_list; | |
122 | }; | |
123 | ||
124 | /* Error code of community-list. */ | |
125 | #define COMMUNITY_LIST_ERR_CANT_FIND_LIST -1 | |
126 | #define COMMUNITY_LIST_ERR_MALFORMED_VAL -2 | |
127 | #define COMMUNITY_LIST_ERR_STANDARD_CONFLICT -3 | |
128 | #define COMMUNITY_LIST_ERR_EXPANDED_CONFLICT -4 | |
129 | ||
130 | /* Handler. */ | |
131 | extern struct community_list_handler *bgp_clist; | |
132 | ||
133 | /* Prototypes. */ | |
134 | extern struct community_list_handler *community_list_init(void); | |
135 | extern void community_list_terminate(struct community_list_handler *); | |
136 | ||
137 | extern int community_list_set(struct community_list_handler *ch, | |
138 | const char *name, const char *str, int direct, | |
139 | int style); | |
140 | extern int community_list_unset(struct community_list_handler *ch, | |
141 | const char *name, const char *str, int direct, | |
142 | int style); | |
143 | extern int extcommunity_list_set(struct community_list_handler *ch, | |
144 | const char *name, const char *str, int direct, | |
145 | int style); | |
146 | extern int extcommunity_list_unset(struct community_list_handler *ch, | |
147 | const char *name, const char *str, | |
148 | int direct, int style); | |
149 | extern int lcommunity_list_set(struct community_list_handler *ch, | |
150 | const char *name, const char *str, int direct, | |
151 | int style); | |
152 | extern int lcommunity_list_unset(struct community_list_handler *ch, | |
153 | const char *name, const char *str, int direct, | |
154 | int style); | |
155 | ||
156 | extern struct community_list_master * | |
157 | community_list_master_lookup(struct community_list_handler *, int); | |
158 | ||
159 | extern struct community_list * | |
160 | community_list_lookup(struct community_list_handler *c, const char *name, | |
161 | uint32_t name_hash, int master); | |
162 | ||
163 | extern int community_list_match(struct community *, struct community_list *); | |
164 | extern int ecommunity_list_match(struct ecommunity *, struct community_list *); | |
165 | extern int lcommunity_list_match(struct lcommunity *, struct community_list *); | |
166 | extern int community_list_exact_match(struct community *, | |
167 | struct community_list *); | |
168 | extern int lcommunity_list_exact_match(struct lcommunity *lcom, | |
169 | struct community_list *list); | |
170 | extern struct community *community_list_match_delete(struct community *, | |
171 | struct community_list *); | |
172 | extern struct lcommunity * | |
173 | lcommunity_list_match_delete(struct lcommunity *lcom, | |
174 | struct community_list *list); | |
175 | ||
176 | static inline uint32_t bgp_clist_hash_key(char *name) | |
177 | { | |
178 | return jhash(name, strlen(name), 0xdeadbeaf); | |
179 | } | |
180 | ||
181 | #endif /* _QUAGGA_BGP_CLIST_H */ |