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/ip/format.h>
18 #include <vnet/ip/lookup.h>
19 #include <vnet/adj/adj.h>
20 #include <vnet/dpo/load_balance.h>
21 #include <vnet/dpo/drop_dpo.h>
23 #include <vnet/fib/fib_entry.h>
24 #include <vnet/fib/fib_walk.h>
25 #include <vnet/fib/fib_entry_src.h>
26 #include <vnet/fib/fib_entry_cover.h>
27 #include <vnet/fib/fib_table.h>
28 #include <vnet/fib/fib_internal.h>
29 #include <vnet/fib/fib_attached_export.h>
30 #include <vnet/fib/fib_path_ext.h>
31 #include <vnet/fib/fib_entry_delegate.h>
32 #include <vnet/fib/fib_entry_track.h>
35 * Array of strings/names for the FIB sources
37 static const char *fib_attribute_names[] = FIB_ENTRY_ATTRIBUTES;
38 static const char *fib_src_attribute_names[] = FIB_ENTRY_SRC_ATTRIBUTES;
41 * Pool for all fib_entries
43 static fib_entry_t *fib_entry_pool;
48 vlib_log_class_t fib_entry_logger;
51 fib_entry_get (fib_node_index_t index)
53 return (pool_elt_at_index(fib_entry_pool, index));
57 fib_entry_get_node (fib_node_index_t index)
59 return ((fib_node_t*)fib_entry_get(index));
63 fib_entry_get_index (const fib_entry_t * fib_entry)
65 return (fib_entry - fib_entry_pool);
69 fib_entry_get_proto (const fib_entry_t * fib_entry)
71 return (fib_entry->fe_prefix.fp_proto);
75 fib_entry_get_dpo_proto (const fib_entry_t * fib_entry)
77 return (fib_proto_to_dpo(fib_entry->fe_prefix.fp_proto));
80 fib_forward_chain_type_t
81 fib_entry_get_default_chain_type (const fib_entry_t *fib_entry)
83 switch (fib_entry->fe_prefix.fp_proto)
85 case FIB_PROTOCOL_IP4:
86 return (FIB_FORW_CHAIN_TYPE_UNICAST_IP4);
87 case FIB_PROTOCOL_IP6:
88 return (FIB_FORW_CHAIN_TYPE_UNICAST_IP6);
89 case FIB_PROTOCOL_MPLS:
90 if (MPLS_EOS == fib_entry->fe_prefix.fp_eos)
91 return (FIB_FORW_CHAIN_TYPE_MPLS_EOS);
93 return (FIB_FORW_CHAIN_TYPE_MPLS_NON_EOS);
96 return (FIB_FORW_CHAIN_TYPE_UNICAST_IP4);
100 format_fib_entry_flags (u8 *s, va_list *args)
102 fib_entry_attribute_t attr;
103 fib_entry_flag_t flag = va_arg(*args, int);
105 FOR_EACH_FIB_ATTRIBUTE(attr) {
106 if ((1<<attr) & flag) {
107 s = format (s, "%s,", fib_attribute_names[attr]);
115 format_fib_entry_src_flags (u8 *s, va_list *args)
117 fib_entry_src_attribute_t sattr;
118 fib_entry_src_flag_t flag = va_arg(*args, int);
120 FOR_EACH_FIB_SRC_ATTRIBUTE(sattr) {
121 if ((1<<sattr) & flag) {
122 s = format (s, "%s,", fib_src_attribute_names[sattr]);
130 format_fib_entry (u8 * s, va_list * args)
132 fib_forward_chain_type_t fct;
133 fib_entry_t *fib_entry;
134 fib_entry_src_t *src;
135 fib_node_index_t fei;
139 fei = va_arg (*args, fib_node_index_t);
140 level = va_arg (*args, int);
141 fib_entry = fib_entry_get(fei);
143 s = format (s, "%U", format_fib_prefix, &fib_entry->fe_prefix);
145 if (level >= FIB_ENTRY_FORMAT_DETAIL)
147 s = format (s, " fib:%d", fib_entry->fe_fib_index);
148 s = format (s, " index:%d", fib_entry_get_index(fib_entry));
149 s = format (s, " locks:%d", fib_entry->fe_node.fn_locks);
151 FOR_EACH_SRC_ADDED(fib_entry, src, source,
153 s = format (s, "\n %U", format_fib_source, source);
154 s = format (s, " refs:%d", src->fes_ref_count);
155 if (FIB_ENTRY_FLAG_NONE != src->fes_entry_flags) {
156 s = format(s, " entry-flags:%U",
157 format_fib_entry_flags, src->fes_entry_flags);
159 if (FIB_ENTRY_SRC_FLAG_NONE != src->fes_flags) {
160 s = format(s, " src-flags:%U",
161 format_fib_entry_src_flags, src->fes_flags);
163 s = fib_entry_src_format(fib_entry, source, s);
164 s = format (s, "\n");
165 if (FIB_NODE_INDEX_INVALID != src->fes_pl)
167 s = fib_path_list_format(src->fes_pl, s);
169 s = format(s, "%U", format_fib_path_ext_list, &src->fes_path_exts);
172 s = format (s, "\n forwarding: ");
176 s = format (s, "\n");
179 fct = fib_entry_get_default_chain_type(fib_entry);
181 if (!dpo_id_is_valid(&fib_entry->fe_lb))
183 s = format (s, " UNRESOLVED\n");
188 s = format(s, " %U-chain\n %U",
189 format_fib_forw_chain_type, fct,
195 if (level >= FIB_ENTRY_FORMAT_DETAIL2)
199 s = format (s, " Delegates:\n");
200 vec_foreach(fedi, fib_entry->fe_delegates)
202 s = format(s, " %U\n", format_fib_entry_delegate, *fedi);
207 if (level >= FIB_ENTRY_FORMAT_DETAIL2)
209 s = format(s, " Children:");
210 s = fib_node_children_format(fib_entry->fe_node.fn_children, s);
217 fib_entry_from_fib_node (fib_node_t *node)
219 ASSERT(FIB_NODE_TYPE_ENTRY == node->fn_type);
220 return ((fib_entry_t*)node);
224 fib_entry_last_lock_gone (fib_node_t *node)
226 fib_entry_delegate_type_t fdt;
227 fib_entry_delegate_t *fed;
228 fib_entry_t *fib_entry;
230 fib_entry = fib_entry_from_fib_node(node);
232 ASSERT(!dpo_id_is_valid(&fib_entry->fe_lb));
234 FOR_EACH_DELEGATE_CHAIN(fib_entry, fdt, fed,
236 dpo_reset(&fed->fd_dpo);
237 fib_entry_delegate_remove(fib_entry, fdt);
240 FIB_ENTRY_DBG(fib_entry, "last-lock");
242 fib_node_deinit(&fib_entry->fe_node);
244 ASSERT(0 == vec_len(fib_entry->fe_delegates));
245 vec_free(fib_entry->fe_delegates);
246 vec_free(fib_entry->fe_srcs);
247 pool_put(fib_entry_pool, fib_entry);
250 static fib_entry_src_t*
251 fib_entry_get_best_src_i (const fib_entry_t *fib_entry)
253 fib_entry_src_t *bsrc;
256 * the enum of sources is deliberately arranged in priority order
258 if (0 == vec_len(fib_entry->fe_srcs))
264 bsrc = vec_elt_at_index(fib_entry->fe_srcs, 0);
271 fib_entry_src_get_source (const fib_entry_src_t *esrc)
275 return (esrc->fes_src);
277 return (FIB_SOURCE_INVALID);
280 static fib_entry_flag_t
281 fib_entry_src_get_flags (const fib_entry_src_t *esrc)
285 return (esrc->fes_entry_flags);
287 return (FIB_ENTRY_FLAG_NONE);
291 fib_entry_get_flags (fib_node_index_t fib_entry_index)
293 return (fib_entry_get_flags_i(fib_entry_get(fib_entry_index)));
297 fib_entry_show_memory (void)
299 u32 n_srcs = 0, n_exts = 0;
300 fib_entry_src_t *esrc;
303 fib_show_memory_usage("Entry",
304 pool_elts(fib_entry_pool),
305 pool_len(fib_entry_pool),
306 sizeof(fib_entry_t));
308 pool_foreach (entry, fib_entry_pool)
310 n_srcs += vec_len(entry->fe_srcs);
311 vec_foreach(esrc, entry->fe_srcs)
313 n_exts += fib_path_ext_list_length(&esrc->fes_path_exts);
317 fib_show_memory_usage("Entry Source",
318 n_srcs, n_srcs, sizeof(fib_entry_src_t));
319 fib_show_memory_usage("Entry Path-Extensions",
321 sizeof(fib_path_ext_t));
325 * @brief Contribute the set of Adjacencies that this entry forwards with
326 * to build the uRPF list of its children
329 fib_entry_contribute_urpf (fib_node_index_t entry_index,
332 fib_entry_t *fib_entry;
334 fib_entry = fib_entry_get(entry_index);
336 return (fib_path_list_contribute_urpf(fib_entry->fe_parent, urpf));
340 * If the client is request a chain for multicast forwarding then swap
341 * the chain type to one that can provide such transport.
343 static fib_forward_chain_type_t
344 fib_entry_chain_type_mcast_to_ucast (fib_forward_chain_type_t fct)
348 case FIB_FORW_CHAIN_TYPE_MCAST_IP4:
349 case FIB_FORW_CHAIN_TYPE_MCAST_IP6:
351 * we can only transport IP multicast packets if there is an
354 fct = FIB_FORW_CHAIN_TYPE_MPLS_EOS;
356 case FIB_FORW_CHAIN_TYPE_MPLS_EOS:
357 case FIB_FORW_CHAIN_TYPE_UNICAST_IP4:
358 case FIB_FORW_CHAIN_TYPE_UNICAST_IP6:
359 case FIB_FORW_CHAIN_TYPE_MPLS_NON_EOS:
360 case FIB_FORW_CHAIN_TYPE_ETHERNET:
361 case FIB_FORW_CHAIN_TYPE_NSH:
362 case FIB_FORW_CHAIN_TYPE_BIER:
370 * fib_entry_contribute_forwarding
372 * Get an lock the forwarding information (DPO) contributed by the FIB entry.
375 fib_entry_contribute_forwarding (fib_node_index_t fib_entry_index,
376 fib_forward_chain_type_t fct,
379 fib_entry_delegate_t *fed;
380 fib_entry_t *fib_entry;
382 fib_entry = fib_entry_get(fib_entry_index);
385 * mfib children ask for mcast chains. fix these to the appropriate ucast types.
387 fct = fib_entry_chain_type_mcast_to_ucast(fct);
389 if (fct == fib_entry_get_default_chain_type(fib_entry))
391 dpo_copy(dpo, &fib_entry->fe_lb);
395 fed = fib_entry_delegate_find(fib_entry,
396 fib_entry_chain_type_to_delegate_type(fct));
401 * use a temporary DPO lest the delegate realloc in the recursive
404 dpo_id_t tmp = DPO_INVALID;
407 * on-demand create eos/non-eos.
408 * There is no on-demand delete because:
409 * - memory versus complexity & reliability:
410 * leaving unrequired [n]eos LB arounds wastes memory, cleaning
411 * then up on the right trigger is more code. i favour the latter.
413 fib_entry_src_mk_lb(fib_entry,
414 fib_entry_get_best_source(fib_entry_index),
418 fed = fib_entry_delegate_find_or_add(
420 fib_entry_chain_type_to_delegate_type(fct));
422 dpo_copy(&fed->fd_dpo, &tmp);
426 dpo_copy(dpo, &fed->fd_dpo);
429 * use the drop DPO is nothing else is present
431 if (!dpo_id_is_valid(dpo))
433 dpo_copy(dpo, drop_dpo_get(fib_forw_chain_type_to_dpo_proto(fct)));
437 * don't allow the special index indicating replicate.vs.load-balance
438 * to escape to the clients
440 dpo->dpoi_index &= ~MPLS_IS_REPLICATE;
444 fib_entry_contribute_ip_forwarding (fib_node_index_t fib_entry_index)
446 fib_forward_chain_type_t fct;
447 fib_entry_t *fib_entry;
449 fib_entry = fib_entry_get(fib_entry_index);
450 fct = fib_entry_get_default_chain_type(fib_entry);
452 ASSERT((fct == FIB_FORW_CHAIN_TYPE_UNICAST_IP4 ||
453 fct == FIB_FORW_CHAIN_TYPE_UNICAST_IP6));
455 if (dpo_id_is_valid(&fib_entry->fe_lb))
457 return (&fib_entry->fe_lb);
460 return (drop_dpo_get(fib_forw_chain_type_to_dpo_proto(fct)));
464 fib_entry_get_adj (fib_node_index_t fib_entry_index)
468 dpo = fib_entry_contribute_ip_forwarding(fib_entry_index);
470 if (dpo_id_is_valid(dpo))
472 dpo = load_balance_get_bucket(dpo->dpoi_index, 0);
476 return (dpo->dpoi_index);
479 return (ADJ_INDEX_INVALID);
483 fib_entry_get_path_list (fib_node_index_t fib_entry_index)
485 fib_entry_t *fib_entry;
487 fib_entry = fib_entry_get(fib_entry_index);
489 return (fib_entry->fe_parent);
493 fib_entry_child_add (fib_node_index_t fib_entry_index,
494 fib_node_type_t child_type,
495 fib_node_index_t child_index)
497 return (fib_node_child_add(FIB_NODE_TYPE_ENTRY,
504 fib_entry_child_remove (fib_node_index_t fib_entry_index,
507 fib_node_child_remove(FIB_NODE_TYPE_ENTRY,
511 if (0 == fib_node_get_n_children(FIB_NODE_TYPE_ENTRY,
515 * if there are no children left then there is no reason to keep
516 * the non-default forwarding chains. those chains are built only
517 * because the children want them.
519 fib_entry_delegate_type_t fdt;
520 fib_entry_delegate_t *fed;
521 fib_entry_t *fib_entry;
523 fib_entry = fib_entry_get(fib_entry_index);
525 FOR_EACH_DELEGATE_CHAIN(fib_entry, fdt, fed,
527 dpo_reset(&fed->fd_dpo);
528 fib_entry_delegate_remove(fib_entry, fdt);
534 fib_entry_alloc (u32 fib_index,
535 const fib_prefix_t *prefix,
536 fib_node_index_t *fib_entry_index)
538 fib_entry_t *fib_entry;
540 u8 need_barrier_sync = pool_get_will_expand (fib_entry_pool);
541 vlib_main_t *vm = vlib_get_main();
542 ASSERT (vm->thread_index == 0);
544 if (need_barrier_sync)
545 vlib_worker_thread_barrier_sync (vm);
547 pool_get(fib_entry_pool, fib_entry);
549 if (need_barrier_sync)
550 vlib_worker_thread_barrier_release (vm);
552 clib_memset(fib_entry, 0, sizeof(*fib_entry));
554 fib_node_init(&fib_entry->fe_node,
555 FIB_NODE_TYPE_ENTRY);
557 fib_entry->fe_fib_index = fib_index;
560 * the one time we need to update the const prefix is when
561 * the entry is first created
563 fep = (fib_prefix_t*)&(fib_entry->fe_prefix);
566 if (FIB_PROTOCOL_MPLS == fib_entry->fe_prefix.fp_proto)
569 if (MPLS_NON_EOS == fep->fp_eos)
571 fep->fp_payload_proto = DPO_PROTO_MPLS;
573 ASSERT(DPO_PROTO_NONE != fib_entry->fe_prefix.fp_payload_proto);
576 dpo_reset(&fib_entry->fe_lb);
578 *fib_entry_index = fib_entry_get_index(fib_entry);
584 fib_entry_post_flag_update_actions (fib_entry_t *fib_entry,
585 fib_entry_flag_t old_flags,
588 fib_node_index_t fei;
591 * save the index so we can recover from pool reallocs
593 fei = fib_entry_get_index(fib_entry);
596 * handle changes to attached export for import entries
598 int is_import = (FIB_ENTRY_FLAG_IMPORT & fib_entry_get_flags_i(fib_entry));
599 int was_import = (FIB_ENTRY_FLAG_IMPORT & old_flags);
601 if (!was_import && is_import)
604 * transition from not exported to exported
608 * there is an assumption here that the entry resolves via only
609 * one interface and that it is the cross VRF interface.
611 if (~0 == new_fib_index)
613 u32 sw_if_index = fib_path_list_get_resolving_interface(fib_entry->fe_parent);
614 new_fib_index = fib_table_get_index_for_sw_if_index(
615 fib_entry_get_proto(fib_entry),
618 fib_attached_export_import(fib_entry, new_fib_index);
620 else if (was_import && !is_import)
623 * transition from exported to not exported
625 fib_attached_export_purge(fib_entry);
627 else if (was_import && is_import && ~0 != new_fib_index)
630 * transition from export from one table to another
632 fib_attached_export_purge(fib_entry);
633 fib_attached_export_import(fib_entry, new_fib_index);
637 * no change. nothing to do.
641 * reload the entry address post possible pool realloc
643 fib_entry = fib_entry_get(fei);
646 * handle changes to attached export for export entries
648 int is_attached = (FIB_ENTRY_FLAG_ATTACHED & fib_entry_get_flags_i(fib_entry));
649 int was_attached = (FIB_ENTRY_FLAG_ATTACHED & old_flags);
651 if (!was_attached && is_attached)
654 * transition to attached. time to export
664 fib_entry_post_install_actions (fib_entry_t *fib_entry,
666 fib_entry_flag_t old_flags)
668 fib_entry = fib_entry_post_flag_update_actions(fib_entry, old_flags, ~0);
669 fib_entry = fib_entry_src_action_installed(fib_entry, source);
675 fib_entry_create (u32 fib_index,
676 const fib_prefix_t *prefix,
678 fib_entry_flag_t flags,
679 const fib_route_path_t *paths)
681 fib_node_index_t fib_entry_index;
682 fib_entry_t *fib_entry;
684 ASSERT(0 < vec_len(paths));
686 fib_entry = fib_entry_alloc(fib_index, prefix, &fib_entry_index);
689 * since this is a new entry create, we don't need to check for winning
690 * sources - there is only one.
692 fib_entry = fib_entry_src_action_add(fib_entry, source, flags,
695 fib_entry_get_proto(fib_entry))));
696 fib_entry_src_action_path_swap(fib_entry,
701 * handle possible realloc's by refetching the pointer
703 fib_entry = fib_entry_get(fib_entry_index);
704 fib_entry_src_action_activate(fib_entry, source);
706 fib_entry = fib_entry_post_install_actions(fib_entry, source,
707 FIB_ENTRY_FLAG_NONE);
709 FIB_ENTRY_DBG(fib_entry, "create");
711 return (fib_entry_index);
715 fib_entry_create_special (u32 fib_index,
716 const fib_prefix_t *prefix,
718 fib_entry_flag_t flags,
721 fib_node_index_t fib_entry_index;
722 fib_entry_t *fib_entry;
725 * create and initialize the new enty
727 fib_entry = fib_entry_alloc(fib_index, prefix, &fib_entry_index);
730 * create the path-list
732 fib_entry = fib_entry_src_action_add(fib_entry, source, flags, dpo);
733 fib_entry_src_action_activate(fib_entry, source);
735 fib_entry = fib_entry_post_install_actions(fib_entry, source,
736 FIB_ENTRY_FLAG_NONE);
738 FIB_ENTRY_DBG(fib_entry, "create-special");
740 return (fib_entry_index);
744 fib_entry_post_update_actions (fib_entry_t *fib_entry,
746 fib_entry_flag_t old_flags)
749 * backwalk to children to inform then of the change to forwarding.
751 fib_node_back_walk_ctx_t bw_ctx = {
752 .fnbw_reason = FIB_NODE_BW_REASON_FLAG_EVALUATE,
755 fib_walk_sync(FIB_NODE_TYPE_ENTRY, fib_entry_get_index(fib_entry), &bw_ctx);
758 * then inform any covered prefixes
760 fib_entry_cover_update_notify(fib_entry);
762 fib_entry_post_install_actions(fib_entry, source, old_flags);
766 fib_entry_recalculate_forwarding (fib_node_index_t fib_entry_index)
768 fib_source_t best_source;
769 fib_entry_t *fib_entry;
770 fib_entry_src_t *bsrc;
772 fib_entry = fib_entry_get(fib_entry_index);
774 bsrc = fib_entry_get_best_src_i(fib_entry);
775 best_source = fib_entry_src_get_source(bsrc);
777 fib_entry_src_action_reactivate(fib_entry, best_source);
781 fib_entry_source_change_w_flags (fib_entry_t *fib_entry,
782 fib_source_t old_source,
783 fib_entry_flag_t old_flags,
784 fib_source_t new_source)
786 switch (fib_source_cmp(new_source, old_source))
788 case FIB_SOURCE_CMP_BETTER:
790 * we have a new winning source.
792 fib_entry_src_action_deactivate(fib_entry, old_source);
793 fib_entry_src_action_activate(fib_entry, new_source);
796 case FIB_SOURCE_CMP_WORSE:
798 * the new source loses. Re-activate the winning sources
799 * in case it is an interposer and hence relied on the losing
800 * source's path-list.
802 fib_entry_src_action_reactivate(fib_entry, old_source);
805 case FIB_SOURCE_CMP_EQUAL:
807 * the new source is one this entry already has.
808 * But the path-list was updated, which will contribute new forwarding,
811 fib_entry_src_action_reactivate(fib_entry, new_source);
815 fib_entry_post_update_actions(fib_entry, new_source, old_flags);
819 fib_entry_source_change (fib_entry_t *fib_entry,
820 fib_source_t old_source,
821 fib_source_t new_source)
823 fib_entry_flag_t old_flags;
825 old_flags = fib_entry_get_flags_for_source(
826 fib_entry_get_index(fib_entry), old_source);
828 return (fib_entry_source_change_w_flags(fib_entry, old_source,
829 old_flags, new_source));
833 fib_entry_special_add (fib_node_index_t fib_entry_index,
835 fib_entry_flag_t flags,
838 fib_source_t best_source;
839 fib_entry_t *fib_entry;
841 fib_entry = fib_entry_get(fib_entry_index);
842 best_source = fib_entry_get_best_source(fib_entry_index);
844 fib_entry = fib_entry_src_action_add(fib_entry, source, flags, dpo);
845 fib_entry_source_change(fib_entry, best_source, source);
846 FIB_ENTRY_DBG(fib_entry, "special-add:%U", format_fib_source, source);
850 fib_entry_special_update (fib_node_index_t fib_entry_index,
852 fib_entry_flag_t flags,
855 fib_source_t best_source;
856 fib_entry_t *fib_entry;
858 fib_entry = fib_entry_get(fib_entry_index);
859 best_source = fib_entry_get_best_source(fib_entry_index);
861 fib_entry = fib_entry_src_action_update(fib_entry, source, flags, dpo);
862 fib_entry_source_change(fib_entry, best_source, source);
864 FIB_ENTRY_DBG(fib_entry, "special-updated:%U", format_fib_source, source);
869 fib_entry_path_add (fib_node_index_t fib_entry_index,
871 fib_entry_flag_t flags,
872 const fib_route_path_t *rpaths)
874 fib_source_t best_source;
875 fib_entry_t *fib_entry;
876 fib_entry_src_t *bsrc;
878 fib_entry = fib_entry_get(fib_entry_index);
879 ASSERT(NULL != fib_entry);
881 bsrc = fib_entry_get_best_src_i(fib_entry);
882 best_source = fib_entry_src_get_source(bsrc);
884 fib_entry = fib_entry_src_action_path_add(fib_entry, source, flags, rpaths);
886 fib_entry_source_change(fib_entry, best_source, source);
888 FIB_ENTRY_DBG(fib_entry, "path add:%U", format_fib_source, source);
891 static fib_entry_src_flag_t
892 fib_entry_src_burn_only_inherited (fib_entry_t *fib_entry)
894 fib_entry_src_t *src;
896 int has_only_inherited_sources = 1;
898 FOR_EACH_SRC_ADDED(fib_entry, src, source,
900 if (!(src->fes_flags & FIB_ENTRY_SRC_FLAG_INHERITED))
902 has_only_inherited_sources = 0;
906 if (has_only_inherited_sources)
908 FOR_EACH_SRC_ADDED(fib_entry, src, source,
910 fib_entry_src_action_remove(fib_entry, source);
912 return (FIB_ENTRY_SRC_FLAG_NONE);
916 return (FIB_ENTRY_SRC_FLAG_ADDED);
920 static fib_entry_src_flag_t
921 fib_entry_source_removed (fib_entry_t *fib_entry,
922 fib_entry_flag_t old_flags)
924 const fib_entry_src_t *bsrc;
925 fib_source_t best_source;
928 * if all that is left are inherited sources, then burn them
930 fib_entry_src_burn_only_inherited(fib_entry);
932 bsrc = fib_entry_get_best_src_i(fib_entry);
933 best_source = fib_entry_src_get_source(bsrc);
935 if (FIB_SOURCE_INVALID == best_source)
938 * no more sources left. this entry is toast.
940 fib_entry = fib_entry_post_flag_update_actions(fib_entry, old_flags, ~0);
941 fib_entry_src_action_uninstall(fib_entry);
943 return (FIB_ENTRY_SRC_FLAG_NONE);
947 fib_entry_src_action_activate(fib_entry, best_source);
950 fib_entry_post_update_actions(fib_entry, best_source, old_flags);
955 return (FIB_ENTRY_SRC_FLAG_ADDED);
959 * fib_entry_path_remove
961 * remove a path from the entry.
962 * return the fib_entry's index if it is still present, INVALID otherwise.
965 fib_entry_path_remove (fib_node_index_t fib_entry_index,
967 const fib_route_path_t *rpaths)
969 fib_entry_src_flag_t sflag;
970 fib_source_t best_source;
971 fib_entry_flag_t bflags;
972 fib_entry_t *fib_entry;
973 fib_entry_src_t *bsrc;
975 fib_entry = fib_entry_get(fib_entry_index);
976 ASSERT(NULL != fib_entry);
978 bsrc = fib_entry_get_best_src_i(fib_entry);
979 best_source = fib_entry_src_get_source(bsrc);
980 bflags = fib_entry_src_get_flags(bsrc);
982 sflag = fib_entry_src_action_path_remove(fib_entry, source, rpaths);
984 FIB_ENTRY_DBG(fib_entry, "path remove:%U", format_fib_source, source);
987 * if the path list for the source passed is invalid,
988 * then we need to create a new one. else we are updating
991 switch (fib_source_cmp(source, best_source))
993 case FIB_SOURCE_CMP_BETTER:
995 * Que! removing a path from a source that is better than the
996 * one this entry is using.
1000 case FIB_SOURCE_CMP_WORSE:
1002 * the source is not the best. no need to update forwarding
1004 if (FIB_ENTRY_SRC_FLAG_ADDED & sflag)
1007 * the source being removed still has paths
1009 return (FIB_ENTRY_SRC_FLAG_ADDED);
1014 * that was the last path from this source, check if those
1015 * that remain are non-inherited
1017 return (fib_entry_src_burn_only_inherited(fib_entry));
1020 case FIB_SOURCE_CMP_EQUAL:
1022 * removing a path from the path-list we were using.
1024 if (!(FIB_ENTRY_SRC_FLAG_ADDED & sflag))
1027 * the last path from the source was removed.
1028 * fallback to lower source
1030 return (fib_entry_source_removed(fib_entry, bflags));
1035 * re-install the new forwarding information
1037 fib_entry_src_action_reactivate(fib_entry, source);
1042 fib_entry_post_update_actions(fib_entry, source, bflags);
1045 * still have sources
1047 return (FIB_ENTRY_SRC_FLAG_ADDED);
1051 * fib_entry_special_remove
1053 * remove a special source from the entry.
1054 * return the fib_entry's index if it is still present, INVALID otherwise.
1056 fib_entry_src_flag_t
1057 fib_entry_special_remove (fib_node_index_t fib_entry_index,
1058 fib_source_t source)
1060 fib_entry_src_flag_t sflag;
1061 fib_source_t best_source;
1062 fib_entry_flag_t bflags;
1063 fib_entry_t *fib_entry;
1064 fib_entry_src_t *bsrc;
1066 fib_entry = fib_entry_get(fib_entry_index);
1067 ASSERT(NULL != fib_entry);
1069 bsrc = fib_entry_get_best_src_i(fib_entry);
1070 best_source = fib_entry_src_get_source(bsrc);
1071 bflags = fib_entry_src_get_flags(bsrc);
1073 FIB_ENTRY_DBG(fib_entry, "special remove:%U", format_fib_source, source);
1075 sflag = fib_entry_src_action_remove_or_update_inherit(fib_entry, source);
1078 * if the path list for the source passed is invalid,
1079 * then we need to create a new one. else we are updating
1082 switch (fib_source_cmp(source, best_source))
1084 case FIB_SOURCE_CMP_BETTER:
1086 * Que! removing a path from a source that is better than the
1087 * one this entry is using. This can only mean it is a source
1088 * this prefix does not have.
1090 return (FIB_ENTRY_SRC_FLAG_ADDED);
1092 case FIB_SOURCE_CMP_WORSE:
1094 * the source is not the best. no need to update forwarding
1096 if (FIB_ENTRY_SRC_FLAG_ADDED & sflag)
1099 * the source being removed still has paths
1101 return (FIB_ENTRY_SRC_FLAG_ADDED);
1106 * that was the last path from this source, check if those
1107 * that remain are non-inherited
1109 if (FIB_ENTRY_SRC_FLAG_NONE == fib_entry_src_burn_only_inherited(fib_entry))
1112 * no more sources left. this entry is toast.
1114 fib_entry = fib_entry_post_flag_update_actions(fib_entry, bflags, ~0);
1115 fib_entry_src_action_uninstall(fib_entry);
1116 return (FIB_ENTRY_SRC_FLAG_NONE);
1120 * reactivate the best source so the interposer gets restacked
1122 fib_entry_src_action_reactivate(fib_entry, best_source);
1124 return (FIB_ENTRY_SRC_FLAG_ADDED);
1128 case FIB_SOURCE_CMP_EQUAL:
1129 if (!(FIB_ENTRY_SRC_FLAG_ADDED & sflag))
1132 * the source was removed. use the next best.
1134 return (fib_entry_source_removed(fib_entry, bflags));
1139 * re-install the new forwarding information
1141 fib_entry_src_action_reactivate(fib_entry, source);
1146 fib_entry_post_update_actions(fib_entry, source, bflags);
1149 * still have sources
1151 return (FIB_ENTRY_SRC_FLAG_ADDED);
1157 * If the source on the cover is inheriting then push this source
1158 * down to the covered.
1161 fib_entry_inherit (fib_node_index_t cover,
1162 fib_node_index_t covered)
1164 fib_entry_src_inherit(fib_entry_get(cover),
1165 fib_entry_get(covered));
1171 * The source is withdrawing all the paths it provided
1173 fib_entry_src_flag_t
1174 fib_entry_delete (fib_node_index_t fib_entry_index,
1175 fib_source_t source)
1177 return (fib_entry_special_remove(fib_entry_index, source));
1183 * The source has provided a new set of paths that will replace the old.
1186 fib_entry_update (fib_node_index_t fib_entry_index,
1187 fib_source_t source,
1188 fib_entry_flag_t flags,
1189 const fib_route_path_t *paths)
1191 fib_source_t best_source;
1192 fib_entry_flag_t bflags;
1193 fib_entry_t *fib_entry;
1194 fib_entry_src_t *bsrc;
1196 fib_entry = fib_entry_get(fib_entry_index);
1197 ASSERT(NULL != fib_entry);
1199 bsrc = fib_entry_get_best_src_i(fib_entry);
1200 best_source = fib_entry_src_get_source(bsrc);
1201 bflags = fib_entry_get_flags_i(fib_entry);
1203 fib_entry = fib_entry_src_action_path_swap(fib_entry,
1208 fib_entry_source_change_w_flags(fib_entry, best_source, bflags, source);
1209 FIB_ENTRY_DBG(fib_entry, "update");
1214 * fib_entry_cover_changed
1216 * this entry is tracking its cover and that cover has changed.
1219 fib_entry_cover_changed (fib_node_index_t fib_entry_index)
1221 fib_entry_src_cover_res_t res = {
1223 .bw_reason = FIB_NODE_BW_REASON_FLAG_NONE,
1225 CLIB_UNUSED(fib_source_t source);
1226 fib_source_t best_source;
1227 fib_entry_flag_t bflags;
1228 fib_entry_t *fib_entry;
1229 fib_entry_src_t *esrc;
1232 bflags = FIB_ENTRY_FLAG_NONE;
1233 best_source = FIB_SOURCE_FIRST;
1234 fib_entry = fib_entry_get(fib_entry_index);
1236 fib_attached_export_cover_change(fib_entry);
1239 * propagate the notification to each of the added sources
1242 FOR_EACH_SRC_ADDED(fib_entry, esrc, source,
1247 * only the best source gets to set the back walk flags
1249 res = fib_entry_src_action_cover_change(fib_entry, esrc);
1250 bflags = fib_entry_src_get_flags(esrc);
1251 best_source = fib_entry_src_get_source(esrc);
1255 fib_entry_src_action_cover_change(fib_entry, esrc);
1262 fib_entry_src_action_reactivate(fib_entry,
1263 fib_entry_src_get_source(
1264 fib_entry_get_best_src_i(fib_entry)));
1265 fib_entry = fib_entry_post_install_actions(fib_entry,
1271 fib_entry_src_action_uninstall(fib_entry);
1274 if (FIB_NODE_BW_REASON_FLAG_NONE != res.bw_reason)
1277 * time for walkies fido.
1279 fib_node_back_walk_ctx_t bw_ctx = {
1280 .fnbw_reason = res.bw_reason,
1283 fib_walk_sync(FIB_NODE_TYPE_ENTRY, fib_entry_index, &bw_ctx);
1285 FIB_ENTRY_DBG(fib_entry, "cover-changed");
1289 * fib_entry_cover_updated
1291 * this entry is tracking its cover and that cover has been updated
1292 * (i.e. its forwarding information has changed).
1295 fib_entry_cover_updated (fib_node_index_t fib_entry_index)
1297 fib_entry_src_cover_res_t res = {
1299 .bw_reason = FIB_NODE_BW_REASON_FLAG_NONE,
1301 CLIB_UNUSED(fib_source_t source);
1302 fib_source_t best_source;
1303 fib_entry_flag_t bflags;
1304 fib_entry_t *fib_entry;
1305 fib_entry_src_t *esrc;
1308 bflags = FIB_ENTRY_FLAG_NONE;
1309 best_source = FIB_SOURCE_FIRST;
1310 fib_entry = fib_entry_get(fib_entry_index);
1312 fib_attached_export_cover_update(fib_entry);
1315 * propagate the notification to each of the added sources
1318 FOR_EACH_SRC_ADDED(fib_entry, esrc, source,
1323 * only the best source gets to set the install result
1325 res = fib_entry_src_action_cover_update(fib_entry, esrc);
1326 bflags = fib_entry_src_get_flags(esrc);
1327 best_source = fib_entry_src_get_source(esrc);
1332 * contirubting sources can set backwalk flags
1334 if (esrc->fes_flags & FIB_ENTRY_SRC_FLAG_CONTRIBUTING)
1336 fib_entry_src_cover_res_t tmp = {
1338 .bw_reason = FIB_NODE_BW_REASON_FLAG_NONE,
1341 tmp = fib_entry_src_action_cover_update(fib_entry, esrc);
1342 res.bw_reason |= tmp.bw_reason;
1346 fib_entry_src_action_cover_update(fib_entry, esrc);
1354 fib_entry_src_action_reactivate(fib_entry,
1355 fib_entry_src_get_source(
1356 fib_entry_get_best_src_i(fib_entry)));
1357 fib_entry = fib_entry_post_install_actions(fib_entry,
1363 fib_entry_src_action_uninstall(fib_entry);
1366 if (FIB_NODE_BW_REASON_FLAG_NONE != res.bw_reason)
1369 * time for walkies fido.
1371 fib_node_back_walk_ctx_t bw_ctx = {
1372 .fnbw_reason = res.bw_reason,
1375 fib_walk_sync(FIB_NODE_TYPE_ENTRY, fib_entry_index, &bw_ctx);
1377 FIB_ENTRY_DBG(fib_entry, "cover-updated");
1381 fib_entry_recursive_loop_detect (fib_node_index_t entry_index,
1382 fib_node_index_t **entry_indicies)
1384 fib_entry_t *fib_entry;
1385 int was_looped, is_looped;
1387 fib_entry = fib_entry_get(entry_index);
1389 if (FIB_NODE_INDEX_INVALID != fib_entry->fe_parent)
1391 fib_node_index_t *entries = *entry_indicies;
1393 vec_add1(entries, entry_index);
1394 was_looped = fib_path_list_is_looped(fib_entry->fe_parent);
1395 is_looped = fib_path_list_recursive_loop_detect(fib_entry->fe_parent,
1398 *entry_indicies = entries;
1400 if (!!was_looped != !!is_looped)
1403 * re-evaluate all the entry's forwarding
1404 * NOTE: this is an inplace modify
1406 fib_entry_delegate_type_t fdt;
1407 fib_entry_delegate_t *fed;
1409 FOR_EACH_DELEGATE_CHAIN(fib_entry, fdt, fed,
1411 fib_entry_src_mk_lb(fib_entry,
1412 fib_entry_get_best_source(entry_index),
1413 fib_entry_delegate_type_to_chain_type(fdt),
1421 * the entry is currently not linked to a path-list. this happens
1422 * when it is this entry that is re-linking path-lists and has thus
1432 * fib_entry_attached_cross_table
1434 * Return true if the route is attached via an interface that
1435 * is not in the same table as the route
1438 fib_entry_attached_cross_table (const fib_entry_t *fib_entry,
1441 const fib_prefix_t *pfx = &fib_entry->fe_prefix;
1443 switch (pfx->fp_proto)
1445 case FIB_PROTOCOL_MPLS:
1446 /* MPLS routes are never imported/exported */
1448 case FIB_PROTOCOL_IP6:
1449 /* Ignore link local addresses these also can't be imported/exported */
1450 if (ip6_address_is_link_local_unicast (&pfx->fp_addr.ip6))
1455 case FIB_PROTOCOL_IP4:
1459 return (fib_entry->fe_fib_index != fib_index);
1463 * fib_entry_back_walk_notify
1465 * A back walk has reach this entry.
1467 static fib_node_back_walk_rc_t
1468 fib_entry_back_walk_notify (fib_node_t *node,
1469 fib_node_back_walk_ctx_t *ctx)
1471 fib_source_t best_source;
1472 fib_entry_t *fib_entry;
1473 fib_entry_src_t *bsrc;
1475 fib_entry = fib_entry_from_fib_node(node);
1476 bsrc = fib_entry_get_best_src_i(fib_entry);
1477 best_source = fib_entry_src_get_source(bsrc);
1479 if (FIB_NODE_BW_REASON_FLAG_INTERFACE_BIND & ctx->fnbw_reason)
1481 fib_entry_flag_t bflags;
1483 bflags = fib_entry_src_get_flags(bsrc);
1485 fib_entry_src_action_reactivate(fib_entry, best_source);
1487 /* re-evaluate whether the prefix is cross table */
1488 if (fib_entry_attached_cross_table(
1489 fib_entry, ctx->interface_bind.fnbw_to_fib_index) &&
1490 !(bsrc->fes_entry_flags & FIB_ENTRY_FLAG_NO_ATTACHED_EXPORT))
1492 bsrc->fes_entry_flags |= FIB_ENTRY_FLAG_IMPORT;
1496 bsrc->fes_entry_flags &= ~FIB_ENTRY_FLAG_IMPORT;
1499 fib_entry = fib_entry_post_flag_update_actions(
1501 ctx->interface_bind.fnbw_to_fib_index);
1503 else if (FIB_NODE_BW_REASON_FLAG_EVALUATE & ctx->fnbw_reason ||
1504 FIB_NODE_BW_REASON_FLAG_ADJ_UPDATE & ctx->fnbw_reason ||
1505 FIB_NODE_BW_REASON_FLAG_ADJ_DOWN & ctx->fnbw_reason ||
1506 FIB_NODE_BW_REASON_FLAG_INTERFACE_UP & ctx->fnbw_reason ||
1507 FIB_NODE_BW_REASON_FLAG_INTERFACE_DOWN & ctx->fnbw_reason ||
1508 FIB_NODE_BW_REASON_FLAG_INTERFACE_BIND & ctx->fnbw_reason ||
1509 FIB_NODE_BW_REASON_FLAG_INTERFACE_DELETE & ctx->fnbw_reason)
1511 fib_entry_src_action_reactivate(fib_entry, best_source);
1515 * all other walk types can be reclassifed to a re-evaluate to
1516 * all recursive dependents.
1517 * By reclassifying we ensure that should any of these walk types meet
1518 * they can be merged.
1520 ctx->fnbw_reason = FIB_NODE_BW_REASON_FLAG_EVALUATE;
1523 * ... and nothing is forced sync from now on.
1525 ctx->fnbw_flags &= ~FIB_NODE_BW_FLAG_FORCE_SYNC;
1527 FIB_ENTRY_DBG(fib_entry, "bw:%U",
1528 format_fib_node_bw_reason, ctx->fnbw_reason);
1531 * propagate the backwalk further if we haven't already reached the
1534 fib_walk_sync(FIB_NODE_TYPE_ENTRY,
1535 fib_entry_get_index(fib_entry),
1538 return (FIB_NODE_BACK_WALK_CONTINUE);
1542 * The FIB path-list's graph node virtual function table
1544 static const fib_node_vft_t fib_entry_vft = {
1545 .fnv_get = fib_entry_get_node,
1546 .fnv_last_lock = fib_entry_last_lock_gone,
1547 .fnv_back_walk = fib_entry_back_walk_notify,
1548 .fnv_mem_show = fib_entry_show_memory,
1552 fib_entry_get_resolving_interface (fib_node_index_t entry_index)
1554 fib_entry_t *fib_entry;
1556 fib_entry = fib_entry_get(entry_index);
1558 return (fib_path_list_get_resolving_interface(fib_entry->fe_parent));
1562 fib_entry_get_any_resolving_interface (fib_node_index_t entry_index)
1564 const fib_entry_src_t *src;
1565 fib_entry_t *fib_entry;
1566 fib_source_t source;
1569 fib_entry = fib_entry_get(entry_index);
1571 FOR_EACH_SRC_ADDED(fib_entry, src, source,
1573 sw_if_index = fib_entry_get_resolving_interface_for_source (entry_index,
1576 if (~0 != sw_if_index)
1579 return (sw_if_index);
1583 fib_entry_get_best_source (fib_node_index_t entry_index)
1585 fib_entry_t *fib_entry;
1586 fib_entry_src_t *bsrc;
1588 fib_entry = fib_entry_get(entry_index);
1590 bsrc = fib_entry_get_best_src_i(fib_entry);
1591 return (fib_entry_src_get_source(bsrc));
1595 * Return !0 is the entry represents a host prefix
1598 fib_entry_is_host (fib_node_index_t fib_entry_index)
1600 return (fib_prefix_is_host(fib_entry_get_prefix(fib_entry_index)));
1604 * Return !0 is the entry is resolved, i.e. will return a valid forwarding
1608 fib_entry_is_resolved (fib_node_index_t fib_entry_index)
1610 fib_entry_delegate_t *fed;
1611 fib_entry_t *fib_entry;
1613 fib_entry = fib_entry_get(fib_entry_index);
1615 fed = fib_entry_delegate_find(fib_entry, FIB_ENTRY_DELEGATE_BFD);
1620 * no BFD tracking - consider it resolved.
1627 * defer to the state of the BFD tracking
1629 return (FIB_BFD_STATE_UP == fed->fd_bfd_state);
1634 fib_entry_set_flow_hash_config (fib_node_index_t fib_entry_index,
1635 flow_hash_config_t hash_config)
1637 fib_entry_t *fib_entry;
1639 fib_entry = fib_entry_get(fib_entry_index);
1642 * pass the hash-config on to the load-balance object where it is cached.
1643 * we can ignore LBs in the delegate chains, since they will not be of the
1644 * correct protocol type (i.e. they are not IP)
1645 * There's no way, nor need, to change the hash config for MPLS.
1647 if (dpo_id_is_valid(&fib_entry->fe_lb))
1651 ASSERT(DPO_LOAD_BALANCE == fib_entry->fe_lb.dpoi_type);
1653 lb = load_balance_get(fib_entry->fe_lb.dpoi_index);
1656 * atomic update for packets in flight
1658 lb->lb_hash_config = hash_config;
1663 fib_entry_get_stats_index (fib_node_index_t fib_entry_index)
1665 fib_entry_t *fib_entry;
1667 fib_entry = fib_entry_get(fib_entry_index);
1669 return (fib_entry->fe_lb.dpoi_index);
1673 fib_ip4_address_compare (const ip4_address_t * a1,
1674 const ip4_address_t * a2)
1677 * IP addresses are unsigned ints. the return value here needs to be signed
1678 * a simple subtraction won't cut it.
1679 * If the addresses are the same, the sort order is undefined, so phoey.
1681 return ((clib_net_to_host_u32(a1->data_u32) >
1682 clib_net_to_host_u32(a2->data_u32) ) ?
1687 fib_ip6_address_compare (const ip6_address_t * a1,
1688 const ip6_address_t * a2)
1691 for (i = 0; i < ARRAY_LEN (a1->as_u16); i++)
1693 int cmp = (clib_net_to_host_u16 (a1->as_u16[i]) -
1694 clib_net_to_host_u16 (a2->as_u16[i]));
1702 fib_entry_cmp (fib_node_index_t fib_entry_index1,
1703 fib_node_index_t fib_entry_index2)
1705 fib_entry_t *fib_entry1, *fib_entry2;
1708 fib_entry1 = fib_entry_get(fib_entry_index1);
1709 fib_entry2 = fib_entry_get(fib_entry_index2);
1711 switch (fib_entry1->fe_prefix.fp_proto)
1713 case FIB_PROTOCOL_IP4:
1714 cmp = fib_ip4_address_compare(&fib_entry1->fe_prefix.fp_addr.ip4,
1715 &fib_entry2->fe_prefix.fp_addr.ip4);
1717 case FIB_PROTOCOL_IP6:
1718 cmp = fib_ip6_address_compare(&fib_entry1->fe_prefix.fp_addr.ip6,
1719 &fib_entry2->fe_prefix.fp_addr.ip6);
1721 case FIB_PROTOCOL_MPLS:
1722 cmp = (fib_entry1->fe_prefix.fp_label - fib_entry2->fe_prefix.fp_label);
1726 cmp = (fib_entry1->fe_prefix.fp_eos - fib_entry2->fe_prefix.fp_eos);
1732 cmp = (fib_entry1->fe_prefix.fp_len - fib_entry2->fe_prefix.fp_len);
1738 fib_entry_cmp_for_sort (void *i1, void *i2)
1740 fib_node_index_t *fib_entry_index1 = i1, *fib_entry_index2 = i2;
1742 return (fib_entry_cmp(*fib_entry_index1,
1743 *fib_entry_index2));
1747 fib_entry_lock (fib_node_index_t fib_entry_index)
1749 fib_entry_t *fib_entry;
1751 fib_entry = fib_entry_get(fib_entry_index);
1753 fib_node_lock(&fib_entry->fe_node);
1757 fib_entry_unlock (fib_node_index_t fib_entry_index)
1759 fib_entry_t *fib_entry;
1761 fib_entry = fib_entry_get(fib_entry_index);
1763 fib_node_unlock(&fib_entry->fe_node);
1767 fib_entry_module_init (void)
1769 fib_node_register_type(FIB_NODE_TYPE_ENTRY, &fib_entry_vft);
1770 fib_entry_logger = vlib_log_register_class("fib", "entry");
1772 fib_entry_track_module_init();
1776 fib_entry_encode (fib_node_index_t fib_entry_index)
1778 fib_path_ext_list_t *ext_list;
1779 fib_path_encode_ctx_t ctx = {
1782 fib_entry_t *fib_entry;
1783 fib_entry_src_t *bsrc;
1786 fib_entry = fib_entry_get(fib_entry_index);
1787 bsrc = fib_entry_get_best_src_i(fib_entry);
1791 ext_list = &bsrc->fes_path_exts;
1794 if (FIB_NODE_INDEX_INVALID != fib_entry->fe_parent)
1796 fib_path_list_walk_w_ext(fib_entry->fe_parent,
1802 return (ctx.rpaths);
1805 const fib_prefix_t *
1806 fib_entry_get_prefix (fib_node_index_t fib_entry_index)
1808 fib_entry_t *fib_entry;
1810 fib_entry = fib_entry_get(fib_entry_index);
1812 return (&fib_entry->fe_prefix);
1816 fib_entry_get_fib_index (fib_node_index_t fib_entry_index)
1818 fib_entry_t *fib_entry;
1820 fib_entry = fib_entry_get(fib_entry_index);
1822 return (fib_entry->fe_fib_index);
1826 fib_entry_pool_size (void)
1828 return (pool_elts(fib_entry_pool));
1833 fib_table_assert_empty (const fib_table_t *fib_table)
1835 fib_node_index_t *fei, *feis = NULL;
1836 fib_entry_t *fib_entry;
1838 pool_foreach (fib_entry, fib_entry_pool)
1840 if (fib_entry->fe_fib_index == fib_table->ft_index)
1841 vec_add1 (feis, fib_entry_get_index(fib_entry));
1846 vec_foreach (fei, feis)
1847 clib_error ("%U", format_fib_entry, *fei, FIB_ENTRY_FORMAT_DETAIL);
1854 static clib_error_t *
1855 show_fib_entry_command (vlib_main_t * vm,
1856 unformat_input_t * input,
1857 vlib_cli_command_t * cmd)
1859 fib_node_index_t fei;
1861 if (unformat (input, "%d", &fei))
1864 * show one in detail
1866 if (!pool_is_free_index(fib_entry_pool, fei))
1868 vlib_cli_output (vm, "%d@%U",
1870 format_fib_entry, fei,
1871 FIB_ENTRY_FORMAT_DETAIL2);
1875 vlib_cli_output (vm, "entry %d invalid", fei);
1883 vlib_cli_output (vm, "FIB Entries:");
1884 pool_foreach_index (fei, fib_entry_pool)
1886 vlib_cli_output (vm, "%d@%U",
1888 format_fib_entry, fei,
1889 FIB_ENTRY_FORMAT_BRIEF);
1896 VLIB_CLI_COMMAND (show_fib_entry, static) = {
1897 .path = "show fib entry",
1898 .function = show_fib_entry_command,
1899 .short_help = "show fib entry",