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 <vppinfra/mhash.h>
17 #include <vnet/ip/ip.h>
18 #include <vnet/adj/adj.h>
19 #include <vnet/dpo/load_balance.h>
20 #include <vnet/dpo/load_balance_map.h>
22 #include <vnet/fib/fib_path_list.h>
23 #include <vnet/fib/fib_internal.h>
24 #include <vnet/fib/fib_node_list.h>
25 #include <vnet/fib/fib_walk.h>
29 * A representation of the list/set of path trough which a prefix is reachable
31 typedef struct fib_path_list_t_ {
33 * A path-list is a node in the FIB graph.
38 * Flags on the path-list
40 fib_path_list_flags_t fpl_flags;
43 * The next-hop protocol for the paths in this path list.
44 * Note that fixing the proto here means we don't support a mix of
45 * v4 and v6 paths. ho hum.
47 fib_protocol_t fpl_nh_proto;
50 * Vector of paths indecies for all configured paths.
51 * For shareable path-lists this list MUST not change.
53 fib_node_index_t *fpl_paths;
57 * Array of strings/names for the FIB sources
59 static const char *fib_path_list_attr_names[] = FIB_PATH_LIST_ATTRIBUTES;
62 * The memory pool from which we allocate all the path-lists
64 static fib_path_list_t * fib_path_list_pool;
67 * The data-base of shared path-lists
69 static uword *fib_path_list_db;
75 #define FIB_PATH_LIST_DBG(_pl, _fmt, _args...) \
78 _tmp = fib_path_list_format( \
79 fib_path_list_get_index(_pl), _tmp); \
80 clib_warning("pl:[%d:%p:%p:%s]:" _fmt, \
81 fib_path_list_get_index(_pl), \
82 _pl, _pl->fpl_paths, _tmp, \
87 #define FIB_PATH_LIST_DBG(_pl, _fmt, _args...)
90 static fib_path_list_t *
91 fib_path_list_get (fib_node_index_t index)
93 return (pool_elt_at_index(fib_path_list_pool, index));
97 fib_path_list_get_node (fib_node_index_t index)
99 return ((fib_node_t*)fib_path_list_get(index));
102 static fib_path_list_t*
103 fib_path_list_from_fib_node (fib_node_t *node)
106 ASSERT(FIB_NODE_TYPE_PATH_LIST == node->fn_type);
108 return ((fib_path_list_t*)node);
111 static fib_node_index_t
112 fib_path_list_get_index (fib_path_list_t *path_list)
114 return (path_list - fib_path_list_pool);
118 format_fib_path_list (u8 * s, va_list * args)
120 fib_path_list_attribute_t attr;
121 fib_node_index_t *path_index;
122 fib_path_list_t *path_list;
124 path_list = va_arg (*args, fib_path_list_t *);
126 s = format (s, " index:%u", fib_path_list_get_index(path_list));
127 s = format (s, " locks:%u", path_list->fpl_node.fn_locks);
128 s = format (s, " proto:%U", format_fib_protocol, path_list->fpl_nh_proto);
130 if (FIB_PATH_LIST_FLAG_NONE != path_list->fpl_flags)
132 s = format (s, " flags:");
133 FOR_EACH_PATH_LIST_ATTRIBUTE(attr)
135 if ((1<<attr) & path_list->fpl_flags)
137 s = format (s, "%s,", fib_path_list_attr_names[attr]);
141 vec_foreach (path_index, path_list->fpl_paths)
143 s = fib_path_format(*path_index, s);
151 fib_path_list_adjs_format (fib_node_index_t path_list_index,
155 fib_path_list_t *path_list;
158 path_list = fib_path_list_get(path_list_index);
160 vec_foreach_index (i, path_list->fpl_paths)
162 s = fib_path_adj_format(path_list->fpl_paths[i],
171 fib_path_list_format (fib_node_index_t path_list_index,
174 fib_path_list_t *path_list;
176 path_list = fib_path_list_get(path_list_index);
178 return (format(s, "%U", format_fib_path_list, path_list));
182 fib_path_list_hash (fib_path_list_t *path_list)
184 uword old_path_list_hash, new_path_list_hash, path_hash;
185 fib_node_index_t *path_index;
189 new_path_list_hash = old_path_list_hash = vec_len(path_list->fpl_paths);
191 vec_foreach (path_index, path_list->fpl_paths)
193 path_hash = fib_path_hash(*path_index);
195 hash_mix64(path_hash, old_path_list_hash, new_path_list_hash);
197 hash_mix32(path_hash, old_path_list_hash, new_path_list_hash);
201 return (new_path_list_hash);
205 fib_path_list_db_hash_key_from_index (uword index)
211 fib_path_list_db_hash_key_is_index (uword key)
217 fib_path_list_db_hash_key_2_index (uword key)
219 ASSERT (fib_path_list_db_hash_key_is_index (key));
223 static fib_path_list_t*
224 fib_path_list_db_get_from_hash_key (uword key)
226 fib_path_list_t *path_list;
228 if (fib_path_list_db_hash_key_is_index (key))
230 fib_node_index_t path_list_index;
232 path_list_index = fib_path_list_db_hash_key_2_index(key);
233 path_list = fib_path_list_get(path_list_index);
237 path_list = uword_to_pointer (key, fib_path_list_t *);
244 fib_path_list_db_hash_key_sum (hash_t * h,
247 fib_path_list_t *path_list;
249 path_list = fib_path_list_db_get_from_hash_key(key);
251 return (fib_path_list_hash(path_list));
255 fib_path_list_db_hash_key_equal (hash_t * h,
259 fib_path_list_t *path_list1, *path_list2;
261 path_list1 = fib_path_list_db_get_from_hash_key(key1);
262 path_list2 = fib_path_list_db_get_from_hash_key(key2);
264 return (fib_path_list_hash(path_list1) ==
265 fib_path_list_hash(path_list2));
268 static fib_node_index_t
269 fib_path_list_db_find (fib_path_list_t *path_list)
273 p = hash_get(fib_path_list_db, path_list);
280 return (FIB_NODE_INDEX_INVALID);
284 fib_path_list_db_insert (fib_node_index_t path_list_index)
286 fib_path_list_t *path_list;
288 path_list = fib_path_list_get(path_list_index);
290 ASSERT(FIB_NODE_INDEX_INVALID == fib_path_list_db_find(path_list));
292 hash_set (fib_path_list_db,
293 fib_path_list_db_hash_key_from_index(path_list_index),
296 FIB_PATH_LIST_DBG(path_list, "DB-inserted");
300 fib_path_list_db_remove (fib_node_index_t path_list_index)
302 fib_path_list_t *path_list;
304 path_list = fib_path_list_get(path_list_index);
306 ASSERT(FIB_NODE_INDEX_INVALID != fib_path_list_db_find(path_list));
308 hash_unset(fib_path_list_db,
309 fib_path_list_db_hash_key_from_index(path_list_index));
311 FIB_PATH_LIST_DBG(path_list, "DB-removed");
315 fib_path_list_destroy (fib_path_list_t *path_list)
317 fib_node_index_t *path_index;
319 FIB_PATH_LIST_DBG(path_list, "destroy");
321 vec_foreach (path_index, path_list->fpl_paths)
323 fib_path_destroy(*path_index);
326 vec_free(path_list->fpl_paths);
328 fib_node_deinit(&path_list->fpl_node);
329 pool_put(fib_path_list_pool, path_list);
333 fib_path_list_last_lock_gone (fib_node_t *node)
335 fib_path_list_t *path_list;
337 path_list = fib_path_list_from_fib_node(node);
339 FIB_PATH_LIST_DBG(path_list, "last-lock");
341 if (path_list->fpl_flags & FIB_PATH_LIST_FLAG_SHARED)
343 fib_path_list_db_remove(fib_path_list_get_index(path_list));
345 fib_path_list_destroy(path_list);
351 * update the multipath adj this path-list will contribute to its
352 * children's forwarding.
355 fib_path_list_mk_lb (fib_path_list_t *path_list,
356 fib_forward_chain_type_t fct,
359 load_balance_path_t *hash_key;
360 fib_node_index_t *path_index;
364 if (!dpo_id_is_valid(dpo))
371 fib_forw_chain_type_to_dpo_proto(fct),
372 load_balance_create(0,
373 fib_forw_chain_type_to_dpo_proto(fct),
374 0 /* FIXME FLOW HASH */));
378 * We gather the DPOs from resolved paths.
380 vec_foreach (path_index, path_list->fpl_paths)
382 hash_key = fib_path_append_nh_for_multipath_hash(
389 * Path-list load-balances, which if used, would be shared and hence
390 * never need a load-balance map.
392 load_balance_multipath_update(dpo, hash_key, LOAD_BALANCE_FLAG_NONE);
394 FIB_PATH_LIST_DBG(path_list, "mk lb: %d", dpo->dpoi_index);
400 * fib_path_list_back_walk
402 * Called from one of this path-list's paths to progate
406 fib_path_list_back_walk (fib_node_index_t path_list_index,
407 fib_node_back_walk_ctx_t *ctx)
409 fib_path_list_t *path_list;
411 path_list = fib_path_list_get(path_list_index);
414 * propagate the backwalk further
416 if (32 >= fib_node_list_get_size(path_list->fpl_node.fn_children))
419 * only a few children. continue the walk synchronously
421 fib_walk_sync(FIB_NODE_TYPE_PATH_LIST, path_list_index, ctx);
426 * many children. schedule a async walk
428 fib_walk_async(FIB_NODE_TYPE_PATH_LIST,
430 FIB_WALK_PRIORITY_LOW,
436 * fib_path_list_back_walk_notify
438 * A back walk has reach this path-list.
440 static fib_node_back_walk_rc_t
441 fib_path_list_back_walk_notify (fib_node_t *node,
442 fib_node_back_walk_ctx_t *ctx)
445 * the path-list is not a direct child of any other node type
446 * paths, which do not change thier to-list-mapping, save the
447 * list they are a member of, and invoke the BW function directly.
451 return (FIB_NODE_BACK_WALK_CONTINUE);
455 * The FIB path-list's graph node virtual function table
457 static const fib_node_vft_t fib_path_list_vft = {
458 .fnv_get = fib_path_list_get_node,
459 .fnv_last_lock = fib_path_list_last_lock_gone,
460 .fnv_back_walk = fib_path_list_back_walk_notify,
463 static fib_path_list_t *
464 fib_path_list_alloc (fib_node_index_t *path_list_index)
466 fib_path_list_t *path_list;
468 pool_get(fib_path_list_pool, path_list);
469 memset(path_list, 0, sizeof(*path_list));
471 fib_node_init(&path_list->fpl_node,
472 FIB_NODE_TYPE_PATH_LIST);
474 if (NULL != path_list_index)
476 *path_list_index = fib_path_list_get_index(path_list);
479 FIB_PATH_LIST_DBG(path_list, "alloc");
484 static fib_path_list_t *
485 fib_path_list_resolve (fib_path_list_t *path_list)
487 fib_node_index_t *path_index, *paths, path_list_index;
489 ASSERT(!(path_list->fpl_flags & FIB_PATH_LIST_FLAG_RESOLVED));
492 * resolving a path-list is a recursive action. this means more path
493 * lists can be created during this call, and hence this path-list
494 * can be realloc'd. so we work with copies.
495 * this function is called only once per-path list, so its no great overhead.
497 path_list_index = fib_path_list_get_index(path_list);
498 paths = vec_dup(path_list->fpl_paths);
500 vec_foreach (path_index, paths)
502 fib_path_resolve(*path_index);
506 path_list = fib_path_list_get(path_list_index);
508 FIB_PATH_LIST_DBG(path_list, "resovled");
514 fib_path_list_get_resolving_interface (fib_node_index_t path_list_index)
516 fib_node_index_t *path_index;
517 fib_path_list_t *path_list;
520 path_list = fib_path_list_get(path_list_index);
523 vec_foreach (path_index, path_list->fpl_paths)
525 sw_if_index = fib_path_get_resolving_interface(*path_index);
526 if (~0 != sw_if_index)
528 return (sw_if_index);
532 return (sw_if_index);
536 fib_path_list_is_looped (fib_node_index_t path_list_index)
538 fib_path_list_t *path_list;
540 path_list = fib_path_list_get(path_list_index);
542 return (path_list->fpl_flags & FIB_PATH_LIST_FLAG_LOOPED);
545 static fib_path_cfg_flags_t
546 fib_path_list_flags_2_path_flags (fib_path_list_flags_t plf)
548 fib_path_cfg_flags_t pf = FIB_PATH_CFG_FLAG_NONE;
550 if (plf & FIB_PATH_LIST_FLAG_LOCAL)
552 pf |= FIB_PATH_CFG_FLAG_LOCAL;
554 if (plf & FIB_PATH_LIST_FLAG_DROP)
556 pf |= FIB_PATH_CFG_FLAG_DROP;
558 if (plf & FIB_PATH_LIST_FLAG_EXCLUSIVE)
560 pf |= FIB_PATH_CFG_FLAG_EXCLUSIVE;
566 static fib_path_list_flags_t
567 fib_path_list_flags_fixup (fib_path_list_flags_t flags)
570 * we do no share drop nor exclusive path-lists
572 if (flags & FIB_PATH_LIST_FLAG_DROP ||
573 flags & FIB_PATH_LIST_FLAG_EXCLUSIVE)
575 flags &= ~FIB_PATH_LIST_FLAG_SHARED;
582 fib_path_list_create (fib_path_list_flags_t flags,
583 const fib_route_path_t *rpaths)
585 fib_node_index_t path_list_index, old_path_list_index;
586 fib_path_list_t *path_list;
589 flags = fib_path_list_flags_fixup(flags);
590 path_list = fib_path_list_alloc(&path_list_index);
591 path_list->fpl_flags = flags;
593 * we'll assume for now all paths are the same next-hop protocol
595 path_list->fpl_nh_proto = rpaths[0].frp_proto;
597 vec_foreach_index(i, rpaths)
599 vec_add1(path_list->fpl_paths,
600 fib_path_create(path_list_index,
601 path_list->fpl_nh_proto,
602 fib_path_list_flags_2_path_flags(flags),
607 * If a shared path list is requested, consult the DB for a match
609 if (flags & FIB_PATH_LIST_FLAG_SHARED)
612 * check for a matching path-list in the DB.
613 * If we find one then we can return the existing one and destroy the
614 * new one just created.
616 old_path_list_index = fib_path_list_db_find(path_list);
617 if (FIB_NODE_INDEX_INVALID != old_path_list_index)
619 fib_path_list_destroy(path_list);
621 path_list_index = old_path_list_index;
626 * if there was not a matching path-list, then this
627 * new one will need inserting into the DB and resolving.
629 fib_path_list_db_insert(path_list_index);
630 path_list = fib_path_list_resolve(path_list);
636 * no shared path list requested. resolve and use the one
639 path_list = fib_path_list_resolve(path_list);
642 return (path_list_index);
646 fib_path_list_create_special (fib_protocol_t nh_proto,
647 fib_path_list_flags_t flags,
650 fib_node_index_t path_index, path_list_index;
651 fib_path_list_t *path_list;
653 path_list = fib_path_list_alloc(&path_list_index);
654 path_list->fpl_flags = flags;
655 path_list->fpl_nh_proto = nh_proto;
658 fib_path_create_special(path_list_index,
659 path_list->fpl_nh_proto,
660 fib_path_list_flags_2_path_flags(flags),
662 vec_add1(path_list->fpl_paths, path_index);
665 * we don't share path-lists. we can do PIC on them so why bother.
667 path_list = fib_path_list_resolve(path_list);
669 return (path_list_index);
673 * fib_path_list_copy_and_path_add
675 * Create a copy of a path-list and append one more path to it.
676 * The path-list returned could either have been newly created, or
677 * can be a shared path-list from the data-base.
680 fib_path_list_copy_and_path_add (fib_node_index_t orig_path_list_index,
681 fib_path_list_flags_t flags,
682 const fib_route_path_t *rpaths)
684 fib_node_index_t path_index, path_list_index, *orig_path_index;
685 fib_path_list_t *path_list, *orig_path_list;
688 ASSERT(1 == vec_len(rpaths));
691 * alloc the new list before we retrieve the old one, lest
692 * the alloc result in a realloc
694 path_list = fib_path_list_alloc(&path_list_index);
696 orig_path_list = fib_path_list_get(orig_path_list_index);
698 FIB_PATH_LIST_DBG(orig_path_list, "copy-add");
700 flags = fib_path_list_flags_fixup(flags);
701 path_list->fpl_flags = flags;
702 path_list->fpl_nh_proto = orig_path_list->fpl_nh_proto;
703 vec_validate(path_list->fpl_paths, vec_len(orig_path_list->fpl_paths));
706 vec_foreach (orig_path_index, orig_path_list->fpl_paths)
708 path_index = fib_path_copy(*orig_path_index, path_list_index);
709 path_list->fpl_paths[pi++] = path_index;
711 path_index = fib_path_create(path_list_index,
712 path_list->fpl_nh_proto,
713 fib_path_list_flags_2_path_flags(flags),
715 path_list->fpl_paths[pi] = path_index;
718 * we sort the paths since the key for the path-list is
719 * the description of the paths it contains. The paths need to
720 * be sorted else this description will differ.
722 vec_sort_with_function(path_list->fpl_paths, fib_path_cmp_for_sort);
724 FIB_PATH_LIST_DBG(path_list, "path-added");
727 * If a shared path list is requested, consult the DB for a match
729 if (path_list->fpl_flags & FIB_PATH_LIST_FLAG_SHARED)
731 fib_node_index_t exist_path_list_index;
733 * check for a matching path-list in the DB.
734 * If we find one then we can return the existing one and destroy the
735 * new one just created.
737 exist_path_list_index = fib_path_list_db_find(path_list);
738 if (FIB_NODE_INDEX_INVALID != exist_path_list_index)
740 fib_path_list_destroy(path_list);
742 path_list_index = exist_path_list_index;
747 * if there was not a matching path-list, then this
748 * new one will need inserting into the DB and resolving.
750 fib_path_list_db_insert(path_list_index);
752 path_list = fib_path_list_resolve(path_list);
758 * no shared path list requested. resolve and use the one
761 path_list = fib_path_list_resolve(path_list);
764 return (path_list_index);
768 * fib_path_list_copy_and_path_remove
770 * Copy the path-list excluding the path passed.
771 * If the path is the last one, then the index reurned will be invalid.
772 * i.e. the path-list is toast.
775 fib_path_list_copy_and_path_remove (fib_node_index_t orig_path_list_index,
776 fib_path_list_flags_t flags,
777 const fib_route_path_t *rpaths)
779 fib_node_index_t path_index, *orig_path_index, path_list_index, tmp_path_index;
780 fib_path_list_t *path_list, *orig_path_list;
783 ASSERT(1 == vec_len(rpaths));
785 path_list = fib_path_list_alloc(&path_list_index);
787 flags = fib_path_list_flags_fixup(flags);
788 orig_path_list = fib_path_list_get(orig_path_list_index);
790 FIB_PATH_LIST_DBG(orig_path_list, "copy-remove");
792 path_list->fpl_flags = flags;
793 path_list->fpl_nh_proto = orig_path_list->fpl_nh_proto;
795 * allocate as many paths as we might need in one go, rather than
796 * using vec_add to do a few at a time.
798 if (vec_len(orig_path_list->fpl_paths) > 1)
800 vec_validate(path_list->fpl_paths, vec_len(orig_path_list->fpl_paths) - 2);
805 * create a representation of the path to be removed, so it
806 * can be used as a comparison object during the copy.
808 tmp_path_index = fib_path_create(path_list_index,
809 path_list->fpl_nh_proto,
810 fib_path_list_flags_2_path_flags(flags),
813 vec_foreach (orig_path_index, orig_path_list->fpl_paths)
815 if (0 != fib_path_cmp(tmp_path_index, *orig_path_index)) {
816 path_index = fib_path_copy(*orig_path_index, path_list_index);
817 if (pi < vec_len(path_list->fpl_paths))
819 path_list->fpl_paths[pi++] = path_index;
824 * this is the unlikely case that the path being
825 * removed does not match one in the path-list, so
826 * we end up with as many paths as we started with.
827 * the paths vector was sized above with the expectation
828 * that we would have 1 less.
830 vec_add1(path_list->fpl_paths, path_index);
836 * done with the temporary now
838 fib_path_destroy(tmp_path_index);
841 * if there are no paths, then the new path-list is aborted
843 if (0 == vec_len(path_list->fpl_paths)) {
844 FIB_PATH_LIST_DBG(path_list, "last-path-removed");
846 fib_path_list_destroy(path_list);
848 path_list_index = FIB_NODE_INDEX_INVALID;
851 * we sort the paths since the key for the path-list is
852 * the description of the paths it contains. The paths need to
853 * be sorted else this description will differ.
855 vec_sort_with_function(path_list->fpl_paths, fib_path_cmp_for_sort);
858 * If a shared path list is requested, consult the DB for a match
860 if (path_list->fpl_flags & FIB_PATH_LIST_FLAG_SHARED)
862 fib_node_index_t exist_path_list_index;
865 * check for a matching path-list in the DB.
866 * If we find one then we can return the existing one and destroy the
867 * new one just created.
869 exist_path_list_index = fib_path_list_db_find(path_list);
870 if (FIB_NODE_INDEX_INVALID != exist_path_list_index)
872 fib_path_list_destroy(path_list);
874 path_list_index = exist_path_list_index;
879 * if there was not a matching path-list, then this
880 * new one will need inserting into the DB and resolving.
882 fib_path_list_db_insert(path_list_index);
884 path_list = fib_path_list_resolve(path_list);
890 * no shared path list requested. resolve and use the one
893 path_list = fib_path_list_resolve(path_list);
897 return (path_list_index);
901 * fib_path_list_contribute_forwarding
903 * Return the index of a load-balance that user of this path-list should
907 fib_path_list_contribute_forwarding (fib_node_index_t path_list_index,
908 fib_forward_chain_type_t type,
911 fib_path_list_t *path_list;
913 path_list = fib_path_list_get(path_list_index);
915 fib_path_list_mk_lb(path_list, type, dpo);
919 * fib_path_list_get_adj
921 * Return the index of a adjacency for the first path that user of this
922 * path-list should use for forwarding
925 fib_path_list_get_adj (fib_node_index_t path_list_index,
926 fib_forward_chain_type_t type)
928 fib_path_list_t *path_list;
930 path_list = fib_path_list_get(path_list_index);
931 return (fib_path_get_adj(path_list->fpl_paths[0]));
935 fib_path_list_recursive_loop_detect (fib_node_index_t path_list_index,
936 fib_node_index_t **entry_indicies)
938 fib_node_index_t *path_index;
939 int is_looped, list_looped;
940 fib_path_list_t *path_list;
943 path_list = fib_path_list_get(path_list_index);
945 vec_foreach (path_index, path_list->fpl_paths)
947 fib_node_index_t *copy, **copy_ptr;
950 * we need a copy of the nodes visited so that when we add entries
951 * we explore on the nth path and a looped is detected, those entries
952 * are not again searched for n+1 path and so finding a loop that does
955 copy = vec_dup(*entry_indicies);
958 is_looped = fib_path_recursive_loop_detect(*path_index, copy_ptr);
959 list_looped += is_looped;
962 FIB_PATH_LIST_DBG(path_list, "loop-detect: eval:%d", eval);
966 path_list->fpl_flags |= FIB_PATH_LIST_FLAG_LOOPED;
970 path_list->fpl_flags &= ~FIB_PATH_LIST_FLAG_LOOPED;
973 return (list_looped);
977 fib_path_list_child_add (fib_node_index_t path_list_index,
978 fib_node_type_t child_type,
979 fib_node_index_t child_index)
981 return (fib_node_child_add(FIB_NODE_TYPE_PATH_LIST,
988 fib_path_list_child_remove (fib_node_index_t path_list_index,
991 fib_node_child_remove(FIB_NODE_TYPE_PATH_LIST,
997 fib_path_list_lock(fib_node_index_t path_list_index)
999 fib_path_list_t *path_list;
1001 if (FIB_NODE_INDEX_INVALID != path_list_index)
1003 path_list = fib_path_list_get(path_list_index);
1005 fib_node_lock(&path_list->fpl_node);
1006 FIB_PATH_LIST_DBG(path_list, "lock");
1011 fib_path_list_unlock (fib_node_index_t path_list_index)
1013 fib_path_list_t *path_list;
1015 if (FIB_NODE_INDEX_INVALID != path_list_index)
1017 path_list = fib_path_list_get(path_list_index);
1018 FIB_PATH_LIST_DBG(path_list, "unlock");
1020 fib_node_unlock(&path_list->fpl_node);
1025 fib_path_list_pool_size (void)
1027 return (pool_elts(fib_path_list_pool));
1031 fib_path_list_db_size (void)
1033 return (hash_elts(fib_path_list_db));
1037 fib_path_list_walk (fib_node_index_t path_list_index,
1038 fib_path_list_walk_fn_t func,
1041 fib_node_index_t *path_index;
1042 fib_path_list_t *path_list;
1044 path_list = fib_path_list_get(path_list_index);
1046 vec_foreach(path_index, path_list->fpl_paths)
1048 if (!func(path_list_index, *path_index, ctx))
1055 fib_path_list_module_init (void)
1057 fib_node_register_type (FIB_NODE_TYPE_PATH_LIST, &fib_path_list_vft);
1059 fib_path_list_db = hash_create2 (/* elts */ 0,
1061 /* value_bytes */ sizeof (fib_node_index_t),
1062 fib_path_list_db_hash_key_sum,
1063 fib_path_list_db_hash_key_equal,
1064 /* format pair/arg */
1068 static clib_error_t *
1069 show_fib_path_list_command (vlib_main_t * vm,
1070 unformat_input_t * input,
1071 vlib_cli_command_t * cmd)
1073 fib_path_list_t *path_list;
1074 fib_node_index_t pli;
1076 if (unformat (input, "%d", &pli))
1079 * show one in detail
1081 if (!pool_is_free_index(fib_path_list_pool, pli))
1083 path_list = fib_path_list_get(pli);
1084 u8 *s = fib_path_list_format(pli, NULL);
1085 s = format(s, "children:");
1086 s = fib_node_children_format(path_list->fpl_node.fn_children, s);
1087 vlib_cli_output (vm, "%s", s);
1092 vlib_cli_output (vm, "path list %d invalid", pli);
1100 vlib_cli_output (vm, "FIB Path Lists");
1101 pool_foreach(path_list, fib_path_list_pool,
1103 vlib_cli_output (vm, "%U", format_fib_path_list, path_list);
1109 VLIB_CLI_COMMAND (show_fib_path_list, static) = {
1110 .path = "show fib path list",
1111 .function = show_fib_path_list_command,
1112 .short_help = "show fib path list",