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