FD.io VPP  v16.12-rc0-308-g931be3a
Vector Packet Processing
fib_path_list.c
Go to the documentation of this file.
1 /*
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:
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
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.
14  */
15 
16 #include <vppinfra/mhash.h>
17 #include <vnet/ip/ip.h>
18 #include <vnet/adj/adj.h>
19 #include <vnet/dpo/load_balance.h>
21 
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>
27 
28 /**
29  * FIB path-list
30  * A representation of the list/set of path trough which a prefix is reachable
31  */
32 typedef struct fib_path_list_t_ {
33  /**
34  * A path-list is a node in the FIB graph.
35  */
37 
38  /**
39  * Flags on the path-list
40  */
42 
43  /**
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.
47  */
49 
50  /**
51  * Vector of paths indicies for all configured paths.
52  * For shareable path-lists this list MUST not change.
53  */
55 
56  /**
57  * the RPF list calculated for this path list
58  */
61 
62 /*
63  * Array of strings/names for the FIB sources
64  */
66 
67 /*
68  * The memory pool from which we allocate all the path-lists
69  */
71 
72 /*
73  * The data-base of shared path-lists
74  */
76 
77 /*
78  * Debug macro
79  */
80 #ifdef FIB_DEBUG
81 #define FIB_PATH_LIST_DBG(_pl, _fmt, _args...) \
82 { \
83  u8 *_tmp = 0; \
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, \
89  ##_args); \
90  vec_free(_tmp); \
91 }
92 #else
93 #define FIB_PATH_LIST_DBG(_pl, _fmt, _args...)
94 #endif
95 
96 static fib_path_list_t *
98 {
99  return (pool_elt_at_index(fib_path_list_pool, index));
100 }
101 
102 static fib_node_t *
104 {
105  return ((fib_node_t*)fib_path_list_get(index));
106 }
107 
108 static fib_path_list_t*
110 {
111 #if CLIB_DEBUG > 0
113 #endif
114  return ((fib_path_list_t*)node);
115 }
116 
117 static fib_node_index_t
119 {
120  return (path_list - fib_path_list_pool);
121 }
122 
123 static u8 *
124 format_fib_path_list (u8 * s, va_list * args)
125 {
127  fib_node_index_t *path_index;
128  fib_path_list_t *path_list;
129 
130  path_list = va_arg (*args, fib_path_list_t *);
131 
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);
135 
136  if (FIB_PATH_LIST_FLAG_NONE != path_list->fpl_flags)
137  {
138  s = format (s, " flags:");
140  {
141  if ((1<<attr) & path_list->fpl_flags)
142  {
143  s = format (s, "%s,", fib_path_list_attr_names[attr]);
144  }
145  }
146  }
147  s = format (s, " %U\n", format_fib_urpf_list, path_list->fpl_urpf);
148 
149  vec_foreach (path_index, path_list->fpl_paths)
150  {
151  s = fib_path_format(*path_index, s);
152  s = format(s, "\n");
153  }
154 
155  return (s);
156 }
157 
158 u8 *
160  u32 indent,
161  u8 * s)
162 {
163  fib_path_list_t *path_list;
164  u32 i;
165 
166  path_list = fib_path_list_get(path_list_index);
167 
168  vec_foreach_index (i, path_list->fpl_paths)
169  {
170  s = fib_path_adj_format(path_list->fpl_paths[i],
171  indent, s);
172  }
173 
174  return (s);
175 }
176 
177 
178 u8 *
180  u8 * s)
181 {
182  fib_path_list_t *path_list;
183 
184  path_list = fib_path_list_get(path_list_index);
185 
186  return (format(s, "%U", format_fib_path_list, path_list));
187 }
188 
189 static uword
191 {
192  uword old_path_list_hash, new_path_list_hash, path_hash;
193  fib_node_index_t *path_index;
194 
195  ASSERT(path_list);
196 
197  new_path_list_hash = old_path_list_hash = vec_len(path_list->fpl_paths);
198 
199  vec_foreach (path_index, path_list->fpl_paths)
200  {
201  path_hash = fib_path_hash(*path_index);
202 #if uword_bits == 64
203  hash_mix64(path_hash, old_path_list_hash, new_path_list_hash);
204 #else
205  hash_mix32(path_hash, old_path_list_hash, new_path_list_hash);
206 #endif
207  }
208 
209  return (new_path_list_hash);
210 }
211 
214 {
215  return 1 + 2*index;
216 }
217 
220 {
221  return key & 1;
222 }
223 
226 {
228  return key / 2;
229 }
230 
231 static fib_path_list_t*
233 {
234  fib_path_list_t *path_list;
235 
237  {
238  fib_node_index_t path_list_index;
239 
240  path_list_index = fib_path_list_db_hash_key_2_index(key);
241  path_list = fib_path_list_get(path_list_index);
242  }
243  else
244  {
245  path_list = uword_to_pointer (key, fib_path_list_t *);
246  }
247 
248  return (path_list);
249 }
250 
251 static uword
253  uword key)
254 {
255  fib_path_list_t *path_list;
256 
257  path_list = fib_path_list_db_get_from_hash_key(key);
258 
259  return (fib_path_list_hash(path_list));
260 }
261 
262 static uword
264  uword key1,
265  uword key2)
266 {
267  fib_path_list_t *path_list1, *path_list2;
268 
269  path_list1 = fib_path_list_db_get_from_hash_key(key1);
270  path_list2 = fib_path_list_db_get_from_hash_key(key2);
271 
272  return (fib_path_list_hash(path_list1) ==
273  fib_path_list_hash(path_list2));
274 }
275 
276 static fib_node_index_t
278 {
279  uword *p;
280 
281  p = hash_get(fib_path_list_db, path_list);
282 
283  if (NULL != p)
284  {
285  return p[0];
286  }
287 
288  return (FIB_NODE_INDEX_INVALID);
289 }
290 
291 static void
293 {
294  fib_path_list_t *path_list;
295 
296  path_list = fib_path_list_get(path_list_index);
297 
299 
301  fib_path_list_db_hash_key_from_index(path_list_index),
302  path_list_index);
303 
304  FIB_PATH_LIST_DBG(path_list, "DB-inserted");
305 }
306 
307 static void
309 {
310  fib_path_list_t *path_list;
311 
312  path_list = fib_path_list_get(path_list_index);
313 
315 
317  fib_path_list_db_hash_key_from_index(path_list_index));
318 
319  FIB_PATH_LIST_DBG(path_list, "DB-removed");
320 }
321 
322 static void
324 {
325  fib_node_index_t *path_index;
326 
327  FIB_PATH_LIST_DBG(path_list, "destroy");
328 
329  vec_foreach (path_index, path_list->fpl_paths)
330  {
331  fib_path_destroy(*path_index);
332  }
333 
334  vec_free(path_list->fpl_paths);
335  fib_urpf_list_unlock(path_list->fpl_urpf);
336 
337  fib_node_deinit(&path_list->fpl_node);
338  pool_put(fib_path_list_pool, path_list);
339 }
340 
341 static void
343 {
344  fib_path_list_t *path_list;
345 
346  path_list = fib_path_list_from_fib_node(node);
347 
348  FIB_PATH_LIST_DBG(path_list, "last-lock");
349 
350  if (path_list->fpl_flags & FIB_PATH_LIST_FLAG_SHARED)
351  {
353  }
354  fib_path_list_destroy(path_list);
355 }
356 
357 /*
358  * fib_path_mk_lb
359  *
360  * update the multipath adj this path-list will contribute to its
361  * children's forwarding.
362  */
363 static void
366  dpo_id_t *dpo)
367 {
368  load_balance_path_t *hash_key;
369  fib_node_index_t *path_index;
370 
371  hash_key = NULL;
372 
373  if (!dpo_id_is_valid(dpo))
374  {
375  /*
376  * first time create
377  */
378  dpo_set(dpo,
383  0 /* FIXME FLOW HASH */));
384  }
385 
386  /*
387  * We gather the DPOs from resolved paths.
388  */
389  vec_foreach (path_index, path_list->fpl_paths)
390  {
392  *path_index,
393  fct,
394  hash_key);
395  }
396 
397  /*
398  * Path-list load-balances, which if used, would be shared and hence
399  * never need a load-balance map.
400  */
402 
403  FIB_PATH_LIST_DBG(path_list, "mk lb: %d", dpo->dpoi_index);
404 
405  vec_free(hash_key);
406 }
407 
408 /**
409  * @brief [re]build the path list's uRPF list
410  */
411 static void
413 {
414  fib_node_index_t *path_index;
415 
416  /*
417  * ditch the old one. by iterating through all paths we are going
418  * to re-find all the adjs that were in the old one anyway. If we
419  * keep the old one, then the |sort|uniq requires more work.
420  * All users of the RPF list have their own lock, so we can release
421  * immediately.
422  */
423  fib_urpf_list_unlock(path_list->fpl_urpf);
424  path_list->fpl_urpf = fib_urpf_list_alloc_and_lock();
425 
426  vec_foreach (path_index, path_list->fpl_paths)
427  {
428  fib_path_contribute_urpf(*path_index, path_list->fpl_urpf);
429  }
430 
431  fib_urpf_list_bake(path_list->fpl_urpf);
432 }
433 
434 /**
435  * @brief Contribute (add) this path list's uRPF list. This allows the child
436  * to construct an aggregate list.
437  */
438 void
440  index_t urpf)
441 {
442  fib_path_list_t *path_list;
443 
444  path_list = fib_path_list_get(path_list_index);
445 
446  fib_urpf_list_combine(urpf, path_list->fpl_urpf);
447 }
448 
449 /**
450  * @brief Return the the child the RPF list pre-built for this path list
451  */
452 index_t
454 {
455  fib_path_list_t *path_list;
456 
457  path_list = fib_path_list_get(path_list_index);
458 
459  return (path_list->fpl_urpf);
460 }
461 
462 /*
463  * fib_path_list_back_walk
464  *
465  * Called from one of this path-list's paths to progate
466  * a back walk
467  */
468 void
471 {
472  fib_path_list_t *path_list;
473 
474  path_list = fib_path_list_get(path_list_index);
475 
476  fib_path_list_mk_urpf(path_list);
477 
478  /*
479  * propagate the backwalk further
480  */
481  if (32 >= fib_node_list_get_size(path_list->fpl_node.fn_children))
482  {
483  /*
484  * only a few children. continue the walk synchronously
485  */
486  fib_walk_sync(FIB_NODE_TYPE_PATH_LIST, path_list_index, ctx);
487  }
488  else
489  {
490  /*
491  * many children. schedule a async walk
492  */
494  path_list_index,
496  ctx);
497  }
498 }
499 
500 /*
501  * fib_path_list_back_walk_notify
502  *
503  * A back walk has reach this path-list.
504  */
508 {
509  /*
510  * the path-list is not a direct child of any other node type
511  * paths, which do not change thier to-list-mapping, save the
512  * list they are a member of, and invoke the BW function directly.
513  */
514  ASSERT(0);
515 
517 }
518 
519 /*
520  * Display the path-list memory usage
521  */
522 static void
524 {
525  fib_show_memory_usage("Path-list",
526  pool_elts(fib_path_list_pool),
527  pool_len(fib_path_list_pool),
528  sizeof(fib_path_list_t));
530 }
531 
532 /*
533  * The FIB path-list's graph node virtual function table
534  */
535 static const fib_node_vft_t fib_path_list_vft = {
537  .fnv_last_lock = fib_path_list_last_lock_gone,
538  .fnv_back_walk = fib_path_list_back_walk_notify,
539  .fnv_mem_show = fib_path_list_memory_show,
540 };
541 
542 static fib_path_list_t *
544 {
545  fib_path_list_t *path_list;
546 
547  pool_get(fib_path_list_pool, path_list);
548  memset(path_list, 0, sizeof(*path_list));
549 
550  fib_node_init(&path_list->fpl_node,
552  path_list->fpl_urpf = INDEX_INVALID;
553 
554  if (NULL != path_list_index)
555  {
556  *path_list_index = fib_path_list_get_index(path_list);
557  }
558 
559  FIB_PATH_LIST_DBG(path_list, "alloc");
560 
561  return (path_list);
562 }
563 
564 static fib_path_list_t *
566 {
567  fib_node_index_t *path_index, *paths, path_list_index;
568 
570 
571  /*
572  * resolving a path-list is a recursive action. this means more path
573  * lists can be created during this call, and hence this path-list
574  * can be realloc'd. so we work with copies.
575  * this function is called only once per-path list, so its no great overhead.
576  */
577  path_list_index = fib_path_list_get_index(path_list);
578  paths = vec_dup(path_list->fpl_paths);
579 
580  vec_foreach (path_index, paths)
581  {
582  fib_path_resolve(*path_index);
583  }
584 
585  vec_free(paths);
586  path_list = fib_path_list_get(path_list_index);
587 
588  FIB_PATH_LIST_DBG(path_list, "resovled");
589  fib_path_list_mk_urpf(path_list);
590 
591  return (path_list);
592 }
593 
594 u32
596 {
597  fib_node_index_t *path_index;
598  fib_path_list_t *path_list;
599  u32 sw_if_index;
600 
601  path_list = fib_path_list_get(path_list_index);
602 
603  sw_if_index = ~0;
604  vec_foreach (path_index, path_list->fpl_paths)
605  {
606  sw_if_index = fib_path_get_resolving_interface(*path_index);
607  if (~0 != sw_if_index)
608  {
609  return (sw_if_index);
610  }
611  }
612 
613  return (sw_if_index);
614 }
615 
616 int
618 {
619  fib_path_list_t *path_list;
620 
621  path_list = fib_path_list_get(path_list_index);
622 
623  return (path_list->fpl_flags & FIB_PATH_LIST_FLAG_LOOPED);
624 }
625 
626 static fib_path_cfg_flags_t
628 {
630 
631  if (plf & FIB_PATH_LIST_FLAG_LOCAL)
632  {
634  }
635  if (plf & FIB_PATH_LIST_FLAG_DROP)
636  {
638  }
640  {
642  }
643 
644  return (pf);
645 }
646 
649 {
650  /*
651  * we do no share drop nor exclusive path-lists
652  */
653  if (flags & FIB_PATH_LIST_FLAG_DROP ||
655  {
656  flags &= ~FIB_PATH_LIST_FLAG_SHARED;
657  }
658 
659  return (flags);
660 }
661 
664  const fib_route_path_t *rpaths)
665 {
666  fib_node_index_t path_list_index, old_path_list_index;
667  fib_path_list_t *path_list;
668  int i;
669 
670  flags = fib_path_list_flags_fixup(flags);
671  path_list = fib_path_list_alloc(&path_list_index);
672  path_list->fpl_flags = flags;
673  /*
674  * we'll assume for now all paths are the same next-hop protocol
675  */
676  path_list->fpl_nh_proto = rpaths[0].frp_proto;
677 
678  vec_foreach_index(i, rpaths)
679  {
680  vec_add1(path_list->fpl_paths,
681  fib_path_create(path_list_index,
682  path_list->fpl_nh_proto,
684  &rpaths[i]));
685  }
686 
687  /*
688  * If a shared path list is requested, consult the DB for a match
689  */
690  if (flags & FIB_PATH_LIST_FLAG_SHARED)
691  {
692  /*
693  * check for a matching path-list in the DB.
694  * If we find one then we can return the existing one and destroy the
695  * new one just created.
696  */
697  old_path_list_index = fib_path_list_db_find(path_list);
698  if (FIB_NODE_INDEX_INVALID != old_path_list_index)
699  {
700  fib_path_list_destroy(path_list);
701 
702  path_list_index = old_path_list_index;
703  }
704  else
705  {
706  /*
707  * if there was not a matching path-list, then this
708  * new one will need inserting into the DB and resolving.
709  */
710  fib_path_list_db_insert(path_list_index);
711  path_list = fib_path_list_resolve(path_list);
712  }
713  }
714  else
715  {
716  /*
717  * no shared path list requested. resolve and use the one
718  * just created.
719  */
720  path_list = fib_path_list_resolve(path_list);
721  }
722 
723  return (path_list_index);
724 }
725 
729  const dpo_id_t *dpo)
730 {
731  fib_node_index_t path_index, path_list_index;
732  fib_path_list_t *path_list;
733 
734  path_list = fib_path_list_alloc(&path_list_index);
735  path_list->fpl_flags = flags;
736  path_list->fpl_nh_proto = nh_proto;
737 
738  path_index =
739  fib_path_create_special(path_list_index,
740  path_list->fpl_nh_proto,
742  dpo);
743  vec_add1(path_list->fpl_paths, path_index);
744 
745  /*
746  * we don't share path-lists. we can do PIC on them so why bother.
747  */
748  path_list = fib_path_list_resolve(path_list);
749 
750  return (path_list_index);
751 }
752 
753 /*
754  * fib_path_list_copy_and_path_add
755  *
756  * Create a copy of a path-list and append one more path to it.
757  * The path-list returned could either have been newly created, or
758  * can be a shared path-list from the data-base.
759  */
763  const fib_route_path_t *rpaths)
764 {
765  fib_node_index_t path_index, path_list_index, *orig_path_index;
766  fib_path_list_t *path_list, *orig_path_list;
767  fib_node_index_t pi;
768 
769  ASSERT(1 == vec_len(rpaths));
770 
771  /*
772  * alloc the new list before we retrieve the old one, lest
773  * the alloc result in a realloc
774  */
775  path_list = fib_path_list_alloc(&path_list_index);
776 
777  orig_path_list = fib_path_list_get(orig_path_list_index);
778 
779  FIB_PATH_LIST_DBG(orig_path_list, "copy-add");
780 
781  flags = fib_path_list_flags_fixup(flags);
782  path_list->fpl_flags = flags;
783  path_list->fpl_nh_proto = orig_path_list->fpl_nh_proto;
784  vec_validate(path_list->fpl_paths, vec_len(orig_path_list->fpl_paths));
785  pi = 0;
786 
787  vec_foreach (orig_path_index, orig_path_list->fpl_paths)
788  {
789  path_index = fib_path_copy(*orig_path_index, path_list_index);
790  path_list->fpl_paths[pi++] = path_index;
791  }
792  path_index = fib_path_create(path_list_index,
793  path_list->fpl_nh_proto,
795  rpaths);
796  path_list->fpl_paths[pi] = path_index;
797 
798  /*
799  * we sort the paths since the key for the path-list is
800  * the description of the paths it contains. The paths need to
801  * be sorted else this description will differ.
802  */
804 
805  FIB_PATH_LIST_DBG(path_list, "path-added");
806 
807  /*
808  * If a shared path list is requested, consult the DB for a match
809  */
810  if (path_list->fpl_flags & FIB_PATH_LIST_FLAG_SHARED)
811  {
812  fib_node_index_t exist_path_list_index;
813  /*
814  * check for a matching path-list in the DB.
815  * If we find one then we can return the existing one and destroy the
816  * new one just created.
817  */
818  exist_path_list_index = fib_path_list_db_find(path_list);
819  if (FIB_NODE_INDEX_INVALID != exist_path_list_index)
820  {
821  fib_path_list_destroy(path_list);
822 
823  path_list_index = exist_path_list_index;
824  }
825  else
826  {
827  /*
828  * if there was not a matching path-list, then this
829  * new one will need inserting into the DB and resolving.
830  */
831  fib_path_list_db_insert(path_list_index);
832 
833  path_list = fib_path_list_resolve(path_list);
834  }
835  }
836  else
837  {
838  /*
839  * no shared path list requested. resolve and use the one
840  * just created.
841  */
842  path_list = fib_path_list_resolve(path_list);
843  }
844 
845  return (path_list_index);
846 }
847 
848 /*
849  * fib_path_list_copy_and_path_remove
850  *
851  * Copy the path-list excluding the path passed.
852  * If the path is the last one, then the index reurned will be invalid.
853  * i.e. the path-list is toast.
854  */
858  const fib_route_path_t *rpaths)
859 {
860  fib_node_index_t path_index, *orig_path_index, path_list_index, tmp_path_index;
861  fib_path_list_t *path_list, *orig_path_list;
862  fib_node_index_t pi;
863 
864  ASSERT(1 == vec_len(rpaths));
865 
866  path_list = fib_path_list_alloc(&path_list_index);
867 
868  flags = fib_path_list_flags_fixup(flags);
869  orig_path_list = fib_path_list_get(orig_path_list_index);
870 
871  FIB_PATH_LIST_DBG(orig_path_list, "copy-remove");
872 
873  path_list->fpl_flags = flags;
874  path_list->fpl_nh_proto = orig_path_list->fpl_nh_proto;
875  /*
876  * allocate as many paths as we might need in one go, rather than
877  * using vec_add to do a few at a time.
878  */
879  if (vec_len(orig_path_list->fpl_paths) > 1)
880  {
881  vec_validate(path_list->fpl_paths, vec_len(orig_path_list->fpl_paths) - 2);
882  }
883  pi = 0;
884 
885  /*
886  * create a representation of the path to be removed, so it
887  * can be used as a comparison object during the copy.
888  */
889  tmp_path_index = fib_path_create(path_list_index,
890  path_list->fpl_nh_proto,
892  rpaths);
893 
894  vec_foreach (orig_path_index, orig_path_list->fpl_paths)
895  {
896  if (0 != fib_path_cmp(tmp_path_index, *orig_path_index)) {
897  path_index = fib_path_copy(*orig_path_index, path_list_index);
898  if (pi < vec_len(path_list->fpl_paths))
899  {
900  path_list->fpl_paths[pi++] = path_index;
901  }
902  else
903  {
904  /*
905  * this is the unlikely case that the path being
906  * removed does not match one in the path-list, so
907  * we end up with as many paths as we started with.
908  * the paths vector was sized above with the expectation
909  * that we would have 1 less.
910  */
911  vec_add1(path_list->fpl_paths, path_index);
912  }
913  }
914  }
915 
916  /*
917  * done with the temporary now
918  */
919  fib_path_destroy(tmp_path_index);
920 
921  /*
922  * if there are no paths, then the new path-list is aborted
923  */
924  if (0 == vec_len(path_list->fpl_paths)) {
925  FIB_PATH_LIST_DBG(path_list, "last-path-removed");
926 
927  fib_path_list_destroy(path_list);
928 
929  path_list_index = FIB_NODE_INDEX_INVALID;
930  } else {
931  /*
932  * we sort the paths since the key for the path-list is
933  * the description of the paths it contains. The paths need to
934  * be sorted else this description will differ.
935  */
937 
938  /*
939  * If a shared path list is requested, consult the DB for a match
940  */
941  if (path_list->fpl_flags & FIB_PATH_LIST_FLAG_SHARED)
942  {
943  fib_node_index_t exist_path_list_index;
944 
945  /*
946  * check for a matching path-list in the DB.
947  * If we find one then we can return the existing one and destroy the
948  * new one just created.
949  */
950  exist_path_list_index = fib_path_list_db_find(path_list);
951  if (FIB_NODE_INDEX_INVALID != exist_path_list_index)
952  {
953  fib_path_list_destroy(path_list);
954 
955  path_list_index = exist_path_list_index;
956  }
957  else
958  {
959  /*
960  * if there was not a matching path-list, then this
961  * new one will need inserting into the DB and resolving.
962  */
963  fib_path_list_db_insert(path_list_index);
964 
965  path_list = fib_path_list_resolve(path_list);
966  }
967  }
968  else
969  {
970  /*
971  * no shared path list requested. resolve and use the one
972  * just created.
973  */
974  path_list = fib_path_list_resolve(path_list);
975  }
976  }
977 
978  return (path_list_index);
979 }
980 
981 /*
982  * fib_path_list_contribute_forwarding
983  *
984  * Return the index of a load-balance that user of this path-list should
985  * use for forwarding
986  */
987 void
990  dpo_id_t *dpo)
991 {
992  fib_path_list_t *path_list;
993 
994  path_list = fib_path_list_get(path_list_index);
995 
996  fib_path_list_mk_lb(path_list, type, dpo);
997 }
998 
999 /*
1000  * fib_path_list_get_adj
1001  *
1002  * Return the index of a adjacency for the first path that user of this
1003  * path-list should use for forwarding
1004  */
1008 {
1009  fib_path_list_t *path_list;
1010 
1011  path_list = fib_path_list_get(path_list_index);
1012  return (fib_path_get_adj(path_list->fpl_paths[0]));
1013 }
1014 
1015 int
1017  fib_node_index_t **entry_indicies)
1018 {
1019  fib_node_index_t *path_index;
1020  int is_looped, list_looped;
1021  fib_path_list_t *path_list;
1022 
1023  list_looped = 0;
1024  path_list = fib_path_list_get(path_list_index);
1025 
1026  vec_foreach (path_index, path_list->fpl_paths)
1027  {
1028  fib_node_index_t *copy, **copy_ptr;
1029 
1030  /*
1031  * we need a copy of the nodes visited so that when we add entries
1032  * we explore on the nth path and a looped is detected, those entries
1033  * are not again searched for n+1 path and so finding a loop that does
1034  * not exist.
1035  */
1036  copy = vec_dup(*entry_indicies);
1037  copy_ptr = &copy;
1038 
1039  is_looped = fib_path_recursive_loop_detect(*path_index, copy_ptr);
1040  list_looped += is_looped;
1041  }
1042 
1043  FIB_PATH_LIST_DBG(path_list, "loop-detect: eval:%d", eval);
1044 
1045  if (list_looped)
1046  {
1047  path_list->fpl_flags |= FIB_PATH_LIST_FLAG_LOOPED;
1048  }
1049  else
1050  {
1051  path_list->fpl_flags &= ~FIB_PATH_LIST_FLAG_LOOPED;
1052  }
1053 
1054  return (list_looped);
1055 }
1056 
1057 u32
1059  fib_node_type_t child_type,
1060  fib_node_index_t child_index)
1061 {
1063  path_list_index,
1064  child_type,
1065  child_index));
1066 }
1067 
1068 void
1070  u32 si)
1071 {
1073  path_list_index,
1074  si);
1075 }
1076 
1077 void
1079 {
1080  fib_path_list_t *path_list;
1081 
1082  if (FIB_NODE_INDEX_INVALID != path_list_index)
1083  {
1084  path_list = fib_path_list_get(path_list_index);
1085 
1086  fib_node_lock(&path_list->fpl_node);
1087  FIB_PATH_LIST_DBG(path_list, "lock");
1088  }
1089 }
1090 
1091 void
1093 {
1094  fib_path_list_t *path_list;
1095 
1096  if (FIB_NODE_INDEX_INVALID != path_list_index)
1097  {
1098  path_list = fib_path_list_get(path_list_index);
1099  FIB_PATH_LIST_DBG(path_list, "unlock");
1100 
1101  fib_node_unlock(&path_list->fpl_node);
1102  }
1103 }
1104 
1105 u32
1107 {
1108  return (pool_elts(fib_path_list_pool));
1109 }
1110 
1111 u32
1113 {
1114  return (hash_elts(fib_path_list_db));
1115 }
1116 
1117 void
1120  void *ctx)
1121 {
1122  fib_node_index_t *path_index;
1123  fib_path_list_t *path_list;
1124 
1125  path_list = fib_path_list_get(path_list_index);
1126 
1127  vec_foreach(path_index, path_list->fpl_paths)
1128  {
1129  if (!func(path_list_index, *path_index, ctx))
1130  break;
1131  }
1132 }
1133 
1134 
1135 void
1137 {
1138  fib_node_register_type (FIB_NODE_TYPE_PATH_LIST, &fib_path_list_vft);
1139 
1140  fib_path_list_db = hash_create2 (/* elts */ 0,
1141  /* user */ 0,
1142  /* value_bytes */ sizeof (fib_node_index_t),
1145  /* format pair/arg */
1146  0, 0);
1147 }
1148 
1149 static clib_error_t *
1151  unformat_input_t * input,
1152  vlib_cli_command_t * cmd)
1153 {
1154  fib_path_list_t *path_list;
1155  fib_node_index_t pli;
1156 
1157  if (unformat (input, "%d", &pli))
1158  {
1159  /*
1160  * show one in detail
1161  */
1162  if (!pool_is_free_index(fib_path_list_pool, pli))
1163  {
1164  path_list = fib_path_list_get(pli);
1165  u8 *s = fib_path_list_format(pli, NULL);
1166  s = format(s, "children:");
1167  s = fib_node_children_format(path_list->fpl_node.fn_children, s);
1168  vlib_cli_output (vm, "%s", s);
1169  vec_free(s);
1170  }
1171  else
1172  {
1173  vlib_cli_output (vm, "path list %d invalid", pli);
1174  }
1175  }
1176  else
1177  {
1178  /*
1179  * show all
1180  */
1181  vlib_cli_output (vm, "FIB Path Lists");
1182  pool_foreach(path_list, fib_path_list_pool,
1183  ({
1184  vlib_cli_output (vm, "%U", format_fib_path_list, path_list);
1185  }));
1186  }
1187  return (NULL);
1188 }
1189 
1190 VLIB_CLI_COMMAND (show_fib_path_list, static) = {
1191  .path = "show fib path-lists",
1192  .function = show_fib_path_list_command,
1193  .short_help = "show fib path-lists",
1194 };
#define vec_validate(V, I)
Make sure vector is long enough for given index (no header, unspecified alignment) ...
Definition: vec.h:396
static fib_node_index_t fib_path_list_db_find(fib_path_list_t *path_list)
static void fib_path_list_db_remove(fib_node_index_t path_list_index)
static clib_error_t * show_fib_path_list_command(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
fib_protocol_t frp_proto
The protocol of the address below.
Definition: fib_types.h:288
int fib_path_resolve(fib_node_index_t path_index)
Definition: fib_path.c:1366
void fib_path_list_module_init(void)
#define vec_foreach_index(var, v)
Iterate over vector indices.
#define hash_set(h, key, value)
Definition: hash.h:254
sll srl srl sll sra u16x4 i
Definition: vector_sse2.h:343
uword fib_path_hash(fib_node_index_t path_index)
Definition: fib_path.c:1085
uword unformat(unformat_input_t *i, char *fmt,...)
Definition: unformat.c:966
void fib_path_list_child_remove(fib_node_index_t path_list_index, u32 si)
enum fib_node_type_t_ fib_node_type_t
The types of nodes in a FIB graph.
#define hash_unset(h, key)
Definition: hash.h:260
void fib_path_contribute_urpf(fib_node_index_t path_index, index_t urpf)
Contribute the path&#39;s adjacency to the list passed.
Definition: fib_path.c:1576
A representation of a path as described by a route producer.
Definition: fib_types.h:283
static uword fib_path_list_db_hash_key_equal(hash_t *h, uword key1, uword key2)
bad routing header type(not 4)") sr_error (NO_MORE_SEGMENTS
adj_index_t fib_path_list_get_adj(fib_node_index_t path_list_index, fib_forward_chain_type_t type)
void fib_path_list_contribute_urpf(fib_node_index_t path_list_index, index_t urpf)
Contribute (add) this path list&#39;s uRPF list.
int fib_path_cmp(fib_node_index_t pi1, fib_node_index_t pi2)
Definition: fib_path.c:1193
void fib_node_init(fib_node_t *node, fib_node_type_t type)
Definition: fib_node.c:172
u32 fib_path_list_get_resolving_interface(fib_node_index_t path_list_index)
static int dpo_id_is_valid(const dpo_id_t *dpoi)
Return true if the DPO object is valid, i.e.
Definition: dpo.h:170
u8 * format_fib_urpf_list(u8 *s, va_list args)
Definition: fib_urpf_list.c:25
#define NULL
Definition: clib.h:55
enum fib_node_back_walk_rc_t_ fib_node_back_walk_rc_t
Return code from a back walk function.
fib_node_index_t * fpl_paths
Vector of paths indicies for all configured paths.
Definition: fib_path_list.c:54
void fib_urpf_list_show_mem(void)
dpo_proto_t fib_forw_chain_type_to_dpo_proto(fib_forward_chain_type_t fct)
Convert from a chain type to the DPO proto it will install.
Definition: fib_types.c:313
u32 index_t
A Data-Path Object is an object that represents actions that are applied to packets are they are swit...
Definition: dpo.h:41
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
Definition: vec.h:482
static uword * fib_path_list_db
Definition: fib_path_list.c:75
void fib_path_list_walk(fib_node_index_t path_list_index, fib_path_list_walk_fn_t func, void *ctx)
void fib_node_deinit(fib_node_t *node)
Definition: fib_node.c:187
void fib_walk_async(fib_node_type_t parent_type, fib_node_index_t parent_index, fib_walk_priority_t prio, fib_node_back_walk_ctx_t *ctx)
Definition: fib_walk.c:587
static uword fib_path_list_db_hash_key_from_index(uword index)
u8 * fib_path_adj_format(fib_node_index_t pi, u32 indent, u8 *s)
Definition: fib_path.c:468
#define FOR_EACH_PATH_LIST_ATTRIBUTE(_item)
Definition: fib_path_list.h:88
#define pool_get(P, E)
Allocate an object E from a pool P (unspecified alignment).
Definition: pool.h:200
int fib_path_cmp_for_sort(void *v1, void *v2)
Definition: fib_path.c:1175
u32 fib_path_list_child_add(fib_node_index_t path_list_index, fib_node_type_t child_type, fib_node_index_t child_index)
static void fib_path_list_mk_urpf(fib_path_list_t *path_list)
[re]build the path list&#39;s uRPF list
#define pool_len(p)
Number of elements in pool vector.
Definition: pool.h:121
FIB path-list A representation of the list/set of path trough which a prefix is reachable.
Definition: fib_path_list.c:32
static fib_path_list_t * fib_path_list_pool
Definition: fib_path_list.c:70
enum fib_protocol_t_ fib_protocol_t
Protocol Type.
load_balance_path_t * fib_path_append_nh_for_multipath_hash(fib_node_index_t path_index, fib_forward_chain_type_t fct, load_balance_path_t *hash_key)
Definition: fib_path.c:1731
u32 fib_node_child_add(fib_node_type_t parent_type, fib_node_index_t parent_index, fib_node_type_t type, fib_node_index_t index)
Definition: fib_node.c:96
static const char * fib_path_list_attr_names[]
Definition: fib_path_list.c:65
void fib_node_register_type(fib_node_type_t type, const fib_node_vft_t *vft)
fib_node_register_type
Definition: fib_node.c:58
index_t load_balance_create(u32 n_buckets, dpo_proto_t lb_proto, flow_hash_config_t fhc)
Definition: load_balance.c:192
fib_node_t fpl_node
A path-list is a node in the FIB graph.
Definition: fib_path_list.c:36
fib_node_index_t fib_path_create(fib_node_index_t pl_index, fib_protocol_t nh_proto, fib_path_cfg_flags_t flags, const fib_route_path_t *rpath)
Definition: fib_path.c:905
static uword fib_path_list_db_hash_key_is_index(uword key)
#define pool_foreach(VAR, POOL, BODY)
Iterate through pool.
Definition: pool.h:348
#define always_inline
Definition: clib.h:84
void fib_walk_sync(fib_node_type_t parent_type, fib_node_index_t parent_index, fib_node_back_walk_ctx_t *ctx)
Back walk all the children of a FIB node.
Definition: fib_walk.c:624
index_t fib_urpf_list_alloc_and_lock(void)
Definition: fib_urpf_list.c:47
void load_balance_multipath_update(const dpo_id_t *dpo, load_balance_path_t *raw_next_hops, load_balance_flags_t flags)
Definition: load_balance.c:456
fib_node_index_t fib_path_create_special(fib_node_index_t pl_index, fib_protocol_t nh_proto, fib_path_cfg_flags_t flags, const dpo_id_t *dpo)
Definition: fib_path.c:986
fib_node_index_t fib_path_copy(fib_node_index_t path_index, fib_node_index_t path_list_index)
Definition: fib_path.c:1031
static void fib_path_list_destroy(fib_path_list_t *path_list)
void fib_show_memory_usage(const char *name, u32 in_use_elts, u32 allocd_elts, size_t size_elt)
Show the memory usage for a type.
Definition: fib_node.c:210
static uword fib_path_list_hash(fib_path_list_t *path_list)
enum fib_path_list_attribute_t_ fib_path_list_attribute_t
Enumeration of path-list flags.
static fib_path_list_t * fib_path_list_alloc(fib_node_index_t *path_list_index)
u32 fib_path_list_db_size(void)
fib_node_index_t fib_path_list_copy_and_path_add(fib_node_index_t orig_path_list_index, fib_path_list_flags_t flags, const fib_route_path_t *rpaths)
The identity of a DPO is a combination of its type and its instance number/index of objects of that t...
Definition: dpo.h:138
static uword fib_path_list_db_hash_key_2_index(uword key)
#define hash_get(h, key)
Definition: hash.h:248
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
Definition: pool.h:369
fib_node_index_t fib_path_list_create(fib_path_list_flags_t flags, const fib_route_path_t *rpaths)
#define FIB_PATH_LIST_ATTRIBUTES
Definition: fib_path_list.h:79
static fib_node_back_walk_rc_t fib_path_list_back_walk_notify(fib_node_t *node, fib_node_back_walk_ctx_t *ctx)
void fib_node_lock(fib_node_t *node)
Definition: fib_node.c:193
load-balancing over a choice of [un]equal cost paths
Definition: dpo.h:102
adj_index_t fib_path_get_adj(fib_node_index_t path_index)
Definition: fib_path.c:1543
#define pool_put(P, E)
Free an object E in pool P.
Definition: pool.h:214
#define vec_dup(V)
Return copy of vector (no header, no alignment)
Definition: vec.h:334
void fib_path_list_lock(fib_node_index_t path_list_index)
fib_node_type_t fn_type
The node&#39;s type.
Definition: fib_node.h:247
An node in the FIB graph.
Definition: fib_node.h:242
void fib_node_unlock(fib_node_t *node)
Definition: fib_node.c:199
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
Definition: cli.c:575
fib_path_list_flags_t fpl_flags
Flags on the path-list.
Definition: fib_path_list.c:41
#define uword_to_pointer(u, type)
Definition: types.h:136
fib_node_index_t fib_path_list_copy_and_path_remove(fib_node_index_t orig_path_list_index, fib_path_list_flags_t flags, const fib_route_path_t *rpaths)
fib_node_list_t fn_children
Vector of nodes that depend upon/use/share this node.
Definition: fib_node.h:259
static void fib_path_list_last_lock_gone(fib_node_t *node)
#define hash_mix64(a0, b0, c0)
Definition: hash.h:507
u8 * fib_path_format(fib_node_index_t pi, u8 *s)
Definition: fib_path.c:457
#define vec_free(V)
Free vector&#39;s memory (no header).
Definition: vec.h:300
#define FIB_PATH_LIST_DBG(_pl, _fmt, _args...)
Definition: fib_path_list.c:93
void fib_urpf_list_bake(index_t ui)
Convert the uRPF list from the itf set obtained during the walk to a unique list. ...
static u8 * format_fib_path_list(u8 *s, va_list *args)
static fib_path_cfg_flags_t fib_path_list_flags_2_path_flags(fib_path_list_flags_t plf)
fib_node_get_t fnv_get
Definition: fib_node.h:230
#define hash_mix32(a0, b0, c0)
Definition: hash.h:515
u32 fib_node_index_t
A typedef of a node index.
Definition: fib_types.h:28
#define pool_is_free_index(P, I)
Use free bitmap to query whether given index is free.
Definition: pool.h:211
u32 adj_index_t
An index for adjacencies.
Definition: adj_types.h:30
int(* fib_path_list_walk_fn_t)(fib_node_index_t pl_index, fib_node_index_t path_index, void *ctx)
A callback function type for walking a path-list&#39;s paths.
fib_node_index_t fpl_urpf
the RPF list calculated for this path list
Definition: fib_path_list.c:59
static fib_path_list_t * fib_path_list_get(fib_node_index_t index)
Definition: fib_path_list.c:97
void dpo_set(dpo_id_t *dpo, dpo_type_t type, dpo_proto_t proto, index_t index)
Set/create a DPO ID The DPO will be locked.
Definition: dpo.c:134
void fib_path_list_unlock(fib_node_index_t path_list_index)
#define hash_create2(_elts, _user, _value_bytes,_key_sum, _key_equal,_format_pair, _format_pair_arg)
Definition: hash.h:470
Context passed between object during a back walk.
Definition: fib_node.h:160
#define VLIB_CLI_COMMAND(x,...)
Definition: cli.h:154
int fib_path_list_recursive_loop_detect(fib_node_index_t path_list_index, fib_node_index_t **entry_indicies)
static fib_path_list_t * fib_path_list_from_fib_node(fib_node_t *node)
int fib_path_list_is_looped(fib_node_index_t path_list_index)
u32 fib_node_list_get_size(fib_node_list_t list)
static uword hash_elts(void *v)
Definition: hash.h:117
#define ASSERT(truth)
unsigned int u32
Definition: types.h:88
static fib_path_list_t * fib_path_list_resolve(fib_path_list_t *path_list)
static void fib_path_list_db_insert(fib_node_index_t path_list_index)
void fib_urpf_list_combine(index_t ui1, index_t ui2)
Combine to interface lists.
enum fib_forward_chain_type_t_ fib_forward_chain_type_t
FIB output chain type.
void fib_node_child_remove(fib_node_type_t parent_type, fib_node_index_t parent_index, fib_node_index_t sibling_index)
Definition: fib_node.c:121
void fib_path_list_contribute_forwarding(fib_node_index_t path_list_index, fib_forward_chain_type_t type, dpo_id_t *dpo)
fib_protocol_t fpl_nh_proto
The next-hop protocol for the paths in this path list.
Definition: fib_path_list.c:48
static fib_path_list_flags_t fib_path_list_flags_fixup(fib_path_list_flags_t flags)
u8 * format_fib_protocol(u8 *s, va_list ap)
Definition: fib_types.c:30
static fib_node_index_t fib_path_list_get_index(fib_path_list_t *path_list)
u64 uword
Definition: types.h:112
void fib_path_list_back_walk(fib_node_index_t path_list_index, fib_node_back_walk_ctx_t *ctx)
u32 fib_path_get_resolving_interface(fib_node_index_t path_index)
Definition: fib_path.c:1518
index_t dpoi_index
the index of objects of that type
Definition: dpo.h:154
#define FIB_NODE_INDEX_INVALID
Definition: fib_types.h:29
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
unsigned char u8
Definition: types.h:56
u32 fn_locks
Number of dependents on this node.
Definition: fib_node.h:265
#define INDEX_INVALID
Invalid index - used when no index is known blazoned capitals INVALID speak volumes where ~0 does not...
Definition: dpo.h:47
static fib_path_list_t * fib_path_list_db_get_from_hash_key(uword key)
u8 * fib_path_list_format(fib_node_index_t path_list_index, u8 *s)
#define vec_sort_with_function(vec, f)
Sort a vector using the supplied element comparison function.
Definition: vec.h:920
void fib_urpf_list_unlock(index_t ui)
Definition: fib_urpf_list.c:60
One path from an [EU]CMP set that the client wants to add to a load-balance object.
Definition: load_balance.h:61
enum fib_path_cfg_flags_t_ fib_path_cfg_flags_t
Path config flags from the attributes.
static void fib_path_list_mk_lb(fib_path_list_t *path_list, fib_forward_chain_type_t fct, dpo_id_t *dpo)
int fib_path_recursive_loop_detect(fib_node_index_t path_index, fib_node_index_t **entry_indicies)
Definition: fib_path.c:1286
A FIB graph nodes virtual function table.
Definition: fib_node.h:229
index_t fib_path_list_get_urpf(fib_node_index_t path_list_index)
Return the the child the RPF list pre-built for this path list.
static void fib_path_list_memory_show(void)
u8 * format(u8 *s, const char *fmt,...)
Definition: format.c:418
u8 * fib_path_list_adjs_format(fib_node_index_t path_list_index, u32 indent, u8 *s)
u32 fib_path_list_pool_size(void)
#define vec_foreach(var, vec)
Vector iterator.
enum fib_path_list_flags_t_ fib_path_list_flags_t
struct _unformat_input_t unformat_input_t
u32 flags
Definition: vhost-user.h:75
u8 * fib_node_children_format(fib_node_list_t list, u8 *s)
Definition: fib_node.c:163
static fib_node_t * fib_path_list_get_node(fib_node_index_t index)
struct fib_path_list_t_ fib_path_list_t
FIB path-list A representation of the list/set of path trough which a prefix is reachable.
void fib_path_destroy(fib_node_index_t path_index)
Definition: fib_path.c:1064
fib_node_index_t fib_path_list_create_special(fib_protocol_t nh_proto, fib_path_list_flags_t flags, const dpo_id_t *dpo)
static uword fib_path_list_db_hash_key_sum(hash_t *h, uword key)
static uword pool_elts(void *v)
Number of active elements in a pool.
Definition: pool.h:109