blob: c08565d966ca7bbf7dbc77af1bc46d77b3bda59e [file] [log] [blame]
Neale Ranns32e1c012016-11-22 17:07:28 +00001/*
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>
Neale Ranns9e829a82018-12-17 05:50:32 -080019#include <vnet/mfib/mfib_entry_src.h>
20#include <vnet/mfib/mfib_entry_cover.h>
Neale Ranns32e1c012016-11-22 17:07:28 +000021#include <vnet/fib/fib_path_list.h>
Neale Ranns9e829a82018-12-17 05:50:32 -080022#include <vnet/fib/fib_walk.h>
Neale Ranns32e1c012016-11-22 17:07:28 +000023
24#include <vnet/dpo/drop_dpo.h>
25#include <vnet/dpo/replicate_dpo.h>
26
27/**
Neale Ranns710071b2018-09-24 12:36:26 +000028 * the logger
29 */
30vlib_log_class_t mfib_entry_logger;
31
32/**
Neale Ranns0f26c5a2017-03-01 15:12:11 -080033 * Pool of path extensions
34 */
35static mfib_path_ext_t *mfib_path_ext_pool;
36
37/**
Neale Ranns32e1c012016-11-22 17:07:28 +000038 * String names for each source
39 */
40static const char *mfib_source_names[] = MFIB_SOURCE_NAMES;
Neale Ranns9db6ada2019-11-08 12:42:31 +000041static const char *mfib_src_attribute_names[] = MFIB_ENTRY_SRC_ATTRIBUTES;
Neale Ranns32e1c012016-11-22 17:07:28 +000042
43/*
44 * Pool for all fib_entries
45 */
46mfib_entry_t *mfib_entry_pool;
47
48static fib_node_t *
49mfib_entry_get_node (fib_node_index_t index)
50{
51 return ((fib_node_t*)mfib_entry_get(index));
52}
53
54static fib_protocol_t
55mfib_entry_get_proto (const mfib_entry_t * mfib_entry)
56{
57 return (mfib_entry->mfe_prefix.fp_proto);
58}
59
60fib_forward_chain_type_t
61mfib_entry_get_default_chain_type (const mfib_entry_t *mfib_entry)
62{
63 switch (mfib_entry->mfe_prefix.fp_proto)
64 {
65 case FIB_PROTOCOL_IP4:
66 return (FIB_FORW_CHAIN_TYPE_MCAST_IP4);
67 case FIB_PROTOCOL_IP6:
68 return (FIB_FORW_CHAIN_TYPE_MCAST_IP6);
69 case FIB_PROTOCOL_MPLS:
70 ASSERT(0);
71 break;
72 }
73 return (FIB_FORW_CHAIN_TYPE_MCAST_IP4);
74}
75
76static u8 *
77format_mfib_entry_dpo (u8 * s, va_list * args)
78{
79 index_t fei = va_arg(*args, index_t);
80 CLIB_UNUSED(u32 indent) = va_arg(*args, u32);
81
82 return (format(s, "%U",
83 format_mfib_entry, fei,
84 MFIB_ENTRY_FORMAT_BRIEF));
85}
86
Neale Ranns0f26c5a2017-03-01 15:12:11 -080087static inline mfib_path_ext_t *
88mfib_entry_path_ext_get (index_t mi)
89{
90 return (pool_elt_at_index(mfib_path_ext_pool, mi));
91}
92
93static u8 *
94format_mfib_entry_path_ext (u8 * s, va_list * args)
95{
96 mfib_path_ext_t *path_ext;
97 index_t mpi = va_arg(*args, index_t);
98
99 path_ext = mfib_entry_path_ext_get(mpi);
100 return (format(s, "path:%d flags:%U",
101 path_ext->mfpe_path,
102 format_mfib_itf_flags, path_ext->mfpe_flags));
103}
104
Neale Ranns32e1c012016-11-22 17:07:28 +0000105u8 *
Neale Ranns9db6ada2019-11-08 12:42:31 +0000106format_mfib_entry_src_flags (u8 *s, va_list *args)
107{
108 mfib_entry_src_attribute_t sattr;
109 mfib_entry_src_flags_t flag = va_arg(*args, int);
110
111 if (!flag)
112 {
113 return format(s, "none");
114 }
115
116 FOR_EACH_MFIB_SRC_ATTRIBUTE(sattr) {
117 if ((1 << sattr) & flag) {
118 s = format (s, "%s,", mfib_src_attribute_names[sattr]);
119 }
120 }
121
122 return (s);
123}
124
125u8 *
Neale Ranns32e1c012016-11-22 17:07:28 +0000126format_mfib_entry (u8 * s, va_list * args)
127{
128 fib_node_index_t fei, mfi;
129 mfib_entry_t *mfib_entry;
130 mfib_entry_src_t *msrc;
131 u32 sw_if_index;
132 int level;
133
134 fei = va_arg (*args, fib_node_index_t);
135 level = va_arg (*args, int);
136 mfib_entry = mfib_entry_get(fei);
137
138 s = format (s, "%U", format_mfib_prefix, &mfib_entry->mfe_prefix);
139 s = format (s, ": %U", format_mfib_entry_flags, mfib_entry->mfe_flags);
140
141 if (level >= MFIB_ENTRY_FORMAT_DETAIL)
142 {
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800143 fib_node_index_t path_index, mpi;
144
Neale Ranns32e1c012016-11-22 17:07:28 +0000145 s = format (s, "\n");
146 s = format (s, " fib:%d", mfib_entry->mfe_fib_index);
147 s = format (s, " index:%d", mfib_entry_get_index(mfib_entry));
148 s = format (s, " locks:%d\n", mfib_entry->mfe_node.fn_locks);
149 vec_foreach(msrc, mfib_entry->mfe_srcs)
150 {
Neale Ranns9db6ada2019-11-08 12:42:31 +0000151 s = format (s, " src:%s flags:%U locks:%d:",
Neale Ranns9e829a82018-12-17 05:50:32 -0800152 mfib_source_names[msrc->mfes_src],
Neale Ranns9db6ada2019-11-08 12:42:31 +0000153 format_mfib_entry_src_flags, msrc->mfes_flags,
Neale Ranns9e829a82018-12-17 05:50:32 -0800154 msrc->mfes_ref_count);
155 if (msrc->mfes_cover != FIB_NODE_INDEX_INVALID)
156 {
157 s = format (s, " cover:%d", msrc->mfes_cover);
158 }
Neale Ranns9db6ada2019-11-08 12:42:31 +0000159 s = format (s, " %U\n", format_mfib_entry_flags, msrc->mfes_route_flags);
Neale Ranns32e1c012016-11-22 17:07:28 +0000160 if (FIB_NODE_INDEX_INVALID != msrc->mfes_pl)
161 {
162 s = fib_path_list_format(msrc->mfes_pl, s);
163 }
Neale Ranns5d85f2d2017-05-02 10:17:17 -0700164 s = format (s, " Extensions:\n");
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800165 hash_foreach(path_index, mpi, msrc->mfes_exts,
166 ({
167 s = format(s, " %U\n", format_mfib_entry_path_ext, mpi);
168 }));
Neale Ranns5d85f2d2017-05-02 10:17:17 -0700169 s = format (s, " Interface-Forwarding:\n");
Neale Ranns32e1c012016-11-22 17:07:28 +0000170 hash_foreach(sw_if_index, mfi, msrc->mfes_itfs,
171 ({
172 s = format(s, " %U\n", format_mfib_itf, mfi);
173 }));
174 }
175 }
176
177 s = format(s, "\n Interfaces:");
178 hash_foreach(sw_if_index, mfi, mfib_entry->mfe_itfs,
179 ({
180 s = format(s, "\n %U", format_mfib_itf, mfi);
181 }));
Neale Rannse821ab12017-06-01 07:45:05 -0700182 if (MFIB_RPF_ID_NONE != mfib_entry->mfe_rpf_id)
183 {
184 s = format(s, "\n RPF-ID:%d", mfib_entry->mfe_rpf_id);
185 }
Neale Ranns32e1c012016-11-22 17:07:28 +0000186 s = format(s, "\n %U-chain\n %U",
187 format_fib_forw_chain_type,
188 mfib_entry_get_default_chain_type(mfib_entry),
189 format_dpo_id,
190 &mfib_entry->mfe_rep,
191 2);
192 s = format(s, "\n");
193
194 if (level >= MFIB_ENTRY_FORMAT_DETAIL2)
195 {
196 s = format(s, "\nchildren:");
197 s = fib_node_children_format(mfib_entry->mfe_node.fn_children, s);
198 }
199
200 return (s);
201}
202
203static mfib_entry_t*
204mfib_entry_from_fib_node (fib_node_t *node)
205{
Neale Ranns32e1c012016-11-22 17:07:28 +0000206 ASSERT(FIB_NODE_TYPE_MFIB_ENTRY == node->fn_type);
Neale Ranns32e1c012016-11-22 17:07:28 +0000207 return ((mfib_entry_t*)node);
208}
209
210static int
211mfib_entry_src_cmp_for_sort (void * v1,
212 void * v2)
213{
214 mfib_entry_src_t *esrc1 = v1, *esrc2 = v2;
215
216 return (esrc1->mfes_src - esrc2->mfes_src);
217}
218
219static void
220mfib_entry_src_init (mfib_entry_t *mfib_entry,
221 mfib_source_t source)
222
223{
224 mfib_entry_src_t esrc = {
225 .mfes_pl = FIB_NODE_INDEX_INVALID,
Neale Ranns9db6ada2019-11-08 12:42:31 +0000226 .mfes_route_flags = MFIB_ENTRY_FLAG_NONE,
Neale Ranns32e1c012016-11-22 17:07:28 +0000227 .mfes_src = source,
Neale Ranns9e829a82018-12-17 05:50:32 -0800228 .mfes_cover = FIB_NODE_INDEX_INVALID,
229 .mfes_sibling = FIB_NODE_INDEX_INVALID,
230 .mfes_ref_count = 1,
Neale Ranns32e1c012016-11-22 17:07:28 +0000231 };
232
233 vec_add1(mfib_entry->mfe_srcs, esrc);
234 vec_sort_with_function(mfib_entry->mfe_srcs,
235 mfib_entry_src_cmp_for_sort);
236}
237
238static mfib_entry_src_t *
239mfib_entry_src_find (const mfib_entry_t *mfib_entry,
Neale Ranns9db6ada2019-11-08 12:42:31 +0000240 mfib_source_t source,
241 u32 *index)
Neale Ranns32e1c012016-11-22 17:07:28 +0000242
243{
244 mfib_entry_src_t *esrc;
245 int ii;
246
247 ii = 0;
248 vec_foreach(esrc, mfib_entry->mfe_srcs)
249 {
250 if (esrc->mfes_src == source)
251 {
252 if (NULL != index)
253 {
254 *index = ii;
255 }
256 return (esrc);
257 }
258 else
259 {
260 ii++;
261 }
262 }
263
264 return (NULL);
265}
266
267static mfib_entry_src_t *
268mfib_entry_src_find_or_create (mfib_entry_t *mfib_entry,
Neale Rannsd792d9c2017-10-21 10:53:20 -0700269 mfib_source_t source)
Neale Ranns32e1c012016-11-22 17:07:28 +0000270{
Neale Ranns9e829a82018-12-17 05:50:32 -0800271 mfib_entry_src_t *msrc;
Neale Ranns32e1c012016-11-22 17:07:28 +0000272
Neale Ranns9e829a82018-12-17 05:50:32 -0800273 msrc = mfib_entry_src_find(mfib_entry, source, NULL);
Neale Ranns32e1c012016-11-22 17:07:28 +0000274
Neale Ranns9e829a82018-12-17 05:50:32 -0800275 if (NULL == msrc)
Neale Ranns32e1c012016-11-22 17:07:28 +0000276 {
277 mfib_entry_src_init(mfib_entry, source);
Neale Ranns9e829a82018-12-17 05:50:32 -0800278 msrc = mfib_entry_src_find(mfib_entry, source, NULL);
Neale Ranns32e1c012016-11-22 17:07:28 +0000279 }
280
Neale Ranns9e829a82018-12-17 05:50:32 -0800281 return (msrc);
Neale Ranns32e1c012016-11-22 17:07:28 +0000282}
283
Neale Ranns9e829a82018-12-17 05:50:32 -0800284static mfib_entry_src_t *
285mfib_entry_src_update (mfib_entry_t *mfib_entry,
286 mfib_source_t source,
287 fib_rpf_id_t rpf_id,
288 mfib_entry_flags_t entry_flags)
289{
290 mfib_entry_src_t *msrc;
291
292 msrc = mfib_entry_src_find_or_create(mfib_entry, source);
293
Neale Ranns9db6ada2019-11-08 12:42:31 +0000294 msrc->mfes_route_flags = entry_flags;
Neale Ranns9e829a82018-12-17 05:50:32 -0800295 msrc->mfes_rpf_id = rpf_id;
Neale Ranns9db6ada2019-11-08 12:42:31 +0000296 msrc->mfes_flags &= ~MFIB_ENTRY_SRC_FLAG_STALE;
Neale Ranns9e829a82018-12-17 05:50:32 -0800297
298 return (msrc);
299}
300
301static mfib_entry_src_t *
302mfib_entry_src_update_and_lock (mfib_entry_t *mfib_entry,
303 mfib_source_t source,
304 fib_rpf_id_t rpf_id,
305 mfib_entry_flags_t entry_flags)
306{
307 mfib_entry_src_t *msrc;
308
309 msrc = mfib_entry_src_update(mfib_entry, source, rpf_id, entry_flags);
310
311 msrc->mfes_ref_count++;
Neale Ranns9db6ada2019-11-08 12:42:31 +0000312 msrc->mfes_flags &= ~MFIB_ENTRY_SRC_FLAG_STALE;
Neale Ranns9e829a82018-12-17 05:50:32 -0800313
314 return (msrc);
315}
316
317mfib_entry_src_t*
Neale Ranns32e1c012016-11-22 17:07:28 +0000318mfib_entry_get_best_src (const mfib_entry_t *mfib_entry)
319{
320 mfib_entry_src_t *bsrc;
321
322 /*
323 * the enum of sources is deliberately arranged in priority order
324 */
325 if (0 == vec_len(mfib_entry->mfe_srcs))
326 {
327 bsrc = NULL;
328 }
329 else
330 {
331 bsrc = vec_elt_at_index(mfib_entry->mfe_srcs, 0);
332 }
333
334 return (bsrc);
335}
336
Neale Ranns9e829a82018-12-17 05:50:32 -0800337static mfib_source_t
338mfib_entry_get_best_source (const mfib_entry_t *mfib_entry)
339{
340 mfib_entry_src_t *bsrc;
341
342 bsrc = mfib_entry_get_best_src(mfib_entry);
343
344 return (bsrc->mfes_src);
345}
346
Neale Ranns15002542017-09-10 04:39:11 -0700347int
348mfib_entry_is_sourced (fib_node_index_t mfib_entry_index,
349 mfib_source_t source)
350{
351 mfib_entry_t *mfib_entry;
352
353 mfib_entry = mfib_entry_get(mfib_entry_index);
354
355 return (NULL != mfib_entry_src_find(mfib_entry, source, NULL));
356}
357
Neale Ranns9e829a82018-12-17 05:50:32 -0800358int
Neale Ranns9db6ada2019-11-08 12:42:31 +0000359mfib_entry_is_marked (fib_node_index_t mfib_entry_index,
360 mfib_source_t source)
361{
362 mfib_entry_t *mfib_entry;
363 mfib_entry_src_t *esrc;
364
365 mfib_entry = mfib_entry_get(mfib_entry_index);
366
367 esrc = mfib_entry_src_find(mfib_entry, source, NULL);
368
369 if (NULL == esrc)
370 {
371 return (0);
372 }
373 else
374 {
375 return (!!(esrc->mfes_flags & MFIB_ENTRY_SRC_FLAG_STALE));
376 }
377}
378
379void
380mfib_entry_mark (fib_node_index_t fib_entry_index,
381 mfib_source_t source)
382{
383 mfib_entry_t *mfib_entry;
384 mfib_entry_src_t *esrc;
385
386 mfib_entry = mfib_entry_get(fib_entry_index);
387
388 esrc = mfib_entry_src_find(mfib_entry, source, NULL);
389
390 if (NULL != esrc)
391 {
392 esrc->mfes_flags |= MFIB_ENTRY_SRC_FLAG_STALE;
393 }
394}
395
396int
Neale Ranns9e829a82018-12-17 05:50:32 -0800397mfib_entry_is_host (fib_node_index_t mfib_entry_index)
398{
399 return (mfib_prefix_is_host(mfib_entry_get_prefix(mfib_entry_index)));
400}
401
402
Neale Ranns32e1c012016-11-22 17:07:28 +0000403static void
404mfib_entry_src_flush (mfib_entry_src_t *msrc)
405{
406 u32 sw_if_index;
407 index_t mfii;
408
409 hash_foreach(sw_if_index, mfii, msrc->mfes_itfs,
410 ({
411 mfib_itf_delete(mfib_itf_get(mfii));
412 }));
Neale Rannsbcc6aa42017-02-24 01:34:14 -0800413 hash_free(msrc->mfes_itfs);
414 msrc->mfes_itfs = NULL;
Neale Rannsa9374df2017-02-02 02:18:18 -0800415 fib_path_list_unlock(msrc->mfes_pl);
Neale Ranns32e1c012016-11-22 17:07:28 +0000416}
417
418static void
419mfib_entry_src_remove (mfib_entry_t *mfib_entry,
420 mfib_source_t source)
421
422{
423 mfib_entry_src_t *msrc;
424 u32 index = ~0;
425
426 msrc = mfib_entry_src_find(mfib_entry, source, &index);
427
428 if (NULL != msrc)
429 {
Neale Ranns9e829a82018-12-17 05:50:32 -0800430 ASSERT(0 != msrc->mfes_ref_count);
431 msrc->mfes_ref_count--;
432
433 if (0 == msrc->mfes_ref_count)
434 {
435 mfib_entry_src_deactivate(mfib_entry, msrc);
436 mfib_entry_src_flush(msrc);
437
438 vec_del1(mfib_entry->mfe_srcs, index);
439 if (vec_len (mfib_entry->mfe_srcs) > 1)
440 vec_sort_with_function(mfib_entry->mfe_srcs,
441 mfib_entry_src_cmp_for_sort);
442 }
Neale Ranns32e1c012016-11-22 17:07:28 +0000443 }
444}
445
Neale Ranns32e1c012016-11-22 17:07:28 +0000446u32
447mfib_entry_child_add (fib_node_index_t mfib_entry_index,
448 fib_node_type_t child_type,
449 fib_node_index_t child_index)
450{
451 return (fib_node_child_add(FIB_NODE_TYPE_MFIB_ENTRY,
452 mfib_entry_index,
453 child_type,
454 child_index));
455};
456
457void
458mfib_entry_child_remove (fib_node_index_t mfib_entry_index,
459 u32 sibling_index)
460{
461 fib_node_child_remove(FIB_NODE_TYPE_MFIB_ENTRY,
462 mfib_entry_index,
463 sibling_index);
464}
465
466static mfib_entry_t *
467mfib_entry_alloc (u32 fib_index,
468 const mfib_prefix_t *prefix,
469 fib_node_index_t *mfib_entry_index)
470{
471 mfib_entry_t *mfib_entry;
472
Marco Varlese47501da2017-08-29 14:04:06 +0200473 pool_get_aligned(mfib_entry_pool, mfib_entry, CLIB_CACHE_LINE_BYTES);
Neale Ranns32e1c012016-11-22 17:07:28 +0000474
475 fib_node_init(&mfib_entry->mfe_node,
476 FIB_NODE_TYPE_MFIB_ENTRY);
477
Neale Ranns5a72c1c2017-02-24 08:29:22 -0800478 /*
479 * Some of the members require non-default initialisation
Dave Barachb7b92992018-10-17 10:38:51 -0400480 * so we also init those that don't and thus save on the call to clib_memset.
Neale Ranns5a72c1c2017-02-24 08:29:22 -0800481 */
482 mfib_entry->mfe_flags = 0;
Neale Ranns32e1c012016-11-22 17:07:28 +0000483 mfib_entry->mfe_fib_index = fib_index;
484 mfib_entry->mfe_prefix = *prefix;
Neale Ranns5a72c1c2017-02-24 08:29:22 -0800485 mfib_entry->mfe_srcs = NULL;
486 mfib_entry->mfe_itfs = NULL;
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800487 mfib_entry->mfe_rpf_id = MFIB_RPF_ID_NONE;
Neale Rannsc2aad532017-05-30 09:53:52 -0700488 mfib_entry->mfe_pl = FIB_NODE_INDEX_INVALID;
Neale Ranns32e1c012016-11-22 17:07:28 +0000489
490 dpo_reset(&mfib_entry->mfe_rep);
491
492 *mfib_entry_index = mfib_entry_get_index(mfib_entry);
493
494 MFIB_ENTRY_DBG(mfib_entry, "alloc");
495
496 return (mfib_entry);
497}
498
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800499static inline mfib_path_ext_t *
500mfib_entry_path_ext_find (mfib_path_ext_t *exts,
501 fib_node_index_t path_index)
502{
503 uword *p;
504
505 p = hash_get(exts, path_index);
506
507 if (NULL != p)
508 {
509 return (mfib_entry_path_ext_get(p[0]));
510 }
511
512 return (NULL);
513}
514
515static mfib_path_ext_t*
516mfib_path_ext_add (mfib_entry_src_t *msrc,
517 fib_node_index_t path_index,
518 mfib_itf_flags_t mfi_flags)
519{
520 mfib_path_ext_t *path_ext;
521
522 pool_get(mfib_path_ext_pool, path_ext);
523
524 path_ext->mfpe_flags = mfi_flags;
525 path_ext->mfpe_path = path_index;
526
527 hash_set(msrc->mfes_exts, path_index,
528 path_ext - mfib_path_ext_pool);
529
530 return (path_ext);
531}
532
533static void
534mfib_path_ext_remove (mfib_entry_src_t *msrc,
535 fib_node_index_t path_index)
536{
537 mfib_path_ext_t *path_ext;
538
539 path_ext = mfib_entry_path_ext_find(msrc->mfes_exts, path_index);
540
541 hash_unset(msrc->mfes_exts, path_index);
542 pool_put(mfib_path_ext_pool, path_ext);
543}
544
Neale Ranns32e1c012016-11-22 17:07:28 +0000545typedef struct mfib_entry_collect_forwarding_ctx_t_
546{
547 load_balance_path_t * next_hops;
548 fib_forward_chain_type_t fct;
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800549 mfib_entry_src_t *msrc;
Neale Ranns32e1c012016-11-22 17:07:28 +0000550} mfib_entry_collect_forwarding_ctx_t;
551
Neale Ranns81424992017-05-18 03:03:22 -0700552static fib_path_list_walk_rc_t
Neale Ranns32e1c012016-11-22 17:07:28 +0000553mfib_entry_src_collect_forwarding (fib_node_index_t pl_index,
554 fib_node_index_t path_index,
555 void *arg)
556{
557 mfib_entry_collect_forwarding_ctx_t *ctx;
558 load_balance_path_t *nh;
559
560 ctx = arg;
561
562 /*
563 * if the path is not resolved, don't include it.
564 */
565 if (!fib_path_is_resolved(path_index))
566 {
Neale Ranns81424992017-05-18 03:03:22 -0700567 return (FIB_PATH_LIST_WALK_CONTINUE);
Neale Ranns32e1c012016-11-22 17:07:28 +0000568 }
569
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800570 /*
571 * If the path is not forwarding to use it
572 */
573 mfib_path_ext_t *path_ext;
574
575 path_ext = mfib_entry_path_ext_find(ctx->msrc->mfes_exts,
576 path_index);
577
578 if (NULL != path_ext &&
579 !(path_ext->mfpe_flags & MFIB_ITF_FLAG_FORWARD))
580 {
Neale Ranns81424992017-05-18 03:03:22 -0700581 return (FIB_PATH_LIST_WALK_CONTINUE);
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800582 }
583
Neale Ranns32e1c012016-11-22 17:07:28 +0000584 switch (ctx->fct)
585 {
586 case FIB_FORW_CHAIN_TYPE_MCAST_IP4:
587 case FIB_FORW_CHAIN_TYPE_MCAST_IP6:
588 /*
589 * EOS traffic with no label to stack, we need the IP Adj
590 */
591 vec_add2(ctx->next_hops, nh, 1);
592
593 nh->path_index = path_index;
594 nh->path_weight = fib_path_get_weight(path_index);
595 fib_path_contribute_forwarding(path_index, ctx->fct, &nh->path_dpo);
596 break;
597
598 case FIB_FORW_CHAIN_TYPE_UNICAST_IP4:
599 case FIB_FORW_CHAIN_TYPE_UNICAST_IP6:
600 case FIB_FORW_CHAIN_TYPE_MPLS_NON_EOS:
601 case FIB_FORW_CHAIN_TYPE_MPLS_EOS:
602 case FIB_FORW_CHAIN_TYPE_ETHERNET:
Florin Corasce1b4c72017-01-26 14:25:34 -0800603 case FIB_FORW_CHAIN_TYPE_NSH:
Neale Rannsd792d9c2017-10-21 10:53:20 -0700604 case FIB_FORW_CHAIN_TYPE_BIER:
Neale Ranns32e1c012016-11-22 17:07:28 +0000605 ASSERT(0);
606 break;
607 }
608
Neale Ranns81424992017-05-18 03:03:22 -0700609 return (FIB_PATH_LIST_WALK_CONTINUE);
Neale Ranns32e1c012016-11-22 17:07:28 +0000610}
611
612static void
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800613mfib_entry_stack (mfib_entry_t *mfib_entry,
614 mfib_entry_src_t *msrc)
Neale Ranns32e1c012016-11-22 17:07:28 +0000615{
Neale Ranns32e1c012016-11-22 17:07:28 +0000616 dpo_proto_t dp;
617
618 dp = fib_proto_to_dpo(mfib_entry_get_proto(mfib_entry));
619
Neale Rannsc2aad532017-05-30 09:53:52 -0700620 /*
621 * unlink the enty from the previous path list.
622 */
623 if (FIB_NODE_INDEX_INVALID != mfib_entry->mfe_pl)
624 {
625 fib_path_list_child_remove(mfib_entry->mfe_pl,
626 mfib_entry->mfe_sibling);
627 }
628
Neale Ranns9e829a82018-12-17 05:50:32 -0800629 if (NULL != msrc)
Neale Ranns32e1c012016-11-22 17:07:28 +0000630 {
Neale Rannsa9374df2017-02-02 02:18:18 -0800631 mfib_entry_collect_forwarding_ctx_t ctx = {
632 .next_hops = NULL,
633 .fct = mfib_entry_get_default_chain_type(mfib_entry),
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800634 .msrc = msrc,
Neale Rannsa9374df2017-02-02 02:18:18 -0800635 };
636
Neale Ranns9e829a82018-12-17 05:50:32 -0800637 /*
638 * link the entry to the path-list.
639 * The entry needs to be a child so that we receive the back-walk
640 * updates to recalculate forwarding.
641 */
642 mfib_entry->mfe_pl = msrc->mfes_pl;
Neale Ranns9db6ada2019-11-08 12:42:31 +0000643 mfib_entry->mfe_flags = msrc->mfes_route_flags;
Neale Ranns9e829a82018-12-17 05:50:32 -0800644 mfib_entry->mfe_itfs = msrc->mfes_itfs;
645 mfib_entry->mfe_rpf_id = msrc->mfes_rpf_id;
Neale Ranns32e1c012016-11-22 17:07:28 +0000646
Neale Ranns9e829a82018-12-17 05:50:32 -0800647 if (FIB_NODE_INDEX_INVALID != mfib_entry->mfe_pl)
648 {
649 mfib_entry->mfe_sibling =
650 fib_path_list_child_add(mfib_entry->mfe_pl,
651 FIB_NODE_TYPE_MFIB_ENTRY,
652 mfib_entry_get_index(mfib_entry));
653
654 fib_path_list_walk(mfib_entry->mfe_pl,
655 mfib_entry_src_collect_forwarding,
656 &ctx);
657 }
Neale Rannsa9374df2017-02-02 02:18:18 -0800658 if (!(MFIB_ENTRY_FLAG_EXCLUSIVE & mfib_entry->mfe_flags))
Neale Ranns32e1c012016-11-22 17:07:28 +0000659 {
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800660 if (NULL == ctx.next_hops)
Neale Rannsa9374df2017-02-02 02:18:18 -0800661 {
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800662 /*
663 * no next-hops, stack directly on the drop
664 */
Neale Rannsa9374df2017-02-02 02:18:18 -0800665 dpo_stack(DPO_MFIB_ENTRY, dp,
666 &mfib_entry->mfe_rep,
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800667 drop_dpo_get(dp));
Neale Rannsa9374df2017-02-02 02:18:18 -0800668 }
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800669 else
670 {
671 /*
672 * each path contirbutes a next-hop. form a replicate
673 * from those choices.
674 */
675 if (!dpo_id_is_valid(&mfib_entry->mfe_rep) ||
676 dpo_is_drop(&mfib_entry->mfe_rep))
677 {
678 dpo_id_t tmp_dpo = DPO_INVALID;
679
680 dpo_set(&tmp_dpo,
681 DPO_REPLICATE, dp,
682 replicate_create(0, dp));
683
684 dpo_stack(DPO_MFIB_ENTRY, dp,
685 &mfib_entry->mfe_rep,
686 &tmp_dpo);
687
688 dpo_reset(&tmp_dpo);
689 }
690 replicate_multipath_update(&mfib_entry->mfe_rep,
691 ctx.next_hops);
692 }
Neale Rannsa9374df2017-02-02 02:18:18 -0800693 }
694 else
695 {
696 /*
697 * for exclusive routes the source provided a replicate DPO
Neale Rannsb7778b62018-12-21 07:00:56 -0800698 * which we stashed in the special path list with one path,
Neale Rannsa9374df2017-02-02 02:18:18 -0800699 * so we can stack directly on that.
700 */
701 ASSERT(1 == vec_len(ctx.next_hops));
Neale Ranns32e1c012016-11-22 17:07:28 +0000702
Neale Rannsb7778b62018-12-21 07:00:56 -0800703 if (NULL != ctx.next_hops)
704 {
705 dpo_stack(DPO_MFIB_ENTRY, dp,
706 &mfib_entry->mfe_rep,
707 &ctx.next_hops[0].path_dpo);
708 dpo_reset(&ctx.next_hops[0].path_dpo);
709 vec_free(ctx.next_hops);
710 }
711 else
712 {
713 dpo_stack(DPO_MFIB_ENTRY, dp,
714 &mfib_entry->mfe_rep,
715 drop_dpo_get(dp));
716 }
Neale Ranns32e1c012016-11-22 17:07:28 +0000717 }
Neale Ranns32e1c012016-11-22 17:07:28 +0000718 }
719 else
720 {
721 dpo_stack(DPO_MFIB_ENTRY, dp,
722 &mfib_entry->mfe_rep,
723 drop_dpo_get(dp));
724 }
Neale Ranns9e829a82018-12-17 05:50:32 -0800725
726 /*
727 * time for walkies fido.
728 */
729 fib_node_back_walk_ctx_t bw_ctx = {
730 .fnbw_reason = FIB_NODE_BW_REASON_FLAG_EVALUATE,
731 };
732
733 fib_walk_sync(FIB_NODE_TYPE_MFIB_ENTRY,
734 mfib_entry_get_index(mfib_entry),
735 &bw_ctx);
Neale Ranns32e1c012016-11-22 17:07:28 +0000736}
737
Neale Ranns097fa662018-05-01 05:17:55 -0700738static fib_node_index_t*
739mfib_entry_src_paths_add (mfib_entry_src_t *msrc,
740 const fib_route_path_t *rpaths)
Neale Ranns32e1c012016-11-22 17:07:28 +0000741{
Neale Ranns9db6ada2019-11-08 12:42:31 +0000742 ASSERT(!(MFIB_ENTRY_FLAG_EXCLUSIVE & msrc->mfes_route_flags));
743
744 msrc->mfes_flags &= ~MFIB_ENTRY_SRC_FLAG_STALE;
Neale Rannsa9374df2017-02-02 02:18:18 -0800745
Neale Ranns32e1c012016-11-22 17:07:28 +0000746 if (FIB_NODE_INDEX_INVALID == msrc->mfes_pl)
747 {
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800748 /* A non-shared path-list */
749 msrc->mfes_pl = fib_path_list_create(FIB_PATH_LIST_FLAG_NO_URPF,
750 NULL);
751 fib_path_list_lock(msrc->mfes_pl);
Neale Ranns32e1c012016-11-22 17:07:28 +0000752 }
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800753
Neale Ranns097fa662018-05-01 05:17:55 -0700754 return (fib_path_list_paths_add(msrc->mfes_pl, rpaths));
Neale Ranns32e1c012016-11-22 17:07:28 +0000755}
756
Neale Ranns097fa662018-05-01 05:17:55 -0700757static fib_node_index_t*
758mfib_entry_src_paths_remove (mfib_entry_src_t *msrc,
759 const fib_route_path_t *rpaths)
Neale Ranns32e1c012016-11-22 17:07:28 +0000760{
Neale Ranns9db6ada2019-11-08 12:42:31 +0000761 ASSERT(!(MFIB_ENTRY_FLAG_EXCLUSIVE & msrc->mfes_route_flags));
762
763 msrc->mfes_flags &= ~MFIB_ENTRY_SRC_FLAG_STALE;
Neale Rannsa9374df2017-02-02 02:18:18 -0800764
Neale Ranns097fa662018-05-01 05:17:55 -0700765 return (fib_path_list_paths_remove(msrc->mfes_pl, rpaths));
Neale Ranns32e1c012016-11-22 17:07:28 +0000766}
767
768static void
Neale Ranns9e829a82018-12-17 05:50:32 -0800769mfib_entry_recalculate_forwarding (mfib_entry_t *mfib_entry,
770 mfib_source_t old_best)
Neale Ranns32e1c012016-11-22 17:07:28 +0000771{
Neale Ranns9e829a82018-12-17 05:50:32 -0800772 mfib_entry_src_t *bsrc, *osrc;
Neale Ranns32e1c012016-11-22 17:07:28 +0000773
Neale Ranns32e1c012016-11-22 17:07:28 +0000774 /*
775 * copy the forwarding data from the bast source
776 */
777 bsrc = mfib_entry_get_best_src(mfib_entry);
Neale Ranns9e829a82018-12-17 05:50:32 -0800778 osrc = mfib_entry_src_find(mfib_entry, old_best, NULL);
Neale Ranns32e1c012016-11-22 17:07:28 +0000779
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800780 if (NULL != bsrc)
Neale Ranns32e1c012016-11-22 17:07:28 +0000781 {
Neale Ranns9e829a82018-12-17 05:50:32 -0800782 if (bsrc->mfes_src != old_best)
783 {
784 /*
785 * we are changing from one source to another
786 * deactivate the old, and activate the new
787 */
788 mfib_entry_src_deactivate(mfib_entry, osrc);
789 mfib_entry_src_activate(mfib_entry, bsrc);
790 }
791 }
792 else
793 {
794 mfib_entry_src_deactivate(mfib_entry, osrc);
Neale Ranns32e1c012016-11-22 17:07:28 +0000795 }
796
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800797 mfib_entry_stack(mfib_entry, bsrc);
Neale Ranns9e829a82018-12-17 05:50:32 -0800798 mfib_entry_cover_update_notify(mfib_entry);
Neale Ranns32e1c012016-11-22 17:07:28 +0000799}
800
801
802fib_node_index_t
803mfib_entry_create (u32 fib_index,
804 mfib_source_t source,
805 const mfib_prefix_t *prefix,
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800806 fib_rpf_id_t rpf_id,
Neale Ranns9e829a82018-12-17 05:50:32 -0800807 mfib_entry_flags_t entry_flags,
808 index_t repi)
Neale Ranns32e1c012016-11-22 17:07:28 +0000809{
810 fib_node_index_t mfib_entry_index;
811 mfib_entry_t *mfib_entry;
812 mfib_entry_src_t *msrc;
813
814 mfib_entry = mfib_entry_alloc(fib_index, prefix,
815 &mfib_entry_index);
Neale Ranns9e829a82018-12-17 05:50:32 -0800816 msrc = mfib_entry_src_update(mfib_entry, source,
817 rpf_id, entry_flags);
Neale Ranns32e1c012016-11-22 17:07:28 +0000818
Neale Ranns9e829a82018-12-17 05:50:32 -0800819 if (INDEX_INVALID != repi)
820 {
821 /*
822 * The source is providing its own replicate DPO.
823 * Create a sepcial path-list to manage it, that way
824 * this entry and the source are equivalent to a normal
825 * entry
826 */
827 fib_node_index_t old_pl_index;
828 dpo_proto_t dp;
829 dpo_id_t dpo = DPO_INVALID;
830
831 dp = fib_proto_to_dpo(mfib_entry_get_proto(mfib_entry));
832 old_pl_index = msrc->mfes_pl;
833
834 dpo_set(&dpo, DPO_REPLICATE, dp, repi);
835
836 msrc->mfes_pl =
837 fib_path_list_create_special(dp,
838 FIB_PATH_LIST_FLAG_EXCLUSIVE,
839 &dpo);
840
841 dpo_reset(&dpo);
842 fib_path_list_lock(msrc->mfes_pl);
843 fib_path_list_unlock(old_pl_index);
844 }
845
846 mfib_entry_recalculate_forwarding(mfib_entry, MFIB_SOURCE_NONE);
Neale Ranns32e1c012016-11-22 17:07:28 +0000847
848 return (mfib_entry_index);
849}
850
851static int
852mfib_entry_ok_for_delete (mfib_entry_t *mfib_entry)
853{
854 return (0 == vec_len(mfib_entry->mfe_srcs));
855}
856
857static int
858mfib_entry_src_ok_for_delete (const mfib_entry_src_t *msrc)
859{
Neale Ranns9e829a82018-12-17 05:50:32 -0800860 return ((INDEX_INVALID == msrc->mfes_cover &&
Neale Ranns9db6ada2019-11-08 12:42:31 +0000861 MFIB_ENTRY_FLAG_NONE == msrc->mfes_route_flags &&
Neale Ranns097fa662018-05-01 05:17:55 -0700862 0 == fib_path_list_get_n_paths(msrc->mfes_pl)) &&
863 (0 == hash_elts(msrc->mfes_itfs)));
864
Neale Ranns9db6ada2019-11-08 12:42:31 +0000865 /* return ((MFIB_ENTRY_FLAG_NONE == msrc->mfes_route_flags) && */
Neale Ranns097fa662018-05-01 05:17:55 -0700866 /* (0 == fib_path_list_get_n_paths(msrc->mfes_pl)) && */
867 /* (0 == hash_elts(msrc->mfes_itfs))); */
Neale Ranns32e1c012016-11-22 17:07:28 +0000868}
869
Neale Ranns9e829a82018-12-17 05:50:32 -0800870
871static void
872mfib_entry_update_i (mfib_entry_t *mfib_entry,
873 mfib_entry_src_t *msrc,
874 mfib_source_t current_best,
875 index_t repi)
Neale Ranns32e1c012016-11-22 17:07:28 +0000876{
Neale Rannsa9374df2017-02-02 02:18:18 -0800877 if (INDEX_INVALID != repi)
878 {
879 /*
880 * The source is providing its own replicate DPO.
881 * Create a sepcial path-list to manage it, that way
882 * this entry and the source are equivalent to a normal
883 * entry
884 */
885 fib_node_index_t old_pl_index;
Neale Rannsda78f952017-05-24 09:15:43 -0700886 dpo_proto_t dp;
Neale Rannsa9374df2017-02-02 02:18:18 -0800887 dpo_id_t dpo = DPO_INVALID;
888
Neale Rannsda78f952017-05-24 09:15:43 -0700889 dp = fib_proto_to_dpo(mfib_entry_get_proto(mfib_entry));
Neale Rannsa9374df2017-02-02 02:18:18 -0800890 old_pl_index = msrc->mfes_pl;
891
Neale Rannsda78f952017-05-24 09:15:43 -0700892 dpo_set(&dpo, DPO_REPLICATE, dp, repi);
Neale Rannsa9374df2017-02-02 02:18:18 -0800893
894 msrc->mfes_pl =
Neale Rannsda78f952017-05-24 09:15:43 -0700895 fib_path_list_create_special(dp,
Neale Rannsa9374df2017-02-02 02:18:18 -0800896 FIB_PATH_LIST_FLAG_EXCLUSIVE,
897 &dpo);
898
899 dpo_reset(&dpo);
900 fib_path_list_lock(msrc->mfes_pl);
901 fib_path_list_unlock(old_pl_index);
902 }
903
Neale Ranns32e1c012016-11-22 17:07:28 +0000904 if (mfib_entry_src_ok_for_delete(msrc))
905 {
906 /*
907 * this source has no interfaces and no flags.
908 * it has nothing left to give - remove it
909 */
Neale Ranns9e829a82018-12-17 05:50:32 -0800910 mfib_entry_src_remove(mfib_entry, msrc->mfes_src);
Neale Ranns32e1c012016-11-22 17:07:28 +0000911 }
912
Neale Ranns9e829a82018-12-17 05:50:32 -0800913 mfib_entry_recalculate_forwarding(mfib_entry, current_best);
914}
915
916int
917mfib_entry_special_add (fib_node_index_t mfib_entry_index,
918 mfib_source_t source,
919 mfib_entry_flags_t entry_flags,
920 fib_rpf_id_t rpf_id,
921 index_t repi)
922{
923 mfib_source_t current_best;
924 mfib_entry_t *mfib_entry;
925 mfib_entry_src_t *msrc;
926
927 mfib_entry = mfib_entry_get(mfib_entry_index);
928 current_best = mfib_entry_get_best_source(mfib_entry);
929
930 msrc = mfib_entry_src_update_and_lock(mfib_entry, source, rpf_id,
931 entry_flags);
932
933 mfib_entry_update_i(mfib_entry, msrc, current_best, repi);
934
935 return (mfib_entry_ok_for_delete(mfib_entry));
936}
937
938int
939mfib_entry_update (fib_node_index_t mfib_entry_index,
940 mfib_source_t source,
941 mfib_entry_flags_t entry_flags,
942 fib_rpf_id_t rpf_id,
943 index_t repi)
944{
945 mfib_source_t current_best;
946 mfib_entry_t *mfib_entry;
947 mfib_entry_src_t *msrc;
948
949 mfib_entry = mfib_entry_get(mfib_entry_index);
950 current_best = mfib_entry_get_best_source(mfib_entry);
951 msrc = mfib_entry_src_update(mfib_entry, source, rpf_id, entry_flags);
952
953 mfib_entry_update_i(mfib_entry, msrc, current_best, repi);
Neale Ranns32e1c012016-11-22 17:07:28 +0000954
955 return (mfib_entry_ok_for_delete(mfib_entry));
956}
957
958static void
959mfib_entry_itf_add (mfib_entry_src_t *msrc,
960 u32 sw_if_index,
961 index_t mi)
962{
963 hash_set(msrc->mfes_itfs, sw_if_index, mi);
964}
965
966static void
967mfib_entry_itf_remove (mfib_entry_src_t *msrc,
968 u32 sw_if_index)
969{
970 mfib_itf_t *mfi;
971
972 mfi = mfib_entry_itf_find(msrc->mfes_itfs, sw_if_index);
973
974 mfib_itf_delete(mfi);
975
976 hash_unset(msrc->mfes_itfs, sw_if_index);
977}
978
Neale Ranns097fa662018-05-01 05:17:55 -0700979static int
980mfib_entry_path_itf_based (const fib_route_path_t *rpath)
981{
982 return (!(rpath->frp_flags & FIB_ROUTE_PATH_BIER_IMP) &&
983 ~0 != rpath->frp_sw_if_index);
984}
985
Neale Ranns32e1c012016-11-22 17:07:28 +0000986void
987mfib_entry_path_update (fib_node_index_t mfib_entry_index,
988 mfib_source_t source,
Neale Ranns097fa662018-05-01 05:17:55 -0700989 const fib_route_path_t *rpaths)
Neale Ranns32e1c012016-11-22 17:07:28 +0000990{
Neale Ranns097fa662018-05-01 05:17:55 -0700991 fib_node_index_t* path_indices, path_index;
992 const fib_route_path_t *rpath;
Neale Ranns9e829a82018-12-17 05:50:32 -0800993 mfib_source_t current_best;
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800994 mfib_path_ext_t *path_ext;
Neale Ranns32e1c012016-11-22 17:07:28 +0000995 mfib_entry_t *mfib_entry;
996 mfib_entry_src_t *msrc;
Neale Rannse821ab12017-06-01 07:45:05 -0700997 mfib_itf_flags_t old;
Neale Ranns097fa662018-05-01 05:17:55 -0700998 u32 ii;
Neale Ranns32e1c012016-11-22 17:07:28 +0000999
1000 mfib_entry = mfib_entry_get(mfib_entry_index);
1001 ASSERT(NULL != mfib_entry);
Neale Ranns9e829a82018-12-17 05:50:32 -08001002 current_best = mfib_entry_get_best_source(mfib_entry);
Neale Ranns32e1c012016-11-22 17:07:28 +00001003 msrc = mfib_entry_src_find_or_create(mfib_entry, source);
1004
1005 /*
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001006 * add the path to the path-list. If it's a duplicate we'll get
1007 * back the original path.
Neale Ranns32e1c012016-11-22 17:07:28 +00001008 */
Neale Ranns097fa662018-05-01 05:17:55 -07001009 path_indices = mfib_entry_src_paths_add(msrc, rpaths);
Neale Ranns32e1c012016-11-22 17:07:28 +00001010
Neale Ranns097fa662018-05-01 05:17:55 -07001011 vec_foreach_index(ii, path_indices)
Neale Ranns32e1c012016-11-22 17:07:28 +00001012 {
Neale Ranns097fa662018-05-01 05:17:55 -07001013 path_index = path_indices[ii];
1014 rpath = &rpaths[ii];
Neale Ranns32e1c012016-11-22 17:07:28 +00001015
Neale Ranns097fa662018-05-01 05:17:55 -07001016 if (FIB_NODE_INDEX_INVALID == path_index)
1017 continue;
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001018
Neale Ranns097fa662018-05-01 05:17:55 -07001019 /*
1020 * find the path extension for that path
1021 */
1022 path_ext = mfib_entry_path_ext_find(msrc->mfes_exts, path_index);
1023
1024 if (NULL == path_ext)
Neale Ranns32e1c012016-11-22 17:07:28 +00001025 {
Neale Ranns097fa662018-05-01 05:17:55 -07001026 old = MFIB_ITF_FLAG_NONE;
1027 path_ext = mfib_path_ext_add(msrc, path_index,
1028 rpath->frp_mitf_flags);
1029 }
1030 else
1031 {
1032 old = path_ext->mfpe_flags;
1033 path_ext->mfpe_flags = rpath->frp_mitf_flags;
1034 }
Neale Rannse821ab12017-06-01 07:45:05 -07001035
Neale Ranns097fa662018-05-01 05:17:55 -07001036 /*
1037 * Has the path changed its contribution to the input interface set.
1038 * Which only paths with interfaces can do...
1039 */
1040 if (mfib_entry_path_itf_based(rpath))
1041 {
1042 mfib_itf_t *mfib_itf;
1043
1044 if (old != rpath->frp_mitf_flags)
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001045 {
Neale Ranns097fa662018-05-01 05:17:55 -07001046 /*
1047 * change of flag contributions
1048 */
1049 mfib_itf = mfib_entry_itf_find(msrc->mfes_itfs,
1050 rpath->frp_sw_if_index);
1051
1052 if (NULL == mfib_itf)
Neale Rannse821ab12017-06-01 07:45:05 -07001053 {
Neale Ranns097fa662018-05-01 05:17:55 -07001054 mfib_entry_itf_add(msrc,
1055 rpath->frp_sw_if_index,
1056 mfib_itf_create(path_index,
1057 rpath->frp_mitf_flags));
1058 }
1059 else
1060 {
1061 if (mfib_itf_update(mfib_itf,
1062 path_index,
1063 rpath->frp_mitf_flags))
1064 {
1065 /*
1066 * no more interface flags on this path, remove
1067 * from the data-plane set
1068 */
1069 mfib_entry_itf_remove(msrc, rpath->frp_sw_if_index);
1070 }
Neale Rannse821ab12017-06-01 07:45:05 -07001071 }
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001072 }
Neale Ranns32e1c012016-11-22 17:07:28 +00001073 }
Neale Ranns32e1c012016-11-22 17:07:28 +00001074 }
Neale Ranns097fa662018-05-01 05:17:55 -07001075 vec_free(path_indices);
Neale Ranns32e1c012016-11-22 17:07:28 +00001076
Neale Ranns9e829a82018-12-17 05:50:32 -08001077 mfib_entry_recalculate_forwarding(mfib_entry, current_best);
Neale Ranns32e1c012016-11-22 17:07:28 +00001078}
1079
1080/*
1081 * mfib_entry_path_remove
1082 *
1083 * remove a path from the entry.
1084 * return the mfib_entry's index if it is still present, INVALID otherwise.
1085 */
1086int
1087mfib_entry_path_remove (fib_node_index_t mfib_entry_index,
1088 mfib_source_t source,
Neale Ranns097fa662018-05-01 05:17:55 -07001089 const fib_route_path_t *rpaths)
Neale Ranns32e1c012016-11-22 17:07:28 +00001090{
Neale Ranns097fa662018-05-01 05:17:55 -07001091 fib_node_index_t path_index, *path_indices;
1092 const fib_route_path_t *rpath;
Neale Ranns9e829a82018-12-17 05:50:32 -08001093 mfib_source_t current_best;
Neale Ranns32e1c012016-11-22 17:07:28 +00001094 mfib_entry_t *mfib_entry;
1095 mfib_entry_src_t *msrc;
Neale Ranns097fa662018-05-01 05:17:55 -07001096 u32 ii;
Neale Ranns32e1c012016-11-22 17:07:28 +00001097
1098 mfib_entry = mfib_entry_get(mfib_entry_index);
1099 ASSERT(NULL != mfib_entry);
Neale Ranns9e829a82018-12-17 05:50:32 -08001100 current_best = mfib_entry_get_best_source(mfib_entry);
Neale Ranns32e1c012016-11-22 17:07:28 +00001101 msrc = mfib_entry_src_find(mfib_entry, source, NULL);
1102
1103 if (NULL == msrc)
1104 {
1105 /*
1106 * there are no paths left for this source
1107 */
1108 return (mfib_entry_ok_for_delete(mfib_entry));
1109 }
1110
1111 /*
Neale Ranns097fa662018-05-01 05:17:55 -07001112 * remove the paths from the path-list. If it's not there we'll get
1113 * back an empty vector
Neale Ranns32e1c012016-11-22 17:07:28 +00001114 */
Neale Ranns097fa662018-05-01 05:17:55 -07001115 path_indices = mfib_entry_src_paths_remove(msrc, rpaths);
Neale Ranns32e1c012016-11-22 17:07:28 +00001116
Neale Ranns097fa662018-05-01 05:17:55 -07001117 vec_foreach_index(ii, path_indices)
Neale Ranns32e1c012016-11-22 17:07:28 +00001118 {
Neale Ranns097fa662018-05-01 05:17:55 -07001119 path_index = path_indices[ii];
1120 rpath = &rpaths[ii];
1121
1122 if (FIB_NODE_INDEX_INVALID == path_index)
1123 continue;
1124
Neale Ranns32e1c012016-11-22 17:07:28 +00001125 /*
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001126 * don't need the extension, nor the interface anymore
Neale Ranns32e1c012016-11-22 17:07:28 +00001127 */
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001128 mfib_path_ext_remove(msrc, path_index);
Neale Ranns097fa662018-05-01 05:17:55 -07001129 if (mfib_entry_path_itf_based(rpath))
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001130 {
Neale Rannse821ab12017-06-01 07:45:05 -07001131 mfib_itf_t *mfib_itf;
1132
1133 mfib_itf = mfib_entry_itf_find(msrc->mfes_itfs,
Neale Ranns097fa662018-05-01 05:17:55 -07001134 rpath->frp_sw_if_index);
Neale Rannse821ab12017-06-01 07:45:05 -07001135
1136 if (mfib_itf_update(mfib_itf,
1137 path_index,
1138 MFIB_ITF_FLAG_NONE))
1139 {
1140 /*
1141 * no more interface flags on this path, remove
1142 * from the data-plane set
1143 */
Neale Ranns097fa662018-05-01 05:17:55 -07001144 mfib_entry_itf_remove(msrc, rpath->frp_sw_if_index);
Neale Rannse821ab12017-06-01 07:45:05 -07001145 }
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001146 }
Neale Ranns32e1c012016-11-22 17:07:28 +00001147 }
Neale Ranns097fa662018-05-01 05:17:55 -07001148 vec_free(path_indices);
Neale Ranns32e1c012016-11-22 17:07:28 +00001149
BenoƮt Ganne95eb01f2020-04-16 12:38:48 +02001150 if (mfib_entry_src_ok_for_delete(msrc))
1151 {
1152 /*
1153 * this source has no interfaces and no flags.
1154 * it has nothing left to give - remove it
1155 */
1156 mfib_entry_src_remove(mfib_entry, source);
1157 }
1158
Neale Ranns9e829a82018-12-17 05:50:32 -08001159 mfib_entry_recalculate_forwarding(mfib_entry, current_best);
Neale Ranns32e1c012016-11-22 17:07:28 +00001160
1161 return (mfib_entry_ok_for_delete(mfib_entry));
1162}
1163
1164/**
1165 * mfib_entry_delete
1166 *
1167 * The source is withdrawing all the paths it provided
1168 */
1169int
1170mfib_entry_delete (fib_node_index_t mfib_entry_index,
1171 mfib_source_t source)
1172{
Neale Ranns9e829a82018-12-17 05:50:32 -08001173 mfib_source_t current_best;
Neale Ranns32e1c012016-11-22 17:07:28 +00001174 mfib_entry_t *mfib_entry;
1175
1176 mfib_entry = mfib_entry_get(mfib_entry_index);
Neale Ranns9e829a82018-12-17 05:50:32 -08001177 current_best = mfib_entry_get_best_source(mfib_entry);
Neale Ranns32e1c012016-11-22 17:07:28 +00001178 mfib_entry_src_remove(mfib_entry, source);
1179
Neale Ranns9e829a82018-12-17 05:50:32 -08001180 mfib_entry_recalculate_forwarding(mfib_entry, current_best);
Neale Ranns32e1c012016-11-22 17:07:28 +00001181
1182 return (mfib_entry_ok_for_delete(mfib_entry));
1183}
1184
1185static int
1186fib_ip4_address_compare (ip4_address_t * a1,
1187 ip4_address_t * a2)
1188{
1189 /*
1190 * IP addresses are unsiged ints. the return value here needs to be signed
1191 * a simple subtraction won't cut it.
1192 * If the addresses are the same, the sort order is undefiend, so phoey.
1193 */
1194 return ((clib_net_to_host_u32(a1->data_u32) >
1195 clib_net_to_host_u32(a2->data_u32) ) ?
1196 1 : -1);
1197}
1198
1199static int
1200fib_ip6_address_compare (ip6_address_t * a1,
1201 ip6_address_t * a2)
1202{
1203 int i;
1204 for (i = 0; i < ARRAY_LEN (a1->as_u16); i++)
1205 {
1206 int cmp = (clib_net_to_host_u16 (a1->as_u16[i]) -
1207 clib_net_to_host_u16 (a2->as_u16[i]));
1208 if (cmp != 0)
1209 return cmp;
1210 }
1211 return 0;
1212}
1213
1214static int
1215mfib_entry_cmp (fib_node_index_t mfib_entry_index1,
1216 fib_node_index_t mfib_entry_index2)
1217{
1218 mfib_entry_t *mfib_entry1, *mfib_entry2;
1219 int cmp = 0;
1220
1221 mfib_entry1 = mfib_entry_get(mfib_entry_index1);
1222 mfib_entry2 = mfib_entry_get(mfib_entry_index2);
1223
1224 switch (mfib_entry1->mfe_prefix.fp_proto)
1225 {
1226 case FIB_PROTOCOL_IP4:
1227 cmp = fib_ip4_address_compare(&mfib_entry1->mfe_prefix.fp_grp_addr.ip4,
1228 &mfib_entry2->mfe_prefix.fp_grp_addr.ip4);
1229
1230 if (0 == cmp)
1231 {
1232 cmp = fib_ip4_address_compare(&mfib_entry1->mfe_prefix.fp_src_addr.ip4,
1233 &mfib_entry2->mfe_prefix.fp_src_addr.ip4);
1234 }
1235 break;
1236 case FIB_PROTOCOL_IP6:
1237 cmp = fib_ip6_address_compare(&mfib_entry1->mfe_prefix.fp_grp_addr.ip6,
1238 &mfib_entry2->mfe_prefix.fp_grp_addr.ip6);
1239
1240 if (0 == cmp)
1241 {
1242 cmp = fib_ip6_address_compare(&mfib_entry1->mfe_prefix.fp_src_addr.ip6,
1243 &mfib_entry2->mfe_prefix.fp_src_addr.ip6);
1244 }
1245 break;
1246 case FIB_PROTOCOL_MPLS:
1247 ASSERT(0);
1248 cmp = 0;
1249 break;
1250 }
1251
1252 if (0 == cmp) {
1253 cmp = (mfib_entry1->mfe_prefix.fp_len - mfib_entry2->mfe_prefix.fp_len);
1254 }
1255 return (cmp);
1256}
1257
1258int
1259mfib_entry_cmp_for_sort (void *i1, void *i2)
1260{
1261 fib_node_index_t *mfib_entry_index1 = i1, *mfib_entry_index2 = i2;
1262
1263 return (mfib_entry_cmp(*mfib_entry_index1,
1264 *mfib_entry_index2));
1265}
1266
Neale Rannsc2aad532017-05-30 09:53:52 -07001267static void
1268mfib_entry_last_lock_gone (fib_node_t *node)
1269{
1270 mfib_entry_t *mfib_entry;
1271 mfib_entry_src_t *msrc;
1272
1273 mfib_entry = mfib_entry_from_fib_node(node);
1274
1275 dpo_reset(&mfib_entry->mfe_rep);
1276
1277 MFIB_ENTRY_DBG(mfib_entry, "last-lock");
1278
1279 vec_foreach(msrc, mfib_entry->mfe_srcs)
1280 {
1281 mfib_entry_src_flush(msrc);
1282 }
1283
1284 vec_free(mfib_entry->mfe_srcs);
1285
1286 fib_node_deinit(&mfib_entry->mfe_node);
1287 pool_put(mfib_entry_pool, mfib_entry);
1288}
1289
Neale Ranns28c142e2018-09-07 09:37:07 -07001290u32
1291mfib_entry_get_stats_index (fib_node_index_t fib_entry_index)
1292{
1293 mfib_entry_t *mfib_entry;
1294
1295 mfib_entry = mfib_entry_get(fib_entry_index);
1296
1297 return (mfib_entry->mfe_rep.dpoi_index);
1298}
1299
Neale Rannsc2aad532017-05-30 09:53:52 -07001300/*
1301 * mfib_entry_back_walk_notify
1302 *
1303 * A back walk has reach this entry.
1304 */
1305static fib_node_back_walk_rc_t
1306mfib_entry_back_walk_notify (fib_node_t *node,
1307 fib_node_back_walk_ctx_t *ctx)
1308{
Neale Ranns9e829a82018-12-17 05:50:32 -08001309 mfib_entry_t *mfib_entry;
1310
1311 mfib_entry = mfib_entry_from_fib_node(node);
1312 mfib_entry_recalculate_forwarding(mfib_entry,
1313 mfib_entry_get_best_source(mfib_entry));
Neale Rannsc2aad532017-05-30 09:53:52 -07001314
1315 return (FIB_NODE_BACK_WALK_CONTINUE);
1316}
1317
1318static void
1319mfib_entry_show_memory (void)
1320{
1321 fib_show_memory_usage("multicast-Entry",
1322 pool_elts(mfib_entry_pool),
1323 pool_len(mfib_entry_pool),
1324 sizeof(mfib_entry_t));
1325}
1326
1327/*
1328 * The MFIB entry's graph node virtual function table
1329 */
1330static const fib_node_vft_t mfib_entry_vft = {
1331 .fnv_get = mfib_entry_get_node,
1332 .fnv_last_lock = mfib_entry_last_lock_gone,
1333 .fnv_back_walk = mfib_entry_back_walk_notify,
1334 .fnv_mem_show = mfib_entry_show_memory,
1335};
1336
Neale Ranns32e1c012016-11-22 17:07:28 +00001337void
1338mfib_entry_lock (fib_node_index_t mfib_entry_index)
1339{
1340 mfib_entry_t *mfib_entry;
1341
1342 mfib_entry = mfib_entry_get(mfib_entry_index);
1343
1344 fib_node_lock(&mfib_entry->mfe_node);
1345}
1346
1347void
1348mfib_entry_unlock (fib_node_index_t mfib_entry_index)
1349{
1350 mfib_entry_t *mfib_entry;
1351
1352 mfib_entry = mfib_entry_get(mfib_entry_index);
1353
1354 fib_node_unlock(&mfib_entry->mfe_node);
1355}
1356
1357static void
1358mfib_entry_dpo_lock (dpo_id_t *dpo)
1359{
1360}
1361static void
1362mfib_entry_dpo_unlock (dpo_id_t *dpo)
1363{
1364}
1365
1366const static dpo_vft_t mfib_entry_dpo_vft = {
1367 .dv_lock = mfib_entry_dpo_lock,
1368 .dv_unlock = mfib_entry_dpo_unlock,
1369 .dv_format = format_mfib_entry_dpo,
1370 .dv_mem_show = mfib_entry_show_memory,
1371};
1372
1373const static char* const mfib_entry_ip4_nodes[] =
1374{
1375 "ip4-mfib-forward-rpf",
1376 NULL,
1377};
1378const static char* const mfib_entry_ip6_nodes[] =
1379{
1380 "ip6-mfib-forward-rpf",
1381 NULL,
1382};
1383
1384const static char* const * const mfib_entry_nodes[DPO_PROTO_NUM] =
1385{
1386 [DPO_PROTO_IP4] = mfib_entry_ip4_nodes,
1387 [DPO_PROTO_IP6] = mfib_entry_ip6_nodes,
1388};
1389
1390void
1391mfib_entry_module_init (void)
1392{
1393 fib_node_register_type (FIB_NODE_TYPE_MFIB_ENTRY, &mfib_entry_vft);
1394 dpo_register(DPO_MFIB_ENTRY, &mfib_entry_dpo_vft, mfib_entry_nodes);
Neale Ranns710071b2018-09-24 12:36:26 +00001395 mfib_entry_logger = vlib_log_register_class("mfib", "entry");
Neale Ranns32e1c012016-11-22 17:07:28 +00001396}
1397
Neale Ranns097fa662018-05-01 05:17:55 -07001398fib_route_path_t*
1399mfib_entry_encode (fib_node_index_t mfib_entry_index)
Neale Ranns32e1c012016-11-22 17:07:28 +00001400{
Neale Ranns097fa662018-05-01 05:17:55 -07001401 fib_path_encode_ctx_t ctx = {
1402 .rpaths = NULL,
1403 };
Neale Ranns32e1c012016-11-22 17:07:28 +00001404 mfib_entry_t *mfib_entry;
Neale Ranns097fa662018-05-01 05:17:55 -07001405 fib_route_path_t *rpath;
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001406 mfib_entry_src_t *bsrc;
Neale Ranns32e1c012016-11-22 17:07:28 +00001407
1408 mfib_entry = mfib_entry_get(mfib_entry_index);
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001409 bsrc = mfib_entry_get_best_src(mfib_entry);
1410
1411 if (FIB_NODE_INDEX_INVALID != bsrc->mfes_pl)
Neale Ranns5a8123b2017-01-26 01:18:23 -08001412 {
Neale Ranns775f73c2018-12-20 03:01:49 -08001413 fib_path_list_walk_w_ext(bsrc->mfes_pl,
1414 NULL,
1415 fib_path_encode,
Neale Ranns097fa662018-05-01 05:17:55 -07001416 &ctx);
Neale Ranns5a8123b2017-01-26 01:18:23 -08001417 }
Neale Ranns7c03ed42018-12-27 03:21:28 -08001418
Neale Ranns097fa662018-05-01 05:17:55 -07001419 vec_foreach(rpath, ctx.rpaths)
Neale Ranns7c03ed42018-12-27 03:21:28 -08001420 {
1421 mfib_itf_t *mfib_itf;
1422
1423 mfib_itf = mfib_entry_itf_find(bsrc->mfes_itfs,
Neale Ranns097fa662018-05-01 05:17:55 -07001424 rpath->frp_sw_if_index);
Neale Ranns7c03ed42018-12-27 03:21:28 -08001425 if (mfib_itf)
1426 {
Neale Ranns097fa662018-05-01 05:17:55 -07001427 rpath->frp_mitf_flags = mfib_itf->mfi_flags;
Neale Ranns7c03ed42018-12-27 03:21:28 -08001428 }
1429 }
Neale Ranns097fa662018-05-01 05:17:55 -07001430
1431 return (ctx.rpaths);
Neale Ranns32e1c012016-11-22 17:07:28 +00001432}
1433
Neale Ranns9e829a82018-12-17 05:50:32 -08001434const mfib_prefix_t *
1435mfib_entry_get_prefix (fib_node_index_t mfib_entry_index)
Neale Ranns32e1c012016-11-22 17:07:28 +00001436{
1437 mfib_entry_t *mfib_entry;
1438
1439 mfib_entry = mfib_entry_get(mfib_entry_index);
Neale Ranns9e829a82018-12-17 05:50:32 -08001440
1441 return (&mfib_entry->mfe_prefix);
Neale Ranns32e1c012016-11-22 17:07:28 +00001442}
1443
1444u32
1445mfib_entry_get_fib_index (fib_node_index_t mfib_entry_index)
1446{
1447 mfib_entry_t *mfib_entry;
1448
1449 mfib_entry = mfib_entry_get(mfib_entry_index);
1450
1451 return (mfib_entry->mfe_fib_index);
1452}
1453
Neale Rannsff233892017-12-12 00:21:19 -08001454const dpo_id_t*
1455mfib_entry_contribute_ip_forwarding (fib_node_index_t mfib_entry_index)
1456{
1457 mfib_entry_t *mfib_entry;
1458
1459 mfib_entry = mfib_entry_get(mfib_entry_index);
1460
1461 return (&mfib_entry->mfe_rep);
1462}
1463
Neale Ranns32e1c012016-11-22 17:07:28 +00001464void
1465mfib_entry_contribute_forwarding (fib_node_index_t mfib_entry_index,
1466 fib_forward_chain_type_t type,
Neale Ranns9e829a82018-12-17 05:50:32 -08001467 mfib_entry_fwd_flags_t flags,
Neale Ranns32e1c012016-11-22 17:07:28 +00001468 dpo_id_t *dpo)
1469{
1470 /*
1471 * An IP mFIB entry can only provide a forwarding chain that
1472 * is the same IP proto as the prefix.
1473 * No use-cases (i know of) for other combinations.
1474 */
1475 mfib_entry_t *mfib_entry;
1476 dpo_proto_t dp;
1477
1478 mfib_entry = mfib_entry_get(mfib_entry_index);
1479
1480 dp = fib_proto_to_dpo(mfib_entry->mfe_prefix.fp_proto);
1481
Neale Ranns9e829a82018-12-17 05:50:32 -08001482 if (type == mfib_forw_chain_type_from_dpo_proto(dp))
Neale Ranns32e1c012016-11-22 17:07:28 +00001483 {
Neale Ranns9e829a82018-12-17 05:50:32 -08001484 replicate_t * rep;
1485
1486 rep = replicate_get(mfib_entry->mfe_rep.dpoi_index);
1487
1488 if ((rep->rep_flags & REPLICATE_FLAGS_HAS_LOCAL) &&
1489 (flags & MFIB_ENTRY_FWD_FLAG_NO_LOCAL))
1490 {
1491 /*
1492 * caller does not want the local paths that the entry has
1493 */
BenoƮt Ganne95eb01f2020-04-16 12:38:48 +02001494 dpo_proto_t rep_proto = rep->rep_proto;
1495 dpo_set(dpo, DPO_REPLICATE, rep_proto,
Neale Ranns9e829a82018-12-17 05:50:32 -08001496 replicate_dup(REPLICATE_FLAGS_NONE,
1497 mfib_entry->mfe_rep.dpoi_index));
1498 }
1499 else
1500 {
1501 dpo_copy(dpo, &mfib_entry->mfe_rep);
1502 }
Neale Ranns32e1c012016-11-22 17:07:28 +00001503 }
1504 else
1505 {
1506 dpo_copy(dpo, drop_dpo_get(dp));
1507 }
1508}
1509
Neale Ranns9e829a82018-12-17 05:50:32 -08001510/*
1511 * fib_entry_cover_changed
1512 *
1513 * this entry is tracking its cover and that cover has changed.
1514 */
1515void
1516mfib_entry_cover_changed (fib_node_index_t mfib_entry_index)
1517{
1518 mfib_entry_t *mfib_entry;
1519 mfib_entry_src_t *msrc;
1520 mfib_src_res_t res;
1521
1522 mfib_entry = mfib_entry_get(mfib_entry_index);
1523 msrc = mfib_entry_get_best_src(mfib_entry);
1524
1525 res = mfib_entry_src_cover_change(mfib_entry, msrc);
1526
1527 if (MFIB_SRC_REEVALUATE == res)
1528 {
1529 mfib_entry_recalculate_forwarding(mfib_entry, msrc->mfes_src);
1530 }
1531 MFIB_ENTRY_DBG(mfib_entry, "cover-changed");
1532}
1533
1534/*
1535 * mfib_entry_cover_updated
1536 *
1537 * this entry is tracking its cover and that cover has been updated
1538 * (i.e. its forwarding information has changed).
1539 */
1540void
1541mfib_entry_cover_updated (fib_node_index_t mfib_entry_index)
1542{
1543 mfib_entry_t *mfib_entry;
1544 mfib_entry_src_t *msrc;
1545 mfib_src_res_t res;
1546
1547 mfib_entry = mfib_entry_get(mfib_entry_index);
1548 msrc = mfib_entry_get_best_src(mfib_entry);
1549
1550 res = mfib_entry_src_cover_update(mfib_entry, msrc);
1551
1552 if (MFIB_SRC_REEVALUATE == res)
1553 {
1554 mfib_entry_recalculate_forwarding(mfib_entry, msrc->mfes_src);
1555 }
1556 MFIB_ENTRY_DBG(mfib_entry, "cover-updated");
1557}
1558
Neale Ranns32e1c012016-11-22 17:07:28 +00001559u32
1560mfib_entry_pool_size (void)
1561{
1562 return (pool_elts(mfib_entry_pool));
1563}
1564
1565static clib_error_t *
1566show_mfib_entry_command (vlib_main_t * vm,
1567 unformat_input_t * input,
1568 vlib_cli_command_t * cmd)
1569{
1570 fib_node_index_t fei;
1571
1572 if (unformat (input, "%d", &fei))
1573 {
1574 /*
1575 * show one in detail
1576 */
1577 if (!pool_is_free_index(mfib_entry_pool, fei))
1578 {
1579 vlib_cli_output (vm, "%d@%U",
1580 fei,
1581 format_mfib_entry, fei,
1582 MFIB_ENTRY_FORMAT_DETAIL2);
1583 }
1584 else
1585 {
1586 vlib_cli_output (vm, "entry %d invalid", fei);
1587 }
1588 }
1589 else
1590 {
1591 /*
1592 * show all
1593 */
1594 vlib_cli_output (vm, "FIB Entries:");
1595 pool_foreach_index(fei, mfib_entry_pool,
1596 ({
1597 vlib_cli_output (vm, "%d@%U",
1598 fei,
1599 format_mfib_entry, fei,
1600 MFIB_ENTRY_FORMAT_BRIEF);
1601 }));
1602 }
1603
1604 return (NULL);
1605}
1606
Neale Rannsc756c1c2017-02-08 09:11:57 -08001607/*?
1608 * This commnad displays an entry, or all entries, in the mfib tables indexed by their unique
1609 * numerical indentifier.
1610 ?*/
Neale Ranns32e1c012016-11-22 17:07:28 +00001611VLIB_CLI_COMMAND (show_mfib_entry, static) = {
1612 .path = "show mfib entry",
1613 .function = show_mfib_entry_command,
1614 .short_help = "show mfib entry",
1615};