blob: 3ddb8453eaad612347fac30b105dcb2961cfaf55 [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
Neale Ranns15002542017-09-10 04:39:11 -070053create_fib_with_table_id (u32 table_id,
54 fib_source_t src)
Neale Ranns0bfe5d82016-08-25 15:29:12 +010055{
56 fib_table_t *fib_table;
Neale Rannsa3af3372017-03-28 03:49:52 -070057 ip6_fib_t *v6_fib;
Neale Ranns0bfe5d82016-08-25 15:29:12 +010058
59 pool_get_aligned(ip6_main.fibs, fib_table, CLIB_CACHE_LINE_BYTES);
Neale Rannsa3af3372017-03-28 03:49:52 -070060 pool_get_aligned(ip6_main.v6_fibs, v6_fib, CLIB_CACHE_LINE_BYTES);
Neale Ranns0bfe5d82016-08-25 15:29:12 +010061
Neale Rannsa3af3372017-03-28 03:49:52 -070062 memset(fib_table, 0, sizeof(*fib_table));
63 memset(v6_fib, 0, sizeof(*v6_fib));
64
65 ASSERT((fib_table - ip6_main.fibs) ==
66 (v6_fib - ip6_main.v6_fibs));
67
Neale Ranns0bfe5d82016-08-25 15:29:12 +010068 fib_table->ft_proto = FIB_PROTOCOL_IP6;
69 fib_table->ft_index =
Neale Rannsa3af3372017-03-28 03:49:52 -070070 v6_fib->index =
71 (fib_table - ip6_main.fibs);
Neale Ranns0bfe5d82016-08-25 15:29:12 +010072
73 hash_set(ip6_main.fib_index_by_table_id, table_id, fib_table->ft_index);
74
75 fib_table->ft_table_id =
Neale Rannsa3af3372017-03-28 03:49:52 -070076 v6_fib->table_id =
Neale Ranns0bfe5d82016-08-25 15:29:12 +010077 table_id;
Neale Ranns227038a2017-04-21 01:07:59 -070078 fib_table->ft_flow_hash_config = IP_FLOW_HASH_DEFAULT;
Neale Ranns0bfe5d82016-08-25 15:29:12 +010079
80 vnet_ip6_fib_init(fib_table->ft_index);
Neale Ranns15002542017-09-10 04:39:11 -070081 fib_table_lock(fib_table->ft_index, FIB_PROTOCOL_IP6, src);
Neale Ranns0bfe5d82016-08-25 15:29:12 +010082
83 return (fib_table->ft_index);
84}
85
86u32
Neale Ranns15002542017-09-10 04:39:11 -070087ip6_fib_table_find_or_create_and_lock (u32 table_id,
88 fib_source_t src)
Neale Ranns0bfe5d82016-08-25 15:29:12 +010089{
90 uword * p;
91
92 p = hash_get (ip6_main.fib_index_by_table_id, table_id);
93 if (NULL == p)
Neale Ranns15002542017-09-10 04:39:11 -070094 return create_fib_with_table_id(table_id, src);
Neale Ranns0bfe5d82016-08-25 15:29:12 +010095
Neale Ranns15002542017-09-10 04:39:11 -070096 fib_table_lock(p[0], FIB_PROTOCOL_IP6, src);
Neale Ranns0bfe5d82016-08-25 15:29:12 +010097
98 return (p[0]);
99}
100
101u32
Neale Ranns15002542017-09-10 04:39:11 -0700102ip6_fib_table_create_and_lock (fib_source_t src)
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100103{
Neale Ranns15002542017-09-10 04:39:11 -0700104 return (create_fib_with_table_id(~0, src));
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100105}
106
107void
108ip6_fib_table_destroy (u32 fib_index)
109{
110 fib_prefix_t pfx = {
111 .fp_proto = FIB_PROTOCOL_IP6,
112 .fp_len = 0,
113 .fp_addr = {
114 .ip6 = {
115 { 0, 0, },
116 },
117 }
118 };
119
120 /*
121 * the default route.
122 */
123 fib_table_entry_special_remove(fib_index,
124 &pfx,
125 FIB_SOURCE_DEFAULT_ROUTE);
126
127
128 /*
129 * ff02::1:ff00:0/104
130 */
131 ip6_set_solicited_node_multicast_address(&pfx.fp_addr.ip6, 0);
132 pfx.fp_len = 104;
133 fib_table_entry_special_remove(fib_index,
134 &pfx,
135 FIB_SOURCE_SPECIAL);
136
137 /*
138 * all-routers multicast address
139 */
140 ip6_set_reserved_multicast_address (&pfx.fp_addr.ip6,
141 IP6_MULTICAST_SCOPE_link_local,
142 IP6_MULTICAST_GROUP_ID_all_routers);
143 pfx.fp_len = 128;
144 fib_table_entry_special_remove(fib_index,
145 &pfx,
146 FIB_SOURCE_SPECIAL);
147
148 /*
149 * all-nodes multicast address
150 */
151 ip6_set_reserved_multicast_address (&pfx.fp_addr.ip6,
152 IP6_MULTICAST_SCOPE_link_local,
153 IP6_MULTICAST_GROUP_ID_all_hosts);
154 pfx.fp_len = 128;
155 fib_table_entry_special_remove(fib_index,
156 &pfx,
157 FIB_SOURCE_SPECIAL);
158
159 /*
160 * all-mldv2 multicast address
161 */
162 ip6_set_reserved_multicast_address (&pfx.fp_addr.ip6,
163 IP6_MULTICAST_SCOPE_link_local,
164 IP6_MULTICAST_GROUP_ID_mldv2_routers);
165 pfx.fp_len = 128;
166 fib_table_entry_special_remove(fib_index,
167 &pfx,
168 FIB_SOURCE_SPECIAL);
169
170 /*
171 * all link local
172 */
173 pfx.fp_addr.ip6.as_u64[0] = clib_host_to_net_u64 (0xFE80000000000000ULL);
174 pfx.fp_addr.ip6.as_u64[1] = 0;
175 pfx.fp_len = 10;
176 fib_table_entry_special_remove(fib_index,
177 &pfx,
178 FIB_SOURCE_SPECIAL);
179
180 fib_table_t *fib_table = fib_table_get(fib_index, FIB_PROTOCOL_IP6);
181 fib_source_t source;
182
183 /*
184 * validate no more routes.
185 */
186 ASSERT(0 == fib_table->ft_total_route_counts);
187 FOR_EACH_FIB_SOURCE(source)
188 {
189 ASSERT(0 == fib_table->ft_src_route_counts[source]);
190 }
191
192 if (~0 != fib_table->ft_table_id)
193 {
194 hash_unset (ip6_main.fib_index_by_table_id, fib_table->ft_table_id);
195 }
Neale Rannsa3af3372017-03-28 03:49:52 -0700196 pool_put_index(ip6_main.v6_fibs, fib_table->ft_index);
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100197 pool_put(ip6_main.fibs, fib_table);
198}
199
200fib_node_index_t
201ip6_fib_table_lookup (u32 fib_index,
202 const ip6_address_t *addr,
203 u32 len)
204{
Dave Barach908a5ea2017-07-14 12:42:21 -0400205 ip6_fib_table_instance_t *table;
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100206 BVT(clib_bihash_kv) kv, value;
207 int i, n_p, rv;
208 u64 fib;
209
210 table = &ip6_main.ip6_table[IP6_FIB_TABLE_NON_FWDING];
211 n_p = vec_len (table->prefix_lengths_in_search_order);
212
213 kv.key[0] = addr->as_u64[0];
214 kv.key[1] = addr->as_u64[1];
215 fib = ((u64)((fib_index))<<32);
216
217 /*
218 * start search from a mask length same length or shorter.
219 * we don't want matches longer than the mask passed
220 */
221 i = 0;
222 while (i < n_p && table->prefix_lengths_in_search_order[i] > len)
223 {
224 i++;
225 }
226
227 for (; i < n_p; i++)
228 {
229 int dst_address_length = table->prefix_lengths_in_search_order[i];
230 ip6_address_t * mask = &ip6_main.fib_masks[dst_address_length];
231
232 ASSERT(dst_address_length >= 0 && dst_address_length <= 128);
233 //As lengths are decreasing, masks are increasingly specific.
234 kv.key[0] &= mask->as_u64[0];
235 kv.key[1] &= mask->as_u64[1];
236 kv.key[2] = fib | dst_address_length;
237
238 rv = BV(clib_bihash_search_inline_2)(&table->ip6_hash, &kv, &value);
239 if (rv == 0)
240 return value.value;
241 }
242
243 return (FIB_NODE_INDEX_INVALID);
244}
245
246fib_node_index_t
247ip6_fib_table_lookup_exact_match (u32 fib_index,
248 const ip6_address_t *addr,
249 u32 len)
250{
Dave Barach908a5ea2017-07-14 12:42:21 -0400251 ip6_fib_table_instance_t *table;
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100252 BVT(clib_bihash_kv) kv, value;
253 ip6_address_t *mask;
254 u64 fib;
255 int rv;
256
257 table = &ip6_main.ip6_table[IP6_FIB_TABLE_NON_FWDING];
258 mask = &ip6_main.fib_masks[len];
259 fib = ((u64)((fib_index))<<32);
260
261 kv.key[0] = addr->as_u64[0] & mask->as_u64[0];
262 kv.key[1] = addr->as_u64[1] & mask->as_u64[1];
263 kv.key[2] = fib | len;
264
265 rv = BV(clib_bihash_search_inline_2)(&table->ip6_hash, &kv, &value);
266 if (rv == 0)
267 return value.value;
268
269 return (FIB_NODE_INDEX_INVALID);
270}
271
272static void
273compute_prefix_lengths_in_search_order (ip6_fib_table_instance_t *table)
274{
275 int i;
276 vec_reset_length (table->prefix_lengths_in_search_order);
277 /* Note: bitmap reversed so this is in fact a longest prefix match */
278 clib_bitmap_foreach (i, table->non_empty_dst_address_length_bitmap,
279 ({
280 int dst_address_length = 128 - i;
281 vec_add1(table->prefix_lengths_in_search_order, dst_address_length);
282 }));
283}
284
285void
286ip6_fib_table_entry_remove (u32 fib_index,
287 const ip6_address_t *addr,
288 u32 len)
289{
290 ip6_fib_table_instance_t *table;
291 BVT(clib_bihash_kv) kv;
292 ip6_address_t *mask;
293 u64 fib;
294
295 table = &ip6_main.ip6_table[IP6_FIB_TABLE_NON_FWDING];
296 mask = &ip6_main.fib_masks[len];
297 fib = ((u64)((fib_index))<<32);
298
299 kv.key[0] = addr->as_u64[0] & mask->as_u64[0];
300 kv.key[1] = addr->as_u64[1] & mask->as_u64[1];
301 kv.key[2] = fib | len;
302
303 BV(clib_bihash_add_del)(&table->ip6_hash, &kv, 0);
304
305 /* refcount accounting */
306 ASSERT (table->dst_address_length_refcounts[len] > 0);
307 if (--table->dst_address_length_refcounts[len] == 0)
308 {
309 table->non_empty_dst_address_length_bitmap =
310 clib_bitmap_set (table->non_empty_dst_address_length_bitmap,
311 128 - len, 0);
312 compute_prefix_lengths_in_search_order (table);
313 }
314}
315
316void
317ip6_fib_table_entry_insert (u32 fib_index,
318 const ip6_address_t *addr,
319 u32 len,
320 fib_node_index_t fib_entry_index)
321{
322 ip6_fib_table_instance_t *table;
323 BVT(clib_bihash_kv) kv;
324 ip6_address_t *mask;
325 u64 fib;
326
327 table = &ip6_main.ip6_table[IP6_FIB_TABLE_NON_FWDING];
328 mask = &ip6_main.fib_masks[len];
329 fib = ((u64)((fib_index))<<32);
330
331 kv.key[0] = addr->as_u64[0] & mask->as_u64[0];
332 kv.key[1] = addr->as_u64[1] & mask->as_u64[1];
333 kv.key[2] = fib | len;
334 kv.value = fib_entry_index;
335
336 BV(clib_bihash_add_del)(&table->ip6_hash, &kv, 1);
337
338 table->dst_address_length_refcounts[len]++;
339
340 table->non_empty_dst_address_length_bitmap =
341 clib_bitmap_set (table->non_empty_dst_address_length_bitmap,
342 128 - len, 1);
343 compute_prefix_lengths_in_search_order (table);
344}
345
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100346u32 ip6_fib_table_fwding_lookup_with_if_index (ip6_main_t * im,
347 u32 sw_if_index,
348 const ip6_address_t * dst)
349{
350 u32 fib_index = vec_elt (im->fib_index_by_sw_if_index, sw_if_index);
351 return ip6_fib_table_fwding_lookup(im, fib_index, dst);
352}
353
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100354u32
355ip6_fib_table_get_index_for_sw_if_index (u32 sw_if_index)
356{
357 if (sw_if_index >= vec_len(ip6_main.fib_index_by_sw_if_index))
358 {
359 /*
360 * This is the case for interfaces that are not yet mapped to
361 * a IP table
362 */
363 return (~0);
364 }
365 return (ip6_main.fib_index_by_sw_if_index[sw_if_index]);
366}
367
368void
369ip6_fib_table_fwding_dpo_update (u32 fib_index,
370 const ip6_address_t *addr,
371 u32 len,
372 const dpo_id_t *dpo)
373{
374 ip6_fib_table_instance_t *table;
375 BVT(clib_bihash_kv) kv;
376 ip6_address_t *mask;
377 u64 fib;
378
379 table = &ip6_main.ip6_table[IP6_FIB_TABLE_FWDING];
380 mask = &ip6_main.fib_masks[len];
381 fib = ((u64)((fib_index))<<32);
382
383 kv.key[0] = addr->as_u64[0] & mask->as_u64[0];
384 kv.key[1] = addr->as_u64[1] & mask->as_u64[1];
385 kv.key[2] = fib | len;
386 kv.value = dpo->dpoi_index;
387
388 BV(clib_bihash_add_del)(&table->ip6_hash, &kv, 1);
389
390 table->dst_address_length_refcounts[len]++;
391
392 table->non_empty_dst_address_length_bitmap =
393 clib_bitmap_set (table->non_empty_dst_address_length_bitmap,
394 128 - len, 1);
395 compute_prefix_lengths_in_search_order (table);
396}
397
398void
399ip6_fib_table_fwding_dpo_remove (u32 fib_index,
400 const ip6_address_t *addr,
401 u32 len,
402 const dpo_id_t *dpo)
403{
404 ip6_fib_table_instance_t *table;
405 BVT(clib_bihash_kv) kv;
406 ip6_address_t *mask;
407 u64 fib;
408
409 table = &ip6_main.ip6_table[IP6_FIB_TABLE_FWDING];
410 mask = &ip6_main.fib_masks[len];
411 fib = ((u64)((fib_index))<<32);
412
413 kv.key[0] = addr->as_u64[0] & mask->as_u64[0];
414 kv.key[1] = addr->as_u64[1] & mask->as_u64[1];
415 kv.key[2] = fib | len;
416 kv.value = dpo->dpoi_index;
417
418 BV(clib_bihash_add_del)(&table->ip6_hash, &kv, 0);
419
420 /* refcount accounting */
421 ASSERT (table->dst_address_length_refcounts[len] > 0);
422 if (--table->dst_address_length_refcounts[len] == 0)
423 {
424 table->non_empty_dst_address_length_bitmap =
Neale Ranns32e1c012016-11-22 17:07:28 +0000425 clib_bitmap_set (table->non_empty_dst_address_length_bitmap,
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100426 128 - len, 0);
427 compute_prefix_lengths_in_search_order (table);
428 }
429}
430
Neale Ranns32e1c012016-11-22 17:07:28 +0000431/**
432 * @brief Context when walking the IPv6 table. Since all VRFs are in the
433 * same hash table, we need to filter only those we need as we walk
434 */
435typedef struct ip6_fib_walk_ctx_t_
436{
437 u32 i6w_fib_index;
438 fib_table_walk_fn_t i6w_fn;
439 void *i6w_ctx;
440} ip6_fib_walk_ctx_t;
441
442static int
443ip6_fib_walk_cb (clib_bihash_kv_24_8_t * kvp,
444 void *arg)
445{
446 ip6_fib_walk_ctx_t *ctx = arg;
447
448 if ((kvp->key[2] >> 32) == ctx->i6w_fib_index)
449 {
450 ctx->i6w_fn(kvp->value, ctx->i6w_ctx);
451 }
452
453 return (1);
454}
455
456void
457ip6_fib_table_walk (u32 fib_index,
458 fib_table_walk_fn_t fn,
459 void *arg)
460{
461 ip6_fib_walk_ctx_t ctx = {
462 .i6w_fib_index = fib_index,
463 .i6w_fn = fn,
464 .i6w_ctx = arg,
465 };
466 ip6_main_t *im = &ip6_main;
467
468 BV(clib_bihash_foreach_key_value_pair)(&im->ip6_table[IP6_FIB_TABLE_NON_FWDING].ip6_hash,
469 ip6_fib_walk_cb,
470 &ctx);
471
472}
473
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100474typedef struct ip6_fib_show_ctx_t_ {
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100475 fib_node_index_t *entries;
476} ip6_fib_show_ctx_t;
477
Neale Ranns32e1c012016-11-22 17:07:28 +0000478static int
479ip6_fib_table_show_walk (fib_node_index_t fib_entry_index,
480 void *arg)
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100481{
482 ip6_fib_show_ctx_t *ctx = arg;
483
Neale Ranns32e1c012016-11-22 17:07:28 +0000484 vec_add1(ctx->entries, fib_entry_index);
485
486 return (1);
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100487}
488
489static void
490ip6_fib_table_show_all (ip6_fib_t *fib,
491 vlib_main_t * vm)
492{
493 fib_node_index_t *fib_entry_index;
494 ip6_fib_show_ctx_t ctx = {
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100495 .entries = NULL,
496 };
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100497
Neale Ranns32e1c012016-11-22 17:07:28 +0000498 ip6_fib_table_walk(fib->index, ip6_fib_table_show_walk, &ctx);
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100499 vec_sort_with_function(ctx.entries, fib_entry_cmp_for_sort);
500
501 vec_foreach(fib_entry_index, ctx.entries)
502 {
503 vlib_cli_output(vm, "%U",
504 format_fib_entry,
505 *fib_entry_index,
506 FIB_ENTRY_FORMAT_BRIEF);
507 }
508
509 vec_free(ctx.entries);
510}
511
512static void
513ip6_fib_table_show_one (ip6_fib_t *fib,
514 vlib_main_t * vm,
515 ip6_address_t *address,
Neale Ranns88fc83e2017-04-05 08:11:14 -0700516 u32 mask_len,
517 int detail)
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100518{
519 vlib_cli_output(vm, "%U",
520 format_fib_entry,
521 ip6_fib_table_lookup(fib->index, address, mask_len),
Neale Ranns88fc83e2017-04-05 08:11:14 -0700522 (detail ?
523 FIB_ENTRY_FORMAT_DETAIL2:
524 FIB_ENTRY_FORMAT_DETAIL));
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100525}
526
527typedef struct {
528 u32 fib_index;
529 u64 count_by_prefix_length[129];
530} count_routes_in_fib_at_prefix_length_arg_t;
531
Neale Ranns88fc83e2017-04-05 08:11:14 -0700532static void
533count_routes_in_fib_at_prefix_length (BVT(clib_bihash_kv) * kvp,
534 void *arg)
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100535{
536 count_routes_in_fib_at_prefix_length_arg_t * ap = arg;
537 int mask_width;
538
539 if ((kvp->key[2]>>32) != ap->fib_index)
540 return;
541
542 mask_width = kvp->key[2] & 0xFF;
543
544 ap->count_by_prefix_length[mask_width]++;
545}
546
547static clib_error_t *
548ip6_show_fib (vlib_main_t * vm,
549 unformat_input_t * input,
550 vlib_cli_command_t * cmd)
551{
552 count_routes_in_fib_at_prefix_length_arg_t _ca, *ca = &_ca;
553 ip6_main_t * im6 = &ip6_main;
554 fib_table_t *fib_table;
555 ip6_fib_t * fib;
556 int verbose, matching;
557 ip6_address_t matching_address;
558 u32 mask_len = 128;
559 int table_id = -1, fib_index = ~0;
Neale Ranns88fc83e2017-04-05 08:11:14 -0700560 int detail = 0;
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100561
562 verbose = 1;
563 matching = 0;
564
565 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
566 {
567 if (unformat (input, "brief") ||
568 unformat (input, "summary") ||
569 unformat (input, "sum"))
570 verbose = 0;
Neale Ranns88fc83e2017-04-05 08:11:14 -0700571
572 else if (unformat (input, "detail") ||
573 unformat (input, "det"))
574 detail = 1;
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100575
576 else if (unformat (input, "%U/%d",
577 unformat_ip6_address, &matching_address, &mask_len))
578 matching = 1;
579
580 else if (unformat (input, "%U", unformat_ip6_address, &matching_address))
581 matching = 1;
582
583 else if (unformat (input, "table %d", &table_id))
584 ;
585 else if (unformat (input, "index %d", &fib_index))
586 ;
587 else
588 break;
589 }
590
591 pool_foreach (fib_table, im6->fibs,
592 ({
Neale Ranns15002542017-09-10 04:39:11 -0700593 fib_source_t source;
594 u8 *s = NULL;
595
Neale Rannsa3af3372017-03-28 03:49:52 -0700596 fib = pool_elt_at_index(im6->v6_fibs, fib_table->ft_index);
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100597 if (table_id >= 0 && table_id != (int)fib->table_id)
598 continue;
599 if (fib_index != ~0 && fib_index != (int)fib->index)
600 continue;
601
Neale Ranns15002542017-09-10 04:39:11 -0700602 s = format(s, "%U, fib_index:%d, flow hash:[%U] locks:[",
603 format_fib_table_name, fib->index,
604 FIB_PROTOCOL_IP6,
605 fib->index,
606 format_ip_flow_hash_config,
607 fib_table->ft_flow_hash_config);
608 FOR_EACH_FIB_SOURCE(source)
609 {
610 if (0 != fib_table->ft_locks[source])
611 {
612 s = format(s, "%U:%d, ",
613 format_fib_source, source,
614 fib_table->ft_locks[source]);
615 }
616 }
617 s = format (s, "]");
618 vlib_cli_output (vm, "%V", s);
619 vec_free(s);
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100620
621 /* Show summary? */
622 if (! verbose)
623 {
624 BVT(clib_bihash) * h = &im6->ip6_table[IP6_FIB_TABLE_NON_FWDING].ip6_hash;
625 int len;
626
627 vlib_cli_output (vm, "%=20s%=16s", "Prefix length", "Count");
628
629 memset (ca, 0, sizeof(*ca));
630 ca->fib_index = fib->index;
631
632 BV(clib_bihash_foreach_key_value_pair)
633 (h, count_routes_in_fib_at_prefix_length, ca);
634
635 for (len = 128; len >= 0; len--)
636 {
637 if (ca->count_by_prefix_length[len])
638 vlib_cli_output (vm, "%=20d%=16lld",
639 len, ca->count_by_prefix_length[len]);
640 }
641 continue;
642 }
643
644 if (!matching)
645 {
646 ip6_fib_table_show_all(fib, vm);
647 }
648 else
649 {
Neale Ranns88fc83e2017-04-05 08:11:14 -0700650 ip6_fib_table_show_one(fib, vm, &matching_address, mask_len, detail);
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100651 }
652 }));
653
654 return 0;
655}
656
657/*?
Billy McFall0683c9c2016-10-13 08:27:31 -0400658 * This command displays the IPv6 FIB Tables (VRF Tables) and the route
659 * entries for each table.
660 *
661 * @note This command will run for a long time when the FIB tables are
662 * comprised of millions of entries. For those senarios, consider displaying
663 * in summary mode.
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100664 *
665 * @cliexpar
Billy McFall0683c9c2016-10-13 08:27:31 -0400666 * @parblock
667 * Example of how to display all the IPv6 FIB tables:
668 * @cliexstart{show ip6 fib}
Billy McFallebb9a6a2016-10-17 11:35:32 -0400669 * ipv6-VRF:0, fib_index 0, flow hash: src dst sport dport proto
670 * @::/0
671 * unicast-ip6-chain
672 * [@0]: dpo-load-balance: [index:5 buckets:1 uRPF:5 to:[0:0]]
673 * [0] [@0]: dpo-drop ip6
674 * fe80::/10
675 * unicast-ip6-chain
676 * [@0]: dpo-load-balance: [index:10 buckets:1 uRPF:10 to:[0:0]]
677 * [0] [@2]: dpo-receive
678 * ff02::1/128
679 * unicast-ip6-chain
680 * [@0]: dpo-load-balance: [index:8 buckets:1 uRPF:8 to:[0:0]]
681 * [0] [@2]: dpo-receive
682 * ff02::2/128
683 * unicast-ip6-chain
684 * [@0]: dpo-load-balance: [index:7 buckets:1 uRPF:7 to:[0:0]]
685 * [0] [@2]: dpo-receive
686 * ff02::16/128
687 * unicast-ip6-chain
688 * [@0]: dpo-load-balance: [index:9 buckets:1 uRPF:9 to:[0:0]]
689 * [0] [@2]: dpo-receive
690 * ff02::1:ff00:0/104
691 * unicast-ip6-chain
692 * [@0]: dpo-load-balance: [index:6 buckets:1 uRPF:6 to:[0:0]]
693 * [0] [@2]: dpo-receive
694 * ipv6-VRF:8, fib_index 1, flow hash: src dst sport dport proto
695 * @::/0
696 * unicast-ip6-chain
697 * [@0]: dpo-load-balance: [index:21 buckets:1 uRPF:20 to:[0:0]]
698 * [0] [@0]: dpo-drop ip6
699 * @::a:1:1:0:4/126
700 * unicast-ip6-chain
701 * [@0]: dpo-load-balance: [index:27 buckets:1 uRPF:26 to:[0:0]]
702 * [0] [@4]: ipv6-glean: af_packet0
703 * @::a:1:1:0:7/128
704 * unicast-ip6-chain
705 * [@0]: dpo-load-balance: [index:28 buckets:1 uRPF:27 to:[0:0]]
706 * [0] [@2]: dpo-receive: @::a:1:1:0:7 on af_packet0
707 * fe80::/10
708 * unicast-ip6-chain
709 * [@0]: dpo-load-balance: [index:26 buckets:1 uRPF:25 to:[0:0]]
710 * [0] [@2]: dpo-receive
711 * fe80::fe:3eff:fe3e:9222/128
712 * unicast-ip6-chain
713 * [@0]: dpo-load-balance: [index:29 buckets:1 uRPF:28 to:[0:0]]
714 * [0] [@2]: dpo-receive: fe80::fe:3eff:fe3e:9222 on af_packet0
715 * ff02::1/128
716 * unicast-ip6-chain
717 * [@0]: dpo-load-balance: [index:24 buckets:1 uRPF:23 to:[0:0]]
718 * [0] [@2]: dpo-receive
719 * ff02::2/128
720 * unicast-ip6-chain
721 * [@0]: dpo-load-balance: [index:23 buckets:1 uRPF:22 to:[0:0]]
722 * [0] [@2]: dpo-receive
723 * ff02::16/128
724 * unicast-ip6-chain
725 * [@0]: dpo-load-balance: [index:25 buckets:1 uRPF:24 to:[0:0]]
726 * [0] [@2]: dpo-receive
727 * ff02::1:ff00:0/104
728 * unicast-ip6-chain
729 * [@0]: dpo-load-balance: [index:22 buckets:1 uRPF:21 to:[0:0]]
730 * [0] [@2]: dpo-receive
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100731 * @cliexend
Billy McFallebb9a6a2016-10-17 11:35:32 -0400732 *
Billy McFall0683c9c2016-10-13 08:27:31 -0400733 * Example of how to display a summary of all IPv6 FIB tables:
734 * @cliexstart{show ip6 fib summary}
Billy McFallebb9a6a2016-10-17 11:35:32 -0400735 * ipv6-VRF:0, fib_index 0, flow hash: src dst sport dport proto
Billy McFall0683c9c2016-10-13 08:27:31 -0400736 * Prefix length Count
737 * 128 3
738 * 104 1
Billy McFallebb9a6a2016-10-17 11:35:32 -0400739 * 10 1
740 * 0 1
741 * ipv6-VRF:8, fib_index 1, flow hash: src dst sport dport proto
Billy McFall0683c9c2016-10-13 08:27:31 -0400742 * Prefix length Count
743 * 128 5
744 * 126 1
745 * 104 1
Billy McFallebb9a6a2016-10-17 11:35:32 -0400746 * 10 1
747 * 0 1
Billy McFall0683c9c2016-10-13 08:27:31 -0400748 * @cliexend
749 * @endparblock
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100750 ?*/
Billy McFall0683c9c2016-10-13 08:27:31 -0400751/* *INDENT-OFF* */
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100752VLIB_CLI_COMMAND (ip6_show_fib_command, static) = {
753 .path = "show ip6 fib",
Neale Ranns88fc83e2017-04-05 08:11:14 -0700754 .short_help = "show ip6 fib [summary] [table <table-id>] [index <fib-id>] [<ip6-addr>[/<width>]] [detail]",
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100755 .function = ip6_show_fib,
756};
Billy McFall0683c9c2016-10-13 08:27:31 -0400757/* *INDENT-ON* */