FD.io VPP  v20.05-21-gb1500e9ff
Vector Packet Processing
ip4_fib.c
Go to the documentation of this file.
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  */
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
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 
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;
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 
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
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 
178  &prefix,
179  ip4_specials[ii].ift_source);
180  }
181 
182  /*
183  * validate no more routes.
184  */
185 #ifdef CLIB_DEBUG
186  if (0 != fib_table->ft_total_route_counts)
187  fib_table_assert_empty(fib_table);
188 #endif
189 
190  vec_foreach(n_locks, fib_table->ft_src_route_counts)
191  {
192  ASSERT(0 == *n_locks);
193  }
194 
195  if (~0 != fib_table->ft_table_id)
196  {
198  }
199 
200  vec_free(fib_table->ft_src_route_counts);
201  ip4_mtrie_free(&v4_fib->mtrie);
202 
203  pool_put(ip4_main.v4_fibs, v4_fib);
204  pool_put(ip4_main.fibs, fib_table);
205 }
206 
207 
208 u32
211 {
212  u32 index;
213 
214  index = ip4_fib_index_from_table_id(table_id);
215  if (~0 == index)
216  return ip4_create_fib_with_table_id(table_id, src);
217 
218  fib_table_lock(index, FIB_PROTOCOL_IP4, src);
219 
220  return (index);
221 }
222 
223 u32
225 {
226  return (ip4_create_fib_with_table_id(~0, src));
227 }
228 
229 u32
231 {
232  if (sw_if_index >= vec_len(ip4_main.fib_index_by_sw_if_index))
233  {
234  /*
235  * This is the case for interfaces that are not yet mapped to
236  * a IP table
237  */
238  return (~0);
239  }
240  return (ip4_main.fib_index_by_sw_if_index[sw_if_index]);
241 }
242 
243 /*
244  * ip4_fib_table_lookup_exact_match
245  *
246  * Exact match prefix lookup
247  */
250  const ip4_address_t *addr,
251  u32 len)
252 {
253  uword * hash, * result;
254  u32 key;
255 
256  hash = fib->fib_entry_by_dst_address[len];
257  key = (addr->data_u32 & ip4_main.fib_masks[len]);
258 
259  result = hash_get(hash, key);
260 
261  if (NULL != result) {
262  return (result[0]);
263  }
264  return (FIB_NODE_INDEX_INVALID);
265 }
266 
267 /*
268  * ip4_fib_table_lookup_adj
269  *
270  * Longest prefix match
271  */
272 index_t
274  const ip4_address_t *addr)
275 {
276  fib_node_index_t fei;
277 
278  fei = ip4_fib_table_lookup(fib, addr, 32);
279 
280  if (FIB_NODE_INDEX_INVALID != fei)
281  {
282  const dpo_id_t *dpo;
283 
285 
286  return (dpo->dpoi_index);
287  }
288  return (INDEX_INVALID);
289 }
290 
291 /*
292  * ip4_fib_table_lookup
293  *
294  * Longest prefix match
295  */
298  const ip4_address_t *addr,
299  u32 len)
300 {
301  uword * hash, * result;
302  i32 mask_len;
303  u32 key;
304 
305  for (mask_len = len; mask_len >= 0; mask_len--)
306  {
307  hash = fib->fib_entry_by_dst_address[mask_len];
308  key = (addr->data_u32 & ip4_main.fib_masks[mask_len]);
309 
310  result = hash_get (hash, key);
311 
312  if (NULL != result) {
313  return (result[0]);
314  }
315  }
316  return (FIB_NODE_INDEX_INVALID);
317 }
318 
319 void
321  const ip4_address_t *addr,
322  u32 len,
323  fib_node_index_t fib_entry_index)
324 {
325  uword * hash, * result;
326  u32 key;
327 
328  key = (addr->data_u32 & ip4_main.fib_masks[len]);
329  hash = fib->fib_entry_by_dst_address[len];
330  result = hash_get (hash, key);
331 
332  if (NULL == result) {
333  /*
334  * adding a new entry
335  */
336  uword *old_heap;
338 
339  if (NULL == hash) {
340  hash = hash_create (32 /* elts */, sizeof (uword));
342 
343  }
344  hash = hash_set(hash, key, fib_entry_index);
345  fib->fib_entry_by_dst_address[len] = hash;
346  clib_mem_set_heap (old_heap);
347  }
348  else
349  {
350  ASSERT(0);
351  }
352 }
353 
354 void
356  const ip4_address_t *addr,
357  u32 len)
358 {
359  uword * hash, * result;
360  u32 key;
361 
362  key = (addr->data_u32 & ip4_main.fib_masks[len]);
363  hash = fib->fib_entry_by_dst_address[len];
364  result = hash_get (hash, key);
365 
366  if (NULL == result)
367  {
368  /*
369  * removing a non-existent entry. i'll allow it.
370  */
371  }
372  else
373  {
374  uword *old_heap;
375 
377  hash_unset(hash, key);
378  clib_mem_set_heap (old_heap);
379  }
380 
381  fib->fib_entry_by_dst_address[len] = hash;
382 }
383 
384 void
386  const ip4_address_t *addr,
387  u32 len,
388  const dpo_id_t *dpo)
389 {
390  ip4_fib_mtrie_route_add(&fib->mtrie, addr, len, dpo->dpoi_index);
391 }
392 
393 void
395  const ip4_address_t *addr,
396  u32 len,
397  const dpo_id_t *dpo,
398  u32 cover_index)
399 {
400  const fib_prefix_t *cover_prefix;
401  const dpo_id_t *cover_dpo;
402 
403  /*
404  * We need to pass the MTRIE the LB index and address length of the
405  * covering prefix, so it can fill the plys with the correct replacement
406  * for the entry being removed
407  */
408  cover_prefix = fib_entry_get_prefix(cover_index);
409  cover_dpo = fib_entry_contribute_ip_forwarding(cover_index);
410 
412  addr, len, dpo->dpoi_index,
413  cover_prefix->fp_len,
414  cover_dpo->dpoi_index);
415 }
416 
417 void
420  void *ctx)
421 {
422  fib_prefix_t root = {
424  // address and length default to all 0
425  };
426 
427  /*
428  * A full tree walk is the dengenerate case of a sub-tree from
429  * the very root
430  */
431  return (ip4_fib_table_sub_tree_walk(fib, &root, fn, ctx));
432 }
433 
434 void
436  const fib_prefix_t *root,
438  void *ctx)
439 {
440  fib_prefix_t *sub_trees = NULL;
441  int i;
442 
443  /*
444  * There is no efficient way to walk this array of hash tables.
445  * so we walk each table with a mask length greater than and equal to
446  * the required root and check it is covered by the root.
447  */
448  for (i = root->fp_len;
450  i++)
451  {
452  uword * hash = fib->fib_entry_by_dst_address[i];
453 
454  if (NULL != hash)
455  {
457  hash_pair_t * p;
458 
459  hash_foreach_pair (p, hash,
460  ({
461  key.as_u32 = p->key;
463  &key,
464  &root->fp_addr.ip4,
465  root->fp_len))
466  {
467  const fib_prefix_t *sub_tree;
468  int skip = 0;
469 
470  /*
471  * exclude sub-trees the walk does not want to explore
472  */
473  vec_foreach(sub_tree, sub_trees)
474  {
475  if (ip4_destination_matches_route(&ip4_main,
476  &key,
477  &sub_tree->fp_addr.ip4,
478  sub_tree->fp_len))
479  {
480  skip = 1;
481  break;
482  }
483  }
484 
485  if (!skip)
486  {
487  switch (fn(p->value[0], ctx))
488  {
489  case FIB_TABLE_WALK_CONTINUE:
490  break;
491  case FIB_TABLE_WALK_SUB_TREE_STOP: {
492  fib_prefix_t pfx = {
493  .fp_proto = FIB_PROTOCOL_IP4,
494  .fp_len = i,
495  .fp_addr.ip4 = key,
496  };
497  vec_add1(sub_trees, pfx);
498  break;
499  }
500  case FIB_TABLE_WALK_STOP:
501  goto done;
502  }
503  }
504  }
505  }));
506  }
507  }
508 done:
509  vec_free(sub_trees);
510  return;
511 }
512 
513 /**
514  * Walk show context
515  */
517 {
520 
521 static fib_table_walk_rc_t
523  void *arg)
524 {
526 
527  vec_add1(ctx->ifsw_indicies, fib_entry_index);
528 
529  return (FIB_TABLE_WALK_CONTINUE);
530 }
531 
532 static void
534  vlib_main_t * vm)
535 {
537  .ifsw_indicies = NULL,
538  };
539  fib_node_index_t *fib_entry_index;
540 
544 
545  vec_foreach(fib_entry_index, ctx.ifsw_indicies)
546  {
547  vlib_cli_output(vm, "%U",
549  *fib_entry_index,
551  }
552 
553  vec_free(ctx.ifsw_indicies);
554 }
555 
556 static void
558  vlib_main_t * vm,
560  u32 mask_len,
561  int detail)
562 {
563  vlib_cli_output(vm, "%U",
565  ip4_fib_table_lookup(fib, address, mask_len),
566  (detail ?
569 }
570 
571 u8 *
572 format_ip4_fib_table_memory (u8 * s, va_list * args)
573 {
574  s = format(s, "%=30s %=6d %=12ld\n",
575  "IPv4 unicast",
578  return (s);
579 }
580 
581 static clib_error_t *
583  unformat_input_t * input,
584  vlib_cli_command_t * cmd)
585 {
586  ip4_main_t * im4 = &ip4_main;
587  fib_table_t * fib_table;
588  u64 total_mtrie_memory, total_hash_memory;
589  int verbose, matching, mtrie, memory;
590  ip4_address_t matching_address;
591  u32 matching_mask = 32;
592  int i, table_id = -1, fib_index = ~0;
593  int detail = 0;
594 
595  verbose = 1;
596  matching = mtrie = memory = 0;
597  total_hash_memory = total_mtrie_memory = 0;
598 
600  {
601  if (unformat (input, "brief") || unformat (input, "summary")
602  || unformat (input, "sum"))
603  verbose = 0;
604 
605  else if (unformat (input, "detail") || unformat (input, "det"))
606  detail = 1;
607 
608  else if (unformat (input, "mtrie"))
609  mtrie = 1;
610 
611  else if (unformat (input, "mem") ||
612  unformat (input, "memory"))
613  memory = 1;
614 
615  else if (unformat (input, "%U/%d",
616  unformat_ip4_address, &matching_address, &matching_mask))
617  matching = 1;
618 
619  else if (unformat (input, "%U", unformat_ip4_address, &matching_address))
620  matching = 1;
621 
622  else if (unformat (input, "table %d", &table_id))
623  ;
624  else if (unformat (input, "index %d", &fib_index))
625  ;
626  else
627  break;
628  }
629 
630  pool_foreach (fib_table, im4->fibs,
631  ({
632  ip4_fib_t *fib = pool_elt_at_index(im4->v4_fibs, fib_table->ft_index);
633  fib_source_t source;
634  u8 *s = NULL;
635 
636  if (table_id >= 0 && table_id != (int)fib->table_id)
637  continue;
638  if (fib_index != ~0 && fib_index != (int)fib->index)
639  continue;
640 
641  if (memory)
642  {
643  uword mtrie_size, hash_size, *old_heap;
644 
645 
646  mtrie_size = ip4_fib_mtrie_memory_usage(&fib->mtrie);
647  hash_size = 0;
648 
649  old_heap = clib_mem_set_heap (ip4_main.mtrie_mheap);
650  for (i = 0; i < ARRAY_LEN (fib->fib_entry_by_dst_address); i++)
651  {
652  uword * hash = fib->fib_entry_by_dst_address[i];
653  if (NULL != hash)
654  {
655  hash_size += hash_bytes(hash);
656  }
657  }
658  clib_mem_set_heap (old_heap);
659 
660  if (verbose)
661  vlib_cli_output (vm, "%U mtrie:%d hash:%d",
662  format_fib_table_name, fib->index,
663  FIB_PROTOCOL_IP4,
664  mtrie_size,
665  hash_size);
666  total_mtrie_memory += mtrie_size;
667  total_hash_memory += hash_size;
668  continue;
669  }
670 
671  s = format(s, "%U, fib_index:%d, flow hash:[%U] epoch:%d flags:%U locks:[",
672  format_fib_table_name, fib->index,
674  fib->index,
676  fib_table->ft_flow_hash_config,
677  fib_table->ft_epoch,
678  format_fib_table_flags, fib_table->ft_flags);
679  vec_foreach_index(source, fib_table->ft_locks)
680  {
681  if (0 != fib_table->ft_locks[source])
682  {
683  s = format(s, "%U:%d, ",
684  format_fib_source, source,
685  fib_table->ft_locks[source]);
686  }
687  }
688  s = format (s, "]");
689  vlib_cli_output (vm, "%v", s);
690  vec_free(s);
691 
692  /* Show summary? */
693  if (mtrie)
694  {
695  vlib_cli_output (vm, "%U", format_ip4_fib_mtrie, &fib->mtrie, verbose);
696  continue;
697  }
698  if (! verbose)
699  {
700  vlib_cli_output (vm, "%=20s%=16s", "Prefix length", "Count");
701  for (i = 0; i < ARRAY_LEN (fib->fib_entry_by_dst_address); i++)
702  {
703  uword * hash = fib->fib_entry_by_dst_address[i];
704  uword n_elts = hash_elts (hash);
705  if (n_elts > 0)
706  vlib_cli_output (vm, "%20d%16d", i, n_elts);
707  }
708  continue;
709  }
710 
711  if (!matching)
712  {
714  }
715  else
716  {
717  ip4_fib_table_show_one(fib, vm, &matching_address,
718  matching_mask, detail);
719  }
720  }));
721 
722  if (memory)
723  {
724  vlib_cli_output (vm, "totals: mtrie:%ld hash:%ld all:%ld",
725  total_mtrie_memory,
726  total_hash_memory,
727  total_mtrie_memory + total_hash_memory);
728  vlib_cli_output (vm, "\nMtrie Mheap Usage: %U\n",
730  }
731  return 0;
732 }
733 
734 /*?
735  * This command displays the IPv4 FIB Tables (VRF Tables) and the route
736  * entries for each table.
737  *
738  * @note This command will run for a long time when the FIB tables are
739  * comprised of millions of entries. For those senarios, consider displaying
740  * a single table or summary mode.
741  *
742  * @cliexpar
743  * Example of how to display all the IPv4 FIB tables:
744  * @cliexstart{show ip fib}
745  * ipv4-VRF:0, fib_index 0, flow hash: src dst sport dport proto
746  * 0.0.0.0/0
747  * unicast-ip4-chain
748  * [@0]: dpo-load-balance: [index:0 buckets:1 uRPF:0 to:[0:0]]
749  * [0] [@0]: dpo-drop ip6
750  * 0.0.0.0/32
751  * unicast-ip4-chain
752  * [@0]: dpo-load-balance: [index:1 buckets:1 uRPF:1 to:[0:0]]
753  * [0] [@0]: dpo-drop ip6
754  * 6.0.1.2/32
755  * unicast-ip4-chain
756  * [@0]: dpo-load-balance: [index:30 buckets:1 uRPF:29 to:[0:0]]
757  * [0] [@3]: arp-ipv4: via 6.0.0.1 af_packet0
758  * 7.0.0.1/32
759  * unicast-ip4-chain
760  * [@0]: dpo-load-balance: [index:31 buckets:4 uRPF:30 to:[0:0]]
761  * [0] [@3]: arp-ipv4: via 6.0.0.2 af_packet0
762  * [1] [@3]: arp-ipv4: via 6.0.0.2 af_packet0
763  * [2] [@3]: arp-ipv4: via 6.0.0.2 af_packet0
764  * [3] [@3]: arp-ipv4: via 6.0.0.1 af_packet0
765  * 224.0.0.0/8
766  * unicast-ip4-chain
767  * [@0]: dpo-load-balance: [index:3 buckets:1 uRPF:3 to:[0:0]]
768  * [0] [@0]: dpo-drop ip6
769  * 240.0.0.0/8
770  * unicast-ip4-chain
771  * [@0]: dpo-load-balance: [index:2 buckets:1 uRPF:2 to:[0:0]]
772  * [0] [@0]: dpo-drop ip6
773  * 255.255.255.255/32
774  * unicast-ip4-chain
775  * [@0]: dpo-load-balance: [index:4 buckets:1 uRPF:4 to:[0:0]]
776  * [0] [@0]: dpo-drop ip6
777  * ipv4-VRF:7, fib_index 1, flow hash: src dst sport dport proto
778  * 0.0.0.0/0
779  * unicast-ip4-chain
780  * [@0]: dpo-load-balance: [index:12 buckets:1 uRPF:11 to:[0:0]]
781  * [0] [@0]: dpo-drop ip6
782  * 0.0.0.0/32
783  * unicast-ip4-chain
784  * [@0]: dpo-load-balance: [index:13 buckets:1 uRPF:12 to:[0:0]]
785  * [0] [@0]: dpo-drop ip6
786  * 172.16.1.0/24
787  * unicast-ip4-chain
788  * [@0]: dpo-load-balance: [index:17 buckets:1 uRPF:16 to:[0:0]]
789  * [0] [@4]: ipv4-glean: af_packet0
790  * 172.16.1.1/32
791  * unicast-ip4-chain
792  * [@0]: dpo-load-balance: [index:18 buckets:1 uRPF:17 to:[1:84]]
793  * [0] [@2]: dpo-receive: 172.16.1.1 on af_packet0
794  * 172.16.1.2/32
795  * unicast-ip4-chain
796  * [@0]: dpo-load-balance: [index:21 buckets:1 uRPF:20 to:[0:0]]
797  * [0] [@5]: ipv4 via 172.16.1.2 af_packet0: IP4: 02:fe:9e:70:7a:2b -> 26:a5:f6:9c:3a:36
798  * 172.16.2.0/24
799  * unicast-ip4-chain
800  * [@0]: dpo-load-balance: [index:19 buckets:1 uRPF:18 to:[0:0]]
801  * [0] [@4]: ipv4-glean: af_packet1
802  * 172.16.2.1/32
803  * unicast-ip4-chain
804  * [@0]: dpo-load-balance: [index:20 buckets:1 uRPF:19 to:[0:0]]
805  * [0] [@2]: dpo-receive: 172.16.2.1 on af_packet1
806  * 224.0.0.0/8
807  * unicast-ip4-chain
808  * [@0]: dpo-load-balance: [index:15 buckets:1 uRPF:14 to:[0:0]]
809  * [0] [@0]: dpo-drop ip6
810  * 240.0.0.0/8
811  * unicast-ip4-chain
812  * [@0]: dpo-load-balance: [index:14 buckets:1 uRPF:13 to:[0:0]]
813  * [0] [@0]: dpo-drop ip6
814  * 255.255.255.255/32
815  * unicast-ip4-chain
816  * [@0]: dpo-load-balance: [index:16 buckets:1 uRPF:15 to:[0:0]]
817  * [0] [@0]: dpo-drop ip6
818  * @cliexend
819  * Example of how to display a single IPv4 FIB table:
820  * @cliexstart{show ip fib table 7}
821  * ipv4-VRF:7, fib_index 1, flow hash: src dst sport dport proto
822  * 0.0.0.0/0
823  * unicast-ip4-chain
824  * [@0]: dpo-load-balance: [index:12 buckets:1 uRPF:11 to:[0:0]]
825  * [0] [@0]: dpo-drop ip6
826  * 0.0.0.0/32
827  * unicast-ip4-chain
828  * [@0]: dpo-load-balance: [index:13 buckets:1 uRPF:12 to:[0:0]]
829  * [0] [@0]: dpo-drop ip6
830  * 172.16.1.0/24
831  * unicast-ip4-chain
832  * [@0]: dpo-load-balance: [index:17 buckets:1 uRPF:16 to:[0:0]]
833  * [0] [@4]: ipv4-glean: af_packet0
834  * 172.16.1.1/32
835  * unicast-ip4-chain
836  * [@0]: dpo-load-balance: [index:18 buckets:1 uRPF:17 to:[1:84]]
837  * [0] [@2]: dpo-receive: 172.16.1.1 on af_packet0
838  * 172.16.1.2/32
839  * unicast-ip4-chain
840  * [@0]: dpo-load-balance: [index:21 buckets:1 uRPF:20 to:[0:0]]
841  * [0] [@5]: ipv4 via 172.16.1.2 af_packet0: IP4: 02:fe:9e:70:7a:2b -> 26:a5:f6:9c:3a:36
842  * 172.16.2.0/24
843  * unicast-ip4-chain
844  * [@0]: dpo-load-balance: [index:19 buckets:1 uRPF:18 to:[0:0]]
845  * [0] [@4]: ipv4-glean: af_packet1
846  * 172.16.2.1/32
847  * unicast-ip4-chain
848  * [@0]: dpo-load-balance: [index:20 buckets:1 uRPF:19 to:[0:0]]
849  * [0] [@2]: dpo-receive: 172.16.2.1 on af_packet1
850  * 224.0.0.0/8
851  * unicast-ip4-chain
852  * [@0]: dpo-load-balance: [index:15 buckets:1 uRPF:14 to:[0:0]]
853  * [0] [@0]: dpo-drop ip6
854  * 240.0.0.0/8
855  * unicast-ip4-chain
856  * [@0]: dpo-load-balance: [index:14 buckets:1 uRPF:13 to:[0:0]]
857  * [0] [@0]: dpo-drop ip6
858  * 255.255.255.255/32
859  * unicast-ip4-chain
860  * [@0]: dpo-load-balance: [index:16 buckets:1 uRPF:15 to:[0:0]]
861  * [0] [@0]: dpo-drop ip6
862  * @cliexend
863  * Example of how to display a summary of all IPv4 FIB tables:
864  * @cliexstart{show ip fib summary}
865  * ipv4-VRF:0, fib_index 0, flow hash: src dst sport dport proto
866  * Prefix length Count
867  * 0 1
868  * 8 2
869  * 32 4
870  * ipv4-VRF:7, fib_index 1, flow hash: src dst sport dport proto
871  * Prefix length Count
872  * 0 1
873  * 8 2
874  * 24 2
875  * 32 4
876  * @cliexend
877  ?*/
878 /* *INDENT-OFF* */
879 VLIB_CLI_COMMAND (ip4_show_fib_command, static) = {
880  .path = "show ip fib",
881  .short_help = "show ip fib [summary] [table <table-id>] [index <fib-id>] [<ip4-addr>[/<mask>]] [mtrie] [detail]",
882  .function = ip4_show_fib,
883 };
884 /* *INDENT-ON* */
fib_protocol_t fp_proto
protocol type
Definition: fib_types.h:212
u8 * format_fib_entry(u8 *s, va_list *args)
Definition: fib_entry.c:130
enum fib_source_t_ fib_source_t
The different sources that can create a route.
#define vec_foreach_index(var, v)
Iterate over vector indices.
Continue on to the next entry.
Definition: fib_table.h:916
static void ip4_fib_table_show_one(ip4_fib_t *fib, vlib_main_t *vm, ip4_address_t *address, u32 mask_len, int detail)
Definition: ip4_fib.c:557
#define hash_set(h, key, value)
Definition: hash.h:255
vhost_user_memory_t memory
Definition: vhost_user.h:255
fib_protocol_t ft_proto
Which protocol this table serves.
Definition: fib_table.h:76
void ip4_fib_table_fwding_dpo_remove(ip4_fib_t *fib, const ip4_address_t *addr, u32 len, const dpo_id_t *dpo, u32 cover_index)
Definition: ip4_fib.c:394
#define hash_unset(h, key)
Definition: hash.h:261
#define FIB_ENTRY_FORMAT_DETAIL
Definition: fib_entry.h:360
unsigned long u64
Definition: types.h:89
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
const dpo_id_t * fib_entry_contribute_ip_forwarding(fib_node_index_t fib_entry_index)
Definition: fib_entry.c:506
u32 index_t
A Data-Path Object is an object that represents actions that are applied to packets are they are swit...
Definition: dpo.h:41
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
Definition: vec.h:590
void ip4_fib_table_destroy(u32 fib_index)
Definition: ip4_fib.c:159
vl_api_address_t src
Definition: gre.api:54
static clib_error_t * ip4_show_fib(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: ip4_fib.c:582
static uword ip4_destination_matches_route(const ip4_main_t *im, const ip4_address_t *key, const ip4_address_t *dest, uword dest_length)
Definition: ip4.h:197
const fib_prefix_t * fib_entry_get_prefix(fib_node_index_t fib_entry_index)
Definition: fib_entry.c:1691
u32 * fib_index_by_sw_if_index
Table index indexed by software interface.
Definition: ip4.h:122
u8 * format(u8 *s, const char *fmt,...)
Definition: format.c:424
vl_api_prefix_t prefix
Definition: ip.api:144
#define pool_get(P, E)
Allocate an object E from a pool P (unspecified alignment).
Definition: pool.h:252
u32 ip4_fib_table_find_or_create_and_lock(u32 table_id, fib_source_t src)
Get or create an IPv4 fib.
Definition: ip4_fib.c:209
vhost_vring_addr_t addr
Definition: vhost_user.h:254
unsigned char u8
Definition: types.h:56
static void ip4_fib_table_show_all(ip4_fib_t *fib, vlib_main_t *vm)
Definition: ip4_fib.c:533
uword value[0]
Definition: hash.h:165
u32 ip4_fib_table_create_and_lock(fib_source_t src)
Definition: ip4_fib.c:224
fib_entry_flag_t ift_flag
Definition: ip4_fib.c:26
u32 ip4_fib_table_get_index_for_sw_if_index(u32 sw_if_index)
Definition: ip4_fib.c:230
#define pool_foreach(VAR, POOL, BODY)
Iterate through pool.
Definition: pool.h:513
unformat_function_t unformat_ip4_address
Definition: format.h:68
vl_api_interface_index_t sw_if_index
Definition: gre.api:53
u32 ft_epoch
Epoch - number of resyncs performed.
Definition: fib_table.h:117
u32 table_id
Definition: ip4_fib.h:54
void fib_table_entry_special_remove(u32 fib_index, const fib_prefix_t *prefix, fib_source_t source)
Remove a &#39;special&#39; entry from the FIB.
Definition: fib_table.c:424
u32 index
Definition: ip4_fib.h:57
void ip4_mtrie_free(ip4_fib_mtrie_t *m)
Free an mtrie, It must be emty when free&#39;d.
Definition: ip4_mtrie.c:199
Aggregate type for a prefix.
Definition: fib_types.h:203
void ip4_fib_table_sub_tree_walk(ip4_fib_t *fib, const fib_prefix_t *root, fib_table_walk_fn_t fn, void *ctx)
Walk all entries in a sub-tree of the FIB table N.B: This is NOT safe to deletes. ...
Definition: ip4_fib.c:435
unsigned int u32
Definition: types.h:88
static void hash_set_flags(void *v, uword flags)
Definition: hash.h:153
u16 fp_len
The mask length.
Definition: fib_types.h:207
void ip4_fib_table_entry_remove(ip4_fib_t *fib, const ip4_address_t *addr, u32 len)
Definition: ip4_fib.c:355
int fib_entry_cmp_for_sort(void *i1, void *i2)
Definition: fib_entry.c:1623
u32 * ft_locks
per-source number of locks on the table
Definition: fib_table.h:86
u8 * format_mheap(u8 *s, va_list *va)
Definition: mem_dlmalloc.c:388
void ip4_mtrie_init(ip4_fib_mtrie_t *m)
Initialise an mtrie.
Definition: ip4_mtrie.c:215
The identity of a DPO is a combination of its type and its instance number/index of objects of that t...
Definition: dpo.h:170
#define hash_get(h, key)
Definition: hash.h:249
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
Definition: pool.h:534
uword * fib_index_by_table_id
Hash table mapping table id to fib index.
Definition: ip4.h:132
ip46_address_t fp_addr
The address type is not deriveable from the fp_addr member.
Definition: fib_types.h:226
u8 * format_fib_table_flags(u8 *s, va_list *args)
Definition: fib_table.c:1348
long ctx[MAX_CONNS]
Definition: main.c:144
struct _unformat_input_t unformat_input_t
#define pool_put(P, E)
Free an object E in pool P.
Definition: pool.h:302
u32 ft_total_route_counts
Total route counters.
Definition: fib_table.h:112
void * mtrie_mheap
The memory heap for the mtries.
Definition: ip4.h:171
void ip4_fib_table_fwding_dpo_update(ip4_fib_t *fib, const ip4_address_t *addr, u32 len, const dpo_id_t *dpo)
Definition: ip4_fib.c:385
vlib_main_t * vm
Definition: in2out_ed.c:1599
ip4_fib_mtrie_t mtrie
Mtrie for fast lookups.
Definition: ip4_fib.h:48
Stop the walk completely.
Definition: fib_table.h:924
u8 len
Definition: ip_types.api:92
#define pool_get_aligned(P, E, A)
Allocate an object E from a pool P with alignment A.
Definition: pool.h:246
fib_node_index_t ip4_fib_table_lookup(const ip4_fib_t *fib, const ip4_address_t *addr, u32 len)
Definition: ip4_fib.c:297
fib_node_index_t fib_table_entry_special_add(u32 fib_index, const fib_prefix_t *prefix, fib_source_t source, fib_entry_flag_t flags)
Add a &#39;special&#39; entry to the FIB.
Definition: fib_table.c:405
void ip4_fib_table_entry_insert(ip4_fib_t *fib, const ip4_address_t *addr, u32 len, fib_node_index_t fib_entry_index)
Definition: ip4_fib.c:320
The IPv4 FIB.
Definition: ip4_fib.h:39
fib_node_index_t ft_index
Index into FIB vector.
Definition: fib_table.h:97
#define UNFORMAT_END_OF_INPUT
Definition: format.h:145
u32 ft_table_id
Table ID (hash key) for this FIB.
Definition: fib_table.h:92
u32 ft_flow_hash_config
flow hash configuration
Definition: fib_table.h:102
sll srl srl sll sra u16x4 i
Definition: vector_sse42.h:317
enum fib_table_walk_rc_t_ fib_table_walk_rc_t
return code controlling how a table walk proceeds
#define vec_free(V)
Free vector&#39;s memory (no header).
Definition: vec.h:380
fib_node_index_t * ifsw_indicies
Definition: ip4_fib.c:518
static void * clib_mem_set_heap(void *heap)
Definition: mem.h:268
fib_table_flags_t ft_flags
Table flags.
Definition: fib_table.h:81
Definition: fib_entry.h:115
u32 fib_node_index_t
A typedef of a node index.
Definition: fib_types.h:30
static u32 ip4_fib_index_from_table_id(u32 table_id)
Definition: ip4_fib.h:145
#define ARRAY_LEN(x)
Definition: clib.h:66
void ip4_fib_table_walk(ip4_fib_t *fib, fib_table_walk_fn_t fn, void *ctx)
Walk all entries in a FIB table N.B: This is NOT safe to deletes.
Definition: ip4_fib.c:418
fib_table_walk_rc_t(* fib_table_walk_fn_t)(fib_node_index_t fei, void *ctx)
Call back function when walking entries in a FIB table.
Definition: fib_table.h:930
enum fib_entry_flag_t_ fib_entry_flag_t
void fib_table_lock(u32 fib_index, fib_protocol_t proto, fib_source_t source)
Release a reference counting lock on the table.
Definition: fib_table.c:1310
#define VLIB_CLI_COMMAND(x,...)
Definition: cli.h:152
signed int i32
Definition: types.h:77
#define hash_create(elts, value_bytes)
Definition: hash.h:696
static uword hash_elts(void *v)
Definition: hash.h:118
#define ASSERT(truth)
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
Definition: cli.c:689
manual_print typedef address
Definition: ip_types.api:85
IPv4 main type.
Definition: ip4.h:106
Walk show context.
Definition: ip4_fib.c:516
#define IP_FLOW_HASH_DEFAULT
Default: 5-tuple without the "reverse" bit.
Definition: lookup.h:70
u8 * format_ip4_fib_table_memory(u8 *s, va_list *args)
Definition: ip4_fib.c:572
typedef key
Definition: ipsec_types.api:85
#define FIB_ENTRY_FORMAT_BRIEF
Definition: fib_entry.h:359
format_function_t format_ip4_fib_mtrie
Format/display the contents of the mtrie.
Definition: ip4_mtrie.h:172
index_t dpoi_index
the index of objects of that type
Definition: dpo.h:186
#define FIB_NODE_INDEX_INVALID
Definition: fib_types.h:31
struct ip4_fib_t_ * v4_fibs
Vector of MTries.
Definition: ip4.h:114
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
#define hash_foreach_pair(p, v, body)
Iterate over hash pairs.
Definition: hash.h:373
#define INDEX_INVALID
Invalid index - used when no index is known blazoned capitals INVALID speak volumes where ~0 does not...
Definition: dpo.h:47
void ip4_fib_mtrie_route_add(ip4_fib_mtrie_t *m, const ip4_address_t *dst_address, u32 dst_address_length, u32 adj_index)
Add a route/entry to the mtrie.
Definition: ip4_mtrie.c:624
u64 uword
Definition: types.h:112
#define vec_sort_with_function(vec, f)
Sort a vector using the supplied element comparison function.
Definition: vec.h:1053
The default route source.
Definition: fib_source.h:131
uword * fib_entry_by_dst_address[33]
Definition: ip4_fib.h:51
u32 * ft_src_route_counts
Per-source route counters.
Definition: fib_table.h:107
struct ip4_fib_table_special_prefix_t_ ip4_fib_table_special_prefix_t
DLMALLOC_EXPORT size_t mspace_footprint(mspace msp)
u8 * format_fib_table_name(u8 *s, va_list *ap)
Format the description/name of the table.
Definition: fib_table.c:1334
ip4_main_t ip4_main
Global ip4 main structure.
Definition: ip4_forward.c:1144
struct fib_table_t_ * fibs
Vector of FIBs.
Definition: ip4.h:111
#define FIB_ENTRY_FORMAT_DETAIL2
Definition: fib_entry.h:361
#define vec_foreach(var, vec)
Vector iterator.
Special sources.
Definition: fib_source.h:42
index_t ip4_fib_table_lookup_lb(ip4_fib_t *fib, const ip4_address_t *addr)
Definition: ip4_fib.c:273
void ip4_fib_mtrie_route_del(ip4_fib_mtrie_t *m, const ip4_address_t *dst_address, u32 dst_address_length, u32 adj_index, u32 cover_address_length, u32 cover_adj_index)
remove a route/entry to the mtrie
Definition: ip4_mtrie.c:641
void fib_table_assert_empty(const fib_table_t *fib_table)
Debug function.
Definition: fib_entry.c:1718
u8 * format_ip_flow_hash_config(u8 *s, va_list *args)
Definition: lookup.c:119
u32 table_id
Definition: fib_types.api:118
#define CLIB_CACHE_LINE_BYTES
Definition: cache.h:59
static fib_table_walk_rc_t ip4_fib_show_walk_cb(fib_node_index_t fib_entry_index, void *arg)
Definition: ip4_fib.c:522
#define HASH_FLAG_NO_AUTO_SHRINK
Definition: hash.h:64
fib_node_index_t ip4_fib_table_lookup_exact_match(const ip4_fib_t *fib, const ip4_address_t *addr, u32 len)
Definition: ip4_fib.c:249
struct ip4_fib_show_walk_ctx_t_ ip4_fib_show_walk_ctx_t
Walk show context.
uword key
Definition: hash.h:162
uword unformat(unformat_input_t *i, const char *fmt,...)
Definition: unformat.c:978
static uword unformat_check_input(unformat_input_t *i)
Definition: format.h:171
A protocol Independent FIB table.
Definition: fib_table.h:71
u32 fib_masks[33]
Definition: ip4.h:119
static u32 ip4_create_fib_with_table_id(u32 table_id, fib_source_t src)
Definition: ip4_fib.c:104
static uword pool_elts(void *v)
Number of active elements in a pool.
Definition: pool.h:128