]>
Commit | Line | Data |
---|---|---|
718e3744 | 1 | /* BGP routing table |
896014f4 DL |
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 | */ | |
718e3744 | 20 | |
00d252cb | 21 | #ifndef _QUAGGA_BGP_TABLE_H |
22 | #define _QUAGGA_BGP_TABLE_H | |
23 | ||
9bedbb1e | 24 | #include "mpls.h" |
67174041 | 25 | #include "table.h" |
aac24838 | 26 | #include "queue.h" |
1dacdd8b | 27 | #include "linklist.h" |
dcc68b5e | 28 | #include "bgpd.h" |
a79c04e7 | 29 | #include "bgp_advertise.h" |
67174041 | 30 | |
d62a17ae | 31 | struct bgp_table { |
960035b2 PZ |
32 | /* table belongs to this instance */ |
33 | struct bgp *bgp; | |
34 | ||
d62a17ae | 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; | |
718e3744 | 43 | }; |
44 | ||
d62a17ae | 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 | |
718e3744 | 55 | |
a79c04e7 | 56 | struct bgp_adj_out_rb adj_out; |
718e3744 | 57 | |
d62a17ae | 58 | struct bgp_adj_in *adj_in; |
718e3744 | 59 | |
d62a17ae | 60 | struct bgp_node *prn; |
200df115 | 61 | |
aac24838 JB |
62 | STAILQ_ENTRY(bgp_node) pq; |
63 | ||
d62a17ae | 64 | mpls_label_t local_label; |
cd1964ff | 65 | |
d62a17ae | 66 | uint64_t version; |
d7c0a89a | 67 | uint8_t flags; |
200df115 | 68 | #define BGP_NODE_PROCESS_SCHEDULED (1 << 0) |
8ad7271d | 69 | #define BGP_NODE_USER_CLEAR (1 << 1) |
cd1964ff | 70 | #define BGP_NODE_LABEL_CHANGED (1 << 2) |
6cf48acc | 71 | #define BGP_NODE_REGISTERED_FOR_LABEL (1 << 3) |
dcc68b5e MS |
72 | |
73 | struct bgp_addpath_node_data tx_addpath; | |
718e3744 | 74 | }; |
75 | ||
28971c8c AS |
76 | /* |
77 | * bgp_table_iter_t | |
d62a17ae | 78 | * |
28971c8c AS |
79 | * Structure that holds state for iterating over a bgp table. |
80 | */ | |
d62a17ae | 81 | typedef struct bgp_table_iter_t_ { |
82 | struct bgp_table *table; | |
83 | route_table_iter_t rt_iter; | |
28971c8c AS |
84 | } bgp_table_iter_t; |
85 | ||
960035b2 | 86 | extern struct bgp_table *bgp_table_init(struct bgp *bgp, afi_t, safi_t); |
d62a17ae | 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 **); | |
67174041 AS |
90 | |
91 | ||
92 | /* | |
93 | * bgp_node_from_rnode | |
94 | * | |
95 | * Returns the bgp_node structure corresponding to a route_node. | |
96 | */ | |
d62a17ae | 97 | static inline struct bgp_node *bgp_node_from_rnode(struct route_node *rnode) |
67174041 | 98 | { |
d62a17ae | 99 | return (struct bgp_node *)rnode; |
67174041 AS |
100 | } |
101 | ||
102 | /* | |
103 | * bgp_node_to_rnode | |
104 | * | |
105 | * Returns the route_node structure corresponding to a bgp_node. | |
106 | */ | |
d62a17ae | 107 | static inline struct route_node *bgp_node_to_rnode(struct bgp_node *node) |
67174041 | 108 | { |
d62a17ae | 109 | return (struct route_node *)node; |
67174041 AS |
110 | } |
111 | ||
112 | /* | |
113 | * bgp_node_table | |
114 | * | |
115 | * Returns the bgp_table that the given node is in. | |
116 | */ | |
d62a17ae | 117 | static inline struct bgp_table *bgp_node_table(struct bgp_node *node) |
67174041 | 118 | { |
6ca30e9e | 119 | return route_table_get_info(bgp_node_to_rnode(node)->table); |
67174041 AS |
120 | } |
121 | ||
67174041 AS |
122 | /* |
123 | * bgp_node_parent_nolock | |
124 | * | |
125 | * Gets the parent node of the given node without locking it. | |
126 | */ | |
d62a17ae | 127 | static inline struct bgp_node *bgp_node_parent_nolock(struct bgp_node *node) |
67174041 | 128 | { |
d62a17ae | 129 | return bgp_node_from_rnode(node->parent); |
67174041 AS |
130 | } |
131 | ||
132 | /* | |
133 | * bgp_unlock_node | |
134 | */ | |
0e70e6c8 | 135 | static inline void bgp_unlock_node(struct bgp_node *node) |
67174041 | 136 | { |
0e70e6c8 | 137 | route_unlock_node(bgp_node_to_rnode(node)); |
67174041 AS |
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 * | |
d62a17ae | 148 | bgp_table_top_nolock(const struct bgp_table *const table) |
67174041 | 149 | { |
d62a17ae | 150 | return bgp_node_from_rnode(table->route_table->top); |
67174041 AS |
151 | } |
152 | ||
153 | /* | |
154 | * bgp_table_top | |
155 | */ | |
156 | static inline struct bgp_node * | |
d62a17ae | 157 | bgp_table_top(const struct bgp_table *const table) |
67174041 | 158 | { |
d62a17ae | 159 | return bgp_node_from_rnode(route_top(table->route_table)); |
67174041 AS |
160 | } |
161 | ||
162 | /* | |
163 | * bgp_route_next | |
164 | */ | |
d62a17ae | 165 | static inline struct bgp_node *bgp_route_next(struct bgp_node *node) |
67174041 | 166 | { |
d62a17ae | 167 | return bgp_node_from_rnode(route_next(bgp_node_to_rnode(node))); |
67174041 AS |
168 | } |
169 | ||
170 | /* | |
171 | * bgp_route_next_until | |
172 | */ | |
d62a17ae | 173 | static inline struct bgp_node *bgp_route_next_until(struct bgp_node *node, |
174 | struct bgp_node *limit) | |
67174041 | 175 | { |
d62a17ae | 176 | struct route_node *rnode; |
67174041 | 177 | |
d62a17ae | 178 | rnode = route_next_until(bgp_node_to_rnode(node), |
179 | bgp_node_to_rnode(limit)); | |
180 | return bgp_node_from_rnode(rnode); | |
67174041 AS |
181 | } |
182 | ||
183 | /* | |
184 | * bgp_node_get | |
185 | */ | |
d62a17ae | 186 | static inline struct bgp_node *bgp_node_get(struct bgp_table *const table, |
187 | struct prefix *p) | |
67174041 | 188 | { |
d62a17ae | 189 | return bgp_node_from_rnode(route_node_get(table->route_table, p)); |
67174041 AS |
190 | } |
191 | ||
192 | /* | |
193 | * bgp_node_lookup | |
194 | */ | |
195 | static inline struct bgp_node * | |
d62a17ae | 196 | bgp_node_lookup(const struct bgp_table *const table, struct prefix *p) |
67174041 | 197 | { |
d62a17ae | 198 | return bgp_node_from_rnode(route_node_lookup(table->route_table, p)); |
67174041 AS |
199 | } |
200 | ||
201 | /* | |
202 | * bgp_lock_node | |
203 | */ | |
d62a17ae | 204 | static inline struct bgp_node *bgp_lock_node(struct bgp_node *node) |
67174041 | 205 | { |
d62a17ae | 206 | return bgp_node_from_rnode(route_lock_node(bgp_node_to_rnode(node))); |
67174041 AS |
207 | } |
208 | ||
209 | /* | |
210 | * bgp_node_match | |
211 | */ | |
d62a17ae | 212 | static inline struct bgp_node *bgp_node_match(const struct bgp_table *table, |
213 | struct prefix *p) | |
67174041 | 214 | { |
d62a17ae | 215 | return bgp_node_from_rnode(route_node_match(table->route_table, p)); |
67174041 AS |
216 | } |
217 | ||
218 | /* | |
219 | * bgp_node_match_ipv4 | |
220 | */ | |
221 | static inline struct bgp_node * | |
d62a17ae | 222 | bgp_node_match_ipv4(const struct bgp_table *table, struct in_addr *addr) |
67174041 | 223 | { |
d62a17ae | 224 | return bgp_node_from_rnode( |
225 | route_node_match_ipv4(table->route_table, addr)); | |
67174041 AS |
226 | } |
227 | ||
67174041 AS |
228 | /* |
229 | * bgp_node_match_ipv6 | |
230 | */ | |
231 | static inline struct bgp_node * | |
d62a17ae | 232 | bgp_node_match_ipv6(const struct bgp_table *table, struct in6_addr *addr) |
67174041 | 233 | { |
d62a17ae | 234 | return bgp_node_from_rnode( |
235 | route_node_match_ipv6(table->route_table, addr)); | |
67174041 AS |
236 | } |
237 | ||
d62a17ae | 238 | static inline unsigned long bgp_table_count(const struct bgp_table *const table) |
67174041 | 239 | { |
d62a17ae | 240 | return route_table_count(table->route_table); |
67174041 AS |
241 | } |
242 | ||
28971c8c AS |
243 | /* |
244 | * bgp_table_get_next | |
245 | */ | |
d62a17ae | 246 | static inline struct bgp_node *bgp_table_get_next(const struct bgp_table *table, |
247 | struct prefix *p) | |
28971c8c | 248 | { |
d62a17ae | 249 | return bgp_node_from_rnode(route_table_get_next(table->route_table, p)); |
28971c8c AS |
250 | } |
251 | ||
252 | /* | |
253 | * bgp_table_iter_init | |
254 | */ | |
d62a17ae | 255 | static inline void bgp_table_iter_init(bgp_table_iter_t *iter, |
256 | struct bgp_table *table) | |
28971c8c | 257 | { |
d62a17ae | 258 | bgp_table_lock(table); |
259 | iter->table = table; | |
260 | route_table_iter_init(&iter->rt_iter, table->route_table); | |
28971c8c AS |
261 | } |
262 | ||
263 | /* | |
264 | * bgp_table_iter_next | |
265 | */ | |
d62a17ae | 266 | static inline struct bgp_node *bgp_table_iter_next(bgp_table_iter_t *iter) |
28971c8c | 267 | { |
d62a17ae | 268 | return bgp_node_from_rnode(route_table_iter_next(&iter->rt_iter)); |
28971c8c AS |
269 | } |
270 | ||
271 | /* | |
272 | * bgp_table_iter_cleanup | |
273 | */ | |
d62a17ae | 274 | static inline void bgp_table_iter_cleanup(bgp_table_iter_t *iter) |
28971c8c | 275 | { |
d62a17ae | 276 | route_table_iter_cleanup(&iter->rt_iter); |
277 | bgp_table_unlock(iter->table); | |
278 | iter->table = NULL; | |
28971c8c AS |
279 | } |
280 | ||
281 | /* | |
282 | * bgp_table_iter_pause | |
283 | */ | |
d62a17ae | 284 | static inline void bgp_table_iter_pause(bgp_table_iter_t *iter) |
28971c8c | 285 | { |
d62a17ae | 286 | route_table_iter_pause(&iter->rt_iter); |
28971c8c AS |
287 | } |
288 | ||
289 | /* | |
290 | * bgp_table_iter_is_done | |
291 | */ | |
d62a17ae | 292 | static inline int bgp_table_iter_is_done(bgp_table_iter_t *iter) |
28971c8c | 293 | { |
d62a17ae | 294 | return route_table_iter_is_done(&iter->rt_iter); |
28971c8c AS |
295 | } |
296 | ||
297 | /* | |
298 | * bgp_table_iter_started | |
299 | */ | |
d62a17ae | 300 | static inline int bgp_table_iter_started(bgp_table_iter_t *iter) |
28971c8c | 301 | { |
d62a17ae | 302 | return route_table_iter_started(&iter->rt_iter); |
28971c8c AS |
303 | } |
304 | ||
3f9c7369 DS |
305 | /* This would benefit from a real atomic operation... |
306 | * until then. */ | |
d62a17ae | 307 | static inline uint64_t bgp_table_next_version(struct bgp_table *table) |
3f9c7369 | 308 | { |
d62a17ae | 309 | return ++table->version; |
3f9c7369 DS |
310 | } |
311 | ||
d62a17ae | 312 | static inline uint64_t bgp_table_version(struct bgp_table *table) |
3f9c7369 | 313 | { |
d62a17ae | 314 | return table->version; |
3f9c7369 DS |
315 | } |
316 | ||
1dacdd8b MR |
317 | void bgp_table_range_lookup(const struct bgp_table *table, struct prefix *p, |
318 | uint8_t maxlen, struct list *matches); | |
319 | ||
b1e62edd DS |
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 | ||
ca2e160d DS |
333 | static inline struct bgp_distance *bgp_distance_get_node(struct bgp_node *node) |
334 | { | |
335 | return node->info; | |
336 | } | |
337 | ||
a78beeb5 DS |
338 | static inline void bgp_distance_set_node_info(struct bgp_node *node, |
339 | struct bgp_distance *distance) | |
ca2e160d DS |
340 | { |
341 | node->info = distance; | |
342 | } | |
343 | ||
a78beeb5 DS |
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 | } | |
3d9dbdbe DS |
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 | ||
14315f2d DS |
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 | ||
00d252cb | 379 | #endif /* _QUAGGA_BGP_TABLE_H */ |