FD.io VPP  v18.07-rc0-415-g6c78436
Vector Packet Processing
fib_entry.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 <vlib/vlib.h>
17 #include <vnet/ip/format.h>
18 #include <vnet/ip/lookup.h>
19 #include <vnet/adj/adj.h>
20 #include <vnet/dpo/load_balance.h>
21 #include <vnet/dpo/drop_dpo.h>
22 
23 #include <vnet/fib/fib_entry.h>
24 #include <vnet/fib/fib_walk.h>
25 #include <vnet/fib/fib_entry_src.h>
27 #include <vnet/fib/fib_table.h>
28 #include <vnet/fib/fib_internal.h>
30 #include <vnet/fib/fib_path_ext.h>
31 
32 /*
33  * Array of strings/names for the FIB sources
34  */
35 static const char *fib_source_names[] = FIB_SOURCES;
38 
39 /*
40  * Pool for all fib_entries
41  */
43 
46 {
47  return (pool_elt_at_index(fib_entry_pool, index));
48 }
49 
50 static fib_node_t *
52 {
53  return ((fib_node_t*)fib_entry_get(index));
54 }
55 
57 fib_entry_get_index (const fib_entry_t * fib_entry)
58 {
59  return (fib_entry - fib_entry_pool);
60 }
61 
63 fib_entry_get_proto (const fib_entry_t * fib_entry)
64 {
65  return (fib_entry->fe_prefix.fp_proto);
66 }
67 
70 {
71  return (fib_proto_to_dpo(fib_entry->fe_prefix.fp_proto));
72 }
73 
76 {
77  switch (fib_entry->fe_prefix.fp_proto)
78  {
79  case FIB_PROTOCOL_IP4:
81  case FIB_PROTOCOL_IP6:
83  case FIB_PROTOCOL_MPLS:
84  if (MPLS_EOS == fib_entry->fe_prefix.fp_eos)
86  else
88  }
89 
91 }
92 
93 u8 *
94 format_fib_source (u8 * s, va_list * args)
95 {
96  fib_source_t source = va_arg (*args, int);
97 
98  s = format (s, "src:%s", fib_source_names[source]);
99 
100  return (s);
101 }
102 
103 u8 *
104 format_fib_entry (u8 * s, va_list * args)
105 {
109  fib_entry_t *fib_entry;
110  fib_entry_src_t *src;
111  fib_node_index_t fei;
112  fib_source_t source;
113  int level;
114 
115  fei = va_arg (*args, fib_node_index_t);
116  level = va_arg (*args, int);
117  fib_entry = fib_entry_get(fei);
118 
119  s = format (s, "%U", format_fib_prefix, &fib_entry->fe_prefix);
120 
121  if (level >= FIB_ENTRY_FORMAT_DETAIL)
122  {
123  s = format (s, " fib:%d", fib_entry->fe_fib_index);
124  s = format (s, " index:%d", fib_entry_get_index(fib_entry));
125  s = format (s, " locks:%d", fib_entry->fe_node.fn_locks);
126 
127  FOR_EACH_SRC_ADDED(fib_entry, src, source,
128  ({
129  s = format (s, "\n %U", format_fib_source, source);
130  s = format (s, " refs:%d", src->fes_ref_count);
131  if (FIB_ENTRY_FLAG_NONE != src->fes_entry_flags) {
132  s = format(s, " entry-flags:");
133  FOR_EACH_FIB_ATTRIBUTE(attr) {
134  if ((1<<attr) & src->fes_entry_flags) {
135  s = format (s, "%s,", fib_attribute_names[attr]);
136  }
137  }
138  }
139  if (FIB_ENTRY_SRC_FLAG_NONE != src->fes_flags) {
140  s = format(s, " src-flags:");
142  if ((1<<sattr) & src->fes_flags) {
143  s = format (s, "%s,", fib_src_attribute_names[sattr]);
144  }
145  }
146  }
147  s = fib_entry_src_format(fib_entry, source, s);
148  s = format (s, "\n");
149  if (FIB_NODE_INDEX_INVALID != src->fes_pl)
150  {
151  s = fib_path_list_format(src->fes_pl, s);
152  }
153  s = format(s, "%U", format_fib_path_ext_list, &src->fes_path_exts);
154  }));
155 
156  s = format (s, "\n forwarding: ");
157  }
158  else
159  {
160  s = format (s, "\n");
161  }
162 
163  fct = fib_entry_get_default_chain_type(fib_entry);
164 
165  if (!dpo_id_is_valid(&fib_entry->fe_lb))
166  {
167  s = format (s, " UNRESOLVED\n");
168  return (s);
169  }
170  else
171  {
172  s = format(s, " %U-chain\n %U",
175  &fib_entry->fe_lb,
176  2);
177  s = format(s, "\n");
178 
179  if (level >= FIB_ENTRY_FORMAT_DETAIL2)
180  {
183 
184  s = format (s, " Delegates:\n");
185  FOR_EACH_DELEGATE(fib_entry, fdt, fed,
186  {
187  s = format(s, " %U\n", format_fib_entry_deletegate, fed);
188  });
189  }
190  }
191 
192  if (level >= FIB_ENTRY_FORMAT_DETAIL2)
193  {
194  s = format(s, " Children:");
195  s = fib_node_children_format(fib_entry->fe_node.fn_children, s);
196  }
197 
198  return (s);
199 }
200 
201 static fib_entry_t*
203 {
205  return ((fib_entry_t*)node);
206 }
207 
208 static void
210 {
213  fib_entry_t *fib_entry;
214 
215  fib_entry = fib_entry_from_fib_node(node);
216 
217  ASSERT(!dpo_id_is_valid(&fib_entry->fe_lb));
218 
219  FOR_EACH_DELEGATE_CHAIN(fib_entry, fdt, fed,
220  {
221  dpo_reset(&fed->fd_dpo);
222  fib_entry_delegate_remove(fib_entry, fdt);
223  });
224 
225  FIB_ENTRY_DBG(fib_entry, "last-lock");
226 
227  fib_node_deinit(&fib_entry->fe_node);
228 
229  ASSERT(0 == vec_len(fib_entry->fe_delegates));
230  vec_free(fib_entry->fe_delegates);
231  vec_free(fib_entry->fe_srcs);
232  pool_put(fib_entry_pool, fib_entry);
233 }
234 
235 static fib_entry_src_t*
237 {
238  fib_entry_src_t *bsrc;
239 
240  /*
241  * the enum of sources is deliberately arranged in priority order
242  */
243  if (0 == vec_len(fib_entry->fe_srcs))
244  {
245  bsrc = NULL;
246  }
247  else
248  {
249  bsrc = vec_elt_at_index(fib_entry->fe_srcs, 0);
250  }
251 
252  return (bsrc);
253 }
254 
255 static fib_source_t
257 {
258  if (NULL != esrc)
259  {
260  return (esrc->fes_src);
261  }
262  return (FIB_SOURCE_MAX);
263 }
264 
265 static fib_entry_flag_t
267 {
268  if (NULL != esrc)
269  {
270  return (esrc->fes_entry_flags);
271  }
272  return (FIB_ENTRY_FLAG_NONE);
273 }
274 
277 {
278  return (fib_entry_get_flags_i(fib_entry_get(fib_entry_index)));
279 }
280 
281 /*
282  * fib_entry_back_walk_notify
283  *
284  * A back walk has reach this entry.
285  */
289 {
290  fib_entry_t *fib_entry;
291 
292  fib_entry = fib_entry_from_fib_node(node);
293 
300  {
303  fib_entry_get_index(fib_entry)));
304  }
305 
306  /*
307  * all other walk types can be reclassifed to a re-evaluate to
308  * all recursive dependents.
309  * By reclassifying we ensure that should any of these walk types meet
310  * they can be merged.
311  */
313 
314  /*
315  * ... and nothing is forced sync from now on.
316  */
318 
319  /*
320  * propagate the backwalk further if we haven't already reached the
321  * maximum depth.
322  */
324  fib_entry_get_index(fib_entry),
325  ctx);
326 
328 }
329 
330 static void
332 {
333  u32 n_srcs = 0, n_exts = 0;
334  fib_entry_src_t *esrc;
335  fib_entry_t *entry;
336 
337  fib_show_memory_usage("Entry",
338  pool_elts(fib_entry_pool),
339  pool_len(fib_entry_pool),
340  sizeof(fib_entry_t));
341 
342  pool_foreach(entry, fib_entry_pool,
343  ({
344  n_srcs += vec_len(entry->fe_srcs);
345  vec_foreach(esrc, entry->fe_srcs)
346  {
347  n_exts += fib_path_ext_list_length(&esrc->fes_path_exts);
348  }
349  }));
350 
351  fib_show_memory_usage("Entry Source",
352  n_srcs, n_srcs, sizeof(fib_entry_src_t));
353  fib_show_memory_usage("Entry Path-Extensions",
354  n_exts, n_exts,
355  sizeof(fib_path_ext_t));
356 }
357 
358 /*
359  * The FIB path-list's graph node virtual function table
360  */
361 static const fib_node_vft_t fib_entry_vft = {
363  .fnv_last_lock = fib_entry_last_lock_gone,
364  .fnv_back_walk = fib_entry_back_walk_notify,
365  .fnv_mem_show = fib_entry_show_memory,
366 };
367 
368 /**
369  * @brief Contribute the set of Adjacencies that this entry forwards with
370  * to build the uRPF list of its children
371  */
372 void
374  index_t urpf)
375 {
376  fib_entry_t *fib_entry;
377 
378  fib_entry = fib_entry_get(entry_index);
379 
380  return (fib_path_list_contribute_urpf(fib_entry->fe_parent, urpf));
381 }
382 
383 /*
384  * If the client is request a chain for multicast forwarding then swap
385  * the chain type to one that can provide such transport.
386  */
389 {
390  switch (fct)
391  {
394  /*
395  * we can only transport IP multicast packets if there is an
396  * LSP.
397  */
399  break;
407  break;
408  }
409 
410  return (fct);
411 }
412 
413 /*
414  * fib_entry_contribute_forwarding
415  *
416  * Get an lock the forwarding information (DPO) contributed by the FIB entry.
417  */
418 void
421  dpo_id_t *dpo)
422 {
424  fib_entry_t *fib_entry;
425 
426  fib_entry = fib_entry_get(fib_entry_index);
427 
428  /*
429  * mfib children ask for mcast chains. fix these to the appropriate ucast types.
430  */
432 
433  if (fct == fib_entry_get_default_chain_type(fib_entry))
434  {
435  dpo_copy(dpo, &fib_entry->fe_lb);
436  }
437  else
438  {
439  fed = fib_entry_delegate_get(fib_entry,
441 
442  if (NULL == fed)
443  {
445  fib_entry,
447  /*
448  * on-demand create eos/non-eos.
449  * There is no on-demand delete because:
450  * - memory versus complexity & reliability:
451  * leaving unrequired [n]eos LB arounds wastes memory, cleaning
452  * then up on the right trigger is more code. i favour the latter.
453  */
454  fib_entry_src_mk_lb(fib_entry,
455  fib_entry_get_best_src_i(fib_entry),
456  fct,
457  &fed->fd_dpo);
458  }
459 
460  dpo_copy(dpo, &fed->fd_dpo);
461  }
462  /*
463  * use the drop DPO is nothing else is present
464  */
465  if (!dpo_id_is_valid(dpo))
466  {
468  }
469 
470  /*
471  * don't allow the special index indicating replicate.vs.load-balance
472  * to escape to the clients
473  */
474  dpo->dpoi_index &= ~MPLS_IS_REPLICATE;
475 }
476 
477 const dpo_id_t *
479 {
481  fib_entry_t *fib_entry;
482 
483  fib_entry = fib_entry_get(fib_entry_index);
484  fct = fib_entry_get_default_chain_type(fib_entry);
485 
488 
489  if (dpo_id_is_valid(&fib_entry->fe_lb))
490  {
491  return (&fib_entry->fe_lb);
492  }
493 
495 }
496 
499 {
500  const dpo_id_t *dpo;
501 
502  dpo = fib_entry_contribute_ip_forwarding(fib_entry_index);
503 
504  if (dpo_id_is_valid(dpo))
505  {
506  dpo = load_balance_get_bucket(dpo->dpoi_index, 0);
507 
508  if (dpo_is_adj(dpo))
509  {
510  return (dpo->dpoi_index);
511  }
512  }
513  return (ADJ_INDEX_INVALID);
514 }
515 
518 {
519  fib_entry_t *fib_entry;
520 
521  fib_entry = fib_entry_get(fib_entry_index);
522 
523  return (fib_entry->fe_parent);
524 }
525 
526 u32
528  fib_node_type_t child_type,
529  fib_node_index_t child_index)
530 {
532  fib_entry_index,
533  child_type,
534  child_index));
535 };
536 
537 void
539  u32 sibling_index)
540 {
542  fib_entry_index,
543  sibling_index);
544 
546  fib_entry_index))
547  {
548  /*
549  * if there are no children left then there is no reason to keep
550  * the non-default forwarding chains. those chains are built only
551  * because the children want them.
552  */
555  fib_entry_t *fib_entry;
556 
557  fib_entry = fib_entry_get(fib_entry_index);
558 
559  FOR_EACH_DELEGATE_CHAIN(fib_entry, fdt, fed,
560  {
561  dpo_reset(&fed->fd_dpo);
562  fib_entry_delegate_remove(fib_entry, fdt);
563  });
564  }
565 }
566 
567 static fib_entry_t *
568 fib_entry_alloc (u32 fib_index,
569  const fib_prefix_t *prefix,
570  fib_node_index_t *fib_entry_index)
571 {
572  fib_entry_t *fib_entry;
573  fib_prefix_t *fep;
574 
575  pool_get(fib_entry_pool, fib_entry);
576  memset(fib_entry, 0, sizeof(*fib_entry));
577 
578  fib_node_init(&fib_entry->fe_node,
580 
581  fib_entry->fe_fib_index = fib_index;
582 
583  /*
584  * the one time we need to update the const prefix is when
585  * the entry is first created
586  */
587  fep = (fib_prefix_t*)&(fib_entry->fe_prefix);
588  *fep = *prefix;
589 
590  if (FIB_PROTOCOL_MPLS == fib_entry->fe_prefix.fp_proto)
591  {
592  fep->fp_len = 21;
593  if (MPLS_NON_EOS == fep->fp_eos)
594  {
596  }
598  }
599 
600  dpo_reset(&fib_entry->fe_lb);
601 
602  *fib_entry_index = fib_entry_get_index(fib_entry);
603 
604  FIB_ENTRY_DBG(fib_entry, "alloc");
605 
606  return (fib_entry);
607 }
608 
609 static fib_entry_t*
611  fib_entry_flag_t old_flags)
612 {
613  fib_node_index_t fei;
614 
615  /*
616  * save the index so we can recover from pool reallocs
617  */
618  fei = fib_entry_get_index(fib_entry);
619 
620  /*
621  * handle changes to attached export for import entries
622  */
623  int is_import = (FIB_ENTRY_FLAG_IMPORT & fib_entry_get_flags_i(fib_entry));
624  int was_import = (FIB_ENTRY_FLAG_IMPORT & old_flags);
625 
626  if (!was_import && is_import)
627  {
628  /*
629  * transition from not exported to exported
630  */
631 
632  /*
633  * there is an assumption here that the entry resolves via only
634  * one interface and that it is the cross VRF interface.
635  */
636  u32 sw_if_index = fib_path_list_get_resolving_interface(fib_entry->fe_parent);
637 
638  fib_attached_export_import(fib_entry,
640  fib_entry_get_proto(fib_entry),
641  sw_if_index));
642  }
643  else if (was_import && !is_import)
644  {
645  /*
646  * transition from exported to not exported
647  */
648  fib_attached_export_purge(fib_entry);
649  }
650  /*
651  * else
652  * no change. nothing to do.
653  */
654 
655  /*
656  * reload the entry address post possible pool realloc
657  */
658  fib_entry = fib_entry_get(fei);
659 
660  /*
661  * handle changes to attached export for export entries
662  */
663  int is_attached = (FIB_ENTRY_FLAG_ATTACHED & fib_entry_get_flags_i(fib_entry));
664  int was_attached = (FIB_ENTRY_FLAG_ATTACHED & old_flags);
665 
666  if (!was_attached && is_attached)
667  {
668  /*
669  * transition to attached. time to export
670  */
671  // FIXME
672  }
673  // else FIXME
674 
675  return (fib_entry);
676 }
677 
678 static void
680  fib_source_t source,
681  fib_entry_flag_t old_flags)
682 {
683  fib_entry = fib_entry_post_flag_update_actions(fib_entry,
684  old_flags);
685  fib_entry_src_action_installed(fib_entry, source);
686 }
687 
690  const fib_prefix_t *prefix,
691  fib_source_t source,
693  const fib_route_path_t *paths)
694 {
695  fib_node_index_t fib_entry_index;
696  fib_entry_t *fib_entry;
697 
698  ASSERT(0 < vec_len(paths));
699 
700  fib_entry = fib_entry_alloc(fib_index, prefix, &fib_entry_index);
701 
702  /*
703  * since this is a new entry create, we don't need to check for winning
704  * sources - there is only one.
705  */
706  fib_entry = fib_entry_src_action_add(fib_entry, source, flags,
707  drop_dpo_get(
709  fib_entry_get_proto(fib_entry))));
711  source,
712  flags,
713  paths);
714  /*
715  * handle possible realloc's by refetching the pointer
716  */
717  fib_entry = fib_entry_get(fib_entry_index);
718  fib_entry_src_action_activate(fib_entry, source);
719 
721 
722  return (fib_entry_index);
723 }
724 
727  const fib_prefix_t *prefix,
728  fib_source_t source,
730  const dpo_id_t *dpo)
731 {
732  fib_node_index_t fib_entry_index;
733  fib_entry_t *fib_entry;
734 
735  /*
736  * create and initiliase the new enty
737  */
738  fib_entry = fib_entry_alloc(fib_index, prefix, &fib_entry_index);
739 
740  /*
741  * create the path-list
742  */
743  fib_entry = fib_entry_src_action_add(fib_entry, source, flags, dpo);
744  fib_entry_src_action_activate(fib_entry, source);
745 
747 
748  return (fib_entry_index);
749 }
750 
751 static void
753  fib_source_t source,
754  fib_entry_flag_t old_flags)
755 {
756  /*
757  * backwalk to children to inform then of the change to forwarding.
758  */
759  fib_node_back_walk_ctx_t bw_ctx = {
761  };
762 
764 
765  /*
766  * then inform any covered prefixes
767  */
769 
770  fib_entry_post_install_actions(fib_entry, source, old_flags);
771 }
772 
773 void
775 {
776  fib_source_t best_source;
777  fib_entry_t *fib_entry;
778  fib_entry_src_t *bsrc;
779 
780  fib_entry = fib_entry_get(fib_entry_index);
781 
782  bsrc = fib_entry_get_best_src_i(fib_entry);
783  best_source = fib_entry_src_get_source(bsrc);
784 
785  fib_entry_src_action_reactivate(fib_entry, best_source);
786 }
787 
788 static void
790  fib_source_t old_source,
791  fib_entry_flag_t old_flags,
792  fib_source_t new_source)
793 {
794  if (new_source < old_source)
795  {
796  /*
797  * we have a new winning source.
798  */
799  fib_entry_src_action_deactivate(fib_entry, old_source);
800  fib_entry_src_action_activate(fib_entry, new_source);
801  }
802  else if (new_source > old_source)
803  {
804  /*
805  * the new source loses. Re-activate the winning sources
806  * in case it is an interposer and hence relied on the losing
807  * source's path-list.
808  */
809  fib_entry_src_action_reactivate(fib_entry, old_source);
810  return;
811  }
812  else
813  {
814  /*
815  * the new source is one this entry already has.
816  * But the path-list was updated, which will contribute new forwarding,
817  * so install it.
818  */
819  fib_entry_src_action_reactivate(fib_entry, new_source);
820  }
821 
822  fib_entry_post_update_actions(fib_entry, new_source, old_flags);
823 }
824 
825 void
827  fib_source_t old_source,
828  fib_source_t new_source)
829 {
830  fib_entry_flag_t old_flags;
831 
832  old_flags = fib_entry_get_flags_for_source(
833  fib_entry_get_index(fib_entry), old_source);
834 
835  return (fib_entry_source_change_w_flags(fib_entry, old_source,
836  old_flags, new_source));
837 }
838 
839 void
841  fib_source_t source,
843  const dpo_id_t *dpo)
844 {
845  fib_source_t best_source;
846  fib_entry_t *fib_entry;
847 
848  fib_entry = fib_entry_get(fib_entry_index);
849  best_source = fib_entry_get_best_source(fib_entry_index);
850 
851  fib_entry = fib_entry_src_action_add(fib_entry, source, flags, dpo);
852  fib_entry_source_change(fib_entry, best_source, source);
853 }
854 
855 void
857  fib_source_t source,
859  const dpo_id_t *dpo)
860 {
861  fib_source_t best_source;
862  fib_entry_t *fib_entry;
863 
864  fib_entry = fib_entry_get(fib_entry_index);
865  best_source = fib_entry_get_best_source(fib_entry_index);
866 
867  fib_entry = fib_entry_src_action_update(fib_entry, source, flags, dpo);
868  fib_entry_source_change(fib_entry, best_source, source);
869 }
870 
871 
872 void
874  fib_source_t source,
876  const fib_route_path_t *rpath)
877 {
878  fib_source_t best_source;
879  fib_entry_t *fib_entry;
880  fib_entry_src_t *bsrc;
881 
882  ASSERT(1 == vec_len(rpath));
883 
884  fib_entry = fib_entry_get(fib_entry_index);
885  ASSERT(NULL != fib_entry);
886 
887  bsrc = fib_entry_get_best_src_i(fib_entry);
888  best_source = fib_entry_src_get_source(bsrc);
889 
890  fib_entry = fib_entry_src_action_path_add(fib_entry, source, flags, rpath);
891 
892  fib_entry_source_change(fib_entry, best_source, source);
893 }
894 
897 {
898  fib_entry_src_t *src;
899  fib_source_t source;
900  int has_only_inherited_sources = 1;
901 
902  FOR_EACH_SRC_ADDED(fib_entry, src, source,
903  ({
905  {
906  has_only_inherited_sources = 0;
907  break;
908  }
909  }));
910  if (has_only_inherited_sources)
911  {
912  FOR_EACH_SRC_ADDED(fib_entry, src, source,
913  ({
914  fib_entry_src_action_remove(fib_entry, source);
915  }));
916  return (FIB_ENTRY_SRC_FLAG_NONE);
917  }
918  else
919  {
920  return (FIB_ENTRY_SRC_FLAG_ADDED);
921  }
922 }
923 
926  fib_entry_flag_t old_flags)
927 {
928  const fib_entry_src_t *bsrc;
929  fib_source_t best_source;
930 
931  /*
932  * if all that is left are inherited sources, then burn them
933  */
935 
936  bsrc = fib_entry_get_best_src_i(fib_entry);
937  best_source = fib_entry_src_get_source(bsrc);
938 
939  if (FIB_SOURCE_MAX == best_source)
940  {
941  /*
942  * no more sources left. this entry is toast.
943  */
944  fib_entry = fib_entry_post_flag_update_actions(fib_entry, old_flags);
946 
947  return (FIB_ENTRY_SRC_FLAG_NONE);
948  }
949  else
950  {
951  fib_entry_src_action_activate(fib_entry, best_source);
952  }
953 
954  fib_entry_post_update_actions(fib_entry, best_source, old_flags);
955 
956  /*
957  * still have sources
958  */
959  return (FIB_ENTRY_SRC_FLAG_ADDED);
960 }
961 
962 /*
963  * fib_entry_path_remove
964  *
965  * remove a path from the entry.
966  * return the fib_entry's index if it is still present, INVALID otherwise.
967  */
970  fib_source_t source,
971  const fib_route_path_t *rpath)
972 {
973  fib_entry_src_flag_t sflag;
974  fib_source_t best_source;
975  fib_entry_flag_t bflags;
976  fib_entry_t *fib_entry;
977  fib_entry_src_t *bsrc;
978 
979  ASSERT(1 == vec_len(rpath));
980 
981  fib_entry = fib_entry_get(fib_entry_index);
982  ASSERT(NULL != fib_entry);
983 
984  bsrc = fib_entry_get_best_src_i(fib_entry);
985  best_source = fib_entry_src_get_source(bsrc);
986  bflags = fib_entry_src_get_flags(bsrc);
987 
988  sflag = fib_entry_src_action_path_remove(fib_entry, source, rpath);
989 
990  /*
991  * if the path list for the source passed is invalid,
992  * then we need to create a new one. else we are updating
993  * an existing.
994  */
995  if (source < best_source)
996  {
997  /*
998  * Que! removing a path from a source that is better than the
999  * one this entry is using.
1000  */
1001  ASSERT(0);
1002  }
1003  else if (source > best_source )
1004  {
1005  /*
1006  * the source is not the best. no need to update forwarding
1007  */
1008  if (FIB_ENTRY_SRC_FLAG_ADDED & sflag)
1009  {
1010  /*
1011  * the source being removed still has paths
1012  */
1013  return (FIB_ENTRY_SRC_FLAG_ADDED);
1014  }
1015  else
1016  {
1017  /*
1018  * that was the last path from this source, check if those
1019  * that remain are non-inherited
1020  */
1021  return (fib_entry_src_burn_only_inherited(fib_entry));
1022  }
1023  }
1024  else
1025  {
1026  /*
1027  * removing a path from the path-list we were using.
1028  */
1029  if (!(FIB_ENTRY_SRC_FLAG_ADDED & sflag))
1030  {
1031  /*
1032  * the last path from the source was removed.
1033  * fallback to lower source
1034  */
1035  return (fib_entry_source_removed(fib_entry, bflags));
1036  }
1037  else
1038  {
1039  /*
1040  * re-install the new forwarding information
1041  */
1042  fib_entry_src_action_reactivate(fib_entry, source);
1043  }
1044  }
1045 
1046  fib_entry_post_update_actions(fib_entry, source, bflags);
1047 
1048  /*
1049  * still have sources
1050  */
1051  return (FIB_ENTRY_SRC_FLAG_ADDED);
1052 }
1053 
1054 /*
1055  * fib_entry_special_remove
1056  *
1057  * remove a special source from the entry.
1058  * return the fib_entry's index if it is still present, INVALID otherwise.
1059  */
1062  fib_source_t source)
1063 {
1064  fib_entry_src_flag_t sflag;
1065  fib_source_t best_source;
1066  fib_entry_flag_t bflags;
1067  fib_entry_t *fib_entry;
1068  fib_entry_src_t *bsrc;
1069 
1070  fib_entry = fib_entry_get(fib_entry_index);
1071  ASSERT(NULL != fib_entry);
1072 
1073  bsrc = fib_entry_get_best_src_i(fib_entry);
1074  best_source = fib_entry_src_get_source(bsrc);
1075  bflags = fib_entry_src_get_flags(bsrc);
1076 
1077  sflag = fib_entry_src_action_remove_or_update_inherit(fib_entry, source);
1078 
1079  /*
1080  * if the path list for the source passed is invalid,
1081  * then we need to create a new one. else we are updating
1082  * an existing.
1083  */
1084  if (source < best_source )
1085  {
1086  /*
1087  * Que! removing a path from a source that is better than the
1088  * one this entry is using. This can only mean it is a source
1089  * this prefix does not have.
1090  */
1091  return (FIB_ENTRY_SRC_FLAG_ADDED);
1092  }
1093  else if (source > best_source ) {
1094  /*
1095  * the source is not the best. no need to update forwarding
1096  */
1097  if (FIB_ENTRY_SRC_FLAG_ADDED & sflag)
1098  {
1099  /*
1100  * the source being removed still has paths
1101  */
1102  return (FIB_ENTRY_SRC_FLAG_ADDED);
1103  }
1104  else
1105  {
1106  /*
1107  * that was the last path from this source, check if those
1108  * that remain are non-inherited
1109  */
1111  {
1112  /*
1113  * no more sources left. this entry is toast.
1114  */
1115  fib_entry = fib_entry_post_flag_update_actions(fib_entry, bflags);
1116  fib_entry_src_action_uninstall(fib_entry);
1117  return (FIB_ENTRY_SRC_FLAG_NONE);
1118  }
1119 
1120  /*
1121  * reactivate the best source so the interposer gets restacked
1122  */
1123  fib_entry_src_action_reactivate(fib_entry, best_source);
1124 
1125  return (FIB_ENTRY_SRC_FLAG_ADDED);
1126  }
1127  }
1128  else
1129  {
1130  if (!(FIB_ENTRY_SRC_FLAG_ADDED & sflag))
1131  {
1132  /*
1133  * the source was removed. use the next best.
1134  */
1135  return (fib_entry_source_removed(fib_entry, bflags));
1136  }
1137  else
1138  {
1139  /*
1140  * re-install the new forwarding information
1141  */
1142  fib_entry_src_action_reactivate(fib_entry, source);
1143  }
1144  }
1145 
1146  fib_entry_post_update_actions(fib_entry, source, bflags);
1147 
1148  /*
1149  * still have sources
1150  */
1151  return (FIB_ENTRY_SRC_FLAG_ADDED);
1152 }
1153 
1154 /**
1155  * fib_entry_inherit
1156  *
1157  * If the source on the cover is inherting then push this source
1158  * down to the covered.
1159  */
1160 void
1162  fib_node_index_t covered)
1163 {
1165  fib_entry_get(covered));
1166 }
1167 
1168 /**
1169  * fib_entry_delete
1170  *
1171  * The source is withdrawing all the paths it provided
1172  */
1175  fib_source_t source)
1176 {
1177  return (fib_entry_special_remove(fib_entry_index, source));
1178 }
1179 
1180 /**
1181  * fib_entry_update
1182  *
1183  * The source has provided a new set of paths that will replace the old.
1184  */
1185 void
1187  fib_source_t source,
1189  const fib_route_path_t *paths)
1190 {
1191  fib_source_t best_source;
1192  fib_entry_flag_t bflags;
1193  fib_entry_t *fib_entry;
1194  fib_entry_src_t *bsrc;
1195 
1196  fib_entry = fib_entry_get(fib_entry_index);
1197  ASSERT(NULL != fib_entry);
1198 
1199  bsrc = fib_entry_get_best_src_i(fib_entry);
1200  best_source = fib_entry_src_get_source(bsrc);
1201  bflags = fib_entry_get_flags_i(fib_entry);
1202 
1203  fib_entry = fib_entry_src_action_path_swap(fib_entry,
1204  source,
1205  flags,
1206  paths);
1207 
1208  fib_entry_source_change_w_flags(fib_entry, best_source, bflags, source);
1209 }
1210 
1211 
1212 /*
1213  * fib_entry_cover_changed
1214  *
1215  * this entry is tracking its cover and that cover has changed.
1216  */
1217 void
1219 {
1221  .install = !0,
1222  .bw_reason = FIB_NODE_BW_REASON_FLAG_NONE,
1223  };
1224  CLIB_UNUSED(fib_source_t source);
1225  fib_source_t best_source;
1226  fib_entry_flag_t bflags;
1227  fib_entry_t *fib_entry;
1228  fib_entry_src_t *esrc;
1229  u32 index;
1230 
1231  bflags = FIB_ENTRY_FLAG_NONE;
1232  best_source = FIB_SOURCE_FIRST;
1233  fib_entry = fib_entry_get(fib_entry_index);
1234 
1236 
1237  /*
1238  * propagate the notificuation to each of the added sources
1239  */
1240  index = 0;
1241  FOR_EACH_SRC_ADDED(fib_entry, esrc, source,
1242  ({
1243  if (0 == index)
1244  {
1245  /*
1246  * only the best source gets to set the back walk flags
1247  */
1248  res = fib_entry_src_action_cover_change(fib_entry, esrc);
1249  bflags = fib_entry_src_get_flags(esrc);
1250  best_source = fib_entry_src_get_source(esrc);
1251  }
1252  else
1253  {
1254  fib_entry_src_action_cover_change(fib_entry, esrc);
1255  }
1256  index++;
1257  }));
1258 
1259  if (res.install)
1260  {
1263  fib_entry_get_best_src_i(fib_entry)));
1264  fib_entry_post_install_actions(fib_entry, best_source, bflags);
1265  }
1266  else
1267  {
1268  fib_entry_src_action_uninstall(fib_entry);
1269  }
1270 
1272  {
1273  /*
1274  * time for walkies fido.
1275  */
1276  fib_node_back_walk_ctx_t bw_ctx = {
1277  .fnbw_reason = res.bw_reason,
1278  };
1279 
1280  fib_walk_sync(FIB_NODE_TYPE_ENTRY, fib_entry_index, &bw_ctx);
1281  }
1282 }
1283 
1284 /*
1285  * fib_entry_cover_updated
1286  *
1287  * this entry is tracking its cover and that cover has been updated
1288  * (i.e. its forwarding information has changed).
1289  */
1290 void
1292 {
1294  .install = !0,
1295  .bw_reason = FIB_NODE_BW_REASON_FLAG_NONE,
1296  };
1297  CLIB_UNUSED(fib_source_t source);
1298  fib_source_t best_source;
1299  fib_entry_flag_t bflags;
1300  fib_entry_t *fib_entry;
1301  fib_entry_src_t *esrc;
1302  u32 index;
1303 
1304  bflags = FIB_ENTRY_FLAG_NONE;
1305  best_source = FIB_SOURCE_FIRST;
1306  fib_entry = fib_entry_get(fib_entry_index);
1307 
1309 
1310  /*
1311  * propagate the notificuation to each of the added sources
1312  */
1313  index = 0;
1314  FOR_EACH_SRC_ADDED(fib_entry, esrc, source,
1315  ({
1316  if (0 == index)
1317  {
1318  /*
1319  * only the best source gets to set the back walk flags
1320  */
1321  res = fib_entry_src_action_cover_update(fib_entry, esrc);
1322  bflags = fib_entry_src_get_flags(esrc);
1323  best_source = fib_entry_src_get_source(esrc);
1324  }
1325  else
1326  {
1327  fib_entry_src_action_cover_update(fib_entry, esrc);
1328  }
1329  index++;
1330  }));
1331 
1332  if (res.install)
1333  {
1336  fib_entry_get_best_src_i(fib_entry)));
1337  fib_entry_post_install_actions(fib_entry, best_source, bflags);
1338  }
1339  else
1340  {
1341  fib_entry_src_action_uninstall(fib_entry);
1342  }
1343 
1345  {
1346  /*
1347  * time for walkies fido.
1348  */
1349  fib_node_back_walk_ctx_t bw_ctx = {
1350  .fnbw_reason = res.bw_reason,
1351  };
1352 
1353  fib_walk_sync(FIB_NODE_TYPE_ENTRY, fib_entry_index, &bw_ctx);
1354  }
1355 }
1356 
1357 int
1359  fib_node_index_t **entry_indicies)
1360 {
1361  fib_entry_t *fib_entry;
1362  int was_looped, is_looped;
1363 
1364  fib_entry = fib_entry_get(entry_index);
1365 
1366  if (FIB_NODE_INDEX_INVALID != fib_entry->fe_parent)
1367  {
1368  fib_node_index_t *entries = *entry_indicies;
1369 
1370  vec_add1(entries, entry_index);
1371  was_looped = fib_path_list_is_looped(fib_entry->fe_parent);
1372  is_looped = fib_path_list_recursive_loop_detect(fib_entry->fe_parent,
1373  &entries);
1374 
1375  *entry_indicies = entries;
1376 
1377  if (!!was_looped != !!is_looped)
1378  {
1379  /*
1380  * re-evaluate all the entry's forwarding
1381  * NOTE: this is an inplace modify
1382  */
1384  fib_entry_delegate_t *fed;
1385 
1386  FOR_EACH_DELEGATE_CHAIN(fib_entry, fdt, fed,
1387  {
1388  fib_entry_src_mk_lb(fib_entry,
1389  fib_entry_get_best_src_i(fib_entry),
1391  &fed->fd_dpo);
1392  });
1393  }
1394  }
1395  else
1396  {
1397  /*
1398  * the entry is currently not linked to a path-list. this happens
1399  * when it is this entry that is re-linking path-lists and has thus
1400  * broken the loop
1401  */
1402  is_looped = 0;
1403  }
1404 
1405  return (is_looped);
1406 }
1407 
1408 u32
1410 {
1411  fib_entry_t *fib_entry;
1412 
1413  fib_entry = fib_entry_get(entry_index);
1414 
1415  return (fib_path_list_get_resolving_interface(fib_entry->fe_parent));
1416 }
1417 
1420 {
1421  fib_entry_t *fib_entry;
1422  fib_entry_src_t *bsrc;
1423 
1424  fib_entry = fib_entry_get(entry_index);
1425 
1426  bsrc = fib_entry_get_best_src_i(fib_entry);
1427  return (fib_entry_src_get_source(bsrc));
1428 }
1429 
1430 /**
1431  * Return !0 is the entry represents a host prefix
1432  */
1433 int
1435 {
1436  fib_prefix_t pfx;
1437 
1438  fib_entry_get_prefix(fib_entry_index, &pfx);
1439 
1440  return (fib_prefix_is_host(&pfx));
1441 }
1442 
1443 /**
1444  * Return !0 is the entry is reoslved, i.e. will return a valid forwarding
1445  * chain
1446  */
1447 int
1449 {
1450  fib_entry_delegate_t *fed;
1451  fib_entry_t *fib_entry;
1452 
1453  fib_entry = fib_entry_get(fib_entry_index);
1454 
1456 
1457  if (NULL == fed)
1458  {
1459  /*
1460  * no BFD tracking - consider it resolved.
1461  */
1462  return (!0);
1463  }
1464  else
1465  {
1466  /*
1467  * defer to the state of the BFD tracking
1468  */
1469  return (FIB_BFD_STATE_UP == fed->fd_bfd_state);
1470  }
1471 }
1472 
1473 void
1475  flow_hash_config_t hash_config)
1476 {
1477  fib_entry_t *fib_entry;
1478 
1479  fib_entry = fib_entry_get(fib_entry_index);
1480 
1481  /*
1482  * pass the hash-config on to the load-balance object where it is cached.
1483  * we can ignore LBs in the delegate chains, since they will not be of the
1484  * correct protocol type (i.e. they are not IP)
1485  * There's no way, nor need, to change the hash config for MPLS.
1486  */
1487  if (dpo_id_is_valid(&fib_entry->fe_lb))
1488  {
1489  load_balance_t *lb;
1490 
1491  ASSERT(DPO_LOAD_BALANCE == fib_entry->fe_lb.dpoi_type);
1492 
1493  lb = load_balance_get(fib_entry->fe_lb.dpoi_index);
1494 
1495  /*
1496  * atomic update for packets in flight
1497  */
1498  lb->lb_hash_config = hash_config;
1499  }
1500 }
1501 
1502 static int
1504  const ip4_address_t * a2)
1505 {
1506  /*
1507  * IP addresses are unsiged ints. the return value here needs to be signed
1508  * a simple subtraction won't cut it.
1509  * If the addresses are the same, the sort order is undefiend, so phoey.
1510  */
1511  return ((clib_net_to_host_u32(a1->data_u32) >
1512  clib_net_to_host_u32(a2->data_u32) ) ?
1513  1 : -1);
1514 }
1515 
1516 static int
1518  const ip6_address_t * a2)
1519 {
1520  int i;
1521  for (i = 0; i < ARRAY_LEN (a1->as_u16); i++)
1522  {
1523  int cmp = (clib_net_to_host_u16 (a1->as_u16[i]) -
1524  clib_net_to_host_u16 (a2->as_u16[i]));
1525  if (cmp != 0)
1526  return cmp;
1527  }
1528  return 0;
1529 }
1530 
1531 static int
1533  fib_node_index_t fib_entry_index2)
1534 {
1535  fib_entry_t *fib_entry1, *fib_entry2;
1536  int cmp = 0;
1537 
1538  fib_entry1 = fib_entry_get(fib_entry_index1);
1539  fib_entry2 = fib_entry_get(fib_entry_index2);
1540 
1541  switch (fib_entry1->fe_prefix.fp_proto)
1542  {
1543  case FIB_PROTOCOL_IP4:
1544  cmp = fib_ip4_address_compare(&fib_entry1->fe_prefix.fp_addr.ip4,
1545  &fib_entry2->fe_prefix.fp_addr.ip4);
1546  break;
1547  case FIB_PROTOCOL_IP6:
1548  cmp = fib_ip6_address_compare(&fib_entry1->fe_prefix.fp_addr.ip6,
1549  &fib_entry2->fe_prefix.fp_addr.ip6);
1550  break;
1551  case FIB_PROTOCOL_MPLS:
1552  cmp = (fib_entry1->fe_prefix.fp_label - fib_entry2->fe_prefix.fp_label);
1553 
1554  if (0 == cmp)
1555  {
1556  cmp = (fib_entry1->fe_prefix.fp_eos - fib_entry2->fe_prefix.fp_eos);
1557  }
1558  break;
1559  }
1560 
1561  if (0 == cmp) {
1562  cmp = (fib_entry1->fe_prefix.fp_len - fib_entry2->fe_prefix.fp_len);
1563  }
1564  return (cmp);
1565 }
1566 
1567 int
1568 fib_entry_cmp_for_sort (void *i1, void *i2)
1569 {
1570  fib_node_index_t *fib_entry_index1 = i1, *fib_entry_index2 = i2;
1571 
1572  return (fib_entry_cmp(*fib_entry_index1,
1573  *fib_entry_index2));
1574 }
1575 
1576 void
1578 {
1579  fib_entry_t *fib_entry;
1580 
1581  fib_entry = fib_entry_get(fib_entry_index);
1582 
1583  fib_node_lock(&fib_entry->fe_node);
1584 }
1585 
1586 void
1588 {
1589  fib_entry_t *fib_entry;
1590 
1591  fib_entry = fib_entry_get(fib_entry_index);
1592 
1593  fib_node_unlock(&fib_entry->fe_node);
1594 }
1595 
1596 void
1598 {
1599  fib_node_register_type (FIB_NODE_TYPE_ENTRY, &fib_entry_vft);
1600 }
1601 
1602 void
1604  fib_route_path_encode_t **api_rpaths)
1605 {
1606  fib_entry_t *fib_entry;
1607 
1608  fib_entry = fib_entry_get(fib_entry_index);
1609  if (FIB_NODE_INDEX_INVALID != fib_entry->fe_parent)
1610  {
1611  fib_path_list_walk(fib_entry->fe_parent, fib_path_encode, api_rpaths);
1612  }
1613 }
1614 
1615 void
1617  fib_prefix_t *pfx)
1618 {
1619  fib_entry_t *fib_entry;
1620 
1621  fib_entry = fib_entry_get(fib_entry_index);
1622  *pfx = fib_entry->fe_prefix;
1623 }
1624 
1625 u32
1627 {
1628  fib_entry_t *fib_entry;
1629 
1630  fib_entry = fib_entry_get(fib_entry_index);
1631 
1632  return (fib_entry->fe_fib_index);
1633 }
1634 
1635 u32
1637 {
1638  return (pool_elts(fib_entry_pool));
1639 }
1640 
1641 static clib_error_t *
1643  unformat_input_t * input,
1644  vlib_cli_command_t * cmd)
1645 {
1646  fib_node_index_t fei;
1647 
1648  if (unformat (input, "%d", &fei))
1649  {
1650  /*
1651  * show one in detail
1652  */
1653  if (!pool_is_free_index(fib_entry_pool, fei))
1654  {
1655  vlib_cli_output (vm, "%d@%U",
1656  fei,
1657  format_fib_entry, fei,
1659  }
1660  else
1661  {
1662  vlib_cli_output (vm, "entry %d invalid", fei);
1663  }
1664  }
1665  else
1666  {
1667  /*
1668  * show all
1669  */
1670  vlib_cli_output (vm, "FIB Entries:");
1671  pool_foreach_index(fei, fib_entry_pool,
1672  ({
1673  vlib_cli_output (vm, "%d@%U",
1674  fei,
1675  format_fib_entry, fei,
1677  }));
1678  }
1679 
1680  return (NULL);
1681 }
1682 
1683 VLIB_CLI_COMMAND (show_fib_entry, static) = {
1684  .path = "show fib entry",
1685  .function = show_fib_entry_command,
1686  .short_help = "show fib entry",
1687 };
fib_protocol_t fp_proto
protocol type
Definition: fib_types.h:197
Contribute an object that is to be used to forward BIER packets.
Definition: fib_types.h:112
u8 * format_fib_entry(u8 *s, va_list *args)
Definition: fib_entry.c:104
u32 fib_entry_get_fib_index(fib_node_index_t fib_entry_index)
Definition: fib_entry.c:1626
static fib_entry_src_flag_t fib_entry_source_removed(fib_entry_t *fib_entry, fib_entry_flag_t old_flags)
Definition: fib_entry.c:925
Contribute an object that is to be used to forward IP6 packets.
Definition: fib_types.h:127
#define FIB_ENTRY_DBG(_e, _fmt, _args...)
Debug macro.
Definition: fib_entry_src.h:42
void fib_entry_unlock(fib_node_index_t fib_entry_index)
Definition: fib_entry.c:1587
Contribute an object that is to be used to forward IP6 packets.
Definition: fib_types.h:103
An entry in a FIB table.
Definition: fib_entry.h:453
#define CLIB_UNUSED(x)
Definition: clib.h:79
A representation of a fib path for fib_path_encode to convey the information to the caller...
Definition: fib_types.h:564
static const char * fib_attribute_names[]
Definition: fib_entry.c:36
fib_node_bw_reason_flag_t bw_reason
Definition: fib_entry_src.h:96
int fib_entry_is_resolved(fib_node_index_t fib_entry_index)
Return !0 is the entry is reoslved, i.e.
Definition: fib_entry.c:1448
fib_protocol_t fib_entry_get_proto(const fib_entry_t *fib_entry)
Definition: fib_entry.c:63
fib_entry_flag_t fib_entry_get_flags_i(const fib_entry_t *fib_entry)
A representation of a path as described by a route producer.
Definition: fib_types.h:455
void fib_attached_export_cover_change(fib_entry_t *fib_entry)
If this entry is tracking a cover (in another table) then that cover has changed. ...
int dpo_is_adj(const dpo_id_t *dpo)
Return TRUE is the DPO is any type of adjacency.
Definition: dpo.c:277
static clib_error_t * show_fib_entry_command(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: fib_entry.c:1642
BFD session state.
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.
void fib_entry_set_flow_hash_config(fib_node_index_t fib_entry_index, flow_hash_config_t hash_config)
Definition: fib_entry.c:1474
void fib_node_init(fib_node_t *node, fib_node_type_t type)
Definition: fib_node.c:185
u32 fib_path_list_get_resolving_interface(fib_node_index_t path_list_index)
u32 fib_entry_child_add(fib_node_index_t fib_entry_index, fib_node_type_t child_type, fib_node_index_t child_index)
Definition: fib_entry.c:527
static fib_forward_chain_type_t fib_entry_chain_type_mcast_to_ucast(fib_forward_chain_type_t fct)
Definition: fib_entry.c:388
fib_entry_src_flag_t fib_entry_path_remove(fib_node_index_t fib_entry_index, fib_source_t source, const fib_route_path_t *rpath)
Definition: fib_entry.c:969
void fib_entry_path_add(fib_node_index_t fib_entry_index, fib_source_t source, fib_entry_flag_t flags, const fib_route_path_t *rpath)
Definition: fib_entry.c:873
#define FIB_ENTRY_FORMAT_DETAIL
Definition: fib_entry.h:508
static int dpo_id_is_valid(const dpo_id_t *dpoi)
Return true if the DPO object is valid, i.e.
Definition: dpo.h:207
void fib_entry_get_prefix(fib_node_index_t fib_entry_index, fib_prefix_t *pfx)
Definition: fib_entry.c:1616
static fib_entry_src_t * fib_entry_get_best_src_i(const fib_entry_t *fib_entry)
Definition: fib_entry.c:236
fib_node_index_t fib_entry_get_path_list(fib_node_index_t fib_entry_index)
Definition: fib_entry.c:517
Definitions for all things IP (v4|v6) unicast and multicast lookup related.
#define NULL
Definition: clib.h:55
Information related to the source of a FIB entry.
Definition: fib_entry.h:345
u32 fib_table_get_index_for_sw_if_index(fib_protocol_t proto, u32 sw_if_index)
Get the index of the FIB bound to the interface.
Definition: fib_table.c:948
Definition: fib_entry.h:276
static int fib_ip6_address_compare(const ip6_address_t *a1, const ip6_address_t *a2)
Definition: fib_entry.c:1517
enum fib_node_back_walk_rc_t_ fib_node_back_walk_rc_t
Return code from a back walk function.
void fib_entry_contribute_forwarding(fib_node_index_t fib_entry_index, fib_forward_chain_type_t fct, dpo_id_t *dpo)
Definition: fib_entry.c:419
void fib_entry_src_action_deactivate(fib_entry_t *fib_entry, fib_source_t source)
flow_hash_config_t lb_hash_config
the hash config to use when selecting a bucket.
Definition: load_balance.h:134
const dpo_id_t * fib_entry_contribute_ip_forwarding(fib_node_index_t fib_entry_index)
Definition: fib_entry.c:478
enum fib_entry_delegate_type_t_ fib_entry_delegate_type_t
Delegate types.
fib_bfd_state_t fd_bfd_state
BFD state.
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:359
void fib_entry_child_remove(fib_node_index_t fib_entry_index, u32 sibling_index)
Definition: fib_entry.c:538
void dpo_copy(dpo_id_t *dst, const dpo_id_t *src)
atomic copy a data-plane object.
Definition: dpo.c:261
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:523
int i
Result from a cover update/change.
Definition: fib_entry_src.h:94
void fib_path_list_walk(fib_node_index_t path_list_index, fib_path_list_walk_fn_t func, void *ctx)
Contribute an object that is to be used to forward IP4 packets.
Definition: fib_types.h:99
static const char * fib_src_attribute_names[]
Definition: fib_entry.c:37
void fib_node_deinit(fib_node_t *node)
Definition: fib_node.c:197
u8 * format(u8 *s, const char *fmt,...)
Definition: format.c:419
u32 fib_entry_pool_size(void)
Definition: fib_entry.c:1636
void fib_entry_module_init(void)
Definition: fib_entry.c:1597
u32 fe_fib_index
The index of the FIB table this entry is in.
Definition: fib_entry.h:466
Definition: fib_entry.h:272
#define pool_get(P, E)
Allocate an object E from a pool P (unspecified alignment).
Definition: pool.h:227
fib_entry_src_t * fe_srcs
Vector of source infos.
Definition: fib_entry.h:485
dpo_id_t fd_dpo
Valid for the forwarding chain delegates.
unsigned char u8
Definition: types.h:56
fib_node_index_t fe_parent
the path-list for which this entry is a child.
Definition: fib_entry.h:490
int fib_prefix_is_host(const fib_prefix_t *prefix)
Return true is the prefix is a host prefix.
Definition: fib_types.c:161
#define pool_len(p)
Number of elements in pool vector.
Definition: pool.h:140
enum fib_protocol_t_ fib_protocol_t
Protocol Type.
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:98
static void fib_entry_post_install_actions(fib_entry_t *fib_entry, fib_source_t source, fib_entry_flag_t old_flags)
Definition: fib_entry.c:679
void fib_node_register_type(fib_node_type_t type, const fib_node_vft_t *vft)
fib_node_register_type
Definition: fib_node.c:60
static fib_entry_src_flag_t fib_entry_src_burn_only_inherited(fib_entry_t *fib_entry)
Definition: fib_entry.c:896
const dpo_id_t * drop_dpo_get(dpo_proto_t proto)
Definition: drop_dpo.c:25
dpo_proto_t fp_payload_proto
This protocol determines the payload protocol of packets that will be forwarded by this entry once th...
Definition: fib_types.h:221
void fib_attached_export_purge(fib_entry_t *fib_entry)
All the imported entries need to be pruged.
enum fib_entry_src_attribute_t_ fib_entry_src_attribute_t
Flags for the source data.
#define FIB_ENTRY_ATTRIBUTES
Definition: fib_entry.h:250
void fib_entry_special_update(fib_node_index_t fib_entry_index, fib_source_t source, fib_entry_flag_t flags, const dpo_id_t *dpo)
Definition: fib_entry.c:856
#define pool_foreach(VAR, POOL, BODY)
Iterate through pool.
Definition: pool.h:440
fib_entry_src_flag_t fib_entry_src_action_path_remove(fib_entry_t *fib_entry, fib_source_t source, const fib_route_path_t *rpath)
fib_entry_t * fib_entry_src_action_path_add(fib_entry_t *fib_entry, fib_source_t source, fib_entry_flag_t flags, const fib_route_path_t *rpath)
void fib_entry_delegate_remove(fib_entry_t *fib_entry, fib_entry_delegate_type_t type)
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:727
#define DPO_PROTO_NONE
Definition: dpo.h:71
int fib_entry_is_host(fib_node_index_t fib_entry_index)
Return !0 is the entry represents a host prefix.
Definition: fib_entry.c:1434
u8 * format_fib_prefix(u8 *s, va_list *args)
Definition: fib_types.c:176
#define MPLS_IS_REPLICATE
The top bit of the index, which is the result of the MPLS lookup is used to determine if the DPO is a...
Definition: mpls_types.h:66
#define vec_elt_at_index(v, i)
Get vector value at index i checking that i is in bounds.
Aggregrate type for a prefix.
Definition: fib_types.h:188
fib_node_index_t fib_entry_get_index(const fib_entry_t *fib_entry)
Definition: fib_entry.c:57
void fib_entry_contribute_urpf(fib_node_index_t entry_index, index_t urpf)
Contribute the set of Adjacencies that this entry forwards with to build the uRPF list of its childre...
Definition: fib_entry.c:373
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:220
unsigned int u32
Definition: types.h:88
Contribute an object that is to be used to forward Ethernet packets.
Definition: fib_types.h:131
static fib_node_back_walk_rc_t fib_entry_back_walk_notify(fib_node_t *node, fib_node_back_walk_ctx_t *ctx)
Definition: fib_entry.c:287
enum dpo_proto_t_ dpo_proto_t
Data path protocol.
u16 fp_len
The mask length.
Definition: fib_types.h:192
fib_entry_delegate_t * fib_entry_delegate_get(const fib_entry_t *fib_entry, fib_entry_delegate_type_t type)
int fib_entry_cmp_for_sort(void *i1, void *i2)
Definition: fib_entry.c:1568
u16 install
Definition: fib_entry_src.h:95
adj_index_t fib_entry_get_adj(fib_node_index_t fib_entry_index)
Definition: fib_entry.c:498
Definition: fib_entry.h:270
#define FOR_EACH_SRC_ADDED(_entry, _src, _source, action)
The identity of a DPO is a combination of its type and its instance number/index of objects of that t...
Definition: dpo.h:168
Contribute an object that is to be used to forward end-of-stack MPLS packets.
Definition: fib_types.h:119
fib_node_bw_reason_flag_t fnbw_reason
The reason/trigger for the backwalk.
Definition: fib_node.h:203
void fib_entry_src_mk_lb(fib_entry_t *fib_entry, const fib_entry_src_t *esrc, fib_forward_chain_type_t fct, dpo_id_t *dpo_lb)
static fib_source_t fib_entry_src_get_source(const fib_entry_src_t *esrc)
Definition: fib_entry.c:256
#define ADJ_INDEX_INVALID
Invalid ADJ index - used when no adj is known likewise blazoned capitals INVALID speak volumes where ...
Definition: adj_types.h:36
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
Definition: pool.h:461
static int fib_ip4_address_compare(const ip4_address_t *a1, const ip4_address_t *a2)
Definition: fib_entry.c:1503
fib_entry_t * fib_entry_src_action_add(fib_entry_t *fib_entry, fib_source_t source, fib_entry_flag_t flags, const dpo_id_t *dpo)
enum fib_source_t_ fib_source_t
The different sources that can create a route.
ip46_address_t fp_addr
The address type is not deriveable from the fp_addr member.
Definition: fib_types.h:211
#define FOR_EACH_DELEGATE_CHAIN(_entry, _fdt, _fed, _body)
dpo_type_t dpoi_type
the type
Definition: dpo.h:172
void fib_node_lock(fib_node_t *node)
Definition: fib_node.c:203
struct _unformat_input_t unformat_input_t
Definition: fib_entry.h:332
load-balancing over a choice of [un]equal cost paths
Definition: dpo.h:102
#define FOR_EACH_FIB_SRC_ATTRIBUTE(_item)
Definition: fib_entry.h:322
#define pool_put(P, E)
Free an object E in pool P.
Definition: pool.h:273
The FIB DPO provieds;.
Definition: load_balance.h:84
fib_node_bw_flags_t fnbw_flags
additional flags for the walk
Definition: fib_node.h:208
fib_entry_src_flag_t fib_entry_delete(fib_node_index_t fib_entry_index, fib_source_t source)
fib_entry_delete
Definition: fib_entry.c:1174
u8 * format_fib_entry_deletegate(u8 *s, va_list *args)
fib_node_index_t fib_entry_create_special(u32 fib_index, const fib_prefix_t *prefix, fib_source_t source, fib_entry_flag_t flags, const dpo_id_t *dpo)
Definition: fib_entry.c:726
enum fib_entry_attribute_t_ fib_entry_attribute_t
The different sources that can create a route.
fib_node_type_t fn_type
The node&#39;s type.
Definition: fib_node.h:290
An node in the FIB graph.
Definition: fib_node.h:286
void fib_node_unlock(fib_node_t *node)
Definition: fib_node.c:209
const dpo_id_t * load_balance_get_bucket(index_t lbi, u32 bucket)
Definition: load_balance.c:294
#define FIB_SOURCE_MAX
The maximum number of sources.
Definition: fib_entry.h:153
fib_entry_src_flag_t fib_entry_src_action_remove_or_update_inherit(fib_entry_t *fib_entry, fib_source_t source)
void fib_entry_inherit(fib_node_index_t cover, fib_node_index_t covered)
fib_entry_inherit
Definition: fib_entry.c:1161
static void fib_entry_source_change_w_flags(fib_entry_t *fib_entry, fib_source_t old_source, fib_entry_flag_t old_flags, fib_source_t new_source)
Definition: fib_entry.c:789
#define FOR_EACH_FIB_ATTRIBUTE(_item)
Definition: fib_entry.h:264
u32 fib_entry_get_resolving_interface(fib_node_index_t entry_index)
Definition: fib_entry.c:1409
fib_entry_src_flag_t fib_entry_src_action_remove(fib_entry_t *fib_entry, fib_source_t source)
static fib_node_t * fib_entry_get_node(fib_node_index_t index)
Definition: fib_entry.c:51
static void fib_entry_last_lock_gone(fib_node_t *node)
Definition: fib_entry.c:209
fib_node_list_t fn_children
Vector of nodes that depend upon/use/share this node.
Definition: fib_node.h:300
fib_entry_delegate_type_t fib_entry_chain_type_to_delegate_type(fib_forward_chain_type_t fct)
vlib_main_t * vm
Definition: buffer.c:294
u8 * format_fib_source(u8 *s, va_list *args)
Definition: fib_entry.c:94
void fib_entry_src_action_installed(const fib_entry_t *fib_entry, fib_source_t source)
Definition: fib_entry.h:328
static fib_entry_t * fib_entry_from_fib_node(fib_node_t *node)
Definition: fib_entry.c:202
Contribute an object that is to be used to forward NSH packets.
Definition: fib_types.h:137
#define vec_free(V)
Free vector&#39;s memory (no header).
Definition: vec.h:339
void fib_entry_src_action_activate(fib_entry_t *fib_entry, fib_source_t source)
void fib_entry_source_change(fib_entry_t *fib_entry, fib_source_t old_source, fib_source_t new_source)
Definition: fib_entry.c:826
Force the walk to be synchronous.
Definition: fib_node.h:165
int fib_entry_recursive_loop_detect(fib_node_index_t entry_index, fib_node_index_t **entry_indicies)
Definition: fib_entry.c:1358
fib_node_get_t fnv_get
Definition: fib_node.h:274
fib_entry_src_cover_res_t fib_entry_src_action_cover_change(fib_entry_t *fib_entry, fib_entry_src_t *esrc)
u32 fib_node_index_t
A typedef of a node index.
Definition: fib_types.h:30
static fib_entry_t * fib_entry_post_flag_update_actions(fib_entry_t *fib_entry, fib_entry_flag_t old_flags)
Definition: fib_entry.c:610
#define pool_is_free_index(P, I)
Use free bitmap to query whether given index is free.
Definition: pool.h:270
u32 fib_node_get_n_children(fib_node_type_t parent_type, fib_node_index_t parent_index)
Definition: fib_node.c:142
u32 adj_index_t
An index for adjacencies.
Definition: adj_types.h:30
#define ARRAY_LEN(x)
Definition: clib.h:59
fib_forward_chain_type_t fib_entry_delegate_type_to_chain_type(fib_entry_delegate_type_t fdt)
fib_entry_t * fib_entry_get(fib_node_index_t index)
Definition: fib_entry.c:45
enum fib_entry_flag_t_ fib_entry_flag_t
mpls_label_t fp_label
Definition: fib_types.h:214
Context passed between object during a back walk.
Definition: fib_node.h:199
void fib_entry_lock(fib_node_index_t fib_entry_index)
Definition: fib_entry.c:1577
#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)
fib_entry_flag_t fes_entry_flags
Flags the source contributes to the entry.
Definition: fib_entry.h:359
int fib_path_list_is_looped(fib_node_index_t path_list_index)
fib_source_t fes_src
Which source this info block is for.
Definition: fib_entry.h:364
#define ASSERT(truth)
fib_entry_src_flag_t fes_flags
Flags on the source.
Definition: fib_entry.h:369
fib_entry_t * fib_entry_src_action_path_swap(fib_entry_t *fib_entry, fib_source_t source, fib_entry_flag_t flags, const fib_route_path_t *rpaths)
static void fib_entry_show_memory(void)
Definition: fib_entry.c:331
long ctx[MAX_CONNS]
Definition: main.c:126
fib_path_list_walk_rc_t fib_path_encode(fib_node_index_t path_list_index, fib_node_index_t path_index, void *ctx)
Definition: fib_path.c:2580
static load_balance_t * load_balance_get(index_t lbi)
Definition: load_balance.h:200
fib_node_t fe_node
Base class.
Definition: fib_entry.h:457
enum fib_forward_chain_type_t_ fib_forward_chain_type_t
FIB output chain type.
fib_entry_t * fib_entry_src_action_update(fib_entry_t *fib_entry, fib_source_t source, fib_entry_flag_t flags, const dpo_id_t *dpo)
u8 * format_fib_forw_chain_type(u8 *s, va_list *args)
Definition: fib_types.c:47
Definition: fib_entry.h:329
int fib_path_ext_list_length(const fib_path_ext_list_t *list)
Definition: fib_path_ext.c:479
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:123
static void fib_entry_post_update_actions(fib_entry_t *fib_entry, fib_source_t source, fib_entry_flag_t old_flags)
Definition: fib_entry.c:752
dpo_proto_t fib_proto_to_dpo(fib_protocol_t fib_proto)
Definition: fib_types.c:236
enum fib_entry_src_flag_t_ fib_entry_src_flag_t
u8 * format_dpo_id(u8 *s, va_list *args)
Format a DPO_id_t oject
Definition: dpo.c:147
u32 flow_hash_config_t
A flow hash configuration is a mask of the flow hash options.
Definition: lookup.h:82
static fib_entry_t * fib_entry_pool
Definition: fib_entry.c:42
u32 entries
void fib_entry_cover_changed(fib_node_index_t fib_entry_index)
Definition: fib_entry.c:1218
void fib_entry_encode(fib_node_index_t fib_entry_index, fib_route_path_encode_t **api_rpaths)
Definition: fib_entry.c:1603
dpo_id_t fe_lb
The load-balance used for forwarding.
Definition: fib_entry.h:479
void fib_attached_export_cover_update(fib_entry_t *fib_entry)
If this entry is tracking a cover (in another table) then that cover has been updated.
fib_entry_delegate_t * fe_delegates
A vector of delegates.
Definition: fib_entry.h:501
fib_node_index_t fes_pl
The path-list created by the source.
Definition: fib_entry.h:354
void fib_entry_src_inherit(const fib_entry_t *cover, fib_entry_t *covered)
void fib_attached_export_import(fib_entry_t *fib_entry, fib_node_index_t export_fib)
FIB attached export.
#define FIB_ENTRY_FORMAT_BRIEF
Definition: fib_entry.h:507
fib_entry_flag_t fib_entry_get_flags_for_source(fib_node_index_t fib_entry_index, fib_source_t source)
static fib_entry_flag_t fib_entry_src_get_flags(const fib_entry_src_t *esrc)
Definition: fib_entry.c:266
index_t dpoi_index
the index of objects of that type
Definition: dpo.h:184
fib_node_index_t fib_entry_create(u32 fib_index, const fib_prefix_t *prefix, fib_source_t source, fib_entry_flag_t flags, const fib_route_path_t *paths)
Definition: fib_entry.c:689
#define FIB_NODE_INDEX_INVALID
Definition: fib_types.h:31
Marker.
Definition: fib_entry.h:34
void fib_entry_recalculate_forwarding(fib_node_index_t fib_entry_index)
Definition: fib_entry.c:774
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
u32 fn_locks
Number of dependents on this node.
Definition: fib_node.h:306
u8 * fib_path_list_format(fib_node_index_t path_list_index, u8 *s)
u8 * fib_entry_src_format(fib_entry_t *fib_entry, fib_source_t source, u8 *s)
#define FOR_EACH_DELEGATE(_entry, _fdt, _fed, _body)
void fib_entry_cover_updated(fib_node_index_t fib_entry_index)
Definition: fib_entry.c:1291
A FIB graph nodes virtual function table.
Definition: fib_node.h:273
enum fib_node_type_t_ fib_node_type_t
The types of nodes in a FIB graph.
void fib_entry_src_action_reactivate(fib_entry_t *fib_entry, fib_source_t source)
void fib_entry_update(fib_node_index_t fib_entry_index, fib_source_t source, fib_entry_flag_t flags, const fib_route_path_t *paths)
fib_entry_update
Definition: fib_entry.c:1186
#define FIB_ENTRY_FORMAT_DETAIL2
Definition: fib_entry.h:509
void dpo_reset(dpo_id_t *dpo)
reset a DPO ID The DPO will be unlocked.
Definition: dpo.c:231
#define vec_foreach(var, vec)
Vector iterator.
A path extension is a per-entry addition to the forwarding information when packets are sent for that...
Definition: fib_path_ext.h:98
u8 fes_ref_count
1 bytes ref count.
Definition: fib_entry.h:376
fib_path_ext_list_t fes_path_exts
A vector of path extensions.
Definition: fib_entry.h:349
dpo_proto_t fib_entry_get_dpo_proto(const fib_entry_t *fib_entry)
Definition: fib_entry.c:69
u8 * format_fib_path_ext_list(u8 *s, va_list *args)
Definition: fib_path_ext.c:459
u16 as_u16[8]
Definition: ip6_packet.h:49
Contribute an object that is to be used to forward non-end-of-stack MPLS packets. ...
Definition: fib_types.h:108
void fib_entry_cover_update_notify(fib_entry_t *fib_entry)
static int fib_entry_cmp(fib_node_index_t fib_entry_index1, fib_node_index_t fib_entry_index2)
Definition: fib_entry.c:1532
A Delagate is a means to implmenet the Delagation design pattern; the extension of an objects functio...
#define pool_foreach_index(i, v, body)
Iterate pool by index.
Definition: pool.h:485
u32 flags
Definition: vhost-user.h:77
u8 * fib_node_children_format(fib_node_list_t list, u8 *s)
Definition: fib_node.c:176
static fib_entry_t * fib_entry_alloc(u32 fib_index, const fib_prefix_t *prefix, fib_node_index_t *fib_entry_index)
Definition: fib_entry.c:568
fib_source_t fib_entry_get_best_source(fib_node_index_t entry_index)
Definition: fib_entry.c:1419
Contribute an object that is to be used to forward IP4 packets.
Definition: fib_types.h:123
fib_entry_delegate_t * fib_entry_delegate_find_or_add(fib_entry_t *fib_entry, fib_entry_delegate_type_t fdt)
#define FIB_ENTRY_SRC_ATTRIBUTES
Definition: fib_entry.h:315
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
Definition: cli.c:681
void fib_entry_special_add(fib_node_index_t fib_entry_index, fib_source_t source, fib_entry_flag_t flags, const dpo_id_t *dpo)
Definition: fib_entry.c:840
fib_forward_chain_type_t fib_entry_get_default_chain_type(const fib_entry_t *fib_entry)
Definition: fib_entry.c:75
fib_entry_src_cover_res_t fib_entry_src_action_cover_update(fib_entry_t *fib_entry, fib_entry_src_t *esrc)
const fib_prefix_t fe_prefix
The prefix of the route.
Definition: fib_entry.h:462
uword unformat(unformat_input_t *i, const char *fmt,...)
Definition: unformat.c:972
fib_entry_src_flag_t fib_entry_special_remove(fib_node_index_t fib_entry_index, fib_source_t source)
Definition: fib_entry.c:1061
static const char * fib_source_names[]
Definition: fib_entry.c:35
void fib_entry_src_action_uninstall(fib_entry_t *fib_entry)
#define FIB_SOURCES
Definition: fib_entry.h:155
mpls_eos_bit_t fp_eos
Definition: fib_types.h:215
fib_entry_flag_t fib_entry_get_flags(fib_node_index_t fib_entry_index)
Definition: fib_entry.c:276
static uword pool_elts(void *v)
Number of active elements in a pool.
Definition: pool.h:128