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