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 #include <vlib/vlib.h>
17 #include <vnet/dpo/drop_dpo.h>
19 #include <vnet/fib/fib_table.h>
20 #include <vnet/fib/fib_entry_cover.h>
21 #include <vnet/fib/fib_internal.h>
22 #include <vnet/fib/ip4_fib.h>
23 #include <vnet/fib/ip6_fib.h>
24 #include <vnet/fib/mpls_fib.h>
27 fib_table_get (fib_node_index_t index,
32 case FIB_PROTOCOL_IP4:
33 return (pool_elt_at_index(ip4_main.fibs, index));
34 case FIB_PROTOCOL_IP6:
35 return (pool_elt_at_index(ip6_main.fibs, index));
36 case FIB_PROTOCOL_MPLS:
37 return (pool_elt_at_index(mpls_main.fibs, index));
43 static inline fib_node_index_t
44 fib_table_lookup_i (fib_table_t *fib_table,
45 const fib_prefix_t *prefix)
47 switch (prefix->fp_proto)
49 case FIB_PROTOCOL_IP4:
50 return (ip4_fib_table_lookup(ip4_fib_get(fib_table->ft_index),
53 case FIB_PROTOCOL_IP6:
54 return (ip6_fib_table_lookup(fib_table->ft_index,
57 case FIB_PROTOCOL_MPLS:
58 return (mpls_fib_table_lookup(mpls_fib_get(fib_table->ft_index),
62 return (FIB_NODE_INDEX_INVALID);
66 fib_table_lookup (u32 fib_index,
67 const fib_prefix_t *prefix)
69 return (fib_table_lookup_i(fib_table_get(fib_index, prefix->fp_proto), prefix));
72 static inline fib_node_index_t
73 fib_table_lookup_exact_match_i (const fib_table_t *fib_table,
74 const fib_prefix_t *prefix)
76 switch (prefix->fp_proto)
78 case FIB_PROTOCOL_IP4:
79 return (ip4_fib_table_lookup_exact_match(ip4_fib_get(fib_table->ft_index),
82 case FIB_PROTOCOL_IP6:
83 return (ip6_fib_table_lookup_exact_match(fib_table->ft_index,
86 case FIB_PROTOCOL_MPLS:
87 return (mpls_fib_table_lookup(mpls_fib_get(fib_table->ft_index),
91 return (FIB_NODE_INDEX_INVALID);
95 fib_table_lookup_exact_match (u32 fib_index,
96 const fib_prefix_t *prefix)
98 return (fib_table_lookup_exact_match_i(fib_table_get(fib_index,
103 static fib_node_index_t
104 fib_table_get_less_specific_i (fib_table_t *fib_table,
105 const fib_prefix_t *prefix)
111 if (FIB_PROTOCOL_MPLS == pfx.fp_proto)
113 return (FIB_NODE_INDEX_INVALID);
117 * in the absence of a tree structure for the table that allows for an O(1)
118 * parent get, a cheeky way to find the cover is to LPM for the prefix with
120 * there should always be a cover, though it may be the default route. the
121 * default route's cover is the default route.
123 if (pfx.fp_len != 0) {
127 return (fib_table_lookup_i(fib_table, &pfx));
131 fib_table_get_less_specific (u32 fib_index,
132 const fib_prefix_t *prefix)
134 return (fib_table_get_less_specific_i(fib_table_get(fib_index,
140 fib_table_entry_remove (fib_table_t *fib_table,
141 const fib_prefix_t *prefix,
142 fib_node_index_t fib_entry_index)
144 vlib_smp_unsafe_warning();
146 fib_table->ft_total_route_counts--;
148 switch (prefix->fp_proto)
150 case FIB_PROTOCOL_IP4:
151 ip4_fib_table_entry_remove(ip4_fib_get(fib_table->ft_index),
152 &prefix->fp_addr.ip4,
155 case FIB_PROTOCOL_IP6:
156 ip6_fib_table_entry_remove(fib_table->ft_index,
157 &prefix->fp_addr.ip6,
160 case FIB_PROTOCOL_MPLS:
161 mpls_fib_table_entry_remove(mpls_fib_get(fib_table->ft_index),
167 fib_entry_unlock(fib_entry_index);
171 fib_table_post_insert_actions (fib_table_t *fib_table,
172 const fib_prefix_t *prefix,
173 fib_node_index_t fib_entry_index)
175 fib_node_index_t fib_entry_cover_index;
178 * no cover relationships in the MPLS FIB
180 if (FIB_PROTOCOL_MPLS == prefix->fp_proto)
184 * find and inform the covering entry that a new more specific
185 * has been inserted beneath it
187 fib_entry_cover_index = fib_table_get_less_specific_i(fib_table, prefix);
189 * the indicies are the same when the default route is first added
191 if (fib_entry_cover_index != fib_entry_index)
193 fib_entry_cover_change_notify(fib_entry_cover_index,
199 fib_table_entry_insert (fib_table_t *fib_table,
200 const fib_prefix_t *prefix,
201 fib_node_index_t fib_entry_index)
203 vlib_smp_unsafe_warning();
205 fib_entry_lock(fib_entry_index);
206 fib_table->ft_total_route_counts++;
208 switch (prefix->fp_proto)
210 case FIB_PROTOCOL_IP4:
211 ip4_fib_table_entry_insert(ip4_fib_get(fib_table->ft_index),
212 &prefix->fp_addr.ip4,
216 case FIB_PROTOCOL_IP6:
217 ip6_fib_table_entry_insert(fib_table->ft_index,
218 &prefix->fp_addr.ip6,
222 case FIB_PROTOCOL_MPLS:
223 mpls_fib_table_entry_insert(mpls_fib_get(fib_table->ft_index),
230 fib_table_post_insert_actions(fib_table, prefix, fib_entry_index);
234 fib_table_fwding_dpo_update (u32 fib_index,
235 const fib_prefix_t *prefix,
238 vlib_smp_unsafe_warning();
240 switch (prefix->fp_proto)
242 case FIB_PROTOCOL_IP4:
243 return (ip4_fib_table_fwding_dpo_update(ip4_fib_get(fib_index),
244 &prefix->fp_addr.ip4,
247 case FIB_PROTOCOL_IP6:
248 return (ip6_fib_table_fwding_dpo_update(fib_index,
249 &prefix->fp_addr.ip6,
252 case FIB_PROTOCOL_MPLS:
253 return (mpls_fib_forwarding_table_update(mpls_fib_get(fib_index),
261 fib_table_fwding_dpo_remove (u32 fib_index,
262 const fib_prefix_t *prefix,
265 vlib_smp_unsafe_warning();
267 switch (prefix->fp_proto)
269 case FIB_PROTOCOL_IP4:
270 return (ip4_fib_table_fwding_dpo_remove(ip4_fib_get(fib_index),
271 &prefix->fp_addr.ip4,
274 fib_table_get_less_specific(fib_index,
276 case FIB_PROTOCOL_IP6:
277 return (ip6_fib_table_fwding_dpo_remove(fib_index,
278 &prefix->fp_addr.ip6,
281 case FIB_PROTOCOL_MPLS:
282 return (mpls_fib_forwarding_table_reset(mpls_fib_get(fib_index),
290 fib_table_entry_special_dpo_add (u32 fib_index,
291 const fib_prefix_t *prefix,
293 fib_entry_flag_t flags,
296 fib_node_index_t fib_entry_index;
297 fib_table_t *fib_table;
299 fib_table = fib_table_get(fib_index, prefix->fp_proto);
300 fib_entry_index = fib_table_lookup_exact_match_i(fib_table, prefix);
302 if (FIB_NODE_INDEX_INVALID == fib_entry_index)
304 fib_entry_index = fib_entry_create_special(fib_index, prefix,
308 fib_table_entry_insert(fib_table, prefix, fib_entry_index);
309 fib_table->ft_src_route_counts[source]++;
315 was_sourced = fib_entry_is_sourced(fib_entry_index, source);
316 fib_entry_special_add(fib_entry_index, source, flags, dpo);
318 if (was_sourced != fib_entry_is_sourced(fib_entry_index, source))
320 fib_table->ft_src_route_counts[source]++;
325 return (fib_entry_index);
329 fib_table_entry_special_dpo_update (u32 fib_index,
330 const fib_prefix_t *prefix,
332 fib_entry_flag_t flags,
335 fib_node_index_t fib_entry_index;
336 fib_table_t *fib_table;
338 fib_table = fib_table_get(fib_index, prefix->fp_proto);
339 fib_entry_index = fib_table_lookup_exact_match_i(fib_table, prefix);
341 if (FIB_NODE_INDEX_INVALID == fib_entry_index)
343 fib_entry_index = fib_entry_create_special(fib_index, prefix,
347 fib_table_entry_insert(fib_table, prefix, fib_entry_index);
348 fib_table->ft_src_route_counts[source]++;
354 was_sourced = fib_entry_is_sourced(fib_entry_index, source);
357 fib_entry_special_update(fib_entry_index, source, flags, dpo);
359 fib_entry_special_add(fib_entry_index, source, flags, dpo);
361 if (was_sourced != fib_entry_is_sourced(fib_entry_index, source))
363 fib_table->ft_src_route_counts[source]++;
367 return (fib_entry_index);
371 fib_table_entry_special_add (u32 fib_index,
372 const fib_prefix_t *prefix,
374 fib_entry_flag_t flags,
375 adj_index_t adj_index)
377 fib_node_index_t fib_entry_index;
378 dpo_id_t tmp_dpo = DPO_INVALID;
380 if (ADJ_INDEX_INVALID != adj_index)
389 dpo_copy(&tmp_dpo, drop_dpo_get(fib_proto_to_dpo(prefix->fp_proto)));
392 fib_entry_index = fib_table_entry_special_dpo_add(fib_index, prefix, source,
395 dpo_unlock(&tmp_dpo);
397 return (fib_entry_index);
401 fib_table_entry_special_remove (u32 fib_index,
402 const fib_prefix_t *prefix,
407 * yes => remove source
408 * 2 - is it still sourced?
411 fib_node_index_t fib_entry_index;
412 fib_table_t *fib_table;
414 fib_table = fib_table_get(fib_index, prefix->fp_proto);
415 fib_entry_index = fib_table_lookup_exact_match_i(fib_table, prefix);
417 if (FIB_NODE_INDEX_INVALID == fib_entry_index)
420 * removing an etry that does not exist. i'll allow it.
425 fib_entry_src_flag_t src_flag;
429 * don't nobody go nowhere
431 fib_entry_lock(fib_entry_index);
432 was_sourced = fib_entry_is_sourced(fib_entry_index, source);
434 src_flag = fib_entry_special_remove(fib_entry_index, source);
436 if (!(FIB_ENTRY_SRC_FLAG_ADDED & src_flag))
439 * last source gone. remove from the table
441 fib_table_entry_remove(fib_table, prefix, fib_entry_index);
444 * now the entry is no longer in the table, we can
445 * inform the entries that it covers to re-calculate their cover
447 fib_entry_cover_change_notify(fib_entry_index,
448 FIB_NODE_INDEX_INVALID);
452 * still has sources, leave it be.
454 if (was_sourced != fib_entry_is_sourced(fib_entry_index, source))
456 fib_table->ft_src_route_counts[source]--;
459 fib_entry_unlock(fib_entry_index);
464 * fib_table_route_path_fixup
466 * Convert attached hosts to attached next-hops.
468 * This special case is required because an attached path will link to a
469 * glean, and the FIB entry will have the interface or API/CLI source. When
470 * the ARP/ND process is completes then that source (which will provide a
471 * complete adjacency) will be lower priority and so the FIB entry will
472 * remain linked to a glean and traffic will never reach the hosts. For
473 * an ATTAHCED_HOST path we can link the path directly to the [incomplete]
477 fib_table_route_path_fixup (const fib_prefix_t *prefix,
478 fib_entry_flag_t eflags,
479 fib_route_path_t *path)
482 * not all zeros next hop &&
483 * is recursive path &&
484 * nexthop is same as the route's address
486 if ((!ip46_address_is_zero(&path->frp_addr)) &&
487 (~0 == path->frp_sw_if_index) &&
488 (0 == ip46_address_cmp(&path->frp_addr, &prefix->fp_addr)))
490 /* Prefix recurses via itse;f */
491 path->frp_flags |= FIB_ROUTE_PATH_DROP;
493 if (fib_prefix_is_host(prefix) &&
494 ip46_address_is_zero(&path->frp_addr) &&
495 path->frp_sw_if_index != ~0)
497 path->frp_addr = prefix->fp_addr;
498 path->frp_flags |= FIB_ROUTE_PATH_ATTACHED;
500 if (eflags & FIB_ENTRY_FLAG_DROP)
502 path->frp_flags |= FIB_ROUTE_PATH_DROP;
504 if (eflags & FIB_ENTRY_FLAG_LOCAL)
506 path->frp_flags |= FIB_ROUTE_PATH_LOCAL;
508 if (eflags & FIB_ENTRY_FLAG_EXCLUSIVE)
510 path->frp_flags |= FIB_ROUTE_PATH_EXCLUSIVE;
515 fib_table_entry_path_add (u32 fib_index,
516 const fib_prefix_t *prefix,
518 fib_entry_flag_t flags,
519 fib_protocol_t next_hop_proto,
520 const ip46_address_t *next_hop,
521 u32 next_hop_sw_if_index,
522 u32 next_hop_fib_index,
524 mpls_label_t *next_hop_labels,
525 fib_route_path_flags_t path_flags)
527 fib_route_path_t path = {
528 .frp_proto = next_hop_proto,
529 .frp_addr = (NULL == next_hop? zero_addr : *next_hop),
530 .frp_sw_if_index = next_hop_sw_if_index,
531 .frp_fib_index = next_hop_fib_index,
532 .frp_weight = next_hop_weight,
533 .frp_flags = path_flags,
534 .frp_label_stack = next_hop_labels,
536 fib_node_index_t fib_entry_index;
537 fib_route_path_t *paths = NULL;
539 vec_add1(paths, path);
541 fib_entry_index = fib_table_entry_path_add2(fib_index, prefix,
542 source, flags, paths);
545 return (fib_entry_index);
549 fib_table_entry_path_add2 (u32 fib_index,
550 const fib_prefix_t *prefix,
552 fib_entry_flag_t flags,
553 fib_route_path_t *rpath)
555 fib_node_index_t fib_entry_index;
556 fib_table_t *fib_table;
559 fib_table = fib_table_get(fib_index, prefix->fp_proto);
560 fib_entry_index = fib_table_lookup_exact_match_i(fib_table, prefix);
562 for (ii = 0; ii < vec_len(rpath); ii++)
564 fib_table_route_path_fixup(prefix, flags, &rpath[ii]);
567 if (FIB_NODE_INDEX_INVALID == fib_entry_index)
569 fib_entry_index = fib_entry_create(fib_index, prefix,
573 fib_table_entry_insert(fib_table, prefix, fib_entry_index);
574 fib_table->ft_src_route_counts[source]++;
580 was_sourced = fib_entry_is_sourced(fib_entry_index, source);
581 fib_entry_path_add(fib_entry_index, source, flags, rpath);;
583 if (was_sourced != fib_entry_is_sourced(fib_entry_index, source))
585 fib_table->ft_src_route_counts[source]++;
589 return (fib_entry_index);
593 fib_table_entry_path_remove2 (u32 fib_index,
594 const fib_prefix_t *prefix,
596 fib_route_path_t *rpath)
600 * yes => remove source
601 * 2 - is it still sourced?
604 fib_node_index_t fib_entry_index;
605 fib_table_t *fib_table;
608 fib_table = fib_table_get(fib_index, prefix->fp_proto);
609 fib_entry_index = fib_table_lookup_exact_match_i(fib_table, prefix);
611 if (FIB_NODE_INDEX_INVALID == fib_entry_index)
614 * removing an etry that does not exist. i'll allow it.
619 fib_entry_src_flag_t src_flag;
623 * don't nobody go nowhere
625 fib_entry_lock(fib_entry_index);
626 was_sourced = fib_entry_is_sourced(fib_entry_index, source);
628 for (ii = 0; ii < vec_len(rpath); ii++)
630 fib_table_route_path_fixup(
632 fib_entry_get_flags_for_source(fib_entry_index,
637 src_flag = fib_entry_path_remove(fib_entry_index, source, rpath);
639 if (!(FIB_ENTRY_SRC_FLAG_ADDED & src_flag))
642 * last source gone. remove from the table
644 fib_table_entry_remove(fib_table, prefix, fib_entry_index);
647 * now the entry is no longer in the table, we can
648 * inform the entries that it covers to re-calculate their cover
650 fib_entry_cover_change_notify(fib_entry_index,
651 FIB_NODE_INDEX_INVALID);
655 * still has sources, leave it be.
657 if (was_sourced != fib_entry_is_sourced(fib_entry_index, source))
659 fib_table->ft_src_route_counts[source]--;
662 fib_entry_unlock(fib_entry_index);
667 fib_table_entry_path_remove (u32 fib_index,
668 const fib_prefix_t *prefix,
670 fib_protocol_t next_hop_proto,
671 const ip46_address_t *next_hop,
672 u32 next_hop_sw_if_index,
673 u32 next_hop_fib_index,
675 fib_route_path_flags_t path_flags)
679 * yes => remove source
680 * 2 - is it still sourced?
683 fib_route_path_t path = {
684 .frp_proto = next_hop_proto,
685 .frp_addr = (NULL == next_hop? zero_addr : *next_hop),
686 .frp_sw_if_index = next_hop_sw_if_index,
687 .frp_fib_index = next_hop_fib_index,
688 .frp_weight = next_hop_weight,
689 .frp_flags = path_flags,
691 fib_route_path_t *paths = NULL;
693 vec_add1(paths, path);
695 fib_table_entry_path_remove2(fib_index, prefix, source, paths);
701 fib_route_path_cmp_for_sort (void * v1,
704 return (fib_route_path_cmp(v1, v2));
708 fib_table_entry_update (u32 fib_index,
709 const fib_prefix_t *prefix,
711 fib_entry_flag_t flags,
712 fib_route_path_t *paths)
714 fib_node_index_t fib_entry_index;
715 fib_table_t *fib_table;
718 fib_table = fib_table_get(fib_index, prefix->fp_proto);
719 fib_entry_index = fib_table_lookup_exact_match_i(fib_table, prefix);
721 for (ii = 0; ii < vec_len(paths); ii++)
723 fib_table_route_path_fixup(prefix, flags, &paths[ii]);
726 * sort the paths provided by the control plane. this means
727 * the paths and the extension on the entry will be sorted.
729 vec_sort_with_function(paths, fib_route_path_cmp_for_sort);
731 if (FIB_NODE_INDEX_INVALID == fib_entry_index)
733 fib_entry_index = fib_entry_create(fib_index, prefix,
737 fib_table_entry_insert(fib_table, prefix, fib_entry_index);
738 fib_table->ft_src_route_counts[source]++;
744 was_sourced = fib_entry_is_sourced(fib_entry_index, source);
745 fib_entry_update(fib_entry_index, source, flags, paths);
747 if (was_sourced != fib_entry_is_sourced(fib_entry_index, source))
749 fib_table->ft_src_route_counts[source]++;
753 return (fib_entry_index);
757 fib_table_entry_update_one_path (u32 fib_index,
758 const fib_prefix_t *prefix,
760 fib_entry_flag_t flags,
761 fib_protocol_t next_hop_proto,
762 const ip46_address_t *next_hop,
763 u32 next_hop_sw_if_index,
764 u32 next_hop_fib_index,
766 mpls_label_t *next_hop_labels,
767 fib_route_path_flags_t path_flags)
769 fib_node_index_t fib_entry_index;
770 fib_route_path_t path = {
771 .frp_proto = next_hop_proto,
772 .frp_addr = (NULL == next_hop? zero_addr : *next_hop),
773 .frp_sw_if_index = next_hop_sw_if_index,
774 .frp_fib_index = next_hop_fib_index,
775 .frp_weight = next_hop_weight,
776 .frp_flags = path_flags,
777 .frp_label_stack = next_hop_labels,
779 fib_route_path_t *paths = NULL;
781 vec_add1(paths, path);
784 fib_table_entry_update(fib_index, prefix, source, flags, paths);
788 return (fib_entry_index);
792 fib_table_entry_delete_i (u32 fib_index,
793 fib_node_index_t fib_entry_index,
794 const fib_prefix_t *prefix,
797 fib_entry_src_flag_t src_flag;
798 fib_table_t *fib_table;
801 fib_table = fib_table_get(fib_index, prefix->fp_proto);
802 was_sourced = fib_entry_is_sourced(fib_entry_index, source);
805 * don't nobody go nowhere
807 fib_entry_lock(fib_entry_index);
809 src_flag = fib_entry_delete(fib_entry_index, source);
811 if (!(FIB_ENTRY_SRC_FLAG_ADDED & src_flag))
814 * last source gone. remove from the table
816 fib_table_entry_remove(fib_table, prefix, fib_entry_index);
819 * now the entry is no longer in the table, we can
820 * inform the entries that it covers to re-calculate their cover
822 fib_entry_cover_change_notify(fib_entry_index,
823 FIB_NODE_INDEX_INVALID);
827 * still has sources, leave it be.
829 if (was_sourced != fib_entry_is_sourced(fib_entry_index, source))
831 fib_table->ft_src_route_counts[source]--;
834 fib_entry_unlock(fib_entry_index);
838 fib_table_entry_delete (u32 fib_index,
839 const fib_prefix_t *prefix,
842 fib_node_index_t fib_entry_index;
844 fib_entry_index = fib_table_lookup_exact_match(fib_index, prefix);
846 if (FIB_NODE_INDEX_INVALID == fib_entry_index)
849 * removing an etry that does not exist.
850 * i'll allow it, but i won't like it.
852 clib_warning("%U not in FIB", format_fib_prefix, prefix);
856 fib_table_entry_delete_i(fib_index, fib_entry_index, prefix, source);
861 fib_table_entry_delete_index (fib_node_index_t fib_entry_index,
866 fib_entry_get_prefix(fib_entry_index, &prefix);
868 fib_table_entry_delete_i(fib_entry_get_fib_index(fib_entry_index),
869 fib_entry_index, &prefix, source);
873 fib_table_entry_local_label_add (u32 fib_index,
874 const fib_prefix_t *prefix,
877 fib_node_index_t fib_entry_index;
879 fib_entry_index = fib_table_lookup_exact_match(fib_index, prefix);
881 if (FIB_NODE_INDEX_INVALID == fib_entry_index ||
882 !fib_entry_is_sourced(fib_entry_index, FIB_SOURCE_MPLS))
885 * only source the prefix once. this allows the label change
888 fib_entry_index = fib_table_entry_special_dpo_add(fib_index, prefix,
894 fib_entry_set_source_data(fib_entry_index, FIB_SOURCE_MPLS, &label);
896 return (fib_entry_index);
900 fib_table_entry_local_label_remove (u32 fib_index,
901 const fib_prefix_t *prefix,
904 fib_node_index_t fib_entry_index;
908 fib_entry_index = fib_table_lookup_exact_match(fib_index, prefix);
910 if (FIB_NODE_INDEX_INVALID == fib_entry_index)
913 data = fib_entry_get_source_data(fib_entry_index, FIB_SOURCE_MPLS);
918 pl = *(mpls_label_t*)data;
923 pl = MPLS_LABEL_INVALID;
925 fib_entry_set_source_data(fib_entry_index, FIB_SOURCE_MPLS, &pl);
926 fib_table_entry_special_remove(fib_index,
932 fib_table_get_index_for_sw_if_index (fib_protocol_t proto,
937 case FIB_PROTOCOL_IP4:
938 return (ip4_fib_table_get_index_for_sw_if_index(sw_if_index));
939 case FIB_PROTOCOL_IP6:
940 return (ip6_fib_table_get_index_for_sw_if_index(sw_if_index));
941 case FIB_PROTOCOL_MPLS:
942 return (mpls_fib_table_get_index_for_sw_if_index(sw_if_index));
948 fib_table_get_flow_hash_config (u32 fib_index,
949 fib_protocol_t proto)
953 case FIB_PROTOCOL_IP4:
954 return (ip4_fib_table_get_flow_hash_config(fib_index));
955 case FIB_PROTOCOL_IP6:
956 return (ip6_fib_table_get_flow_hash_config(fib_index));
957 case FIB_PROTOCOL_MPLS:
958 return (mpls_fib_table_get_flow_hash_config(fib_index));
965 fib_table_get_table_id_for_sw_if_index (fib_protocol_t proto,
968 fib_table_t *fib_table;
970 fib_table = fib_table_get(fib_table_get_index_for_sw_if_index(
974 return ((NULL != fib_table ? fib_table->ft_table_id : ~0));
978 fib_table_find (fib_protocol_t proto,
983 case FIB_PROTOCOL_IP4:
984 return (ip4_fib_index_from_table_id(table_id));
985 case FIB_PROTOCOL_IP6:
986 return (ip6_fib_index_from_table_id(table_id));
987 case FIB_PROTOCOL_MPLS:
988 return (mpls_fib_index_from_table_id(table_id));
994 fib_table_find_or_create_and_lock (fib_protocol_t proto,
997 fib_table_t *fib_table;
1002 case FIB_PROTOCOL_IP4:
1003 fi = ip4_fib_table_find_or_create_and_lock(table_id);
1005 case FIB_PROTOCOL_IP6:
1006 fi = ip6_fib_table_find_or_create_and_lock(table_id);
1008 case FIB_PROTOCOL_MPLS:
1009 fi = mpls_fib_table_find_or_create_and_lock(table_id);
1015 fib_table = fib_table_get(fi, proto);
1017 fib_table->ft_desc = format(NULL, "%U-VRF:%d",
1018 format_fib_protocol, proto,
1025 fib_table_create_and_lock (fib_protocol_t proto,
1026 const char *const fmt,
1029 fib_table_t *fib_table;
1030 fib_node_index_t fi;
1037 case FIB_PROTOCOL_IP4:
1038 fi = ip4_fib_table_create_and_lock();
1040 case FIB_PROTOCOL_IP6:
1041 fi = ip6_fib_table_create_and_lock();
1043 case FIB_PROTOCOL_MPLS:
1044 fi = mpls_fib_table_create_and_lock();
1050 fib_table = fib_table_get(fi, proto);
1052 fib_table->ft_desc = va_format(fib_table->ft_desc, fmt, &ap);
1059 fib_table_destroy (fib_table_t *fib_table)
1061 vec_free(fib_table->ft_desc);
1063 switch (fib_table->ft_proto)
1065 case FIB_PROTOCOL_IP4:
1066 ip4_fib_table_destroy(fib_table->ft_index);
1068 case FIB_PROTOCOL_IP6:
1069 ip6_fib_table_destroy(fib_table->ft_index);
1071 case FIB_PROTOCOL_MPLS:
1072 mpls_fib_table_destroy(fib_table->ft_index);
1078 fib_table_walk (u32 fib_index,
1079 fib_protocol_t proto,
1080 fib_table_walk_fn_t fn,
1085 case FIB_PROTOCOL_IP4:
1086 ip4_fib_table_walk(ip4_fib_get(fib_index), fn, ctx);
1088 case FIB_PROTOCOL_IP6:
1089 ip6_fib_table_walk(fib_index, fn, ctx);
1091 case FIB_PROTOCOL_MPLS:
1092 mpls_fib_table_walk(mpls_fib_get(fib_index), fn, ctx);
1098 fib_table_unlock (u32 fib_index,
1099 fib_protocol_t proto)
1101 fib_table_t *fib_table;
1103 fib_table = fib_table_get(fib_index, proto);
1104 fib_table->ft_locks--;
1106 if (0 == fib_table->ft_locks)
1108 fib_table_destroy(fib_table);
1112 fib_table_lock (u32 fib_index,
1113 fib_protocol_t proto)
1115 fib_table_t *fib_table;
1117 fib_table = fib_table_get(fib_index, proto);
1118 fib_table->ft_locks++;
1122 fib_table_get_num_entries (u32 fib_index,
1123 fib_protocol_t proto,
1124 fib_source_t source)
1126 fib_table_t *fib_table;
1128 fib_table = fib_table_get(fib_index, proto);
1130 return (fib_table->ft_src_route_counts[source]);
1134 format_fib_table_name (u8* s, va_list ap)
1136 fib_node_index_t fib_index = va_arg(ap, fib_node_index_t);
1137 fib_protocol_t proto = va_arg(ap, int); // int promotion
1138 fib_table_t *fib_table;
1140 fib_table = fib_table_get(fib_index, proto);
1142 s = format(s, "%v", fib_table->ft_desc);
1148 * @brief Table flush context. Store the indicies of matching FIB entries
1149 * that need to be removed.
1151 typedef struct fib_table_flush_ctx_t_
1154 * The list of entries to flush
1156 fib_node_index_t *ftf_entries;
1159 * The source we are flushing
1161 fib_source_t ftf_source;
1162 } fib_table_flush_ctx_t;
1165 fib_table_flush_cb (fib_node_index_t fib_entry_index,
1168 fib_table_flush_ctx_t *ctx = arg;
1170 if (fib_entry_is_sourced(fib_entry_index, ctx->ftf_source))
1172 vec_add1(ctx->ftf_entries, fib_entry_index);
1179 fib_table_flush (u32 fib_index,
1180 fib_protocol_t proto,
1181 fib_source_t source)
1183 fib_node_index_t *fib_entry_index;
1184 fib_table_flush_ctx_t ctx = {
1185 .ftf_entries = NULL,
1186 .ftf_source = source,
1189 fib_table_walk(fib_index, proto,
1193 vec_foreach(fib_entry_index, ctx.ftf_entries)
1195 fib_table_entry_delete_index(*fib_entry_index, source);
1198 vec_free(ctx.ftf_entries);