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