blob: 0eaaa67eea2d9e7b5b983f4a59d8199e221948f1 [file] [log] [blame]
Neale Ranns0bfe5d82016-08-25 15:29:12 +01001/*
2 * Copyright (c) 2016 Cisco and/or its affiliates.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at:
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16#ifndef __FIB_TABLE_H__
17#define __FIB_TABLE_H__
18
19#include <vnet/ip/ip.h>
20#include <vnet/adj/adj.h>
21#include <vnet/fib/fib_entry.h>
22#include <vnet/mpls/mpls.h>
23#include <vnet/mpls/packet.h>
24
25/**
Neale Ranns53da2212018-02-24 02:11:19 -080026 * Flags for the source data
27 */
28typedef enum fib_table_attribute_t_ {
29 /**
30 * Marker. Add new values after this one.
31 */
32 FIB_TABLE_ATTRIBUTE_FIRST,
33 /**
34 * the table is for IP6 link local addresses
35 */
36 FIB_TABLE_ATTRIBUTE_IP6_LL = FIB_TABLE_ATTRIBUTE_FIRST,
37 /**
Neale Ranns9db6ada2019-11-08 12:42:31 +000038 * the table is currently resync-ing
39 */
40 FIB_TABLE_ATTRIBUTE_RESYNC,
41 /**
Neale Ranns53da2212018-02-24 02:11:19 -080042 * Marker. add new entries before this one.
43 */
Neale Ranns9db6ada2019-11-08 12:42:31 +000044 FIB_TABLE_ATTRIBUTE_LAST = FIB_TABLE_ATTRIBUTE_RESYNC,
Neale Ranns53da2212018-02-24 02:11:19 -080045} fib_table_attribute_t;
46
47#define FIB_TABLE_ATTRIBUTE_MAX (FIB_TABLE_ATTRIBUTE_LAST+1)
48
49#define FIB_TABLE_ATTRIBUTES { \
50 [FIB_TABLE_ATTRIBUTE_IP6_LL] = "ip6-ll", \
Neale Ranns9db6ada2019-11-08 12:42:31 +000051 [FIB_TABLE_ATTRIBUTE_RESYNC] = "resync", \
Neale Ranns53da2212018-02-24 02:11:19 -080052}
53
54#define FOR_EACH_FIB_TABLE_ATTRIBUTE(_item) \
55 for (_item = FIB_TABLE_ATTRIBUTE_FIRST; \
56 _item < FIB_TABLE_ATTRIBUTE_MAX; \
57 _item++)
58
59typedef enum fib_table_flags_t_ {
60 FIB_TABLE_FLAG_NONE = 0,
61 FIB_TABLE_FLAG_IP6_LL = (1 << FIB_TABLE_ATTRIBUTE_IP6_LL),
Neale Ranns9db6ada2019-11-08 12:42:31 +000062 FIB_TABLE_FLAG_RESYNC = (1 << FIB_TABLE_ATTRIBUTE_RESYNC),
Neale Ranns53da2212018-02-24 02:11:19 -080063} __attribute__ ((packed)) fib_table_flags_t;
64
Neale Ranns9db6ada2019-11-08 12:42:31 +000065extern u8* format_fib_table_flags(u8 *s, va_list *args);
66
Neale Ranns53da2212018-02-24 02:11:19 -080067/**
Neale Ranns0bfe5d82016-08-25 15:29:12 +010068 * @brief
69 * A protocol Independent FIB table
70 */
71typedef struct fib_table_t_
72{
73 /**
Neale Ranns0bfe5d82016-08-25 15:29:12 +010074 * Which protocol this table serves. Used to switch on the union above.
75 */
76 fib_protocol_t ft_proto;
77
78 /**
Neale Ranns53da2212018-02-24 02:11:19 -080079 * Table flags
80 */
81 fib_table_flags_t ft_flags;
82
83 /**
Neale Ranns15002542017-09-10 04:39:11 -070084 * per-source number of locks on the table
Neale Ranns0bfe5d82016-08-25 15:29:12 +010085 */
Miklos Tirpak4a94cd22019-12-20 11:55:43 +010086 u32 *ft_locks;
Neale Ranns3bab8f92019-12-04 06:11:00 +000087 u32 ft_total_locks;
Neale Ranns0bfe5d82016-08-25 15:29:12 +010088
89 /**
90 * Table ID (hash key) for this FIB.
91 */
92 u32 ft_table_id;
93
94 /**
95 * Index into FIB vector.
96 */
97 fib_node_index_t ft_index;
98
99 /**
100 * flow hash configuration
101 */
102 u32 ft_flow_hash_config;
103
104 /**
105 * Per-source route counters
106 */
Neale Ranns3bab8f92019-12-04 06:11:00 +0000107 u32 *ft_src_route_counts;
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100108
109 /**
110 * Total route counters
111 */
112 u32 ft_total_route_counts;
113
114 /**
Neale Ranns9db6ada2019-11-08 12:42:31 +0000115 * Epoch - number of resyncs performed
116 */
117 u32 ft_epoch;
118
119 /**
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100120 * Table description
121 */
122 u8* ft_desc;
123} fib_table_t;
124
Jon Loeligerd465fd02024-03-22 12:22:36 -0500125
126/**
127 * @brief
128 * Default names for IP4, IP6, and MPLS FIB table index 0.
129 * Nominally like "ipv4-VRF:0", but this will override that name if set
130 * in a config section of the startup.conf file.
131 */
132extern char *fib_table_default_names[FIB_PROTOCOL_MAX];
133
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100134/**
135 * @brief
136 * Format the description/name of the table
137 */
Christophe Fontained3c008d2017-10-02 18:10:54 +0200138extern u8* format_fib_table_name(u8* s, va_list *ap);
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100139
140/**
141 * @brief
142 * Perfom a longest prefix match in the non-forwarding table
143 *
144 * @param fib_index
145 * The index of the FIB
146 *
147 * @param prefix
148 * The prefix to lookup
149 *
150 * @return
151 * The index of the fib_entry_t for the best match, which may be the default route
152 */
153extern fib_node_index_t fib_table_lookup(u32 fib_index,
154 const fib_prefix_t *prefix);
155
156/**
157 * @brief
158 * Perfom an exact match in the non-forwarding table
159 *
160 * @param fib_index
161 * The index of the FIB
162 *
163 * @param prefix
164 * The prefix to lookup
165 *
166 * @return
167 * The index of the fib_entry_t for the exact match, or INVALID
168 * is there is no match.
169 */
170extern fib_node_index_t fib_table_lookup_exact_match(u32 fib_index,
171 const fib_prefix_t *prefix);
172
173/**
174 * @brief
175 * Get the less specific (covering) prefix
176 *
177 * @param fib_index
178 * The index of the FIB
179 *
180 * @param prefix
181 * The prefix to lookup
182 *
183 * @return
184 * The index of the less specific fib_entry_t.
185 */
186extern fib_node_index_t fib_table_get_less_specific(u32 fib_index,
187 const fib_prefix_t *prefix);
188
189/**
190 * @brief
Neale Rannsa0558302017-04-13 00:44:52 -0700191 * Add a 'special' entry to the FIB.
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100192 * A special entry is an entry that the FIB is not expect to resolve
193 * via the usual mechanisms (i.e. recurisve or neighbour adj DB lookup).
Neale Rannsa0558302017-04-13 00:44:52 -0700194 * Instead the will link to a DPO valid for the source and/or the flags.
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100195 * This add is reference counting per-source. So n 'removes' are required
196 * for n 'adds', if the entry is no longer required.
Neale Rannsa0558302017-04-13 00:44:52 -0700197 * If the source needs to provide non-default forwarding use:
198 * fib_table_entry_special_dpo_add()
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100199 *
Neale Rannsa0558302017-04-13 00:44:52 -0700200 * @param fib_index
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100201 * The index of the FIB
202 *
203 * @param prefix
204 * The prefix to add
205 *
206 * @param source
207 * The ID of the client/source adding the entry.
208 *
209 * @param flags
210 * Flags for the entry.
211 *
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100212 * @return
213 * the index of the fib_entry_t that is created (or exists already).
214 */
215extern fib_node_index_t fib_table_entry_special_add(u32 fib_index,
216 const fib_prefix_t *prefix,
217 fib_source_t source,
Neale Rannsa0558302017-04-13 00:44:52 -0700218 fib_entry_flag_t flags);
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100219
220/**
221 * @brief
222 * Add a 'special' entry to the FIB that links to the DPO passed
223 * A special entry is an entry that the FIB is not expect to resolve
224 * via the usual mechanisms (i.e. recurisve or neighbour adj DB lookup).
225 * Instead the client/source provides the DPO to link to.
226 * This add is reference counting per-source. So n 'removes' are required
227 * for n 'adds', if the entry is no longer required.
228 *
229 * @param fib_index
230 * The index of the FIB
231 *
232 * @param prefix
233 * The prefix to add
234 *
235 * @param source
236 * The ID of the client/source adding the entry.
237 *
238 * @param flags
239 * Flags for the entry.
240 *
241 * @param dpo
242 * The DPO to link to.
243 *
244 * @return
245 * the index of the fib_entry_t that is created (or existed already).
246 */
247extern fib_node_index_t fib_table_entry_special_dpo_add(u32 fib_index,
248 const fib_prefix_t *prefix,
249 fib_source_t source,
250 fib_entry_flag_t stype,
251 const dpo_id_t *dpo);
252
253/**
254 * @brief
255 * Update a 'special' entry to the FIB that links to the DPO passed
256 * A special entry is an entry that the FIB is not expect to resolve
257 * via the usual mechanisms (i.e. recurisve or neighbour adj DB lookup).
258 * Instead the client/source provides the DPO to link to.
259 * Special entries are add/remove reference counted per-source. So n
260 * 'removes' are required for n 'adds', if the entry is no longer required.
Neale Ranns948e00f2016-10-20 13:39:34 +0100261 * An 'update' is an 'add' if no 'add' has already been called, otherwise an 'add'
262 * is therefore assumed to act on the reference instance of that add.
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100263 *
264 * @param fib_entry_index
265 * The index of the FIB entry to update
266 *
267 * @param source
268 * The ID of the client/source adding the entry.
269 *
270 * @param flags
271 * Flags for the entry.
272 *
273 * @param dpo
274 * The DPO to link to.
275 *
276 * @return
277 * the index of the fib_entry_t that is created (or existed already).
278 */
Neale Ranns948e00f2016-10-20 13:39:34 +0100279extern fib_node_index_t fib_table_entry_special_dpo_update (u32 fib_index,
280 const fib_prefix_t *prefix,
281 fib_source_t source,
282 fib_entry_flag_t stype,
283 const dpo_id_t *dpo);
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100284
285/**
286 * @brief
287 * Remove a 'special' entry from the FIB.
288 * This add is reference counting per-source. So n 'removes' are required
289 * for n 'adds', if the entry is no longer required.
290 *
291 * @param fib_index
292 * The index of the FIB
293 *
294 * @param prefix
295 * The prefix to remove
296 *
297 * @param source
298 * The ID of the client/source adding the entry.
299 *
300 */
301extern void fib_table_entry_special_remove(u32 fib_index,
302 const fib_prefix_t *prefix,
303 fib_source_t source);
304
305/**
306 * @brief
307 * Add one path to an entry (aka route) in the FIB. If the entry does not
308 * exist, it will be created.
309 * See the documentation for fib_route_path_t for more descirptions of
310 * the path parameters.
311 *
312 * @param fib_index
313 * The index of the FIB
314 *
315 * @param prefix
316 * The prefix for the entry to add
317 *
318 * @param source
319 * The ID of the client/source adding the entry.
320 *
321 * @param flags
322 * Flags for the entry.
323 *
324 * @paran next_hop_proto
325 * The protocol of the next hop. This cannot be derived in the event that
326 * the next hop is all zeros.
327 *
328 * @param next_hop
329 * The address of the next-hop.
330 *
331 * @param sw_if_index
332 * The index of the interface.
333 *
334 * @param next_hop_fib_index,
335 * The fib index of the next-hop for recursive resolution
336 *
337 * @param next_hop_weight
338 * [un]equal cost path weight
339 *
Neale Rannsad422ed2016-11-02 14:20:04 +0000340 * @param next_hop_label_stack
341 * The path's out-going label stack. NULL is there is none.
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100342 *
343 * @param pf
344 * Flags for the path
345 *
346 * @return
347 * the index of the fib_entry_t that is created (or existed already).
348 */
349extern fib_node_index_t fib_table_entry_path_add(u32 fib_index,
350 const fib_prefix_t *prefix,
351 fib_source_t source,
352 fib_entry_flag_t flags,
Neale Rannsda78f952017-05-24 09:15:43 -0700353 dpo_proto_t next_hop_proto,
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100354 const ip46_address_t *next_hop,
355 u32 next_hop_sw_if_index,
356 u32 next_hop_fib_index,
357 u32 next_hop_weight,
Neale Ranns31ed7442018-02-23 05:29:09 -0800358 fib_mpls_label_t *next_hop_label_stack,
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100359 fib_route_path_flags_t pf);
360/**
361 * @brief
362 * Add n paths to an entry (aka route) in the FIB. If the entry does not
363 * exist, it will be created.
364 * See the documentation for fib_route_path_t for more descirptions of
365 * the path parameters.
366 *
367 * @param fib_index
368 * The index of the FIB
369 *
370 * @param prefix
371 * The prefix for the entry to add
372 *
373 * @param source
374 * The ID of the client/source adding the entry.
375 *
376 * @param flags
377 * Flags for the entry.
378 *
379 * @param rpaths
Neale Rannsad422ed2016-11-02 14:20:04 +0000380 * A vector of paths. Not const since they may be modified.
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100381 *
382 * @return
383 * the index of the fib_entry_t that is created (or existed already).
384 */
385extern fib_node_index_t fib_table_entry_path_add2(u32 fib_index,
386 const fib_prefix_t *prefix,
387 fib_source_t source,
388 fib_entry_flag_t flags,
Neale Rannsad422ed2016-11-02 14:20:04 +0000389 fib_route_path_t *rpath);
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100390
391/**
392 * @brief
393 * remove one path to an entry (aka route) in the FIB. If this is the entry's
394 * last path, then the entry will be removed, unless it has other sources.
395 * See the documentation for fib_route_path_t for more descirptions of
396 * the path parameters.
397 *
398 * @param fib_index
399 * The index of the FIB
400 *
401 * @param prefix
402 * The prefix for the entry to add
403 *
404 * @param source
405 * The ID of the client/source adding the entry.
406 *
407 * @paran next_hop_proto
408 * The protocol of the next hop. This cannot be derived in the event that
409 * the next hop is all zeros.
410 *
411 * @param next_hop
412 * The address of the next-hop.
413 *
414 * @param sw_if_index
415 * The index of the interface.
416 *
417 * @param next_hop_fib_index,
418 * The fib index of the next-hop for recursive resolution
419 *
420 * @param next_hop_weight
421 * [un]equal cost path weight
422 *
423 * @param pf
424 * Flags for the path
425 */
426extern void fib_table_entry_path_remove(u32 fib_index,
427 const fib_prefix_t *prefix,
428 fib_source_t source,
Neale Rannsda78f952017-05-24 09:15:43 -0700429 dpo_proto_t next_hop_proto,
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100430 const ip46_address_t *next_hop,
431 u32 next_hop_sw_if_index,
432 u32 next_hop_fib_index,
433 u32 next_hop_weight,
434 fib_route_path_flags_t pf);
435
436/**
437 * @brief
438 * Remove n paths to an entry (aka route) in the FIB. If this is the entry's
439 * last path, then the entry will be removed, unless it has other sources.
440 * See the documentation for fib_route_path_t for more descirptions of
441 * the path parameters.
442 *
443 * @param fib_index
444 * The index of the FIB
445 *
446 * @param prefix
447 * The prefix for the entry to add
448 *
449 * @param source
450 * The ID of the client/source adding the entry.
451 *
452 * @param rpaths
453 * A vector of paths.
454 */
455extern void fib_table_entry_path_remove2(u32 fib_index,
456 const fib_prefix_t *prefix,
457 fib_source_t source,
Neale Rannsad422ed2016-11-02 14:20:04 +0000458 fib_route_path_t *paths);
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100459
460/**
461 * @brief
462 * Update an entry to have a new set of paths. If the entry does not
463 * exist, it will be created.
464 * The difference between an 'path-add' and an update, is that path-add is
465 * an incremental addition of paths, whereas an update is a wholesale swap.
466 *
467 * @param fib_index
468 * The index of the FIB
469 *
470 * @param prefix
471 * The prefix for the entry to add
472 *
473 * @param source
474 * The ID of the client/source adding the entry.
475 *
476 * @param rpaths
Neale Rannsad422ed2016-11-02 14:20:04 +0000477 * A vector of paths. Not const since they may be modified.
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100478 *
479 * @return
480 * the index of the fib_entry_t that is created (or existed already).
481 */
482extern fib_node_index_t fib_table_entry_update(u32 fib_index,
483 const fib_prefix_t *prefix,
484 fib_source_t source,
485 fib_entry_flag_t flags,
Neale Rannsad422ed2016-11-02 14:20:04 +0000486 fib_route_path_t *paths);
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100487
488/**
489 * @brief
490 * Update the entry to have just one path. If the entry does not
491 * exist, it will be created.
492 * See the documentation for fib_route_path_t for more descirptions of
493 * the path parameters.
494 *
495 * @param fib_index
496 * The index of the FIB
497 *
498 * @param prefix
499 * The prefix for the entry to add
500 *
501 * @param source
502 * The ID of the client/source adding the entry.
503 *
504 * @param flags
505 * Flags for the entry.
506 *
507 * @paran next_hop_proto
508 * The protocol of the next hop. This cannot be derived in the event that
509 * the next hop is all zeros.
510 *
511 * @param next_hop
512 * The address of the next-hop.
513 *
514 * @param sw_if_index
515 * The index of the interface.
516 *
517 * @param next_hop_fib_index,
518 * The fib index of the next-hop for recursive resolution
519 *
520 * @param next_hop_weight
521 * [un]equal cost path weight
522 *
Neale Rannsad422ed2016-11-02 14:20:04 +0000523 * @param next_hop_label_stack
524 * The path's out-going label stack. NULL is there is none.
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100525 *
526 * @param pf
527 * Flags for the path
528 *
529 * @return
530 * the index of the fib_entry_t that is created (or existed already).
531 */
532extern fib_node_index_t fib_table_entry_update_one_path(u32 fib_index,
533 const fib_prefix_t *prefix,
534 fib_source_t source,
535 fib_entry_flag_t flags,
Neale Rannsda78f952017-05-24 09:15:43 -0700536 dpo_proto_t next_hop_proto,
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100537 const ip46_address_t *next_hop,
538 u32 next_hop_sw_if_index,
539 u32 next_hop_fib_index,
540 u32 next_hop_weight,
Neale Ranns31ed7442018-02-23 05:29:09 -0800541 fib_mpls_label_t *next_hop_label_stack,
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100542 fib_route_path_flags_t pf);
543
544/**
545 * @brief
546 * Add a MPLS local label for the prefix/route. If the entry does not
547 * exist, it will be created. In theory more than one local label can be
548 * added, but this is not yet supported.
549 *
550 * @param fib_index
551 * The index of the FIB
552 *
553 * @param prefix
554 * The prefix for the entry to which to add the label
555 *
556 * @param label
557 * The MPLS label to add
558 *
559 * @return
560 * the index of the fib_entry_t that is created (or existed already).
561 */
562extern fib_node_index_t fib_table_entry_local_label_add(u32 fib_index,
563 const fib_prefix_t *prefix,
564 mpls_label_t label);
565/**
566 * @brief
567 * remove a MPLS local label for the prefix/route.
568 *
569 * @param fib_index
570 * The index of the FIB
571 *
572 * @param prefix
573 * The prefix for the entry to which to add the label
574 *
575 * @param label
576 * The MPLS label to add
577 */
578extern void fib_table_entry_local_label_remove(u32 fib_index,
579 const fib_prefix_t *prefix,
580 mpls_label_t label);
581
582/**
583 * @brief
584 * Delete a FIB entry. If the entry has no more sources, then it is
585 * removed from the table.
586 *
587 * @param fib_index
588 * The index of the FIB
589 *
590 * @param prefix
591 * The prefix for the entry to remove
592 *
593 * @param source
594 * The ID of the client/source adding the entry.
595 */
596extern void fib_table_entry_delete(u32 fib_index,
597 const fib_prefix_t *prefix,
598 fib_source_t source);
599
600/**
601 * @brief
602 * Delete a FIB entry. If the entry has no more sources, then it is
603 * removed from the table.
604 *
605 * @param entry_index
606 * The index of the FIB entry
607 *
608 * @param source
609 * The ID of the client/source adding the entry.
610 */
611extern void fib_table_entry_delete_index(fib_node_index_t entry_index,
612 fib_source_t source);
613
614/**
615 * @brief
Neale Ranns008dbe12018-09-07 09:32:36 -0700616 * Return the stats index for a FIB entry
617 * @param fib_index
618 * The table's FIB index
619 * @param prefix
620 * The entry's prefix's
621 */
622extern u32 fib_table_entry_get_stats_index(u32 fib_index,
623 const fib_prefix_t *prefix);
624
625/**
626 * @brief
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100627 * Flush all entries from a table for the source
628 *
629 * @param fib_index
630 * The index of the FIB
631 *
632 * @paran proto
633 * The protocol of the entries in the table
634 *
635 * @param source
636 * the source to flush
637 */
638extern void fib_table_flush(u32 fib_index,
639 fib_protocol_t proto,
640 fib_source_t source);
641
642/**
643 * @brief
Neale Ranns9db6ada2019-11-08 12:42:31 +0000644 * Resync all entries from a table for the source
645 * this is the mark part of the mark and sweep algorithm.
646 * All entries in this FIB that are sourced by 'source' are marked
647 * as stale.
648 *
649 * @param fib_index
650 * The index of the FIB
651 *
652 * @paran proto
653 * The protocol of the entries in the table
654 *
655 * @param source
656 * the source to flush
657 */
658extern void fib_table_mark(u32 fib_index,
659 fib_protocol_t proto,
660 fib_source_t source);
661
662/**
663 * @brief
664 * Signal that the table has converged, i.e. all updates are complete.
665 * this is the sweep part of the mark and sweep algorithm.
666 * All entries in this FIB that are sourced by 'source' and marked
667 * as stale are flushed.
668 *
669 * @param fib_index
670 * The index of the FIB
671 *
672 * @paran proto
673 * The protocol of the entries in the table
674 *
675 * @param source
676 * the source to flush
677 */
678extern void fib_table_sweep(u32 fib_index,
679 fib_protocol_t proto,
680 fib_source_t source);
681
682/**
683 * @brief
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100684 * Get the index of the FIB bound to the interface
685 *
686 * @paran proto
687 * The protocol of the FIB (and thus the entries therein)
688 *
689 * @param sw_if_index
690 * The interface index
691 *
692 * @return fib_index
693 * The index of the FIB
694 */
695extern u32 fib_table_get_index_for_sw_if_index(fib_protocol_t proto,
696 u32 sw_if_index);
697
698/**
699 * @brief
700 * Get the Table-ID of the FIB bound to the interface
701 *
702 * @paran proto
703 * The protocol of the FIB (and thus the entries therein)
704 *
705 * @param sw_if_index
706 * The interface index
707 *
708 * @return fib_index
709 * The tableID of the FIB
710 */
711extern u32 fib_table_get_table_id_for_sw_if_index(fib_protocol_t proto,
712 u32 sw_if_index);
713
714/**
715 * @brief
Neale Ranns25b04942018-04-04 09:34:50 -0700716 * Get the Table-ID of the FIB from protocol and index
717 *
718 * @param fib_index
719 * The FIB index
720 *
721 * @paran proto
722 * The protocol of the FIB (and thus the entries therein)
723 *
724 * @return fib_index
725 * The tableID of the FIB
726 */
727extern u32 fib_table_get_table_id(u32 fib_index, fib_protocol_t proto);
728
729/**
730 * @brief
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100731 * Get the index of the FIB for a Table-ID. This DOES NOT create the
732 * FIB if it does not exist.
733 *
734 * @paran proto
735 * The protocol of the FIB (and thus the entries therein)
736 *
737 * @param table-id
738 * The Table-ID
739 *
740 * @return fib_index
741 * The index of the FIB, which may be INVALID.
742 */
743extern u32 fib_table_find(fib_protocol_t proto, u32 table_id);
744
745
746/**
747 * @brief
748 * Get the index of the FIB for a Table-ID. This DOES create the
749 * FIB if it does not exist.
750 *
751 * @paran proto
752 * The protocol of the FIB (and thus the entries therein)
753 *
754 * @param table-id
755 * The Table-ID
756 *
757 * @return fib_index
758 * The index of the FIB
Neale Ranns15002542017-09-10 04:39:11 -0700759 *
760 * @param source
761 * The ID of the client/source.
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100762 */
763extern u32 fib_table_find_or_create_and_lock(fib_protocol_t proto,
Neale Ranns15002542017-09-10 04:39:11 -0700764 u32 table_id,
765 fib_source_t source);
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100766
767/**
768 * @brief
Neale Ranns2297af02017-09-12 09:45:04 -0700769 * Get the index of the FIB for a Table-ID. This DOES create the
770 * FIB if it does not exist.
771 *
772 * @paran proto
773 * The protocol of the FIB (and thus the entries therein)
774 *
775 * @param table-id
776 * The Table-ID
777 *
778 * @return fib_index
779 * The index of the FIB
780 *
781 * @param source
782 * The ID of the client/source.
783 *
784 * @param name
785 * The client is choosing the name they want the table to have
786 */
787extern u32 fib_table_find_or_create_and_lock_w_name(fib_protocol_t proto,
788 u32 table_id,
789 fib_source_t source,
790 const u8 *name);
791
792/**
793 * @brief
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100794 * Create a new table with no table ID. This means it does not get
795 * added to the hash-table and so can only be found by using the index returned.
796 *
797 * @paran proto
798 * The protocol of the FIB (and thus the entries therein)
799 *
800 * @param fmt
801 * A string to describe the table
802 *
Neale Ranns15002542017-09-10 04:39:11 -0700803 * @param source
804 * The ID of the client/source.
805 *
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100806 * @return fib_index
807 * The index of the FIB
808 */
809extern u32 fib_table_create_and_lock(fib_protocol_t proto,
Neale Ranns15002542017-09-10 04:39:11 -0700810 fib_source_t source,
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100811 const char *const fmt,
812 ...);
813
814/**
815 * @brief
816 * Get the flow hash configured used by the table
817 *
818 * @param fib_index
819 * The index of the FIB
820 *
821 * @paran proto
Neale Rannsd792d9c2017-10-21 10:53:20 -0700822 * The protocol the packets the flow hash will be calculated for.
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100823 *
824 * @return The flow hash config
825 */
826extern flow_hash_config_t fib_table_get_flow_hash_config(u32 fib_index,
827 fib_protocol_t proto);
828
829/**
830 * @brief
Neale Ranns41da54f2017-05-02 10:15:19 -0700831 * Get the flow hash configured used by the protocol
832 *
833 * @paran proto
834 * The protocol of the FIB (and thus the entries therein)
835 *
836 * @return The flow hash config
837 */
838extern flow_hash_config_t fib_table_get_default_flow_hash_config(fib_protocol_t proto);
839
840/**
841 * @brief
Neale Ranns227038a2017-04-21 01:07:59 -0700842 * Set the flow hash configured used by the table
843 *
844 * @param fib_index
845 * The index of the FIB
846 *
847 * @paran proto
848 * The protocol of the FIB (and thus the entries therein)
849 *
850 * @param hash_config
851 * The flow-hash config to set
852 *
853 * @return none
854 */
855extern void fib_table_set_flow_hash_config(u32 fib_index,
856 fib_protocol_t proto,
857 flow_hash_config_t hash_config);
858
859/**
860 * @brief
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100861 * Take a reference counting lock on the table
862 *
863 * @param fib_index
864 * The index of the FIB
865 *
866 * @paran proto
867 * The protocol of the FIB (and thus the entries therein)
Neale Ranns15002542017-09-10 04:39:11 -0700868 *
869 * @param source
870 * The ID of the client/source.
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100871 */
872extern void fib_table_unlock(u32 fib_index,
Neale Ranns15002542017-09-10 04:39:11 -0700873 fib_protocol_t proto,
874 fib_source_t source);
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100875
876/**
877 * @brief
878 * Release a reference counting lock on the table. When the last lock
879 * has gone. the FIB is deleted.
880 *
881 * @param fib_index
882 * The index of the FIB
883 *
884 * @paran proto
885 * The protocol of the FIB (and thus the entries therein)
Neale Ranns15002542017-09-10 04:39:11 -0700886 *
887 * @param source
888 * The ID of the client/source.
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100889 */
890extern void fib_table_lock(u32 fib_index,
Neale Ranns15002542017-09-10 04:39:11 -0700891 fib_protocol_t proto,
892 fib_source_t source);
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100893
894/**
895 * @brief
896 * Return the number of entries in the FIB added by a given source.
897 *
898 * @param fib_index
899 * The index of the FIB
900 *
901 * @paran proto
902 * The protocol of the FIB (and thus the entries therein)
903 *
904 * @return number of sourced entries.
905 */
906extern u32 fib_table_get_num_entries(u32 fib_index,
907 fib_protocol_t proto,
908 fib_source_t source);
909
910/**
911 * @brief
912 * Get a pointer to a FIB table
913 */
914extern fib_table_t *fib_table_get(fib_node_index_t index,
915 fib_protocol_t proto);
916
Neale Ranns32e1c012016-11-22 17:07:28 +0000917/**
Neale Ranns89541992017-04-06 04:41:02 -0700918 * @brief return code controlling how a table walk proceeds
919 */
920typedef enum fib_table_walk_rc_t_
921{
922 /**
923 * Continue on to the next entry
924 */
925 FIB_TABLE_WALK_CONTINUE,
926 /**
927 * Do no traverse down this sub-tree
928 */
929 FIB_TABLE_WALK_SUB_TREE_STOP,
930 /**
931 * Stop the walk completely
932 */
933 FIB_TABLE_WALK_STOP,
934} fib_table_walk_rc_t;
935
936/**
Neale Ranns32e1c012016-11-22 17:07:28 +0000937 * @brief Call back function when walking entries in a FIB table
938 */
Neale Ranns89541992017-04-06 04:41:02 -0700939typedef fib_table_walk_rc_t (*fib_table_walk_fn_t)(fib_node_index_t fei,
940 void *ctx);
Neale Ranns32e1c012016-11-22 17:07:28 +0000941
942/**
943 * @brief Walk all entries in a FIB table
944 * N.B: This is NOT safe to deletes. If you need to delete walk the whole
945 * table and store elements in a vector, then delete the elements
946 */
947extern void fib_table_walk(u32 fib_index,
948 fib_protocol_t proto,
949 fib_table_walk_fn_t fn,
950 void *ctx);
951
Neale Rannsc87aafa2017-11-29 00:59:31 -0800952/**
Neale Ranns976b2592019-12-04 06:11:00 +0000953 * @brief Walk all entries in a FIB table
954 * N.B: This is NOT safe to deletes. If you need to delete walk the whole
955 * table and store elements in a vector, then delete the elements
956 */
957extern void fib_table_walk_w_src(u32 fib_index,
958 fib_protocol_t proto,
959 fib_source_t src,
960 fib_table_walk_fn_t fn,
961 void *ctx);
962
963/**
Neale Ranns89541992017-04-06 04:41:02 -0700964 * @brief Walk all entries in a sub-tree FIB table. The 'root' paraneter
965 * is the prefix at the root of the sub-tree.
966 * N.B: This is NOT safe to deletes. If you need to delete walk the whole
967 * table and store elements in a vector, then delete the elements
968 */
969extern void fib_table_sub_tree_walk(u32 fib_index,
970 fib_protocol_t proto,
971 const fib_prefix_t *root,
972 fib_table_walk_fn_t fn,
973 void *ctx);
974
975/**
Neale Rannsc87aafa2017-11-29 00:59:31 -0800976 * @brief format (display) the memory used by the FIB tables
977 */
978extern u8 *format_fib_table_memory(u8 *s, va_list *args);
979
Neale Rannscbe25aa2019-09-30 10:53:31 +0000980/**
981 * Debug function
982 */
Matthew Smithee167e52020-07-02 17:24:17 -0500983#if CLIB_DEBUG > 0
Neale Rannscbe25aa2019-09-30 10:53:31 +0000984extern void fib_table_assert_empty(const fib_table_t *fib_table);
985#endif
986
987
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100988#endif