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:
7 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 #ifndef __FIB_TABLE_H__
17 #define __FIB_TABLE_H__
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>
27 * A protocol Independent FIB table
29 typedef struct fib_table_t_
32 * Which protocol this table serves. Used to switch on the union above.
34 fib_protocol_t ft_proto;
37 * number of locks on the table
42 * Table ID (hash key) for this FIB.
47 * Index into FIB vector.
49 fib_node_index_t ft_index;
52 * flow hash configuration
54 u32 ft_flow_hash_config;
57 * Per-source route counters
59 u32 ft_src_route_counts[FIB_SOURCE_MAX];
62 * Total route counters
64 u32 ft_total_route_counts;
74 * Format the description/name of the table
76 extern u8* format_fib_table_name(u8* s, va_list ap);
80 * Perfom a longest prefix match in the non-forwarding table
83 * The index of the FIB
86 * The prefix to lookup
89 * The index of the fib_entry_t for the best match, which may be the default route
91 extern fib_node_index_t fib_table_lookup(u32 fib_index,
92 const fib_prefix_t *prefix);
96 * Perfom an exact match in the non-forwarding table
99 * The index of the FIB
102 * The prefix to lookup
105 * The index of the fib_entry_t for the exact match, or INVALID
106 * is there is no match.
108 extern fib_node_index_t fib_table_lookup_exact_match(u32 fib_index,
109 const fib_prefix_t *prefix);
113 * Get the less specific (covering) prefix
116 * The index of the FIB
119 * The prefix to lookup
122 * The index of the less specific fib_entry_t.
124 extern fib_node_index_t fib_table_get_less_specific(u32 fib_index,
125 const fib_prefix_t *prefix);
129 * Add a 'special' entry to the FIB that links to the adj passed
130 * A special entry is an entry that the FIB is not expect to resolve
131 * via the usual mechanisms (i.e. recurisve or neighbour adj DB lookup).
132 * Instead the client/source provides the adj to link to.
133 * This add is reference counting per-source. So n 'removes' are required
134 * for n 'adds', if the entry is no longer required.
137 * The index of the FIB
143 * The ID of the client/source adding the entry.
146 * Flags for the entry.
149 * The adjacency to link to.
152 * the index of the fib_entry_t that is created (or exists already).
154 extern fib_node_index_t fib_table_entry_special_add(u32 fib_index,
155 const fib_prefix_t *prefix,
157 fib_entry_flag_t flags,
158 adj_index_t adj_index);
162 * Add a 'special' entry to the FIB that links to the DPO passed
163 * A special entry is an entry that the FIB is not expect to resolve
164 * via the usual mechanisms (i.e. recurisve or neighbour adj DB lookup).
165 * Instead the client/source provides the DPO to link to.
166 * This add is reference counting per-source. So n 'removes' are required
167 * for n 'adds', if the entry is no longer required.
170 * The index of the FIB
176 * The ID of the client/source adding the entry.
179 * Flags for the entry.
182 * The DPO to link to.
185 * the index of the fib_entry_t that is created (or existed already).
187 extern fib_node_index_t fib_table_entry_special_dpo_add(u32 fib_index,
188 const fib_prefix_t *prefix,
190 fib_entry_flag_t stype,
191 const dpo_id_t *dpo);
195 * Update a 'special' entry to the FIB that links to the DPO passed
196 * A special entry is an entry that the FIB is not expect to resolve
197 * via the usual mechanisms (i.e. recurisve or neighbour adj DB lookup).
198 * Instead the client/source provides the DPO to link to.
199 * Special entries are add/remove reference counted per-source. So n
200 * 'removes' are required for n 'adds', if the entry is no longer required.
201 * An 'update' is an 'add' if no 'add' has already been called, otherwise an 'add'
202 * is therefore assumed to act on the reference instance of that add.
204 * @param fib_entry_index
205 * The index of the FIB entry to update
208 * The ID of the client/source adding the entry.
211 * Flags for the entry.
214 * The DPO to link to.
217 * the index of the fib_entry_t that is created (or existed already).
219 extern fib_node_index_t fib_table_entry_special_dpo_update (u32 fib_index,
220 const fib_prefix_t *prefix,
222 fib_entry_flag_t stype,
223 const dpo_id_t *dpo);
227 * Remove a 'special' entry from the FIB.
228 * This add is reference counting per-source. So n 'removes' are required
229 * for n 'adds', if the entry is no longer required.
232 * The index of the FIB
235 * The prefix to remove
238 * The ID of the client/source adding the entry.
241 extern void fib_table_entry_special_remove(u32 fib_index,
242 const fib_prefix_t *prefix,
243 fib_source_t source);
247 * Add one path to an entry (aka route) in the FIB. If the entry does not
248 * exist, it will be created.
249 * See the documentation for fib_route_path_t for more descirptions of
250 * the path parameters.
253 * The index of the FIB
256 * The prefix for the entry to add
259 * The ID of the client/source adding the entry.
262 * Flags for the entry.
264 * @paran next_hop_proto
265 * The protocol of the next hop. This cannot be derived in the event that
266 * the next hop is all zeros.
269 * The address of the next-hop.
272 * The index of the interface.
274 * @param next_hop_fib_index,
275 * The fib index of the next-hop for recursive resolution
277 * @param next_hop_weight
278 * [un]equal cost path weight
280 * @param next_hop_label_stack
281 * The path's out-going label stack. NULL is there is none.
287 * the index of the fib_entry_t that is created (or existed already).
289 extern fib_node_index_t fib_table_entry_path_add(u32 fib_index,
290 const fib_prefix_t *prefix,
292 fib_entry_flag_t flags,
293 fib_protocol_t next_hop_proto,
294 const ip46_address_t *next_hop,
295 u32 next_hop_sw_if_index,
296 u32 next_hop_fib_index,
298 mpls_label_t *next_hop_label_stack,
299 fib_route_path_flags_t pf);
302 * Add n paths to an entry (aka route) in the FIB. If the entry does not
303 * exist, it will be created.
304 * See the documentation for fib_route_path_t for more descirptions of
305 * the path parameters.
308 * The index of the FIB
311 * The prefix for the entry to add
314 * The ID of the client/source adding the entry.
317 * Flags for the entry.
320 * A vector of paths. Not const since they may be modified.
323 * the index of the fib_entry_t that is created (or existed already).
325 extern fib_node_index_t fib_table_entry_path_add2(u32 fib_index,
326 const fib_prefix_t *prefix,
328 fib_entry_flag_t flags,
329 fib_route_path_t *rpath);
333 * remove one path to an entry (aka route) in the FIB. If this is the entry's
334 * last path, then the entry will be removed, unless it has other sources.
335 * See the documentation for fib_route_path_t for more descirptions of
336 * the path parameters.
339 * The index of the FIB
342 * The prefix for the entry to add
345 * The ID of the client/source adding the entry.
347 * @paran next_hop_proto
348 * The protocol of the next hop. This cannot be derived in the event that
349 * the next hop is all zeros.
352 * The address of the next-hop.
355 * The index of the interface.
357 * @param next_hop_fib_index,
358 * The fib index of the next-hop for recursive resolution
360 * @param next_hop_weight
361 * [un]equal cost path weight
366 extern void fib_table_entry_path_remove(u32 fib_index,
367 const fib_prefix_t *prefix,
369 fib_protocol_t next_hop_proto,
370 const ip46_address_t *next_hop,
371 u32 next_hop_sw_if_index,
372 u32 next_hop_fib_index,
374 fib_route_path_flags_t pf);
378 * Remove n paths to an entry (aka route) in the FIB. If this is the entry's
379 * last path, then the entry will be removed, unless it has other sources.
380 * See the documentation for fib_route_path_t for more descirptions of
381 * the path parameters.
384 * The index of the FIB
387 * The prefix for the entry to add
390 * The ID of the client/source adding the entry.
395 extern void fib_table_entry_path_remove2(u32 fib_index,
396 const fib_prefix_t *prefix,
398 fib_route_path_t *paths);
402 * Update an entry to have a new set of paths. If the entry does not
403 * exist, it will be created.
404 * The difference between an 'path-add' and an update, is that path-add is
405 * an incremental addition of paths, whereas an update is a wholesale swap.
408 * The index of the FIB
411 * The prefix for the entry to add
414 * The ID of the client/source adding the entry.
417 * A vector of paths. Not const since they may be modified.
420 * the index of the fib_entry_t that is created (or existed already).
422 extern fib_node_index_t fib_table_entry_update(u32 fib_index,
423 const fib_prefix_t *prefix,
425 fib_entry_flag_t flags,
426 fib_route_path_t *paths);
430 * Update the entry to have just one path. If the entry does not
431 * exist, it will be created.
432 * See the documentation for fib_route_path_t for more descirptions of
433 * the path parameters.
436 * The index of the FIB
439 * The prefix for the entry to add
442 * The ID of the client/source adding the entry.
445 * Flags for the entry.
447 * @paran next_hop_proto
448 * The protocol of the next hop. This cannot be derived in the event that
449 * the next hop is all zeros.
452 * The address of the next-hop.
455 * The index of the interface.
457 * @param next_hop_fib_index,
458 * The fib index of the next-hop for recursive resolution
460 * @param next_hop_weight
461 * [un]equal cost path weight
463 * @param next_hop_label_stack
464 * The path's out-going label stack. NULL is there is none.
470 * the index of the fib_entry_t that is created (or existed already).
472 extern fib_node_index_t fib_table_entry_update_one_path(u32 fib_index,
473 const fib_prefix_t *prefix,
475 fib_entry_flag_t flags,
476 fib_protocol_t next_hop_proto,
477 const ip46_address_t *next_hop,
478 u32 next_hop_sw_if_index,
479 u32 next_hop_fib_index,
481 mpls_label_t *next_hop_label_stack,
482 fib_route_path_flags_t pf);
486 * Add a MPLS local label for the prefix/route. If the entry does not
487 * exist, it will be created. In theory more than one local label can be
488 * added, but this is not yet supported.
491 * The index of the FIB
494 * The prefix for the entry to which to add the label
497 * The MPLS label to add
500 * the index of the fib_entry_t that is created (or existed already).
502 extern fib_node_index_t fib_table_entry_local_label_add(u32 fib_index,
503 const fib_prefix_t *prefix,
507 * remove a MPLS local label for the prefix/route.
510 * The index of the FIB
513 * The prefix for the entry to which to add the label
516 * The MPLS label to add
518 extern void fib_table_entry_local_label_remove(u32 fib_index,
519 const fib_prefix_t *prefix,
524 * Delete a FIB entry. If the entry has no more sources, then it is
525 * removed from the table.
528 * The index of the FIB
531 * The prefix for the entry to remove
534 * The ID of the client/source adding the entry.
536 extern void fib_table_entry_delete(u32 fib_index,
537 const fib_prefix_t *prefix,
538 fib_source_t source);
542 * Delete a FIB entry. If the entry has no more sources, then it is
543 * removed from the table.
546 * The index of the FIB entry
549 * The ID of the client/source adding the entry.
551 extern void fib_table_entry_delete_index(fib_node_index_t entry_index,
552 fib_source_t source);
556 * Flush all entries from a table for the source
559 * The index of the FIB
562 * The protocol of the entries in the table
565 * the source to flush
567 extern void fib_table_flush(u32 fib_index,
568 fib_protocol_t proto,
569 fib_source_t source);
573 * Get the index of the FIB bound to the interface
576 * The protocol of the FIB (and thus the entries therein)
579 * The interface index
582 * The index of the FIB
584 extern u32 fib_table_get_index_for_sw_if_index(fib_protocol_t proto,
589 * Get the Table-ID of the FIB bound to the interface
592 * The protocol of the FIB (and thus the entries therein)
595 * The interface index
598 * The tableID of the FIB
600 extern u32 fib_table_get_table_id_for_sw_if_index(fib_protocol_t proto,
605 * Get the index of the FIB for a Table-ID. This DOES NOT create the
606 * FIB if it does not exist.
609 * The protocol of the FIB (and thus the entries therein)
615 * The index of the FIB, which may be INVALID.
617 extern u32 fib_table_find(fib_protocol_t proto, u32 table_id);
622 * Get the index of the FIB for a Table-ID. This DOES create the
623 * FIB if it does not exist.
626 * The protocol of the FIB (and thus the entries therein)
632 * The index of the FIB
634 extern u32 fib_table_find_or_create_and_lock(fib_protocol_t proto,
639 * Create a new table with no table ID. This means it does not get
640 * added to the hash-table and so can only be found by using the index returned.
643 * The protocol of the FIB (and thus the entries therein)
646 * A string to describe the table
649 * The index of the FIB
651 extern u32 fib_table_create_and_lock(fib_protocol_t proto,
652 const char *const fmt,
657 * Get the flow hash configured used by the table
660 * The index of the FIB
663 * The protocol of the FIB (and thus the entries therein)
665 * @return The flow hash config
667 extern flow_hash_config_t fib_table_get_flow_hash_config(u32 fib_index,
668 fib_protocol_t proto);
672 * Take a reference counting lock on the table
675 * The index of the FIB
678 * The protocol of the FIB (and thus the entries therein)
680 extern void fib_table_unlock(u32 fib_index,
681 fib_protocol_t proto);
685 * Release a reference counting lock on the table. When the last lock
686 * has gone. the FIB is deleted.
689 * The index of the FIB
692 * The protocol of the FIB (and thus the entries therein)
694 extern void fib_table_lock(u32 fib_index,
695 fib_protocol_t proto);
699 * Return the number of entries in the FIB added by a given source.
702 * The index of the FIB
705 * The protocol of the FIB (and thus the entries therein)
707 * @return number of sourced entries.
709 extern u32 fib_table_get_num_entries(u32 fib_index,
710 fib_protocol_t proto,
711 fib_source_t source);
715 * Get a pointer to a FIB table
717 extern fib_table_t *fib_table_get(fib_node_index_t index,
718 fib_protocol_t proto);
721 * @brief Call back function when walking entries in a FIB table
723 typedef int (*fib_table_walk_fn_t)(fib_node_index_t fei,
727 * @brief Walk all entries in a FIB table
728 * N.B: This is NOT safe to deletes. If you need to delete walk the whole
729 * table and store elements in a vector, then delete the elements
731 extern void fib_table_walk(u32 fib_index,
732 fib_protocol_t proto,
733 fib_table_walk_fn_t fn,