e4ff1bf77ccd5cbb60a457023aec7c3aa169e31f
[vpp.git] / src / vnet / fib / ip4_fib.c
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 <vnet/fib/fib_table.h>
17 #include <vnet/fib/fib_entry.h>
18 #include <vnet/fib/ip4_fib.h>
19
20 /*
21  * A table of prefixes to be added to tables and the sources for them
22  */
23 typedef struct ip4_fib_table_special_prefix_t_ {
24     fib_prefix_t ift_prefix;
25     fib_source_t ift_source;
26     fib_entry_flag_t ift_flag;
27 } ip4_fib_table_special_prefix_t;
28
29 static const ip4_fib_table_special_prefix_t ip4_specials[] = {
30     {
31         /* 0.0.0.0/0*/
32         .ift_prefix = {
33             .fp_addr = {
34                 .ip4.data_u32 = 0,
35             },
36             .fp_len  = 0,
37             .fp_proto = FIB_PROTOCOL_IP4,
38         },
39         .ift_source = FIB_SOURCE_DEFAULT_ROUTE,
40         .ift_flag   = FIB_ENTRY_FLAG_DROP,
41     },
42     {
43         /* 0.0.0.0/32*/
44         .ift_prefix = {
45             .fp_addr = {
46                 .ip4.data_u32 = 0,
47             },
48             .fp_len  = 32,
49             .fp_proto = FIB_PROTOCOL_IP4,
50         },
51         .ift_source = FIB_SOURCE_DEFAULT_ROUTE,
52         .ift_flag   = FIB_ENTRY_FLAG_DROP,
53     },
54     {
55         /*
56          * 240.0.0.0/4
57          * drop class E
58          */
59         .ift_prefix = {
60             .fp_addr = {
61                 .ip4.data_u32 = 0xf0000000,
62             },
63             .fp_len   = 4,
64             .fp_proto = FIB_PROTOCOL_IP4,
65         },
66         .ift_source = FIB_SOURCE_SPECIAL,
67         .ift_flag   = FIB_ENTRY_FLAG_DROP,
68
69     },
70     {
71         /*
72          * 224.0.0.0/4
73          * drop all mcast
74          */
75         .ift_prefix = {
76             .fp_addr = {
77                 .ip4.data_u32 = 0xe0000000,
78             },
79             .fp_len   = 4,
80             .fp_proto = FIB_PROTOCOL_IP4,
81         },
82         .ift_source = FIB_SOURCE_SPECIAL,
83         .ift_flag    = FIB_ENTRY_FLAG_DROP,
84     },
85     {
86         /*
87          * 255.255.255.255/32
88          * drop, but we'll allow it to be usurped by the likes of DHCP
89          */
90         .ift_prefix = {
91             .fp_addr = {
92                 .ip4.data_u32 = 0xffffffff,
93             },
94             .fp_len   = 32,
95             .fp_proto = FIB_PROTOCOL_IP4,
96         },
97         .ift_source = FIB_SOURCE_DEFAULT_ROUTE,
98         .ift_flag   = FIB_ENTRY_FLAG_DROP,
99     }
100 };
101
102
103 static u32
104 ip4_create_fib_with_table_id (u32 table_id,
105                               fib_source_t src)
106 {
107     fib_table_t *fib_table;
108     ip4_fib_t *v4_fib;
109     void *old_heap;
110
111     pool_get(ip4_main.fibs, fib_table);
112     clib_memset(fib_table, 0, sizeof(*fib_table));
113
114     old_heap = clib_mem_set_heap (ip4_main.mtrie_mheap);
115     pool_get_aligned(ip4_main.v4_fibs, v4_fib, CLIB_CACHE_LINE_BYTES);
116     clib_mem_set_heap (old_heap);
117
118     ASSERT((fib_table - ip4_main.fibs) ==
119            (v4_fib - ip4_main.v4_fibs));
120
121     fib_table->ft_proto = FIB_PROTOCOL_IP4;
122     fib_table->ft_index =
123         v4_fib->index =
124             (fib_table - ip4_main.fibs);
125
126     hash_set (ip4_main.fib_index_by_table_id, table_id, fib_table->ft_index);
127
128     fib_table->ft_table_id =
129         v4_fib->table_id =
130             table_id;
131     fib_table->ft_flow_hash_config = IP_FLOW_HASH_DEFAULT;
132     
133     fib_table_lock(fib_table->ft_index, FIB_PROTOCOL_IP4, src);
134
135     ip4_mtrie_init(&v4_fib->mtrie);
136
137     /*
138      * add the special entries into the new FIB
139      */
140     int ii;
141
142     for (ii = 0; ii < ARRAY_LEN(ip4_specials); ii++)
143     {
144         fib_prefix_t prefix = ip4_specials[ii].ift_prefix;
145
146         prefix.fp_addr.ip4.data_u32 =
147             clib_host_to_net_u32(prefix.fp_addr.ip4.data_u32);
148
149         fib_table_entry_special_add(fib_table->ft_index,
150                                     &prefix,
151                                     ip4_specials[ii].ift_source,
152                                     ip4_specials[ii].ift_flag);
153     }
154
155     return (fib_table->ft_index);
156 }
157
158 void
159 ip4_fib_table_destroy (u32 fib_index)
160 {
161     fib_table_t *fib_table = pool_elt_at_index(ip4_main.fibs, fib_index);
162     ip4_fib_t *v4_fib = pool_elt_at_index(ip4_main.v4_fibs, fib_index);
163     u32 *n_locks;
164     int ii;
165
166     /*
167      * remove all the specials we added when the table was created.
168      * In reverse order so the default route is last.
169      */
170     for (ii = ARRAY_LEN(ip4_specials) - 1; ii >= 0; ii--)
171     {
172         fib_prefix_t prefix = ip4_specials[ii].ift_prefix;
173
174         prefix.fp_addr.ip4.data_u32 =
175             clib_host_to_net_u32(prefix.fp_addr.ip4.data_u32);
176
177         fib_table_entry_special_remove(fib_table->ft_index,
178                                        &prefix,
179                                        ip4_specials[ii].ift_source);
180     }
181
182     /*
183      * validate no more routes.
184      */
185     ASSERT(0 == fib_table->ft_total_route_counts);
186
187     vec_foreach(n_locks, fib_table->ft_src_route_counts)
188     {
189         ASSERT(0 == *n_locks);
190     }
191
192     if (~0 != fib_table->ft_table_id)
193     {
194         hash_unset (ip4_main.fib_index_by_table_id, fib_table->ft_table_id);
195     }
196
197     vec_free(fib_table->ft_src_route_counts);
198     ip4_mtrie_free(&v4_fib->mtrie);
199
200     pool_put(ip4_main.v4_fibs, v4_fib);
201     pool_put(ip4_main.fibs, fib_table);
202 }
203
204
205 u32
206 ip4_fib_table_find_or_create_and_lock (u32 table_id,
207                                        fib_source_t src)
208 {
209     u32 index;
210
211     index = ip4_fib_index_from_table_id(table_id);
212     if (~0 == index)
213         return ip4_create_fib_with_table_id(table_id, src);
214
215     fib_table_lock(index, FIB_PROTOCOL_IP4, src);
216
217     return (index);
218 }
219
220 u32
221 ip4_fib_table_create_and_lock (fib_source_t src)
222 {
223     return (ip4_create_fib_with_table_id(~0, src));
224 }
225
226 u32
227 ip4_fib_table_get_index_for_sw_if_index (u32 sw_if_index)
228 {
229     if (sw_if_index >= vec_len(ip4_main.fib_index_by_sw_if_index))
230     {
231         /*
232          * This is the case for interfaces that are not yet mapped to
233          * a IP table
234          */
235         return (~0);
236     }
237     return (ip4_main.fib_index_by_sw_if_index[sw_if_index]);
238 }
239
240 /*
241  * ip4_fib_table_lookup_exact_match
242  *
243  * Exact match prefix lookup
244  */
245 fib_node_index_t
246 ip4_fib_table_lookup_exact_match (const ip4_fib_t *fib,
247                                   const ip4_address_t *addr,
248                                   u32 len)
249 {
250     uword * hash, * result;
251     u32 key;
252
253     hash = fib->fib_entry_by_dst_address[len];
254     key  = (addr->data_u32 & ip4_main.fib_masks[len]);
255
256     result = hash_get(hash, key);
257
258     if (NULL != result) {
259         return (result[0]);
260     }
261     return (FIB_NODE_INDEX_INVALID);
262 }
263
264 /*
265  * ip4_fib_table_lookup_adj
266  *
267  * Longest prefix match
268  */
269 index_t
270 ip4_fib_table_lookup_lb (ip4_fib_t *fib,
271                          const ip4_address_t *addr)
272 {
273     fib_node_index_t fei;
274
275     fei = ip4_fib_table_lookup(fib, addr, 32);
276
277     if (FIB_NODE_INDEX_INVALID != fei)
278     {
279         const dpo_id_t *dpo;
280
281         dpo = fib_entry_contribute_ip_forwarding(fei);
282
283         return (dpo->dpoi_index);
284     }
285     return (INDEX_INVALID);
286 }
287
288 /*
289  * ip4_fib_table_lookup
290  *
291  * Longest prefix match
292  */
293 fib_node_index_t
294 ip4_fib_table_lookup (const ip4_fib_t *fib,
295                       const ip4_address_t *addr,
296                       u32 len)
297 {
298     uword * hash, * result;
299     i32 mask_len;
300     u32 key;
301
302     for (mask_len = len; mask_len >= 0; mask_len--)
303     {
304         hash = fib->fib_entry_by_dst_address[mask_len];
305         key = (addr->data_u32 & ip4_main.fib_masks[mask_len]);
306
307         result = hash_get (hash, key);
308
309         if (NULL != result) {
310             return (result[0]);
311         }
312     }
313     return (FIB_NODE_INDEX_INVALID);
314 }
315
316 void
317 ip4_fib_table_entry_insert (ip4_fib_t *fib,
318                             const ip4_address_t *addr,
319                             u32 len,
320                             fib_node_index_t fib_entry_index)
321 {
322     uword * hash, * result;
323     u32 key;
324
325     key = (addr->data_u32 & ip4_main.fib_masks[len]);
326     hash = fib->fib_entry_by_dst_address[len];
327     result = hash_get (hash, key);
328
329     if (NULL == result) {
330         /*
331          * adding a new entry
332          */
333         uword *old_heap;
334         old_heap = clib_mem_set_heap (ip4_main.mtrie_mheap);
335
336         if (NULL == hash) {
337             hash = hash_create (32 /* elts */, sizeof (uword));
338             hash_set_flags (hash, HASH_FLAG_NO_AUTO_SHRINK);
339
340         }
341         hash = hash_set(hash, key, fib_entry_index);
342         fib->fib_entry_by_dst_address[len] = hash;
343         clib_mem_set_heap (old_heap);
344     }
345     else
346     {
347         ASSERT(0);
348     }
349 }
350
351 void
352 ip4_fib_table_entry_remove (ip4_fib_t *fib,
353                             const ip4_address_t *addr,
354                             u32 len)
355 {
356     uword * hash, * result;
357     u32 key;
358
359     key = (addr->data_u32 & ip4_main.fib_masks[len]);
360     hash = fib->fib_entry_by_dst_address[len];
361     result = hash_get (hash, key);
362
363     if (NULL == result)
364     {
365         /*
366          * removing a non-existent entry. i'll allow it.
367          */
368     }
369     else 
370     {
371         uword *old_heap;
372
373         old_heap = clib_mem_set_heap (ip4_main.mtrie_mheap);
374         hash_unset(hash, key);
375         clib_mem_set_heap (old_heap);
376     }
377
378     fib->fib_entry_by_dst_address[len] = hash;
379 }
380
381 void
382 ip4_fib_table_fwding_dpo_update (ip4_fib_t *fib,
383                                  const ip4_address_t *addr,
384                                  u32 len,
385                                  const dpo_id_t *dpo)
386 {
387     ip4_fib_mtrie_route_add(&fib->mtrie, addr, len, dpo->dpoi_index);
388 }
389
390 void
391 ip4_fib_table_fwding_dpo_remove (ip4_fib_t *fib,
392                                  const ip4_address_t *addr,
393                                  u32 len,
394                                  const dpo_id_t *dpo,
395                                  u32 cover_index)
396 {
397     const fib_prefix_t *cover_prefix;
398     const dpo_id_t *cover_dpo;
399
400     /*
401      * We need to pass the MTRIE the LB index and address length of the
402      * covering prefix, so it can fill the plys with the correct replacement
403      * for the entry being removed
404      */
405     cover_prefix = fib_entry_get_prefix(cover_index);
406     cover_dpo = fib_entry_contribute_ip_forwarding(cover_index);
407
408     ip4_fib_mtrie_route_del(&fib->mtrie,
409                             addr, len, dpo->dpoi_index,
410                             cover_prefix->fp_len,
411                             cover_dpo->dpoi_index);
412 }
413
414 void
415 ip4_fib_table_walk (ip4_fib_t *fib,
416                     fib_table_walk_fn_t fn,
417                     void *ctx)
418 {
419     fib_prefix_t root = {
420         .fp_proto = FIB_PROTOCOL_IP4,
421         // address and length default to all 0
422     };
423
424     /*
425      * A full tree walk is the dengenerate case of a sub-tree from
426      * the very root
427      */
428     return (ip4_fib_table_sub_tree_walk(fib, &root, fn, ctx));
429 }
430
431 void
432 ip4_fib_table_sub_tree_walk (ip4_fib_t *fib,
433                              const fib_prefix_t *root,
434                              fib_table_walk_fn_t fn,
435                              void *ctx)
436 {
437     fib_prefix_t *sub_trees = NULL;
438     int i;
439
440     /*
441      * There is no efficient way to walk this array of hash tables.
442      * so we walk each table with a mask length greater than and equal to
443      * the required root and check it is covered by the root.
444      */
445     for (i = root->fp_len;
446          i < ARRAY_LEN (fib->fib_entry_by_dst_address);
447          i++)
448     {
449         uword * hash = fib->fib_entry_by_dst_address[i];
450
451         if (NULL != hash)
452         {
453             ip4_address_t key;
454             hash_pair_t * p;
455
456             hash_foreach_pair (p, hash,
457             ({
458                 key.as_u32 = p->key;
459                 if (ip4_destination_matches_route(&ip4_main,
460                                                   &key,
461                                                   &root->fp_addr.ip4,
462                                                   root->fp_len))
463                 {
464                     const fib_prefix_t *sub_tree;
465                     int skip = 0;
466
467                     /*
468                      * exclude sub-trees the walk does not want to explore
469                      */
470                     vec_foreach(sub_tree, sub_trees)
471                     {
472                         if (ip4_destination_matches_route(&ip4_main,
473                                                           &key,
474                                                           &sub_tree->fp_addr.ip4,
475                                                           sub_tree->fp_len))
476                         {
477                             skip = 1;
478                             break;
479                         }
480                     }
481
482                     if (!skip)
483                     {
484                         switch (fn(p->value[0], ctx))
485                         {
486                         case FIB_TABLE_WALK_CONTINUE:
487                             break;
488                         case FIB_TABLE_WALK_SUB_TREE_STOP: {
489                             fib_prefix_t pfx = {
490                                 .fp_proto = FIB_PROTOCOL_IP4,
491                                 .fp_len = i,
492                                 .fp_addr.ip4 = key,
493                             };
494                             vec_add1(sub_trees, pfx);
495                             break;
496                         }
497                         case FIB_TABLE_WALK_STOP:
498                             goto done;
499                         }
500                     }
501                 }
502             }));
503         }
504     }
505 done:
506     vec_free(sub_trees);
507     return;
508 }
509
510 /**
511  * Walk show context
512  */
513 typedef struct ip4_fib_show_walk_ctx_t_
514 {
515     fib_node_index_t *ifsw_indicies;
516 } ip4_fib_show_walk_ctx_t;
517
518 static fib_table_walk_rc_t
519 ip4_fib_show_walk_cb (fib_node_index_t fib_entry_index,
520                       void *arg)
521 {
522     ip4_fib_show_walk_ctx_t *ctx = arg;
523
524     vec_add1(ctx->ifsw_indicies, fib_entry_index);
525
526     return (FIB_TABLE_WALK_CONTINUE);
527 }
528
529 static void
530 ip4_fib_table_show_all (ip4_fib_t *fib,
531                         vlib_main_t * vm)
532 {
533     ip4_fib_show_walk_ctx_t ctx = {
534         .ifsw_indicies = NULL,
535     };
536     fib_node_index_t *fib_entry_index;
537
538     ip4_fib_table_walk(fib, ip4_fib_show_walk_cb, &ctx);
539     vec_sort_with_function(ctx.ifsw_indicies,
540                            fib_entry_cmp_for_sort);
541
542     vec_foreach(fib_entry_index, ctx.ifsw_indicies)
543     {
544         vlib_cli_output(vm, "%U",
545                         format_fib_entry,
546                         *fib_entry_index,
547                         FIB_ENTRY_FORMAT_BRIEF);
548     }
549
550     vec_free(ctx.ifsw_indicies);
551 }
552
553 static void
554 ip4_fib_table_show_one (ip4_fib_t *fib,
555                         vlib_main_t * vm,
556                         ip4_address_t *address,
557                         u32 mask_len,
558                         int detail)
559 {    
560     vlib_cli_output(vm, "%U",
561                     format_fib_entry,
562                     ip4_fib_table_lookup(fib, address, mask_len),
563                     (detail ?
564                      FIB_ENTRY_FORMAT_DETAIL2 :
565                      FIB_ENTRY_FORMAT_DETAIL));
566 }
567
568 u8 *
569 format_ip4_fib_table_memory (u8 * s, va_list * args)
570 {
571 #if USE_DLMALLOC == 0
572     s = format(s, "%=30s %=6d %=12ld\n",
573                "IPv4 unicast",
574                pool_elts(ip4_main.fibs),
575                mheap_bytes(ip4_main.mtrie_mheap));
576 #else
577     s = format(s, "%=30s %=6d %=12ld\n",
578                "IPv4 unicast",
579                pool_elts(ip4_main.fibs),
580                mspace_footprint(ip4_main.mtrie_mheap));
581 #endif
582     
583
584     return (s);
585 }
586
587 static clib_error_t *
588 ip4_show_fib (vlib_main_t * vm,
589               unformat_input_t * input,
590               vlib_cli_command_t * cmd)
591 {
592     ip4_main_t * im4 = &ip4_main;
593     fib_table_t * fib_table;
594     u64 total_mtrie_memory, total_hash_memory;
595     int verbose, matching, mtrie, memory;
596     ip4_address_t matching_address;
597     u32 matching_mask = 32;
598     int i, table_id = -1, fib_index = ~0;
599     int detail = 0;
600
601     verbose = 1;
602     matching = mtrie = memory = 0;
603     total_hash_memory = total_mtrie_memory = 0;
604
605     while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
606     {
607         if (unformat (input, "brief") || unformat (input, "summary")
608             || unformat (input, "sum"))
609             verbose = 0;
610
611         else if (unformat (input, "detail") || unformat (input, "det"))
612             detail = 1;
613
614         else if (unformat (input, "mtrie"))
615             mtrie = 1;
616
617         else if (unformat (input, "mem") ||
618                  unformat (input, "memory"))
619             memory = 1;
620
621         else if (unformat (input, "%U/%d",
622                            unformat_ip4_address, &matching_address, &matching_mask))
623             matching = 1;
624
625         else if (unformat (input, "%U", unformat_ip4_address, &matching_address))
626             matching = 1;
627
628         else if (unformat (input, "table %d", &table_id))
629             ;
630         else if (unformat (input, "index %d", &fib_index))
631             ;
632         else
633             break;
634     }
635
636     pool_foreach (fib_table, im4->fibs,
637     ({
638         ip4_fib_t *fib = pool_elt_at_index(im4->v4_fibs, fib_table->ft_index);
639         fib_source_t source;
640         u8 *s = NULL;
641
642         if (table_id >= 0 && table_id != (int)fib->table_id)
643             continue;
644         if (fib_index != ~0 && fib_index != (int)fib->index)
645             continue;
646
647         if (memory)
648         {
649             uword mtrie_size, hash_size, *old_heap;
650
651
652             mtrie_size = ip4_fib_mtrie_memory_usage(&fib->mtrie);
653             hash_size = 0;
654
655             old_heap = clib_mem_set_heap (ip4_main.mtrie_mheap);
656             for (i = 0; i < ARRAY_LEN (fib->fib_entry_by_dst_address); i++)
657             {
658                 uword * hash = fib->fib_entry_by_dst_address[i];
659                 if (NULL != hash)
660                 {
661                     hash_size += hash_bytes(hash);
662                 }
663             }
664             clib_mem_set_heap (old_heap);
665
666             if (verbose)
667                 vlib_cli_output (vm, "%U mtrie:%d hash:%d",
668                                  format_fib_table_name, fib->index,
669                                  FIB_PROTOCOL_IP4,
670                                  mtrie_size,
671                                  hash_size);
672             total_mtrie_memory += mtrie_size;
673             total_hash_memory += hash_size;
674             continue;
675         }
676
677         s = format(s, "%U, fib_index:%d, flow hash:[%U] epoch:%d flags:%U locks:[",
678                    format_fib_table_name, fib->index,
679                    FIB_PROTOCOL_IP4,
680                    fib->index,
681                    format_ip_flow_hash_config,
682                    fib_table->ft_flow_hash_config,
683                    fib_table->ft_epoch,
684                    format_fib_table_flags, fib_table->ft_flags);
685         vec_foreach_index(source, fib_table->ft_locks)
686         {
687             if (0 != fib_table->ft_locks[source])
688             {
689                 s = format(s, "%U:%d, ",
690                            format_fib_source, source,
691                            fib_table->ft_locks[source]);
692             }
693         }
694         s = format (s, "]");
695         vlib_cli_output (vm, "%v", s);
696         vec_free(s);
697
698         /* Show summary? */
699         if (mtrie)
700         {
701             vlib_cli_output (vm, "%U", format_ip4_fib_mtrie, &fib->mtrie, verbose);
702             continue;
703         }
704         if (! verbose)
705         {
706             vlib_cli_output (vm, "%=20s%=16s", "Prefix length", "Count");
707             for (i = 0; i < ARRAY_LEN (fib->fib_entry_by_dst_address); i++)
708             {
709                 uword * hash = fib->fib_entry_by_dst_address[i];
710                 uword n_elts = hash_elts (hash);
711                 if (n_elts > 0)
712                     vlib_cli_output (vm, "%20d%16d", i, n_elts);
713             }
714             continue;
715         }
716
717         if (!matching)
718         {
719             ip4_fib_table_show_all(fib, vm);
720         }
721         else
722         {
723             ip4_fib_table_show_one(fib, vm, &matching_address,
724                                    matching_mask, detail);
725         }
726     }));
727
728     if (memory)
729     {
730         vlib_cli_output (vm, "totals: mtrie:%ld hash:%ld all:%ld",
731                          total_mtrie_memory,
732                          total_hash_memory,
733                          total_mtrie_memory + total_hash_memory);
734         vlib_cli_output (vm, "\nMtrie Mheap Usage: %U\n",
735                          format_mheap, ip4_main.mtrie_mheap, 1);
736     }
737     return 0;
738 }
739
740 /*?
741  * This command displays the IPv4 FIB Tables (VRF Tables) and the route
742  * entries for each table.
743  *
744  * @note This command will run for a long time when the FIB tables are
745  * comprised of millions of entries. For those senarios, consider displaying
746  * a single table or summary mode.
747  *
748  * @cliexpar
749  * Example of how to display all the IPv4 FIB tables:
750  * @cliexstart{show ip fib}
751  * ipv4-VRF:0, fib_index 0, flow hash: src dst sport dport proto
752  * 0.0.0.0/0
753  *   unicast-ip4-chain
754  *   [@0]: dpo-load-balance: [index:0 buckets:1 uRPF:0 to:[0:0]]
755  *     [0] [@0]: dpo-drop ip6
756  * 0.0.0.0/32
757  *   unicast-ip4-chain
758  *   [@0]: dpo-load-balance: [index:1 buckets:1 uRPF:1 to:[0:0]]
759  *     [0] [@0]: dpo-drop ip6
760  * 6.0.1.2/32
761  *   unicast-ip4-chain
762  *   [@0]: dpo-load-balance: [index:30 buckets:1 uRPF:29 to:[0:0]]
763  *     [0] [@3]: arp-ipv4: via 6.0.0.1 af_packet0
764  * 7.0.0.1/32
765  *   unicast-ip4-chain
766  *   [@0]: dpo-load-balance: [index:31 buckets:4 uRPF:30 to:[0:0]]
767  *     [0] [@3]: arp-ipv4: via 6.0.0.2 af_packet0
768  *     [1] [@3]: arp-ipv4: via 6.0.0.2 af_packet0
769  *     [2] [@3]: arp-ipv4: via 6.0.0.2 af_packet0
770  *     [3] [@3]: arp-ipv4: via 6.0.0.1 af_packet0
771  * 224.0.0.0/8
772  *   unicast-ip4-chain
773  *   [@0]: dpo-load-balance: [index:3 buckets:1 uRPF:3 to:[0:0]]
774  *     [0] [@0]: dpo-drop ip6
775  * 240.0.0.0/8
776  *   unicast-ip4-chain
777  *   [@0]: dpo-load-balance: [index:2 buckets:1 uRPF:2 to:[0:0]]
778  *     [0] [@0]: dpo-drop ip6
779  * 255.255.255.255/32
780  *   unicast-ip4-chain
781  *   [@0]: dpo-load-balance: [index:4 buckets:1 uRPF:4 to:[0:0]]
782  *     [0] [@0]: dpo-drop ip6
783  * ipv4-VRF:7, fib_index 1, flow hash: src dst sport dport proto
784  * 0.0.0.0/0
785  *   unicast-ip4-chain
786  *   [@0]: dpo-load-balance: [index:12 buckets:1 uRPF:11 to:[0:0]]
787  *     [0] [@0]: dpo-drop ip6
788  * 0.0.0.0/32
789  *   unicast-ip4-chain
790  *   [@0]: dpo-load-balance: [index:13 buckets:1 uRPF:12 to:[0:0]]
791  *     [0] [@0]: dpo-drop ip6
792  * 172.16.1.0/24
793  *   unicast-ip4-chain
794  *   [@0]: dpo-load-balance: [index:17 buckets:1 uRPF:16 to:[0:0]]
795  *     [0] [@4]: ipv4-glean: af_packet0
796  * 172.16.1.1/32
797  *   unicast-ip4-chain
798  *   [@0]: dpo-load-balance: [index:18 buckets:1 uRPF:17 to:[1:84]]
799  *     [0] [@2]: dpo-receive: 172.16.1.1 on af_packet0
800  * 172.16.1.2/32
801  *   unicast-ip4-chain
802  *   [@0]: dpo-load-balance: [index:21 buckets:1 uRPF:20 to:[0:0]]
803  *     [0] [@5]: ipv4 via 172.16.1.2 af_packet0: IP4: 02:fe:9e:70:7a:2b -> 26:a5:f6:9c:3a:36
804  * 172.16.2.0/24
805  *   unicast-ip4-chain
806  *   [@0]: dpo-load-balance: [index:19 buckets:1 uRPF:18 to:[0:0]]
807  *     [0] [@4]: ipv4-glean: af_packet1
808  * 172.16.2.1/32
809  *   unicast-ip4-chain
810  *   [@0]: dpo-load-balance: [index:20 buckets:1 uRPF:19 to:[0:0]]
811  *     [0] [@2]: dpo-receive: 172.16.2.1 on af_packet1
812  * 224.0.0.0/8
813  *   unicast-ip4-chain
814  *   [@0]: dpo-load-balance: [index:15 buckets:1 uRPF:14 to:[0:0]]
815  *     [0] [@0]: dpo-drop ip6
816  * 240.0.0.0/8
817  *   unicast-ip4-chain
818  *   [@0]: dpo-load-balance: [index:14 buckets:1 uRPF:13 to:[0:0]]
819  *     [0] [@0]: dpo-drop ip6
820  * 255.255.255.255/32
821  *   unicast-ip4-chain
822  *   [@0]: dpo-load-balance: [index:16 buckets:1 uRPF:15 to:[0:0]]
823  *     [0] [@0]: dpo-drop ip6
824  * @cliexend
825  * Example of how to display a single IPv4 FIB table:
826  * @cliexstart{show ip fib table 7}
827  * ipv4-VRF:7, fib_index 1, flow hash: src dst sport dport proto
828  * 0.0.0.0/0
829  *   unicast-ip4-chain
830  *   [@0]: dpo-load-balance: [index:12 buckets:1 uRPF:11 to:[0:0]]
831  *     [0] [@0]: dpo-drop ip6
832  * 0.0.0.0/32
833  *   unicast-ip4-chain
834  *   [@0]: dpo-load-balance: [index:13 buckets:1 uRPF:12 to:[0:0]]
835  *     [0] [@0]: dpo-drop ip6
836  * 172.16.1.0/24
837  *   unicast-ip4-chain
838  *   [@0]: dpo-load-balance: [index:17 buckets:1 uRPF:16 to:[0:0]]
839  *     [0] [@4]: ipv4-glean: af_packet0
840  * 172.16.1.1/32
841  *   unicast-ip4-chain
842  *   [@0]: dpo-load-balance: [index:18 buckets:1 uRPF:17 to:[1:84]]
843  *     [0] [@2]: dpo-receive: 172.16.1.1 on af_packet0
844  * 172.16.1.2/32
845  *   unicast-ip4-chain
846  *   [@0]: dpo-load-balance: [index:21 buckets:1 uRPF:20 to:[0:0]]
847  *     [0] [@5]: ipv4 via 172.16.1.2 af_packet0: IP4: 02:fe:9e:70:7a:2b -> 26:a5:f6:9c:3a:36
848  * 172.16.2.0/24
849  *   unicast-ip4-chain
850  *   [@0]: dpo-load-balance: [index:19 buckets:1 uRPF:18 to:[0:0]]
851  *     [0] [@4]: ipv4-glean: af_packet1
852  * 172.16.2.1/32
853  *   unicast-ip4-chain
854  *   [@0]: dpo-load-balance: [index:20 buckets:1 uRPF:19 to:[0:0]]
855  *     [0] [@2]: dpo-receive: 172.16.2.1 on af_packet1
856  * 224.0.0.0/8
857  *   unicast-ip4-chain
858  *   [@0]: dpo-load-balance: [index:15 buckets:1 uRPF:14 to:[0:0]]
859  *     [0] [@0]: dpo-drop ip6
860  * 240.0.0.0/8
861  *   unicast-ip4-chain
862  *   [@0]: dpo-load-balance: [index:14 buckets:1 uRPF:13 to:[0:0]]
863  *     [0] [@0]: dpo-drop ip6
864  * 255.255.255.255/32
865  *   unicast-ip4-chain
866  *   [@0]: dpo-load-balance: [index:16 buckets:1 uRPF:15 to:[0:0]]
867  *     [0] [@0]: dpo-drop ip6
868  * @cliexend
869  * Example of how to display a summary of all IPv4 FIB tables:
870  * @cliexstart{show ip fib summary}
871  * ipv4-VRF:0, fib_index 0, flow hash: src dst sport dport proto
872  *     Prefix length         Count
873  *                    0               1
874  *                    8               2
875  *                   32               4
876  * ipv4-VRF:7, fib_index 1, flow hash: src dst sport dport proto
877  *     Prefix length         Count
878  *                    0               1
879  *                    8               2
880  *                   24               2
881  *                   32               4
882  * @cliexend
883  ?*/
884 /* *INDENT-OFF* */
885 VLIB_CLI_COMMAND (ip4_show_fib_command, static) = {
886     .path = "show ip fib",
887     .short_help = "show ip fib [summary] [table <table-id>] [index <fib-id>] [<ip4-addr>[/<mask>]] [mtrie] [detail]",
888     .function = ip4_show_fib,
889 };
890 /* *INDENT-ON* */