blob: 002971400fe974a4d27cfa708f127de9733e604d [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/ip6_fib.h>
17#include <vnet/fib/fib_table.h>
18
19static void
20vnet_ip6_fib_init (u32 fib_index)
21{
22 fib_prefix_t pfx = {
23 .fp_proto = FIB_PROTOCOL_IP6,
24 .fp_len = 0,
25 .fp_addr = {
26 .ip6 = {
27 { 0, 0, },
28 },
29 }
30 };
31
32 /*
33 * Add the default route.
34 */
35 fib_table_entry_special_add(fib_index,
36 &pfx,
37 FIB_SOURCE_DEFAULT_ROUTE,
38 FIB_ENTRY_FLAG_DROP,
39 ADJ_INDEX_INVALID);
40
41 /*
Neale Ranns0bfe5d82016-08-25 15:29:12 +010042 * all link local for us
43 */
44 pfx.fp_addr.ip6.as_u64[0] = clib_host_to_net_u64 (0xFE80000000000000ULL);
45 pfx.fp_addr.ip6.as_u64[1] = 0;
46 pfx.fp_len = 10;
47 fib_table_entry_special_add(fib_index,
48 &pfx,
49 FIB_SOURCE_SPECIAL,
50 FIB_ENTRY_FLAG_LOCAL,
51 ADJ_INDEX_INVALID);
52}
53
54static u32
55create_fib_with_table_id (u32 table_id)
56{
57 fib_table_t *fib_table;
Neale Rannsa3af3372017-03-28 03:49:52 -070058 ip6_fib_t *v6_fib;
Neale Ranns0bfe5d82016-08-25 15:29:12 +010059
60 pool_get_aligned(ip6_main.fibs, fib_table, CLIB_CACHE_LINE_BYTES);
Neale Rannsa3af3372017-03-28 03:49:52 -070061 pool_get_aligned(ip6_main.v6_fibs, v6_fib, CLIB_CACHE_LINE_BYTES);
Neale Ranns0bfe5d82016-08-25 15:29:12 +010062
Neale Rannsa3af3372017-03-28 03:49:52 -070063 memset(fib_table, 0, sizeof(*fib_table));
64 memset(v6_fib, 0, sizeof(*v6_fib));
65
66 ASSERT((fib_table - ip6_main.fibs) ==
67 (v6_fib - ip6_main.v6_fibs));
68
Neale Ranns0bfe5d82016-08-25 15:29:12 +010069 fib_table->ft_proto = FIB_PROTOCOL_IP6;
70 fib_table->ft_index =
Neale Rannsa3af3372017-03-28 03:49:52 -070071 v6_fib->index =
72 (fib_table - ip6_main.fibs);
Neale Ranns0bfe5d82016-08-25 15:29:12 +010073
74 hash_set(ip6_main.fib_index_by_table_id, table_id, fib_table->ft_index);
75
76 fib_table->ft_table_id =
Neale Rannsa3af3372017-03-28 03:49:52 -070077 v6_fib->table_id =
Neale Ranns0bfe5d82016-08-25 15:29:12 +010078 table_id;
79 fib_table->ft_flow_hash_config =
Neale Rannsa3af3372017-03-28 03:49:52 -070080 v6_fib->flow_hash_config =
Neale Ranns0bfe5d82016-08-25 15:29:12 +010081 IP_FLOW_HASH_DEFAULT;
82
83 vnet_ip6_fib_init(fib_table->ft_index);
84 fib_table_lock(fib_table->ft_index, FIB_PROTOCOL_IP6);
85
86 return (fib_table->ft_index);
87}
88
89u32
90ip6_fib_table_find_or_create_and_lock (u32 table_id)
91{
92 uword * p;
93
94 p = hash_get (ip6_main.fib_index_by_table_id, table_id);
95 if (NULL == p)
96 return create_fib_with_table_id(table_id);
97
98 fib_table_lock(p[0], FIB_PROTOCOL_IP6);
99
100 return (p[0]);
101}
102
103u32
104ip6_fib_table_create_and_lock (void)
105{
106 return (create_fib_with_table_id(~0));
107}
108
109void
110ip6_fib_table_destroy (u32 fib_index)
111{
112 fib_prefix_t pfx = {
113 .fp_proto = FIB_PROTOCOL_IP6,
114 .fp_len = 0,
115 .fp_addr = {
116 .ip6 = {
117 { 0, 0, },
118 },
119 }
120 };
121
122 /*
123 * the default route.
124 */
125 fib_table_entry_special_remove(fib_index,
126 &pfx,
127 FIB_SOURCE_DEFAULT_ROUTE);
128
129
130 /*
131 * ff02::1:ff00:0/104
132 */
133 ip6_set_solicited_node_multicast_address(&pfx.fp_addr.ip6, 0);
134 pfx.fp_len = 104;
135 fib_table_entry_special_remove(fib_index,
136 &pfx,
137 FIB_SOURCE_SPECIAL);
138
139 /*
140 * all-routers multicast address
141 */
142 ip6_set_reserved_multicast_address (&pfx.fp_addr.ip6,
143 IP6_MULTICAST_SCOPE_link_local,
144 IP6_MULTICAST_GROUP_ID_all_routers);
145 pfx.fp_len = 128;
146 fib_table_entry_special_remove(fib_index,
147 &pfx,
148 FIB_SOURCE_SPECIAL);
149
150 /*
151 * all-nodes multicast address
152 */
153 ip6_set_reserved_multicast_address (&pfx.fp_addr.ip6,
154 IP6_MULTICAST_SCOPE_link_local,
155 IP6_MULTICAST_GROUP_ID_all_hosts);
156 pfx.fp_len = 128;
157 fib_table_entry_special_remove(fib_index,
158 &pfx,
159 FIB_SOURCE_SPECIAL);
160
161 /*
162 * all-mldv2 multicast address
163 */
164 ip6_set_reserved_multicast_address (&pfx.fp_addr.ip6,
165 IP6_MULTICAST_SCOPE_link_local,
166 IP6_MULTICAST_GROUP_ID_mldv2_routers);
167 pfx.fp_len = 128;
168 fib_table_entry_special_remove(fib_index,
169 &pfx,
170 FIB_SOURCE_SPECIAL);
171
172 /*
173 * all link local
174 */
175 pfx.fp_addr.ip6.as_u64[0] = clib_host_to_net_u64 (0xFE80000000000000ULL);
176 pfx.fp_addr.ip6.as_u64[1] = 0;
177 pfx.fp_len = 10;
178 fib_table_entry_special_remove(fib_index,
179 &pfx,
180 FIB_SOURCE_SPECIAL);
181
182 fib_table_t *fib_table = fib_table_get(fib_index, FIB_PROTOCOL_IP6);
183 fib_source_t source;
184
185 /*
186 * validate no more routes.
187 */
188 ASSERT(0 == fib_table->ft_total_route_counts);
189 FOR_EACH_FIB_SOURCE(source)
190 {
191 ASSERT(0 == fib_table->ft_src_route_counts[source]);
192 }
193
194 if (~0 != fib_table->ft_table_id)
195 {
196 hash_unset (ip6_main.fib_index_by_table_id, fib_table->ft_table_id);
197 }
Neale Rannsa3af3372017-03-28 03:49:52 -0700198 pool_put_index(ip6_main.v6_fibs, fib_table->ft_index);
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100199 pool_put(ip6_main.fibs, fib_table);
200}
201
202fib_node_index_t
203ip6_fib_table_lookup (u32 fib_index,
204 const ip6_address_t *addr,
205 u32 len)
206{
207 const ip6_fib_table_instance_t *table;
208 BVT(clib_bihash_kv) kv, value;
209 int i, n_p, rv;
210 u64 fib;
211
212 table = &ip6_main.ip6_table[IP6_FIB_TABLE_NON_FWDING];
213 n_p = vec_len (table->prefix_lengths_in_search_order);
214
215 kv.key[0] = addr->as_u64[0];
216 kv.key[1] = addr->as_u64[1];
217 fib = ((u64)((fib_index))<<32);
218
219 /*
220 * start search from a mask length same length or shorter.
221 * we don't want matches longer than the mask passed
222 */
223 i = 0;
224 while (i < n_p && table->prefix_lengths_in_search_order[i] > len)
225 {
226 i++;
227 }
228
229 for (; i < n_p; i++)
230 {
231 int dst_address_length = table->prefix_lengths_in_search_order[i];
232 ip6_address_t * mask = &ip6_main.fib_masks[dst_address_length];
233
234 ASSERT(dst_address_length >= 0 && dst_address_length <= 128);
235 //As lengths are decreasing, masks are increasingly specific.
236 kv.key[0] &= mask->as_u64[0];
237 kv.key[1] &= mask->as_u64[1];
238 kv.key[2] = fib | dst_address_length;
239
240 rv = BV(clib_bihash_search_inline_2)(&table->ip6_hash, &kv, &value);
241 if (rv == 0)
242 return value.value;
243 }
244
245 return (FIB_NODE_INDEX_INVALID);
246}
247
248fib_node_index_t
249ip6_fib_table_lookup_exact_match (u32 fib_index,
250 const ip6_address_t *addr,
251 u32 len)
252{
253 const ip6_fib_table_instance_t *table;
254 BVT(clib_bihash_kv) kv, value;
255 ip6_address_t *mask;
256 u64 fib;
257 int rv;
258
259 table = &ip6_main.ip6_table[IP6_FIB_TABLE_NON_FWDING];
260 mask = &ip6_main.fib_masks[len];
261 fib = ((u64)((fib_index))<<32);
262
263 kv.key[0] = addr->as_u64[0] & mask->as_u64[0];
264 kv.key[1] = addr->as_u64[1] & mask->as_u64[1];
265 kv.key[2] = fib | len;
266
267 rv = BV(clib_bihash_search_inline_2)(&table->ip6_hash, &kv, &value);
268 if (rv == 0)
269 return value.value;
270
271 return (FIB_NODE_INDEX_INVALID);
272}
273
274static void
275compute_prefix_lengths_in_search_order (ip6_fib_table_instance_t *table)
276{
277 int i;
278 vec_reset_length (table->prefix_lengths_in_search_order);
279 /* Note: bitmap reversed so this is in fact a longest prefix match */
280 clib_bitmap_foreach (i, table->non_empty_dst_address_length_bitmap,
281 ({
282 int dst_address_length = 128 - i;
283 vec_add1(table->prefix_lengths_in_search_order, dst_address_length);
284 }));
285}
286
287void
288ip6_fib_table_entry_remove (u32 fib_index,
289 const ip6_address_t *addr,
290 u32 len)
291{
292 ip6_fib_table_instance_t *table;
293 BVT(clib_bihash_kv) kv;
294 ip6_address_t *mask;
295 u64 fib;
296
297 table = &ip6_main.ip6_table[IP6_FIB_TABLE_NON_FWDING];
298 mask = &ip6_main.fib_masks[len];
299 fib = ((u64)((fib_index))<<32);
300
301 kv.key[0] = addr->as_u64[0] & mask->as_u64[0];
302 kv.key[1] = addr->as_u64[1] & mask->as_u64[1];
303 kv.key[2] = fib | len;
304
305 BV(clib_bihash_add_del)(&table->ip6_hash, &kv, 0);
306
307 /* refcount accounting */
308 ASSERT (table->dst_address_length_refcounts[len] > 0);
309 if (--table->dst_address_length_refcounts[len] == 0)
310 {
311 table->non_empty_dst_address_length_bitmap =
312 clib_bitmap_set (table->non_empty_dst_address_length_bitmap,
313 128 - len, 0);
314 compute_prefix_lengths_in_search_order (table);
315 }
316}
317
318void
319ip6_fib_table_entry_insert (u32 fib_index,
320 const ip6_address_t *addr,
321 u32 len,
322 fib_node_index_t fib_entry_index)
323{
324 ip6_fib_table_instance_t *table;
325 BVT(clib_bihash_kv) kv;
326 ip6_address_t *mask;
327 u64 fib;
328
329 table = &ip6_main.ip6_table[IP6_FIB_TABLE_NON_FWDING];
330 mask = &ip6_main.fib_masks[len];
331 fib = ((u64)((fib_index))<<32);
332
333 kv.key[0] = addr->as_u64[0] & mask->as_u64[0];
334 kv.key[1] = addr->as_u64[1] & mask->as_u64[1];
335 kv.key[2] = fib | len;
336 kv.value = fib_entry_index;
337
338 BV(clib_bihash_add_del)(&table->ip6_hash, &kv, 1);
339
340 table->dst_address_length_refcounts[len]++;
341
342 table->non_empty_dst_address_length_bitmap =
343 clib_bitmap_set (table->non_empty_dst_address_length_bitmap,
344 128 - len, 1);
345 compute_prefix_lengths_in_search_order (table);
346}
347
348u32
349ip6_fib_table_fwding_lookup (ip6_main_t * im,
350 u32 fib_index,
351 const ip6_address_t * dst)
352{
353 const ip6_fib_table_instance_t *table;
354 int i, len;
355 int rv;
356 BVT(clib_bihash_kv) kv, value;
357 u64 fib;
358
359 table = &ip6_main.ip6_table[IP6_FIB_TABLE_FWDING];
360 len = vec_len (table->prefix_lengths_in_search_order);
361
362 kv.key[0] = dst->as_u64[0];
363 kv.key[1] = dst->as_u64[1];
364 fib = ((u64)((fib_index))<<32);
365
366 for (i = 0; i < len; i++)
367 {
368 int dst_address_length = table->prefix_lengths_in_search_order[i];
369 ip6_address_t * mask = &ip6_main.fib_masks[dst_address_length];
370
371 ASSERT(dst_address_length >= 0 && dst_address_length <= 128);
372 //As lengths are decreasing, masks are increasingly specific.
373 kv.key[0] &= mask->as_u64[0];
374 kv.key[1] &= mask->as_u64[1];
375 kv.key[2] = fib | dst_address_length;
376
377 rv = BV(clib_bihash_search_inline_2)(&table->ip6_hash, &kv, &value);
378 if (rv == 0)
379 return value.value;
380 }
381
382 /* default route is always present */
383 ASSERT(0);
384 return 0;
385}
386
387u32 ip6_fib_table_fwding_lookup_with_if_index (ip6_main_t * im,
388 u32 sw_if_index,
389 const ip6_address_t * dst)
390{
391 u32 fib_index = vec_elt (im->fib_index_by_sw_if_index, sw_if_index);
392 return ip6_fib_table_fwding_lookup(im, fib_index, dst);
393}
394
395flow_hash_config_t
396ip6_fib_table_get_flow_hash_config (u32 fib_index)
397{
398 return (ip6_fib_get(fib_index)->flow_hash_config);
399}
400
401u32
402ip6_fib_table_get_index_for_sw_if_index (u32 sw_if_index)
403{
404 if (sw_if_index >= vec_len(ip6_main.fib_index_by_sw_if_index))
405 {
406 /*
407 * This is the case for interfaces that are not yet mapped to
408 * a IP table
409 */
410 return (~0);
411 }
412 return (ip6_main.fib_index_by_sw_if_index[sw_if_index]);
413}
414
415void
416ip6_fib_table_fwding_dpo_update (u32 fib_index,
417 const ip6_address_t *addr,
418 u32 len,
419 const dpo_id_t *dpo)
420{
421 ip6_fib_table_instance_t *table;
422 BVT(clib_bihash_kv) kv;
423 ip6_address_t *mask;
424 u64 fib;
425
426 table = &ip6_main.ip6_table[IP6_FIB_TABLE_FWDING];
427 mask = &ip6_main.fib_masks[len];
428 fib = ((u64)((fib_index))<<32);
429
430 kv.key[0] = addr->as_u64[0] & mask->as_u64[0];
431 kv.key[1] = addr->as_u64[1] & mask->as_u64[1];
432 kv.key[2] = fib | len;
433 kv.value = dpo->dpoi_index;
434
435 BV(clib_bihash_add_del)(&table->ip6_hash, &kv, 1);
436
437 table->dst_address_length_refcounts[len]++;
438
439 table->non_empty_dst_address_length_bitmap =
440 clib_bitmap_set (table->non_empty_dst_address_length_bitmap,
441 128 - len, 1);
442 compute_prefix_lengths_in_search_order (table);
443}
444
445void
446ip6_fib_table_fwding_dpo_remove (u32 fib_index,
447 const ip6_address_t *addr,
448 u32 len,
449 const dpo_id_t *dpo)
450{
451 ip6_fib_table_instance_t *table;
452 BVT(clib_bihash_kv) kv;
453 ip6_address_t *mask;
454 u64 fib;
455
456 table = &ip6_main.ip6_table[IP6_FIB_TABLE_FWDING];
457 mask = &ip6_main.fib_masks[len];
458 fib = ((u64)((fib_index))<<32);
459
460 kv.key[0] = addr->as_u64[0] & mask->as_u64[0];
461 kv.key[1] = addr->as_u64[1] & mask->as_u64[1];
462 kv.key[2] = fib | len;
463 kv.value = dpo->dpoi_index;
464
465 BV(clib_bihash_add_del)(&table->ip6_hash, &kv, 0);
466
467 /* refcount accounting */
468 ASSERT (table->dst_address_length_refcounts[len] > 0);
469 if (--table->dst_address_length_refcounts[len] == 0)
470 {
471 table->non_empty_dst_address_length_bitmap =
Neale Ranns32e1c012016-11-22 17:07:28 +0000472 clib_bitmap_set (table->non_empty_dst_address_length_bitmap,
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100473 128 - len, 0);
474 compute_prefix_lengths_in_search_order (table);
475 }
476}
477
Neale Ranns32e1c012016-11-22 17:07:28 +0000478/**
479 * @brief Context when walking the IPv6 table. Since all VRFs are in the
480 * same hash table, we need to filter only those we need as we walk
481 */
482typedef struct ip6_fib_walk_ctx_t_
483{
484 u32 i6w_fib_index;
485 fib_table_walk_fn_t i6w_fn;
486 void *i6w_ctx;
487} ip6_fib_walk_ctx_t;
488
489static int
490ip6_fib_walk_cb (clib_bihash_kv_24_8_t * kvp,
491 void *arg)
492{
493 ip6_fib_walk_ctx_t *ctx = arg;
494
495 if ((kvp->key[2] >> 32) == ctx->i6w_fib_index)
496 {
497 ctx->i6w_fn(kvp->value, ctx->i6w_ctx);
498 }
499
500 return (1);
501}
502
503void
504ip6_fib_table_walk (u32 fib_index,
505 fib_table_walk_fn_t fn,
506 void *arg)
507{
508 ip6_fib_walk_ctx_t ctx = {
509 .i6w_fib_index = fib_index,
510 .i6w_fn = fn,
511 .i6w_ctx = arg,
512 };
513 ip6_main_t *im = &ip6_main;
514
515 BV(clib_bihash_foreach_key_value_pair)(&im->ip6_table[IP6_FIB_TABLE_NON_FWDING].ip6_hash,
516 ip6_fib_walk_cb,
517 &ctx);
518
519}
520
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100521typedef struct ip6_fib_show_ctx_t_ {
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100522 fib_node_index_t *entries;
523} ip6_fib_show_ctx_t;
524
Neale Ranns32e1c012016-11-22 17:07:28 +0000525static int
526ip6_fib_table_show_walk (fib_node_index_t fib_entry_index,
527 void *arg)
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100528{
529 ip6_fib_show_ctx_t *ctx = arg;
530
Neale Ranns32e1c012016-11-22 17:07:28 +0000531 vec_add1(ctx->entries, fib_entry_index);
532
533 return (1);
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100534}
535
536static void
537ip6_fib_table_show_all (ip6_fib_t *fib,
538 vlib_main_t * vm)
539{
540 fib_node_index_t *fib_entry_index;
541 ip6_fib_show_ctx_t ctx = {
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100542 .entries = NULL,
543 };
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100544
Neale Ranns32e1c012016-11-22 17:07:28 +0000545 ip6_fib_table_walk(fib->index, ip6_fib_table_show_walk, &ctx);
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100546 vec_sort_with_function(ctx.entries, fib_entry_cmp_for_sort);
547
548 vec_foreach(fib_entry_index, ctx.entries)
549 {
550 vlib_cli_output(vm, "%U",
551 format_fib_entry,
552 *fib_entry_index,
553 FIB_ENTRY_FORMAT_BRIEF);
554 }
555
556 vec_free(ctx.entries);
557}
558
559static void
560ip6_fib_table_show_one (ip6_fib_t *fib,
561 vlib_main_t * vm,
562 ip6_address_t *address,
Neale Ranns88fc83e2017-04-05 08:11:14 -0700563 u32 mask_len,
564 int detail)
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100565{
566 vlib_cli_output(vm, "%U",
567 format_fib_entry,
568 ip6_fib_table_lookup(fib->index, address, mask_len),
Neale Ranns88fc83e2017-04-05 08:11:14 -0700569 (detail ?
570 FIB_ENTRY_FORMAT_DETAIL2:
571 FIB_ENTRY_FORMAT_DETAIL));
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100572}
573
574typedef struct {
575 u32 fib_index;
576 u64 count_by_prefix_length[129];
577} count_routes_in_fib_at_prefix_length_arg_t;
578
Neale Ranns88fc83e2017-04-05 08:11:14 -0700579static void
580count_routes_in_fib_at_prefix_length (BVT(clib_bihash_kv) * kvp,
581 void *arg)
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100582{
583 count_routes_in_fib_at_prefix_length_arg_t * ap = arg;
584 int mask_width;
585
586 if ((kvp->key[2]>>32) != ap->fib_index)
587 return;
588
589 mask_width = kvp->key[2] & 0xFF;
590
591 ap->count_by_prefix_length[mask_width]++;
592}
593
594static clib_error_t *
595ip6_show_fib (vlib_main_t * vm,
596 unformat_input_t * input,
597 vlib_cli_command_t * cmd)
598{
599 count_routes_in_fib_at_prefix_length_arg_t _ca, *ca = &_ca;
600 ip6_main_t * im6 = &ip6_main;
601 fib_table_t *fib_table;
602 ip6_fib_t * fib;
603 int verbose, matching;
604 ip6_address_t matching_address;
605 u32 mask_len = 128;
606 int table_id = -1, fib_index = ~0;
Neale Ranns88fc83e2017-04-05 08:11:14 -0700607 int detail = 0;
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100608
609 verbose = 1;
610 matching = 0;
611
612 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
613 {
614 if (unformat (input, "brief") ||
615 unformat (input, "summary") ||
616 unformat (input, "sum"))
617 verbose = 0;
Neale Ranns88fc83e2017-04-05 08:11:14 -0700618
619 else if (unformat (input, "detail") ||
620 unformat (input, "det"))
621 detail = 1;
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100622
623 else if (unformat (input, "%U/%d",
624 unformat_ip6_address, &matching_address, &mask_len))
625 matching = 1;
626
627 else if (unformat (input, "%U", unformat_ip6_address, &matching_address))
628 matching = 1;
629
630 else if (unformat (input, "table %d", &table_id))
631 ;
632 else if (unformat (input, "index %d", &fib_index))
633 ;
634 else
635 break;
636 }
637
638 pool_foreach (fib_table, im6->fibs,
639 ({
Neale Rannsa3af3372017-03-28 03:49:52 -0700640 fib = pool_elt_at_index(im6->v6_fibs, fib_table->ft_index);
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100641 if (table_id >= 0 && table_id != (int)fib->table_id)
642 continue;
643 if (fib_index != ~0 && fib_index != (int)fib->index)
644 continue;
645
646 vlib_cli_output (vm, "%s, fib_index %d, flow hash: %U",
647 fib_table->ft_desc, fib->index,
648 format_ip_flow_hash_config, fib->flow_hash_config);
649
650 /* Show summary? */
651 if (! verbose)
652 {
653 BVT(clib_bihash) * h = &im6->ip6_table[IP6_FIB_TABLE_NON_FWDING].ip6_hash;
654 int len;
655
656 vlib_cli_output (vm, "%=20s%=16s", "Prefix length", "Count");
657
658 memset (ca, 0, sizeof(*ca));
659 ca->fib_index = fib->index;
660
661 BV(clib_bihash_foreach_key_value_pair)
662 (h, count_routes_in_fib_at_prefix_length, ca);
663
664 for (len = 128; len >= 0; len--)
665 {
666 if (ca->count_by_prefix_length[len])
667 vlib_cli_output (vm, "%=20d%=16lld",
668 len, ca->count_by_prefix_length[len]);
669 }
670 continue;
671 }
672
673 if (!matching)
674 {
675 ip6_fib_table_show_all(fib, vm);
676 }
677 else
678 {
Neale Ranns88fc83e2017-04-05 08:11:14 -0700679 ip6_fib_table_show_one(fib, vm, &matching_address, mask_len, detail);
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100680 }
681 }));
682
683 return 0;
684}
685
686/*?
Billy McFall0683c9c2016-10-13 08:27:31 -0400687 * This command displays the IPv6 FIB Tables (VRF Tables) and the route
688 * entries for each table.
689 *
690 * @note This command will run for a long time when the FIB tables are
691 * comprised of millions of entries. For those senarios, consider displaying
692 * in summary mode.
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100693 *
694 * @cliexpar
Billy McFall0683c9c2016-10-13 08:27:31 -0400695 * @parblock
696 * Example of how to display all the IPv6 FIB tables:
697 * @cliexstart{show ip6 fib}
Billy McFallebb9a6a2016-10-17 11:35:32 -0400698 * ipv6-VRF:0, fib_index 0, flow hash: src dst sport dport proto
699 * @::/0
700 * unicast-ip6-chain
701 * [@0]: dpo-load-balance: [index:5 buckets:1 uRPF:5 to:[0:0]]
702 * [0] [@0]: dpo-drop ip6
703 * fe80::/10
704 * unicast-ip6-chain
705 * [@0]: dpo-load-balance: [index:10 buckets:1 uRPF:10 to:[0:0]]
706 * [0] [@2]: dpo-receive
707 * ff02::1/128
708 * unicast-ip6-chain
709 * [@0]: dpo-load-balance: [index:8 buckets:1 uRPF:8 to:[0:0]]
710 * [0] [@2]: dpo-receive
711 * ff02::2/128
712 * unicast-ip6-chain
713 * [@0]: dpo-load-balance: [index:7 buckets:1 uRPF:7 to:[0:0]]
714 * [0] [@2]: dpo-receive
715 * ff02::16/128
716 * unicast-ip6-chain
717 * [@0]: dpo-load-balance: [index:9 buckets:1 uRPF:9 to:[0:0]]
718 * [0] [@2]: dpo-receive
719 * ff02::1:ff00:0/104
720 * unicast-ip6-chain
721 * [@0]: dpo-load-balance: [index:6 buckets:1 uRPF:6 to:[0:0]]
722 * [0] [@2]: dpo-receive
723 * ipv6-VRF:8, fib_index 1, flow hash: src dst sport dport proto
724 * @::/0
725 * unicast-ip6-chain
726 * [@0]: dpo-load-balance: [index:21 buckets:1 uRPF:20 to:[0:0]]
727 * [0] [@0]: dpo-drop ip6
728 * @::a:1:1:0:4/126
729 * unicast-ip6-chain
730 * [@0]: dpo-load-balance: [index:27 buckets:1 uRPF:26 to:[0:0]]
731 * [0] [@4]: ipv6-glean: af_packet0
732 * @::a:1:1:0:7/128
733 * unicast-ip6-chain
734 * [@0]: dpo-load-balance: [index:28 buckets:1 uRPF:27 to:[0:0]]
735 * [0] [@2]: dpo-receive: @::a:1:1:0:7 on af_packet0
736 * fe80::/10
737 * unicast-ip6-chain
738 * [@0]: dpo-load-balance: [index:26 buckets:1 uRPF:25 to:[0:0]]
739 * [0] [@2]: dpo-receive
740 * fe80::fe:3eff:fe3e:9222/128
741 * unicast-ip6-chain
742 * [@0]: dpo-load-balance: [index:29 buckets:1 uRPF:28 to:[0:0]]
743 * [0] [@2]: dpo-receive: fe80::fe:3eff:fe3e:9222 on af_packet0
744 * ff02::1/128
745 * unicast-ip6-chain
746 * [@0]: dpo-load-balance: [index:24 buckets:1 uRPF:23 to:[0:0]]
747 * [0] [@2]: dpo-receive
748 * ff02::2/128
749 * unicast-ip6-chain
750 * [@0]: dpo-load-balance: [index:23 buckets:1 uRPF:22 to:[0:0]]
751 * [0] [@2]: dpo-receive
752 * ff02::16/128
753 * unicast-ip6-chain
754 * [@0]: dpo-load-balance: [index:25 buckets:1 uRPF:24 to:[0:0]]
755 * [0] [@2]: dpo-receive
756 * ff02::1:ff00:0/104
757 * unicast-ip6-chain
758 * [@0]: dpo-load-balance: [index:22 buckets:1 uRPF:21 to:[0:0]]
759 * [0] [@2]: dpo-receive
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100760 * @cliexend
Billy McFallebb9a6a2016-10-17 11:35:32 -0400761 *
Billy McFall0683c9c2016-10-13 08:27:31 -0400762 * Example of how to display a summary of all IPv6 FIB tables:
763 * @cliexstart{show ip6 fib summary}
Billy McFallebb9a6a2016-10-17 11:35:32 -0400764 * ipv6-VRF:0, fib_index 0, flow hash: src dst sport dport proto
Billy McFall0683c9c2016-10-13 08:27:31 -0400765 * Prefix length Count
766 * 128 3
767 * 104 1
Billy McFallebb9a6a2016-10-17 11:35:32 -0400768 * 10 1
769 * 0 1
770 * ipv6-VRF:8, fib_index 1, flow hash: src dst sport dport proto
Billy McFall0683c9c2016-10-13 08:27:31 -0400771 * Prefix length Count
772 * 128 5
773 * 126 1
774 * 104 1
Billy McFallebb9a6a2016-10-17 11:35:32 -0400775 * 10 1
776 * 0 1
Billy McFall0683c9c2016-10-13 08:27:31 -0400777 * @cliexend
778 * @endparblock
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100779 ?*/
Billy McFall0683c9c2016-10-13 08:27:31 -0400780/* *INDENT-OFF* */
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100781VLIB_CLI_COMMAND (ip6_show_fib_command, static) = {
782 .path = "show ip6 fib",
Neale Ranns88fc83e2017-04-05 08:11:14 -0700783 .short_help = "show ip6 fib [summary] [table <table-id>] [index <fib-id>] [<ip6-addr>[/<width>]] [detail]",
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100784 .function = ip6_show_fib,
785};
Billy McFall0683c9c2016-10-13 08:27:31 -0400786/* *INDENT-ON* */