]>
Commit | Line | Data |
---|---|---|
1 | /* BGP routing table | |
2 | * Copyright (C) 1998, 2001 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_TABLE_H | |
22 | #define _QUAGGA_BGP_TABLE_H | |
23 | ||
24 | #include "mpls.h" | |
25 | #include "table.h" | |
26 | #include "queue.h" | |
27 | #include "linklist.h" | |
28 | #include "bgpd.h" | |
29 | #include "bgp_advertise.h" | |
30 | ||
31 | struct bgp_table { | |
32 | /* table belongs to this instance */ | |
33 | struct bgp *bgp; | |
34 | ||
35 | /* afi/safi of this table */ | |
36 | afi_t afi; | |
37 | safi_t safi; | |
38 | ||
39 | int lock; | |
40 | ||
41 | struct route_table *route_table; | |
42 | uint64_t version; | |
43 | }; | |
44 | ||
45 | struct bgp_node { | |
46 | /* | |
47 | * CAUTION | |
48 | * | |
49 | * These fields must be the very first fields in this structure. | |
50 | * | |
51 | * @see bgp_node_to_rnode | |
52 | * @see bgp_node_from_rnode | |
53 | */ | |
54 | ROUTE_NODE_FIELDS | |
55 | ||
56 | struct bgp_adj_out_rb adj_out; | |
57 | ||
58 | struct bgp_adj_in *adj_in; | |
59 | ||
60 | struct bgp_node *prn; | |
61 | ||
62 | STAILQ_ENTRY(bgp_node) pq; | |
63 | ||
64 | mpls_label_t local_label; | |
65 | ||
66 | uint64_t version; | |
67 | uint8_t flags; | |
68 | #define BGP_NODE_PROCESS_SCHEDULED (1 << 0) | |
69 | #define BGP_NODE_USER_CLEAR (1 << 1) | |
70 | #define BGP_NODE_LABEL_CHANGED (1 << 2) | |
71 | #define BGP_NODE_REGISTERED_FOR_LABEL (1 << 3) | |
72 | ||
73 | struct bgp_addpath_node_data tx_addpath; | |
74 | }; | |
75 | ||
76 | /* | |
77 | * bgp_table_iter_t | |
78 | * | |
79 | * Structure that holds state for iterating over a bgp table. | |
80 | */ | |
81 | typedef struct bgp_table_iter_t_ { | |
82 | struct bgp_table *table; | |
83 | route_table_iter_t rt_iter; | |
84 | } bgp_table_iter_t; | |
85 | ||
86 | extern struct bgp_table *bgp_table_init(struct bgp *bgp, afi_t, safi_t); | |
87 | extern void bgp_table_lock(struct bgp_table *); | |
88 | extern void bgp_table_unlock(struct bgp_table *); | |
89 | extern void bgp_table_finish(struct bgp_table **); | |
90 | ||
91 | ||
92 | /* | |
93 | * bgp_node_from_rnode | |
94 | * | |
95 | * Returns the bgp_node structure corresponding to a route_node. | |
96 | */ | |
97 | static inline struct bgp_node *bgp_node_from_rnode(struct route_node *rnode) | |
98 | { | |
99 | return (struct bgp_node *)rnode; | |
100 | } | |
101 | ||
102 | /* | |
103 | * bgp_node_to_rnode | |
104 | * | |
105 | * Returns the route_node structure corresponding to a bgp_node. | |
106 | */ | |
107 | static inline struct route_node *bgp_node_to_rnode(struct bgp_node *node) | |
108 | { | |
109 | return (struct route_node *)node; | |
110 | } | |
111 | ||
112 | /* | |
113 | * bgp_node_table | |
114 | * | |
115 | * Returns the bgp_table that the given node is in. | |
116 | */ | |
117 | static inline struct bgp_table *bgp_node_table(struct bgp_node *node) | |
118 | { | |
119 | return route_table_get_info(bgp_node_to_rnode(node)->table); | |
120 | } | |
121 | ||
122 | /* | |
123 | * bgp_node_parent_nolock | |
124 | * | |
125 | * Gets the parent node of the given node without locking it. | |
126 | */ | |
127 | static inline struct bgp_node *bgp_node_parent_nolock(struct bgp_node *node) | |
128 | { | |
129 | return bgp_node_from_rnode(node->parent); | |
130 | } | |
131 | ||
132 | /* | |
133 | * bgp_unlock_node | |
134 | */ | |
135 | static inline void bgp_unlock_node(struct bgp_node *node) | |
136 | { | |
137 | route_unlock_node(bgp_node_to_rnode(node)); | |
138 | } | |
139 | ||
140 | /* | |
141 | * bgp_table_top_nolock | |
142 | * | |
143 | * Gets the top node in the table without locking it. | |
144 | * | |
145 | * @see bgp_table_top | |
146 | */ | |
147 | static inline struct bgp_node * | |
148 | bgp_table_top_nolock(const struct bgp_table *const table) | |
149 | { | |
150 | return bgp_node_from_rnode(table->route_table->top); | |
151 | } | |
152 | ||
153 | /* | |
154 | * bgp_table_top | |
155 | */ | |
156 | static inline struct bgp_node * | |
157 | bgp_table_top(const struct bgp_table *const table) | |
158 | { | |
159 | return bgp_node_from_rnode(route_top(table->route_table)); | |
160 | } | |
161 | ||
162 | /* | |
163 | * bgp_route_next | |
164 | */ | |
165 | static inline struct bgp_node *bgp_route_next(struct bgp_node *node) | |
166 | { | |
167 | return bgp_node_from_rnode(route_next(bgp_node_to_rnode(node))); | |
168 | } | |
169 | ||
170 | /* | |
171 | * bgp_route_next_until | |
172 | */ | |
173 | static inline struct bgp_node *bgp_route_next_until(struct bgp_node *node, | |
174 | struct bgp_node *limit) | |
175 | { | |
176 | struct route_node *rnode; | |
177 | ||
178 | rnode = route_next_until(bgp_node_to_rnode(node), | |
179 | bgp_node_to_rnode(limit)); | |
180 | return bgp_node_from_rnode(rnode); | |
181 | } | |
182 | ||
183 | /* | |
184 | * bgp_node_get | |
185 | */ | |
186 | static inline struct bgp_node *bgp_node_get(struct bgp_table *const table, | |
187 | struct prefix *p) | |
188 | { | |
189 | return bgp_node_from_rnode(route_node_get(table->route_table, p)); | |
190 | } | |
191 | ||
192 | /* | |
193 | * bgp_node_lookup | |
194 | */ | |
195 | static inline struct bgp_node * | |
196 | bgp_node_lookup(const struct bgp_table *const table, struct prefix *p) | |
197 | { | |
198 | return bgp_node_from_rnode(route_node_lookup(table->route_table, p)); | |
199 | } | |
200 | ||
201 | /* | |
202 | * bgp_lock_node | |
203 | */ | |
204 | static inline struct bgp_node *bgp_lock_node(struct bgp_node *node) | |
205 | { | |
206 | return bgp_node_from_rnode(route_lock_node(bgp_node_to_rnode(node))); | |
207 | } | |
208 | ||
209 | /* | |
210 | * bgp_node_match | |
211 | */ | |
212 | static inline struct bgp_node *bgp_node_match(const struct bgp_table *table, | |
213 | struct prefix *p) | |
214 | { | |
215 | return bgp_node_from_rnode(route_node_match(table->route_table, p)); | |
216 | } | |
217 | ||
218 | /* | |
219 | * bgp_node_match_ipv4 | |
220 | */ | |
221 | static inline struct bgp_node * | |
222 | bgp_node_match_ipv4(const struct bgp_table *table, struct in_addr *addr) | |
223 | { | |
224 | return bgp_node_from_rnode( | |
225 | route_node_match_ipv4(table->route_table, addr)); | |
226 | } | |
227 | ||
228 | /* | |
229 | * bgp_node_match_ipv6 | |
230 | */ | |
231 | static inline struct bgp_node * | |
232 | bgp_node_match_ipv6(const struct bgp_table *table, struct in6_addr *addr) | |
233 | { | |
234 | return bgp_node_from_rnode( | |
235 | route_node_match_ipv6(table->route_table, addr)); | |
236 | } | |
237 | ||
238 | static inline unsigned long bgp_table_count(const struct bgp_table *const table) | |
239 | { | |
240 | return route_table_count(table->route_table); | |
241 | } | |
242 | ||
243 | /* | |
244 | * bgp_table_get_next | |
245 | */ | |
246 | static inline struct bgp_node *bgp_table_get_next(const struct bgp_table *table, | |
247 | struct prefix *p) | |
248 | { | |
249 | return bgp_node_from_rnode(route_table_get_next(table->route_table, p)); | |
250 | } | |
251 | ||
252 | /* | |
253 | * bgp_table_iter_init | |
254 | */ | |
255 | static inline void bgp_table_iter_init(bgp_table_iter_t *iter, | |
256 | struct bgp_table *table) | |
257 | { | |
258 | bgp_table_lock(table); | |
259 | iter->table = table; | |
260 | route_table_iter_init(&iter->rt_iter, table->route_table); | |
261 | } | |
262 | ||
263 | /* | |
264 | * bgp_table_iter_next | |
265 | */ | |
266 | static inline struct bgp_node *bgp_table_iter_next(bgp_table_iter_t *iter) | |
267 | { | |
268 | return bgp_node_from_rnode(route_table_iter_next(&iter->rt_iter)); | |
269 | } | |
270 | ||
271 | /* | |
272 | * bgp_table_iter_cleanup | |
273 | */ | |
274 | static inline void bgp_table_iter_cleanup(bgp_table_iter_t *iter) | |
275 | { | |
276 | route_table_iter_cleanup(&iter->rt_iter); | |
277 | bgp_table_unlock(iter->table); | |
278 | iter->table = NULL; | |
279 | } | |
280 | ||
281 | /* | |
282 | * bgp_table_iter_pause | |
283 | */ | |
284 | static inline void bgp_table_iter_pause(bgp_table_iter_t *iter) | |
285 | { | |
286 | route_table_iter_pause(&iter->rt_iter); | |
287 | } | |
288 | ||
289 | /* | |
290 | * bgp_table_iter_is_done | |
291 | */ | |
292 | static inline int bgp_table_iter_is_done(bgp_table_iter_t *iter) | |
293 | { | |
294 | return route_table_iter_is_done(&iter->rt_iter); | |
295 | } | |
296 | ||
297 | /* | |
298 | * bgp_table_iter_started | |
299 | */ | |
300 | static inline int bgp_table_iter_started(bgp_table_iter_t *iter) | |
301 | { | |
302 | return route_table_iter_started(&iter->rt_iter); | |
303 | } | |
304 | ||
305 | /* This would benefit from a real atomic operation... | |
306 | * until then. */ | |
307 | static inline uint64_t bgp_table_next_version(struct bgp_table *table) | |
308 | { | |
309 | return ++table->version; | |
310 | } | |
311 | ||
312 | static inline uint64_t bgp_table_version(struct bgp_table *table) | |
313 | { | |
314 | return table->version; | |
315 | } | |
316 | ||
317 | void bgp_table_range_lookup(const struct bgp_table *table, struct prefix *p, | |
318 | uint8_t maxlen, struct list *matches); | |
319 | ||
320 | ||
321 | static inline struct bgp_aggregate * | |
322 | bgp_aggregate_get_node_info(struct bgp_node *node) | |
323 | { | |
324 | return node->info; | |
325 | } | |
326 | ||
327 | static inline void bgp_aggregate_set_node_info(struct bgp_node *node, | |
328 | struct bgp_aggregate *aggregate) | |
329 | { | |
330 | node->info = aggregate; | |
331 | } | |
332 | ||
333 | static inline struct bgp_distance *bgp_distance_get_node(struct bgp_node *node) | |
334 | { | |
335 | return node->info; | |
336 | } | |
337 | ||
338 | static inline void bgp_distance_set_node_info(struct bgp_node *node, | |
339 | struct bgp_distance *distance) | |
340 | { | |
341 | node->info = distance; | |
342 | } | |
343 | ||
344 | static inline struct bgp_static *bgp_static_get_node_info(struct bgp_node *node) | |
345 | { | |
346 | return node->info; | |
347 | } | |
348 | ||
349 | static inline void bgp_static_set_node_info(struct bgp_node *node, | |
350 | struct bgp_static *bgp_static) | |
351 | { | |
352 | node->info = bgp_static; | |
353 | } | |
354 | ||
355 | static inline struct bgp_connected_ref * | |
356 | bgp_connected_get_node_info(struct bgp_node *node) | |
357 | { | |
358 | return node->info; | |
359 | } | |
360 | ||
361 | static inline void bgp_connected_set_node_info(struct bgp_node *node, | |
362 | struct bgp_connected_ref *bc) | |
363 | { | |
364 | node->info = bc; | |
365 | } | |
366 | ||
367 | static inline struct bgp_nexthop_cache * | |
368 | bgp_nexthop_get_node_info(struct bgp_node *node) | |
369 | { | |
370 | return node->info; | |
371 | } | |
372 | ||
373 | static inline void bgp_nexthop_set_node_info(struct bgp_node *node, | |
374 | struct bgp_nexthop_cache *bnc) | |
375 | { | |
376 | node->info = bnc; | |
377 | } | |
378 | ||
379 | #endif /* _QUAGGA_BGP_TABLE_H */ |