FD.io VPP  v19.04.4-rc0-5-ge88582fac
Vector Packet Processing
mfib_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 
18 #include <vnet/mfib/mfib_entry.h>
21 #include <vnet/fib/fib_path_list.h>
22 #include <vnet/fib/fib_walk.h>
23 
24 #include <vnet/dpo/drop_dpo.h>
25 #include <vnet/dpo/replicate_dpo.h>
26 
27 /**
28  * the logger
29  */
31 
32 /**
33  * Pool of path extensions
34  */
36 
37 /**
38  * String names for each source
39  */
40 static const char *mfib_source_names[] = MFIB_SOURCE_NAMES;
41 
42 /*
43  * Pool for all fib_entries
44  */
46 
47 static fib_node_t *
49 {
50  return ((fib_node_t*)mfib_entry_get(index));
51 }
52 
53 static fib_protocol_t
54 mfib_entry_get_proto (const mfib_entry_t * mfib_entry)
55 {
56  return (mfib_entry->mfe_prefix.fp_proto);
57 }
58 
61 {
62  switch (mfib_entry->mfe_prefix.fp_proto)
63  {
64  case FIB_PROTOCOL_IP4:
66  case FIB_PROTOCOL_IP6:
68  case FIB_PROTOCOL_MPLS:
69  ASSERT(0);
70  break;
71  }
73 }
74 
75 static u8 *
76 format_mfib_entry_dpo (u8 * s, va_list * args)
77 {
78  index_t fei = va_arg(*args, index_t);
79  CLIB_UNUSED(u32 indent) = va_arg(*args, u32);
80 
81  return (format(s, "%U",
82  format_mfib_entry, fei,
84 }
85 
86 static inline mfib_path_ext_t *
88 {
89  return (pool_elt_at_index(mfib_path_ext_pool, mi));
90 }
91 
92 static u8 *
93 format_mfib_entry_path_ext (u8 * s, va_list * args)
94 {
95  mfib_path_ext_t *path_ext;
96  index_t mpi = va_arg(*args, index_t);
97 
98  path_ext = mfib_entry_path_ext_get(mpi);
99  return (format(s, "path:%d flags:%U",
100  path_ext->mfpe_path,
101  format_mfib_itf_flags, path_ext->mfpe_flags));
102 }
103 
104 u8 *
105 format_mfib_entry (u8 * s, va_list * args)
106 {
107  fib_node_index_t fei, mfi;
108  mfib_entry_t *mfib_entry;
109  mfib_entry_src_t *msrc;
111  int level;
112 
113  fei = va_arg (*args, fib_node_index_t);
114  level = va_arg (*args, int);
115  mfib_entry = mfib_entry_get(fei);
116 
117  s = format (s, "%U", format_mfib_prefix, &mfib_entry->mfe_prefix);
118  s = format (s, ": %U", format_mfib_entry_flags, mfib_entry->mfe_flags);
119 
120  if (level >= MFIB_ENTRY_FORMAT_DETAIL)
121  {
122  fib_node_index_t path_index, mpi;
123 
124  s = format (s, "\n");
125  s = format (s, " fib:%d", mfib_entry->mfe_fib_index);
126  s = format (s, " index:%d", mfib_entry_get_index(mfib_entry));
127  s = format (s, " locks:%d\n", mfib_entry->mfe_node.fn_locks);
128  vec_foreach(msrc, mfib_entry->mfe_srcs)
129  {
130  s = format (s, " src:%s locks:%d:",
132  msrc->mfes_ref_count);
133  if (msrc->mfes_cover != FIB_NODE_INDEX_INVALID)
134  {
135  s = format (s, " cover:%d", msrc->mfes_cover);
136  }
137  s = format (s, " %U\n", format_mfib_entry_flags, msrc->mfes_flags);
138  if (FIB_NODE_INDEX_INVALID != msrc->mfes_pl)
139  {
140  s = fib_path_list_format(msrc->mfes_pl, s);
141  }
142  s = format (s, " Extensions:\n");
143  hash_foreach(path_index, mpi, msrc->mfes_exts,
144  ({
145  s = format(s, " %U\n", format_mfib_entry_path_ext, mpi);
146  }));
147  s = format (s, " Interface-Forwarding:\n");
148  hash_foreach(sw_if_index, mfi, msrc->mfes_itfs,
149  ({
150  s = format(s, " %U\n", format_mfib_itf, mfi);
151  }));
152  }
153  }
154 
155  s = format(s, "\n Interfaces:");
156  hash_foreach(sw_if_index, mfi, mfib_entry->mfe_itfs,
157  ({
158  s = format(s, "\n %U", format_mfib_itf, mfi);
159  }));
160  if (MFIB_RPF_ID_NONE != mfib_entry->mfe_rpf_id)
161  {
162  s = format(s, "\n RPF-ID:%d", mfib_entry->mfe_rpf_id);
163  }
164  s = format(s, "\n %U-chain\n %U",
168  &mfib_entry->mfe_rep,
169  2);
170  s = format(s, "\n");
171 
172  if (level >= MFIB_ENTRY_FORMAT_DETAIL2)
173  {
174  s = format(s, "\nchildren:");
175  s = fib_node_children_format(mfib_entry->mfe_node.fn_children, s);
176  }
177 
178  return (s);
179 }
180 
181 static mfib_entry_t*
183 {
185  return ((mfib_entry_t*)node);
186 }
187 
188 static int
190  void * v2)
191 {
192  mfib_entry_src_t *esrc1 = v1, *esrc2 = v2;
193 
194  return (esrc1->mfes_src - esrc2->mfes_src);
195 }
196 
197 static void
199  mfib_source_t source)
200 
201 {
202  mfib_entry_src_t esrc = {
204  .mfes_flags = MFIB_ENTRY_FLAG_NONE,
205  .mfes_src = source,
206  .mfes_cover = FIB_NODE_INDEX_INVALID,
207  .mfes_sibling = FIB_NODE_INDEX_INVALID,
208  .mfes_ref_count = 1,
209  };
210 
211  vec_add1(mfib_entry->mfe_srcs, esrc);
212  vec_sort_with_function(mfib_entry->mfe_srcs,
214 }
215 
216 static mfib_entry_src_t *
218  mfib_source_t source,
219  u32 *index)
220 
221 {
222  mfib_entry_src_t *esrc;
223  int ii;
224 
225  ii = 0;
226  vec_foreach(esrc, mfib_entry->mfe_srcs)
227  {
228  if (esrc->mfes_src == source)
229  {
230  if (NULL != index)
231  {
232  *index = ii;
233  }
234  return (esrc);
235  }
236  else
237  {
238  ii++;
239  }
240  }
241 
242  return (NULL);
243 }
244 
245 static mfib_entry_src_t *
247  mfib_source_t source)
248 {
249  mfib_entry_src_t *msrc;
250 
251  msrc = mfib_entry_src_find(mfib_entry, source, NULL);
252 
253  if (NULL == msrc)
254  {
255  mfib_entry_src_init(mfib_entry, source);
256  msrc = mfib_entry_src_find(mfib_entry, source, NULL);
257  }
258 
259  return (msrc);
260 }
261 
262 static mfib_entry_src_t *
264  mfib_source_t source,
265  fib_rpf_id_t rpf_id,
266  mfib_entry_flags_t entry_flags)
267 {
268  mfib_entry_src_t *msrc;
269 
270  msrc = mfib_entry_src_find_or_create(mfib_entry, source);
271 
272  msrc->mfes_flags = entry_flags;
273  msrc->mfes_rpf_id = rpf_id;
274 
275  return (msrc);
276 }
277 
278 static mfib_entry_src_t *
280  mfib_source_t source,
281  fib_rpf_id_t rpf_id,
282  mfib_entry_flags_t entry_flags)
283 {
284  mfib_entry_src_t *msrc;
285 
286  msrc = mfib_entry_src_update(mfib_entry, source, rpf_id, entry_flags);
287 
288  msrc->mfes_ref_count++;
289 
290  return (msrc);
291 }
292 
295 {
296  mfib_entry_src_t *bsrc;
297 
298  /*
299  * the enum of sources is deliberately arranged in priority order
300  */
301  if (0 == vec_len(mfib_entry->mfe_srcs))
302  {
303  bsrc = NULL;
304  }
305  else
306  {
307  bsrc = vec_elt_at_index(mfib_entry->mfe_srcs, 0);
308  }
309 
310  return (bsrc);
311 }
312 
313 static mfib_source_t
315 {
316  mfib_entry_src_t *bsrc;
317 
318  bsrc = mfib_entry_get_best_src(mfib_entry);
319 
320  return (bsrc->mfes_src);
321 }
322 
323 int
325  mfib_source_t source)
326 {
327  mfib_entry_t *mfib_entry;
328 
329  mfib_entry = mfib_entry_get(mfib_entry_index);
330 
331  return (NULL != mfib_entry_src_find(mfib_entry, source, NULL));
332 }
333 
334 int
336 {
337  return (mfib_prefix_is_host(mfib_entry_get_prefix(mfib_entry_index)));
338 }
339 
340 
341 static void
343 {
345  index_t mfii;
346 
347  hash_foreach(sw_if_index, mfii, msrc->mfes_itfs,
348  ({
349  mfib_itf_delete(mfib_itf_get(mfii));
350  }));
351  hash_free(msrc->mfes_itfs);
352  msrc->mfes_itfs = NULL;
354 }
355 
356 static void
358  mfib_source_t source)
359 
360 {
361  mfib_entry_src_t *msrc;
362  u32 index = ~0;
363 
364  msrc = mfib_entry_src_find(mfib_entry, source, &index);
365 
366  if (NULL != msrc)
367  {
368  ASSERT(0 != msrc->mfes_ref_count);
369  msrc->mfes_ref_count--;
370 
371  if (0 == msrc->mfes_ref_count)
372  {
373  mfib_entry_src_deactivate(mfib_entry, msrc);
374  mfib_entry_src_flush(msrc);
375 
376  vec_del1(mfib_entry->mfe_srcs, index);
377  if (vec_len (mfib_entry->mfe_srcs) > 1)
378  vec_sort_with_function(mfib_entry->mfe_srcs,
380  }
381  }
382 }
383 
384 u32
386  fib_node_type_t child_type,
387  fib_node_index_t child_index)
388 {
390  mfib_entry_index,
391  child_type,
392  child_index));
393 };
394 
395 void
397  u32 sibling_index)
398 {
400  mfib_entry_index,
401  sibling_index);
402 }
403 
404 static mfib_entry_t *
406  const mfib_prefix_t *prefix,
407  fib_node_index_t *mfib_entry_index)
408 {
409  mfib_entry_t *mfib_entry;
410 
411  pool_get_aligned(mfib_entry_pool, mfib_entry, CLIB_CACHE_LINE_BYTES);
412 
413  fib_node_init(&mfib_entry->mfe_node,
415 
416  /*
417  * Some of the members require non-default initialisation
418  * so we also init those that don't and thus save on the call to clib_memset.
419  */
420  mfib_entry->mfe_flags = 0;
421  mfib_entry->mfe_fib_index = fib_index;
422  mfib_entry->mfe_prefix = *prefix;
423  mfib_entry->mfe_srcs = NULL;
424  mfib_entry->mfe_itfs = NULL;
425  mfib_entry->mfe_rpf_id = MFIB_RPF_ID_NONE;
426  mfib_entry->mfe_pl = FIB_NODE_INDEX_INVALID;
427 
428  dpo_reset(&mfib_entry->mfe_rep);
429 
430  *mfib_entry_index = mfib_entry_get_index(mfib_entry);
431 
432  MFIB_ENTRY_DBG(mfib_entry, "alloc");
433 
434  return (mfib_entry);
435 }
436 
437 static inline mfib_path_ext_t *
439  fib_node_index_t path_index)
440 {
441  uword *p;
442 
443  p = hash_get(exts, path_index);
444 
445  if (NULL != p)
446  {
447  return (mfib_entry_path_ext_get(p[0]));
448  }
449 
450  return (NULL);
451 }
452 
453 static mfib_path_ext_t*
455  fib_node_index_t path_index,
456  mfib_itf_flags_t mfi_flags)
457 {
458  mfib_path_ext_t *path_ext;
459 
460  pool_get(mfib_path_ext_pool, path_ext);
461 
462  path_ext->mfpe_flags = mfi_flags;
463  path_ext->mfpe_path = path_index;
464 
465  hash_set(msrc->mfes_exts, path_index,
466  path_ext - mfib_path_ext_pool);
467 
468  return (path_ext);
469 }
470 
471 static void
473  fib_node_index_t path_index)
474 {
475  mfib_path_ext_t *path_ext;
476 
477  path_ext = mfib_entry_path_ext_find(msrc->mfes_exts, path_index);
478 
479  hash_unset(msrc->mfes_exts, path_index);
480  pool_put(mfib_path_ext_pool, path_ext);
481 }
482 
484 {
489 
492  fib_node_index_t path_index,
493  void *arg)
494 {
497 
498  ctx = arg;
499 
500  /*
501  * if the path is not resolved, don't include it.
502  */
503  if (!fib_path_is_resolved(path_index))
504  {
506  }
507 
508  /*
509  * If the path is not forwarding to use it
510  */
511  mfib_path_ext_t *path_ext;
512 
513  path_ext = mfib_entry_path_ext_find(ctx->msrc->mfes_exts,
514  path_index);
515 
516  if (NULL != path_ext &&
517  !(path_ext->mfpe_flags & MFIB_ITF_FLAG_FORWARD))
518  {
520  }
521 
522  switch (ctx->fct)
523  {
526  /*
527  * EOS traffic with no label to stack, we need the IP Adj
528  */
529  vec_add2(ctx->next_hops, nh, 1);
530 
531  nh->path_index = path_index;
532  nh->path_weight = fib_path_get_weight(path_index);
533  fib_path_contribute_forwarding(path_index, ctx->fct, &nh->path_dpo);
534  break;
535 
543  ASSERT(0);
544  break;
545  }
546 
548 }
549 
550 static void
553 {
554  dpo_proto_t dp;
555 
556  dp = fib_proto_to_dpo(mfib_entry_get_proto(mfib_entry));
557 
558  /*
559  * unlink the enty from the previous path list.
560  */
561  if (FIB_NODE_INDEX_INVALID != mfib_entry->mfe_pl)
562  {
564  mfib_entry->mfe_sibling);
565  }
566 
567  if (NULL != msrc)
568  {
570  .next_hops = NULL,
571  .fct = mfib_entry_get_default_chain_type(mfib_entry),
572  .msrc = msrc,
573  };
574 
575  /*
576  * link the entry to the path-list.
577  * The entry needs to be a child so that we receive the back-walk
578  * updates to recalculate forwarding.
579  */
580  mfib_entry->mfe_pl = msrc->mfes_pl;
581  mfib_entry->mfe_flags = msrc->mfes_flags;
582  mfib_entry->mfe_itfs = msrc->mfes_itfs;
583  mfib_entry->mfe_rpf_id = msrc->mfes_rpf_id;
584 
585  if (FIB_NODE_INDEX_INVALID != mfib_entry->mfe_pl)
586  {
587  mfib_entry->mfe_sibling =
588  fib_path_list_child_add(mfib_entry->mfe_pl,
590  mfib_entry_get_index(mfib_entry));
591 
592  fib_path_list_walk(mfib_entry->mfe_pl,
594  &ctx);
595  }
596  if (!(MFIB_ENTRY_FLAG_EXCLUSIVE & mfib_entry->mfe_flags))
597  {
598  if (NULL == ctx.next_hops)
599  {
600  /*
601  * no next-hops, stack directly on the drop
602  */
604  &mfib_entry->mfe_rep,
605  drop_dpo_get(dp));
606  }
607  else
608  {
609  /*
610  * each path contirbutes a next-hop. form a replicate
611  * from those choices.
612  */
613  if (!dpo_id_is_valid(&mfib_entry->mfe_rep) ||
614  dpo_is_drop(&mfib_entry->mfe_rep))
615  {
616  dpo_id_t tmp_dpo = DPO_INVALID;
617 
618  dpo_set(&tmp_dpo,
619  DPO_REPLICATE, dp,
620  replicate_create(0, dp));
621 
623  &mfib_entry->mfe_rep,
624  &tmp_dpo);
625 
626  dpo_reset(&tmp_dpo);
627  }
628  replicate_multipath_update(&mfib_entry->mfe_rep,
629  ctx.next_hops);
630  }
631  }
632  else
633  {
634  /*
635  * for exclusive routes the source provided a replicate DPO
636  * which we stashed in the special path list with one path,
637  * so we can stack directly on that.
638  */
639  ASSERT(1 == vec_len(ctx.next_hops));
640 
641  if (NULL != ctx.next_hops)
642  {
644  &mfib_entry->mfe_rep,
645  &ctx.next_hops[0].path_dpo);
646  dpo_reset(&ctx.next_hops[0].path_dpo);
647  vec_free(ctx.next_hops);
648  }
649  else
650  {
652  &mfib_entry->mfe_rep,
653  drop_dpo_get(dp));
654  }
655  }
656  }
657  else
658  {
660  &mfib_entry->mfe_rep,
661  drop_dpo_get(dp));
662  }
663 
664  /*
665  * time for walkies fido.
666  */
667  fib_node_back_walk_ctx_t bw_ctx = {
669  };
670 
672  mfib_entry_get_index(mfib_entry),
673  &bw_ctx);
674 }
675 
676 static fib_node_index_t
678  const fib_route_path_t *rpath)
679 {
680  fib_node_index_t path_index;
681  fib_route_path_t *rpaths;
682 
684 
685  /*
686  * path-lists require a vector of paths
687  */
688  rpaths = NULL;
689  vec_add1(rpaths, rpath[0]);
690 
691  if (FIB_NODE_INDEX_INVALID == msrc->mfes_pl)
692  {
693  /* A non-shared path-list */
695  NULL);
697  }
698 
699  path_index = fib_path_list_path_add(msrc->mfes_pl, rpaths);
700 
701  vec_free(rpaths);
702 
703  return (path_index);
704 }
705 
706 static fib_node_index_t
708  const fib_route_path_t *rpath)
709 {
710  fib_node_index_t path_index;
711  fib_route_path_t *rpaths;
712 
714 
715  /*
716  * path-lists require a vector of paths
717  */
718  rpaths = NULL;
719  vec_add1(rpaths, rpath[0]);
720 
721  path_index = fib_path_list_path_remove(msrc->mfes_pl, rpaths);
722 
723  vec_free(rpaths);
724 
725  return (path_index);
726 }
727 
728 static void
730  mfib_source_t old_best)
731 {
732  mfib_entry_src_t *bsrc, *osrc;
733 
734  /*
735  * copy the forwarding data from the bast source
736  */
737  bsrc = mfib_entry_get_best_src(mfib_entry);
738  osrc = mfib_entry_src_find(mfib_entry, old_best, NULL);
739 
740  if (NULL != bsrc)
741  {
742  if (bsrc->mfes_src != old_best)
743  {
744  /*
745  * we are changing from one source to another
746  * deactivate the old, and activate the new
747  */
748  mfib_entry_src_deactivate(mfib_entry, osrc);
749  mfib_entry_src_activate(mfib_entry, bsrc);
750  }
751  }
752  else
753  {
754  mfib_entry_src_deactivate(mfib_entry, osrc);
755  }
756 
757  mfib_entry_stack(mfib_entry, bsrc);
758  mfib_entry_cover_update_notify(mfib_entry);
759 }
760 
761 
764  mfib_source_t source,
765  const mfib_prefix_t *prefix,
766  fib_rpf_id_t rpf_id,
767  mfib_entry_flags_t entry_flags,
768  index_t repi)
769 {
770  fib_node_index_t mfib_entry_index;
771  mfib_entry_t *mfib_entry;
773 
774  mfib_entry = mfib_entry_alloc(fib_index, prefix,
775  &mfib_entry_index);
776  msrc = mfib_entry_src_update(mfib_entry, source,
777  rpf_id, entry_flags);
778 
779  if (INDEX_INVALID != repi)
780  {
781  /*
782  * The source is providing its own replicate DPO.
783  * Create a sepcial path-list to manage it, that way
784  * this entry and the source are equivalent to a normal
785  * entry
786  */
787  fib_node_index_t old_pl_index;
788  dpo_proto_t dp;
789  dpo_id_t dpo = DPO_INVALID;
790 
791  dp = fib_proto_to_dpo(mfib_entry_get_proto(mfib_entry));
792  old_pl_index = msrc->mfes_pl;
793 
794  dpo_set(&dpo, DPO_REPLICATE, dp, repi);
795 
796  msrc->mfes_pl =
799  &dpo);
800 
801  dpo_reset(&dpo);
803  fib_path_list_unlock(old_pl_index);
804  }
805 
807 
808  return (mfib_entry_index);
809 }
810 
811 static int
813 {
814  return (0 == vec_len(mfib_entry->mfe_srcs));
815 }
816 
817 static int
819 {
820  return ((INDEX_INVALID == msrc->mfes_cover &&
821  MFIB_ENTRY_FLAG_NONE == msrc->mfes_flags &&
822  0 == fib_path_list_get_n_paths(msrc->mfes_pl)));
823 }
824 
825 
826 static void
829  mfib_source_t current_best,
830  index_t repi)
831 {
832  if (INDEX_INVALID != repi)
833  {
834  /*
835  * The source is providing its own replicate DPO.
836  * Create a sepcial path-list to manage it, that way
837  * this entry and the source are equivalent to a normal
838  * entry
839  */
840  fib_node_index_t old_pl_index;
841  dpo_proto_t dp;
842  dpo_id_t dpo = DPO_INVALID;
843 
844  dp = fib_proto_to_dpo(mfib_entry_get_proto(mfib_entry));
845  old_pl_index = msrc->mfes_pl;
846 
847  dpo_set(&dpo, DPO_REPLICATE, dp, repi);
848 
849  msrc->mfes_pl =
852  &dpo);
853 
854  dpo_reset(&dpo);
856  fib_path_list_unlock(old_pl_index);
857  }
858 
860  {
861  /*
862  * this source has no interfaces and no flags.
863  * it has nothing left to give - remove it
864  */
865  mfib_entry_src_remove(mfib_entry, msrc->mfes_src);
866  }
867 
868  mfib_entry_recalculate_forwarding(mfib_entry, current_best);
869 }
870 
871 int
873  mfib_source_t source,
874  mfib_entry_flags_t entry_flags,
875  fib_rpf_id_t rpf_id,
876  index_t repi)
877 {
878  mfib_source_t current_best;
879  mfib_entry_t *mfib_entry;
881 
882  mfib_entry = mfib_entry_get(mfib_entry_index);
883  current_best = mfib_entry_get_best_source(mfib_entry);
884 
885  msrc = mfib_entry_src_update_and_lock(mfib_entry, source, rpf_id,
886  entry_flags);
887 
888  mfib_entry_update_i(mfib_entry, msrc, current_best, repi);
889 
890  return (mfib_entry_ok_for_delete(mfib_entry));
891 }
892 
893 int
895  mfib_source_t source,
896  mfib_entry_flags_t entry_flags,
897  fib_rpf_id_t rpf_id,
898  index_t repi)
899 {
900  mfib_source_t current_best;
901  mfib_entry_t *mfib_entry;
903 
904  mfib_entry = mfib_entry_get(mfib_entry_index);
905  current_best = mfib_entry_get_best_source(mfib_entry);
906  msrc = mfib_entry_src_update(mfib_entry, source, rpf_id, entry_flags);
907 
908  mfib_entry_update_i(mfib_entry, msrc, current_best, repi);
909 
910  return (mfib_entry_ok_for_delete(mfib_entry));
911 }
912 
913 static void
916  index_t mi)
917 {
918  hash_set(msrc->mfes_itfs, sw_if_index, mi);
919 }
920 
921 static void
924 {
925  mfib_itf_t *mfi;
926 
927  mfi = mfib_entry_itf_find(msrc->mfes_itfs, sw_if_index);
928 
929  mfib_itf_delete(mfi);
930 
931  hash_unset(msrc->mfes_itfs, sw_if_index);
932 }
933 
934 void
936  mfib_source_t source,
937  const fib_route_path_t *rpath,
939 {
940  fib_node_index_t path_index;
941  mfib_source_t current_best;
942  mfib_path_ext_t *path_ext;
943  mfib_entry_t *mfib_entry;
945  mfib_itf_flags_t old;
946 
947  mfib_entry = mfib_entry_get(mfib_entry_index);
948  ASSERT(NULL != mfib_entry);
949  current_best = mfib_entry_get_best_source(mfib_entry);
950  msrc = mfib_entry_src_find_or_create(mfib_entry, source);
951 
952  /*
953  * add the path to the path-list. If it's a duplicate we'll get
954  * back the original path.
955  */
956  path_index = mfib_entry_src_path_add(msrc, rpath);
957 
958  /*
959  * find the path extension for that path
960  */
961  path_ext = mfib_entry_path_ext_find(msrc->mfes_exts, path_index);
962 
963  if (NULL == path_ext)
964  {
965  old = MFIB_ITF_FLAG_NONE;
966  path_ext = mfib_path_ext_add(msrc, path_index, itf_flags);
967  }
968  else
969  {
970  old = path_ext->mfpe_flags;
971  path_ext->mfpe_flags = itf_flags;
972  }
973 
974  /*
975  * Has the path changed its contribution to the input interface set.
976  * Which only paths with interfaces can do...
977  */
978  if (~0 != rpath[0].frp_sw_if_index)
979  {
980  mfib_itf_t *mfib_itf;
981 
982  if (old != itf_flags)
983  {
984  /*
985  * change of flag contributions
986  */
987  mfib_itf = mfib_entry_itf_find(msrc->mfes_itfs,
988  rpath[0].frp_sw_if_index);
989 
990  if (NULL == mfib_itf)
991  {
992  mfib_entry_itf_add(msrc,
993  rpath[0].frp_sw_if_index,
994  mfib_itf_create(path_index, itf_flags));
995  }
996  else
997  {
998  if (mfib_itf_update(mfib_itf,
999  path_index,
1000  itf_flags))
1001  {
1002  /*
1003  * no more interface flags on this path, remove
1004  * from the data-plane set
1005  */
1006  mfib_entry_itf_remove(msrc, rpath[0].frp_sw_if_index);
1007  }
1008  }
1009  }
1010  }
1011 
1012  mfib_entry_recalculate_forwarding(mfib_entry, current_best);
1013 }
1014 
1015 /*
1016  * mfib_entry_path_remove
1017  *
1018  * remove a path from the entry.
1019  * return the mfib_entry's index if it is still present, INVALID otherwise.
1020  */
1021 int
1023  mfib_source_t source,
1024  const fib_route_path_t *rpath)
1025 {
1026  fib_node_index_t path_index;
1027  mfib_source_t current_best;
1028  mfib_entry_t *mfib_entry;
1030 
1031  mfib_entry = mfib_entry_get(mfib_entry_index);
1032  ASSERT(NULL != mfib_entry);
1033  current_best = mfib_entry_get_best_source(mfib_entry);
1034  msrc = mfib_entry_src_find(mfib_entry, source, NULL);
1035 
1036  if (NULL == msrc)
1037  {
1038  /*
1039  * there are no paths left for this source
1040  */
1041  return (mfib_entry_ok_for_delete(mfib_entry));
1042  }
1043 
1044  /*
1045  * remove the path from the path-list. If it's not there we'll get
1046  * back invalid
1047  */
1048  path_index = mfib_entry_src_path_remove(msrc, rpath);
1049 
1050  if (FIB_NODE_INDEX_INVALID != path_index)
1051  {
1052  /*
1053  * don't need the extension, nor the interface anymore
1054  */
1055  mfib_path_ext_remove(msrc, path_index);
1056  if (~0 != rpath[0].frp_sw_if_index)
1057  {
1058  mfib_itf_t *mfib_itf;
1059 
1060  mfib_itf = mfib_entry_itf_find(msrc->mfes_itfs,
1061  rpath[0].frp_sw_if_index);
1062 
1063  if (mfib_itf_update(mfib_itf,
1064  path_index,
1066  {
1067  /*
1068  * no more interface flags on this path, remove
1069  * from the data-plane set
1070  */
1071  mfib_entry_itf_remove(msrc, rpath[0].frp_sw_if_index);
1072  }
1073  }
1074  }
1075 
1076  if (mfib_entry_src_ok_for_delete(msrc))
1077  {
1078  /*
1079  * this source has no interfaces and no flags.
1080  * it has nothing left to give - remove it
1081  */
1082  mfib_entry_src_remove(mfib_entry, source);
1083  }
1084 
1085  mfib_entry_recalculate_forwarding(mfib_entry, current_best);
1086 
1087  return (mfib_entry_ok_for_delete(mfib_entry));
1088 }
1089 
1090 /**
1091  * mfib_entry_delete
1092  *
1093  * The source is withdrawing all the paths it provided
1094  */
1095 int
1097  mfib_source_t source)
1098 {
1099  mfib_source_t current_best;
1100  mfib_entry_t *mfib_entry;
1101 
1102  mfib_entry = mfib_entry_get(mfib_entry_index);
1103  current_best = mfib_entry_get_best_source(mfib_entry);
1104  mfib_entry_src_remove(mfib_entry, source);
1105 
1106  mfib_entry_recalculate_forwarding(mfib_entry, current_best);
1107 
1108  return (mfib_entry_ok_for_delete(mfib_entry));
1109 }
1110 
1111 static int
1113  ip4_address_t * a2)
1114 {
1115  /*
1116  * IP addresses are unsiged ints. the return value here needs to be signed
1117  * a simple subtraction won't cut it.
1118  * If the addresses are the same, the sort order is undefiend, so phoey.
1119  */
1120  return ((clib_net_to_host_u32(a1->data_u32) >
1121  clib_net_to_host_u32(a2->data_u32) ) ?
1122  1 : -1);
1123 }
1124 
1125 static int
1127  ip6_address_t * a2)
1128 {
1129  int i;
1130  for (i = 0; i < ARRAY_LEN (a1->as_u16); i++)
1131  {
1132  int cmp = (clib_net_to_host_u16 (a1->as_u16[i]) -
1133  clib_net_to_host_u16 (a2->as_u16[i]));
1134  if (cmp != 0)
1135  return cmp;
1136  }
1137  return 0;
1138 }
1139 
1140 static int
1142  fib_node_index_t mfib_entry_index2)
1143 {
1144  mfib_entry_t *mfib_entry1, *mfib_entry2;
1145  int cmp = 0;
1146 
1147  mfib_entry1 = mfib_entry_get(mfib_entry_index1);
1148  mfib_entry2 = mfib_entry_get(mfib_entry_index2);
1149 
1150  switch (mfib_entry1->mfe_prefix.fp_proto)
1151  {
1152  case FIB_PROTOCOL_IP4:
1153  cmp = fib_ip4_address_compare(&mfib_entry1->mfe_prefix.fp_grp_addr.ip4,
1154  &mfib_entry2->mfe_prefix.fp_grp_addr.ip4);
1155 
1156  if (0 == cmp)
1157  {
1158  cmp = fib_ip4_address_compare(&mfib_entry1->mfe_prefix.fp_src_addr.ip4,
1159  &mfib_entry2->mfe_prefix.fp_src_addr.ip4);
1160  }
1161  break;
1162  case FIB_PROTOCOL_IP6:
1163  cmp = fib_ip6_address_compare(&mfib_entry1->mfe_prefix.fp_grp_addr.ip6,
1164  &mfib_entry2->mfe_prefix.fp_grp_addr.ip6);
1165 
1166  if (0 == cmp)
1167  {
1168  cmp = fib_ip6_address_compare(&mfib_entry1->mfe_prefix.fp_src_addr.ip6,
1169  &mfib_entry2->mfe_prefix.fp_src_addr.ip6);
1170  }
1171  break;
1172  case FIB_PROTOCOL_MPLS:
1173  ASSERT(0);
1174  cmp = 0;
1175  break;
1176  }
1177 
1178  if (0 == cmp) {
1179  cmp = (mfib_entry1->mfe_prefix.fp_len - mfib_entry2->mfe_prefix.fp_len);
1180  }
1181  return (cmp);
1182 }
1183 
1184 int
1185 mfib_entry_cmp_for_sort (void *i1, void *i2)
1186 {
1187  fib_node_index_t *mfib_entry_index1 = i1, *mfib_entry_index2 = i2;
1188 
1189  return (mfib_entry_cmp(*mfib_entry_index1,
1190  *mfib_entry_index2));
1191 }
1192 
1193 static void
1195 {
1196  mfib_entry_t *mfib_entry;
1198 
1199  mfib_entry = mfib_entry_from_fib_node(node);
1200 
1201  dpo_reset(&mfib_entry->mfe_rep);
1202 
1203  MFIB_ENTRY_DBG(mfib_entry, "last-lock");
1204 
1205  vec_foreach(msrc, mfib_entry->mfe_srcs)
1206  {
1207  mfib_entry_src_flush(msrc);
1208  }
1209 
1210  vec_free(mfib_entry->mfe_srcs);
1211 
1212  fib_node_deinit(&mfib_entry->mfe_node);
1213  pool_put(mfib_entry_pool, mfib_entry);
1214 }
1215 
1216 u32
1218 {
1219  mfib_entry_t *mfib_entry;
1220 
1221  mfib_entry = mfib_entry_get(fib_entry_index);
1222 
1223  return (mfib_entry->mfe_rep.dpoi_index);
1224 }
1225 
1226 /*
1227  * mfib_entry_back_walk_notify
1228  *
1229  * A back walk has reach this entry.
1230  */
1234 {
1235  mfib_entry_t *mfib_entry;
1236 
1237  mfib_entry = mfib_entry_from_fib_node(node);
1239  mfib_entry_get_best_source(mfib_entry));
1240 
1241  return (FIB_NODE_BACK_WALK_CONTINUE);
1242 }
1243 
1244 static void
1246 {
1247  fib_show_memory_usage("multicast-Entry",
1248  pool_elts(mfib_entry_pool),
1249  pool_len(mfib_entry_pool),
1250  sizeof(mfib_entry_t));
1251 }
1252 
1253 /*
1254  * The MFIB entry's graph node virtual function table
1255  */
1256 static const fib_node_vft_t mfib_entry_vft = {
1258  .fnv_last_lock = mfib_entry_last_lock_gone,
1259  .fnv_back_walk = mfib_entry_back_walk_notify,
1260  .fnv_mem_show = mfib_entry_show_memory,
1261 };
1262 
1263 void
1265 {
1266  mfib_entry_t *mfib_entry;
1267 
1268  mfib_entry = mfib_entry_get(mfib_entry_index);
1269 
1270  fib_node_lock(&mfib_entry->mfe_node);
1271 }
1272 
1273 void
1275 {
1276  mfib_entry_t *mfib_entry;
1277 
1278  mfib_entry = mfib_entry_get(mfib_entry_index);
1279 
1280  fib_node_unlock(&mfib_entry->mfe_node);
1281 }
1282 
1283 static void
1285 {
1286 }
1287 static void
1289 {
1290 }
1291 
1292 const static dpo_vft_t mfib_entry_dpo_vft = {
1294  .dv_unlock = mfib_entry_dpo_unlock,
1295  .dv_format = format_mfib_entry_dpo,
1296  .dv_mem_show = mfib_entry_show_memory,
1297 };
1298 
1299 const static char* const mfib_entry_ip4_nodes[] =
1300 {
1301  "ip4-mfib-forward-rpf",
1302  NULL,
1303 };
1304 const static char* const mfib_entry_ip6_nodes[] =
1305 {
1306  "ip6-mfib-forward-rpf",
1307  NULL,
1308 };
1309 
1310 const static char* const * const mfib_entry_nodes[DPO_PROTO_NUM] =
1311 {
1314 };
1315 
1316 void
1318 {
1320  dpo_register(DPO_MFIB_ENTRY, &mfib_entry_dpo_vft, mfib_entry_nodes);
1321  mfib_entry_logger = vlib_log_register_class("mfib", "entry");
1322 }
1323 
1324 void
1326  fib_route_path_encode_t **api_rpaths)
1327 {
1328  fib_route_path_encode_t *api_rpath;
1329  mfib_entry_t *mfib_entry;
1330  mfib_entry_src_t *bsrc;
1331 
1332  mfib_entry = mfib_entry_get(mfib_entry_index);
1333  bsrc = mfib_entry_get_best_src(mfib_entry);
1334 
1335  if (FIB_NODE_INDEX_INVALID != bsrc->mfes_pl)
1336  {
1338  NULL,
1340  api_rpaths);
1341  }
1342 
1343  vec_foreach(api_rpath, *api_rpaths)
1344  {
1345  mfib_itf_t *mfib_itf;
1346 
1347  mfib_itf = mfib_entry_itf_find(bsrc->mfes_itfs,
1348  api_rpath->rpath.frp_sw_if_index);
1349  if (mfib_itf)
1350  {
1351  api_rpath->rpath.frp_mitf_flags = mfib_itf->mfi_flags;
1352  }
1353  }
1354 }
1355 
1356 const mfib_prefix_t *
1358 {
1359  mfib_entry_t *mfib_entry;
1360 
1361  mfib_entry = mfib_entry_get(mfib_entry_index);
1362 
1363  return (&mfib_entry->mfe_prefix);
1364 }
1365 
1366 u32
1368 {
1369  mfib_entry_t *mfib_entry;
1370 
1371  mfib_entry = mfib_entry_get(mfib_entry_index);
1372 
1373  return (mfib_entry->mfe_fib_index);
1374 }
1375 
1376 const dpo_id_t*
1378 {
1379  mfib_entry_t *mfib_entry;
1380 
1381  mfib_entry = mfib_entry_get(mfib_entry_index);
1382 
1383  return (&mfib_entry->mfe_rep);
1384 }
1385 
1386 void
1390  dpo_id_t *dpo)
1391 {
1392  /*
1393  * An IP mFIB entry can only provide a forwarding chain that
1394  * is the same IP proto as the prefix.
1395  * No use-cases (i know of) for other combinations.
1396  */
1397  mfib_entry_t *mfib_entry;
1398  dpo_proto_t dp;
1399 
1400  mfib_entry = mfib_entry_get(mfib_entry_index);
1401 
1402  dp = fib_proto_to_dpo(mfib_entry->mfe_prefix.fp_proto);
1403 
1404  if (type == mfib_forw_chain_type_from_dpo_proto(dp))
1405  {
1406  replicate_t * rep;
1407 
1408  rep = replicate_get(mfib_entry->mfe_rep.dpoi_index);
1409 
1410  if ((rep->rep_flags & REPLICATE_FLAGS_HAS_LOCAL) &&
1411  (flags & MFIB_ENTRY_FWD_FLAG_NO_LOCAL))
1412  {
1413  /*
1414  * caller does not want the local paths that the entry has
1415  */
1416  dpo_set(dpo, DPO_REPLICATE, rep->rep_proto,
1418  mfib_entry->mfe_rep.dpoi_index));
1419  }
1420  else
1421  {
1422  dpo_copy(dpo, &mfib_entry->mfe_rep);
1423  }
1424  }
1425  else
1426  {
1427  dpo_copy(dpo, drop_dpo_get(dp));
1428  }
1429 }
1430 
1431 /*
1432  * fib_entry_cover_changed
1433  *
1434  * this entry is tracking its cover and that cover has changed.
1435  */
1436 void
1438 {
1439  mfib_entry_t *mfib_entry;
1441  mfib_src_res_t res;
1442 
1443  mfib_entry = mfib_entry_get(mfib_entry_index);
1444  msrc = mfib_entry_get_best_src(mfib_entry);
1445 
1446  res = mfib_entry_src_cover_change(mfib_entry, msrc);
1447 
1448  if (MFIB_SRC_REEVALUATE == res)
1449  {
1450  mfib_entry_recalculate_forwarding(mfib_entry, msrc->mfes_src);
1451  }
1452  MFIB_ENTRY_DBG(mfib_entry, "cover-changed");
1453 }
1454 
1455 /*
1456  * mfib_entry_cover_updated
1457  *
1458  * this entry is tracking its cover and that cover has been updated
1459  * (i.e. its forwarding information has changed).
1460  */
1461 void
1463 {
1464  mfib_entry_t *mfib_entry;
1466  mfib_src_res_t res;
1467 
1468  mfib_entry = mfib_entry_get(mfib_entry_index);
1469  msrc = mfib_entry_get_best_src(mfib_entry);
1470 
1471  res = mfib_entry_src_cover_update(mfib_entry, msrc);
1472 
1473  if (MFIB_SRC_REEVALUATE == res)
1474  {
1475  mfib_entry_recalculate_forwarding(mfib_entry, msrc->mfes_src);
1476  }
1477  MFIB_ENTRY_DBG(mfib_entry, "cover-updated");
1478 }
1479 
1480 u32
1482 {
1483  return (pool_elts(mfib_entry_pool));
1484 }
1485 
1486 static clib_error_t *
1488  unformat_input_t * input,
1489  vlib_cli_command_t * cmd)
1490 {
1491  fib_node_index_t fei;
1492 
1493  if (unformat (input, "%d", &fei))
1494  {
1495  /*
1496  * show one in detail
1497  */
1498  if (!pool_is_free_index(mfib_entry_pool, fei))
1499  {
1500  vlib_cli_output (vm, "%d@%U",
1501  fei,
1502  format_mfib_entry, fei,
1504  }
1505  else
1506  {
1507  vlib_cli_output (vm, "entry %d invalid", fei);
1508  }
1509  }
1510  else
1511  {
1512  /*
1513  * show all
1514  */
1515  vlib_cli_output (vm, "FIB Entries:");
1516  pool_foreach_index(fei, mfib_entry_pool,
1517  ({
1518  vlib_cli_output (vm, "%d@%U",
1519  fei,
1520  format_mfib_entry, fei,
1522  }));
1523  }
1524 
1525  return (NULL);
1526 }
1527 
1528 /*?
1529  * This commnad displays an entry, or all entries, in the mfib tables indexed by their unique
1530  * numerical indentifier.
1531  ?*/
1532 VLIB_CLI_COMMAND (show_mfib_entry, static) = {
1533  .path = "show mfib entry",
1534  .function = show_mfib_entry_command,
1535  .short_help = "show mfib entry",
1536 };
int mfib_itf_update(mfib_itf_t *mfib_itf, fib_node_index_t path_index, mfib_itf_flags_t mfi_flags)
update an interface from a path.
Definition: mfib_itf.c:66
vlib_log_class_t vlib_log_register_class(char *class, char *subclass)
Definition: log.c:227
u32 sw_if_index
Definition: ipsec_gre.api:37
int fib_path_is_resolved(fib_node_index_t path_index)
Definition: fib_path.c:2604
dpo_lock_fn_t dv_lock
A reference counting lock function.
Definition: dpo.h:404
Contribute an object that is to be used to forward BIER packets.
Definition: fib_types.h:122
#define MFIB_ENTRY_FORMAT_DETAIL
Definition: mfib_entry.h:111
static const char *const mfib_entry_ip4_nodes[]
Definition: mfib_entry.c:1299
Contribute an object that is to be used to forward IP6 packets.
Definition: fib_types.h:137
ip46_address_t fp_src_addr
Definition: mfib_types.h:47
Contribute an object that is to be used to forward IP6 packets.
Definition: fib_types.h:113
#define hash_set(h, key, value)
Definition: hash.h:255
u32 flags
Definition: vhost_user.h:115
static mfib_entry_src_t * mfib_entry_src_find_or_create(mfib_entry_t *mfib_entry, mfib_source_t source)
Definition: mfib_entry.c:246
fib_node_index_t path_index
The index of the FIB path.
Definition: load_balance.h:71
#define CLIB_UNUSED(x)
Definition: clib.h:82
A virtual function table regisitered for a DPO type.
Definition: dpo.h:399
A representation of a fib path for fib_path_encode to convey the information to the caller...
Definition: fib_types.h:594
fib_forward_chain_type_t fct
Definition: mfib_entry.c:486
void fib_path_contribute_forwarding(fib_node_index_t path_index, fib_forward_chain_type_t fct, dpo_id_t *dpo)
Definition: fib_path.c:2335
static const char *const *const mfib_entry_nodes[DPO_PROTO_NUM]
Definition: mfib_entry.c:1310
u32 mfib_entry_pool_size(void)
Definition: mfib_entry.c:1481
void fib_path_list_child_remove(fib_node_index_t path_list_index, u32 si)
int mfib_entry_delete(fib_node_index_t mfib_entry_index, mfib_source_t source)
mfib_entry_delete
Definition: mfib_entry.c:1096
enum mfib_entry_flags_t_ mfib_entry_flags_t
#define hash_unset(h, key)
Definition: hash.h:261
fib_node_index_t mfes_cover
A representation of a path as described by a route producer.
Definition: fib_types.h:476
dpo_id_t path_dpo
ID of the Data-path object.
Definition: load_balance.h:66
The FIB DPO provieds;.
Definition: replicate_dpo.h:63
enum mfib_entry_fwd_flags_t_ mfib_entry_fwd_flags_t
Flags to control what is present in the replicate DPO returned when the entry contributes forwarding...
void fib_node_init(fib_node_t *node, fib_node_type_t type)
Definition: fib_node.c:185
u32 frp_mitf_flags
MFIB interface flags.
Definition: fib_types.h:540
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 mfib_entry_unlock(fib_node_index_t mfib_entry_index)
Definition: mfib_entry.c:1274
struct mfib_entry_src_t_ * mfe_srcs
A vector of sources contributing forwarding.
Definition: mfib_entry.h:52
#define NULL
Definition: clib.h:58
An entry in a FIB table.
Definition: mfib_entry.h:32
u32 mfe_sibling
The sibling index on the path-list.
Definition: mfib_entry.h:62
#define MFIB_SOURCE_NONE
Definition: mfib_types.h:202
enum fib_node_back_walk_rc_t_ fib_node_back_walk_rc_t
Return code from a back walk function.
fib_node_index_t fib_path_list_create_special(dpo_proto_t nh_proto, fib_path_list_flags_t flags, const dpo_id_t *dpo)
vlib_log_class_t mfib_entry_logger
the logger
Definition: mfib_entry.c:30
#define MFIB_SOURCE_NAMES
Definition: mfib_types.h:179
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
static void mfib_entry_dpo_unlock(dpo_id_t *dpo)
Definition: mfib_entry.c:1288
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
Definition: vec.h:522
static fib_node_t * mfib_entry_get_node(fib_node_index_t index)
Definition: mfib_entry.c:48
dpo_proto_t rep_proto
The protocol of packets that traverse this REP.
Definition: replicate_dpo.h:80
static void mfib_entry_itf_remove(mfib_entry_src_t *msrc, u32 sw_if_index)
Definition: mfib_entry.c:922
#define vec_add2(V, P, N)
Add N elements to end of vector V, return pointer to new elements in P.
Definition: vec.h:560
int i
static fib_node_index_t mfib_entry_get_index(const mfib_entry_t *mfe)
Definition: mfib_entry.h:205
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:109
void fib_node_deinit(fib_node_t *node)
Definition: fib_node.c:197
u32 mfib_entry_child_add(fib_node_index_t mfib_entry_index, fib_node_type_t child_type, fib_node_index_t child_index)
Definition: mfib_entry.c:385
u8 * format(u8 *s, const char *fmt,...)
Definition: format.c:424
static mfib_path_ext_t * mfib_entry_path_ext_find(mfib_path_ext_t *exts, fib_node_index_t path_index)
Definition: mfib_entry.c:438
static replicate_t * replicate_get(index_t repi)
static const char *const mfib_entry_ip6_nodes[]
Definition: mfib_entry.c:1304
#define MFIB_ENTRY_FORMAT_BRIEF
Definition: mfib_entry.h:110
mfib_itf_t * mfes_itfs
The hash table of all interfaces.
#define pool_get(P, E)
Allocate an object E from a pool P (unspecified alignment).
Definition: pool.h:236
fib_forward_chain_type_t mfib_forw_chain_type_from_dpo_proto(dpo_proto_t proto)
Definition: mfib_types.c:71
void mfib_entry_cover_changed(fib_node_index_t mfib_entry_index)
Definition: mfib_entry.c:1437
u32 fib_path_list_child_add(fib_node_index_t path_list_index, fib_node_type_t child_type, fib_node_index_t child_index)
unsigned char u8
Definition: types.h:56
#define pool_len(p)
Number of elements in pool vector.
Definition: pool.h:140
fib_forward_chain_type_t mfib_entry_get_default_chain_type(const mfib_entry_t *mfib_entry)
Definition: mfib_entry.c:60
enum fib_protocol_t_ fib_protocol_t
Protocol Type.
static mfib_entry_t * mfib_entry_from_fib_node(fib_node_t *node)
Definition: mfib_entry.c:182
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
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
u8 * format_mfib_entry_flags(u8 *s, va_list *args)
Definition: mfib_types.c:161
enum mfib_source_t_ mfib_source_t
Possible [control plane] sources of MFIB entries.
static mfib_entry_t * mfib_entry_alloc(u32 fib_index, const mfib_prefix_t *prefix, fib_node_index_t *mfib_entry_index)
Definition: mfib_entry.c:405
u32 vlib_log_class_t
Definition: vlib.h:50
static void mfib_entry_recalculate_forwarding(mfib_entry_t *mfib_entry, mfib_source_t old_best)
Definition: mfib_entry.c:729
void dpo_register(dpo_type_t type, const dpo_vft_t *vft, const char *const *const *nodes)
For a given DPO type Register:
Definition: dpo.c:321
u32 frp_sw_if_index
The interface.
Definition: fib_types.h:511
#define MFIB_RPF_ID_NONE
Definition: fib_types.h:399
The source of an MFIB entry.
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:745
mfib_source_t mfes_src
Which source this is.
#define hash_foreach(key_var, value_var, h, body)
Definition: hash.h:442
load_balance_path_t * next_hops
Definition: mfib_entry.c:485
#define vec_elt_at_index(v, i)
Get vector value at index i checking that i is in bounds.
index_t replicate_dup(replicate_flags_t flags, index_t repi)
static fib_protocol_t mfib_entry_get_proto(const mfib_entry_t *mfib_entry)
Definition: mfib_entry.c:54
mfib_prefix_t mfe_prefix
The prefix of the route.
Definition: mfib_entry.h:42
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
void mfib_entry_module_init(void)
Definition: mfib_entry.c:1317
u32 mfib_entry_get_stats_index(fib_node_index_t fib_entry_index)
Definition: mfib_entry.c:1217
void mfib_entry_contribute_forwarding(fib_node_index_t mfib_entry_index, fib_forward_chain_type_t type, mfib_entry_fwd_flags_t flags, dpo_id_t *dpo)
Definition: mfib_entry.c:1387
struct mfib_entry_collect_forwarding_ctx_t_ mfib_entry_collect_forwarding_ctx_t
unsigned int u32
Definition: types.h:88
Contribute an object that is to be used to forward Ethernet packets.
Definition: fib_types.h:141
enum dpo_proto_t_ dpo_proto_t
Data path protocol.
u16 fib_path_get_weight(fib_node_index_t path_index)
Definition: fib_path.c:2170
static mfib_entry_src_t * mfib_entry_src_update(mfib_entry_t *mfib_entry, mfib_source_t source, fib_rpf_id_t rpf_id, mfib_entry_flags_t entry_flags)
Definition: mfib_entry.c:263
u32 mfib_entry_get_fib_index(fib_node_index_t mfib_entry_index)
Definition: mfib_entry.c:1367
void mfib_entry_src_deactivate(mfib_entry_t *mfib_entry, mfib_entry_src_t *msrc)
static mfib_source_t mfib_entry_get_best_source(const mfib_entry_t *mfib_entry)
Definition: mfib_entry.c:314
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:129
fib_node_bw_reason_flag_t fnbw_reason
The reason/trigger for the backwalk.
Definition: fib_node.h:208
int mfib_entry_update(fib_node_index_t mfib_entry_index, mfib_source_t source, mfib_entry_flags_t entry_flags, fib_rpf_id_t rpf_id, index_t repi)
Definition: mfib_entry.c:894
#define hash_get(h, key)
Definition: hash.h:249
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
Definition: pool.h:514
fib_node_index_t fib_path_list_create(fib_path_list_flags_t flags, const fib_route_path_t *rpaths)
dpo_id_t mfe_rep
The DPO used for forwarding; replicate, drop, etc.
Definition: mfib_entry.h:72
static fib_path_list_walk_rc_t mfib_entry_src_collect_forwarding(fib_node_index_t pl_index, fib_node_index_t path_index, void *arg)
Definition: mfib_entry.c:491
u32 mfes_ref_count
The reference count on the entry.
int mfib_entry_is_host(fib_node_index_t mfib_entry_index)
Definition: mfib_entry.c:335
static void mfib_entry_src_flush(mfib_entry_src_t *msrc)
Definition: mfib_entry.c:342
void fib_node_lock(fib_node_t *node)
Definition: fib_node.c:203
long ctx[MAX_CONNS]
Definition: main.c:144
static int fib_ip6_address_compare(ip6_address_t *a1, ip6_address_t *a2)
Definition: mfib_entry.c:1126
struct _unformat_input_t unformat_input_t
static fib_node_index_t mfib_entry_src_path_add(mfib_entry_src_t *msrc, const fib_route_path_t *rpath)
Definition: mfib_entry.c:677
int mfib_entry_is_sourced(fib_node_index_t mfib_entry_index, mfib_source_t source)
Definition: mfib_entry.c:324
#define hash_free(h)
Definition: hash.h:310
int mfib_entry_special_add(fib_node_index_t mfib_entry_index, mfib_source_t source, mfib_entry_flags_t entry_flags, fib_rpf_id_t rpf_id, index_t repi)
Definition: mfib_entry.c:872
#define pool_put(P, E)
Free an object E in pool P.
Definition: pool.h:286
fib_node_t mfe_node
Base class.
Definition: mfib_entry.h:37
int mfib_entry_cmp_for_sort(void *i1, void *i2)
Definition: mfib_entry.c:1185
void mfib_entry_path_update(fib_node_index_t mfib_entry_index, mfib_source_t source, const fib_route_path_t *rpath, mfib_itf_flags_t itf_flags)
Definition: mfib_entry.c:935
mfib_entry_t * mfib_entry_pool
Definition: mfib_entry.c:45
#define vec_del1(v, i)
Delete the element at index I.
Definition: vec.h:804
void fib_path_list_lock(fib_node_index_t path_list_index)
static mfib_path_ext_t * mfib_entry_path_ext_get(index_t mi)
Definition: mfib_entry.c:87
fib_rpf_id_t mfes_rpf_id
RPF-ID.
fib_node_type_t fn_type
The node&#39;s type.
Definition: fib_node.h:295
static void mfib_entry_dpo_lock(dpo_id_t *dpo)
Definition: mfib_entry.c:1284
An node in the FIB graph.
Definition: fib_node.h:291
void fib_node_unlock(fib_node_t *node)
Definition: fib_node.c:209
void mfib_entry_lock(fib_node_index_t mfib_entry_index)
Definition: mfib_entry.c:1264
u32 mfe_fib_index
The index of the FIB table this entry is in.
Definition: mfib_entry.h:47
static mfib_entry_t * mfib_entry_get(fib_node_index_t index)
Definition: mfib_entry.h:200
#define pool_get_aligned(P, E, A)
Allocate an object E from a pool P with alignment A.
Definition: pool.h:230
static mfib_path_ext_t * mfib_path_ext_add(mfib_entry_src_t *msrc, fib_node_index_t path_index, mfib_itf_flags_t mfi_flags)
Definition: mfib_entry.c:454
#define MFIB_ENTRY_DBG(_e, _fmt, _args...)
Definition: mfib_entry.h:100
void replicate_multipath_update(const dpo_id_t *dpo, load_balance_path_t *next_hops)
fib_node_list_t fn_children
Vector of nodes that depend upon/use/share this node.
Definition: fib_node.h:305
static u8 * format_mfib_entry_dpo(u8 *s, va_list *args)
Definition: mfib_entry.c:76
Do not reutrn any local replications in the set.
Definition: mfib_entry.h:182
vlib_main_t * vm
Definition: buffer.c:312
static mfib_entry_src_t * mfib_entry_src_find(const mfib_entry_t *mfib_entry, mfib_source_t source, u32 *index)
Definition: mfib_entry.c:217
Contribute an object that is to be used to forward NSH packets.
Definition: fib_types.h:147
u8 * format_mfib_entry(u8 *s, va_list *args)
Definition: mfib_entry.c:105
#define vec_free(V)
Free vector&#39;s memory (no header).
Definition: vec.h:341
static mfib_itf_t * mfib_entry_itf_find(mfib_itf_t *itfs, u32 sw_if_index)
Definition: mfib_entry.h:212
mfib_itf_flags_t mfi_flags
Forwarding Flags on the entry - checked in the data-path.
Definition: mfib_itf.h:35
static mfib_entry_src_t * mfib_entry_src_update_and_lock(mfib_entry_t *mfib_entry, mfib_source_t source, fib_rpf_id_t rpf_id, mfib_entry_flags_t entry_flags)
Definition: mfib_entry.c:279
fib_node_get_t fnv_get
Definition: fib_node.h:279
u32 fib_path_list_get_n_paths(fib_node_index_t path_list_index)
fib_node_index_t mfes_pl
The path-list of forwarding interfaces.
mfib_itf_t * mfe_itfs
A hash table of interfaces.
Definition: mfib_entry.h:87
u32 fib_node_index_t
A typedef of a node index.
Definition: fib_types.h:30
mfib_entry_flags_t mfe_flags
Route flags.
Definition: mfib_entry.h:77
#define pool_is_free_index(P, I)
Use free bitmap to query whether given index is free.
Definition: pool.h:283
#define ARRAY_LEN(x)
Definition: clib.h:62
mfib_path_ext_t * mfes_exts
Hash table of path extensions.
void dpo_set(dpo_id_t *dpo, dpo_type_t type, dpo_proto_t proto, index_t index)
Set/create a DPO ID The DPO will be locked.
Definition: dpo.c:185
void fib_path_list_unlock(fib_node_index_t path_list_index)
index_t replicate_create(u32 n_buckets, dpo_proto_t rep_proto)
static void mfib_entry_itf_add(mfib_entry_src_t *msrc, u32 sw_if_index, index_t mi)
Definition: mfib_entry.c:914
Aggregrate type for a prefix.
Definition: mfib_types.h:24
enum mfib_src_res_t_ mfib_src_res_t
signals from the sources to the caller
Context passed between object during a back walk.
Definition: fib_node.h:204
u32 fib_rpf_id_t
An RPF-ID is numerical value that is used RPF validate.
Definition: fib_types.h:397
#define VLIB_CLI_COMMAND(x,...)
Definition: cli.h:155
fib_node_index_t mfe_pl
The path-list of which this entry is a child.
Definition: mfib_entry.h:57
static void mfib_path_ext_remove(mfib_entry_src_t *msrc, fib_node_index_t path_index)
Definition: mfib_entry.c:472
MFIB extensions to each path.
static void mfib_entry_last_lock_gone(fib_node_t *node)
Definition: mfib_entry.c:1194
#define ASSERT(truth)
static void mfib_entry_update_i(mfib_entry_t *mfib_entry, mfib_entry_src_t *msrc, mfib_source_t current_best, index_t repi)
Definition: mfib_entry.c:827
mfib_src_res_t mfib_entry_src_cover_update(mfib_entry_t *mfib_entry, mfib_entry_src_t *msrc)
void mfib_entry_cover_updated(fib_node_index_t mfib_entry_index)
Definition: mfib_entry.c:1462
static void mfib_entry_stack(mfib_entry_t *mfib_entry, mfib_entry_src_t *msrc)
Definition: mfib_entry.c:551
mfib_itf_flags_t mfpe_flags
const dpo_id_t * mfib_entry_contribute_ip_forwarding(fib_node_index_t mfib_entry_index)
Definition: mfib_entry.c:1377
An interface associated with a particular MFIB entry.
Definition: mfib_itf.h:25
static int mfib_entry_ok_for_delete(mfib_entry_t *mfib_entry)
Definition: mfib_entry.c:812
static u8 * format_mfib_entry_path_ext(u8 *s, va_list *args)
Definition: mfib_entry.c:93
enum fib_forward_chain_type_t_ fib_forward_chain_type_t
FIB output chain type.
u8 * format_fib_forw_chain_type(u8 *s, va_list *args)
Definition: fib_types.c:48
static int mfib_entry_cmp(fib_node_index_t mfib_entry_index1, fib_node_index_t mfib_entry_index2)
Definition: mfib_entry.c:1141
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
dpo_proto_t fib_proto_to_dpo(fib_protocol_t fib_proto)
Definition: fib_types.c:244
fib_rpf_id_t mfe_rpf_id
RPF-ID used when the packets ingress not from an interface.
Definition: mfib_entry.h:82
u8 * format_dpo_id(u8 *s, va_list *args)
Format a DPO_id_t oject
Definition: dpo.c:147
static clib_error_t * show_mfib_entry_command(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: mfib_entry.c:1487
void mfib_entry_encode(fib_node_index_t mfib_entry_index, fib_route_path_encode_t **api_rpaths)
Definition: mfib_entry.c:1325
index_t mfib_itf_create(fib_node_index_t path_index, mfib_itf_flags_t mfi_flags)
Definition: mfib_itf.c:25
fib_protocol_t fp_proto
protocol type
Definition: mfib_types.h:33
#define DPO_PROTO_NUM
Definition: dpo.h:70
enum fib_path_list_walk_rc_t_ fib_path_list_walk_rc_t
return code to control pat-hlist walk
index_t dpoi_index
the index of objects of that type
Definition: dpo.h:184
#define FIB_NODE_INDEX_INVALID
Definition: fib_types.h:31
mfib_src_res_t mfib_entry_src_cover_change(mfib_entry_t *mfib_entry, mfib_entry_src_t *msrc)
fib_node_index_t mfpe_path
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
u32 path_weight
weight for the path.
Definition: load_balance.h:76
fib_node_index_t mfib_entry_create(u32 fib_index, mfib_source_t source, const mfib_prefix_t *prefix, fib_rpf_id_t rpf_id, mfib_entry_flags_t entry_flags, index_t repi)
Definition: mfib_entry.c:763
u32 fn_locks
Number of dependents on this node.
Definition: fib_node.h:311
const mfib_prefix_t * mfib_entry_get_prefix(fib_node_index_t mfib_entry_index)
Definition: mfib_entry.c:1357
#define INDEX_INVALID
Invalid index - used when no index is known blazoned capitals INVALID speak volumes where ~0 does not...
Definition: dpo.h:47
static mfib_path_ext_t * mfib_path_ext_pool
Pool of path extensions.
Definition: mfib_entry.c:35
u8 * fib_path_list_format(fib_node_index_t path_list_index, u8 *s)
u64 uword
Definition: types.h:112
#define vec_sort_with_function(vec, f)
Sort a vector using the supplied element comparison function.
Definition: vec.h:980
int mfib_prefix_is_host(const mfib_prefix_t *pfx)
Return true is the prefix is a host prefix.
Definition: mfib_types.c:55
static int fib_ip4_address_compare(ip4_address_t *a1, ip4_address_t *a2)
Definition: mfib_entry.c:1112
u8 * format_mfib_itf_flags(u8 *s, va_list *args)
Definition: mfib_types.c:181
#define DPO_INVALID
An initialiser for DPOs declared on the stack.
Definition: dpo.h:195
One path from an [EU]CMP set that the client wants to add to a load-balance object.
Definition: load_balance.h:62
enum mfib_itf_flags_t_ mfib_itf_flags_t
typedef prefix
Definition: ip_types.api:35
Definition: mfib_entry.c:483
void mfib_entry_src_activate(mfib_entry_t *mfib_entry, mfib_entry_src_t *msrc)
fib_node_index_t fib_path_list_path_add(fib_node_index_t path_list_index, const fib_route_path_t *rpaths)
static int mfib_entry_src_ok_for_delete(const mfib_entry_src_t *msrc)
Definition: mfib_entry.c:818
A FIB graph nodes virtual function table.
Definition: fib_node.h:278
static fib_node_index_t mfib_entry_src_path_remove(mfib_entry_src_t *msrc, const fib_route_path_t *rpath)
Definition: mfib_entry.c:707
static const char * mfib_source_names[]
String names for each source.
Definition: mfib_entry.c:40
static void mfib_entry_src_init(mfib_entry_t *mfib_entry, mfib_source_t source)
Definition: mfib_entry.c:198
mfib_entry_flags_t mfes_flags
Route flags.
enum fib_node_type_t_ fib_node_type_t
The types of nodes in a FIB graph.
static fib_node_back_walk_rc_t mfib_entry_back_walk_notify(fib_node_t *node, fib_node_back_walk_ctx_t *ctx)
Definition: mfib_entry.c:1232
int dpo_is_drop(const dpo_id_t *dpo)
The Drop DPO will drop all packets, no questions asked.
Definition: drop_dpo.c:33
void dpo_reset(dpo_id_t *dpo)
reset a DPO ID The DPO will be unlocked.
Definition: dpo.c:231
void mfib_entry_cover_update_notify(mfib_entry_t *mfib_entry)
#define vec_foreach(var, vec)
Vector iterator.
void mfib_itf_delete(mfib_itf_t *mfi)
Definition: mfib_itf.c:113
fib_path_list_walk_rc_t fib_path_encode(fib_node_index_t path_list_index, fib_node_index_t path_index, const fib_path_ext_t *path_ext, void *ctx)
Definition: fib_path.c:2627
fib_route_path_t rpath
Definition: fib_types.h:595
mfib_entry_src_t * mfib_entry_get_best_src(const mfib_entry_t *mfib_entry)
Definition: mfib_entry.c:294
static void mfib_entry_show_memory(void)
Definition: mfib_entry.c:1245
void fib_path_list_walk_w_ext(fib_node_index_t path_list_index, const fib_path_ext_list_t *ext_list, fib_path_list_walk_w_ext_fn_t func, void *ctx)
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:118
replicate_flags_t rep_flags
Flags specifying the replicate properties/behaviour.
Definition: replicate_dpo.h:85
static void mfib_entry_src_remove(mfib_entry_t *mfib_entry, mfib_source_t source)
Definition: mfib_entry.c:357
#define pool_foreach_index(i, v, body)
Iterate pool by index.
Definition: pool.h:538
#define MFIB_ENTRY_FORMAT_DETAIL2
Definition: mfib_entry.h:112
u16 fp_len
The mask length.
Definition: mfib_types.h:28
u8 * fib_node_children_format(fib_node_list_t list, u8 *s)
Definition: fib_node.c:176
#define CLIB_CACHE_LINE_BYTES
Definition: cache.h:59
void mfib_entry_child_remove(fib_node_index_t mfib_entry_index, u32 sibling_index)
Definition: mfib_entry.c:396
mfib_entry_src_t * msrc
Definition: mfib_entry.c:487
static int mfib_entry_src_cmp_for_sort(void *v1, void *v2)
Definition: mfib_entry.c:189
Contribute an object that is to be used to forward IP4 packets.
Definition: fib_types.h:133
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
Definition: cli.c:762
u8 * format_mfib_prefix(u8 *s, va_list *args)
Definition: mfib_types.c:106
uword unformat(unformat_input_t *i, const char *fmt,...)
Definition: unformat.c:972
ip46_address_t fp_grp_addr
The address type is not deriveable from the fp_addr member.
Definition: mfib_types.h:46
fib_node_index_t fib_path_list_path_remove(fib_node_index_t path_list_index, const fib_route_path_t *rpaths)
int mfib_entry_path_remove(fib_node_index_t mfib_entry_index, mfib_source_t source, const fib_route_path_t *rpath)
Definition: mfib_entry.c:1022
void dpo_stack(dpo_type_t child_type, dpo_proto_t child_proto, dpo_id_t *dpo, const dpo_id_t *parent)
Stack one DPO object on another, and thus establish a child-parent relationship.
Definition: dpo.c:515
u32 itf_flags
Definition: ip.api:511
static uword pool_elts(void *v)
Number of active elements in a pool.
Definition: pool.h:128