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