blob: 847f25e7f1f262a298dcb28d209909ec65b5fa87 [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>
19#include <vnet/fib/fib_path_list.h>
20
21#include <vnet/dpo/drop_dpo.h>
22#include <vnet/dpo/replicate_dpo.h>
23
24/**
25 * Debug macro
26 */
27#ifdef MFIB_DEBUG
28#DEFIne MFIB_ENTRY_DBG(_e, _fmt, _args...) \
29{ \
30 u8*__tmp = NULL; \
31 __tmp = format(__tmp, "e:[%d:%U", \
32 mfib_entry_get_index(_e), \
33 format_ip46_address, \
34 &_e->mfe_prefix.fp_grp_addr, \
35 IP46_TYPE_ANY); \
36 __tmp = format(__tmp, "/%d,", \
37 _e->mfe_prefix.fp_len); \
38 __tmp = format(__tmp, "%U]", \
39 mfib_entry_get_index(_e), \
40 format_ip46_address, \
41 &_e->mfe_prefix.fp_src_addr, \
42 IP46_TYPE_ANY); \
43 __tmp = format(__tmp, _fmt, ##_args); \
44 clib_warning("%s", __tmp); \
45 vec_free(__tmp); \
46}
47#else
48#define MFIB_ENTRY_DBG(_e, _fmt, _args...)
49#endif
50
51/**
Neale Ranns0f26c5a2017-03-01 15:12:11 -080052 * MFIB extensions to each path
53 */
54typedef struct mfib_path_ext_t_
55{
56 mfib_itf_flags_t mfpe_flags;
57 fib_node_index_t mfpe_path;
58} mfib_path_ext_t;
59
60/**
Neale Ranns32e1c012016-11-22 17:07:28 +000061 * The source of an MFIB entry
62 */
63typedef struct mfib_entry_src_t_
64{
65 /**
66 * Which source this is
67 */
68 mfib_source_t mfes_src;
69
70 /**
Neale Ranns32e1c012016-11-22 17:07:28 +000071 * Route flags
72 */
73 mfib_entry_flags_t mfes_flags;
74
75 /**
Neale Ranns0f26c5a2017-03-01 15:12:11 -080076 * The path-list of forwarding interfaces
77 */
78 fib_node_index_t mfes_pl;
79
80 /**
81 * RPF-ID
82 */
83 fib_rpf_id_t mfes_rpf_id;
84
85 /**
86 * Hash table of path extensions
87 */
88 mfib_path_ext_t *mfes_exts;
89
90 /**
91 * The hash table of all interfaces.
92 * This is forwarding time information derived from the paths
93 * and their extensions.
Neale Ranns32e1c012016-11-22 17:07:28 +000094 */
95 mfib_itf_t *mfes_itfs;
96} mfib_entry_src_t;
97
98/**
Neale Ranns0f26c5a2017-03-01 15:12:11 -080099 * Pool of path extensions
100 */
101static mfib_path_ext_t *mfib_path_ext_pool;
102
103/**
Neale Ranns32e1c012016-11-22 17:07:28 +0000104 * String names for each source
105 */
106static const char *mfib_source_names[] = MFIB_SOURCE_NAMES;
107
108/*
109 * Pool for all fib_entries
110 */
111mfib_entry_t *mfib_entry_pool;
112
113static fib_node_t *
114mfib_entry_get_node (fib_node_index_t index)
115{
116 return ((fib_node_t*)mfib_entry_get(index));
117}
118
119static fib_protocol_t
120mfib_entry_get_proto (const mfib_entry_t * mfib_entry)
121{
122 return (mfib_entry->mfe_prefix.fp_proto);
123}
124
125fib_forward_chain_type_t
126mfib_entry_get_default_chain_type (const mfib_entry_t *mfib_entry)
127{
128 switch (mfib_entry->mfe_prefix.fp_proto)
129 {
130 case FIB_PROTOCOL_IP4:
131 return (FIB_FORW_CHAIN_TYPE_MCAST_IP4);
132 case FIB_PROTOCOL_IP6:
133 return (FIB_FORW_CHAIN_TYPE_MCAST_IP6);
134 case FIB_PROTOCOL_MPLS:
135 ASSERT(0);
136 break;
137 }
138 return (FIB_FORW_CHAIN_TYPE_MCAST_IP4);
139}
140
141static u8 *
142format_mfib_entry_dpo (u8 * s, va_list * args)
143{
144 index_t fei = va_arg(*args, index_t);
145 CLIB_UNUSED(u32 indent) = va_arg(*args, u32);
146
147 return (format(s, "%U",
148 format_mfib_entry, fei,
149 MFIB_ENTRY_FORMAT_BRIEF));
150}
151
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800152static inline mfib_path_ext_t *
153mfib_entry_path_ext_get (index_t mi)
154{
155 return (pool_elt_at_index(mfib_path_ext_pool, mi));
156}
157
158static u8 *
159format_mfib_entry_path_ext (u8 * s, va_list * args)
160{
161 mfib_path_ext_t *path_ext;
162 index_t mpi = va_arg(*args, index_t);
163
164 path_ext = mfib_entry_path_ext_get(mpi);
165 return (format(s, "path:%d flags:%U",
166 path_ext->mfpe_path,
167 format_mfib_itf_flags, path_ext->mfpe_flags));
168}
169
Neale Ranns32e1c012016-11-22 17:07:28 +0000170u8 *
171format_mfib_entry (u8 * s, va_list * args)
172{
173 fib_node_index_t fei, mfi;
174 mfib_entry_t *mfib_entry;
175 mfib_entry_src_t *msrc;
176 u32 sw_if_index;
177 int level;
178
179 fei = va_arg (*args, fib_node_index_t);
180 level = va_arg (*args, int);
181 mfib_entry = mfib_entry_get(fei);
182
183 s = format (s, "%U", format_mfib_prefix, &mfib_entry->mfe_prefix);
184 s = format (s, ": %U", format_mfib_entry_flags, mfib_entry->mfe_flags);
185
186 if (level >= MFIB_ENTRY_FORMAT_DETAIL)
187 {
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800188 fib_node_index_t path_index, mpi;
189
Neale Ranns32e1c012016-11-22 17:07:28 +0000190 s = format (s, "\n");
191 s = format (s, " fib:%d", mfib_entry->mfe_fib_index);
192 s = format (s, " index:%d", mfib_entry_get_index(mfib_entry));
193 s = format (s, " locks:%d\n", mfib_entry->mfe_node.fn_locks);
194 vec_foreach(msrc, mfib_entry->mfe_srcs)
195 {
196 s = format (s, " src:%s", mfib_source_names[msrc->mfes_src]);
197 s = format (s, ": %U\n", format_mfib_entry_flags, msrc->mfes_flags);
198 if (FIB_NODE_INDEX_INVALID != msrc->mfes_pl)
199 {
200 s = fib_path_list_format(msrc->mfes_pl, s);
201 }
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800202 s = format (s, " Extensions:\n",
203 mfib_source_names[msrc->mfes_src]);
204 hash_foreach(path_index, mpi, msrc->mfes_exts,
205 ({
206 s = format(s, " %U\n", format_mfib_entry_path_ext, mpi);
207 }));
208 s = format (s, " Interface-Forwarding:\n",
209 mfib_source_names[msrc->mfes_src]);
Neale Ranns32e1c012016-11-22 17:07:28 +0000210 hash_foreach(sw_if_index, mfi, msrc->mfes_itfs,
211 ({
212 s = format(s, " %U\n", format_mfib_itf, mfi);
213 }));
214 }
215 }
216
217 s = format(s, "\n Interfaces:");
218 hash_foreach(sw_if_index, mfi, mfib_entry->mfe_itfs,
219 ({
220 s = format(s, "\n %U", format_mfib_itf, mfi);
221 }));
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800222 s = format(s, "\n RPF-ID:%d", mfib_entry->mfe_rpf_id);
Neale Ranns32e1c012016-11-22 17:07:28 +0000223 s = format(s, "\n %U-chain\n %U",
224 format_fib_forw_chain_type,
225 mfib_entry_get_default_chain_type(mfib_entry),
226 format_dpo_id,
227 &mfib_entry->mfe_rep,
228 2);
229 s = format(s, "\n");
230
231 if (level >= MFIB_ENTRY_FORMAT_DETAIL2)
232 {
233 s = format(s, "\nchildren:");
234 s = fib_node_children_format(mfib_entry->mfe_node.fn_children, s);
235 }
236
237 return (s);
238}
239
240static mfib_entry_t*
241mfib_entry_from_fib_node (fib_node_t *node)
242{
243#if CLIB_DEBUG > 0
244 ASSERT(FIB_NODE_TYPE_MFIB_ENTRY == node->fn_type);
245#endif
246 return ((mfib_entry_t*)node);
247}
248
249static int
250mfib_entry_src_cmp_for_sort (void * v1,
251 void * v2)
252{
253 mfib_entry_src_t *esrc1 = v1, *esrc2 = v2;
254
255 return (esrc1->mfes_src - esrc2->mfes_src);
256}
257
258static void
259mfib_entry_src_init (mfib_entry_t *mfib_entry,
260 mfib_source_t source)
261
262{
263 mfib_entry_src_t esrc = {
264 .mfes_pl = FIB_NODE_INDEX_INVALID,
265 .mfes_flags = MFIB_ENTRY_FLAG_NONE,
266 .mfes_src = source,
267 };
268
269 vec_add1(mfib_entry->mfe_srcs, esrc);
270 vec_sort_with_function(mfib_entry->mfe_srcs,
271 mfib_entry_src_cmp_for_sort);
272}
273
274static mfib_entry_src_t *
275mfib_entry_src_find (const mfib_entry_t *mfib_entry,
276 mfib_source_t source,
277 u32 *index)
278
279{
280 mfib_entry_src_t *esrc;
281 int ii;
282
283 ii = 0;
284 vec_foreach(esrc, mfib_entry->mfe_srcs)
285 {
286 if (esrc->mfes_src == source)
287 {
288 if (NULL != index)
289 {
290 *index = ii;
291 }
292 return (esrc);
293 }
294 else
295 {
296 ii++;
297 }
298 }
299
300 return (NULL);
301}
302
303static mfib_entry_src_t *
304mfib_entry_src_find_or_create (mfib_entry_t *mfib_entry,
305 mfib_source_t source)
306{
307 mfib_entry_src_t *esrc;
308
309 esrc = mfib_entry_src_find(mfib_entry, source, NULL);
310
311 if (NULL == esrc)
312 {
313 mfib_entry_src_init(mfib_entry, source);
314 }
315
316 return (mfib_entry_src_find(mfib_entry, source, NULL));
317}
318
319static mfib_entry_src_t*
320mfib_entry_get_best_src (const mfib_entry_t *mfib_entry)
321{
322 mfib_entry_src_t *bsrc;
323
324 /*
325 * the enum of sources is deliberately arranged in priority order
326 */
327 if (0 == vec_len(mfib_entry->mfe_srcs))
328 {
329 bsrc = NULL;
330 }
331 else
332 {
333 bsrc = vec_elt_at_index(mfib_entry->mfe_srcs, 0);
334 }
335
336 return (bsrc);
337}
338
339static void
340mfib_entry_src_flush (mfib_entry_src_t *msrc)
341{
342 u32 sw_if_index;
343 index_t mfii;
344
345 hash_foreach(sw_if_index, mfii, msrc->mfes_itfs,
346 ({
347 mfib_itf_delete(mfib_itf_get(mfii));
348 }));
Neale Rannsbcc6aa42017-02-24 01:34:14 -0800349 hash_free(msrc->mfes_itfs);
350 msrc->mfes_itfs = NULL;
Neale Rannsa9374df2017-02-02 02:18:18 -0800351 fib_path_list_unlock(msrc->mfes_pl);
Neale Ranns32e1c012016-11-22 17:07:28 +0000352}
353
354static void
355mfib_entry_src_remove (mfib_entry_t *mfib_entry,
356 mfib_source_t source)
357
358{
359 mfib_entry_src_t *msrc;
360 u32 index = ~0;
361
362 msrc = mfib_entry_src_find(mfib_entry, source, &index);
363
364 if (NULL != msrc)
365 {
366 mfib_entry_src_flush(msrc);
367 vec_del1(mfib_entry->mfe_srcs, index);
368 }
369}
370
Neale Ranns32e1c012016-11-22 17:07:28 +0000371static void
372mfib_entry_last_lock_gone (fib_node_t *node)
373{
374 mfib_entry_t *mfib_entry;
375 mfib_entry_src_t *msrc;
376
377 mfib_entry = mfib_entry_from_fib_node(node);
378
379 dpo_reset(&mfib_entry->mfe_rep);
380
381 MFIB_ENTRY_DBG(mfib_entry, "last-lock");
382
383 vec_foreach(msrc, mfib_entry->mfe_srcs)
384 {
385 mfib_entry_src_flush(msrc);
386 }
387
Neale Ranns32e1c012016-11-22 17:07:28 +0000388 vec_free(mfib_entry->mfe_srcs);
389
390 fib_node_deinit(&mfib_entry->mfe_node);
391 pool_put(mfib_entry_pool, mfib_entry);
392}
393
394/*
395 * mfib_entry_back_walk_notify
396 *
397 * A back walk has reach this entry.
398 */
399static fib_node_back_walk_rc_t
400mfib_entry_back_walk_notify (fib_node_t *node,
401 fib_node_back_walk_ctx_t *ctx)
402{
403 // FIXME - re-evalute
404
405 return (FIB_NODE_BACK_WALK_CONTINUE);
406}
407
408static void
409mfib_entry_show_memory (void)
410{
411 fib_show_memory_usage("multicast-Entry",
412 pool_elts(mfib_entry_pool),
413 pool_len(mfib_entry_pool),
414 sizeof(mfib_entry_t));
415}
416
417/*
418 * The MFIB entry's graph node virtual function table
419 */
420static const fib_node_vft_t mfib_entry_vft = {
421 .fnv_get = mfib_entry_get_node,
422 .fnv_last_lock = mfib_entry_last_lock_gone,
423 .fnv_back_walk = mfib_entry_back_walk_notify,
424 .fnv_mem_show = mfib_entry_show_memory,
425};
426
427u32
428mfib_entry_child_add (fib_node_index_t mfib_entry_index,
429 fib_node_type_t child_type,
430 fib_node_index_t child_index)
431{
432 return (fib_node_child_add(FIB_NODE_TYPE_MFIB_ENTRY,
433 mfib_entry_index,
434 child_type,
435 child_index));
436};
437
438void
439mfib_entry_child_remove (fib_node_index_t mfib_entry_index,
440 u32 sibling_index)
441{
442 fib_node_child_remove(FIB_NODE_TYPE_MFIB_ENTRY,
443 mfib_entry_index,
444 sibling_index);
445}
446
447static mfib_entry_t *
448mfib_entry_alloc (u32 fib_index,
449 const mfib_prefix_t *prefix,
450 fib_node_index_t *mfib_entry_index)
451{
452 mfib_entry_t *mfib_entry;
453
454 pool_get(mfib_entry_pool, mfib_entry);
Neale Ranns32e1c012016-11-22 17:07:28 +0000455
456 fib_node_init(&mfib_entry->mfe_node,
457 FIB_NODE_TYPE_MFIB_ENTRY);
458
Neale Ranns5a72c1c2017-02-24 08:29:22 -0800459 /*
460 * Some of the members require non-default initialisation
461 * so we also init those that don't and thus save on the call to memset.
462 */
463 mfib_entry->mfe_flags = 0;
Neale Ranns32e1c012016-11-22 17:07:28 +0000464 mfib_entry->mfe_fib_index = fib_index;
465 mfib_entry->mfe_prefix = *prefix;
Neale Ranns5a72c1c2017-02-24 08:29:22 -0800466 mfib_entry->mfe_srcs = NULL;
467 mfib_entry->mfe_itfs = NULL;
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800468 mfib_entry->mfe_rpf_id = MFIB_RPF_ID_NONE;
Neale Ranns32e1c012016-11-22 17:07:28 +0000469
470 dpo_reset(&mfib_entry->mfe_rep);
471
472 *mfib_entry_index = mfib_entry_get_index(mfib_entry);
473
474 MFIB_ENTRY_DBG(mfib_entry, "alloc");
475
476 return (mfib_entry);
477}
478
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800479static inline mfib_path_ext_t *
480mfib_entry_path_ext_find (mfib_path_ext_t *exts,
481 fib_node_index_t path_index)
482{
483 uword *p;
484
485 p = hash_get(exts, path_index);
486
487 if (NULL != p)
488 {
489 return (mfib_entry_path_ext_get(p[0]));
490 }
491
492 return (NULL);
493}
494
495static mfib_path_ext_t*
496mfib_path_ext_add (mfib_entry_src_t *msrc,
497 fib_node_index_t path_index,
498 mfib_itf_flags_t mfi_flags)
499{
500 mfib_path_ext_t *path_ext;
501
502 pool_get(mfib_path_ext_pool, path_ext);
503
504 path_ext->mfpe_flags = mfi_flags;
505 path_ext->mfpe_path = path_index;
506
507 hash_set(msrc->mfes_exts, path_index,
508 path_ext - mfib_path_ext_pool);
509
510 return (path_ext);
511}
512
513static void
514mfib_path_ext_remove (mfib_entry_src_t *msrc,
515 fib_node_index_t path_index)
516{
517 mfib_path_ext_t *path_ext;
518
519 path_ext = mfib_entry_path_ext_find(msrc->mfes_exts, path_index);
520
521 hash_unset(msrc->mfes_exts, path_index);
522 pool_put(mfib_path_ext_pool, path_ext);
523}
524
Neale Ranns32e1c012016-11-22 17:07:28 +0000525typedef struct mfib_entry_collect_forwarding_ctx_t_
526{
527 load_balance_path_t * next_hops;
528 fib_forward_chain_type_t fct;
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800529 mfib_entry_src_t *msrc;
Neale Ranns32e1c012016-11-22 17:07:28 +0000530} mfib_entry_collect_forwarding_ctx_t;
531
532static int
533mfib_entry_src_collect_forwarding (fib_node_index_t pl_index,
534 fib_node_index_t path_index,
535 void *arg)
536{
537 mfib_entry_collect_forwarding_ctx_t *ctx;
538 load_balance_path_t *nh;
539
540 ctx = arg;
541
542 /*
543 * if the path is not resolved, don't include it.
544 */
545 if (!fib_path_is_resolved(path_index))
546 {
547 return (!0);
548 }
549
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800550 /*
551 * If the path is not forwarding to use it
552 */
553 mfib_path_ext_t *path_ext;
554
555 path_ext = mfib_entry_path_ext_find(ctx->msrc->mfes_exts,
556 path_index);
557
558 if (NULL != path_ext &&
559 !(path_ext->mfpe_flags & MFIB_ITF_FLAG_FORWARD))
560 {
561 return (!0);
562 }
563
Neale Ranns32e1c012016-11-22 17:07:28 +0000564 switch (ctx->fct)
565 {
566 case FIB_FORW_CHAIN_TYPE_MCAST_IP4:
567 case FIB_FORW_CHAIN_TYPE_MCAST_IP6:
568 /*
569 * EOS traffic with no label to stack, we need the IP Adj
570 */
571 vec_add2(ctx->next_hops, nh, 1);
572
573 nh->path_index = path_index;
574 nh->path_weight = fib_path_get_weight(path_index);
575 fib_path_contribute_forwarding(path_index, ctx->fct, &nh->path_dpo);
576 break;
577
578 case FIB_FORW_CHAIN_TYPE_UNICAST_IP4:
579 case FIB_FORW_CHAIN_TYPE_UNICAST_IP6:
580 case FIB_FORW_CHAIN_TYPE_MPLS_NON_EOS:
581 case FIB_FORW_CHAIN_TYPE_MPLS_EOS:
582 case FIB_FORW_CHAIN_TYPE_ETHERNET:
Florin Corasce1b4c72017-01-26 14:25:34 -0800583 case FIB_FORW_CHAIN_TYPE_NSH:
Neale Ranns32e1c012016-11-22 17:07:28 +0000584 ASSERT(0);
585 break;
586 }
587
588 return (!0);
589}
590
591static void
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800592mfib_entry_stack (mfib_entry_t *mfib_entry,
593 mfib_entry_src_t *msrc)
Neale Ranns32e1c012016-11-22 17:07:28 +0000594{
Neale Ranns32e1c012016-11-22 17:07:28 +0000595 dpo_proto_t dp;
596
597 dp = fib_proto_to_dpo(mfib_entry_get_proto(mfib_entry));
598
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800599 if (NULL != msrc &&
600 FIB_NODE_INDEX_INVALID != msrc->mfes_pl)
Neale Ranns32e1c012016-11-22 17:07:28 +0000601 {
Neale Rannsa9374df2017-02-02 02:18:18 -0800602 mfib_entry_collect_forwarding_ctx_t ctx = {
603 .next_hops = NULL,
604 .fct = mfib_entry_get_default_chain_type(mfib_entry),
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800605 .msrc = msrc,
Neale Rannsa9374df2017-02-02 02:18:18 -0800606 };
607
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800608 fib_path_list_walk(msrc->mfes_pl,
Neale Ranns32e1c012016-11-22 17:07:28 +0000609 mfib_entry_src_collect_forwarding,
610 &ctx);
611
Neale Rannsa9374df2017-02-02 02:18:18 -0800612 if (!(MFIB_ENTRY_FLAG_EXCLUSIVE & mfib_entry->mfe_flags))
Neale Ranns32e1c012016-11-22 17:07:28 +0000613 {
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800614 if (NULL == ctx.next_hops)
Neale Rannsa9374df2017-02-02 02:18:18 -0800615 {
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800616 /*
617 * no next-hops, stack directly on the drop
618 */
Neale Rannsa9374df2017-02-02 02:18:18 -0800619 dpo_stack(DPO_MFIB_ENTRY, dp,
620 &mfib_entry->mfe_rep,
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800621 drop_dpo_get(dp));
Neale Rannsa9374df2017-02-02 02:18:18 -0800622 }
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800623 else
624 {
625 /*
626 * each path contirbutes a next-hop. form a replicate
627 * from those choices.
628 */
629 if (!dpo_id_is_valid(&mfib_entry->mfe_rep) ||
630 dpo_is_drop(&mfib_entry->mfe_rep))
631 {
632 dpo_id_t tmp_dpo = DPO_INVALID;
633
634 dpo_set(&tmp_dpo,
635 DPO_REPLICATE, dp,
636 replicate_create(0, dp));
637
638 dpo_stack(DPO_MFIB_ENTRY, dp,
639 &mfib_entry->mfe_rep,
640 &tmp_dpo);
641
642 dpo_reset(&tmp_dpo);
643 }
644 replicate_multipath_update(&mfib_entry->mfe_rep,
645 ctx.next_hops);
646 }
Neale Rannsa9374df2017-02-02 02:18:18 -0800647 }
648 else
649 {
650 /*
651 * for exclusive routes the source provided a replicate DPO
652 * we we stashed inthe special path list with one path
653 * so we can stack directly on that.
654 */
655 ASSERT(1 == vec_len(ctx.next_hops));
Neale Ranns32e1c012016-11-22 17:07:28 +0000656
657 dpo_stack(DPO_MFIB_ENTRY, dp,
658 &mfib_entry->mfe_rep,
Neale Rannsa9374df2017-02-02 02:18:18 -0800659 &ctx.next_hops[0].path_dpo);
660 dpo_reset(&ctx.next_hops[0].path_dpo);
661 vec_free(ctx.next_hops);
Neale Ranns32e1c012016-11-22 17:07:28 +0000662 }
Neale Ranns32e1c012016-11-22 17:07:28 +0000663 }
664 else
665 {
666 dpo_stack(DPO_MFIB_ENTRY, dp,
667 &mfib_entry->mfe_rep,
668 drop_dpo_get(dp));
669 }
670}
671
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800672static fib_node_index_t
673mfib_entry_src_path_add (mfib_entry_src_t *msrc,
674 const fib_route_path_t *rpath)
Neale Ranns32e1c012016-11-22 17:07:28 +0000675{
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800676 fib_node_index_t path_index;
Neale Ranns32e1c012016-11-22 17:07:28 +0000677 fib_route_path_t *rpaths;
678
Neale Rannsa9374df2017-02-02 02:18:18 -0800679 ASSERT(!(MFIB_ENTRY_FLAG_EXCLUSIVE & msrc->mfes_flags));
680
Neale Ranns32e1c012016-11-22 17:07:28 +0000681 /*
682 * path-lists require a vector of paths
683 */
684 rpaths = NULL;
685 vec_add1(rpaths, rpath[0]);
686
Neale Ranns32e1c012016-11-22 17:07:28 +0000687 if (FIB_NODE_INDEX_INVALID == msrc->mfes_pl)
688 {
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800689 /* A non-shared path-list */
690 msrc->mfes_pl = fib_path_list_create(FIB_PATH_LIST_FLAG_NO_URPF,
691 NULL);
692 fib_path_list_lock(msrc->mfes_pl);
Neale Ranns32e1c012016-11-22 17:07:28 +0000693 }
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800694
695 path_index = fib_path_list_path_add(msrc->mfes_pl, rpaths);
Neale Ranns32e1c012016-11-22 17:07:28 +0000696
697 vec_free(rpaths);
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800698
699 return (path_index);
Neale Ranns32e1c012016-11-22 17:07:28 +0000700}
701
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800702static fib_node_index_t
703mfib_entry_src_path_remove (mfib_entry_src_t *msrc,
704 const fib_route_path_t *rpath)
Neale Ranns32e1c012016-11-22 17:07:28 +0000705{
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800706 fib_node_index_t path_index;
Neale Ranns32e1c012016-11-22 17:07:28 +0000707 fib_route_path_t *rpaths;
708
Neale Rannsa9374df2017-02-02 02:18:18 -0800709 ASSERT(!(MFIB_ENTRY_FLAG_EXCLUSIVE & msrc->mfes_flags));
710
Neale Ranns32e1c012016-11-22 17:07:28 +0000711 /*
712 * path-lists require a vector of paths
713 */
714 rpaths = NULL;
715 vec_add1(rpaths, rpath[0]);
716
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800717 path_index = fib_path_list_path_remove(msrc->mfes_pl, rpaths);
Neale Ranns32e1c012016-11-22 17:07:28 +0000718
719 vec_free(rpaths);
720
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800721 return (path_index);
Neale Ranns32e1c012016-11-22 17:07:28 +0000722}
723
724static void
725mfib_entry_recalculate_forwarding (mfib_entry_t *mfib_entry)
726{
Neale Ranns32e1c012016-11-22 17:07:28 +0000727 mfib_entry_src_t *bsrc;
728
Neale Ranns32e1c012016-11-22 17:07:28 +0000729 /*
730 * copy the forwarding data from the bast source
731 */
732 bsrc = mfib_entry_get_best_src(mfib_entry);
733
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800734 if (NULL != bsrc)
Neale Ranns32e1c012016-11-22 17:07:28 +0000735 {
Neale Ranns32e1c012016-11-22 17:07:28 +0000736 mfib_entry->mfe_flags = bsrc->mfes_flags;
737 mfib_entry->mfe_itfs = bsrc->mfes_itfs;
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800738 mfib_entry->mfe_rpf_id = bsrc->mfes_rpf_id;
Neale Ranns32e1c012016-11-22 17:07:28 +0000739 }
740
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800741 mfib_entry_stack(mfib_entry, bsrc);
Neale Ranns32e1c012016-11-22 17:07:28 +0000742}
743
744
745fib_node_index_t
746mfib_entry_create (u32 fib_index,
747 mfib_source_t source,
748 const mfib_prefix_t *prefix,
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800749 fib_rpf_id_t rpf_id,
Neale Ranns32e1c012016-11-22 17:07:28 +0000750 mfib_entry_flags_t entry_flags)
751{
752 fib_node_index_t mfib_entry_index;
753 mfib_entry_t *mfib_entry;
754 mfib_entry_src_t *msrc;
755
756 mfib_entry = mfib_entry_alloc(fib_index, prefix,
757 &mfib_entry_index);
758 msrc = mfib_entry_src_find_or_create(mfib_entry, source);
759 msrc->mfes_flags = entry_flags;
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800760 msrc->mfes_rpf_id = rpf_id;
Neale Ranns32e1c012016-11-22 17:07:28 +0000761
762 mfib_entry_recalculate_forwarding(mfib_entry);
763
764 return (mfib_entry_index);
765}
766
767static int
768mfib_entry_ok_for_delete (mfib_entry_t *mfib_entry)
769{
770 return (0 == vec_len(mfib_entry->mfe_srcs));
771}
772
773static int
774mfib_entry_src_ok_for_delete (const mfib_entry_src_t *msrc)
775{
776 return ((MFIB_ENTRY_FLAG_NONE == msrc->mfes_flags &&
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800777 0 == fib_path_list_get_n_paths(msrc->mfes_pl)));
Neale Ranns32e1c012016-11-22 17:07:28 +0000778}
779
780int
781mfib_entry_update (fib_node_index_t mfib_entry_index,
782 mfib_source_t source,
Neale Rannsa9374df2017-02-02 02:18:18 -0800783 mfib_entry_flags_t entry_flags,
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800784 fib_rpf_id_t rpf_id,
Neale Rannsa9374df2017-02-02 02:18:18 -0800785 index_t repi)
Neale Ranns32e1c012016-11-22 17:07:28 +0000786{
787 mfib_entry_t *mfib_entry;
788 mfib_entry_src_t *msrc;
789
790 mfib_entry = mfib_entry_get(mfib_entry_index);
791 msrc = mfib_entry_src_find_or_create(mfib_entry, source);
792 msrc->mfes_flags = entry_flags;
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800793 msrc->mfes_rpf_id = rpf_id;
Neale Ranns32e1c012016-11-22 17:07:28 +0000794
Neale Rannsa9374df2017-02-02 02:18:18 -0800795 if (INDEX_INVALID != repi)
796 {
797 /*
798 * The source is providing its own replicate DPO.
799 * Create a sepcial path-list to manage it, that way
800 * this entry and the source are equivalent to a normal
801 * entry
802 */
803 fib_node_index_t old_pl_index;
804 fib_protocol_t fp;
805 dpo_id_t dpo = DPO_INVALID;
806
807 fp = mfib_entry_get_proto(mfib_entry);
808 old_pl_index = msrc->mfes_pl;
809
810 dpo_set(&dpo, DPO_REPLICATE,
811 fib_proto_to_dpo(fp),
812 repi);
813
814 msrc->mfes_pl =
815 fib_path_list_create_special(fp,
816 FIB_PATH_LIST_FLAG_EXCLUSIVE,
817 &dpo);
818
819 dpo_reset(&dpo);
820 fib_path_list_lock(msrc->mfes_pl);
821 fib_path_list_unlock(old_pl_index);
822 }
823
Neale Ranns32e1c012016-11-22 17:07:28 +0000824 if (mfib_entry_src_ok_for_delete(msrc))
825 {
826 /*
827 * this source has no interfaces and no flags.
828 * it has nothing left to give - remove it
829 */
830 mfib_entry_src_remove(mfib_entry, source);
831 }
832
833 mfib_entry_recalculate_forwarding(mfib_entry);
834
835 return (mfib_entry_ok_for_delete(mfib_entry));
836}
837
838static void
839mfib_entry_itf_add (mfib_entry_src_t *msrc,
840 u32 sw_if_index,
841 index_t mi)
842{
843 hash_set(msrc->mfes_itfs, sw_if_index, mi);
844}
845
846static void
847mfib_entry_itf_remove (mfib_entry_src_t *msrc,
848 u32 sw_if_index)
849{
850 mfib_itf_t *mfi;
851
852 mfi = mfib_entry_itf_find(msrc->mfes_itfs, sw_if_index);
853
854 mfib_itf_delete(mfi);
855
856 hash_unset(msrc->mfes_itfs, sw_if_index);
857}
858
859void
860mfib_entry_path_update (fib_node_index_t mfib_entry_index,
861 mfib_source_t source,
862 const fib_route_path_t *rpath,
863 mfib_itf_flags_t itf_flags)
864{
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800865 fib_node_index_t path_index;
866 mfib_path_ext_t *path_ext;
867 mfib_itf_flags_t old, new;
Neale Ranns32e1c012016-11-22 17:07:28 +0000868 mfib_entry_t *mfib_entry;
869 mfib_entry_src_t *msrc;
Neale Ranns32e1c012016-11-22 17:07:28 +0000870
871 mfib_entry = mfib_entry_get(mfib_entry_index);
872 ASSERT(NULL != mfib_entry);
873 msrc = mfib_entry_src_find_or_create(mfib_entry, source);
874
875 /*
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800876 * add the path to the path-list. If it's a duplicate we'll get
877 * back the original path.
Neale Ranns32e1c012016-11-22 17:07:28 +0000878 */
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800879 path_index = mfib_entry_src_path_add(msrc, rpath);
Neale Ranns32e1c012016-11-22 17:07:28 +0000880
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800881 /*
882 * find the path extension for that path
883 */
884 path_ext = mfib_entry_path_ext_find(msrc->mfes_exts, path_index);
885
886 if (NULL == path_ext)
Neale Ranns32e1c012016-11-22 17:07:28 +0000887 {
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800888 old = MFIB_ITF_FLAG_NONE;
889 path_ext = mfib_path_ext_add(msrc, path_index, itf_flags);
Neale Ranns32e1c012016-11-22 17:07:28 +0000890 }
891 else
892 {
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800893 old = path_ext->mfpe_flags;
894 path_ext->mfpe_flags = itf_flags;
895 }
Neale Ranns32e1c012016-11-22 17:07:28 +0000896
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800897 /*
898 * Has the path changed its contribution to the input interface set.
899 * Which only paths with interfaces can do...
900 */
901 if (~0 != rpath[0].frp_sw_if_index)
902 {
903 mfib_itf_t *mfib_itf;
904
905 new = itf_flags;
906
907 if (old != new)
Neale Ranns32e1c012016-11-22 17:07:28 +0000908 {
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800909 if (MFIB_ITF_FLAG_NONE == new)
910 {
911 /*
912 * no more interface flags on this path, remove
913 * from the data-plane set
914 */
915 mfib_entry_itf_remove(msrc, rpath[0].frp_sw_if_index);
916 }
917 else if (MFIB_ITF_FLAG_NONE == old)
918 {
919 /*
920 * This interface is now contributing
921 */
922 mfib_entry_itf_add(msrc,
923 rpath[0].frp_sw_if_index,
924 mfib_itf_create(rpath[0].frp_sw_if_index,
925 itf_flags));
926 }
927 else
928 {
929 /*
930 * change of flag contributions
931 */
932 mfib_itf = mfib_entry_itf_find(msrc->mfes_itfs,
933 rpath[0].frp_sw_if_index);
934 /* Seen by packets inflight */
935 mfib_itf->mfi_flags = new;
936 }
Neale Ranns32e1c012016-11-22 17:07:28 +0000937 }
Neale Ranns32e1c012016-11-22 17:07:28 +0000938 }
939
940 mfib_entry_recalculate_forwarding(mfib_entry);
941}
942
943/*
944 * mfib_entry_path_remove
945 *
946 * remove a path from the entry.
947 * return the mfib_entry's index if it is still present, INVALID otherwise.
948 */
949int
950mfib_entry_path_remove (fib_node_index_t mfib_entry_index,
951 mfib_source_t source,
952 const fib_route_path_t *rpath)
953{
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800954 fib_node_index_t path_index;
Neale Ranns32e1c012016-11-22 17:07:28 +0000955 mfib_entry_t *mfib_entry;
956 mfib_entry_src_t *msrc;
Neale Ranns32e1c012016-11-22 17:07:28 +0000957
958 mfib_entry = mfib_entry_get(mfib_entry_index);
959 ASSERT(NULL != mfib_entry);
960 msrc = mfib_entry_src_find(mfib_entry, source, NULL);
961
962 if (NULL == msrc)
963 {
964 /*
965 * there are no paths left for this source
966 */
967 return (mfib_entry_ok_for_delete(mfib_entry));
968 }
969
970 /*
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800971 * remove the path from the path-list. If it's not there we'll get
972 * back invalid
Neale Ranns32e1c012016-11-22 17:07:28 +0000973 */
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800974 path_index = mfib_entry_src_path_remove(msrc, rpath);
Neale Ranns32e1c012016-11-22 17:07:28 +0000975
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800976 if (FIB_NODE_INDEX_INVALID != path_index)
Neale Ranns32e1c012016-11-22 17:07:28 +0000977 {
978 /*
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800979 * don't need the extension, nor the interface anymore
Neale Ranns32e1c012016-11-22 17:07:28 +0000980 */
Neale Ranns0f26c5a2017-03-01 15:12:11 -0800981 mfib_path_ext_remove(msrc, path_index);
982 if (~0 != rpath[0].frp_sw_if_index)
983 {
984 mfib_entry_itf_remove(msrc, rpath[0].frp_sw_if_index);
985 }
Neale Ranns32e1c012016-11-22 17:07:28 +0000986 }
987
Neale Ranns32e1c012016-11-22 17:07:28 +0000988 if (mfib_entry_src_ok_for_delete(msrc))
989 {
990 /*
991 * this source has no interfaces and no flags.
992 * it has nothing left to give - remove it
993 */
994 mfib_entry_src_remove(mfib_entry, source);
995 }
996
997 mfib_entry_recalculate_forwarding(mfib_entry);
998
999 return (mfib_entry_ok_for_delete(mfib_entry));
1000}
1001
1002/**
1003 * mfib_entry_delete
1004 *
1005 * The source is withdrawing all the paths it provided
1006 */
1007int
1008mfib_entry_delete (fib_node_index_t mfib_entry_index,
1009 mfib_source_t source)
1010{
1011 mfib_entry_t *mfib_entry;
1012
1013 mfib_entry = mfib_entry_get(mfib_entry_index);
1014 mfib_entry_src_remove(mfib_entry, source);
1015
1016 mfib_entry_recalculate_forwarding(mfib_entry);
1017
1018 return (mfib_entry_ok_for_delete(mfib_entry));
1019}
1020
1021static int
1022fib_ip4_address_compare (ip4_address_t * a1,
1023 ip4_address_t * a2)
1024{
1025 /*
1026 * IP addresses are unsiged ints. the return value here needs to be signed
1027 * a simple subtraction won't cut it.
1028 * If the addresses are the same, the sort order is undefiend, so phoey.
1029 */
1030 return ((clib_net_to_host_u32(a1->data_u32) >
1031 clib_net_to_host_u32(a2->data_u32) ) ?
1032 1 : -1);
1033}
1034
1035static int
1036fib_ip6_address_compare (ip6_address_t * a1,
1037 ip6_address_t * a2)
1038{
1039 int i;
1040 for (i = 0; i < ARRAY_LEN (a1->as_u16); i++)
1041 {
1042 int cmp = (clib_net_to_host_u16 (a1->as_u16[i]) -
1043 clib_net_to_host_u16 (a2->as_u16[i]));
1044 if (cmp != 0)
1045 return cmp;
1046 }
1047 return 0;
1048}
1049
1050static int
1051mfib_entry_cmp (fib_node_index_t mfib_entry_index1,
1052 fib_node_index_t mfib_entry_index2)
1053{
1054 mfib_entry_t *mfib_entry1, *mfib_entry2;
1055 int cmp = 0;
1056
1057 mfib_entry1 = mfib_entry_get(mfib_entry_index1);
1058 mfib_entry2 = mfib_entry_get(mfib_entry_index2);
1059
1060 switch (mfib_entry1->mfe_prefix.fp_proto)
1061 {
1062 case FIB_PROTOCOL_IP4:
1063 cmp = fib_ip4_address_compare(&mfib_entry1->mfe_prefix.fp_grp_addr.ip4,
1064 &mfib_entry2->mfe_prefix.fp_grp_addr.ip4);
1065
1066 if (0 == cmp)
1067 {
1068 cmp = fib_ip4_address_compare(&mfib_entry1->mfe_prefix.fp_src_addr.ip4,
1069 &mfib_entry2->mfe_prefix.fp_src_addr.ip4);
1070 }
1071 break;
1072 case FIB_PROTOCOL_IP6:
1073 cmp = fib_ip6_address_compare(&mfib_entry1->mfe_prefix.fp_grp_addr.ip6,
1074 &mfib_entry2->mfe_prefix.fp_grp_addr.ip6);
1075
1076 if (0 == cmp)
1077 {
1078 cmp = fib_ip6_address_compare(&mfib_entry1->mfe_prefix.fp_src_addr.ip6,
1079 &mfib_entry2->mfe_prefix.fp_src_addr.ip6);
1080 }
1081 break;
1082 case FIB_PROTOCOL_MPLS:
1083 ASSERT(0);
1084 cmp = 0;
1085 break;
1086 }
1087
1088 if (0 == cmp) {
1089 cmp = (mfib_entry1->mfe_prefix.fp_len - mfib_entry2->mfe_prefix.fp_len);
1090 }
1091 return (cmp);
1092}
1093
1094int
1095mfib_entry_cmp_for_sort (void *i1, void *i2)
1096{
1097 fib_node_index_t *mfib_entry_index1 = i1, *mfib_entry_index2 = i2;
1098
1099 return (mfib_entry_cmp(*mfib_entry_index1,
1100 *mfib_entry_index2));
1101}
1102
1103void
1104mfib_entry_lock (fib_node_index_t mfib_entry_index)
1105{
1106 mfib_entry_t *mfib_entry;
1107
1108 mfib_entry = mfib_entry_get(mfib_entry_index);
1109
1110 fib_node_lock(&mfib_entry->mfe_node);
1111}
1112
1113void
1114mfib_entry_unlock (fib_node_index_t mfib_entry_index)
1115{
1116 mfib_entry_t *mfib_entry;
1117
1118 mfib_entry = mfib_entry_get(mfib_entry_index);
1119
1120 fib_node_unlock(&mfib_entry->mfe_node);
1121}
1122
1123static void
1124mfib_entry_dpo_lock (dpo_id_t *dpo)
1125{
1126}
1127static void
1128mfib_entry_dpo_unlock (dpo_id_t *dpo)
1129{
1130}
1131
1132const static dpo_vft_t mfib_entry_dpo_vft = {
1133 .dv_lock = mfib_entry_dpo_lock,
1134 .dv_unlock = mfib_entry_dpo_unlock,
1135 .dv_format = format_mfib_entry_dpo,
1136 .dv_mem_show = mfib_entry_show_memory,
1137};
1138
1139const static char* const mfib_entry_ip4_nodes[] =
1140{
1141 "ip4-mfib-forward-rpf",
1142 NULL,
1143};
1144const static char* const mfib_entry_ip6_nodes[] =
1145{
1146 "ip6-mfib-forward-rpf",
1147 NULL,
1148};
1149
1150const static char* const * const mfib_entry_nodes[DPO_PROTO_NUM] =
1151{
1152 [DPO_PROTO_IP4] = mfib_entry_ip4_nodes,
1153 [DPO_PROTO_IP6] = mfib_entry_ip6_nodes,
1154};
1155
1156void
1157mfib_entry_module_init (void)
1158{
1159 fib_node_register_type (FIB_NODE_TYPE_MFIB_ENTRY, &mfib_entry_vft);
1160 dpo_register(DPO_MFIB_ENTRY, &mfib_entry_dpo_vft, mfib_entry_nodes);
1161}
1162
1163void
1164mfib_entry_encode (fib_node_index_t mfib_entry_index,
1165 fib_route_path_encode_t **api_rpaths)
1166{
1167 mfib_entry_t *mfib_entry;
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001168 mfib_entry_src_t *bsrc;
Neale Ranns32e1c012016-11-22 17:07:28 +00001169
1170 mfib_entry = mfib_entry_get(mfib_entry_index);
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001171 bsrc = mfib_entry_get_best_src(mfib_entry);
1172
1173 if (FIB_NODE_INDEX_INVALID != bsrc->mfes_pl)
Neale Ranns5a8123b2017-01-26 01:18:23 -08001174 {
Neale Ranns0f26c5a2017-03-01 15:12:11 -08001175 fib_path_list_walk(bsrc->mfes_pl,
Neale Ranns5a8123b2017-01-26 01:18:23 -08001176 fib_path_encode,
1177 api_rpaths);
1178 }
Neale Ranns32e1c012016-11-22 17:07:28 +00001179}
1180
Neale Ranns5a8123b2017-01-26 01:18:23 -08001181
Neale Ranns32e1c012016-11-22 17:07:28 +00001182void
1183mfib_entry_get_prefix (fib_node_index_t mfib_entry_index,
1184 mfib_prefix_t *pfx)
1185{
1186 mfib_entry_t *mfib_entry;
1187
1188 mfib_entry = mfib_entry_get(mfib_entry_index);
1189 *pfx = mfib_entry->mfe_prefix;
1190}
1191
1192u32
1193mfib_entry_get_fib_index (fib_node_index_t mfib_entry_index)
1194{
1195 mfib_entry_t *mfib_entry;
1196
1197 mfib_entry = mfib_entry_get(mfib_entry_index);
1198
1199 return (mfib_entry->mfe_fib_index);
1200}
1201
1202void
1203mfib_entry_contribute_forwarding (fib_node_index_t mfib_entry_index,
1204 fib_forward_chain_type_t type,
1205 dpo_id_t *dpo)
1206{
1207 /*
1208 * An IP mFIB entry can only provide a forwarding chain that
1209 * is the same IP proto as the prefix.
1210 * No use-cases (i know of) for other combinations.
1211 */
1212 mfib_entry_t *mfib_entry;
1213 dpo_proto_t dp;
1214
1215 mfib_entry = mfib_entry_get(mfib_entry_index);
1216
1217 dp = fib_proto_to_dpo(mfib_entry->mfe_prefix.fp_proto);
1218
1219 if (type == fib_forw_chain_type_from_dpo_proto(dp))
1220 {
1221 dpo_copy(dpo, &mfib_entry->mfe_rep);
1222 }
1223 else
1224 {
1225 dpo_copy(dpo, drop_dpo_get(dp));
1226 }
1227}
1228
1229u32
1230mfib_entry_pool_size (void)
1231{
1232 return (pool_elts(mfib_entry_pool));
1233}
1234
1235static clib_error_t *
1236show_mfib_entry_command (vlib_main_t * vm,
1237 unformat_input_t * input,
1238 vlib_cli_command_t * cmd)
1239{
1240 fib_node_index_t fei;
1241
1242 if (unformat (input, "%d", &fei))
1243 {
1244 /*
1245 * show one in detail
1246 */
1247 if (!pool_is_free_index(mfib_entry_pool, fei))
1248 {
1249 vlib_cli_output (vm, "%d@%U",
1250 fei,
1251 format_mfib_entry, fei,
1252 MFIB_ENTRY_FORMAT_DETAIL2);
1253 }
1254 else
1255 {
1256 vlib_cli_output (vm, "entry %d invalid", fei);
1257 }
1258 }
1259 else
1260 {
1261 /*
1262 * show all
1263 */
1264 vlib_cli_output (vm, "FIB Entries:");
1265 pool_foreach_index(fei, mfib_entry_pool,
1266 ({
1267 vlib_cli_output (vm, "%d@%U",
1268 fei,
1269 format_mfib_entry, fei,
1270 MFIB_ENTRY_FORMAT_BRIEF);
1271 }));
1272 }
1273
1274 return (NULL);
1275}
1276
Neale Rannsc756c1c2017-02-08 09:11:57 -08001277/*?
1278 * This commnad displays an entry, or all entries, in the mfib tables indexed by their unique
1279 * numerical indentifier.
1280 ?*/
Neale Ranns32e1c012016-11-22 17:07:28 +00001281VLIB_CLI_COMMAND (show_mfib_entry, static) = {
1282 .path = "show mfib entry",
1283 .function = show_mfib_entry_command,
1284 .short_help = "show mfib entry",
1285};