Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2016 Cisco and/or its affiliates. |
| 3 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | * you may not use this file except in compliance with the License. |
| 5 | * You may obtain a copy of the License at: |
| 6 | * |
| 7 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | * |
| 9 | * Unless required by applicable law or agreed to in writing, software |
| 10 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | * See the License for the specific language governing permissions and |
| 13 | * limitations under the License. |
| 14 | */ |
| 15 | |
| 16 | #include <vnet/fib/ip6_fib.h> |
| 17 | #include <vnet/fib/fib_table.h> |
Neale Ranns | 53da221 | 2018-02-24 02:11:19 -0800 | [diff] [blame] | 18 | #include <vnet/dpo/ip6_ll_dpo.h> |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 19 | |
Neale Ranns | ae80983 | 2018-11-23 09:00:27 -0800 | [diff] [blame] | 20 | #include <vppinfra/bihash_24_8.h> |
| 21 | #include <vppinfra/bihash_template.c> |
| 22 | |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 23 | static void |
| 24 | vnet_ip6_fib_init (u32 fib_index) |
| 25 | { |
| 26 | fib_prefix_t pfx = { |
| 27 | .fp_proto = FIB_PROTOCOL_IP6, |
| 28 | .fp_len = 0, |
| 29 | .fp_addr = { |
| 30 | .ip6 = { |
| 31 | { 0, 0, }, |
| 32 | }, |
| 33 | } |
| 34 | }; |
| 35 | |
| 36 | /* |
| 37 | * Add the default route. |
| 38 | */ |
| 39 | fib_table_entry_special_add(fib_index, |
| 40 | &pfx, |
| 41 | FIB_SOURCE_DEFAULT_ROUTE, |
Neale Ranns | a055830 | 2017-04-13 00:44:52 -0700 | [diff] [blame] | 42 | FIB_ENTRY_FLAG_DROP); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 43 | |
| 44 | /* |
Neale Ranns | 53da221 | 2018-02-24 02:11:19 -0800 | [diff] [blame] | 45 | * all link local via the link local lookup DPO |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 46 | */ |
| 47 | pfx.fp_addr.ip6.as_u64[0] = clib_host_to_net_u64 (0xFE80000000000000ULL); |
| 48 | pfx.fp_addr.ip6.as_u64[1] = 0; |
| 49 | pfx.fp_len = 10; |
Neale Ranns | 53da221 | 2018-02-24 02:11:19 -0800 | [diff] [blame] | 50 | fib_table_entry_special_dpo_add(fib_index, |
| 51 | &pfx, |
| 52 | FIB_SOURCE_SPECIAL, |
| 53 | FIB_ENTRY_FLAG_NONE, |
| 54 | ip6_ll_dpo_get()); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | static u32 |
Neale Ranns | 1500254 | 2017-09-10 04:39:11 -0700 | [diff] [blame] | 58 | create_fib_with_table_id (u32 table_id, |
Neale Ranns | 53da221 | 2018-02-24 02:11:19 -0800 | [diff] [blame] | 59 | fib_source_t src, |
| 60 | fib_table_flags_t flags, |
| 61 | u8 *desc) |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 62 | { |
| 63 | fib_table_t *fib_table; |
Neale Ranns | a3af337 | 2017-03-28 03:49:52 -0700 | [diff] [blame] | 64 | ip6_fib_t *v6_fib; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 65 | |
Dave Barach | eb987d3 | 2018-05-03 08:26:39 -0400 | [diff] [blame] | 66 | pool_get(ip6_main.fibs, fib_table); |
Neale Ranns | a3af337 | 2017-03-28 03:49:52 -0700 | [diff] [blame] | 67 | pool_get_aligned(ip6_main.v6_fibs, v6_fib, CLIB_CACHE_LINE_BYTES); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 68 | |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 69 | clib_memset(fib_table, 0, sizeof(*fib_table)); |
| 70 | clib_memset(v6_fib, 0, sizeof(*v6_fib)); |
Neale Ranns | a3af337 | 2017-03-28 03:49:52 -0700 | [diff] [blame] | 71 | |
| 72 | ASSERT((fib_table - ip6_main.fibs) == |
| 73 | (v6_fib - ip6_main.v6_fibs)); |
| 74 | |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 75 | fib_table->ft_proto = FIB_PROTOCOL_IP6; |
| 76 | fib_table->ft_index = |
Neale Ranns | a3af337 | 2017-03-28 03:49:52 -0700 | [diff] [blame] | 77 | v6_fib->index = |
| 78 | (fib_table - ip6_main.fibs); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 79 | |
| 80 | hash_set(ip6_main.fib_index_by_table_id, table_id, fib_table->ft_index); |
| 81 | |
| 82 | fib_table->ft_table_id = |
Neale Ranns | a3af337 | 2017-03-28 03:49:52 -0700 | [diff] [blame] | 83 | v6_fib->table_id = |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 84 | table_id; |
Neale Ranns | 227038a | 2017-04-21 01:07:59 -0700 | [diff] [blame] | 85 | fib_table->ft_flow_hash_config = IP_FLOW_HASH_DEFAULT; |
Neale Ranns | 53da221 | 2018-02-24 02:11:19 -0800 | [diff] [blame] | 86 | fib_table->ft_flags = flags; |
| 87 | fib_table->ft_desc = desc; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 88 | |
| 89 | vnet_ip6_fib_init(fib_table->ft_index); |
Neale Ranns | 1500254 | 2017-09-10 04:39:11 -0700 | [diff] [blame] | 90 | fib_table_lock(fib_table->ft_index, FIB_PROTOCOL_IP6, src); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 91 | |
| 92 | return (fib_table->ft_index); |
| 93 | } |
| 94 | |
| 95 | u32 |
Neale Ranns | 1500254 | 2017-09-10 04:39:11 -0700 | [diff] [blame] | 96 | ip6_fib_table_find_or_create_and_lock (u32 table_id, |
| 97 | fib_source_t src) |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 98 | { |
| 99 | uword * p; |
| 100 | |
| 101 | p = hash_get (ip6_main.fib_index_by_table_id, table_id); |
| 102 | if (NULL == p) |
Neale Ranns | 53da221 | 2018-02-24 02:11:19 -0800 | [diff] [blame] | 103 | return create_fib_with_table_id(table_id, src, |
| 104 | FIB_TABLE_FLAG_NONE, |
| 105 | NULL); |
| 106 | |
Neale Ranns | 1500254 | 2017-09-10 04:39:11 -0700 | [diff] [blame] | 107 | fib_table_lock(p[0], FIB_PROTOCOL_IP6, src); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 108 | |
| 109 | return (p[0]); |
| 110 | } |
| 111 | |
| 112 | u32 |
Neale Ranns | 53da221 | 2018-02-24 02:11:19 -0800 | [diff] [blame] | 113 | ip6_fib_table_create_and_lock (fib_source_t src, |
| 114 | fib_table_flags_t flags, |
| 115 | u8 *desc) |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 116 | { |
Neale Ranns | 53da221 | 2018-02-24 02:11:19 -0800 | [diff] [blame] | 117 | return (create_fib_with_table_id(~0, src, flags, desc)); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 118 | } |
| 119 | |
| 120 | void |
| 121 | ip6_fib_table_destroy (u32 fib_index) |
| 122 | { |
Neale Ranns | 53da221 | 2018-02-24 02:11:19 -0800 | [diff] [blame] | 123 | /* |
| 124 | * all link local first ... |
| 125 | */ |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 126 | fib_prefix_t pfx = { |
| 127 | .fp_proto = FIB_PROTOCOL_IP6, |
Neale Ranns | 53da221 | 2018-02-24 02:11:19 -0800 | [diff] [blame] | 128 | .fp_len = 10, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 129 | .fp_addr = { |
| 130 | .ip6 = { |
Neale Ranns | 53da221 | 2018-02-24 02:11:19 -0800 | [diff] [blame] | 131 | .as_u8 = { |
| 132 | [0] = 0xFE, |
| 133 | [1] = 0x80, |
| 134 | }, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 135 | }, |
| 136 | } |
| 137 | }; |
Neale Ranns | 53da221 | 2018-02-24 02:11:19 -0800 | [diff] [blame] | 138 | fib_table_entry_delete(fib_index, |
| 139 | &pfx, |
| 140 | FIB_SOURCE_SPECIAL); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 141 | |
| 142 | /* |
Neale Ranns | 53da221 | 2018-02-24 02:11:19 -0800 | [diff] [blame] | 143 | * ... then the default route. |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 144 | */ |
Neale Ranns | 53da221 | 2018-02-24 02:11:19 -0800 | [diff] [blame] | 145 | pfx.fp_addr.ip6.as_u64[0] = 0; |
| 146 | pfx.fp_len = 00; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 147 | fib_table_entry_special_remove(fib_index, |
| 148 | &pfx, |
| 149 | FIB_SOURCE_DEFAULT_ROUTE); |
| 150 | |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 151 | fib_table_t *fib_table = fib_table_get(fib_index, FIB_PROTOCOL_IP6); |
| 152 | fib_source_t source; |
Neale Ranns | 53da221 | 2018-02-24 02:11:19 -0800 | [diff] [blame] | 153 | |
Neale Ranns | 3bab8f9 | 2019-12-04 06:11:00 +0000 | [diff] [blame] | 154 | /* |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 155 | * validate no more routes. |
| 156 | */ |
| 157 | ASSERT(0 == fib_table->ft_total_route_counts); |
Neale Ranns | 3bab8f9 | 2019-12-04 06:11:00 +0000 | [diff] [blame] | 158 | vec_foreach_index(source, fib_table->ft_src_route_counts) |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 159 | { |
| 160 | ASSERT(0 == fib_table->ft_src_route_counts[source]); |
| 161 | } |
| 162 | |
| 163 | if (~0 != fib_table->ft_table_id) |
| 164 | { |
| 165 | hash_unset (ip6_main.fib_index_by_table_id, fib_table->ft_table_id); |
| 166 | } |
Neale Ranns | 3bab8f9 | 2019-12-04 06:11:00 +0000 | [diff] [blame] | 167 | vec_free(fib_table->ft_src_route_counts); |
Neale Ranns | a3af337 | 2017-03-28 03:49:52 -0700 | [diff] [blame] | 168 | pool_put_index(ip6_main.v6_fibs, fib_table->ft_index); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 169 | pool_put(ip6_main.fibs, fib_table); |
| 170 | } |
| 171 | |
| 172 | fib_node_index_t |
| 173 | ip6_fib_table_lookup (u32 fib_index, |
| 174 | const ip6_address_t *addr, |
| 175 | u32 len) |
| 176 | { |
Dave Barach | 908a5ea | 2017-07-14 12:42:21 -0400 | [diff] [blame] | 177 | ip6_fib_table_instance_t *table; |
Neale Ranns | ae80983 | 2018-11-23 09:00:27 -0800 | [diff] [blame] | 178 | clib_bihash_kv_24_8_t kv, value; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 179 | int i, n_p, rv; |
| 180 | u64 fib; |
| 181 | |
| 182 | table = &ip6_main.ip6_table[IP6_FIB_TABLE_NON_FWDING]; |
| 183 | n_p = vec_len (table->prefix_lengths_in_search_order); |
| 184 | |
| 185 | kv.key[0] = addr->as_u64[0]; |
| 186 | kv.key[1] = addr->as_u64[1]; |
| 187 | fib = ((u64)((fib_index))<<32); |
| 188 | |
| 189 | /* |
| 190 | * start search from a mask length same length or shorter. |
| 191 | * we don't want matches longer than the mask passed |
| 192 | */ |
| 193 | i = 0; |
| 194 | while (i < n_p && table->prefix_lengths_in_search_order[i] > len) |
| 195 | { |
| 196 | i++; |
| 197 | } |
| 198 | |
| 199 | for (; i < n_p; i++) |
| 200 | { |
| 201 | int dst_address_length = table->prefix_lengths_in_search_order[i]; |
| 202 | ip6_address_t * mask = &ip6_main.fib_masks[dst_address_length]; |
| 203 | |
| 204 | ASSERT(dst_address_length >= 0 && dst_address_length <= 128); |
| 205 | //As lengths are decreasing, masks are increasingly specific. |
| 206 | kv.key[0] &= mask->as_u64[0]; |
| 207 | kv.key[1] &= mask->as_u64[1]; |
| 208 | kv.key[2] = fib | dst_address_length; |
| 209 | |
Neale Ranns | ae80983 | 2018-11-23 09:00:27 -0800 | [diff] [blame] | 210 | rv = clib_bihash_search_inline_2_24_8(&table->ip6_hash, &kv, &value); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 211 | if (rv == 0) |
| 212 | return value.value; |
| 213 | } |
| 214 | |
| 215 | return (FIB_NODE_INDEX_INVALID); |
| 216 | } |
| 217 | |
| 218 | fib_node_index_t |
| 219 | ip6_fib_table_lookup_exact_match (u32 fib_index, |
| 220 | const ip6_address_t *addr, |
| 221 | u32 len) |
| 222 | { |
Dave Barach | 908a5ea | 2017-07-14 12:42:21 -0400 | [diff] [blame] | 223 | ip6_fib_table_instance_t *table; |
Neale Ranns | ae80983 | 2018-11-23 09:00:27 -0800 | [diff] [blame] | 224 | clib_bihash_kv_24_8_t kv, value; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 225 | ip6_address_t *mask; |
| 226 | u64 fib; |
| 227 | int rv; |
| 228 | |
| 229 | table = &ip6_main.ip6_table[IP6_FIB_TABLE_NON_FWDING]; |
| 230 | mask = &ip6_main.fib_masks[len]; |
| 231 | fib = ((u64)((fib_index))<<32); |
| 232 | |
| 233 | kv.key[0] = addr->as_u64[0] & mask->as_u64[0]; |
| 234 | kv.key[1] = addr->as_u64[1] & mask->as_u64[1]; |
| 235 | kv.key[2] = fib | len; |
| 236 | |
Neale Ranns | ae80983 | 2018-11-23 09:00:27 -0800 | [diff] [blame] | 237 | rv = clib_bihash_search_inline_2_24_8(&table->ip6_hash, &kv, &value); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 238 | if (rv == 0) |
| 239 | return value.value; |
| 240 | |
| 241 | return (FIB_NODE_INDEX_INVALID); |
| 242 | } |
| 243 | |
| 244 | static void |
| 245 | compute_prefix_lengths_in_search_order (ip6_fib_table_instance_t *table) |
| 246 | { |
| 247 | int i; |
| 248 | vec_reset_length (table->prefix_lengths_in_search_order); |
| 249 | /* Note: bitmap reversed so this is in fact a longest prefix match */ |
| 250 | clib_bitmap_foreach (i, table->non_empty_dst_address_length_bitmap, |
| 251 | ({ |
| 252 | int dst_address_length = 128 - i; |
| 253 | vec_add1(table->prefix_lengths_in_search_order, dst_address_length); |
| 254 | })); |
| 255 | } |
| 256 | |
| 257 | void |
| 258 | ip6_fib_table_entry_remove (u32 fib_index, |
| 259 | const ip6_address_t *addr, |
| 260 | u32 len) |
| 261 | { |
| 262 | ip6_fib_table_instance_t *table; |
Neale Ranns | ae80983 | 2018-11-23 09:00:27 -0800 | [diff] [blame] | 263 | clib_bihash_kv_24_8_t kv; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 264 | ip6_address_t *mask; |
| 265 | u64 fib; |
| 266 | |
| 267 | table = &ip6_main.ip6_table[IP6_FIB_TABLE_NON_FWDING]; |
| 268 | mask = &ip6_main.fib_masks[len]; |
| 269 | fib = ((u64)((fib_index))<<32); |
| 270 | |
| 271 | kv.key[0] = addr->as_u64[0] & mask->as_u64[0]; |
| 272 | kv.key[1] = addr->as_u64[1] & mask->as_u64[1]; |
| 273 | kv.key[2] = fib | len; |
| 274 | |
Neale Ranns | ae80983 | 2018-11-23 09:00:27 -0800 | [diff] [blame] | 275 | clib_bihash_add_del_24_8(&table->ip6_hash, &kv, 0); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 276 | |
| 277 | /* refcount accounting */ |
| 278 | ASSERT (table->dst_address_length_refcounts[len] > 0); |
| 279 | if (--table->dst_address_length_refcounts[len] == 0) |
| 280 | { |
| 281 | table->non_empty_dst_address_length_bitmap = |
| 282 | clib_bitmap_set (table->non_empty_dst_address_length_bitmap, |
| 283 | 128 - len, 0); |
| 284 | compute_prefix_lengths_in_search_order (table); |
| 285 | } |
| 286 | } |
| 287 | |
| 288 | void |
| 289 | ip6_fib_table_entry_insert (u32 fib_index, |
| 290 | const ip6_address_t *addr, |
| 291 | u32 len, |
| 292 | fib_node_index_t fib_entry_index) |
| 293 | { |
| 294 | ip6_fib_table_instance_t *table; |
Neale Ranns | ae80983 | 2018-11-23 09:00:27 -0800 | [diff] [blame] | 295 | clib_bihash_kv_24_8_t kv; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 296 | ip6_address_t *mask; |
| 297 | u64 fib; |
| 298 | |
| 299 | table = &ip6_main.ip6_table[IP6_FIB_TABLE_NON_FWDING]; |
| 300 | mask = &ip6_main.fib_masks[len]; |
| 301 | fib = ((u64)((fib_index))<<32); |
| 302 | |
| 303 | kv.key[0] = addr->as_u64[0] & mask->as_u64[0]; |
| 304 | kv.key[1] = addr->as_u64[1] & mask->as_u64[1]; |
| 305 | kv.key[2] = fib | len; |
| 306 | kv.value = fib_entry_index; |
| 307 | |
Neale Ranns | ae80983 | 2018-11-23 09:00:27 -0800 | [diff] [blame] | 308 | clib_bihash_add_del_24_8(&table->ip6_hash, &kv, 1); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 309 | |
| 310 | table->dst_address_length_refcounts[len]++; |
| 311 | |
| 312 | table->non_empty_dst_address_length_bitmap = |
| 313 | clib_bitmap_set (table->non_empty_dst_address_length_bitmap, |
| 314 | 128 - len, 1); |
| 315 | compute_prefix_lengths_in_search_order (table); |
| 316 | } |
| 317 | |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 318 | u32 ip6_fib_table_fwding_lookup_with_if_index (ip6_main_t * im, |
| 319 | u32 sw_if_index, |
| 320 | const ip6_address_t * dst) |
| 321 | { |
| 322 | u32 fib_index = vec_elt (im->fib_index_by_sw_if_index, sw_if_index); |
Simon Zhang | e7eba48 | 2019-08-25 15:30:45 +0800 | [diff] [blame] | 323 | return ip6_fib_table_fwding_lookup(fib_index, dst); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 324 | } |
| 325 | |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 326 | u32 |
| 327 | ip6_fib_table_get_index_for_sw_if_index (u32 sw_if_index) |
| 328 | { |
| 329 | if (sw_if_index >= vec_len(ip6_main.fib_index_by_sw_if_index)) |
| 330 | { |
| 331 | /* |
| 332 | * This is the case for interfaces that are not yet mapped to |
| 333 | * a IP table |
| 334 | */ |
| 335 | return (~0); |
| 336 | } |
| 337 | return (ip6_main.fib_index_by_sw_if_index[sw_if_index]); |
| 338 | } |
| 339 | |
| 340 | void |
| 341 | ip6_fib_table_fwding_dpo_update (u32 fib_index, |
| 342 | const ip6_address_t *addr, |
| 343 | u32 len, |
| 344 | const dpo_id_t *dpo) |
| 345 | { |
| 346 | ip6_fib_table_instance_t *table; |
Neale Ranns | ae80983 | 2018-11-23 09:00:27 -0800 | [diff] [blame] | 347 | clib_bihash_kv_24_8_t kv; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 348 | ip6_address_t *mask; |
| 349 | u64 fib; |
| 350 | |
| 351 | table = &ip6_main.ip6_table[IP6_FIB_TABLE_FWDING]; |
| 352 | mask = &ip6_main.fib_masks[len]; |
| 353 | fib = ((u64)((fib_index))<<32); |
| 354 | |
| 355 | kv.key[0] = addr->as_u64[0] & mask->as_u64[0]; |
| 356 | kv.key[1] = addr->as_u64[1] & mask->as_u64[1]; |
| 357 | kv.key[2] = fib | len; |
| 358 | kv.value = dpo->dpoi_index; |
| 359 | |
Neale Ranns | ae80983 | 2018-11-23 09:00:27 -0800 | [diff] [blame] | 360 | clib_bihash_add_del_24_8(&table->ip6_hash, &kv, 1); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 361 | |
| 362 | table->dst_address_length_refcounts[len]++; |
| 363 | |
| 364 | table->non_empty_dst_address_length_bitmap = |
| 365 | clib_bitmap_set (table->non_empty_dst_address_length_bitmap, |
| 366 | 128 - len, 1); |
| 367 | compute_prefix_lengths_in_search_order (table); |
| 368 | } |
| 369 | |
| 370 | void |
| 371 | ip6_fib_table_fwding_dpo_remove (u32 fib_index, |
| 372 | const ip6_address_t *addr, |
| 373 | u32 len, |
| 374 | const dpo_id_t *dpo) |
| 375 | { |
| 376 | ip6_fib_table_instance_t *table; |
Neale Ranns | ae80983 | 2018-11-23 09:00:27 -0800 | [diff] [blame] | 377 | clib_bihash_kv_24_8_t kv; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 378 | ip6_address_t *mask; |
| 379 | u64 fib; |
| 380 | |
| 381 | table = &ip6_main.ip6_table[IP6_FIB_TABLE_FWDING]; |
| 382 | mask = &ip6_main.fib_masks[len]; |
| 383 | fib = ((u64)((fib_index))<<32); |
| 384 | |
| 385 | kv.key[0] = addr->as_u64[0] & mask->as_u64[0]; |
| 386 | kv.key[1] = addr->as_u64[1] & mask->as_u64[1]; |
| 387 | kv.key[2] = fib | len; |
| 388 | kv.value = dpo->dpoi_index; |
| 389 | |
Neale Ranns | ae80983 | 2018-11-23 09:00:27 -0800 | [diff] [blame] | 390 | clib_bihash_add_del_24_8(&table->ip6_hash, &kv, 0); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 391 | |
| 392 | /* refcount accounting */ |
| 393 | ASSERT (table->dst_address_length_refcounts[len] > 0); |
| 394 | if (--table->dst_address_length_refcounts[len] == 0) |
| 395 | { |
| 396 | table->non_empty_dst_address_length_bitmap = |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 397 | clib_bitmap_set (table->non_empty_dst_address_length_bitmap, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 398 | 128 - len, 0); |
| 399 | compute_prefix_lengths_in_search_order (table); |
| 400 | } |
| 401 | } |
| 402 | |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 403 | /** |
| 404 | * @brief Context when walking the IPv6 table. Since all VRFs are in the |
| 405 | * same hash table, we need to filter only those we need as we walk |
| 406 | */ |
| 407 | typedef struct ip6_fib_walk_ctx_t_ |
| 408 | { |
| 409 | u32 i6w_fib_index; |
| 410 | fib_table_walk_fn_t i6w_fn; |
| 411 | void *i6w_ctx; |
Neale Ranns | 8954199 | 2017-04-06 04:41:02 -0700 | [diff] [blame] | 412 | fib_prefix_t i6w_root; |
| 413 | fib_prefix_t *i6w_sub_trees; |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 414 | } ip6_fib_walk_ctx_t; |
| 415 | |
| 416 | static int |
| 417 | ip6_fib_walk_cb (clib_bihash_kv_24_8_t * kvp, |
| 418 | void *arg) |
| 419 | { |
| 420 | ip6_fib_walk_ctx_t *ctx = arg; |
Neale Ranns | 8954199 | 2017-04-06 04:41:02 -0700 | [diff] [blame] | 421 | ip6_address_t key; |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 422 | |
| 423 | if ((kvp->key[2] >> 32) == ctx->i6w_fib_index) |
| 424 | { |
Neale Ranns | 8954199 | 2017-04-06 04:41:02 -0700 | [diff] [blame] | 425 | key.as_u64[0] = kvp->key[0]; |
| 426 | key.as_u64[1] = kvp->key[1]; |
| 427 | |
| 428 | if (ip6_destination_matches_route(&ip6_main, |
| 429 | &key, |
| 430 | &ctx->i6w_root.fp_addr.ip6, |
| 431 | ctx->i6w_root.fp_len)) |
| 432 | { |
| 433 | const fib_prefix_t *sub_tree; |
| 434 | int skip = 0; |
| 435 | |
| 436 | /* |
| 437 | * exclude sub-trees the walk does not want to explore |
| 438 | */ |
| 439 | vec_foreach(sub_tree, ctx->i6w_sub_trees) |
| 440 | { |
| 441 | if (ip6_destination_matches_route(&ip6_main, |
| 442 | &key, |
| 443 | &sub_tree->fp_addr.ip6, |
| 444 | sub_tree->fp_len)) |
| 445 | { |
| 446 | skip = 1; |
| 447 | break; |
| 448 | } |
| 449 | } |
| 450 | |
| 451 | if (!skip) |
| 452 | { |
| 453 | switch (ctx->i6w_fn(kvp->value, ctx->i6w_ctx)) |
| 454 | { |
| 455 | case FIB_TABLE_WALK_CONTINUE: |
| 456 | break; |
| 457 | case FIB_TABLE_WALK_SUB_TREE_STOP: { |
| 458 | fib_prefix_t pfx = { |
| 459 | .fp_proto = FIB_PROTOCOL_IP6, |
| 460 | .fp_len = kvp->key[2] & 0xffffffff, |
| 461 | .fp_addr.ip6 = key, |
| 462 | }; |
| 463 | vec_add1(ctx->i6w_sub_trees, pfx); |
| 464 | break; |
| 465 | } |
| 466 | case FIB_TABLE_WALK_STOP: |
| 467 | goto done; |
| 468 | } |
| 469 | } |
| 470 | } |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 471 | } |
Neale Ranns | 8954199 | 2017-04-06 04:41:02 -0700 | [diff] [blame] | 472 | done: |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 473 | |
| 474 | return (1); |
| 475 | } |
| 476 | |
| 477 | void |
| 478 | ip6_fib_table_walk (u32 fib_index, |
| 479 | fib_table_walk_fn_t fn, |
| 480 | void *arg) |
| 481 | { |
| 482 | ip6_fib_walk_ctx_t ctx = { |
| 483 | .i6w_fib_index = fib_index, |
| 484 | .i6w_fn = fn, |
| 485 | .i6w_ctx = arg, |
Neale Ranns | 8954199 | 2017-04-06 04:41:02 -0700 | [diff] [blame] | 486 | .i6w_root = { |
| 487 | .fp_proto = FIB_PROTOCOL_IP6, |
| 488 | }, |
| 489 | .i6w_sub_trees = NULL, |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 490 | }; |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 491 | |
Neale Ranns | ae80983 | 2018-11-23 09:00:27 -0800 | [diff] [blame] | 492 | clib_bihash_foreach_key_value_pair_24_8( |
Neale Ranns | 8954199 | 2017-04-06 04:41:02 -0700 | [diff] [blame] | 493 | &ip6_main.ip6_table[IP6_FIB_TABLE_NON_FWDING].ip6_hash, |
| 494 | ip6_fib_walk_cb, |
| 495 | &ctx); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 496 | |
Neale Ranns | 8954199 | 2017-04-06 04:41:02 -0700 | [diff] [blame] | 497 | vec_free(ctx.i6w_sub_trees); |
| 498 | } |
| 499 | |
| 500 | void |
| 501 | ip6_fib_table_sub_tree_walk (u32 fib_index, |
| 502 | const fib_prefix_t *root, |
| 503 | fib_table_walk_fn_t fn, |
| 504 | void *arg) |
| 505 | { |
| 506 | ip6_fib_walk_ctx_t ctx = { |
| 507 | .i6w_fib_index = fib_index, |
| 508 | .i6w_fn = fn, |
| 509 | .i6w_ctx = arg, |
| 510 | .i6w_root = *root, |
| 511 | }; |
| 512 | |
Neale Ranns | ae80983 | 2018-11-23 09:00:27 -0800 | [diff] [blame] | 513 | clib_bihash_foreach_key_value_pair_24_8( |
Neale Ranns | 8954199 | 2017-04-06 04:41:02 -0700 | [diff] [blame] | 514 | &ip6_main.ip6_table[IP6_FIB_TABLE_NON_FWDING].ip6_hash, |
| 515 | ip6_fib_walk_cb, |
| 516 | &ctx); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 517 | } |
| 518 | |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 519 | typedef struct ip6_fib_show_ctx_t_ { |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 520 | fib_node_index_t *entries; |
| 521 | } ip6_fib_show_ctx_t; |
| 522 | |
Neale Ranns | 8954199 | 2017-04-06 04:41:02 -0700 | [diff] [blame] | 523 | static fib_table_walk_rc_t |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 524 | ip6_fib_table_show_walk (fib_node_index_t fib_entry_index, |
| 525 | void *arg) |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 526 | { |
| 527 | ip6_fib_show_ctx_t *ctx = arg; |
| 528 | |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 529 | vec_add1(ctx->entries, fib_entry_index); |
| 530 | |
Neale Ranns | 8954199 | 2017-04-06 04:41:02 -0700 | [diff] [blame] | 531 | return (FIB_TABLE_WALK_CONTINUE); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 532 | } |
| 533 | |
| 534 | static void |
| 535 | ip6_fib_table_show_all (ip6_fib_t *fib, |
| 536 | vlib_main_t * vm) |
| 537 | { |
| 538 | fib_node_index_t *fib_entry_index; |
| 539 | ip6_fib_show_ctx_t ctx = { |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 540 | .entries = NULL, |
| 541 | }; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 542 | |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 543 | ip6_fib_table_walk(fib->index, ip6_fib_table_show_walk, &ctx); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 544 | vec_sort_with_function(ctx.entries, fib_entry_cmp_for_sort); |
| 545 | |
| 546 | vec_foreach(fib_entry_index, ctx.entries) |
| 547 | { |
| 548 | vlib_cli_output(vm, "%U", |
| 549 | format_fib_entry, |
| 550 | *fib_entry_index, |
| 551 | FIB_ENTRY_FORMAT_BRIEF); |
| 552 | } |
| 553 | |
| 554 | vec_free(ctx.entries); |
| 555 | } |
| 556 | |
| 557 | static void |
| 558 | ip6_fib_table_show_one (ip6_fib_t *fib, |
| 559 | vlib_main_t * vm, |
| 560 | ip6_address_t *address, |
Neale Ranns | 88fc83e | 2017-04-05 08:11:14 -0700 | [diff] [blame] | 561 | u32 mask_len, |
| 562 | int detail) |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 563 | { |
| 564 | vlib_cli_output(vm, "%U", |
| 565 | format_fib_entry, |
| 566 | ip6_fib_table_lookup(fib->index, address, mask_len), |
Neale Ranns | 88fc83e | 2017-04-05 08:11:14 -0700 | [diff] [blame] | 567 | (detail ? |
| 568 | FIB_ENTRY_FORMAT_DETAIL2: |
| 569 | FIB_ENTRY_FORMAT_DETAIL)); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 570 | } |
| 571 | |
Neale Ranns | c87aafa | 2017-11-29 00:59:31 -0800 | [diff] [blame] | 572 | u8 * |
| 573 | format_ip6_fib_table_memory (u8 * s, va_list * args) |
| 574 | { |
Dave Barach | 97f5af0 | 2018-02-22 09:48:45 -0500 | [diff] [blame] | 575 | uword bytes_inuse; |
| 576 | |
Neale Ranns | 05cac30 | 2019-05-28 11:09:40 +0000 | [diff] [blame] | 577 | bytes_inuse = (alloc_arena_next(&(ip6_main.ip6_table[IP6_FIB_TABLE_NON_FWDING].ip6_hash)) + |
| 578 | alloc_arena_next(&(ip6_main.ip6_table[IP6_FIB_TABLE_FWDING].ip6_hash))); |
Dave Barach | 97f5af0 | 2018-02-22 09:48:45 -0500 | [diff] [blame] | 579 | |
Neale Ranns | 05cac30 | 2019-05-28 11:09:40 +0000 | [diff] [blame] | 580 | s = format(s, "%=30s %=6d %=12ld\n", |
Neale Ranns | c87aafa | 2017-11-29 00:59:31 -0800 | [diff] [blame] | 581 | "IPv6 unicast", |
| 582 | pool_elts(ip6_main.fibs), |
Dave Barach | 97f5af0 | 2018-02-22 09:48:45 -0500 | [diff] [blame] | 583 | bytes_inuse); |
Neale Ranns | c87aafa | 2017-11-29 00:59:31 -0800 | [diff] [blame] | 584 | return (s); |
| 585 | } |
| 586 | |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 587 | typedef struct { |
| 588 | u32 fib_index; |
| 589 | u64 count_by_prefix_length[129]; |
| 590 | } count_routes_in_fib_at_prefix_length_arg_t; |
| 591 | |
Neale Ranns | 88fc83e | 2017-04-05 08:11:14 -0700 | [diff] [blame] | 592 | static void |
Neale Ranns | ae80983 | 2018-11-23 09:00:27 -0800 | [diff] [blame] | 593 | count_routes_in_fib_at_prefix_length (clib_bihash_kv_24_8_t * kvp, |
Neale Ranns | 88fc83e | 2017-04-05 08:11:14 -0700 | [diff] [blame] | 594 | void *arg) |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 595 | { |
| 596 | count_routes_in_fib_at_prefix_length_arg_t * ap = arg; |
| 597 | int mask_width; |
| 598 | |
| 599 | if ((kvp->key[2]>>32) != ap->fib_index) |
| 600 | return; |
| 601 | |
| 602 | mask_width = kvp->key[2] & 0xFF; |
| 603 | |
| 604 | ap->count_by_prefix_length[mask_width]++; |
| 605 | } |
| 606 | |
| 607 | static clib_error_t * |
| 608 | ip6_show_fib (vlib_main_t * vm, |
| 609 | unformat_input_t * input, |
| 610 | vlib_cli_command_t * cmd) |
| 611 | { |
| 612 | count_routes_in_fib_at_prefix_length_arg_t _ca, *ca = &_ca; |
| 613 | ip6_main_t * im6 = &ip6_main; |
| 614 | fib_table_t *fib_table; |
| 615 | ip6_fib_t * fib; |
| 616 | int verbose, matching; |
| 617 | ip6_address_t matching_address; |
| 618 | u32 mask_len = 128; |
| 619 | int table_id = -1, fib_index = ~0; |
Neale Ranns | 88fc83e | 2017-04-05 08:11:14 -0700 | [diff] [blame] | 620 | int detail = 0; |
Neale Ranns | 05cac30 | 2019-05-28 11:09:40 +0000 | [diff] [blame] | 621 | int hash = 0; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 622 | |
| 623 | verbose = 1; |
| 624 | matching = 0; |
| 625 | |
| 626 | while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) |
| 627 | { |
| 628 | if (unformat (input, "brief") || |
| 629 | unformat (input, "summary") || |
| 630 | unformat (input, "sum")) |
| 631 | verbose = 0; |
Neale Ranns | 88fc83e | 2017-04-05 08:11:14 -0700 | [diff] [blame] | 632 | |
| 633 | else if (unformat (input, "detail") || |
| 634 | unformat (input, "det")) |
| 635 | detail = 1; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 636 | |
Neale Ranns | 05cac30 | 2019-05-28 11:09:40 +0000 | [diff] [blame] | 637 | else if (unformat (input, "hash") || |
| 638 | unformat (input, "mem") || |
| 639 | unformat (input, "memory")) |
| 640 | hash = 1; |
| 641 | |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 642 | else if (unformat (input, "%U/%d", |
| 643 | unformat_ip6_address, &matching_address, &mask_len)) |
| 644 | matching = 1; |
| 645 | |
| 646 | else if (unformat (input, "%U", unformat_ip6_address, &matching_address)) |
| 647 | matching = 1; |
| 648 | |
| 649 | else if (unformat (input, "table %d", &table_id)) |
| 650 | ; |
| 651 | else if (unformat (input, "index %d", &fib_index)) |
| 652 | ; |
| 653 | else |
| 654 | break; |
| 655 | } |
| 656 | |
Neale Ranns | 05cac30 | 2019-05-28 11:09:40 +0000 | [diff] [blame] | 657 | if (hash) |
| 658 | { |
| 659 | vlib_cli_output (vm, "IPv6 Non-Forwarding Hash Table:\n%U\n", |
| 660 | BV (format_bihash), |
| 661 | &im6->ip6_table[IP6_FIB_TABLE_NON_FWDING].ip6_hash, |
| 662 | detail); |
| 663 | vlib_cli_output (vm, "IPv6 Forwarding Hash Table:\n%U\n", |
| 664 | BV (format_bihash), |
| 665 | &im6->ip6_table[IP6_FIB_TABLE_FWDING].ip6_hash, |
| 666 | detail); |
| 667 | return (NULL); |
| 668 | } |
| 669 | |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 670 | pool_foreach (fib_table, im6->fibs, |
| 671 | ({ |
Neale Ranns | 1500254 | 2017-09-10 04:39:11 -0700 | [diff] [blame] | 672 | fib_source_t source; |
| 673 | u8 *s = NULL; |
| 674 | |
Neale Ranns | a3af337 | 2017-03-28 03:49:52 -0700 | [diff] [blame] | 675 | fib = pool_elt_at_index(im6->v6_fibs, fib_table->ft_index); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 676 | if (table_id >= 0 && table_id != (int)fib->table_id) |
| 677 | continue; |
| 678 | if (fib_index != ~0 && fib_index != (int)fib->index) |
| 679 | continue; |
Neale Ranns | 53da221 | 2018-02-24 02:11:19 -0800 | [diff] [blame] | 680 | if (fib_table->ft_flags & FIB_TABLE_FLAG_IP6_LL) |
| 681 | continue; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 682 | |
Neale Ranns | 9db6ada | 2019-11-08 12:42:31 +0000 | [diff] [blame] | 683 | s = format(s, "%U, fib_index:%d, flow hash:[%U] epoch:%d flags:%U locks:[", |
Neale Ranns | 1500254 | 2017-09-10 04:39:11 -0700 | [diff] [blame] | 684 | format_fib_table_name, fib->index, |
| 685 | FIB_PROTOCOL_IP6, |
| 686 | fib->index, |
| 687 | format_ip_flow_hash_config, |
Neale Ranns | 9db6ada | 2019-11-08 12:42:31 +0000 | [diff] [blame] | 688 | fib_table->ft_flow_hash_config, |
| 689 | fib_table->ft_epoch, |
| 690 | format_fib_table_flags, fib_table->ft_flags); |
| 691 | |
Neale Ranns | 3bab8f9 | 2019-12-04 06:11:00 +0000 | [diff] [blame] | 692 | vec_foreach_index(source, fib_table->ft_locks) |
Neale Ranns | 1500254 | 2017-09-10 04:39:11 -0700 | [diff] [blame] | 693 | { |
| 694 | if (0 != fib_table->ft_locks[source]) |
| 695 | { |
| 696 | s = format(s, "%U:%d, ", |
| 697 | format_fib_source, source, |
| 698 | fib_table->ft_locks[source]); |
| 699 | } |
| 700 | } |
| 701 | s = format (s, "]"); |
Neale Ranns | 2297af0 | 2017-09-12 09:45:04 -0700 | [diff] [blame] | 702 | vlib_cli_output (vm, "%v", s); |
Neale Ranns | 1500254 | 2017-09-10 04:39:11 -0700 | [diff] [blame] | 703 | vec_free(s); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 704 | |
| 705 | /* Show summary? */ |
| 706 | if (! verbose) |
| 707 | { |
Neale Ranns | ae80983 | 2018-11-23 09:00:27 -0800 | [diff] [blame] | 708 | clib_bihash_24_8_t * h = &im6->ip6_table[IP6_FIB_TABLE_NON_FWDING].ip6_hash; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 709 | int len; |
| 710 | |
| 711 | vlib_cli_output (vm, "%=20s%=16s", "Prefix length", "Count"); |
| 712 | |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 713 | clib_memset (ca, 0, sizeof(*ca)); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 714 | ca->fib_index = fib->index; |
| 715 | |
Neale Ranns | ae80983 | 2018-11-23 09:00:27 -0800 | [diff] [blame] | 716 | clib_bihash_foreach_key_value_pair_24_8 |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 717 | (h, count_routes_in_fib_at_prefix_length, ca); |
| 718 | |
| 719 | for (len = 128; len >= 0; len--) |
| 720 | { |
| 721 | if (ca->count_by_prefix_length[len]) |
| 722 | vlib_cli_output (vm, "%=20d%=16lld", |
| 723 | len, ca->count_by_prefix_length[len]); |
| 724 | } |
| 725 | continue; |
| 726 | } |
| 727 | |
| 728 | if (!matching) |
| 729 | { |
| 730 | ip6_fib_table_show_all(fib, vm); |
| 731 | } |
| 732 | else |
| 733 | { |
Neale Ranns | 88fc83e | 2017-04-05 08:11:14 -0700 | [diff] [blame] | 734 | ip6_fib_table_show_one(fib, vm, &matching_address, mask_len, detail); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 735 | } |
| 736 | })); |
| 737 | |
| 738 | return 0; |
| 739 | } |
| 740 | |
| 741 | /*? |
Billy McFall | 0683c9c | 2016-10-13 08:27:31 -0400 | [diff] [blame] | 742 | * This command displays the IPv6 FIB Tables (VRF Tables) and the route |
| 743 | * entries for each table. |
| 744 | * |
| 745 | * @note This command will run for a long time when the FIB tables are |
| 746 | * comprised of millions of entries. For those senarios, consider displaying |
| 747 | * in summary mode. |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 748 | * |
| 749 | * @cliexpar |
Billy McFall | 0683c9c | 2016-10-13 08:27:31 -0400 | [diff] [blame] | 750 | * @parblock |
| 751 | * Example of how to display all the IPv6 FIB tables: |
| 752 | * @cliexstart{show ip6 fib} |
Billy McFall | ebb9a6a | 2016-10-17 11:35:32 -0400 | [diff] [blame] | 753 | * ipv6-VRF:0, fib_index 0, flow hash: src dst sport dport proto |
| 754 | * @::/0 |
| 755 | * unicast-ip6-chain |
| 756 | * [@0]: dpo-load-balance: [index:5 buckets:1 uRPF:5 to:[0:0]] |
| 757 | * [0] [@0]: dpo-drop ip6 |
| 758 | * fe80::/10 |
| 759 | * unicast-ip6-chain |
| 760 | * [@0]: dpo-load-balance: [index:10 buckets:1 uRPF:10 to:[0:0]] |
| 761 | * [0] [@2]: dpo-receive |
| 762 | * ff02::1/128 |
| 763 | * unicast-ip6-chain |
| 764 | * [@0]: dpo-load-balance: [index:8 buckets:1 uRPF:8 to:[0:0]] |
| 765 | * [0] [@2]: dpo-receive |
| 766 | * ff02::2/128 |
| 767 | * unicast-ip6-chain |
| 768 | * [@0]: dpo-load-balance: [index:7 buckets:1 uRPF:7 to:[0:0]] |
| 769 | * [0] [@2]: dpo-receive |
| 770 | * ff02::16/128 |
| 771 | * unicast-ip6-chain |
| 772 | * [@0]: dpo-load-balance: [index:9 buckets:1 uRPF:9 to:[0:0]] |
| 773 | * [0] [@2]: dpo-receive |
| 774 | * ff02::1:ff00:0/104 |
| 775 | * unicast-ip6-chain |
| 776 | * [@0]: dpo-load-balance: [index:6 buckets:1 uRPF:6 to:[0:0]] |
| 777 | * [0] [@2]: dpo-receive |
| 778 | * ipv6-VRF:8, fib_index 1, flow hash: src dst sport dport proto |
| 779 | * @::/0 |
| 780 | * unicast-ip6-chain |
| 781 | * [@0]: dpo-load-balance: [index:21 buckets:1 uRPF:20 to:[0:0]] |
| 782 | * [0] [@0]: dpo-drop ip6 |
| 783 | * @::a:1:1:0:4/126 |
| 784 | * unicast-ip6-chain |
| 785 | * [@0]: dpo-load-balance: [index:27 buckets:1 uRPF:26 to:[0:0]] |
| 786 | * [0] [@4]: ipv6-glean: af_packet0 |
| 787 | * @::a:1:1:0:7/128 |
| 788 | * unicast-ip6-chain |
| 789 | * [@0]: dpo-load-balance: [index:28 buckets:1 uRPF:27 to:[0:0]] |
| 790 | * [0] [@2]: dpo-receive: @::a:1:1:0:7 on af_packet0 |
| 791 | * fe80::/10 |
| 792 | * unicast-ip6-chain |
| 793 | * [@0]: dpo-load-balance: [index:26 buckets:1 uRPF:25 to:[0:0]] |
| 794 | * [0] [@2]: dpo-receive |
| 795 | * fe80::fe:3eff:fe3e:9222/128 |
| 796 | * unicast-ip6-chain |
| 797 | * [@0]: dpo-load-balance: [index:29 buckets:1 uRPF:28 to:[0:0]] |
| 798 | * [0] [@2]: dpo-receive: fe80::fe:3eff:fe3e:9222 on af_packet0 |
| 799 | * ff02::1/128 |
| 800 | * unicast-ip6-chain |
| 801 | * [@0]: dpo-load-balance: [index:24 buckets:1 uRPF:23 to:[0:0]] |
| 802 | * [0] [@2]: dpo-receive |
| 803 | * ff02::2/128 |
| 804 | * unicast-ip6-chain |
| 805 | * [@0]: dpo-load-balance: [index:23 buckets:1 uRPF:22 to:[0:0]] |
| 806 | * [0] [@2]: dpo-receive |
| 807 | * ff02::16/128 |
| 808 | * unicast-ip6-chain |
| 809 | * [@0]: dpo-load-balance: [index:25 buckets:1 uRPF:24 to:[0:0]] |
| 810 | * [0] [@2]: dpo-receive |
| 811 | * ff02::1:ff00:0/104 |
| 812 | * unicast-ip6-chain |
| 813 | * [@0]: dpo-load-balance: [index:22 buckets:1 uRPF:21 to:[0:0]] |
| 814 | * [0] [@2]: dpo-receive |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 815 | * @cliexend |
Billy McFall | ebb9a6a | 2016-10-17 11:35:32 -0400 | [diff] [blame] | 816 | * |
Billy McFall | 0683c9c | 2016-10-13 08:27:31 -0400 | [diff] [blame] | 817 | * Example of how to display a summary of all IPv6 FIB tables: |
| 818 | * @cliexstart{show ip6 fib summary} |
Billy McFall | ebb9a6a | 2016-10-17 11:35:32 -0400 | [diff] [blame] | 819 | * ipv6-VRF:0, fib_index 0, flow hash: src dst sport dport proto |
Billy McFall | 0683c9c | 2016-10-13 08:27:31 -0400 | [diff] [blame] | 820 | * Prefix length Count |
| 821 | * 128 3 |
| 822 | * 104 1 |
Billy McFall | ebb9a6a | 2016-10-17 11:35:32 -0400 | [diff] [blame] | 823 | * 10 1 |
| 824 | * 0 1 |
| 825 | * ipv6-VRF:8, fib_index 1, flow hash: src dst sport dport proto |
Billy McFall | 0683c9c | 2016-10-13 08:27:31 -0400 | [diff] [blame] | 826 | * Prefix length Count |
| 827 | * 128 5 |
| 828 | * 126 1 |
| 829 | * 104 1 |
Billy McFall | ebb9a6a | 2016-10-17 11:35:32 -0400 | [diff] [blame] | 830 | * 10 1 |
| 831 | * 0 1 |
Billy McFall | 0683c9c | 2016-10-13 08:27:31 -0400 | [diff] [blame] | 832 | * @cliexend |
| 833 | * @endparblock |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 834 | ?*/ |
Billy McFall | 0683c9c | 2016-10-13 08:27:31 -0400 | [diff] [blame] | 835 | /* *INDENT-OFF* */ |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 836 | VLIB_CLI_COMMAND (ip6_show_fib_command, static) = { |
| 837 | .path = "show ip6 fib", |
Neale Ranns | 88fc83e | 2017-04-05 08:11:14 -0700 | [diff] [blame] | 838 | .short_help = "show ip6 fib [summary] [table <table-id>] [index <fib-id>] [<ip6-addr>[/<width>]] [detail]", |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 839 | .function = ip6_show_fib, |
| 840 | }; |
Billy McFall | 0683c9c | 2016-10-13 08:27:31 -0400 | [diff] [blame] | 841 | /* *INDENT-ON* */ |