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 * Display the path-list memory usage
458 fib_path_list_memory_show (void)
460 fib_show_memory_usage("Path-list",
461 pool_elts(fib_path_list_pool),
462 pool_len(fib_path_list_pool),
463 sizeof(fib_path_list_t));
467 * The FIB path-list's graph node virtual function table
469 static const fib_node_vft_t fib_path_list_vft = {
470 .fnv_get = fib_path_list_get_node,
471 .fnv_last_lock = fib_path_list_last_lock_gone,
472 .fnv_back_walk = fib_path_list_back_walk_notify,
473 .fnv_mem_show = fib_path_list_memory_show,
476 static fib_path_list_t *
477 fib_path_list_alloc (fib_node_index_t *path_list_index)
479 fib_path_list_t *path_list;
481 pool_get(fib_path_list_pool, path_list);
482 memset(path_list, 0, sizeof(*path_list));
484 fib_node_init(&path_list->fpl_node,
485 FIB_NODE_TYPE_PATH_LIST);
487 if (NULL != path_list_index)
489 *path_list_index = fib_path_list_get_index(path_list);
492 FIB_PATH_LIST_DBG(path_list, "alloc");
497 static fib_path_list_t *
498 fib_path_list_resolve (fib_path_list_t *path_list)
500 fib_node_index_t *path_index, *paths, path_list_index;
502 ASSERT(!(path_list->fpl_flags & FIB_PATH_LIST_FLAG_RESOLVED));
505 * resolving a path-list is a recursive action. this means more path
506 * lists can be created during this call, and hence this path-list
507 * can be realloc'd. so we work with copies.
508 * this function is called only once per-path list, so its no great overhead.
510 path_list_index = fib_path_list_get_index(path_list);
511 paths = vec_dup(path_list->fpl_paths);
513 vec_foreach (path_index, paths)
515 fib_path_resolve(*path_index);
519 path_list = fib_path_list_get(path_list_index);
521 FIB_PATH_LIST_DBG(path_list, "resovled");
527 fib_path_list_get_resolving_interface (fib_node_index_t path_list_index)
529 fib_node_index_t *path_index;
530 fib_path_list_t *path_list;
533 path_list = fib_path_list_get(path_list_index);
536 vec_foreach (path_index, path_list->fpl_paths)
538 sw_if_index = fib_path_get_resolving_interface(*path_index);
539 if (~0 != sw_if_index)
541 return (sw_if_index);
545 return (sw_if_index);
549 fib_path_list_is_looped (fib_node_index_t path_list_index)
551 fib_path_list_t *path_list;
553 path_list = fib_path_list_get(path_list_index);
555 return (path_list->fpl_flags & FIB_PATH_LIST_FLAG_LOOPED);
558 static fib_path_cfg_flags_t
559 fib_path_list_flags_2_path_flags (fib_path_list_flags_t plf)
561 fib_path_cfg_flags_t pf = FIB_PATH_CFG_FLAG_NONE;
563 if (plf & FIB_PATH_LIST_FLAG_LOCAL)
565 pf |= FIB_PATH_CFG_FLAG_LOCAL;
567 if (plf & FIB_PATH_LIST_FLAG_DROP)
569 pf |= FIB_PATH_CFG_FLAG_DROP;
571 if (plf & FIB_PATH_LIST_FLAG_EXCLUSIVE)
573 pf |= FIB_PATH_CFG_FLAG_EXCLUSIVE;
579 static fib_path_list_flags_t
580 fib_path_list_flags_fixup (fib_path_list_flags_t flags)
583 * we do no share drop nor exclusive path-lists
585 if (flags & FIB_PATH_LIST_FLAG_DROP ||
586 flags & FIB_PATH_LIST_FLAG_EXCLUSIVE)
588 flags &= ~FIB_PATH_LIST_FLAG_SHARED;
595 fib_path_list_create (fib_path_list_flags_t flags,
596 const fib_route_path_t *rpaths)
598 fib_node_index_t path_list_index, old_path_list_index;
599 fib_path_list_t *path_list;
602 flags = fib_path_list_flags_fixup(flags);
603 path_list = fib_path_list_alloc(&path_list_index);
604 path_list->fpl_flags = flags;
606 * we'll assume for now all paths are the same next-hop protocol
608 path_list->fpl_nh_proto = rpaths[0].frp_proto;
610 vec_foreach_index(i, rpaths)
612 vec_add1(path_list->fpl_paths,
613 fib_path_create(path_list_index,
614 path_list->fpl_nh_proto,
615 fib_path_list_flags_2_path_flags(flags),
620 * If a shared path list is requested, consult the DB for a match
622 if (flags & FIB_PATH_LIST_FLAG_SHARED)
625 * check for a matching path-list in the DB.
626 * If we find one then we can return the existing one and destroy the
627 * new one just created.
629 old_path_list_index = fib_path_list_db_find(path_list);
630 if (FIB_NODE_INDEX_INVALID != old_path_list_index)
632 fib_path_list_destroy(path_list);
634 path_list_index = old_path_list_index;
639 * if there was not a matching path-list, then this
640 * new one will need inserting into the DB and resolving.
642 fib_path_list_db_insert(path_list_index);
643 path_list = fib_path_list_resolve(path_list);
649 * no shared path list requested. resolve and use the one
652 path_list = fib_path_list_resolve(path_list);
655 return (path_list_index);
659 fib_path_list_create_special (fib_protocol_t nh_proto,
660 fib_path_list_flags_t flags,
663 fib_node_index_t path_index, path_list_index;
664 fib_path_list_t *path_list;
666 path_list = fib_path_list_alloc(&path_list_index);
667 path_list->fpl_flags = flags;
668 path_list->fpl_nh_proto = nh_proto;
671 fib_path_create_special(path_list_index,
672 path_list->fpl_nh_proto,
673 fib_path_list_flags_2_path_flags(flags),
675 vec_add1(path_list->fpl_paths, path_index);
678 * we don't share path-lists. we can do PIC on them so why bother.
680 path_list = fib_path_list_resolve(path_list);
682 return (path_list_index);
686 * fib_path_list_copy_and_path_add
688 * Create a copy of a path-list and append one more path to it.
689 * The path-list returned could either have been newly created, or
690 * can be a shared path-list from the data-base.
693 fib_path_list_copy_and_path_add (fib_node_index_t orig_path_list_index,
694 fib_path_list_flags_t flags,
695 const fib_route_path_t *rpaths)
697 fib_node_index_t path_index, path_list_index, *orig_path_index;
698 fib_path_list_t *path_list, *orig_path_list;
701 ASSERT(1 == vec_len(rpaths));
704 * alloc the new list before we retrieve the old one, lest
705 * the alloc result in a realloc
707 path_list = fib_path_list_alloc(&path_list_index);
709 orig_path_list = fib_path_list_get(orig_path_list_index);
711 FIB_PATH_LIST_DBG(orig_path_list, "copy-add");
713 flags = fib_path_list_flags_fixup(flags);
714 path_list->fpl_flags = flags;
715 path_list->fpl_nh_proto = orig_path_list->fpl_nh_proto;
716 vec_validate(path_list->fpl_paths, vec_len(orig_path_list->fpl_paths));
719 vec_foreach (orig_path_index, orig_path_list->fpl_paths)
721 path_index = fib_path_copy(*orig_path_index, path_list_index);
722 path_list->fpl_paths[pi++] = path_index;
724 path_index = fib_path_create(path_list_index,
725 path_list->fpl_nh_proto,
726 fib_path_list_flags_2_path_flags(flags),
728 path_list->fpl_paths[pi] = path_index;
731 * we sort the paths since the key for the path-list is
732 * the description of the paths it contains. The paths need to
733 * be sorted else this description will differ.
735 vec_sort_with_function(path_list->fpl_paths, fib_path_cmp_for_sort);
737 FIB_PATH_LIST_DBG(path_list, "path-added");
740 * If a shared path list is requested, consult the DB for a match
742 if (path_list->fpl_flags & FIB_PATH_LIST_FLAG_SHARED)
744 fib_node_index_t exist_path_list_index;
746 * check for a matching path-list in the DB.
747 * If we find one then we can return the existing one and destroy the
748 * new one just created.
750 exist_path_list_index = fib_path_list_db_find(path_list);
751 if (FIB_NODE_INDEX_INVALID != exist_path_list_index)
753 fib_path_list_destroy(path_list);
755 path_list_index = exist_path_list_index;
760 * if there was not a matching path-list, then this
761 * new one will need inserting into the DB and resolving.
763 fib_path_list_db_insert(path_list_index);
765 path_list = fib_path_list_resolve(path_list);
771 * no shared path list requested. resolve and use the one
774 path_list = fib_path_list_resolve(path_list);
777 return (path_list_index);
781 * fib_path_list_copy_and_path_remove
783 * Copy the path-list excluding the path passed.
784 * If the path is the last one, then the index reurned will be invalid.
785 * i.e. the path-list is toast.
788 fib_path_list_copy_and_path_remove (fib_node_index_t orig_path_list_index,
789 fib_path_list_flags_t flags,
790 const fib_route_path_t *rpaths)
792 fib_node_index_t path_index, *orig_path_index, path_list_index, tmp_path_index;
793 fib_path_list_t *path_list, *orig_path_list;
796 ASSERT(1 == vec_len(rpaths));
798 path_list = fib_path_list_alloc(&path_list_index);
800 flags = fib_path_list_flags_fixup(flags);
801 orig_path_list = fib_path_list_get(orig_path_list_index);
803 FIB_PATH_LIST_DBG(orig_path_list, "copy-remove");
805 path_list->fpl_flags = flags;
806 path_list->fpl_nh_proto = orig_path_list->fpl_nh_proto;
808 * allocate as many paths as we might need in one go, rather than
809 * using vec_add to do a few at a time.
811 if (vec_len(orig_path_list->fpl_paths) > 1)
813 vec_validate(path_list->fpl_paths, vec_len(orig_path_list->fpl_paths) - 2);
818 * create a representation of the path to be removed, so it
819 * can be used as a comparison object during the copy.
821 tmp_path_index = fib_path_create(path_list_index,
822 path_list->fpl_nh_proto,
823 fib_path_list_flags_2_path_flags(flags),
826 vec_foreach (orig_path_index, orig_path_list->fpl_paths)
828 if (0 != fib_path_cmp(tmp_path_index, *orig_path_index)) {
829 path_index = fib_path_copy(*orig_path_index, path_list_index);
830 if (pi < vec_len(path_list->fpl_paths))
832 path_list->fpl_paths[pi++] = path_index;
837 * this is the unlikely case that the path being
838 * removed does not match one in the path-list, so
839 * we end up with as many paths as we started with.
840 * the paths vector was sized above with the expectation
841 * that we would have 1 less.
843 vec_add1(path_list->fpl_paths, path_index);
849 * done with the temporary now
851 fib_path_destroy(tmp_path_index);
854 * if there are no paths, then the new path-list is aborted
856 if (0 == vec_len(path_list->fpl_paths)) {
857 FIB_PATH_LIST_DBG(path_list, "last-path-removed");
859 fib_path_list_destroy(path_list);
861 path_list_index = FIB_NODE_INDEX_INVALID;
864 * we sort the paths since the key for the path-list is
865 * the description of the paths it contains. The paths need to
866 * be sorted else this description will differ.
868 vec_sort_with_function(path_list->fpl_paths, fib_path_cmp_for_sort);
871 * If a shared path list is requested, consult the DB for a match
873 if (path_list->fpl_flags & FIB_PATH_LIST_FLAG_SHARED)
875 fib_node_index_t exist_path_list_index;
878 * check for a matching path-list in the DB.
879 * If we find one then we can return the existing one and destroy the
880 * new one just created.
882 exist_path_list_index = fib_path_list_db_find(path_list);
883 if (FIB_NODE_INDEX_INVALID != exist_path_list_index)
885 fib_path_list_destroy(path_list);
887 path_list_index = exist_path_list_index;
892 * if there was not a matching path-list, then this
893 * new one will need inserting into the DB and resolving.
895 fib_path_list_db_insert(path_list_index);
897 path_list = fib_path_list_resolve(path_list);
903 * no shared path list requested. resolve and use the one
906 path_list = fib_path_list_resolve(path_list);
910 return (path_list_index);
914 * fib_path_list_contribute_forwarding
916 * Return the index of a load-balance that user of this path-list should
920 fib_path_list_contribute_forwarding (fib_node_index_t path_list_index,
921 fib_forward_chain_type_t type,
924 fib_path_list_t *path_list;
926 path_list = fib_path_list_get(path_list_index);
928 fib_path_list_mk_lb(path_list, type, dpo);
932 * fib_path_list_get_adj
934 * Return the index of a adjacency for the first path that user of this
935 * path-list should use for forwarding
938 fib_path_list_get_adj (fib_node_index_t path_list_index,
939 fib_forward_chain_type_t type)
941 fib_path_list_t *path_list;
943 path_list = fib_path_list_get(path_list_index);
944 return (fib_path_get_adj(path_list->fpl_paths[0]));
948 fib_path_list_recursive_loop_detect (fib_node_index_t path_list_index,
949 fib_node_index_t **entry_indicies)
951 fib_node_index_t *path_index;
952 int is_looped, list_looped;
953 fib_path_list_t *path_list;
956 path_list = fib_path_list_get(path_list_index);
958 vec_foreach (path_index, path_list->fpl_paths)
960 fib_node_index_t *copy, **copy_ptr;
963 * we need a copy of the nodes visited so that when we add entries
964 * we explore on the nth path and a looped is detected, those entries
965 * are not again searched for n+1 path and so finding a loop that does
968 copy = vec_dup(*entry_indicies);
971 is_looped = fib_path_recursive_loop_detect(*path_index, copy_ptr);
972 list_looped += is_looped;
975 FIB_PATH_LIST_DBG(path_list, "loop-detect: eval:%d", eval);
979 path_list->fpl_flags |= FIB_PATH_LIST_FLAG_LOOPED;
983 path_list->fpl_flags &= ~FIB_PATH_LIST_FLAG_LOOPED;
986 return (list_looped);
990 fib_path_list_child_add (fib_node_index_t path_list_index,
991 fib_node_type_t child_type,
992 fib_node_index_t child_index)
994 return (fib_node_child_add(FIB_NODE_TYPE_PATH_LIST,
1001 fib_path_list_child_remove (fib_node_index_t path_list_index,
1004 fib_node_child_remove(FIB_NODE_TYPE_PATH_LIST,
1010 fib_path_list_lock(fib_node_index_t path_list_index)
1012 fib_path_list_t *path_list;
1014 if (FIB_NODE_INDEX_INVALID != path_list_index)
1016 path_list = fib_path_list_get(path_list_index);
1018 fib_node_lock(&path_list->fpl_node);
1019 FIB_PATH_LIST_DBG(path_list, "lock");
1024 fib_path_list_unlock (fib_node_index_t path_list_index)
1026 fib_path_list_t *path_list;
1028 if (FIB_NODE_INDEX_INVALID != path_list_index)
1030 path_list = fib_path_list_get(path_list_index);
1031 FIB_PATH_LIST_DBG(path_list, "unlock");
1033 fib_node_unlock(&path_list->fpl_node);
1038 fib_path_list_pool_size (void)
1040 return (pool_elts(fib_path_list_pool));
1044 fib_path_list_db_size (void)
1046 return (hash_elts(fib_path_list_db));
1050 fib_path_list_walk (fib_node_index_t path_list_index,
1051 fib_path_list_walk_fn_t func,
1054 fib_node_index_t *path_index;
1055 fib_path_list_t *path_list;
1057 path_list = fib_path_list_get(path_list_index);
1059 vec_foreach(path_index, path_list->fpl_paths)
1061 if (!func(path_list_index, *path_index, ctx))
1068 fib_path_list_module_init (void)
1070 fib_node_register_type (FIB_NODE_TYPE_PATH_LIST, &fib_path_list_vft);
1072 fib_path_list_db = hash_create2 (/* elts */ 0,
1074 /* value_bytes */ sizeof (fib_node_index_t),
1075 fib_path_list_db_hash_key_sum,
1076 fib_path_list_db_hash_key_equal,
1077 /* format pair/arg */
1081 static clib_error_t *
1082 show_fib_path_list_command (vlib_main_t * vm,
1083 unformat_input_t * input,
1084 vlib_cli_command_t * cmd)
1086 fib_path_list_t *path_list;
1087 fib_node_index_t pli;
1089 if (unformat (input, "%d", &pli))
1092 * show one in detail
1094 if (!pool_is_free_index(fib_path_list_pool, pli))
1096 path_list = fib_path_list_get(pli);
1097 u8 *s = fib_path_list_format(pli, NULL);
1098 s = format(s, "children:");
1099 s = fib_node_children_format(path_list->fpl_node.fn_children, s);
1100 vlib_cli_output (vm, "%s", s);
1105 vlib_cli_output (vm, "path list %d invalid", pli);
1113 vlib_cli_output (vm, "FIB Path Lists");
1114 pool_foreach(path_list, fib_path_list_pool,
1116 vlib_cli_output (vm, "%U", format_fib_path_list, path_list);
1122 VLIB_CLI_COMMAND (show_fib_path_list, static) = {
1123 .path = "show fib path list",
1124 .function = show_fib_path_list_command,
1125 .short_help = "show fib path list",