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>
18 #include <vnet/mfib/mfib_entry.h>
19 #include <vnet/fib/fib_path_list.h>
21 #include <vnet/dpo/drop_dpo.h>
22 #include <vnet/dpo/replicate_dpo.h>
28 #DEFIne MFIB_ENTRY_DBG(_e, _fmt, _args...) \
31 __tmp = format(__tmp, "e:[%d:%U", \
32 mfib_entry_get_index(_e), \
33 format_ip46_address, \
34 &_e->mfe_prefix.fp_grp_addr, \
36 __tmp = format(__tmp, "/%d,", \
37 _e->mfe_prefix.fp_len); \
38 __tmp = format(__tmp, "%U]", \
39 mfib_entry_get_index(_e), \
40 format_ip46_address, \
41 &_e->mfe_prefix.fp_src_addr, \
43 __tmp = format(__tmp, _fmt, ##_args); \
44 clib_warning("%s", __tmp); \
48 #define MFIB_ENTRY_DBG(_e, _fmt, _args...)
52 * The source of an MFIB entry
54 typedef struct mfib_entry_src_t_
57 * Which source this is
59 mfib_source_t mfes_src;
62 * The path-list of forwarding interfaces
64 fib_node_index_t mfes_pl;
69 mfib_entry_flags_t mfes_flags;
72 * The hash table of all interfaces
74 mfib_itf_t *mfes_itfs;
78 * String names for each source
80 static const char *mfib_source_names[] = MFIB_SOURCE_NAMES;
83 * Pool for all fib_entries
85 mfib_entry_t *mfib_entry_pool;
88 mfib_entry_get_node (fib_node_index_t index)
90 return ((fib_node_t*)mfib_entry_get(index));
94 mfib_entry_get_proto (const mfib_entry_t * mfib_entry)
96 return (mfib_entry->mfe_prefix.fp_proto);
99 fib_forward_chain_type_t
100 mfib_entry_get_default_chain_type (const mfib_entry_t *mfib_entry)
102 switch (mfib_entry->mfe_prefix.fp_proto)
104 case FIB_PROTOCOL_IP4:
105 return (FIB_FORW_CHAIN_TYPE_MCAST_IP4);
106 case FIB_PROTOCOL_IP6:
107 return (FIB_FORW_CHAIN_TYPE_MCAST_IP6);
108 case FIB_PROTOCOL_MPLS:
112 return (FIB_FORW_CHAIN_TYPE_MCAST_IP4);
116 format_mfib_entry_dpo (u8 * s, va_list * args)
118 index_t fei = va_arg(*args, index_t);
119 CLIB_UNUSED(u32 indent) = va_arg(*args, u32);
121 return (format(s, "%U",
122 format_mfib_entry, fei,
123 MFIB_ENTRY_FORMAT_BRIEF));
127 format_mfib_entry (u8 * s, va_list * args)
129 fib_node_index_t fei, mfi;
130 mfib_entry_t *mfib_entry;
131 mfib_entry_src_t *msrc;
135 fei = va_arg (*args, fib_node_index_t);
136 level = va_arg (*args, int);
137 mfib_entry = mfib_entry_get(fei);
139 s = format (s, "%U", format_mfib_prefix, &mfib_entry->mfe_prefix);
140 s = format (s, ": %U", format_mfib_entry_flags, mfib_entry->mfe_flags);
142 if (level >= MFIB_ENTRY_FORMAT_DETAIL)
144 s = format (s, "\n");
145 s = format (s, " fib:%d", mfib_entry->mfe_fib_index);
146 s = format (s, " index:%d", mfib_entry_get_index(mfib_entry));
147 s = format (s, " locks:%d\n", mfib_entry->mfe_node.fn_locks);
148 vec_foreach(msrc, mfib_entry->mfe_srcs)
150 s = format (s, " src:%s", mfib_source_names[msrc->mfes_src]);
151 s = format (s, ": %U\n", format_mfib_entry_flags, msrc->mfes_flags);
152 if (FIB_NODE_INDEX_INVALID != msrc->mfes_pl)
154 s = fib_path_list_format(msrc->mfes_pl, s);
156 hash_foreach(sw_if_index, mfi, msrc->mfes_itfs,
158 s = format(s, " %U\n", format_mfib_itf, mfi);
163 s = format(s, "\n Interfaces:");
164 hash_foreach(sw_if_index, mfi, mfib_entry->mfe_itfs,
166 s = format(s, "\n %U", format_mfib_itf, mfi);
169 s = format(s, "\n %U-chain\n %U",
170 format_fib_forw_chain_type,
171 mfib_entry_get_default_chain_type(mfib_entry),
173 &mfib_entry->mfe_rep,
177 if (level >= MFIB_ENTRY_FORMAT_DETAIL2)
179 s = format(s, "\nchildren:");
180 s = fib_node_children_format(mfib_entry->mfe_node.fn_children, s);
187 mfib_entry_from_fib_node (fib_node_t *node)
190 ASSERT(FIB_NODE_TYPE_MFIB_ENTRY == node->fn_type);
192 return ((mfib_entry_t*)node);
196 mfib_entry_src_cmp_for_sort (void * v1,
199 mfib_entry_src_t *esrc1 = v1, *esrc2 = v2;
201 return (esrc1->mfes_src - esrc2->mfes_src);
205 mfib_entry_src_init (mfib_entry_t *mfib_entry,
206 mfib_source_t source)
209 mfib_entry_src_t esrc = {
210 .mfes_pl = FIB_NODE_INDEX_INVALID,
211 .mfes_flags = MFIB_ENTRY_FLAG_NONE,
215 vec_add1(mfib_entry->mfe_srcs, esrc);
216 vec_sort_with_function(mfib_entry->mfe_srcs,
217 mfib_entry_src_cmp_for_sort);
220 static mfib_entry_src_t *
221 mfib_entry_src_find (const mfib_entry_t *mfib_entry,
222 mfib_source_t source,
226 mfib_entry_src_t *esrc;
230 vec_foreach(esrc, mfib_entry->mfe_srcs)
232 if (esrc->mfes_src == source)
249 static mfib_entry_src_t *
250 mfib_entry_src_find_or_create (mfib_entry_t *mfib_entry,
251 mfib_source_t source)
253 mfib_entry_src_t *esrc;
255 esrc = mfib_entry_src_find(mfib_entry, source, NULL);
259 mfib_entry_src_init(mfib_entry, source);
262 return (mfib_entry_src_find(mfib_entry, source, NULL));
265 static mfib_entry_src_t*
266 mfib_entry_get_best_src (const mfib_entry_t *mfib_entry)
268 mfib_entry_src_t *bsrc;
271 * the enum of sources is deliberately arranged in priority order
273 if (0 == vec_len(mfib_entry->mfe_srcs))
279 bsrc = vec_elt_at_index(mfib_entry->mfe_srcs, 0);
286 mfib_entry_src_flush (mfib_entry_src_t *msrc)
291 hash_foreach(sw_if_index, mfii, msrc->mfes_itfs,
293 mfib_itf_delete(mfib_itf_get(mfii));
295 hash_free(msrc->mfes_itfs);
296 msrc->mfes_itfs = NULL;
297 fib_path_list_unlock(msrc->mfes_pl);
301 mfib_entry_src_remove (mfib_entry_t *mfib_entry,
302 mfib_source_t source)
305 mfib_entry_src_t *msrc;
308 msrc = mfib_entry_src_find(mfib_entry, source, &index);
312 mfib_entry_src_flush(msrc);
313 vec_del1(mfib_entry->mfe_srcs, index);
318 mfib_entry_src_n_itfs (const mfib_entry_src_t *msrc)
320 return (hash_elts(msrc->mfes_itfs));
325 mfib_entry_last_lock_gone (fib_node_t *node)
327 mfib_entry_t *mfib_entry;
328 mfib_entry_src_t *msrc;
330 mfib_entry = mfib_entry_from_fib_node(node);
332 dpo_reset(&mfib_entry->mfe_rep);
334 MFIB_ENTRY_DBG(mfib_entry, "last-lock");
336 vec_foreach(msrc, mfib_entry->mfe_srcs)
338 mfib_entry_src_flush(msrc);
341 fib_path_list_unlock(mfib_entry->mfe_parent);
342 vec_free(mfib_entry->mfe_srcs);
344 fib_node_deinit(&mfib_entry->mfe_node);
345 pool_put(mfib_entry_pool, mfib_entry);
349 * mfib_entry_back_walk_notify
351 * A back walk has reach this entry.
353 static fib_node_back_walk_rc_t
354 mfib_entry_back_walk_notify (fib_node_t *node,
355 fib_node_back_walk_ctx_t *ctx)
357 // FIXME - re-evalute
359 return (FIB_NODE_BACK_WALK_CONTINUE);
363 mfib_entry_show_memory (void)
365 fib_show_memory_usage("multicast-Entry",
366 pool_elts(mfib_entry_pool),
367 pool_len(mfib_entry_pool),
368 sizeof(mfib_entry_t));
372 * The MFIB entry's graph node virtual function table
374 static const fib_node_vft_t mfib_entry_vft = {
375 .fnv_get = mfib_entry_get_node,
376 .fnv_last_lock = mfib_entry_last_lock_gone,
377 .fnv_back_walk = mfib_entry_back_walk_notify,
378 .fnv_mem_show = mfib_entry_show_memory,
382 mfib_entry_child_add (fib_node_index_t mfib_entry_index,
383 fib_node_type_t child_type,
384 fib_node_index_t child_index)
386 return (fib_node_child_add(FIB_NODE_TYPE_MFIB_ENTRY,
393 mfib_entry_child_remove (fib_node_index_t mfib_entry_index,
396 fib_node_child_remove(FIB_NODE_TYPE_MFIB_ENTRY,
401 static mfib_entry_t *
402 mfib_entry_alloc (u32 fib_index,
403 const mfib_prefix_t *prefix,
404 fib_node_index_t *mfib_entry_index)
406 mfib_entry_t *mfib_entry;
408 pool_get(mfib_entry_pool, mfib_entry);
410 fib_node_init(&mfib_entry->mfe_node,
411 FIB_NODE_TYPE_MFIB_ENTRY);
414 * Some of the members require non-default initialisation
415 * so we also init those that don't and thus save on the call to memset.
417 mfib_entry->mfe_flags = 0;
418 mfib_entry->mfe_fib_index = fib_index;
419 mfib_entry->mfe_prefix = *prefix;
420 mfib_entry->mfe_parent = FIB_NODE_INDEX_INVALID;
421 mfib_entry->mfe_sibling = FIB_NODE_INDEX_INVALID;
422 mfib_entry->mfe_srcs = NULL;
423 mfib_entry->mfe_itfs = NULL;
425 dpo_reset(&mfib_entry->mfe_rep);
427 *mfib_entry_index = mfib_entry_get_index(mfib_entry);
429 MFIB_ENTRY_DBG(mfib_entry, "alloc");
434 typedef struct mfib_entry_collect_forwarding_ctx_t_
436 load_balance_path_t * next_hops;
437 fib_forward_chain_type_t fct;
438 } mfib_entry_collect_forwarding_ctx_t;
441 mfib_entry_src_collect_forwarding (fib_node_index_t pl_index,
442 fib_node_index_t path_index,
445 mfib_entry_collect_forwarding_ctx_t *ctx;
446 load_balance_path_t *nh;
451 * if the path is not resolved, don't include it.
453 if (!fib_path_is_resolved(path_index))
460 case FIB_FORW_CHAIN_TYPE_MCAST_IP4:
461 case FIB_FORW_CHAIN_TYPE_MCAST_IP6:
463 * EOS traffic with no label to stack, we need the IP Adj
465 vec_add2(ctx->next_hops, nh, 1);
467 nh->path_index = path_index;
468 nh->path_weight = fib_path_get_weight(path_index);
469 fib_path_contribute_forwarding(path_index, ctx->fct, &nh->path_dpo);
472 case FIB_FORW_CHAIN_TYPE_UNICAST_IP4:
473 case FIB_FORW_CHAIN_TYPE_UNICAST_IP6:
474 case FIB_FORW_CHAIN_TYPE_MPLS_NON_EOS:
475 case FIB_FORW_CHAIN_TYPE_MPLS_EOS:
476 case FIB_FORW_CHAIN_TYPE_ETHERNET:
477 case FIB_FORW_CHAIN_TYPE_NSH:
486 mfib_entry_stack (mfib_entry_t *mfib_entry)
490 dp = fib_proto_to_dpo(mfib_entry_get_proto(mfib_entry));
492 if (FIB_NODE_INDEX_INVALID != mfib_entry->mfe_parent)
494 mfib_entry_collect_forwarding_ctx_t ctx = {
496 .fct = mfib_entry_get_default_chain_type(mfib_entry),
499 fib_path_list_walk(mfib_entry->mfe_parent,
500 mfib_entry_src_collect_forwarding,
503 if (!(MFIB_ENTRY_FLAG_EXCLUSIVE & mfib_entry->mfe_flags))
506 * each path contirbutes a next-hop. form a replicate
507 * from those choices.
509 if (!dpo_id_is_valid(&mfib_entry->mfe_rep) ||
510 dpo_is_drop(&mfib_entry->mfe_rep))
512 dpo_id_t tmp_dpo = DPO_INVALID;
516 replicate_create(0, dp));
518 dpo_stack(DPO_MFIB_ENTRY, dp,
519 &mfib_entry->mfe_rep,
524 replicate_multipath_update(&mfib_entry->mfe_rep,
530 * for exclusive routes the source provided a replicate DPO
531 * we we stashed inthe special path list with one path
532 * so we can stack directly on that.
534 ASSERT(1 == vec_len(ctx.next_hops));
536 dpo_stack(DPO_MFIB_ENTRY, dp,
537 &mfib_entry->mfe_rep,
538 &ctx.next_hops[0].path_dpo);
539 dpo_reset(&ctx.next_hops[0].path_dpo);
540 vec_free(ctx.next_hops);
545 dpo_stack(DPO_MFIB_ENTRY, dp,
546 &mfib_entry->mfe_rep,
552 mfib_entry_forwarding_path_add (mfib_entry_src_t *msrc,
553 const fib_route_path_t *rpath)
555 fib_node_index_t old_pl_index;
556 fib_route_path_t *rpaths;
558 ASSERT(!(MFIB_ENTRY_FLAG_EXCLUSIVE & msrc->mfes_flags));
561 * path-lists require a vector of paths
564 vec_add1(rpaths, rpath[0]);
566 old_pl_index = msrc->mfes_pl;
568 if (FIB_NODE_INDEX_INVALID == msrc->mfes_pl)
571 fib_path_list_create(FIB_PATH_LIST_FLAG_NO_URPF,
577 fib_path_list_copy_and_path_add(msrc->mfes_pl,
578 FIB_PATH_LIST_FLAG_NO_URPF,
581 fib_path_list_lock(msrc->mfes_pl);
582 fib_path_list_unlock(old_pl_index);
588 mfib_entry_forwarding_path_remove (mfib_entry_src_t *msrc,
589 const fib_route_path_t *rpath)
591 fib_node_index_t old_pl_index;
592 fib_route_path_t *rpaths;
594 ASSERT(!(MFIB_ENTRY_FLAG_EXCLUSIVE & msrc->mfes_flags));
597 * path-lists require a vector of paths
600 vec_add1(rpaths, rpath[0]);
602 old_pl_index = msrc->mfes_pl;
605 fib_path_list_copy_and_path_remove(msrc->mfes_pl,
606 FIB_PATH_LIST_FLAG_NONE,
609 fib_path_list_lock(msrc->mfes_pl);
610 fib_path_list_unlock(old_pl_index);
614 return (FIB_NODE_INDEX_INVALID != msrc->mfes_pl);
618 mfib_entry_recalculate_forwarding (mfib_entry_t *mfib_entry)
620 fib_node_index_t old_pl_index;
621 mfib_entry_src_t *bsrc;
623 old_pl_index = mfib_entry->mfe_parent;
626 * copy the forwarding data from the bast source
628 bsrc = mfib_entry_get_best_src(mfib_entry);
632 mfib_entry->mfe_parent = FIB_NODE_INDEX_INVALID;
636 mfib_entry->mfe_parent = bsrc->mfes_pl;
637 mfib_entry->mfe_flags = bsrc->mfes_flags;
638 mfib_entry->mfe_itfs = bsrc->mfes_itfs;
642 * re-stack the entry on the best forwarding info.
644 if (old_pl_index != mfib_entry->mfe_parent ||
645 FIB_NODE_INDEX_INVALID == old_pl_index)
647 mfib_entry_stack(mfib_entry);
649 fib_path_list_lock(mfib_entry->mfe_parent);
650 fib_path_list_unlock(old_pl_index);
656 mfib_entry_create (u32 fib_index,
657 mfib_source_t source,
658 const mfib_prefix_t *prefix,
659 mfib_entry_flags_t entry_flags)
661 fib_node_index_t mfib_entry_index;
662 mfib_entry_t *mfib_entry;
663 mfib_entry_src_t *msrc;
665 mfib_entry = mfib_entry_alloc(fib_index, prefix,
667 msrc = mfib_entry_src_find_or_create(mfib_entry, source);
668 msrc->mfes_flags = entry_flags;
670 mfib_entry_recalculate_forwarding(mfib_entry);
672 return (mfib_entry_index);
676 mfib_entry_ok_for_delete (mfib_entry_t *mfib_entry)
678 return (0 == vec_len(mfib_entry->mfe_srcs));
682 mfib_entry_src_ok_for_delete (const mfib_entry_src_t *msrc)
684 return ((MFIB_ENTRY_FLAG_NONE == msrc->mfes_flags &&
685 0 == mfib_entry_src_n_itfs(msrc)));
689 mfib_entry_update (fib_node_index_t mfib_entry_index,
690 mfib_source_t source,
691 mfib_entry_flags_t entry_flags,
694 mfib_entry_t *mfib_entry;
695 mfib_entry_src_t *msrc;
697 mfib_entry = mfib_entry_get(mfib_entry_index);
698 msrc = mfib_entry_src_find_or_create(mfib_entry, source);
699 msrc->mfes_flags = entry_flags;
701 if (INDEX_INVALID != repi)
704 * The source is providing its own replicate DPO.
705 * Create a sepcial path-list to manage it, that way
706 * this entry and the source are equivalent to a normal
709 fib_node_index_t old_pl_index;
711 dpo_id_t dpo = DPO_INVALID;
713 fp = mfib_entry_get_proto(mfib_entry);
714 old_pl_index = msrc->mfes_pl;
716 dpo_set(&dpo, DPO_REPLICATE,
717 fib_proto_to_dpo(fp),
721 fib_path_list_create_special(fp,
722 FIB_PATH_LIST_FLAG_EXCLUSIVE,
726 fib_path_list_lock(msrc->mfes_pl);
727 fib_path_list_unlock(old_pl_index);
730 if (mfib_entry_src_ok_for_delete(msrc))
733 * this source has no interfaces and no flags.
734 * it has nothing left to give - remove it
736 mfib_entry_src_remove(mfib_entry, source);
739 mfib_entry_recalculate_forwarding(mfib_entry);
741 return (mfib_entry_ok_for_delete(mfib_entry));
745 mfib_entry_itf_add (mfib_entry_src_t *msrc,
749 hash_set(msrc->mfes_itfs, sw_if_index, mi);
753 mfib_entry_itf_remove (mfib_entry_src_t *msrc,
758 mfi = mfib_entry_itf_find(msrc->mfes_itfs, sw_if_index);
760 mfib_itf_delete(mfi);
762 hash_unset(msrc->mfes_itfs, sw_if_index);
766 mfib_entry_path_update (fib_node_index_t mfib_entry_index,
767 mfib_source_t source,
768 const fib_route_path_t *rpath,
769 mfib_itf_flags_t itf_flags)
771 mfib_entry_t *mfib_entry;
772 mfib_entry_src_t *msrc;
773 mfib_itf_t *mfib_itf;
775 mfib_entry = mfib_entry_get(mfib_entry_index);
776 ASSERT(NULL != mfib_entry);
777 msrc = mfib_entry_src_find_or_create(mfib_entry, source);
780 * search for the interface in the current set
782 mfib_itf = mfib_entry_itf_find(msrc->mfes_itfs,
783 rpath[0].frp_sw_if_index);
785 if (NULL == mfib_itf)
788 * this is a path we do not yet have. If it is forwarding then we
789 * add it to the replication set
791 if (itf_flags & MFIB_ITF_FLAG_FORWARD)
793 mfib_entry_forwarding_path_add(msrc, rpath);
796 * construct a new ITF for this entry's list
798 mfib_entry_itf_add(msrc,
799 rpath[0].frp_sw_if_index,
800 mfib_itf_create(rpath[0].frp_sw_if_index,
805 int was_forwarding = !!(mfib_itf->mfi_flags & MFIB_ITF_FLAG_FORWARD);
806 int is_forwarding = !!(itf_flags & MFIB_ITF_FLAG_FORWARD);
808 if (!was_forwarding && is_forwarding)
810 mfib_entry_forwarding_path_add(msrc, rpath);
812 else if (was_forwarding && !is_forwarding)
814 mfib_entry_forwarding_path_remove(msrc, rpath);
817 * packets in flight see these updates.
819 mfib_itf->mfi_flags = itf_flags;
822 mfib_entry_recalculate_forwarding(mfib_entry);
826 * mfib_entry_path_remove
828 * remove a path from the entry.
829 * return the mfib_entry's index if it is still present, INVALID otherwise.
832 mfib_entry_path_remove (fib_node_index_t mfib_entry_index,
833 mfib_source_t source,
834 const fib_route_path_t *rpath)
836 mfib_entry_t *mfib_entry;
837 mfib_entry_src_t *msrc;
838 mfib_itf_t *mfib_itf;
840 mfib_entry = mfib_entry_get(mfib_entry_index);
841 ASSERT(NULL != mfib_entry);
842 msrc = mfib_entry_src_find(mfib_entry, source, NULL);
847 * there are no paths left for this source
849 return (mfib_entry_ok_for_delete(mfib_entry));
853 * search for the interface in the current set
855 mfib_itf = mfib_entry_itf_find(msrc->mfes_itfs,
856 rpath[0].frp_sw_if_index);
858 if (NULL == mfib_itf)
861 * removing a path that does not exist
863 return (mfib_entry_ok_for_delete(mfib_entry));
867 * we have this path. If it is forwarding then we
868 * remove it to the replication set
870 if (mfib_itf->mfi_flags & MFIB_ITF_FLAG_FORWARD)
872 mfib_entry_forwarding_path_remove(msrc, rpath);
876 * remove the interface/path from this entry's list
878 mfib_entry_itf_remove(msrc, rpath[0].frp_sw_if_index);
880 if (mfib_entry_src_ok_for_delete(msrc))
883 * this source has no interfaces and no flags.
884 * it has nothing left to give - remove it
886 mfib_entry_src_remove(mfib_entry, source);
889 mfib_entry_recalculate_forwarding(mfib_entry);
891 return (mfib_entry_ok_for_delete(mfib_entry));
897 * The source is withdrawing all the paths it provided
900 mfib_entry_delete (fib_node_index_t mfib_entry_index,
901 mfib_source_t source)
903 mfib_entry_t *mfib_entry;
905 mfib_entry = mfib_entry_get(mfib_entry_index);
906 mfib_entry_src_remove(mfib_entry, source);
908 mfib_entry_recalculate_forwarding(mfib_entry);
910 return (mfib_entry_ok_for_delete(mfib_entry));
914 fib_ip4_address_compare (ip4_address_t * a1,
918 * IP addresses are unsiged ints. the return value here needs to be signed
919 * a simple subtraction won't cut it.
920 * If the addresses are the same, the sort order is undefiend, so phoey.
922 return ((clib_net_to_host_u32(a1->data_u32) >
923 clib_net_to_host_u32(a2->data_u32) ) ?
928 fib_ip6_address_compare (ip6_address_t * a1,
932 for (i = 0; i < ARRAY_LEN (a1->as_u16); i++)
934 int cmp = (clib_net_to_host_u16 (a1->as_u16[i]) -
935 clib_net_to_host_u16 (a2->as_u16[i]));
943 mfib_entry_cmp (fib_node_index_t mfib_entry_index1,
944 fib_node_index_t mfib_entry_index2)
946 mfib_entry_t *mfib_entry1, *mfib_entry2;
949 mfib_entry1 = mfib_entry_get(mfib_entry_index1);
950 mfib_entry2 = mfib_entry_get(mfib_entry_index2);
952 switch (mfib_entry1->mfe_prefix.fp_proto)
954 case FIB_PROTOCOL_IP4:
955 cmp = fib_ip4_address_compare(&mfib_entry1->mfe_prefix.fp_grp_addr.ip4,
956 &mfib_entry2->mfe_prefix.fp_grp_addr.ip4);
960 cmp = fib_ip4_address_compare(&mfib_entry1->mfe_prefix.fp_src_addr.ip4,
961 &mfib_entry2->mfe_prefix.fp_src_addr.ip4);
964 case FIB_PROTOCOL_IP6:
965 cmp = fib_ip6_address_compare(&mfib_entry1->mfe_prefix.fp_grp_addr.ip6,
966 &mfib_entry2->mfe_prefix.fp_grp_addr.ip6);
970 cmp = fib_ip6_address_compare(&mfib_entry1->mfe_prefix.fp_src_addr.ip6,
971 &mfib_entry2->mfe_prefix.fp_src_addr.ip6);
974 case FIB_PROTOCOL_MPLS:
981 cmp = (mfib_entry1->mfe_prefix.fp_len - mfib_entry2->mfe_prefix.fp_len);
987 mfib_entry_cmp_for_sort (void *i1, void *i2)
989 fib_node_index_t *mfib_entry_index1 = i1, *mfib_entry_index2 = i2;
991 return (mfib_entry_cmp(*mfib_entry_index1,
992 *mfib_entry_index2));
996 mfib_entry_lock (fib_node_index_t mfib_entry_index)
998 mfib_entry_t *mfib_entry;
1000 mfib_entry = mfib_entry_get(mfib_entry_index);
1002 fib_node_lock(&mfib_entry->mfe_node);
1006 mfib_entry_unlock (fib_node_index_t mfib_entry_index)
1008 mfib_entry_t *mfib_entry;
1010 mfib_entry = mfib_entry_get(mfib_entry_index);
1012 fib_node_unlock(&mfib_entry->mfe_node);
1016 mfib_entry_dpo_lock (dpo_id_t *dpo)
1020 mfib_entry_dpo_unlock (dpo_id_t *dpo)
1024 const static dpo_vft_t mfib_entry_dpo_vft = {
1025 .dv_lock = mfib_entry_dpo_lock,
1026 .dv_unlock = mfib_entry_dpo_unlock,
1027 .dv_format = format_mfib_entry_dpo,
1028 .dv_mem_show = mfib_entry_show_memory,
1031 const static char* const mfib_entry_ip4_nodes[] =
1033 "ip4-mfib-forward-rpf",
1036 const static char* const mfib_entry_ip6_nodes[] =
1038 "ip6-mfib-forward-rpf",
1042 const static char* const * const mfib_entry_nodes[DPO_PROTO_NUM] =
1044 [DPO_PROTO_IP4] = mfib_entry_ip4_nodes,
1045 [DPO_PROTO_IP6] = mfib_entry_ip6_nodes,
1049 mfib_entry_module_init (void)
1051 fib_node_register_type (FIB_NODE_TYPE_MFIB_ENTRY, &mfib_entry_vft);
1052 dpo_register(DPO_MFIB_ENTRY, &mfib_entry_dpo_vft, mfib_entry_nodes);
1056 mfib_entry_encode (fib_node_index_t mfib_entry_index,
1057 fib_route_path_encode_t **api_rpaths)
1059 mfib_entry_t *mfib_entry;
1061 mfib_entry = mfib_entry_get(mfib_entry_index);
1062 if (FIB_NODE_INDEX_INVALID != mfib_entry->mfe_parent)
1064 fib_path_list_walk(mfib_entry->mfe_parent,
1072 mfib_entry_get_prefix (fib_node_index_t mfib_entry_index,
1075 mfib_entry_t *mfib_entry;
1077 mfib_entry = mfib_entry_get(mfib_entry_index);
1078 *pfx = mfib_entry->mfe_prefix;
1082 mfib_entry_get_fib_index (fib_node_index_t mfib_entry_index)
1084 mfib_entry_t *mfib_entry;
1086 mfib_entry = mfib_entry_get(mfib_entry_index);
1088 return (mfib_entry->mfe_fib_index);
1092 mfib_entry_contribute_forwarding (fib_node_index_t mfib_entry_index,
1093 fib_forward_chain_type_t type,
1097 * An IP mFIB entry can only provide a forwarding chain that
1098 * is the same IP proto as the prefix.
1099 * No use-cases (i know of) for other combinations.
1101 mfib_entry_t *mfib_entry;
1104 mfib_entry = mfib_entry_get(mfib_entry_index);
1106 dp = fib_proto_to_dpo(mfib_entry->mfe_prefix.fp_proto);
1108 if (type == fib_forw_chain_type_from_dpo_proto(dp))
1110 dpo_copy(dpo, &mfib_entry->mfe_rep);
1114 dpo_copy(dpo, drop_dpo_get(dp));
1119 mfib_entry_pool_size (void)
1121 return (pool_elts(mfib_entry_pool));
1124 static clib_error_t *
1125 show_mfib_entry_command (vlib_main_t * vm,
1126 unformat_input_t * input,
1127 vlib_cli_command_t * cmd)
1129 fib_node_index_t fei;
1131 if (unformat (input, "%d", &fei))
1134 * show one in detail
1136 if (!pool_is_free_index(mfib_entry_pool, fei))
1138 vlib_cli_output (vm, "%d@%U",
1140 format_mfib_entry, fei,
1141 MFIB_ENTRY_FORMAT_DETAIL2);
1145 vlib_cli_output (vm, "entry %d invalid", fei);
1153 vlib_cli_output (vm, "FIB Entries:");
1154 pool_foreach_index(fei, mfib_entry_pool,
1156 vlib_cli_output (vm, "%d@%U",
1158 format_mfib_entry, fei,
1159 MFIB_ENTRY_FORMAT_BRIEF);
1167 * This commnad displays an entry, or all entries, in the mfib tables indexed by their unique
1168 * numerical indentifier.
1170 VLIB_CLI_COMMAND (show_mfib_entry, static) = {
1171 .path = "show mfib entry",
1172 .function = show_mfib_entry_command,
1173 .short_help = "show mfib entry",