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.
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 will link to a DPO valid for the source and/or the flags.
133 * This add is reference counting per-source. So n 'removes' are required
134 * for n 'adds', if the entry is no longer required.
135 * If the source needs to provide non-default forwarding use:
136 * fib_table_entry_special_dpo_add()
139 * The index of the FIB
145 * The ID of the client/source adding the entry.
148 * Flags for the entry.
151 * the index of the fib_entry_t that is created (or exists already).
153 extern fib_node_index_t fib_table_entry_special_add(u32 fib_index,
154 const fib_prefix_t *prefix,
156 fib_entry_flag_t flags);
160 * Add a 'special' entry to the FIB that links to the DPO passed
161 * A special entry is an entry that the FIB is not expect to resolve
162 * via the usual mechanisms (i.e. recurisve or neighbour adj DB lookup).
163 * Instead the client/source provides the DPO to link to.
164 * This add is reference counting per-source. So n 'removes' are required
165 * for n 'adds', if the entry is no longer required.
168 * The index of the FIB
174 * The ID of the client/source adding the entry.
177 * Flags for the entry.
180 * The DPO to link to.
183 * the index of the fib_entry_t that is created (or existed already).
185 extern fib_node_index_t fib_table_entry_special_dpo_add(u32 fib_index,
186 const fib_prefix_t *prefix,
188 fib_entry_flag_t stype,
189 const dpo_id_t *dpo);
193 * Update a 'special' entry to the FIB that links to the DPO passed
194 * A special entry is an entry that the FIB is not expect to resolve
195 * via the usual mechanisms (i.e. recurisve or neighbour adj DB lookup).
196 * Instead the client/source provides the DPO to link to.
197 * Special entries are add/remove reference counted per-source. So n
198 * 'removes' are required for n 'adds', if the entry is no longer required.
199 * An 'update' is an 'add' if no 'add' has already been called, otherwise an 'add'
200 * is therefore assumed to act on the reference instance of that add.
202 * @param fib_entry_index
203 * The index of the FIB entry to update
206 * The ID of the client/source adding the entry.
209 * Flags for the entry.
212 * The DPO to link to.
215 * the index of the fib_entry_t that is created (or existed already).
217 extern fib_node_index_t fib_table_entry_special_dpo_update (u32 fib_index,
218 const fib_prefix_t *prefix,
220 fib_entry_flag_t stype,
221 const dpo_id_t *dpo);
225 * Remove a 'special' entry from the FIB.
226 * This add is reference counting per-source. So n 'removes' are required
227 * for n 'adds', if the entry is no longer required.
230 * The index of the FIB
233 * The prefix to remove
236 * The ID of the client/source adding the entry.
239 extern void fib_table_entry_special_remove(u32 fib_index,
240 const fib_prefix_t *prefix,
241 fib_source_t source);
245 * Add one path to an entry (aka route) in the FIB. If the entry does not
246 * exist, it will be created.
247 * See the documentation for fib_route_path_t for more descirptions of
248 * the path parameters.
251 * The index of the FIB
254 * The prefix for the entry to add
257 * The ID of the client/source adding the entry.
260 * Flags for the entry.
262 * @paran next_hop_proto
263 * The protocol of the next hop. This cannot be derived in the event that
264 * the next hop is all zeros.
267 * The address of the next-hop.
270 * The index of the interface.
272 * @param next_hop_fib_index,
273 * The fib index of the next-hop for recursive resolution
275 * @param next_hop_weight
276 * [un]equal cost path weight
278 * @param next_hop_label_stack
279 * The path's out-going label stack. NULL is there is none.
285 * the index of the fib_entry_t that is created (or existed already).
287 extern fib_node_index_t fib_table_entry_path_add(u32 fib_index,
288 const fib_prefix_t *prefix,
290 fib_entry_flag_t flags,
291 fib_protocol_t next_hop_proto,
292 const ip46_address_t *next_hop,
293 u32 next_hop_sw_if_index,
294 u32 next_hop_fib_index,
296 mpls_label_t *next_hop_label_stack,
297 fib_route_path_flags_t pf);
300 * Add n paths to an entry (aka route) in the FIB. If the entry does not
301 * exist, it will be created.
302 * See the documentation for fib_route_path_t for more descirptions of
303 * the path parameters.
306 * The index of the FIB
309 * The prefix for the entry to add
312 * The ID of the client/source adding the entry.
315 * Flags for the entry.
318 * A vector of paths. Not const since they may be modified.
321 * the index of the fib_entry_t that is created (or existed already).
323 extern fib_node_index_t fib_table_entry_path_add2(u32 fib_index,
324 const fib_prefix_t *prefix,
326 fib_entry_flag_t flags,
327 fib_route_path_t *rpath);
331 * remove one path to an entry (aka route) in the FIB. If this is the entry's
332 * last path, then the entry will be removed, unless it has other sources.
333 * See the documentation for fib_route_path_t for more descirptions of
334 * the path parameters.
337 * The index of the FIB
340 * The prefix for the entry to add
343 * The ID of the client/source adding the entry.
345 * @paran next_hop_proto
346 * The protocol of the next hop. This cannot be derived in the event that
347 * the next hop is all zeros.
350 * The address of the next-hop.
353 * The index of the interface.
355 * @param next_hop_fib_index,
356 * The fib index of the next-hop for recursive resolution
358 * @param next_hop_weight
359 * [un]equal cost path weight
364 extern void fib_table_entry_path_remove(u32 fib_index,
365 const fib_prefix_t *prefix,
367 fib_protocol_t next_hop_proto,
368 const ip46_address_t *next_hop,
369 u32 next_hop_sw_if_index,
370 u32 next_hop_fib_index,
372 fib_route_path_flags_t pf);
376 * Remove n paths to an entry (aka route) in the FIB. If this is the entry's
377 * last path, then the entry will be removed, unless it has other sources.
378 * See the documentation for fib_route_path_t for more descirptions of
379 * the path parameters.
382 * The index of the FIB
385 * The prefix for the entry to add
388 * The ID of the client/source adding the entry.
393 extern void fib_table_entry_path_remove2(u32 fib_index,
394 const fib_prefix_t *prefix,
396 fib_route_path_t *paths);
400 * Update an entry to have a new set of paths. If the entry does not
401 * exist, it will be created.
402 * The difference between an 'path-add' and an update, is that path-add is
403 * an incremental addition of paths, whereas an update is a wholesale swap.
406 * The index of the FIB
409 * The prefix for the entry to add
412 * The ID of the client/source adding the entry.
415 * A vector of paths. Not const since they may be modified.
418 * the index of the fib_entry_t that is created (or existed already).
420 extern fib_node_index_t fib_table_entry_update(u32 fib_index,
421 const fib_prefix_t *prefix,
423 fib_entry_flag_t flags,
424 fib_route_path_t *paths);
428 * Update the entry to have just one path. If the entry does not
429 * exist, it will be created.
430 * See the documentation for fib_route_path_t for more descirptions of
431 * the path parameters.
434 * The index of the FIB
437 * The prefix for the entry to add
440 * The ID of the client/source adding the entry.
443 * Flags for the entry.
445 * @paran next_hop_proto
446 * The protocol of the next hop. This cannot be derived in the event that
447 * the next hop is all zeros.
450 * The address of the next-hop.
453 * The index of the interface.
455 * @param next_hop_fib_index,
456 * The fib index of the next-hop for recursive resolution
458 * @param next_hop_weight
459 * [un]equal cost path weight
461 * @param next_hop_label_stack
462 * The path's out-going label stack. NULL is there is none.
468 * the index of the fib_entry_t that is created (or existed already).
470 extern fib_node_index_t fib_table_entry_update_one_path(u32 fib_index,
471 const fib_prefix_t *prefix,
473 fib_entry_flag_t flags,
474 fib_protocol_t next_hop_proto,
475 const ip46_address_t *next_hop,
476 u32 next_hop_sw_if_index,
477 u32 next_hop_fib_index,
479 mpls_label_t *next_hop_label_stack,
480 fib_route_path_flags_t pf);
484 * Add a MPLS local label for the prefix/route. If the entry does not
485 * exist, it will be created. In theory more than one local label can be
486 * added, but this is not yet supported.
489 * The index of the FIB
492 * The prefix for the entry to which to add the label
495 * The MPLS label to add
498 * the index of the fib_entry_t that is created (or existed already).
500 extern fib_node_index_t fib_table_entry_local_label_add(u32 fib_index,
501 const fib_prefix_t *prefix,
505 * remove a MPLS local label for the prefix/route.
508 * The index of the FIB
511 * The prefix for the entry to which to add the label
514 * The MPLS label to add
516 extern void fib_table_entry_local_label_remove(u32 fib_index,
517 const fib_prefix_t *prefix,
522 * Delete a FIB entry. If the entry has no more sources, then it is
523 * removed from the table.
526 * The index of the FIB
529 * The prefix for the entry to remove
532 * The ID of the client/source adding the entry.
534 extern void fib_table_entry_delete(u32 fib_index,
535 const fib_prefix_t *prefix,
536 fib_source_t source);
540 * Delete a FIB entry. If the entry has no more sources, then it is
541 * removed from the table.
544 * The index of the FIB entry
547 * The ID of the client/source adding the entry.
549 extern void fib_table_entry_delete_index(fib_node_index_t entry_index,
550 fib_source_t source);
554 * Flush all entries from a table for the source
557 * The index of the FIB
560 * The protocol of the entries in the table
563 * the source to flush
565 extern void fib_table_flush(u32 fib_index,
566 fib_protocol_t proto,
567 fib_source_t source);
571 * Get the index of the FIB bound to the interface
574 * The protocol of the FIB (and thus the entries therein)
577 * The interface index
580 * The index of the FIB
582 extern u32 fib_table_get_index_for_sw_if_index(fib_protocol_t proto,
587 * Get the Table-ID of the FIB bound to the interface
590 * The protocol of the FIB (and thus the entries therein)
593 * The interface index
596 * The tableID of the FIB
598 extern u32 fib_table_get_table_id_for_sw_if_index(fib_protocol_t proto,
603 * Get the index of the FIB for a Table-ID. This DOES NOT create the
604 * FIB if it does not exist.
607 * The protocol of the FIB (and thus the entries therein)
613 * The index of the FIB, which may be INVALID.
615 extern u32 fib_table_find(fib_protocol_t proto, u32 table_id);
620 * Get the index of the FIB for a Table-ID. This DOES create the
621 * FIB if it does not exist.
624 * The protocol of the FIB (and thus the entries therein)
630 * The index of the FIB
632 extern u32 fib_table_find_or_create_and_lock(fib_protocol_t proto,
637 * Create a new table with no table ID. This means it does not get
638 * added to the hash-table and so can only be found by using the index returned.
641 * The protocol of the FIB (and thus the entries therein)
644 * A string to describe the table
647 * The index of the FIB
649 extern u32 fib_table_create_and_lock(fib_protocol_t proto,
650 const char *const fmt,
655 * Get the flow hash configured used by the table
658 * The index of the FIB
661 * The protocol of the FIB (and thus the entries therein)
663 * @return The flow hash config
665 extern flow_hash_config_t fib_table_get_flow_hash_config(u32 fib_index,
666 fib_protocol_t proto);
670 * Get the flow hash configured used by the protocol
673 * The protocol of the FIB (and thus the entries therein)
675 * @return The flow hash config
677 extern flow_hash_config_t fib_table_get_default_flow_hash_config(fib_protocol_t proto);
681 * Set the flow hash configured used by the table
684 * The index of the FIB
687 * The protocol of the FIB (and thus the entries therein)
690 * The flow-hash config to set
694 extern void fib_table_set_flow_hash_config(u32 fib_index,
695 fib_protocol_t proto,
696 flow_hash_config_t hash_config);
700 * Take a reference counting lock on the table
703 * The index of the FIB
706 * The protocol of the FIB (and thus the entries therein)
708 extern void fib_table_unlock(u32 fib_index,
709 fib_protocol_t proto);
713 * Release a reference counting lock on the table. When the last lock
714 * has gone. the FIB is deleted.
717 * The index of the FIB
720 * The protocol of the FIB (and thus the entries therein)
722 extern void fib_table_lock(u32 fib_index,
723 fib_protocol_t proto);
727 * Return the number of entries in the FIB added by a given source.
730 * The index of the FIB
733 * The protocol of the FIB (and thus the entries therein)
735 * @return number of sourced entries.
737 extern u32 fib_table_get_num_entries(u32 fib_index,
738 fib_protocol_t proto,
739 fib_source_t source);
743 * Get a pointer to a FIB table
745 extern fib_table_t *fib_table_get(fib_node_index_t index,
746 fib_protocol_t proto);
749 * @brief Call back function when walking entries in a FIB table
751 typedef int (*fib_table_walk_fn_t)(fib_node_index_t fei,
755 * @brief Walk all entries in a FIB table
756 * N.B: This is NOT safe to deletes. If you need to delete walk the whole
757 * table and store elements in a vector, then delete the elements
759 extern void fib_table_walk(u32 fib_index,
760 fib_protocol_t proto,
761 fib_table_walk_fn_t fn,