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