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