blob: 23f70a770bf8d646a29d194488c241e24adfde3d [file] [log] [blame]
Neale Ranns0bfe5d82016-08-25 15:29:12 +01001/*
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/*
Lijian.Zhang33af8c12019-09-16 16:22:36 +080021 * A table of prefixes to be added to tables and the sources for them
Neale Ranns0bfe5d82016-08-25 15:29:12 +010022 */
23typedef 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
29static 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 /*
Neale Ranns86fb04d2016-12-01 17:03:25 +000056 * 240.0.0.0/4
Neale Ranns0bfe5d82016-08-25 15:29:12 +010057 * drop class E
58 */
59 .ift_prefix = {
60 .fp_addr = {
61 .ip4.data_u32 = 0xf0000000,
62 },
Neale Ranns86fb04d2016-12-01 17:03:25 +000063 .fp_len = 4,
Neale Ranns0bfe5d82016-08-25 15:29:12 +010064 .fp_proto = FIB_PROTOCOL_IP4,
65 },
66 .ift_source = FIB_SOURCE_SPECIAL,
67 .ift_flag = FIB_ENTRY_FLAG_DROP,
68
69 },
70 {
71 /*
Neale Ranns86fb04d2016-12-01 17:03:25 +000072 * 224.0.0.0/4
Neale Ranns0bfe5d82016-08-25 15:29:12 +010073 * drop all mcast
74 */
75 .ift_prefix = {
76 .fp_addr = {
77 .ip4.data_u32 = 0xe0000000,
78 },
Neale Ranns86fb04d2016-12-01 17:03:25 +000079 .fp_len = 4,
Neale Ranns0bfe5d82016-08-25 15:29:12 +010080 .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
Neale Rannsd6953332021-08-10 07:39:18 +0000102void
103ip4_fib_hash_load_specials (u32 fib_index)
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100104{
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100105 /*
106 * add the special entries into the new FIB
107 */
108 int ii;
109
110 for (ii = 0; ii < ARRAY_LEN(ip4_specials); ii++)
111 {
112 fib_prefix_t prefix = ip4_specials[ii].ift_prefix;
113
114 prefix.fp_addr.ip4.data_u32 =
115 clib_host_to_net_u32(prefix.fp_addr.ip4.data_u32);
116
Neale Rannsd6953332021-08-10 07:39:18 +0000117 fib_table_entry_special_add(fib_index,
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100118 &prefix,
119 ip4_specials[ii].ift_source,
Neale Rannsa0558302017-04-13 00:44:52 -0700120 ip4_specials[ii].ift_flag);
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100121 }
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100122}
123
124void
Neale Rannsd6953332021-08-10 07:39:18 +0000125ip4_fib_hash_flush_specials (u32 fib_index)
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100126{
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100127 int ii;
128
129 /*
130 * remove all the specials we added when the table was created.
Neale Ranns04a75e32017-03-23 06:46:01 -0700131 * In reverse order so the default route is last.
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100132 */
Neale Ranns04a75e32017-03-23 06:46:01 -0700133 for (ii = ARRAY_LEN(ip4_specials) - 1; ii >= 0; ii--)
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100134 {
135 fib_prefix_t prefix = ip4_specials[ii].ift_prefix;
136
137 prefix.fp_addr.ip4.data_u32 =
138 clib_host_to_net_u32(prefix.fp_addr.ip4.data_u32);
139
Neale Rannsd6953332021-08-10 07:39:18 +0000140 fib_table_entry_special_remove(fib_index,
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100141 &prefix,
142 ip4_specials[ii].ift_source);
143 }
Neale Rannsd6953332021-08-10 07:39:18 +0000144}
145
146static u32
147ip4_create_fib_with_table_id (u32 table_id,
148 fib_source_t src)
149{
150 fib_table_t *fib_table;
151 ip4_fib_t *v4_fib;
152
153 pool_get(ip4_main.fibs, fib_table);
154 clib_memset(fib_table, 0, sizeof(*fib_table));
155
156 pool_get_aligned(ip4_fibs, v4_fib, CLIB_CACHE_LINE_BYTES);
157
158 fib_table->ft_proto = FIB_PROTOCOL_IP4;
159 fib_table->ft_index = (v4_fib - ip4_fibs);
160
161 /*
162 * It is required that the index of the fib_table_t in its pool
163 * is the same as the index of the ip4_fib_t in its pool, since the
164 * rest of the code usues the 'fib_index' to mean either of these
165 * objects, depending on the context.
166 */
167 ASSERT(fib_table->ft_index == fib_table - ip4_main.fibs);
168
169 hash_set (ip4_main.fib_index_by_table_id, table_id, fib_table->ft_index);
170
171 fib_table->ft_table_id =
172 v4_fib->hash.table_id =
173 table_id;
174 fib_table->ft_flow_hash_config = IP_FLOW_HASH_DEFAULT;
175
176 fib_table_lock(fib_table->ft_index, FIB_PROTOCOL_IP4, src);
177
178 ip4_fib_table_init(v4_fib);
179
180 /*
181 * add the special entries into the new FIB
182 */
183 ip4_fib_hash_load_specials(fib_table - ip4_main.fibs);
184
185 return (fib_table->ft_index);
186}
187
188void
189ip4_fib_table_destroy (u32 fib_index)
190{
191 fib_table_t *fib_table = pool_elt_at_index(ip4_main.fibs, fib_index);
192 ip4_fib_t *v4_fib = pool_elt_at_index(ip4_fibs, fib_table->ft_index);
193 u32 *n_locks;
194
195 /*
196 * remove all the specials we added when the table was created.
197 * In reverse order so the default route is last.
198 */
199 ip4_fib_hash_flush_specials(fib_table - ip4_main.fibs);
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100200
201 /*
202 * validate no more routes.
203 */
Benoît Gannecaaa6332023-09-13 17:21:04 +0200204 fib_table_assert_empty(fib_table);
Neale Ranns3bab8f92019-12-04 06:11:00 +0000205
206 vec_foreach(n_locks, fib_table->ft_src_route_counts)
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100207 {
Neale Ranns3bab8f92019-12-04 06:11:00 +0000208 ASSERT(0 == *n_locks);
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100209 }
210
211 if (~0 != fib_table->ft_table_id)
212 {
213 hash_unset (ip4_main.fib_index_by_table_id, fib_table->ft_table_id);
214 }
Neale Rannsa3af3372017-03-28 03:49:52 -0700215
Steven Luong221be7c2021-12-15 13:27:53 -0800216 vec_free (fib_table->ft_locks);
Neale Ranns3bab8f92019-12-04 06:11:00 +0000217 vec_free(fib_table->ft_src_route_counts);
Neale Rannsd6953332021-08-10 07:39:18 +0000218 ip4_fib_table_free(v4_fib);
Neale Rannsa3af3372017-03-28 03:49:52 -0700219
Neale Rannsd6953332021-08-10 07:39:18 +0000220 pool_put(ip4_fibs, v4_fib);
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100221 pool_put(ip4_main.fibs, fib_table);
222}
223
224
225u32
Neale Ranns15002542017-09-10 04:39:11 -0700226ip4_fib_table_find_or_create_and_lock (u32 table_id,
227 fib_source_t src)
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100228{
229 u32 index;
230
231 index = ip4_fib_index_from_table_id(table_id);
232 if (~0 == index)
Neale Ranns15002542017-09-10 04:39:11 -0700233 return ip4_create_fib_with_table_id(table_id, src);
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100234
Neale Ranns15002542017-09-10 04:39:11 -0700235 fib_table_lock(index, FIB_PROTOCOL_IP4, src);
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100236
237 return (index);
238}
239
240u32
Neale Ranns15002542017-09-10 04:39:11 -0700241ip4_fib_table_create_and_lock (fib_source_t src)
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100242{
Neale Ranns15002542017-09-10 04:39:11 -0700243 return (ip4_create_fib_with_table_id(~0, src));
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100244}
245
246u32
247ip4_fib_table_get_index_for_sw_if_index (u32 sw_if_index)
248{
249 if (sw_if_index >= vec_len(ip4_main.fib_index_by_sw_if_index))
250 {
251 /*
252 * This is the case for interfaces that are not yet mapped to
253 * a IP table
254 */
255 return (~0);
256 }
257 return (ip4_main.fib_index_by_sw_if_index[sw_if_index]);
258}
259
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100260
Neale Ranns32e1c012016-11-22 17:07:28 +0000261/**
262 * Walk show context
263 */
264typedef struct ip4_fib_show_walk_ctx_t_
265{
266 fib_node_index_t *ifsw_indicies;
267} ip4_fib_show_walk_ctx_t;
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100268
Neale Ranns89541992017-04-06 04:41:02 -0700269static fib_table_walk_rc_t
Neale Ranns32e1c012016-11-22 17:07:28 +0000270ip4_fib_show_walk_cb (fib_node_index_t fib_entry_index,
271 void *arg)
272{
273 ip4_fib_show_walk_ctx_t *ctx = arg;
274
275 vec_add1(ctx->ifsw_indicies, fib_entry_index);
276
Neale Ranns89541992017-04-06 04:41:02 -0700277 return (FIB_TABLE_WALK_CONTINUE);
Neale Ranns32e1c012016-11-22 17:07:28 +0000278}
279
280static void
281ip4_fib_table_show_all (ip4_fib_t *fib,
282 vlib_main_t * vm)
283{
284 ip4_fib_show_walk_ctx_t ctx = {
285 .ifsw_indicies = NULL,
286 };
287 fib_node_index_t *fib_entry_index;
288
289 ip4_fib_table_walk(fib, ip4_fib_show_walk_cb, &ctx);
290 vec_sort_with_function(ctx.ifsw_indicies,
291 fib_entry_cmp_for_sort);
292
293 vec_foreach(fib_entry_index, ctx.ifsw_indicies)
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100294 {
295 vlib_cli_output(vm, "%U",
296 format_fib_entry,
297 *fib_entry_index,
298 FIB_ENTRY_FORMAT_BRIEF);
299 }
300
Neale Ranns32e1c012016-11-22 17:07:28 +0000301 vec_free(ctx.ifsw_indicies);
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100302}
303
304static void
305ip4_fib_table_show_one (ip4_fib_t *fib,
306 vlib_main_t * vm,
307 ip4_address_t *address,
Neale Ranns88fc83e2017-04-05 08:11:14 -0700308 u32 mask_len,
309 int detail)
Dave Barach2c8e0022020-02-11 15:06:34 -0500310{
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100311 vlib_cli_output(vm, "%U",
312 format_fib_entry,
313 ip4_fib_table_lookup(fib, address, mask_len),
Neale Ranns88fc83e2017-04-05 08:11:14 -0700314 (detail ?
315 FIB_ENTRY_FORMAT_DETAIL2 :
316 FIB_ENTRY_FORMAT_DETAIL));
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100317}
318
Neale Rannsc87aafa2017-11-29 00:59:31 -0800319u8 *
320format_ip4_fib_table_memory (u8 * s, va_list * args)
321{
Damjan Marion8157a162020-09-16 17:06:45 +0200322 s = format(s, "%=30s %=6d\n",
Dave Barach6a5adc32018-07-04 10:56:23 -0400323 "IPv4 unicast",
Damjan Marion8157a162020-09-16 17:06:45 +0200324 pool_elts(ip4_main.fibs));
Neale Rannsc87aafa2017-11-29 00:59:31 -0800325 return (s);
326}
327
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100328static clib_error_t *
329ip4_show_fib (vlib_main_t * vm,
330 unformat_input_t * input,
331 vlib_cli_command_t * cmd)
332{
333 ip4_main_t * im4 = &ip4_main;
Neale Rannsc87aafa2017-11-29 00:59:31 -0800334 u64 total_mtrie_memory, total_hash_memory;
335 int verbose, matching, mtrie, memory;
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100336 ip4_address_t matching_address;
Neale Rannsd6953332021-08-10 07:39:18 +0000337 u32 fib_index, matching_mask = 32;
338 int i, table_id = -1, user_fib_index = ~0;
Neale Ranns88fc83e2017-04-05 08:11:14 -0700339 int detail = 0;
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100340
341 verbose = 1;
Neale Rannsc87aafa2017-11-29 00:59:31 -0800342 matching = mtrie = memory = 0;
343 total_hash_memory = total_mtrie_memory = 0;
344
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100345 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
346 {
347 if (unformat (input, "brief") || unformat (input, "summary")
348 || unformat (input, "sum"))
349 verbose = 0;
350
Neale Ranns88fc83e2017-04-05 08:11:14 -0700351 else if (unformat (input, "detail") || unformat (input, "det"))
352 detail = 1;
353
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100354 else if (unformat (input, "mtrie"))
355 mtrie = 1;
356
Neale Rannsc87aafa2017-11-29 00:59:31 -0800357 else if (unformat (input, "mem") ||
358 unformat (input, "memory"))
359 memory = 1;
360
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100361 else if (unformat (input, "%U/%d",
362 unformat_ip4_address, &matching_address, &matching_mask))
363 matching = 1;
364
365 else if (unformat (input, "%U", unformat_ip4_address, &matching_address))
366 matching = 1;
367
368 else if (unformat (input, "table %d", &table_id))
369 ;
Neale Rannsd6953332021-08-10 07:39:18 +0000370 else if (unformat (input, "index %d", &user_fib_index))
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100371 ;
372 else
373 break;
374 }
375
Neale Rannsd6953332021-08-10 07:39:18 +0000376 pool_foreach_index (fib_index, im4->fibs)
Damjan Marionb2c31b62020-12-13 21:47:40 +0100377 {
Neale Rannsd6953332021-08-10 07:39:18 +0000378 fib_table_t *fib_table = pool_elt_at_index(im4->fibs, fib_index);
379 ip4_fib_t *fib = pool_elt_at_index(ip4_fibs, fib_table->ft_index);
Neale Ranns15002542017-09-10 04:39:11 -0700380 fib_source_t source;
381 u8 *s = NULL;
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100382
Neale Rannsd6953332021-08-10 07:39:18 +0000383 if (table_id >= 0 && table_id != (int)fib->hash.table_id)
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100384 continue;
Neale Rannsd6953332021-08-10 07:39:18 +0000385 if (user_fib_index != ~0 && user_fib_index != fib_index)
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100386 continue;
387
Neale Rannsc87aafa2017-11-29 00:59:31 -0800388 if (memory)
389 {
Damjan Marion8157a162020-09-16 17:06:45 +0200390 uword mtrie_size, hash_size;
Lollita Liue18b45c2019-01-11 05:23:12 -0500391
Neale Rannsc87aafa2017-11-29 00:59:31 -0800392
Neale Rannsd6953332021-08-10 07:39:18 +0000393 mtrie_size = ip4_mtrie_memory_usage(&fib->mtrie);
Neale Rannsc87aafa2017-11-29 00:59:31 -0800394 hash_size = 0;
395
Neale Rannsd6953332021-08-10 07:39:18 +0000396 for (i = 0; i < ARRAY_LEN (fib->hash.fib_entry_by_dst_address); i++)
Neale Rannsc87aafa2017-11-29 00:59:31 -0800397 {
Neale Rannsd6953332021-08-10 07:39:18 +0000398 uword * hash = fib->hash.fib_entry_by_dst_address[i];
Neale Rannsc87aafa2017-11-29 00:59:31 -0800399 if (NULL != hash)
400 {
401 hash_size += hash_bytes(hash);
402 }
403 }
Lollita Liue18b45c2019-01-11 05:23:12 -0500404
Neale Rannsc87aafa2017-11-29 00:59:31 -0800405 if (verbose)
406 vlib_cli_output (vm, "%U mtrie:%d hash:%d",
Neale Rannsd6953332021-08-10 07:39:18 +0000407 format_fib_table_name, fib_index,
Neale Rannsc87aafa2017-11-29 00:59:31 -0800408 FIB_PROTOCOL_IP4,
409 mtrie_size,
410 hash_size);
411 total_mtrie_memory += mtrie_size;
412 total_hash_memory += hash_size;
413 continue;
414 }
415
Neale Ranns9db6ada2019-11-08 12:42:31 +0000416 s = format(s, "%U, fib_index:%d, flow hash:[%U] epoch:%d flags:%U locks:[",
Neale Rannsd6953332021-08-10 07:39:18 +0000417 format_fib_table_name, fib_index,
Neale Ranns15002542017-09-10 04:39:11 -0700418 FIB_PROTOCOL_IP4,
Neale Rannsd6953332021-08-10 07:39:18 +0000419 fib_index,
Neale Ranns15002542017-09-10 04:39:11 -0700420 format_ip_flow_hash_config,
Neale Ranns9db6ada2019-11-08 12:42:31 +0000421 fib_table->ft_flow_hash_config,
422 fib_table->ft_epoch,
423 format_fib_table_flags, fib_table->ft_flags);
Neale Ranns3bab8f92019-12-04 06:11:00 +0000424 vec_foreach_index(source, fib_table->ft_locks)
Neale Ranns15002542017-09-10 04:39:11 -0700425 {
426 if (0 != fib_table->ft_locks[source])
427 {
428 s = format(s, "%U:%d, ",
429 format_fib_source, source,
430 fib_table->ft_locks[source]);
431 }
432 }
433 s = format (s, "]");
Neale Ranns2297af02017-09-12 09:45:04 -0700434 vlib_cli_output (vm, "%v", s);
Neale Ranns15002542017-09-10 04:39:11 -0700435 vec_free(s);
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100436
437 /* Show summary? */
Neale Ranns39194252017-11-27 01:03:25 -0800438 if (mtrie)
439 {
Neale Rannsd6953332021-08-10 07:39:18 +0000440 vlib_cli_output (vm, "%U", format_ip4_mtrie, &fib->mtrie, verbose);
Neale Ranns39194252017-11-27 01:03:25 -0800441 continue;
442 }
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100443 if (! verbose)
444 {
445 vlib_cli_output (vm, "%=20s%=16s", "Prefix length", "Count");
Neale Rannsd6953332021-08-10 07:39:18 +0000446 for (i = 0; i < ARRAY_LEN (fib->hash.fib_entry_by_dst_address); i++)
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100447 {
Neale Rannsd6953332021-08-10 07:39:18 +0000448 uword * hash = fib->hash.fib_entry_by_dst_address[i];
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100449 uword n_elts = hash_elts (hash);
450 if (n_elts > 0)
451 vlib_cli_output (vm, "%20d%16d", i, n_elts);
452 }
453 continue;
454 }
455
456 if (!matching)
457 {
458 ip4_fib_table_show_all(fib, vm);
459 }
460 else
461 {
Neale Ranns88fc83e2017-04-05 08:11:14 -0700462 ip4_fib_table_show_one(fib, vm, &matching_address,
463 matching_mask, detail);
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100464 }
Damjan Marionb2c31b62020-12-13 21:47:40 +0100465 }
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100466
Neale Rannsc87aafa2017-11-29 00:59:31 -0800467 if (memory)
Lollita Liue18b45c2019-01-11 05:23:12 -0500468 {
Neale Rannsc87aafa2017-11-29 00:59:31 -0800469 vlib_cli_output (vm, "totals: mtrie:%ld hash:%ld all:%ld",
470 total_mtrie_memory,
471 total_hash_memory,
472 total_mtrie_memory + total_hash_memory);
Lollita Liue18b45c2019-01-11 05:23:12 -0500473 }
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100474 return 0;
475}
476
477/*?
Billy McFall0683c9c2016-10-13 08:27:31 -0400478 * This command displays the IPv4 FIB Tables (VRF Tables) and the route
479 * entries for each table.
480 *
481 * @note This command will run for a long time when the FIB tables are
Nathan Skrzypczakda331052021-09-29 15:28:26 +0200482 * comprised of millions of entries. For those scenarios, consider displaying
Billy McFall0683c9c2016-10-13 08:27:31 -0400483 * a single table or summary mode.
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100484 *
485 * @cliexpar
Billy McFall0683c9c2016-10-13 08:27:31 -0400486 * Example of how to display all the IPv4 FIB tables:
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100487 * @cliexstart{show ip fib}
Billy McFallebb9a6a2016-10-17 11:35:32 -0400488 * ipv4-VRF:0, fib_index 0, flow hash: src dst sport dport proto
489 * 0.0.0.0/0
490 * unicast-ip4-chain
491 * [@0]: dpo-load-balance: [index:0 buckets:1 uRPF:0 to:[0:0]]
492 * [0] [@0]: dpo-drop ip6
493 * 0.0.0.0/32
494 * unicast-ip4-chain
495 * [@0]: dpo-load-balance: [index:1 buckets:1 uRPF:1 to:[0:0]]
496 * [0] [@0]: dpo-drop ip6
497 * 6.0.1.2/32
498 * unicast-ip4-chain
499 * [@0]: dpo-load-balance: [index:30 buckets:1 uRPF:29 to:[0:0]]
500 * [0] [@3]: arp-ipv4: via 6.0.0.1 af_packet0
501 * 7.0.0.1/32
502 * unicast-ip4-chain
503 * [@0]: dpo-load-balance: [index:31 buckets:4 uRPF:30 to:[0:0]]
504 * [0] [@3]: arp-ipv4: via 6.0.0.2 af_packet0
505 * [1] [@3]: arp-ipv4: via 6.0.0.2 af_packet0
506 * [2] [@3]: arp-ipv4: via 6.0.0.2 af_packet0
507 * [3] [@3]: arp-ipv4: via 6.0.0.1 af_packet0
508 * 224.0.0.0/8
509 * unicast-ip4-chain
510 * [@0]: dpo-load-balance: [index:3 buckets:1 uRPF:3 to:[0:0]]
511 * [0] [@0]: dpo-drop ip6
512 * 240.0.0.0/8
513 * unicast-ip4-chain
514 * [@0]: dpo-load-balance: [index:2 buckets:1 uRPF:2 to:[0:0]]
515 * [0] [@0]: dpo-drop ip6
516 * 255.255.255.255/32
517 * unicast-ip4-chain
518 * [@0]: dpo-load-balance: [index:4 buckets:1 uRPF:4 to:[0:0]]
519 * [0] [@0]: dpo-drop ip6
520 * ipv4-VRF:7, fib_index 1, flow hash: src dst sport dport proto
521 * 0.0.0.0/0
522 * unicast-ip4-chain
523 * [@0]: dpo-load-balance: [index:12 buckets:1 uRPF:11 to:[0:0]]
524 * [0] [@0]: dpo-drop ip6
525 * 0.0.0.0/32
526 * unicast-ip4-chain
527 * [@0]: dpo-load-balance: [index:13 buckets:1 uRPF:12 to:[0:0]]
528 * [0] [@0]: dpo-drop ip6
529 * 172.16.1.0/24
530 * unicast-ip4-chain
531 * [@0]: dpo-load-balance: [index:17 buckets:1 uRPF:16 to:[0:0]]
532 * [0] [@4]: ipv4-glean: af_packet0
533 * 172.16.1.1/32
534 * unicast-ip4-chain
535 * [@0]: dpo-load-balance: [index:18 buckets:1 uRPF:17 to:[1:84]]
536 * [0] [@2]: dpo-receive: 172.16.1.1 on af_packet0
537 * 172.16.1.2/32
538 * unicast-ip4-chain
539 * [@0]: dpo-load-balance: [index:21 buckets:1 uRPF:20 to:[0:0]]
540 * [0] [@5]: ipv4 via 172.16.1.2 af_packet0: IP4: 02:fe:9e:70:7a:2b -> 26:a5:f6:9c:3a:36
541 * 172.16.2.0/24
542 * unicast-ip4-chain
543 * [@0]: dpo-load-balance: [index:19 buckets:1 uRPF:18 to:[0:0]]
544 * [0] [@4]: ipv4-glean: af_packet1
545 * 172.16.2.1/32
546 * unicast-ip4-chain
547 * [@0]: dpo-load-balance: [index:20 buckets:1 uRPF:19 to:[0:0]]
548 * [0] [@2]: dpo-receive: 172.16.2.1 on af_packet1
549 * 224.0.0.0/8
550 * unicast-ip4-chain
551 * [@0]: dpo-load-balance: [index:15 buckets:1 uRPF:14 to:[0:0]]
552 * [0] [@0]: dpo-drop ip6
553 * 240.0.0.0/8
554 * unicast-ip4-chain
555 * [@0]: dpo-load-balance: [index:14 buckets:1 uRPF:13 to:[0:0]]
556 * [0] [@0]: dpo-drop ip6
557 * 255.255.255.255/32
558 * unicast-ip4-chain
559 * [@0]: dpo-load-balance: [index:16 buckets:1 uRPF:15 to:[0:0]]
560 * [0] [@0]: dpo-drop ip6
Billy McFall0683c9c2016-10-13 08:27:31 -0400561 * @cliexend
562 * Example of how to display a single IPv4 FIB table:
563 * @cliexstart{show ip fib table 7}
Billy McFallebb9a6a2016-10-17 11:35:32 -0400564 * ipv4-VRF:7, fib_index 1, flow hash: src dst sport dport proto
565 * 0.0.0.0/0
566 * unicast-ip4-chain
567 * [@0]: dpo-load-balance: [index:12 buckets:1 uRPF:11 to:[0:0]]
568 * [0] [@0]: dpo-drop ip6
569 * 0.0.0.0/32
570 * unicast-ip4-chain
571 * [@0]: dpo-load-balance: [index:13 buckets:1 uRPF:12 to:[0:0]]
572 * [0] [@0]: dpo-drop ip6
573 * 172.16.1.0/24
574 * unicast-ip4-chain
575 * [@0]: dpo-load-balance: [index:17 buckets:1 uRPF:16 to:[0:0]]
576 * [0] [@4]: ipv4-glean: af_packet0
577 * 172.16.1.1/32
578 * unicast-ip4-chain
579 * [@0]: dpo-load-balance: [index:18 buckets:1 uRPF:17 to:[1:84]]
580 * [0] [@2]: dpo-receive: 172.16.1.1 on af_packet0
581 * 172.16.1.2/32
582 * unicast-ip4-chain
583 * [@0]: dpo-load-balance: [index:21 buckets:1 uRPF:20 to:[0:0]]
584 * [0] [@5]: ipv4 via 172.16.1.2 af_packet0: IP4: 02:fe:9e:70:7a:2b -> 26:a5:f6:9c:3a:36
585 * 172.16.2.0/24
586 * unicast-ip4-chain
587 * [@0]: dpo-load-balance: [index:19 buckets:1 uRPF:18 to:[0:0]]
588 * [0] [@4]: ipv4-glean: af_packet1
589 * 172.16.2.1/32
590 * unicast-ip4-chain
591 * [@0]: dpo-load-balance: [index:20 buckets:1 uRPF:19 to:[0:0]]
592 * [0] [@2]: dpo-receive: 172.16.2.1 on af_packet1
593 * 224.0.0.0/8
594 * unicast-ip4-chain
595 * [@0]: dpo-load-balance: [index:15 buckets:1 uRPF:14 to:[0:0]]
596 * [0] [@0]: dpo-drop ip6
597 * 240.0.0.0/8
598 * unicast-ip4-chain
599 * [@0]: dpo-load-balance: [index:14 buckets:1 uRPF:13 to:[0:0]]
600 * [0] [@0]: dpo-drop ip6
601 * 255.255.255.255/32
602 * unicast-ip4-chain
603 * [@0]: dpo-load-balance: [index:16 buckets:1 uRPF:15 to:[0:0]]
604 * [0] [@0]: dpo-drop ip6
Billy McFall0683c9c2016-10-13 08:27:31 -0400605 * @cliexend
606 * Example of how to display a summary of all IPv4 FIB tables:
607 * @cliexstart{show ip fib summary}
Billy McFallebb9a6a2016-10-17 11:35:32 -0400608 * ipv4-VRF:0, fib_index 0, flow hash: src dst sport dport proto
Billy McFall0683c9c2016-10-13 08:27:31 -0400609 * Prefix length Count
Billy McFallebb9a6a2016-10-17 11:35:32 -0400610 * 0 1
611 * 8 2
612 * 32 4
613 * ipv4-VRF:7, fib_index 1, flow hash: src dst sport dport proto
Billy McFall0683c9c2016-10-13 08:27:31 -0400614 * Prefix length Count
Billy McFallebb9a6a2016-10-17 11:35:32 -0400615 * 0 1
616 * 8 2
617 * 24 2
618 * 32 4
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100619 * @cliexend
620 ?*/
621VLIB_CLI_COMMAND (ip4_show_fib_command, static) = {
622 .path = "show ip fib",
Neale Ranns88fc83e2017-04-05 08:11:14 -0700623 .short_help = "show ip fib [summary] [table <table-id>] [index <fib-id>] [<ip4-addr>[/<mask>]] [mtrie] [detail]",
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100624 .function = ip4_show_fib,
625};
Jon Loeligerd465fd02024-03-22 12:22:36 -0500626
627static clib_error_t *
628ip_config (vlib_main_t * vm, unformat_input_t * input)
629{
630 char *default_name = 0;
631
632 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
633 {
634 if (unformat (input, "default-table-name %s", &default_name))
635 ;
636 else
637 return clib_error_return (0, "unknown input '%U'",
638 format_unformat_error, input);
639 }
640
641 fib_table_default_names[FIB_PROTOCOL_IP4] = default_name;
642
643 return 0;
644}
645
646VLIB_EARLY_CONFIG_FUNCTION (ip_config, "ip");