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