FD.io VPP  v19.01.3-6-g70449b9b9
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 pefixes 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  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 
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);
186  {
187  ASSERT(0 == fib_table->ft_src_route_counts[ii]);
188  }
189 
190  if (~0 != fib_table->ft_table_id)
191  {
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
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
219 {
220  return (ip4_create_fib_with_table_id(~0, src));
221 }
222 
223 u32
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  */
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
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 
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  */
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
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;
332 
333  if (NULL == hash) {
334  hash = hash_create (32 /* elts */, sizeof (uword));
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
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 
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
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
389  const ip4_address_t *addr,
390  u32 len,
391  const dpo_id_t *dpo,
392  u32 cover_index)
393 {
394  const fib_prefix_t *cover_prefix;
395  const dpo_id_t *cover_dpo;
396 
397  /*
398  * We need to pass the MTRIE the LB index and address length of the
399  * covering prefix, so it can fill the plys with the correct replacement
400  * for the entry being removed
401  */
402  cover_prefix = fib_entry_get_prefix(cover_index);
403  cover_dpo = fib_entry_contribute_ip_forwarding(cover_index);
404 
406  addr, len, dpo->dpoi_index,
407  cover_prefix->fp_len,
408  cover_dpo->dpoi_index);
409 }
410 
411 void
414  void *ctx)
415 {
416  fib_prefix_t root = {
418  // address and length default to all 0
419  };
420 
421  /*
422  * A full tree walk is the dengenerate case of a sub-tree from
423  * the very root
424  */
425  return (ip4_fib_table_sub_tree_walk(fib, &root, fn, ctx));
426 }
427 
428 void
430  const fib_prefix_t *root,
432  void *ctx)
433 {
434  fib_prefix_t *sub_trees = NULL;
435  int i;
436 
437  /*
438  * There is no efficent way to walk this array of hash tables.
439  * so we walk each table with a mask length greater than and equal to
440  * the required root and check it is covered by the root.
441  */
442  for (i = root->fp_len;
444  i++)
445  {
446  uword * hash = fib->fib_entry_by_dst_address[i];
447 
448  if (NULL != hash)
449  {
450  ip4_address_t key;
451  hash_pair_t * p;
452 
453  hash_foreach_pair (p, hash,
454  ({
455  key.as_u32 = p->key;
457  &key,
458  &root->fp_addr.ip4,
459  root->fp_len))
460  {
461  const fib_prefix_t *sub_tree;
462  int skip = 0;
463 
464  /*
465  * exclude sub-trees the walk does not want to explore
466  */
467  vec_foreach(sub_tree, sub_trees)
468  {
469  if (ip4_destination_matches_route(&ip4_main,
470  &key,
471  &sub_tree->fp_addr.ip4,
472  sub_tree->fp_len))
473  {
474  skip = 1;
475  break;
476  }
477  }
478 
479  if (!skip)
480  {
481  switch (fn(p->value[0], ctx))
482  {
483  case FIB_TABLE_WALK_CONTINUE:
484  break;
485  case FIB_TABLE_WALK_SUB_TREE_STOP: {
486  fib_prefix_t pfx = {
487  .fp_proto = FIB_PROTOCOL_IP4,
488  .fp_len = i,
489  .fp_addr.ip4 = key,
490  };
491  vec_add1(sub_trees, pfx);
492  break;
493  }
494  case FIB_TABLE_WALK_STOP:
495  goto done;
496  }
497  }
498  }
499  }));
500  }
501  }
502 done:
503  vec_free(sub_trees);
504  return;
505 }
506 
507 /**
508  * Walk show context
509  */
511 {
514 
515 static fib_table_walk_rc_t
517  void *arg)
518 {
520 
521  vec_add1(ctx->ifsw_indicies, fib_entry_index);
522 
523  return (FIB_TABLE_WALK_CONTINUE);
524 }
525 
526 static void
528  vlib_main_t * vm)
529 {
531  .ifsw_indicies = NULL,
532  };
533  fib_node_index_t *fib_entry_index;
534 
538 
539  vec_foreach(fib_entry_index, ctx.ifsw_indicies)
540  {
541  vlib_cli_output(vm, "%U",
543  *fib_entry_index,
545  }
546 
547  vec_free(ctx.ifsw_indicies);
548 }
549 
550 static void
552  vlib_main_t * vm,
554  u32 mask_len,
555  int detail)
556 {
557  vlib_cli_output(vm, "%U",
559  ip4_fib_table_lookup(fib, address, mask_len),
560  (detail ?
563 }
564 
565 u8 *
566 format_ip4_fib_table_memory (u8 * s, va_list * args)
567 {
568 #if USE_DLMALLOC == 0
569  s = format(s, "%=30s %=6d %=8ld\n",
570  "IPv4 unicast",
573 #else
574  s = format(s, "%=30s %=6d %=8ld\n",
575  "IPv4 unicast",
578 #endif
579 
580 
581  return (s);
582 }
583 
584 static clib_error_t *
586  unformat_input_t * input,
587  vlib_cli_command_t * cmd)
588 {
589  ip4_main_t * im4 = &ip4_main;
590  fib_table_t * fib_table;
591  u64 total_mtrie_memory, total_hash_memory;
592  int verbose, matching, mtrie, memory;
593  ip4_address_t matching_address;
594  u32 matching_mask = 32;
595  int i, table_id = -1, fib_index = ~0;
596  int detail = 0;
597 
598  verbose = 1;
599  matching = mtrie = memory = 0;
600  total_hash_memory = total_mtrie_memory = 0;
601 
603  {
604  if (unformat (input, "brief") || unformat (input, "summary")
605  || unformat (input, "sum"))
606  verbose = 0;
607 
608  else if (unformat (input, "detail") || unformat (input, "det"))
609  detail = 1;
610 
611  else if (unformat (input, "mtrie"))
612  mtrie = 1;
613 
614  else if (unformat (input, "mem") ||
615  unformat (input, "memory"))
616  memory = 1;
617 
618  else if (unformat (input, "%U/%d",
619  unformat_ip4_address, &matching_address, &matching_mask))
620  matching = 1;
621 
622  else if (unformat (input, "%U", unformat_ip4_address, &matching_address))
623  matching = 1;
624 
625  else if (unformat (input, "table %d", &table_id))
626  ;
627  else if (unformat (input, "index %d", &fib_index))
628  ;
629  else
630  break;
631  }
632 
633  pool_foreach (fib_table, im4->fibs,
634  ({
635  ip4_fib_t *fib = pool_elt_at_index(im4->v4_fibs, fib_table->ft_index);
636  fib_source_t source;
637  u8 *s = NULL;
638 
639  if (table_id >= 0 && table_id != (int)fib->table_id)
640  continue;
641  if (fib_index != ~0 && fib_index != (int)fib->index)
642  continue;
643 
644  if (memory)
645  {
646  uword mtrie_size, hash_size;
647 
648  mtrie_size = ip4_fib_mtrie_memory_usage(&fib->mtrie);
649  hash_size = 0;
650 
651  for (i = 0; i < ARRAY_LEN (fib->fib_entry_by_dst_address); i++)
652  {
653  uword * hash = fib->fib_entry_by_dst_address[i];
654  if (NULL != hash)
655  {
656  hash_size += hash_bytes(hash);
657  }
658  }
659  if (verbose)
660  vlib_cli_output (vm, "%U mtrie:%d hash:%d",
661  format_fib_table_name, fib->index,
662  FIB_PROTOCOL_IP4,
663  mtrie_size,
664  hash_size);
665  total_mtrie_memory += mtrie_size;
666  total_hash_memory += hash_size;
667  continue;
668  }
669 
670  s = format(s, "%U, fib_index:%d, flow hash:[%U] locks:[",
671  format_fib_table_name, fib->index,
673  fib->index,
675  fib_table->ft_flow_hash_config);
676  FOR_EACH_FIB_SOURCE(source)
677  {
678  if (0 != fib_table->ft_locks[source])
679  {
680  s = format(s, "%U:%d, ",
681  format_fib_source, source,
682  fib_table->ft_locks[source]);
683  }
684  }
685  s = format (s, "]");
686  vlib_cli_output (vm, "%v", s);
687  vec_free(s);
688 
689  /* Show summary? */
690  if (mtrie)
691  {
692  vlib_cli_output (vm, "%U", format_ip4_fib_mtrie, &fib->mtrie, verbose);
693  continue;
694  }
695  if (! verbose)
696  {
697  vlib_cli_output (vm, "%=20s%=16s", "Prefix length", "Count");
698  for (i = 0; i < ARRAY_LEN (fib->fib_entry_by_dst_address); i++)
699  {
700  uword * hash = fib->fib_entry_by_dst_address[i];
701  uword n_elts = hash_elts (hash);
702  if (n_elts > 0)
703  vlib_cli_output (vm, "%20d%16d", i, n_elts);
704  }
705  continue;
706  }
707 
708  if (!matching)
709  {
710  ip4_fib_table_show_all(fib, vm);
711  }
712  else
713  {
714  ip4_fib_table_show_one(fib, vm, &matching_address,
715  matching_mask, detail);
716  }
717  }));
718 
719  if (memory)
720  vlib_cli_output (vm, "totals: mtrie:%ld hash:%ld all:%ld",
721  total_mtrie_memory,
722  total_hash_memory,
723  total_mtrie_memory + total_hash_memory);
724 
725  return 0;
726 }
727 
728 /*?
729  * This command displays the IPv4 FIB Tables (VRF Tables) and the route
730  * entries for each table.
731  *
732  * @note This command will run for a long time when the FIB tables are
733  * comprised of millions of entries. For those senarios, consider displaying
734  * a single table or summary mode.
735  *
736  * @cliexpar
737  * Example of how to display all the IPv4 FIB tables:
738  * @cliexstart{show ip fib}
739  * ipv4-VRF:0, fib_index 0, flow hash: src dst sport dport proto
740  * 0.0.0.0/0
741  * unicast-ip4-chain
742  * [@0]: dpo-load-balance: [index:0 buckets:1 uRPF:0 to:[0:0]]
743  * [0] [@0]: dpo-drop ip6
744  * 0.0.0.0/32
745  * unicast-ip4-chain
746  * [@0]: dpo-load-balance: [index:1 buckets:1 uRPF:1 to:[0:0]]
747  * [0] [@0]: dpo-drop ip6
748  * 6.0.1.2/32
749  * unicast-ip4-chain
750  * [@0]: dpo-load-balance: [index:30 buckets:1 uRPF:29 to:[0:0]]
751  * [0] [@3]: arp-ipv4: via 6.0.0.1 af_packet0
752  * 7.0.0.1/32
753  * unicast-ip4-chain
754  * [@0]: dpo-load-balance: [index:31 buckets:4 uRPF:30 to:[0:0]]
755  * [0] [@3]: arp-ipv4: via 6.0.0.2 af_packet0
756  * [1] [@3]: arp-ipv4: via 6.0.0.2 af_packet0
757  * [2] [@3]: arp-ipv4: via 6.0.0.2 af_packet0
758  * [3] [@3]: arp-ipv4: via 6.0.0.1 af_packet0
759  * 224.0.0.0/8
760  * unicast-ip4-chain
761  * [@0]: dpo-load-balance: [index:3 buckets:1 uRPF:3 to:[0:0]]
762  * [0] [@0]: dpo-drop ip6
763  * 240.0.0.0/8
764  * unicast-ip4-chain
765  * [@0]: dpo-load-balance: [index:2 buckets:1 uRPF:2 to:[0:0]]
766  * [0] [@0]: dpo-drop ip6
767  * 255.255.255.255/32
768  * unicast-ip4-chain
769  * [@0]: dpo-load-balance: [index:4 buckets:1 uRPF:4 to:[0:0]]
770  * [0] [@0]: dpo-drop ip6
771  * ipv4-VRF:7, fib_index 1, flow hash: src dst sport dport proto
772  * 0.0.0.0/0
773  * unicast-ip4-chain
774  * [@0]: dpo-load-balance: [index:12 buckets:1 uRPF:11 to:[0:0]]
775  * [0] [@0]: dpo-drop ip6
776  * 0.0.0.0/32
777  * unicast-ip4-chain
778  * [@0]: dpo-load-balance: [index:13 buckets:1 uRPF:12 to:[0:0]]
779  * [0] [@0]: dpo-drop ip6
780  * 172.16.1.0/24
781  * unicast-ip4-chain
782  * [@0]: dpo-load-balance: [index:17 buckets:1 uRPF:16 to:[0:0]]
783  * [0] [@4]: ipv4-glean: af_packet0
784  * 172.16.1.1/32
785  * unicast-ip4-chain
786  * [@0]: dpo-load-balance: [index:18 buckets:1 uRPF:17 to:[1:84]]
787  * [0] [@2]: dpo-receive: 172.16.1.1 on af_packet0
788  * 172.16.1.2/32
789  * unicast-ip4-chain
790  * [@0]: dpo-load-balance: [index:21 buckets:1 uRPF:20 to:[0:0]]
791  * [0] [@5]: ipv4 via 172.16.1.2 af_packet0: IP4: 02:fe:9e:70:7a:2b -> 26:a5:f6:9c:3a:36
792  * 172.16.2.0/24
793  * unicast-ip4-chain
794  * [@0]: dpo-load-balance: [index:19 buckets:1 uRPF:18 to:[0:0]]
795  * [0] [@4]: ipv4-glean: af_packet1
796  * 172.16.2.1/32
797  * unicast-ip4-chain
798  * [@0]: dpo-load-balance: [index:20 buckets:1 uRPF:19 to:[0:0]]
799  * [0] [@2]: dpo-receive: 172.16.2.1 on af_packet1
800  * 224.0.0.0/8
801  * unicast-ip4-chain
802  * [@0]: dpo-load-balance: [index:15 buckets:1 uRPF:14 to:[0:0]]
803  * [0] [@0]: dpo-drop ip6
804  * 240.0.0.0/8
805  * unicast-ip4-chain
806  * [@0]: dpo-load-balance: [index:14 buckets:1 uRPF:13 to:[0:0]]
807  * [0] [@0]: dpo-drop ip6
808  * 255.255.255.255/32
809  * unicast-ip4-chain
810  * [@0]: dpo-load-balance: [index:16 buckets:1 uRPF:15 to:[0:0]]
811  * [0] [@0]: dpo-drop ip6
812  * @cliexend
813  * Example of how to display a single IPv4 FIB table:
814  * @cliexstart{show ip fib table 7}
815  * ipv4-VRF:7, fib_index 1, flow hash: src dst sport dport proto
816  * 0.0.0.0/0
817  * unicast-ip4-chain
818  * [@0]: dpo-load-balance: [index:12 buckets:1 uRPF:11 to:[0:0]]
819  * [0] [@0]: dpo-drop ip6
820  * 0.0.0.0/32
821  * unicast-ip4-chain
822  * [@0]: dpo-load-balance: [index:13 buckets:1 uRPF:12 to:[0:0]]
823  * [0] [@0]: dpo-drop ip6
824  * 172.16.1.0/24
825  * unicast-ip4-chain
826  * [@0]: dpo-load-balance: [index:17 buckets:1 uRPF:16 to:[0:0]]
827  * [0] [@4]: ipv4-glean: af_packet0
828  * 172.16.1.1/32
829  * unicast-ip4-chain
830  * [@0]: dpo-load-balance: [index:18 buckets:1 uRPF:17 to:[1:84]]
831  * [0] [@2]: dpo-receive: 172.16.1.1 on af_packet0
832  * 172.16.1.2/32
833  * unicast-ip4-chain
834  * [@0]: dpo-load-balance: [index:21 buckets:1 uRPF:20 to:[0:0]]
835  * [0] [@5]: ipv4 via 172.16.1.2 af_packet0: IP4: 02:fe:9e:70:7a:2b -> 26:a5:f6:9c:3a:36
836  * 172.16.2.0/24
837  * unicast-ip4-chain
838  * [@0]: dpo-load-balance: [index:19 buckets:1 uRPF:18 to:[0:0]]
839  * [0] [@4]: ipv4-glean: af_packet1
840  * 172.16.2.1/32
841  * unicast-ip4-chain
842  * [@0]: dpo-load-balance: [index:20 buckets:1 uRPF:19 to:[0:0]]
843  * [0] [@2]: dpo-receive: 172.16.2.1 on af_packet1
844  * 224.0.0.0/8
845  * unicast-ip4-chain
846  * [@0]: dpo-load-balance: [index:15 buckets:1 uRPF:14 to:[0:0]]
847  * [0] [@0]: dpo-drop ip6
848  * 240.0.0.0/8
849  * unicast-ip4-chain
850  * [@0]: dpo-load-balance: [index:14 buckets:1 uRPF:13 to:[0:0]]
851  * [0] [@0]: dpo-drop ip6
852  * 255.255.255.255/32
853  * unicast-ip4-chain
854  * [@0]: dpo-load-balance: [index:16 buckets:1 uRPF:15 to:[0:0]]
855  * [0] [@0]: dpo-drop ip6
856  * @cliexend
857  * Example of how to display a summary of all IPv4 FIB tables:
858  * @cliexstart{show ip fib summary}
859  * ipv4-VRF:0, fib_index 0, flow hash: src dst sport dport proto
860  * Prefix length Count
861  * 0 1
862  * 8 2
863  * 32 4
864  * ipv4-VRF:7, fib_index 1, flow hash: src dst sport dport proto
865  * Prefix length Count
866  * 0 1
867  * 8 2
868  * 24 2
869  * 32 4
870  * @cliexend
871  ?*/
872 /* *INDENT-OFF* */
873 VLIB_CLI_COMMAND (ip4_show_fib_command, static) = {
874  .path = "show ip fib",
875  .short_help = "show ip fib [summary] [table <table-id>] [index <fib-id>] [<ip4-addr>[/<mask>]] [mtrie] [detail]",
876  .function = ip4_show_fib,
877 };
878 /* *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:139
Continue on to the next entry.
Definition: fib_table.h:868
typedef address
Definition: ip_types.api:30
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:551
#define hash_set(h, key, value)
Definition: hash.h:255
vl_api_address_t src
Definition: vxlan_gbp.api:32
vhost_user_memory_t memory
Definition: vhost_user.h:122
fib_protocol_t ft_proto
Which protocol this table serves.
Definition: fib_table.h:74
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:388
#define hash_unset(h, key)
Definition: hash.h:261
#define FIB_ENTRY_FORMAT_DETAIL
Definition: fib_entry.h:517
unsigned long u64
Definition: types.h:89
#define NULL
Definition: clib.h:58
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:525
void ip4_fib_table_destroy(u32 fib_index)
Definition: ip4_fib.c:159
int i
static clib_error_t * ip4_show_fib(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: ip4_fib.c:585
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:181
const fib_prefix_t * fib_entry_get_prefix(fib_node_index_t fib_entry_index)
Definition: fib_entry.c:1678
u32 * fib_index_by_sw_if_index
Table index indexed by software interface.
Definition: ip4.h:112
u8 * format(u8 *s, const char *fmt,...)
Definition: format.c:419
#define pool_get(P, E)
Allocate an object E from a pool P (unspecified alignment).
Definition: pool.h:236
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:203
vhost_vring_addr_t addr
Definition: vhost_user.h:121
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:527
uword value[0]
Definition: hash.h:165
u32 ip4_fib_table_create_and_lock(fib_source_t src)
Definition: ip4_fib.c:218
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:224
#define pool_foreach(VAR, POOL, BODY)
Iterate through pool.
Definition: pool.h:490
unformat_function_t unformat_ip4_address
Definition: format.h:70
u32 table_id
Definition: ip4_fib.h:54
u32 sw_if_index
Definition: vxlan_gbp.api:37
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:407
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
Aggregrate 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:429
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:349
int fib_entry_cmp_for_sort(void *i1, void *i2)
Definition: fib_entry.c:1616
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:168
#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:511
uword * fib_index_by_table_id
Hash table mapping table id to fib index.
Definition: ip4.h:122
enum fib_source_t_ fib_source_t
The different sources that can create a route.
ip46_address_t fp_addr
The address type is not deriveable from the fp_addr member.
Definition: fib_types.h:226
u16 ft_locks[FIB_TABLE_N_LOCKS]
per-source number of locks on the table
Definition: fib_table.h:84
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:286
u32 ft_total_route_counts
Total route counters.
Definition: fib_table.h:109
void * mtrie_mheap
The memory heap for the mtries.
Definition: ip4.h:157
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:379
ip4_fib_mtrie_t mtrie
Mtrie for fast lookups.
Definition: ip4_fib.h:48
Stop the walk completely.
Definition: fib_table.h:876
u8 len
Definition: ip_types.api:49
#define pool_get_aligned(P, E, A)
Allocate an object E from a pool P with alignment A.
Definition: pool.h:230
fib_node_index_t ip4_fib_table_lookup(const ip4_fib_t *fib, const ip4_address_t *addr, u32 len)
Definition: ip4_fib.c:291
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:388
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:314
The IPv4 FIB.
Definition: ip4_fib.h:39
fib_node_index_t ft_index
Index into FIB vector.
Definition: fib_table.h:94
#define UNFORMAT_END_OF_INPUT
Definition: format.h:144
u32 ft_table_id
Table ID (hash key) for this FIB.
Definition: fib_table.h:89
vlib_main_t * vm
Definition: buffer.c:301
u32 ft_flow_hash_config
flow hash configuration
Definition: fib_table.h:99
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:341
#define FOR_EACH_FIB_SOURCE(_item)
Definition: fib_entry.h:185
fib_node_index_t * ifsw_indicies
Definition: ip4_fib.c:512
static void * clib_mem_set_heap(void *heap)
Definition: mem.h:261
Definition: fib_entry.h:278
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:62
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:412
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:882
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:1266
#define VLIB_CLI_COMMAND(x,...)
Definition: cli.h:155
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)
The default route source.
Definition: fib_entry.h:137
IPv4 main type.
Definition: ip4.h:96
Walk show context.
Definition: ip4_fib.c:510
u32 ft_src_route_counts[FIB_SOURCE_MAX]
Per-source route counters.
Definition: fib_table.h:104
#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:566
uword mheap_bytes(void *v)
Definition: mheap.c:1069
#define FIB_ENTRY_FORMAT_BRIEF
Definition: fib_entry.h:516
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:184
#define FIB_NODE_INDEX_INVALID
Definition: fib_types.h:31
struct ip4_fib_t_ * v4_fibs
Vector of MTries.
Definition: ip4.h:104
#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/rntry to the mtrie.
Definition: ip4_mtrie.c:631
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:984
Special sources.
Definition: fib_entry.h:40
typedef prefix
Definition: ip_types.api:35
uword * fib_entry_by_dst_address[33]
Definition: ip4_fib.h:51
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:1293
ip4_main_t ip4_main
Global ip4 main structure.
Definition: ip4_forward.c:903
struct fib_table_t_ * fibs
Vector of FIBs.
Definition: ip4.h:101
#define FIB_ENTRY_FORMAT_DETAIL2
Definition: fib_entry.h:518
#define vec_foreach(var, vec)
Vector iterator.
index_t ip4_fib_table_lookup_lb(ip4_fib_t *fib, const ip4_address_t *addr)
Definition: ip4_fib.c:267
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/rntry to the mtrie
Definition: ip4_mtrie.c:648
u8 * format_ip_flow_hash_config(u8 *s, va_list *args)
Definition: lookup.c:244
#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:516
#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:243
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
Definition: cli.c:762
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:972
static uword unformat_check_input(unformat_input_t *i)
Definition: format.h:170
A protocol Independent FIB table.
Definition: fib_table.h:69
u32 fib_masks[33]
Definition: ip4.h:109
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