FD.io VPP  v17.10-9-gd594711
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
105  fib_source_t src)
106 {
107  fib_table_t *fib_table;
108  ip4_fib_t *v4_fib;
109 
111  memset(fib_table, 0, sizeof(*fib_table));
112 
114 
115  ASSERT((fib_table - ip4_main.fibs) ==
116  (v4_fib - ip4_main.v4_fibs));
117 
118  fib_table->ft_proto = FIB_PROTOCOL_IP4;
119  fib_table->ft_index =
120  v4_fib->index =
121  (fib_table - ip4_main.fibs);
122 
123  hash_set (ip4_main.fib_index_by_table_id, table_id, fib_table->ft_index);
124 
125  fib_table->ft_table_id =
126  v4_fib->table_id =
127  table_id;
129  v4_fib->fwd_classify_table_index = ~0;
130  v4_fib->rev_classify_table_index = ~0;
131 
132  fib_table_lock(fib_table->ft_index, FIB_PROTOCOL_IP4, src);
133 
134  ip4_mtrie_init(&v4_fib->mtrie);
135 
136  /*
137  * add the special entries into the new FIB
138  */
139  int ii;
140 
141  for (ii = 0; ii < ARRAY_LEN(ip4_specials); ii++)
142  {
143  fib_prefix_t prefix = ip4_specials[ii].ift_prefix;
144 
145  prefix.fp_addr.ip4.data_u32 =
146  clib_host_to_net_u32(prefix.fp_addr.ip4.data_u32);
147 
149  &prefix,
150  ip4_specials[ii].ift_source,
151  ip4_specials[ii].ift_flag);
152  }
153 
154  return (fib_table->ft_index);
155 }
156 
157 void
159 {
160  fib_table_t *fib_table = pool_elt_at_index(ip4_main.fibs, fib_index);
161  ip4_fib_t *v4_fib = pool_elt_at_index(ip4_main.v4_fibs, fib_index);
162  int ii;
163 
164  /*
165  * remove all the specials we added when the table was created.
166  * In reverse order so the default route is last.
167  */
168  for (ii = ARRAY_LEN(ip4_specials) - 1; ii >= 0; ii--)
169  {
170  fib_prefix_t prefix = ip4_specials[ii].ift_prefix;
171 
172  prefix.fp_addr.ip4.data_u32 =
173  clib_host_to_net_u32(prefix.fp_addr.ip4.data_u32);
174 
176  &prefix,
177  ip4_specials[ii].ift_source);
178  }
179 
180  /*
181  * validate no more routes.
182  */
183  ASSERT(0 == fib_table->ft_total_route_counts);
185  {
186  ASSERT(0 == fib_table->ft_src_route_counts[ii]);
187  }
188 
189  if (~0 != fib_table->ft_table_id)
190  {
192  }
193 
194  ip4_mtrie_free(&v4_fib->mtrie);
195 
196  pool_put(ip4_main.v4_fibs, v4_fib);
197  pool_put(ip4_main.fibs, fib_table);
198 }
199 
200 
201 u32
203  fib_source_t src)
204 {
205  u32 index;
206 
207  index = ip4_fib_index_from_table_id(table_id);
208  if (~0 == index)
209  return ip4_create_fib_with_table_id(table_id, src);
210 
211  fib_table_lock(index, FIB_PROTOCOL_IP4, src);
212 
213  return (index);
214 }
215 
216 u32
218 {
219  return (ip4_create_fib_with_table_id(~0, src));
220 }
221 
222 u32
224 {
225  if (sw_if_index >= vec_len(ip4_main.fib_index_by_sw_if_index))
226  {
227  /*
228  * This is the case for interfaces that are not yet mapped to
229  * a IP table
230  */
231  return (~0);
232  }
233  return (ip4_main.fib_index_by_sw_if_index[sw_if_index]);
234 }
235 
236 /*
237  * ip4_fib_table_lookup_exact_match
238  *
239  * Exact match prefix lookup
240  */
243  const ip4_address_t *addr,
244  u32 len)
245 {
246  uword * hash, * result;
247  u32 key;
248 
249  hash = fib->fib_entry_by_dst_address[len];
250  key = (addr->data_u32 & ip4_main.fib_masks[len]);
251 
252  result = hash_get(hash, key);
253 
254  if (NULL != result) {
255  return (result[0]);
256  }
257  return (FIB_NODE_INDEX_INVALID);
258 }
259 
260 /*
261  * ip4_fib_table_lookup_adj
262  *
263  * Longest prefix match
264  */
265 index_t
267  const ip4_address_t *addr)
268 {
269  fib_node_index_t fei;
270 
271  fei = ip4_fib_table_lookup(fib, addr, 32);
272 
273  if (FIB_NODE_INDEX_INVALID != fei)
274  {
275  const dpo_id_t *dpo;
276 
278 
279  return (dpo->dpoi_index);
280  }
281  return (INDEX_INVALID);
282 }
283 
284 /*
285  * ip4_fib_table_lookup
286  *
287  * Longest prefix match
288  */
291  const ip4_address_t *addr,
292  u32 len)
293 {
294  uword * hash, * result;
295  i32 mask_len;
296  u32 key;
297 
298  for (mask_len = len; mask_len >= 0; mask_len--)
299  {
300  hash = fib->fib_entry_by_dst_address[mask_len];
301  key = (addr->data_u32 & ip4_main.fib_masks[mask_len]);
302 
303  result = hash_get (hash, key);
304 
305  if (NULL != result) {
306  return (result[0]);
307  }
308  }
309  return (FIB_NODE_INDEX_INVALID);
310 }
311 
312 void
314  const ip4_address_t *addr,
315  u32 len,
316  fib_node_index_t fib_entry_index)
317 {
318  uword * hash, * result;
319  u32 key;
320 
321  key = (addr->data_u32 & ip4_main.fib_masks[len]);
322  hash = fib->fib_entry_by_dst_address[len];
323  result = hash_get (hash, key);
324 
325  if (NULL == result) {
326  /*
327  * adding a new entry
328  */
329  if (NULL == hash) {
330  hash = hash_create (32 /* elts */, sizeof (uword));
332  }
333  hash = hash_set(hash, key, fib_entry_index);
334  fib->fib_entry_by_dst_address[len] = hash;
335  }
336  else
337  {
338  ASSERT(0);
339  }
340 }
341 
342 void
344  const ip4_address_t *addr,
345  u32 len)
346 {
347  uword * hash, * result;
348  u32 key;
349 
350  key = (addr->data_u32 & ip4_main.fib_masks[len]);
351  hash = fib->fib_entry_by_dst_address[len];
352  result = hash_get (hash, key);
353 
354  if (NULL == result)
355  {
356  /*
357  * removing a non-existant entry. i'll allow it.
358  */
359  }
360  else
361  {
362  hash_unset(hash, key);
363  }
364 
365  fib->fib_entry_by_dst_address[len] = hash;
366 }
367 
368 void
370  const ip4_address_t *addr,
371  u32 len,
372  const dpo_id_t *dpo)
373 {
374  ip4_fib_mtrie_route_add(&fib->mtrie, addr, len, dpo->dpoi_index);
375 }
376 
377 void
379  const ip4_address_t *addr,
380  u32 len,
381  const dpo_id_t *dpo,
382  u32 cover_index)
383 {
384  fib_prefix_t cover_prefix = {
385  .fp_len = 0,
386  };
387  const dpo_id_t *cover_dpo;
388 
389  /*
390  * We need to pass the MTRIE the LB index and address length of the
391  * covering prefix, so it can fill the plys with the correct replacement
392  * for the entry being removed
393  */
394  fib_entry_get_prefix(cover_index, &cover_prefix);
395  cover_dpo = fib_entry_contribute_ip_forwarding(cover_index);
396 
398  addr, len, dpo->dpoi_index,
399  cover_prefix.fp_len,
400  cover_dpo->dpoi_index);
401 }
402 
403 void
406  void *ctx)
407 {
408  int i;
409 
410  for (i = 0; i < ARRAY_LEN (fib->fib_entry_by_dst_address); i++)
411  {
412  uword * hash = fib->fib_entry_by_dst_address[i];
413 
414  if (NULL != hash)
415  {
416  hash_pair_t * p;
417 
418  hash_foreach_pair (p, hash,
419  ({
420  fn(p->value[0], ctx);
421  }));
422  }
423  }
424 }
425 
426 /**
427  * Walk show context
428  */
430 {
433 
434 static int
436  void *arg)
437 {
439 
440  vec_add1(ctx->ifsw_indicies, fib_entry_index);
441 
442  return (1);
443 }
444 
445 static void
447  vlib_main_t * vm)
448 {
450  .ifsw_indicies = NULL,
451  };
452  fib_node_index_t *fib_entry_index;
453 
457 
458  vec_foreach(fib_entry_index, ctx.ifsw_indicies)
459  {
460  vlib_cli_output(vm, "%U",
462  *fib_entry_index,
464  }
465 
466  vec_free(ctx.ifsw_indicies);
467 }
468 
469 static void
471  vlib_main_t * vm,
472  ip4_address_t *address,
473  u32 mask_len,
474  int detail)
475 {
476  vlib_cli_output(vm, "%U",
478  ip4_fib_table_lookup(fib, address, mask_len),
479  (detail ?
482 }
483 
484 static clib_error_t *
486  unformat_input_t * input,
487  vlib_cli_command_t * cmd)
488 {
489  ip4_main_t * im4 = &ip4_main;
490  fib_table_t * fib_table;
491  int verbose, matching, mtrie;
492  ip4_address_t matching_address;
493  u32 matching_mask = 32;
494  int i, table_id = -1, fib_index = ~0;
495  int detail = 0;
496 
497  verbose = 1;
498  matching = 0;
499  mtrie = 0;
501  {
502  if (unformat (input, "brief") || unformat (input, "summary")
503  || unformat (input, "sum"))
504  verbose = 0;
505 
506  else if (unformat (input, "detail") || unformat (input, "det"))
507  detail = 1;
508 
509  else if (unformat (input, "mtrie"))
510  mtrie = 1;
511 
512  else if (unformat (input, "%U/%d",
513  unformat_ip4_address, &matching_address, &matching_mask))
514  matching = 1;
515 
516  else if (unformat (input, "%U", unformat_ip4_address, &matching_address))
517  matching = 1;
518 
519  else if (unformat (input, "table %d", &table_id))
520  ;
521  else if (unformat (input, "index %d", &fib_index))
522  ;
523  else
524  break;
525  }
526 
527  pool_foreach (fib_table, im4->fibs,
528  ({
529  ip4_fib_t *fib = pool_elt_at_index(im4->v4_fibs, fib_table->ft_index);
530  fib_source_t source;
531  u8 *s = NULL;
532 
533  if (table_id >= 0 && table_id != (int)fib->table_id)
534  continue;
535  if (fib_index != ~0 && fib_index != (int)fib->index)
536  continue;
537 
538  s = format(s, "%U, fib_index:%d, flow hash:[%U] locks:[",
539  format_fib_table_name, fib->index,
540  FIB_PROTOCOL_IP4,
541  fib->index,
542  format_ip_flow_hash_config,
543  fib_table->ft_flow_hash_config);
544  FOR_EACH_FIB_SOURCE(source)
545  {
546  if (0 != fib_table->ft_locks[source])
547  {
548  s = format(s, "%U:%d, ",
549  format_fib_source, source,
550  fib_table->ft_locks[source]);
551  }
552  }
553  s = format (s, "]");
554  vlib_cli_output (vm, "%v", s);
555  vec_free(s);
556 
557  /* Show summary? */
558  if (! verbose)
559  {
560  vlib_cli_output (vm, "%=20s%=16s", "Prefix length", "Count");
561  for (i = 0; i < ARRAY_LEN (fib->fib_entry_by_dst_address); i++)
562  {
563  uword * hash = fib->fib_entry_by_dst_address[i];
564  uword n_elts = hash_elts (hash);
565  if (n_elts > 0)
566  vlib_cli_output (vm, "%20d%16d", i, n_elts);
567  }
568  continue;
569  }
570  if (mtrie)
571  {
572  vlib_cli_output (vm, "%U", format_ip4_fib_mtrie, &fib->mtrie);
573  continue;
574  }
575 
576  if (!matching)
577  {
578  ip4_fib_table_show_all(fib, vm);
579  }
580  else
581  {
582  ip4_fib_table_show_one(fib, vm, &matching_address,
583  matching_mask, detail);
584  }
585  }));
586 
587  return 0;
588 }
589 
590 /*?
591  * This command displays the IPv4 FIB Tables (VRF Tables) and the route
592  * entries for each table.
593  *
594  * @note This command will run for a long time when the FIB tables are
595  * comprised of millions of entries. For those senarios, consider displaying
596  * a single table or summary mode.
597  *
598  * @cliexpar
599  * Example of how to display all the IPv4 FIB tables:
600  * @cliexstart{show ip fib}
601  * ipv4-VRF:0, fib_index 0, flow hash: src dst sport dport proto
602  * 0.0.0.0/0
603  * unicast-ip4-chain
604  * [@0]: dpo-load-balance: [index:0 buckets:1 uRPF:0 to:[0:0]]
605  * [0] [@0]: dpo-drop ip6
606  * 0.0.0.0/32
607  * unicast-ip4-chain
608  * [@0]: dpo-load-balance: [index:1 buckets:1 uRPF:1 to:[0:0]]
609  * [0] [@0]: dpo-drop ip6
610  * 6.0.1.2/32
611  * unicast-ip4-chain
612  * [@0]: dpo-load-balance: [index:30 buckets:1 uRPF:29 to:[0:0]]
613  * [0] [@3]: arp-ipv4: via 6.0.0.1 af_packet0
614  * 7.0.0.1/32
615  * unicast-ip4-chain
616  * [@0]: dpo-load-balance: [index:31 buckets:4 uRPF:30 to:[0:0]]
617  * [0] [@3]: arp-ipv4: via 6.0.0.2 af_packet0
618  * [1] [@3]: arp-ipv4: via 6.0.0.2 af_packet0
619  * [2] [@3]: arp-ipv4: via 6.0.0.2 af_packet0
620  * [3] [@3]: arp-ipv4: via 6.0.0.1 af_packet0
621  * 224.0.0.0/8
622  * unicast-ip4-chain
623  * [@0]: dpo-load-balance: [index:3 buckets:1 uRPF:3 to:[0:0]]
624  * [0] [@0]: dpo-drop ip6
625  * 240.0.0.0/8
626  * unicast-ip4-chain
627  * [@0]: dpo-load-balance: [index:2 buckets:1 uRPF:2 to:[0:0]]
628  * [0] [@0]: dpo-drop ip6
629  * 255.255.255.255/32
630  * unicast-ip4-chain
631  * [@0]: dpo-load-balance: [index:4 buckets:1 uRPF:4 to:[0:0]]
632  * [0] [@0]: dpo-drop ip6
633  * ipv4-VRF:7, fib_index 1, flow hash: src dst sport dport proto
634  * 0.0.0.0/0
635  * unicast-ip4-chain
636  * [@0]: dpo-load-balance: [index:12 buckets:1 uRPF:11 to:[0:0]]
637  * [0] [@0]: dpo-drop ip6
638  * 0.0.0.0/32
639  * unicast-ip4-chain
640  * [@0]: dpo-load-balance: [index:13 buckets:1 uRPF:12 to:[0:0]]
641  * [0] [@0]: dpo-drop ip6
642  * 172.16.1.0/24
643  * unicast-ip4-chain
644  * [@0]: dpo-load-balance: [index:17 buckets:1 uRPF:16 to:[0:0]]
645  * [0] [@4]: ipv4-glean: af_packet0
646  * 172.16.1.1/32
647  * unicast-ip4-chain
648  * [@0]: dpo-load-balance: [index:18 buckets:1 uRPF:17 to:[1:84]]
649  * [0] [@2]: dpo-receive: 172.16.1.1 on af_packet0
650  * 172.16.1.2/32
651  * unicast-ip4-chain
652  * [@0]: dpo-load-balance: [index:21 buckets:1 uRPF:20 to:[0:0]]
653  * [0] [@5]: ipv4 via 172.16.1.2 af_packet0: IP4: 02:fe:9e:70:7a:2b -> 26:a5:f6:9c:3a:36
654  * 172.16.2.0/24
655  * unicast-ip4-chain
656  * [@0]: dpo-load-balance: [index:19 buckets:1 uRPF:18 to:[0:0]]
657  * [0] [@4]: ipv4-glean: af_packet1
658  * 172.16.2.1/32
659  * unicast-ip4-chain
660  * [@0]: dpo-load-balance: [index:20 buckets:1 uRPF:19 to:[0:0]]
661  * [0] [@2]: dpo-receive: 172.16.2.1 on af_packet1
662  * 224.0.0.0/8
663  * unicast-ip4-chain
664  * [@0]: dpo-load-balance: [index:15 buckets:1 uRPF:14 to:[0:0]]
665  * [0] [@0]: dpo-drop ip6
666  * 240.0.0.0/8
667  * unicast-ip4-chain
668  * [@0]: dpo-load-balance: [index:14 buckets:1 uRPF:13 to:[0:0]]
669  * [0] [@0]: dpo-drop ip6
670  * 255.255.255.255/32
671  * unicast-ip4-chain
672  * [@0]: dpo-load-balance: [index:16 buckets:1 uRPF:15 to:[0:0]]
673  * [0] [@0]: dpo-drop ip6
674  * @cliexend
675  * Example of how to display a single IPv4 FIB table:
676  * @cliexstart{show ip fib table 7}
677  * ipv4-VRF:7, fib_index 1, flow hash: src dst sport dport proto
678  * 0.0.0.0/0
679  * unicast-ip4-chain
680  * [@0]: dpo-load-balance: [index:12 buckets:1 uRPF:11 to:[0:0]]
681  * [0] [@0]: dpo-drop ip6
682  * 0.0.0.0/32
683  * unicast-ip4-chain
684  * [@0]: dpo-load-balance: [index:13 buckets:1 uRPF:12 to:[0:0]]
685  * [0] [@0]: dpo-drop ip6
686  * 172.16.1.0/24
687  * unicast-ip4-chain
688  * [@0]: dpo-load-balance: [index:17 buckets:1 uRPF:16 to:[0:0]]
689  * [0] [@4]: ipv4-glean: af_packet0
690  * 172.16.1.1/32
691  * unicast-ip4-chain
692  * [@0]: dpo-load-balance: [index:18 buckets:1 uRPF:17 to:[1:84]]
693  * [0] [@2]: dpo-receive: 172.16.1.1 on af_packet0
694  * 172.16.1.2/32
695  * unicast-ip4-chain
696  * [@0]: dpo-load-balance: [index:21 buckets:1 uRPF:20 to:[0:0]]
697  * [0] [@5]: ipv4 via 172.16.1.2 af_packet0: IP4: 02:fe:9e:70:7a:2b -> 26:a5:f6:9c:3a:36
698  * 172.16.2.0/24
699  * unicast-ip4-chain
700  * [@0]: dpo-load-balance: [index:19 buckets:1 uRPF:18 to:[0:0]]
701  * [0] [@4]: ipv4-glean: af_packet1
702  * 172.16.2.1/32
703  * unicast-ip4-chain
704  * [@0]: dpo-load-balance: [index:20 buckets:1 uRPF:19 to:[0:0]]
705  * [0] [@2]: dpo-receive: 172.16.2.1 on af_packet1
706  * 224.0.0.0/8
707  * unicast-ip4-chain
708  * [@0]: dpo-load-balance: [index:15 buckets:1 uRPF:14 to:[0:0]]
709  * [0] [@0]: dpo-drop ip6
710  * 240.0.0.0/8
711  * unicast-ip4-chain
712  * [@0]: dpo-load-balance: [index:14 buckets:1 uRPF:13 to:[0:0]]
713  * [0] [@0]: dpo-drop ip6
714  * 255.255.255.255/32
715  * unicast-ip4-chain
716  * [@0]: dpo-load-balance: [index:16 buckets:1 uRPF:15 to:[0:0]]
717  * [0] [@0]: dpo-drop ip6
718  * @cliexend
719  * Example of how to display a summary of all IPv4 FIB tables:
720  * @cliexstart{show ip fib summary}
721  * ipv4-VRF:0, fib_index 0, flow hash: src dst sport dport proto
722  * Prefix length Count
723  * 0 1
724  * 8 2
725  * 32 4
726  * ipv4-VRF:7, fib_index 1, flow hash: src dst sport dport proto
727  * Prefix length Count
728  * 0 1
729  * 8 2
730  * 24 2
731  * 32 4
732  * @cliexend
733  ?*/
734 /* *INDENT-OFF* */
735 VLIB_CLI_COMMAND (ip4_show_fib_command, static) = {
736  .path = "show ip fib",
737  .short_help = "show ip fib [summary] [table <table-id>] [index <fib-id>] [<ip4-addr>[/<mask>]] [mtrie] [detail]",
738  .function = ip4_show_fib,
739 };
740 /* *INDENT-ON* */
u8 * format_fib_entry(u8 *s, va_list *args)
Definition: fib_entry.c:103
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:470
#define hash_set(h, key, value)
Definition: hash.h:254
sll srl srl sll sra u16x4 i
Definition: vector_sse2.h:337
fib_protocol_t ft_proto
Which protocol this table serves.
Definition: fib_table.h:40
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:378
#define hash_unset(h, key)
Definition: hash.h:260
#define FIB_ENTRY_FORMAT_DETAIL
Definition: fib_entry.h:430
void fib_entry_get_prefix(fib_node_index_t fib_entry_index, fib_prefix_t *pfx)
Definition: fib_entry.c:1547
#define NULL
Definition: clib.h:55
int(* 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:798
const dpo_id_t * fib_entry_contribute_ip_forwarding(fib_node_index_t fib_entry_index)
Definition: fib_entry.c:460
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:518
void ip4_fib_table_destroy(u32 fib_index)
Definition: ip4_fib.c:158
static clib_error_t * ip4_show_fib(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: ip4_fib.c:485
u32 * fib_index_by_sw_if_index
Table index indexed by software interface.
Definition: ip4.h:111
u8 * format(u8 *s, const char *fmt,...)
Definition: format.c:419
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:202
static void ip4_fib_table_show_all(ip4_fib_t *fib, vlib_main_t *vm)
Definition: ip4_fib.c:446
uword value[0]
Definition: hash.h:164
u32 ip4_fib_table_create_and_lock(fib_source_t src)
Definition: ip4_fib.c:217
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:223
#define pool_foreach(VAR, POOL, BODY)
Iterate through pool.
Definition: pool.h:437
unformat_function_t unformat_ip4_address
Definition: format.h:76
u32 table_id
Definition: ip4_fib.h:51
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:390
u32 index
Definition: ip4_fib.h:54
int i32
Definition: types.h:81
void ip4_mtrie_free(ip4_fib_mtrie_t *m)
Free an mtrie, It must be emty when free&#39;d.
Definition: ip4_mtrie.c:196
Aggregrate type for a prefix.
Definition: fib_types.h:160
static void hash_set_flags(void *v, uword flags)
Definition: hash.h:152
static int ip4_fib_show_walk_cb(fib_node_index_t fib_entry_index, void *arg)
Definition: ip4_fib.c:435
u16 fp_len
The mask length.
Definition: fib_types.h:164
void ip4_fib_table_entry_remove(ip4_fib_t *fib, const ip4_address_t *addr, u32 len)
Definition: ip4_fib.c:343
int fib_entry_cmp_for_sort(void *i1, void *i2)
Definition: fib_entry.c:1499
void ip4_mtrie_init(ip4_fib_mtrie_t *m)
Initialise an mtrie.
Definition: ip4_mtrie.c:212
The identity of a DPO is a combination of its type and its instance number/index of objects of that t...
Definition: dpo.h:150
#define hash_get(h, key)
Definition: hash.h:248
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
Definition: pool.h:458
uword * fib_index_by_table_id
Hash table mapping table id to fib index.
Definition: ip4.h:121
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:183
struct _unformat_input_t unformat_input_t
#define pool_put(P, E)
Free an object E in pool P.
Definition: pool.h:270
u32 ft_total_route_counts
Total route counters.
Definition: fib_table.h:70
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:369
ip4_fib_mtrie_t mtrie
Mtrie for fast lookups.
Definition: ip4_fib.h:45
#define pool_get_aligned(P, E, A)
Allocate an object E from a pool P (general version).
Definition: pool.h:188
fib_node_index_t ip4_fib_table_lookup(const ip4_fib_t *fib, const ip4_address_t *addr, u32 len)
Definition: ip4_fib.c:290
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:371
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:313
The IPv4 FIB.
Definition: ip4_fib.h:39
fib_node_index_t ft_index
Index into FIB vector.
Definition: fib_table.h:55
#define UNFORMAT_END_OF_INPUT
Definition: format.h:143
u32 ft_table_id
Table ID (hash key) for this FIB.
Definition: fib_table.h:50
vlib_main_t * vm
Definition: buffer.c:283
u32 ft_flow_hash_config
flow hash configuration
Definition: fib_table.h:60
#define vec_free(V)
Free vector&#39;s memory (no header).
Definition: vec.h:336
#define FOR_EACH_FIB_SOURCE(_item)
Definition: fib_entry.h:156
fib_node_index_t * ifsw_indicies
Definition: ip4_fib.c:431
Definition: fib_entry.h:231
u32 fib_node_index_t
A typedef of a node index.
Definition: fib_types.h:28
static u32 ip4_fib_index_from_table_id(u32 table_id)
Definition: ip4_fib.h:136
#define ARRAY_LEN(x)
Definition: clib.h:59
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:404
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:1206
#define VLIB_CLI_COMMAND(x,...)
Definition: cli.h:154
#define hash_create(elts, value_bytes)
Definition: hash.h:658
static uword hash_elts(void *v)
Definition: hash.h:117
#define ASSERT(truth)
unsigned int u32
Definition: types.h:88
long ctx[MAX_CONNS]
Definition: main.c:95
The default route source.
Definition: fib_entry.h:121
IPv4 main type.
Definition: ip4.h:95
Walk show context.
Definition: ip4_fib.c:429
u32 ft_src_route_counts[FIB_SOURCE_MAX]
Per-source route counters.
Definition: fib_table.h:65
#define IP_FLOW_HASH_DEFAULT
Default: 5-tuple without the "reverse" bit.
Definition: lookup.h:69
u64 uword
Definition: types.h:112
#define FIB_ENTRY_FORMAT_BRIEF
Definition: fib_entry.h:429
format_function_t format_ip4_fib_mtrie
Format/display the contents of the mtrie.
Definition: ip4_mtrie.h:167
index_t dpoi_index
the index of objects of that type
Definition: dpo.h:166
#define FIB_NODE_INDEX_INVALID
Definition: fib_types.h:29
struct ip4_fib_t_ * v4_fibs
Vector of MTries.
Definition: ip4.h:103
#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:349
#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:630
#define vec_sort_with_function(vec, f)
Sort a vector using the supplied element comparison function.
Definition: vec.h:956
u32 rev_classify_table_index
Definition: ip4_fib.h:58
Special sources.
Definition: fib_entry.h:40
u32 fwd_classify_table_index
Definition: ip4_fib.h:57
uword * fib_entry_by_dst_address[33]
Definition: ip4_fib.h:48
struct ip4_fib_table_special_prefix_t_ ip4_fib_table_special_prefix_t
ip4_main_t ip4_main
Global ip4 main structure.
Definition: ip4_forward.c:1175
struct fib_table_t_ * fibs
Vector of FIBs.
Definition: ip4.h:100
#define FIB_ENTRY_FORMAT_DETAIL2
Definition: fib_entry.h:431
#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:266
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:647
vhost_vring_addr_t addr
Definition: vhost-user.h:83
#define CLIB_CACHE_LINE_BYTES
Definition: cache.h:67
#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:242
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
Definition: cli.c:680
struct ip4_fib_show_walk_ctx_t_ ip4_fib_show_walk_ctx_t
Walk show context.
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:169
A protocol Independent FIB table.
Definition: fib_table.h:35
u32 fib_masks[33]
Definition: ip4.h:108
static u32 ip4_create_fib_with_table_id(u32 table_id, fib_source_t src)
Definition: ip4_fib.c:104