]>
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 | ||
9bcb3eef DS |
24 | /* XXX BEGIN TEMPORARY COMPAT */ |
25 | #define bgp_dest bgp_node | |
26 | /* XXX END TEMPORARY COMPAT */ | |
27 | ||
9bedbb1e | 28 | #include "mpls.h" |
67174041 | 29 | #include "table.h" |
aac24838 | 30 | #include "queue.h" |
1dacdd8b | 31 | #include "linklist.h" |
dcc68b5e | 32 | #include "bgpd.h" |
a79c04e7 | 33 | #include "bgp_advertise.h" |
67174041 | 34 | |
d62a17ae | 35 | struct bgp_table { |
960035b2 PZ |
36 | /* table belongs to this instance */ |
37 | struct bgp *bgp; | |
38 | ||
d62a17ae | 39 | /* afi/safi of this table */ |
40 | afi_t afi; | |
41 | safi_t safi; | |
42 | ||
43 | int lock; | |
44 | ||
45 | struct route_table *route_table; | |
46 | uint64_t version; | |
718e3744 | 47 | }; |
48 | ||
fdf81fa0 DS |
49 | enum bgp_path_selection_reason { |
50 | bgp_path_selection_none, | |
51 | bgp_path_selection_first, | |
52 | bgp_path_selection_evpn_sticky_mac, | |
53 | bgp_path_selection_evpn_seq, | |
d071f237 AK |
54 | bgp_path_selection_evpn_local_path, |
55 | bgp_path_selection_evpn_non_proxy, | |
fdf81fa0 DS |
56 | bgp_path_selection_evpn_lower_ip, |
57 | bgp_path_selection_weight, | |
58 | bgp_path_selection_local_pref, | |
59 | bgp_path_selection_local_route, | |
60 | bgp_path_selection_confed_as_path, | |
61 | bgp_path_selection_as_path, | |
62 | bgp_path_selection_origin, | |
63 | bgp_path_selection_med, | |
64 | bgp_path_selection_peer, | |
65 | bgp_path_selection_confed, | |
66 | bgp_path_selection_igp_metric, | |
67 | bgp_path_selection_older, | |
68 | bgp_path_selection_router_id, | |
69 | bgp_path_selection_cluster_length, | |
70 | bgp_path_selection_stale, | |
71 | bgp_path_selection_local_configured, | |
72 | bgp_path_selection_neighbor_ip, | |
73 | bgp_path_selection_default, | |
74 | }; | |
75 | ||
d62a17ae | 76 | struct bgp_node { |
77 | /* | |
78 | * CAUTION | |
79 | * | |
80 | * These fields must be the very first fields in this structure. | |
81 | * | |
82 | * @see bgp_node_to_rnode | |
83 | * @see bgp_node_from_rnode | |
84 | */ | |
85 | ROUTE_NODE_FIELDS | |
718e3744 | 86 | |
a79c04e7 | 87 | struct bgp_adj_out_rb adj_out; |
718e3744 | 88 | |
d62a17ae | 89 | struct bgp_adj_in *adj_in; |
718e3744 | 90 | |
9bcb3eef | 91 | struct bgp_dest *pdest; |
200df115 | 92 | |
9bcb3eef | 93 | STAILQ_ENTRY(bgp_dest) pq; |
aac24838 | 94 | |
aaafc321 DS |
95 | uint64_t version; |
96 | ||
d62a17ae | 97 | mpls_label_t local_label; |
cd1964ff | 98 | |
d7c0a89a | 99 | uint8_t flags; |
200df115 | 100 | #define BGP_NODE_PROCESS_SCHEDULED (1 << 0) |
8ad7271d | 101 | #define BGP_NODE_USER_CLEAR (1 << 1) |
cd1964ff | 102 | #define BGP_NODE_LABEL_CHANGED (1 << 2) |
6cf48acc | 103 | #define BGP_NODE_REGISTERED_FOR_LABEL (1 << 3) |
f009ff26 | 104 | #define BGP_NODE_SELECT_DEFER (1 << 4) |
a77e2f4b S |
105 | #define BGP_NODE_FIB_INSTALL_PENDING (1 << 5) |
106 | #define BGP_NODE_FIB_INSTALLED (1 << 6) | |
26742171 | 107 | |
dcc68b5e | 108 | struct bgp_addpath_node_data tx_addpath; |
fdf81fa0 DS |
109 | |
110 | enum bgp_path_selection_reason reason; | |
718e3744 | 111 | }; |
112 | ||
9bcb3eef | 113 | extern void bgp_delete_listnode(struct bgp_dest *dest); |
28971c8c AS |
114 | /* |
115 | * bgp_table_iter_t | |
d62a17ae | 116 | * |
28971c8c AS |
117 | * Structure that holds state for iterating over a bgp table. |
118 | */ | |
d62a17ae | 119 | typedef struct bgp_table_iter_t_ { |
120 | struct bgp_table *table; | |
121 | route_table_iter_t rt_iter; | |
28971c8c AS |
122 | } bgp_table_iter_t; |
123 | ||
960035b2 | 124 | extern struct bgp_table *bgp_table_init(struct bgp *bgp, afi_t, safi_t); |
d62a17ae | 125 | extern void bgp_table_lock(struct bgp_table *); |
126 | extern void bgp_table_unlock(struct bgp_table *); | |
127 | extern void bgp_table_finish(struct bgp_table **); | |
67174041 AS |
128 | |
129 | ||
130 | /* | |
9bcb3eef | 131 | * bgp_dest_from_rnode |
67174041 | 132 | * |
9bcb3eef | 133 | * Returns the bgp_dest structure corresponding to a route_node. |
67174041 | 134 | */ |
9bcb3eef | 135 | static inline struct bgp_dest *bgp_dest_from_rnode(struct route_node *rnode) |
67174041 | 136 | { |
9bcb3eef | 137 | return (struct bgp_dest *)rnode; |
67174041 AS |
138 | } |
139 | ||
140 | /* | |
9bcb3eef | 141 | * bgp_dest_to_rnode |
67174041 | 142 | * |
9bcb3eef | 143 | * Returns the route_node structure corresponding to a bgp_dest. |
67174041 | 144 | */ |
9bcb3eef | 145 | static inline struct route_node *bgp_dest_to_rnode(const struct bgp_dest *dest) |
67174041 | 146 | { |
9bcb3eef | 147 | return (struct route_node *)dest; |
67174041 AS |
148 | } |
149 | ||
150 | /* | |
9bcb3eef | 151 | * bgp_dest_table |
67174041 | 152 | * |
9bcb3eef | 153 | * Returns the bgp_table that the given dest is in. |
67174041 | 154 | */ |
9bcb3eef | 155 | static inline struct bgp_table *bgp_dest_table(struct bgp_dest *dest) |
67174041 | 156 | { |
9bcb3eef | 157 | return route_table_get_info(bgp_dest_to_rnode(dest)->table); |
67174041 AS |
158 | } |
159 | ||
67174041 | 160 | /* |
9bcb3eef | 161 | * bgp_dest_parent_nolock |
67174041 | 162 | * |
9bcb3eef | 163 | * Gets the parent dest of the given node without locking it. |
67174041 | 164 | */ |
9bcb3eef | 165 | static inline struct bgp_dest *bgp_dest_parent_nolock(struct bgp_dest *dest) |
67174041 | 166 | { |
9bcb3eef DS |
167 | struct route_node *rn = bgp_dest_to_rnode(dest)->parent; |
168 | ||
169 | return bgp_dest_from_rnode(rn); | |
67174041 AS |
170 | } |
171 | ||
172 | /* | |
9bcb3eef | 173 | * bgp_dest_unlock_node |
67174041 | 174 | */ |
9bcb3eef | 175 | static inline void bgp_dest_unlock_node(struct bgp_dest *dest) |
67174041 | 176 | { |
9bcb3eef DS |
177 | bgp_delete_listnode(dest); |
178 | route_unlock_node(bgp_dest_to_rnode(dest)); | |
67174041 AS |
179 | } |
180 | ||
181 | /* | |
182 | * bgp_table_top_nolock | |
183 | * | |
9bcb3eef | 184 | * Gets the top dest in the table without locking it. |
67174041 AS |
185 | * |
186 | * @see bgp_table_top | |
187 | */ | |
9bcb3eef | 188 | static inline struct bgp_dest * |
d62a17ae | 189 | bgp_table_top_nolock(const struct bgp_table *const table) |
67174041 | 190 | { |
9bcb3eef | 191 | return bgp_dest_from_rnode(table->route_table->top); |
67174041 AS |
192 | } |
193 | ||
194 | /* | |
195 | * bgp_table_top | |
196 | */ | |
9bcb3eef | 197 | static inline struct bgp_dest * |
d62a17ae | 198 | bgp_table_top(const struct bgp_table *const table) |
67174041 | 199 | { |
9bcb3eef | 200 | return bgp_dest_from_rnode(route_top(table->route_table)); |
67174041 AS |
201 | } |
202 | ||
203 | /* | |
204 | * bgp_route_next | |
205 | */ | |
9bcb3eef | 206 | static inline struct bgp_dest *bgp_route_next(struct bgp_dest *dest) |
67174041 | 207 | { |
9bcb3eef | 208 | return bgp_dest_from_rnode(route_next(bgp_dest_to_rnode(dest))); |
67174041 AS |
209 | } |
210 | ||
211 | /* | |
212 | * bgp_route_next_until | |
213 | */ | |
9bcb3eef DS |
214 | static inline struct bgp_dest *bgp_route_next_until(struct bgp_dest *dest, |
215 | struct bgp_dest *limit) | |
67174041 | 216 | { |
d62a17ae | 217 | struct route_node *rnode; |
67174041 | 218 | |
9bcb3eef DS |
219 | rnode = route_next_until(bgp_dest_to_rnode(dest), |
220 | bgp_dest_to_rnode(limit)); | |
221 | ||
222 | return bgp_dest_from_rnode(rnode); | |
67174041 AS |
223 | } |
224 | ||
225 | /* | |
226 | * bgp_node_get | |
227 | */ | |
9bcb3eef | 228 | static inline struct bgp_dest *bgp_node_get(struct bgp_table *const table, |
99a088e7 | 229 | const struct prefix *p) |
67174041 | 230 | { |
9bcb3eef | 231 | return bgp_dest_from_rnode(route_node_get(table->route_table, p)); |
67174041 AS |
232 | } |
233 | ||
234 | /* | |
235 | * bgp_node_lookup | |
236 | */ | |
9bcb3eef | 237 | static inline struct bgp_dest * |
99a088e7 | 238 | bgp_node_lookup(const struct bgp_table *const table, const struct prefix *p) |
67174041 | 239 | { |
9bcb3eef DS |
240 | struct route_node *rn = route_node_lookup(table->route_table, p); |
241 | ||
242 | return bgp_dest_from_rnode(rn); | |
67174041 AS |
243 | } |
244 | ||
245 | /* | |
9bcb3eef | 246 | * bgp_dest_lock_node |
67174041 | 247 | */ |
9bcb3eef | 248 | static inline struct bgp_dest *bgp_dest_lock_node(struct bgp_dest *dest) |
67174041 | 249 | { |
9bcb3eef DS |
250 | struct route_node *rn = route_lock_node(bgp_dest_to_rnode(dest)); |
251 | ||
252 | return bgp_dest_from_rnode(rn); | |
67174041 AS |
253 | } |
254 | ||
255 | /* | |
256 | * bgp_node_match | |
257 | */ | |
9bcb3eef | 258 | static inline struct bgp_dest *bgp_node_match(const struct bgp_table *table, |
99a088e7 | 259 | const struct prefix *p) |
67174041 | 260 | { |
9bcb3eef DS |
261 | struct route_node *rn = route_node_match(table->route_table, p); |
262 | ||
263 | return bgp_dest_from_rnode(rn); | |
67174041 AS |
264 | } |
265 | ||
266 | /* | |
267 | * bgp_node_match_ipv4 | |
268 | */ | |
9bcb3eef | 269 | static inline struct bgp_dest * |
d62a17ae | 270 | bgp_node_match_ipv4(const struct bgp_table *table, struct in_addr *addr) |
67174041 | 271 | { |
9bcb3eef DS |
272 | struct route_node *rn = route_node_match_ipv4(table->route_table, addr); |
273 | ||
274 | return bgp_dest_from_rnode(rn); | |
67174041 AS |
275 | } |
276 | ||
67174041 AS |
277 | /* |
278 | * bgp_node_match_ipv6 | |
279 | */ | |
9bcb3eef | 280 | static inline struct bgp_dest * |
d62a17ae | 281 | bgp_node_match_ipv6(const struct bgp_table *table, struct in6_addr *addr) |
67174041 | 282 | { |
9bcb3eef DS |
283 | struct route_node *rn = route_node_match_ipv6(table->route_table, addr); |
284 | ||
285 | return bgp_dest_from_rnode(rn); | |
67174041 AS |
286 | } |
287 | ||
d62a17ae | 288 | static inline unsigned long bgp_table_count(const struct bgp_table *const table) |
67174041 | 289 | { |
d62a17ae | 290 | return route_table_count(table->route_table); |
67174041 AS |
291 | } |
292 | ||
28971c8c AS |
293 | /* |
294 | * bgp_table_get_next | |
295 | */ | |
9bcb3eef | 296 | static inline struct bgp_dest *bgp_table_get_next(const struct bgp_table *table, |
99a088e7 | 297 | const struct prefix *p) |
28971c8c | 298 | { |
9bcb3eef | 299 | return bgp_dest_from_rnode(route_table_get_next(table->route_table, p)); |
28971c8c AS |
300 | } |
301 | ||
302 | /* | |
303 | * bgp_table_iter_init | |
304 | */ | |
d62a17ae | 305 | static inline void bgp_table_iter_init(bgp_table_iter_t *iter, |
306 | struct bgp_table *table) | |
28971c8c | 307 | { |
d62a17ae | 308 | bgp_table_lock(table); |
309 | iter->table = table; | |
310 | route_table_iter_init(&iter->rt_iter, table->route_table); | |
28971c8c AS |
311 | } |
312 | ||
313 | /* | |
314 | * bgp_table_iter_next | |
315 | */ | |
9bcb3eef | 316 | static inline struct bgp_dest *bgp_table_iter_next(bgp_table_iter_t *iter) |
28971c8c | 317 | { |
9bcb3eef | 318 | return bgp_dest_from_rnode(route_table_iter_next(&iter->rt_iter)); |
28971c8c AS |
319 | } |
320 | ||
321 | /* | |
322 | * bgp_table_iter_cleanup | |
323 | */ | |
d62a17ae | 324 | static inline void bgp_table_iter_cleanup(bgp_table_iter_t *iter) |
28971c8c | 325 | { |
d62a17ae | 326 | route_table_iter_cleanup(&iter->rt_iter); |
327 | bgp_table_unlock(iter->table); | |
328 | iter->table = NULL; | |
28971c8c AS |
329 | } |
330 | ||
331 | /* | |
332 | * bgp_table_iter_pause | |
333 | */ | |
d62a17ae | 334 | static inline void bgp_table_iter_pause(bgp_table_iter_t *iter) |
28971c8c | 335 | { |
d62a17ae | 336 | route_table_iter_pause(&iter->rt_iter); |
28971c8c AS |
337 | } |
338 | ||
339 | /* | |
340 | * bgp_table_iter_is_done | |
341 | */ | |
d62a17ae | 342 | static inline int bgp_table_iter_is_done(bgp_table_iter_t *iter) |
28971c8c | 343 | { |
d62a17ae | 344 | return route_table_iter_is_done(&iter->rt_iter); |
28971c8c AS |
345 | } |
346 | ||
347 | /* | |
348 | * bgp_table_iter_started | |
349 | */ | |
d62a17ae | 350 | static inline int bgp_table_iter_started(bgp_table_iter_t *iter) |
28971c8c | 351 | { |
d62a17ae | 352 | return route_table_iter_started(&iter->rt_iter); |
28971c8c AS |
353 | } |
354 | ||
3f9c7369 DS |
355 | /* This would benefit from a real atomic operation... |
356 | * until then. */ | |
d62a17ae | 357 | static inline uint64_t bgp_table_next_version(struct bgp_table *table) |
3f9c7369 | 358 | { |
d62a17ae | 359 | return ++table->version; |
3f9c7369 DS |
360 | } |
361 | ||
d62a17ae | 362 | static inline uint64_t bgp_table_version(struct bgp_table *table) |
3f9c7369 | 363 | { |
d62a17ae | 364 | return table->version; |
3f9c7369 DS |
365 | } |
366 | ||
bac31cb8 MR |
367 | /* Find the subtree of the prefix p |
368 | * | |
369 | * This will return the first node that belongs the the subtree of p. Including | |
370 | * p itself, if it is in the tree. | |
371 | * | |
372 | * If the subtree is not present in the table, NULL is returned. | |
373 | */ | |
9bcb3eef | 374 | struct bgp_dest *bgp_table_subtree_lookup(const struct bgp_table *table, |
bac31cb8 | 375 | const struct prefix *p); |
1dacdd8b | 376 | |
b1e62edd | 377 | static inline struct bgp_aggregate * |
9bcb3eef | 378 | bgp_dest_get_bgp_aggregate_info(struct bgp_dest *dest) |
b1e62edd | 379 | { |
9bcb3eef | 380 | return dest ? dest->info : NULL; |
b1e62edd DS |
381 | } |
382 | ||
b613a918 | 383 | static inline void |
9bcb3eef | 384 | bgp_dest_set_bgp_aggregate_info(struct bgp_dest *dest, |
b613a918 | 385 | struct bgp_aggregate *aggregate) |
b1e62edd | 386 | { |
9bcb3eef | 387 | dest->info = aggregate; |
b1e62edd DS |
388 | } |
389 | ||
5b00b40e | 390 | static inline struct bgp_distance * |
9bcb3eef | 391 | bgp_dest_get_bgp_distance_info(struct bgp_dest *dest) |
ca2e160d | 392 | { |
9bcb3eef | 393 | return dest ? dest->info : NULL; |
ca2e160d DS |
394 | } |
395 | ||
9bcb3eef | 396 | static inline void bgp_dest_set_bgp_distance_info(struct bgp_dest *dest, |
5b00b40e | 397 | struct bgp_distance *distance) |
ca2e160d | 398 | { |
9bcb3eef | 399 | dest->info = distance; |
ca2e160d DS |
400 | } |
401 | ||
5a8ba9fc | 402 | static inline struct bgp_static * |
9bcb3eef | 403 | bgp_dest_get_bgp_static_info(struct bgp_dest *dest) |
a78beeb5 | 404 | { |
9bcb3eef | 405 | return dest ? dest->info : NULL; |
a78beeb5 DS |
406 | } |
407 | ||
9bcb3eef | 408 | static inline void bgp_dest_set_bgp_static_info(struct bgp_dest *dest, |
5a8ba9fc | 409 | struct bgp_static *bgp_static) |
a78beeb5 | 410 | { |
9bcb3eef | 411 | dest->info = bgp_static; |
a78beeb5 | 412 | } |
3d9dbdbe DS |
413 | |
414 | static inline struct bgp_connected_ref * | |
9bcb3eef | 415 | bgp_dest_get_bgp_connected_ref_info(struct bgp_dest *dest) |
3d9dbdbe | 416 | { |
9bcb3eef | 417 | return dest ? dest->info : NULL; |
3d9dbdbe DS |
418 | } |
419 | ||
cb8c85ab | 420 | static inline void |
9bcb3eef | 421 | bgp_dest_set_bgp_connected_ref_info(struct bgp_dest *dest, |
cb8c85ab | 422 | struct bgp_connected_ref *bc) |
3d9dbdbe | 423 | { |
9bcb3eef | 424 | dest->info = bc; |
3d9dbdbe DS |
425 | } |
426 | ||
14315f2d | 427 | static inline struct bgp_nexthop_cache * |
9bcb3eef | 428 | bgp_dest_get_bgp_nexthop_info(struct bgp_dest *dest) |
14315f2d | 429 | { |
9bcb3eef | 430 | return dest ? dest->info : NULL; |
14315f2d DS |
431 | } |
432 | ||
9bcb3eef DS |
433 | static inline void bgp_dest_set_bgp_nexthop_info(struct bgp_dest *dest, |
434 | struct bgp_nexthop_cache *bnc) | |
14315f2d | 435 | { |
9bcb3eef | 436 | dest->info = bnc; |
14315f2d DS |
437 | } |
438 | ||
6f94b685 | 439 | static inline struct bgp_path_info * |
9bcb3eef | 440 | bgp_dest_get_bgp_path_info(struct bgp_dest *dest) |
6f94b685 | 441 | { |
9bcb3eef | 442 | return dest ? dest->info : NULL; |
6f94b685 DS |
443 | } |
444 | ||
9bcb3eef | 445 | static inline void bgp_dest_set_bgp_path_info(struct bgp_dest *dest, |
6f94b685 DS |
446 | struct bgp_path_info *bi) |
447 | { | |
9bcb3eef | 448 | dest->info = bi; |
6f94b685 DS |
449 | } |
450 | ||
67009e22 | 451 | static inline struct bgp_table * |
9bcb3eef | 452 | bgp_dest_get_bgp_table_info(struct bgp_dest *dest) |
67009e22 | 453 | { |
9bcb3eef | 454 | return dest->info; |
67009e22 DS |
455 | } |
456 | ||
9bcb3eef | 457 | static inline void bgp_dest_set_bgp_table_info(struct bgp_dest *dest, |
67009e22 DS |
458 | struct bgp_table *table) |
459 | { | |
9bcb3eef | 460 | dest->info = table; |
67009e22 DS |
461 | } |
462 | ||
9bcb3eef | 463 | static inline bool bgp_dest_has_bgp_path_info_data(struct bgp_dest *dest) |
6f94b685 | 464 | { |
9bcb3eef | 465 | return !!dest->info; |
6f94b685 DS |
466 | } |
467 | ||
9bcb3eef | 468 | static inline const struct prefix *bgp_dest_get_prefix(const struct bgp_dest *dest) |
b54892e0 | 469 | { |
9bcb3eef | 470 | return &dest->p; |
b54892e0 DS |
471 | } |
472 | ||
c10e14e9 DS |
473 | static inline unsigned int bgp_dest_get_lock_count(const struct bgp_dest *dest) |
474 | { | |
475 | return dest->lock; | |
476 | } | |
477 | ||
07ef3e34 DL |
478 | #ifdef _FRR_ATTRIBUTE_PRINTFRR |
479 | #pragma FRR printfrr_ext "%pRN" (struct bgp_node *) | |
56ca3b5b | 480 | #pragma FRR printfrr_ext "%pBD" (struct bgp_dest *) |
07ef3e34 DL |
481 | #endif |
482 | ||
00d252cb | 483 | #endif /* _QUAGGA_BGP_TABLE_H */ |