]> git.proxmox.com Git - mirror_frr.git/blob - bgpd/bgp_table.h
Merge pull request #8887 from LabNConsulting/chopps/fix-test-retries
[mirror_frr.git] / bgpd / bgp_table.h
1 /* BGP routing table
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 */
20
21 #ifndef _QUAGGA_BGP_TABLE_H
22 #define _QUAGGA_BGP_TABLE_H
23
24 /* XXX BEGIN TEMPORARY COMPAT */
25 #define bgp_dest bgp_node
26 /* XXX END TEMPORARY COMPAT */
27
28 #include "mpls.h"
29 #include "table.h"
30 #include "queue.h"
31 #include "linklist.h"
32 #include "bgpd.h"
33 #include "bgp_advertise.h"
34 #include "bgpd/bgp_trace.h"
35
36 struct bgp_table {
37 /* table belongs to this instance */
38 struct bgp *bgp;
39
40 /* afi/safi of this table */
41 afi_t afi;
42 safi_t safi;
43
44 int lock;
45
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
53 struct route_table *route_table;
54 uint64_t version;
55 };
56
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,
62 bgp_path_selection_evpn_local_path,
63 bgp_path_selection_evpn_non_proxy,
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
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
94
95 struct bgp_adj_out_rb adj_out;
96
97 struct bgp_adj_in *adj_in;
98
99 struct bgp_dest *pdest;
100
101 STAILQ_ENTRY(bgp_dest) pq;
102
103 uint64_t version;
104
105 mpls_label_t local_label;
106
107 uint16_t flags;
108 #define BGP_NODE_PROCESS_SCHEDULED (1 << 0)
109 #define BGP_NODE_USER_CLEAR (1 << 1)
110 #define BGP_NODE_LABEL_CHANGED (1 << 2)
111 #define BGP_NODE_REGISTERED_FOR_LABEL (1 << 3)
112 #define BGP_NODE_SELECT_DEFER (1 << 4)
113 #define BGP_NODE_FIB_INSTALL_PENDING (1 << 5)
114 #define BGP_NODE_FIB_INSTALLED (1 << 6)
115 #define BGP_NODE_LABEL_REQUESTED (1 << 7)
116 #define BGP_NODE_SOFT_RECONFIG (1 << 8)
117
118 struct bgp_addpath_node_data tx_addpath;
119
120 enum bgp_path_selection_reason reason;
121 };
122
123 extern void bgp_delete_listnode(struct bgp_dest *dest);
124 /*
125 * bgp_table_iter_t
126 *
127 * Structure that holds state for iterating over a bgp table.
128 */
129 typedef struct bgp_table_iter_t_ {
130 struct bgp_table *table;
131 route_table_iter_t rt_iter;
132 } bgp_table_iter_t;
133
134 extern struct bgp_table *bgp_table_init(struct bgp *bgp, afi_t, safi_t);
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 **);
138
139
140 /*
141 * bgp_dest_from_rnode
142 *
143 * Returns the bgp_dest structure corresponding to a route_node.
144 */
145 static inline struct bgp_dest *bgp_dest_from_rnode(struct route_node *rnode)
146 {
147 return (struct bgp_dest *)rnode;
148 }
149
150 /*
151 * bgp_dest_to_rnode
152 *
153 * Returns the route_node structure corresponding to a bgp_dest.
154 */
155 static inline struct route_node *bgp_dest_to_rnode(const struct bgp_dest *dest)
156 {
157 return (struct route_node *)dest;
158 }
159
160 /*
161 * bgp_dest_table
162 *
163 * Returns the bgp_table that the given dest is in.
164 */
165 static inline struct bgp_table *bgp_dest_table(struct bgp_dest *dest)
166 {
167 return route_table_get_info(bgp_dest_to_rnode(dest)->table);
168 }
169
170 /*
171 * bgp_dest_parent_nolock
172 *
173 * Gets the parent dest of the given node without locking it.
174 */
175 static inline struct bgp_dest *bgp_dest_parent_nolock(struct bgp_dest *dest)
176 {
177 struct route_node *rn = bgp_dest_to_rnode(dest)->parent;
178
179 return bgp_dest_from_rnode(rn);
180 }
181
182 /*
183 * bgp_dest_unlock_node
184 */
185 static inline void bgp_dest_unlock_node(struct bgp_dest *dest)
186 {
187 frrtrace(1, frr_bgp, bgp_dest_unlock, dest);
188 bgp_delete_listnode(dest);
189 route_unlock_node(bgp_dest_to_rnode(dest));
190 }
191
192 /*
193 * bgp_table_top_nolock
194 *
195 * Gets the top dest in the table without locking it.
196 *
197 * @see bgp_table_top
198 */
199 static inline struct bgp_dest *
200 bgp_table_top_nolock(const struct bgp_table *const table)
201 {
202 return bgp_dest_from_rnode(table->route_table->top);
203 }
204
205 /*
206 * bgp_table_top
207 */
208 static inline struct bgp_dest *
209 bgp_table_top(const struct bgp_table *const table)
210 {
211 return bgp_dest_from_rnode(route_top(table->route_table));
212 }
213
214 /*
215 * bgp_route_next
216 */
217 static inline struct bgp_dest *bgp_route_next(struct bgp_dest *dest)
218 {
219 return bgp_dest_from_rnode(route_next(bgp_dest_to_rnode(dest)));
220 }
221
222 /*
223 * bgp_route_next_until
224 */
225 static inline struct bgp_dest *bgp_route_next_until(struct bgp_dest *dest,
226 struct bgp_dest *limit)
227 {
228 struct route_node *rnode;
229
230 rnode = route_next_until(bgp_dest_to_rnode(dest),
231 bgp_dest_to_rnode(limit));
232
233 return bgp_dest_from_rnode(rnode);
234 }
235
236 /*
237 * bgp_node_get
238 */
239 static inline struct bgp_dest *bgp_node_get(struct bgp_table *const table,
240 const struct prefix *p)
241 {
242 return bgp_dest_from_rnode(route_node_get(table->route_table, p));
243 }
244
245 /*
246 * bgp_node_lookup
247 */
248 static inline struct bgp_dest *
249 bgp_node_lookup(const struct bgp_table *const table, const struct prefix *p)
250 {
251 struct route_node *rn = route_node_lookup(table->route_table, p);
252
253 return bgp_dest_from_rnode(rn);
254 }
255
256 /*
257 * bgp_dest_lock_node
258 */
259 static inline struct bgp_dest *bgp_dest_lock_node(struct bgp_dest *dest)
260 {
261 frrtrace(1, frr_bgp, bgp_dest_lock, dest);
262 struct route_node *rn = route_lock_node(bgp_dest_to_rnode(dest));
263
264 return bgp_dest_from_rnode(rn);
265 }
266
267 /*
268 * bgp_node_match
269 */
270 static inline struct bgp_dest *bgp_node_match(const struct bgp_table *table,
271 const struct prefix *p)
272 {
273 struct route_node *rn = route_node_match(table->route_table, p);
274
275 return bgp_dest_from_rnode(rn);
276 }
277
278 /*
279 * bgp_node_match_ipv4
280 */
281 static inline struct bgp_dest *
282 bgp_node_match_ipv4(const struct bgp_table *table, struct in_addr *addr)
283 {
284 struct route_node *rn = route_node_match_ipv4(table->route_table, addr);
285
286 return bgp_dest_from_rnode(rn);
287 }
288
289 /*
290 * bgp_node_match_ipv6
291 */
292 static inline struct bgp_dest *
293 bgp_node_match_ipv6(const struct bgp_table *table, struct in6_addr *addr)
294 {
295 struct route_node *rn = route_node_match_ipv6(table->route_table, addr);
296
297 return bgp_dest_from_rnode(rn);
298 }
299
300 static inline unsigned long bgp_table_count(const struct bgp_table *const table)
301 {
302 return route_table_count(table->route_table);
303 }
304
305 /*
306 * bgp_table_get_next
307 */
308 static inline struct bgp_dest *bgp_table_get_next(const struct bgp_table *table,
309 const struct prefix *p)
310 {
311 return bgp_dest_from_rnode(route_table_get_next(table->route_table, p));
312 }
313
314 /*
315 * bgp_table_iter_init
316 */
317 static inline void bgp_table_iter_init(bgp_table_iter_t *iter,
318 struct bgp_table *table)
319 {
320 bgp_table_lock(table);
321 iter->table = table;
322 route_table_iter_init(&iter->rt_iter, table->route_table);
323 }
324
325 /*
326 * bgp_table_iter_next
327 */
328 static inline struct bgp_dest *bgp_table_iter_next(bgp_table_iter_t *iter)
329 {
330 return bgp_dest_from_rnode(route_table_iter_next(&iter->rt_iter));
331 }
332
333 /*
334 * bgp_table_iter_cleanup
335 */
336 static inline void bgp_table_iter_cleanup(bgp_table_iter_t *iter)
337 {
338 route_table_iter_cleanup(&iter->rt_iter);
339 bgp_table_unlock(iter->table);
340 iter->table = NULL;
341 }
342
343 /*
344 * bgp_table_iter_pause
345 */
346 static inline void bgp_table_iter_pause(bgp_table_iter_t *iter)
347 {
348 route_table_iter_pause(&iter->rt_iter);
349 }
350
351 /*
352 * bgp_table_iter_is_done
353 */
354 static inline int bgp_table_iter_is_done(bgp_table_iter_t *iter)
355 {
356 return route_table_iter_is_done(&iter->rt_iter);
357 }
358
359 /*
360 * bgp_table_iter_started
361 */
362 static inline int bgp_table_iter_started(bgp_table_iter_t *iter)
363 {
364 return route_table_iter_started(&iter->rt_iter);
365 }
366
367 /* This would benefit from a real atomic operation...
368 * until then. */
369 static inline uint64_t bgp_table_next_version(struct bgp_table *table)
370 {
371 return ++table->version;
372 }
373
374 static inline uint64_t bgp_table_version(struct bgp_table *table)
375 {
376 return table->version;
377 }
378
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 */
386 struct bgp_dest *bgp_table_subtree_lookup(const struct bgp_table *table,
387 const struct prefix *p);
388
389 static inline struct bgp_aggregate *
390 bgp_dest_get_bgp_aggregate_info(struct bgp_dest *dest)
391 {
392 return dest ? dest->info : NULL;
393 }
394
395 static inline void
396 bgp_dest_set_bgp_aggregate_info(struct bgp_dest *dest,
397 struct bgp_aggregate *aggregate)
398 {
399 dest->info = aggregate;
400 }
401
402 static inline struct bgp_distance *
403 bgp_dest_get_bgp_distance_info(struct bgp_dest *dest)
404 {
405 return dest ? dest->info : NULL;
406 }
407
408 static inline void bgp_dest_set_bgp_distance_info(struct bgp_dest *dest,
409 struct bgp_distance *distance)
410 {
411 dest->info = distance;
412 }
413
414 static inline struct bgp_static *
415 bgp_dest_get_bgp_static_info(struct bgp_dest *dest)
416 {
417 return dest ? dest->info : NULL;
418 }
419
420 static inline void bgp_dest_set_bgp_static_info(struct bgp_dest *dest,
421 struct bgp_static *bgp_static)
422 {
423 dest->info = bgp_static;
424 }
425
426 static inline struct bgp_connected_ref *
427 bgp_dest_get_bgp_connected_ref_info(struct bgp_dest *dest)
428 {
429 return dest ? dest->info : NULL;
430 }
431
432 static inline void
433 bgp_dest_set_bgp_connected_ref_info(struct bgp_dest *dest,
434 struct bgp_connected_ref *bc)
435 {
436 dest->info = bc;
437 }
438
439 static inline struct bgp_nexthop_cache *
440 bgp_dest_get_bgp_nexthop_info(struct bgp_dest *dest)
441 {
442 return dest ? dest->info : NULL;
443 }
444
445 static inline void bgp_dest_set_bgp_nexthop_info(struct bgp_dest *dest,
446 struct bgp_nexthop_cache *bnc)
447 {
448 dest->info = bnc;
449 }
450
451 static inline struct bgp_path_info *
452 bgp_dest_get_bgp_path_info(struct bgp_dest *dest)
453 {
454 return dest ? dest->info : NULL;
455 }
456
457 static inline void bgp_dest_set_bgp_path_info(struct bgp_dest *dest,
458 struct bgp_path_info *bi)
459 {
460 dest->info = bi;
461 }
462
463 static inline struct bgp_table *
464 bgp_dest_get_bgp_table_info(struct bgp_dest *dest)
465 {
466 return dest->info;
467 }
468
469 static inline void bgp_dest_set_bgp_table_info(struct bgp_dest *dest,
470 struct bgp_table *table)
471 {
472 dest->info = table;
473 }
474
475 static inline bool bgp_dest_has_bgp_path_info_data(struct bgp_dest *dest)
476 {
477 return !!dest->info;
478 }
479
480 static inline const struct prefix *bgp_dest_get_prefix(const struct bgp_dest *dest)
481 {
482 return &dest->p;
483 }
484
485 static inline unsigned int bgp_dest_get_lock_count(const struct bgp_dest *dest)
486 {
487 return dest->lock;
488 }
489
490 #ifdef _FRR_ATTRIBUTE_PRINTFRR
491 #pragma FRR printfrr_ext "%pRN" (struct bgp_node *)
492 #pragma FRR printfrr_ext "%pBD" (struct bgp_dest *)
493 #endif
494
495 #endif /* _QUAGGA_BGP_TABLE_H */