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