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>
26 #include <vnet/fib/fib_urpf_list.h>
30 * A representation of the list/set of path trough which a prefix is reachable
32 typedef struct fib_path_list_t_ {
34 * A path-list is a node in the FIB graph.
39 * Flags on the path-list
41 fib_path_list_flags_t fpl_flags;
44 * The next-hop protocol for the paths in this path list.
45 * Note that fixing the proto here means we don't support a mix of
46 * v4 and v6 paths. ho hum.
48 fib_protocol_t fpl_nh_proto;
51 * Vector of paths indicies for all configured paths.
52 * For shareable path-lists this list MUST not change.
54 fib_node_index_t *fpl_paths;
57 * the RPF list calculated for this path list
59 fib_node_index_t fpl_urpf;
63 * Array of strings/names for the FIB sources
65 static const char *fib_path_list_attr_names[] = FIB_PATH_LIST_ATTRIBUTES;
68 * The memory pool from which we allocate all the path-lists
70 static fib_path_list_t * fib_path_list_pool;
73 * The data-base of shared path-lists
75 static uword *fib_path_list_db;
81 #define FIB_PATH_LIST_DBG(_pl, _fmt, _args...) \
84 _tmp = fib_path_list_format( \
85 fib_path_list_get_index(_pl), _tmp); \
86 clib_warning("pl:[%d:%p:%p:%s]:" _fmt, \
87 fib_path_list_get_index(_pl), \
88 _pl, _pl->fpl_paths, _tmp, \
93 #define FIB_PATH_LIST_DBG(_pl, _fmt, _args...)
96 static fib_path_list_t *
97 fib_path_list_get (fib_node_index_t index)
99 return (pool_elt_at_index(fib_path_list_pool, index));
103 fib_path_list_get_node (fib_node_index_t index)
105 return ((fib_node_t*)fib_path_list_get(index));
108 static fib_path_list_t*
109 fib_path_list_from_fib_node (fib_node_t *node)
112 ASSERT(FIB_NODE_TYPE_PATH_LIST == node->fn_type);
114 return ((fib_path_list_t*)node);
117 static fib_node_index_t
118 fib_path_list_get_index (fib_path_list_t *path_list)
120 return (path_list - fib_path_list_pool);
124 format_fib_path_list (u8 * s, va_list * args)
126 fib_path_list_attribute_t attr;
127 fib_node_index_t *path_index;
128 fib_path_list_t *path_list;
130 path_list = va_arg (*args, fib_path_list_t *);
132 s = format (s, " index:%u", fib_path_list_get_index(path_list));
133 s = format (s, " locks:%u", path_list->fpl_node.fn_locks);
134 s = format (s, " proto:%U", format_fib_protocol, path_list->fpl_nh_proto);
136 if (FIB_PATH_LIST_FLAG_NONE != path_list->fpl_flags)
138 s = format (s, " flags:");
139 FOR_EACH_PATH_LIST_ATTRIBUTE(attr)
141 if ((1<<attr) & path_list->fpl_flags)
143 s = format (s, "%s,", fib_path_list_attr_names[attr]);
147 s = format (s, " %U\n", format_fib_urpf_list, path_list->fpl_urpf);
149 vec_foreach (path_index, path_list->fpl_paths)
151 s = fib_path_format(*path_index, s);
159 fib_path_list_adjs_format (fib_node_index_t path_list_index,
163 fib_path_list_t *path_list;
166 path_list = fib_path_list_get(path_list_index);
168 vec_foreach_index (i, path_list->fpl_paths)
170 s = fib_path_adj_format(path_list->fpl_paths[i],
179 fib_path_list_format (fib_node_index_t path_list_index,
182 fib_path_list_t *path_list;
184 path_list = fib_path_list_get(path_list_index);
186 return (format(s, "%U", format_fib_path_list, path_list));
190 fib_path_list_hash (fib_path_list_t *path_list)
192 uword old_path_list_hash, new_path_list_hash, path_hash;
193 fib_node_index_t *path_index;
197 new_path_list_hash = old_path_list_hash = vec_len(path_list->fpl_paths);
199 vec_foreach (path_index, path_list->fpl_paths)
201 path_hash = fib_path_hash(*path_index);
203 hash_mix64(path_hash, old_path_list_hash, new_path_list_hash);
205 hash_mix32(path_hash, old_path_list_hash, new_path_list_hash);
209 return (new_path_list_hash);
213 fib_path_list_db_hash_key_from_index (uword index)
219 fib_path_list_db_hash_key_is_index (uword key)
225 fib_path_list_db_hash_key_2_index (uword key)
227 ASSERT (fib_path_list_db_hash_key_is_index (key));
231 static fib_path_list_t*
232 fib_path_list_db_get_from_hash_key (uword key)
234 fib_path_list_t *path_list;
236 if (fib_path_list_db_hash_key_is_index (key))
238 fib_node_index_t path_list_index;
240 path_list_index = fib_path_list_db_hash_key_2_index(key);
241 path_list = fib_path_list_get(path_list_index);
245 path_list = uword_to_pointer (key, fib_path_list_t *);
252 fib_path_list_db_hash_key_sum (hash_t * h,
255 fib_path_list_t *path_list;
257 path_list = fib_path_list_db_get_from_hash_key(key);
259 return (fib_path_list_hash(path_list));
263 fib_path_list_db_hash_key_equal (hash_t * h,
267 fib_path_list_t *path_list1, *path_list2;
269 path_list1 = fib_path_list_db_get_from_hash_key(key1);
270 path_list2 = fib_path_list_db_get_from_hash_key(key2);
272 return (fib_path_list_hash(path_list1) ==
273 fib_path_list_hash(path_list2));
276 static fib_node_index_t
277 fib_path_list_db_find (fib_path_list_t *path_list)
281 p = hash_get(fib_path_list_db, path_list);
288 return (FIB_NODE_INDEX_INVALID);
292 fib_path_list_db_insert (fib_node_index_t path_list_index)
294 fib_path_list_t *path_list;
296 path_list = fib_path_list_get(path_list_index);
298 ASSERT(FIB_NODE_INDEX_INVALID == fib_path_list_db_find(path_list));
300 hash_set (fib_path_list_db,
301 fib_path_list_db_hash_key_from_index(path_list_index),
304 FIB_PATH_LIST_DBG(path_list, "DB-inserted");
308 fib_path_list_db_remove (fib_node_index_t path_list_index)
310 fib_path_list_t *path_list;
312 path_list = fib_path_list_get(path_list_index);
314 ASSERT(FIB_NODE_INDEX_INVALID != fib_path_list_db_find(path_list));
316 hash_unset(fib_path_list_db,
317 fib_path_list_db_hash_key_from_index(path_list_index));
319 FIB_PATH_LIST_DBG(path_list, "DB-removed");
323 fib_path_list_destroy (fib_path_list_t *path_list)
325 fib_node_index_t *path_index;
327 FIB_PATH_LIST_DBG(path_list, "destroy");
329 vec_foreach (path_index, path_list->fpl_paths)
331 fib_path_destroy(*path_index);
334 vec_free(path_list->fpl_paths);
335 fib_urpf_list_unlock(path_list->fpl_urpf);
337 fib_node_deinit(&path_list->fpl_node);
338 pool_put(fib_path_list_pool, path_list);
342 fib_path_list_last_lock_gone (fib_node_t *node)
344 fib_path_list_t *path_list;
346 path_list = fib_path_list_from_fib_node(node);
348 FIB_PATH_LIST_DBG(path_list, "last-lock");
350 if (path_list->fpl_flags & FIB_PATH_LIST_FLAG_SHARED)
352 fib_path_list_db_remove(fib_path_list_get_index(path_list));
354 fib_path_list_destroy(path_list);
360 * update the multipath adj this path-list will contribute to its
361 * children's forwarding.
364 fib_path_list_mk_lb (fib_path_list_t *path_list,
365 fib_forward_chain_type_t fct,
368 load_balance_path_t *nhs;
369 fib_node_index_t *path_index;
373 if (!dpo_id_is_valid(dpo))
380 fib_forw_chain_type_to_dpo_proto(fct),
381 load_balance_create(0,
382 fib_forw_chain_type_to_dpo_proto(fct),
383 0 /* FIXME FLOW HASH */));
387 * We gather the DPOs from resolved paths.
389 vec_foreach (path_index, path_list->fpl_paths)
391 nhs = fib_path_append_nh_for_multipath_hash(*path_index,
397 * Path-list load-balances, which if used, would be shared and hence
398 * never need a load-balance map.
400 load_balance_multipath_update(dpo, nhs, LOAD_BALANCE_FLAG_NONE);
402 FIB_PATH_LIST_DBG(path_list, "mk lb: %d", dpo->dpoi_index);
408 * @brief [re]build the path list's uRPF list
411 fib_path_list_mk_urpf (fib_path_list_t *path_list)
413 fib_node_index_t *path_index;
416 * ditch the old one. by iterating through all paths we are going
417 * to re-find all the adjs that were in the old one anyway. If we
418 * keep the old one, then the |sort|uniq requires more work.
419 * All users of the RPF list have their own lock, so we can release
422 fib_urpf_list_unlock(path_list->fpl_urpf);
423 path_list->fpl_urpf = fib_urpf_list_alloc_and_lock();
425 vec_foreach (path_index, path_list->fpl_paths)
427 fib_path_contribute_urpf(*path_index, path_list->fpl_urpf);
430 fib_urpf_list_bake(path_list->fpl_urpf);
434 * @brief Contribute (add) this path list's uRPF list. This allows the child
435 * to construct an aggregate list.
438 fib_path_list_contribute_urpf (fib_node_index_t path_list_index,
441 fib_path_list_t *path_list;
443 path_list = fib_path_list_get(path_list_index);
445 fib_urpf_list_combine(urpf, path_list->fpl_urpf);
449 * @brief Return the the child the RPF list pre-built for this path list
452 fib_path_list_get_urpf (fib_node_index_t path_list_index)
454 fib_path_list_t *path_list;
456 path_list = fib_path_list_get(path_list_index);
458 return (path_list->fpl_urpf);
462 * fib_path_list_back_walk
464 * Called from one of this path-list's paths to progate
468 fib_path_list_back_walk (fib_node_index_t path_list_index,
469 fib_node_back_walk_ctx_t *ctx)
471 fib_path_list_t *path_list;
473 path_list = fib_path_list_get(path_list_index);
475 fib_path_list_mk_urpf(path_list);
478 * propagate the backwalk further
480 if (32 >= fib_node_list_get_size(path_list->fpl_node.fn_children))
483 * only a few children. continue the walk synchronously
485 fib_walk_sync(FIB_NODE_TYPE_PATH_LIST, path_list_index, ctx);
490 * many children. schedule a async walk
492 fib_walk_async(FIB_NODE_TYPE_PATH_LIST,
494 FIB_WALK_PRIORITY_LOW,
500 * fib_path_list_back_walk_notify
502 * A back walk has reach this path-list.
504 static fib_node_back_walk_rc_t
505 fib_path_list_back_walk_notify (fib_node_t *node,
506 fib_node_back_walk_ctx_t *ctx)
509 * the path-list is not a direct child of any other node type
510 * paths, which do not change thier to-list-mapping, save the
511 * list they are a member of, and invoke the BW function directly.
515 return (FIB_NODE_BACK_WALK_CONTINUE);
519 * Display the path-list memory usage
522 fib_path_list_memory_show (void)
524 fib_show_memory_usage("Path-list",
525 pool_elts(fib_path_list_pool),
526 pool_len(fib_path_list_pool),
527 sizeof(fib_path_list_t));
528 fib_urpf_list_show_mem();
532 * The FIB path-list's graph node virtual function table
534 static const fib_node_vft_t fib_path_list_vft = {
535 .fnv_get = fib_path_list_get_node,
536 .fnv_last_lock = fib_path_list_last_lock_gone,
537 .fnv_back_walk = fib_path_list_back_walk_notify,
538 .fnv_mem_show = fib_path_list_memory_show,
541 static fib_path_list_t *
542 fib_path_list_alloc (fib_node_index_t *path_list_index)
544 fib_path_list_t *path_list;
546 pool_get(fib_path_list_pool, path_list);
547 memset(path_list, 0, sizeof(*path_list));
549 fib_node_init(&path_list->fpl_node,
550 FIB_NODE_TYPE_PATH_LIST);
551 path_list->fpl_urpf = INDEX_INVALID;
553 if (NULL != path_list_index)
555 *path_list_index = fib_path_list_get_index(path_list);
558 FIB_PATH_LIST_DBG(path_list, "alloc");
563 static fib_path_list_t *
564 fib_path_list_resolve (fib_path_list_t *path_list)
566 fib_node_index_t *path_index, *paths, path_list_index;
568 ASSERT(!(path_list->fpl_flags & FIB_PATH_LIST_FLAG_RESOLVED));
571 * resolving a path-list is a recursive action. this means more path
572 * lists can be created during this call, and hence this path-list
573 * can be realloc'd. so we work with copies.
574 * this function is called only once per-path list, so its no great overhead.
576 path_list_index = fib_path_list_get_index(path_list);
577 paths = vec_dup(path_list->fpl_paths);
579 vec_foreach (path_index, paths)
581 fib_path_resolve(*path_index);
585 path_list = fib_path_list_get(path_list_index);
587 FIB_PATH_LIST_DBG(path_list, "resovled");
589 if (!(path_list->fpl_flags & FIB_PATH_LIST_FLAG_NO_URPF))
591 fib_path_list_mk_urpf(path_list);
597 fib_path_list_get_n_paths (fib_node_index_t path_list_index)
599 fib_path_list_t *path_list;
601 path_list = fib_path_list_get(path_list_index);
603 return (vec_len(path_list->fpl_paths));
608 fib_path_list_get_resolving_interface (fib_node_index_t path_list_index)
610 fib_node_index_t *path_index;
611 fib_path_list_t *path_list;
614 path_list = fib_path_list_get(path_list_index);
617 vec_foreach (path_index, path_list->fpl_paths)
619 sw_if_index = fib_path_get_resolving_interface(*path_index);
620 if (~0 != sw_if_index)
622 return (sw_if_index);
626 return (sw_if_index);
630 fib_path_list_get_proto (fib_node_index_t path_list_index)
632 fib_path_list_t *path_list;
634 path_list = fib_path_list_get(path_list_index);
637 * we don't support a mix of path protocols, so we can return the proto
640 return (fib_path_get_proto(path_list->fpl_paths[0]));
644 fib_path_list_is_looped (fib_node_index_t path_list_index)
646 fib_path_list_t *path_list;
648 path_list = fib_path_list_get(path_list_index);
650 return (path_list->fpl_flags & FIB_PATH_LIST_FLAG_LOOPED);
653 static fib_path_cfg_flags_t
654 fib_path_list_flags_2_path_flags (fib_path_list_flags_t plf)
656 fib_path_cfg_flags_t pf = FIB_PATH_CFG_FLAG_NONE;
658 if (plf & FIB_PATH_LIST_FLAG_LOCAL)
660 pf |= FIB_PATH_CFG_FLAG_LOCAL;
662 if (plf & FIB_PATH_LIST_FLAG_DROP)
664 pf |= FIB_PATH_CFG_FLAG_DROP;
666 if (plf & FIB_PATH_LIST_FLAG_EXCLUSIVE)
668 pf |= FIB_PATH_CFG_FLAG_EXCLUSIVE;
674 static fib_path_list_flags_t
675 fib_path_list_flags_fixup (fib_path_list_flags_t flags)
678 * we do no share drop nor exclusive path-lists
680 if (flags & FIB_PATH_LIST_FLAG_DROP ||
681 flags & FIB_PATH_LIST_FLAG_EXCLUSIVE)
683 flags &= ~FIB_PATH_LIST_FLAG_SHARED;
690 fib_path_list_create (fib_path_list_flags_t flags,
691 const fib_route_path_t *rpaths)
693 fib_node_index_t path_list_index, old_path_list_index;
694 fib_path_list_t *path_list;
697 flags = fib_path_list_flags_fixup(flags);
698 path_list = fib_path_list_alloc(&path_list_index);
699 path_list->fpl_flags = flags;
701 * we'll assume for now all paths are the same next-hop protocol
703 path_list->fpl_nh_proto = rpaths[0].frp_proto;
705 vec_foreach_index(i, rpaths)
707 vec_add1(path_list->fpl_paths,
708 fib_path_create(path_list_index,
709 path_list->fpl_nh_proto,
710 fib_path_list_flags_2_path_flags(flags),
715 * If a shared path list is requested, consult the DB for a match
717 if (flags & FIB_PATH_LIST_FLAG_SHARED)
720 * check for a matching path-list in the DB.
721 * If we find one then we can return the existing one and destroy the
722 * new one just created.
724 old_path_list_index = fib_path_list_db_find(path_list);
725 if (FIB_NODE_INDEX_INVALID != old_path_list_index)
727 fib_path_list_destroy(path_list);
729 path_list_index = old_path_list_index;
734 * if there was not a matching path-list, then this
735 * new one will need inserting into the DB and resolving.
737 fib_path_list_db_insert(path_list_index);
738 path_list = fib_path_list_resolve(path_list);
744 * no shared path list requested. resolve and use the one
747 path_list = fib_path_list_resolve(path_list);
750 return (path_list_index);
754 fib_path_list_create_special (fib_protocol_t nh_proto,
755 fib_path_list_flags_t flags,
758 fib_node_index_t path_index, path_list_index;
759 fib_path_list_t *path_list;
761 path_list = fib_path_list_alloc(&path_list_index);
762 path_list->fpl_flags = flags;
763 path_list->fpl_nh_proto = nh_proto;
766 fib_path_create_special(path_list_index,
767 path_list->fpl_nh_proto,
768 fib_path_list_flags_2_path_flags(flags),
770 vec_add1(path_list->fpl_paths, path_index);
773 * we don't share path-lists. we can do PIC on them so why bother.
775 path_list = fib_path_list_resolve(path_list);
777 return (path_list_index);
781 * fib_path_list_copy_and_path_add
783 * Create a copy of a path-list and append one more path to it.
784 * The path-list returned could either have been newly created, or
785 * can be a shared path-list from the data-base.
788 fib_path_list_copy_and_path_add (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, new_path_index, *orig_path_index;
793 fib_path_list_t *path_list, *orig_path_list;
794 fib_node_index_t path_list_index;
797 ASSERT(1 == vec_len(rpaths));
800 * alloc the new list before we retrieve the old one, lest
801 * the alloc result in a realloc
803 path_list = fib_path_list_alloc(&path_list_index);
805 orig_path_list = fib_path_list_get(orig_path_list_index);
807 FIB_PATH_LIST_DBG(orig_path_list, "copy-add");
809 flags = fib_path_list_flags_fixup(flags);
810 path_list->fpl_flags = flags;
811 path_list->fpl_nh_proto = orig_path_list->fpl_nh_proto;
812 vec_validate(path_list->fpl_paths, vec_len(orig_path_list->fpl_paths));
815 new_path_index = fib_path_create(path_list_index,
816 path_list->fpl_nh_proto,
817 fib_path_list_flags_2_path_flags(flags),
820 vec_foreach (orig_path_index, orig_path_list->fpl_paths)
823 * don't add duplicate paths
824 * In the unlikely event the path is a duplicate, then we'll
825 * find a matching path-list later and this one will be toast.
827 if (0 != fib_path_cmp(new_path_index, *orig_path_index))
829 path_index = fib_path_copy(*orig_path_index, path_list_index);
830 path_list->fpl_paths[pi++] = path_index;
834 _vec_len(path_list->fpl_paths) = vec_len(orig_path_list->fpl_paths);
838 path_list->fpl_paths[pi] = new_path_index;
841 * we sort the paths since the key for the path-list is
842 * the description of the paths it contains. The paths need to
843 * be sorted else this description will differ.
845 vec_sort_with_function(path_list->fpl_paths, fib_path_cmp_for_sort);
847 FIB_PATH_LIST_DBG(path_list, "path-added");
850 * If a shared path list is requested, consult the DB for a match
852 if (path_list->fpl_flags & FIB_PATH_LIST_FLAG_SHARED)
854 fib_node_index_t exist_path_list_index;
856 * check for a matching path-list in the DB.
857 * If we find one then we can return the existing one and destroy the
858 * new one just created.
860 exist_path_list_index = fib_path_list_db_find(path_list);
861 if (FIB_NODE_INDEX_INVALID != exist_path_list_index)
863 fib_path_list_destroy(path_list);
865 path_list_index = exist_path_list_index;
870 * if there was not a matching path-list, then this
871 * new one will need inserting into the DB and resolving.
873 fib_path_list_db_insert(path_list_index);
875 path_list = fib_path_list_resolve(path_list);
881 * no shared path list requested. resolve and use the one
884 path_list = fib_path_list_resolve(path_list);
887 return (path_list_index);
891 * fib_path_list_copy_and_path_remove
893 * Copy the path-list excluding the path passed.
894 * If the path is the last one, then the index reurned will be invalid.
895 * i.e. the path-list is toast.
898 fib_path_list_copy_and_path_remove (fib_node_index_t orig_path_list_index,
899 fib_path_list_flags_t flags,
900 const fib_route_path_t *rpaths)
902 fib_node_index_t path_index, *orig_path_index, path_list_index, tmp_path_index;
903 fib_path_list_t *path_list, *orig_path_list;
906 ASSERT(1 == vec_len(rpaths));
908 path_list = fib_path_list_alloc(&path_list_index);
910 flags = fib_path_list_flags_fixup(flags);
911 orig_path_list = fib_path_list_get(orig_path_list_index);
913 FIB_PATH_LIST_DBG(orig_path_list, "copy-remove");
915 path_list->fpl_flags = flags;
916 path_list->fpl_nh_proto = orig_path_list->fpl_nh_proto;
918 * allocate as many paths as we might need in one go, rather than
919 * using vec_add to do a few at a time.
921 if (vec_len(orig_path_list->fpl_paths) > 1)
923 vec_validate(path_list->fpl_paths, vec_len(orig_path_list->fpl_paths) - 2);
928 * create a representation of the path to be removed, so it
929 * can be used as a comparison object during the copy.
931 tmp_path_index = fib_path_create(path_list_index,
932 path_list->fpl_nh_proto,
933 fib_path_list_flags_2_path_flags(flags),
936 vec_foreach (orig_path_index, orig_path_list->fpl_paths)
938 if (0 != fib_path_cmp(tmp_path_index, *orig_path_index)) {
939 path_index = fib_path_copy(*orig_path_index, path_list_index);
940 if (pi < vec_len(path_list->fpl_paths))
942 path_list->fpl_paths[pi++] = path_index;
947 * this is the unlikely case that the path being
948 * removed does not match one in the path-list, so
949 * we end up with as many paths as we started with.
950 * the paths vector was sized above with the expectation
951 * that we would have 1 less.
953 vec_add1(path_list->fpl_paths, path_index);
959 * done with the temporary now
961 fib_path_destroy(tmp_path_index);
964 * if there are no paths, then the new path-list is aborted
966 if (0 == vec_len(path_list->fpl_paths)) {
967 FIB_PATH_LIST_DBG(path_list, "last-path-removed");
969 fib_path_list_destroy(path_list);
971 path_list_index = FIB_NODE_INDEX_INVALID;
974 * we sort the paths since the key for the path-list is
975 * the description of the paths it contains. The paths need to
976 * be sorted else this description will differ.
978 vec_sort_with_function(path_list->fpl_paths, fib_path_cmp_for_sort);
981 * If a shared path list is requested, consult the DB for a match
983 if (path_list->fpl_flags & FIB_PATH_LIST_FLAG_SHARED)
985 fib_node_index_t exist_path_list_index;
988 * check for a matching path-list in the DB.
989 * If we find one then we can return the existing one and destroy the
990 * new one just created.
992 exist_path_list_index = fib_path_list_db_find(path_list);
993 if (FIB_NODE_INDEX_INVALID != exist_path_list_index)
995 fib_path_list_destroy(path_list);
997 path_list_index = exist_path_list_index;
1002 * if there was not a matching path-list, then this
1003 * new one will need inserting into the DB and resolving.
1005 fib_path_list_db_insert(path_list_index);
1007 path_list = fib_path_list_resolve(path_list);
1013 * no shared path list requested. resolve and use the one
1016 path_list = fib_path_list_resolve(path_list);
1020 return (path_list_index);
1024 * fib_path_list_contribute_forwarding
1026 * Return the index of a load-balance that user of this path-list should
1027 * use for forwarding
1030 fib_path_list_contribute_forwarding (fib_node_index_t path_list_index,
1031 fib_forward_chain_type_t fct,
1034 fib_path_list_t *path_list;
1036 path_list = fib_path_list_get(path_list_index);
1038 fib_path_list_mk_lb(path_list, fct, dpo);
1042 * fib_path_list_get_adj
1044 * Return the index of a adjacency for the first path that user of this
1045 * path-list should use for forwarding
1048 fib_path_list_get_adj (fib_node_index_t path_list_index,
1049 fib_forward_chain_type_t type)
1051 fib_path_list_t *path_list;
1053 path_list = fib_path_list_get(path_list_index);
1054 return (fib_path_get_adj(path_list->fpl_paths[0]));
1058 fib_path_list_recursive_loop_detect (fib_node_index_t path_list_index,
1059 fib_node_index_t **entry_indicies)
1061 fib_node_index_t *path_index;
1062 int is_looped, list_looped;
1063 fib_path_list_t *path_list;
1066 path_list = fib_path_list_get(path_list_index);
1068 vec_foreach (path_index, path_list->fpl_paths)
1070 fib_node_index_t *copy, **copy_ptr;
1073 * we need a copy of the nodes visited so that when we add entries
1074 * we explore on the nth path and a looped is detected, those entries
1075 * are not again searched for n+1 path and so finding a loop that does
1078 copy = vec_dup(*entry_indicies);
1081 is_looped = fib_path_recursive_loop_detect(*path_index, copy_ptr);
1082 list_looped += is_looped;
1085 FIB_PATH_LIST_DBG(path_list, "loop-detect: eval:%d", eval);
1089 path_list->fpl_flags |= FIB_PATH_LIST_FLAG_LOOPED;
1093 path_list->fpl_flags &= ~FIB_PATH_LIST_FLAG_LOOPED;
1096 return (list_looped);
1100 fib_path_list_child_add (fib_node_index_t path_list_index,
1101 fib_node_type_t child_type,
1102 fib_node_index_t child_index)
1104 return (fib_node_child_add(FIB_NODE_TYPE_PATH_LIST,
1111 fib_path_list_child_remove (fib_node_index_t path_list_index,
1114 fib_node_child_remove(FIB_NODE_TYPE_PATH_LIST,
1120 fib_path_list_lock(fib_node_index_t path_list_index)
1122 fib_path_list_t *path_list;
1124 if (FIB_NODE_INDEX_INVALID != path_list_index)
1126 path_list = fib_path_list_get(path_list_index);
1128 fib_node_lock(&path_list->fpl_node);
1129 FIB_PATH_LIST_DBG(path_list, "lock");
1134 fib_path_list_unlock (fib_node_index_t path_list_index)
1136 fib_path_list_t *path_list;
1138 if (FIB_NODE_INDEX_INVALID != path_list_index)
1140 path_list = fib_path_list_get(path_list_index);
1141 FIB_PATH_LIST_DBG(path_list, "unlock");
1143 fib_node_unlock(&path_list->fpl_node);
1148 fib_path_list_pool_size (void)
1150 return (pool_elts(fib_path_list_pool));
1154 fib_path_list_db_size (void)
1156 return (hash_elts(fib_path_list_db));
1160 fib_path_list_walk (fib_node_index_t path_list_index,
1161 fib_path_list_walk_fn_t func,
1164 fib_node_index_t *path_index;
1165 fib_path_list_t *path_list;
1167 path_list = fib_path_list_get(path_list_index);
1169 vec_foreach(path_index, path_list->fpl_paths)
1171 if (!func(path_list_index, *path_index, ctx))
1178 fib_path_list_module_init (void)
1180 fib_node_register_type (FIB_NODE_TYPE_PATH_LIST, &fib_path_list_vft);
1182 fib_path_list_db = hash_create2 (/* elts */ 0,
1184 /* value_bytes */ sizeof (fib_node_index_t),
1185 fib_path_list_db_hash_key_sum,
1186 fib_path_list_db_hash_key_equal,
1187 /* format pair/arg */
1191 static clib_error_t *
1192 show_fib_path_list_command (vlib_main_t * vm,
1193 unformat_input_t * input,
1194 vlib_cli_command_t * cmd)
1196 fib_path_list_t *path_list;
1197 fib_node_index_t pli;
1199 if (unformat (input, "%d", &pli))
1202 * show one in detail
1204 if (!pool_is_free_index(fib_path_list_pool, pli))
1206 path_list = fib_path_list_get(pli);
1207 u8 *s = fib_path_list_format(pli, NULL);
1208 s = format(s, "children:");
1209 s = fib_node_children_format(path_list->fpl_node.fn_children, s);
1210 vlib_cli_output (vm, "%s", s);
1215 vlib_cli_output (vm, "path list %d invalid", pli);
1223 vlib_cli_output (vm, "FIB Path Lists");
1224 pool_foreach(path_list, fib_path_list_pool,
1226 vlib_cli_output (vm, "%U", format_fib_path_list, path_list);
1232 VLIB_CLI_COMMAND (show_fib_path_list, static) = {
1233 .path = "show fib path-lists",
1234 .function = show_fib_path_list_command,
1235 .short_help = "show fib path-lists",