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 | 5a59b2b | 2020-10-19 14:47:20 +0000 | [diff] [blame] | 23 | ip6_fib_table_instance_t ip6_fib_table[IP6_FIB_NUM_TABLES]; |
| 24 | |
| 25 | /* ip6 lookup table config parameters */ |
| 26 | u32 ip6_fib_table_nbuckets; |
| 27 | uword ip6_fib_table_size; |
| 28 | |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 29 | static void |
| 30 | vnet_ip6_fib_init (u32 fib_index) |
| 31 | { |
| 32 | fib_prefix_t pfx = { |
| 33 | .fp_proto = FIB_PROTOCOL_IP6, |
| 34 | .fp_len = 0, |
| 35 | .fp_addr = { |
| 36 | .ip6 = { |
| 37 | { 0, 0, }, |
| 38 | }, |
| 39 | } |
| 40 | }; |
| 41 | |
| 42 | /* |
| 43 | * Add the default route. |
| 44 | */ |
| 45 | fib_table_entry_special_add(fib_index, |
| 46 | &pfx, |
| 47 | FIB_SOURCE_DEFAULT_ROUTE, |
Neale Ranns | a055830 | 2017-04-13 00:44:52 -0700 | [diff] [blame] | 48 | FIB_ENTRY_FLAG_DROP); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 49 | |
| 50 | /* |
Neale Ranns | 53da221 | 2018-02-24 02:11:19 -0800 | [diff] [blame] | 51 | * all link local via the link local lookup DPO |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 52 | */ |
| 53 | pfx.fp_addr.ip6.as_u64[0] = clib_host_to_net_u64 (0xFE80000000000000ULL); |
| 54 | pfx.fp_addr.ip6.as_u64[1] = 0; |
| 55 | pfx.fp_len = 10; |
Neale Ranns | 53da221 | 2018-02-24 02:11:19 -0800 | [diff] [blame] | 56 | fib_table_entry_special_dpo_add(fib_index, |
| 57 | &pfx, |
| 58 | FIB_SOURCE_SPECIAL, |
| 59 | FIB_ENTRY_FLAG_NONE, |
| 60 | ip6_ll_dpo_get()); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | static u32 |
Neale Ranns | 1500254 | 2017-09-10 04:39:11 -0700 | [diff] [blame] | 64 | create_fib_with_table_id (u32 table_id, |
Neale Ranns | 53da221 | 2018-02-24 02:11:19 -0800 | [diff] [blame] | 65 | fib_source_t src, |
| 66 | fib_table_flags_t flags, |
| 67 | u8 *desc) |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 68 | { |
| 69 | fib_table_t *fib_table; |
Neale Ranns | a3af337 | 2017-03-28 03:49:52 -0700 | [diff] [blame] | 70 | ip6_fib_t *v6_fib; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 71 | |
Dave Barach | eb987d3 | 2018-05-03 08:26:39 -0400 | [diff] [blame] | 72 | pool_get(ip6_main.fibs, fib_table); |
Neale Ranns | a3af337 | 2017-03-28 03:49:52 -0700 | [diff] [blame] | 73 | 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] | 74 | |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 75 | clib_memset(fib_table, 0, sizeof(*fib_table)); |
| 76 | clib_memset(v6_fib, 0, sizeof(*v6_fib)); |
Neale Ranns | a3af337 | 2017-03-28 03:49:52 -0700 | [diff] [blame] | 77 | |
| 78 | ASSERT((fib_table - ip6_main.fibs) == |
| 79 | (v6_fib - ip6_main.v6_fibs)); |
| 80 | |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 81 | fib_table->ft_proto = FIB_PROTOCOL_IP6; |
| 82 | fib_table->ft_index = |
Neale Ranns | a3af337 | 2017-03-28 03:49:52 -0700 | [diff] [blame] | 83 | v6_fib->index = |
| 84 | (fib_table - ip6_main.fibs); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 85 | |
| 86 | hash_set(ip6_main.fib_index_by_table_id, table_id, fib_table->ft_index); |
| 87 | |
| 88 | fib_table->ft_table_id = |
Neale Ranns | a3af337 | 2017-03-28 03:49:52 -0700 | [diff] [blame] | 89 | v6_fib->table_id = |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 90 | table_id; |
Neale Ranns | 227038a | 2017-04-21 01:07:59 -0700 | [diff] [blame] | 91 | fib_table->ft_flow_hash_config = IP_FLOW_HASH_DEFAULT; |
Neale Ranns | 53da221 | 2018-02-24 02:11:19 -0800 | [diff] [blame] | 92 | fib_table->ft_flags = flags; |
| 93 | fib_table->ft_desc = desc; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 94 | |
| 95 | vnet_ip6_fib_init(fib_table->ft_index); |
Neale Ranns | 1500254 | 2017-09-10 04:39:11 -0700 | [diff] [blame] | 96 | fib_table_lock(fib_table->ft_index, FIB_PROTOCOL_IP6, src); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 97 | |
| 98 | return (fib_table->ft_index); |
| 99 | } |
| 100 | |
| 101 | u32 |
Neale Ranns | 1500254 | 2017-09-10 04:39:11 -0700 | [diff] [blame] | 102 | ip6_fib_table_find_or_create_and_lock (u32 table_id, |
| 103 | fib_source_t src) |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 104 | { |
| 105 | uword * p; |
| 106 | |
| 107 | p = hash_get (ip6_main.fib_index_by_table_id, table_id); |
| 108 | if (NULL == p) |
Neale Ranns | 53da221 | 2018-02-24 02:11:19 -0800 | [diff] [blame] | 109 | return create_fib_with_table_id(table_id, src, |
| 110 | FIB_TABLE_FLAG_NONE, |
| 111 | NULL); |
| 112 | |
Neale Ranns | 1500254 | 2017-09-10 04:39:11 -0700 | [diff] [blame] | 113 | fib_table_lock(p[0], FIB_PROTOCOL_IP6, src); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 114 | |
| 115 | return (p[0]); |
| 116 | } |
| 117 | |
| 118 | u32 |
Neale Ranns | 53da221 | 2018-02-24 02:11:19 -0800 | [diff] [blame] | 119 | ip6_fib_table_create_and_lock (fib_source_t src, |
| 120 | fib_table_flags_t flags, |
| 121 | u8 *desc) |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 122 | { |
Neale Ranns | 53da221 | 2018-02-24 02:11:19 -0800 | [diff] [blame] | 123 | return (create_fib_with_table_id(~0, src, flags, desc)); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 124 | } |
| 125 | |
| 126 | void |
| 127 | ip6_fib_table_destroy (u32 fib_index) |
| 128 | { |
Neale Ranns | 53da221 | 2018-02-24 02:11:19 -0800 | [diff] [blame] | 129 | /* |
| 130 | * all link local first ... |
| 131 | */ |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 132 | fib_prefix_t pfx = { |
| 133 | .fp_proto = FIB_PROTOCOL_IP6, |
Neale Ranns | 53da221 | 2018-02-24 02:11:19 -0800 | [diff] [blame] | 134 | .fp_len = 10, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 135 | .fp_addr = { |
| 136 | .ip6 = { |
Neale Ranns | 53da221 | 2018-02-24 02:11:19 -0800 | [diff] [blame] | 137 | .as_u8 = { |
| 138 | [0] = 0xFE, |
| 139 | [1] = 0x80, |
| 140 | }, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 141 | }, |
| 142 | } |
| 143 | }; |
Neale Ranns | 53da221 | 2018-02-24 02:11:19 -0800 | [diff] [blame] | 144 | fib_table_entry_delete(fib_index, |
| 145 | &pfx, |
| 146 | FIB_SOURCE_SPECIAL); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 147 | |
| 148 | /* |
Neale Ranns | 53da221 | 2018-02-24 02:11:19 -0800 | [diff] [blame] | 149 | * ... then the default route. |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 150 | */ |
Neale Ranns | 53da221 | 2018-02-24 02:11:19 -0800 | [diff] [blame] | 151 | pfx.fp_addr.ip6.as_u64[0] = 0; |
| 152 | pfx.fp_len = 00; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 153 | fib_table_entry_special_remove(fib_index, |
| 154 | &pfx, |
| 155 | FIB_SOURCE_DEFAULT_ROUTE); |
| 156 | |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 157 | fib_table_t *fib_table = fib_table_get(fib_index, FIB_PROTOCOL_IP6); |
| 158 | fib_source_t source; |
Neale Ranns | 53da221 | 2018-02-24 02:11:19 -0800 | [diff] [blame] | 159 | |
Neale Ranns | 3bab8f9 | 2019-12-04 06:11:00 +0000 | [diff] [blame] | 160 | /* |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 161 | * validate no more routes. |
| 162 | */ |
Matthew Smith | ee167e5 | 2020-07-02 17:24:17 -0500 | [diff] [blame] | 163 | #if CLIB_DEBUG > 0 |
Neale Ranns | cbe25aa | 2019-09-30 10:53:31 +0000 | [diff] [blame] | 164 | if (0 != fib_table->ft_total_route_counts) |
| 165 | fib_table_assert_empty(fib_table); |
| 166 | #endif |
| 167 | |
Neale Ranns | 3bab8f9 | 2019-12-04 06:11:00 +0000 | [diff] [blame] | 168 | vec_foreach_index(source, fib_table->ft_src_route_counts) |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 169 | { |
| 170 | ASSERT(0 == fib_table->ft_src_route_counts[source]); |
| 171 | } |
| 172 | |
| 173 | if (~0 != fib_table->ft_table_id) |
| 174 | { |
| 175 | hash_unset (ip6_main.fib_index_by_table_id, fib_table->ft_table_id); |
| 176 | } |
Steven Luong | 97866a3 | 2022-02-08 07:59:11 -0800 | [diff] [blame^] | 177 | vec_free (fib_table->ft_locks); |
Neale Ranns | 3bab8f9 | 2019-12-04 06:11:00 +0000 | [diff] [blame] | 178 | vec_free(fib_table->ft_src_route_counts); |
Neale Ranns | a3af337 | 2017-03-28 03:49:52 -0700 | [diff] [blame] | 179 | pool_put_index(ip6_main.v6_fibs, fib_table->ft_index); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 180 | pool_put(ip6_main.fibs, fib_table); |
| 181 | } |
| 182 | |
| 183 | fib_node_index_t |
| 184 | ip6_fib_table_lookup (u32 fib_index, |
| 185 | const ip6_address_t *addr, |
| 186 | u32 len) |
| 187 | { |
Dave Barach | 908a5ea | 2017-07-14 12:42:21 -0400 | [diff] [blame] | 188 | ip6_fib_table_instance_t *table; |
Neale Ranns | ae80983 | 2018-11-23 09:00:27 -0800 | [diff] [blame] | 189 | clib_bihash_kv_24_8_t kv, value; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 190 | int i, n_p, rv; |
| 191 | u64 fib; |
| 192 | |
Neale Ranns | 5a59b2b | 2020-10-19 14:47:20 +0000 | [diff] [blame] | 193 | table = &ip6_fib_table[IP6_FIB_TABLE_NON_FWDING]; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 194 | n_p = vec_len (table->prefix_lengths_in_search_order); |
| 195 | |
| 196 | kv.key[0] = addr->as_u64[0]; |
| 197 | kv.key[1] = addr->as_u64[1]; |
| 198 | fib = ((u64)((fib_index))<<32); |
| 199 | |
| 200 | /* |
| 201 | * start search from a mask length same length or shorter. |
| 202 | * we don't want matches longer than the mask passed |
| 203 | */ |
| 204 | i = 0; |
| 205 | while (i < n_p && table->prefix_lengths_in_search_order[i] > len) |
| 206 | { |
| 207 | i++; |
| 208 | } |
| 209 | |
| 210 | for (; i < n_p; i++) |
| 211 | { |
| 212 | int dst_address_length = table->prefix_lengths_in_search_order[i]; |
| 213 | ip6_address_t * mask = &ip6_main.fib_masks[dst_address_length]; |
| 214 | |
| 215 | ASSERT(dst_address_length >= 0 && dst_address_length <= 128); |
| 216 | //As lengths are decreasing, masks are increasingly specific. |
| 217 | kv.key[0] &= mask->as_u64[0]; |
| 218 | kv.key[1] &= mask->as_u64[1]; |
| 219 | kv.key[2] = fib | dst_address_length; |
| 220 | |
Neale Ranns | ae80983 | 2018-11-23 09:00:27 -0800 | [diff] [blame] | 221 | 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] | 222 | if (rv == 0) |
| 223 | return value.value; |
| 224 | } |
| 225 | |
| 226 | return (FIB_NODE_INDEX_INVALID); |
| 227 | } |
| 228 | |
| 229 | fib_node_index_t |
| 230 | ip6_fib_table_lookup_exact_match (u32 fib_index, |
| 231 | const ip6_address_t *addr, |
| 232 | u32 len) |
| 233 | { |
Dave Barach | 908a5ea | 2017-07-14 12:42:21 -0400 | [diff] [blame] | 234 | ip6_fib_table_instance_t *table; |
Neale Ranns | ae80983 | 2018-11-23 09:00:27 -0800 | [diff] [blame] | 235 | clib_bihash_kv_24_8_t kv, value; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 236 | ip6_address_t *mask; |
| 237 | u64 fib; |
| 238 | int rv; |
| 239 | |
Neale Ranns | 5a59b2b | 2020-10-19 14:47:20 +0000 | [diff] [blame] | 240 | table = &ip6_fib_table[IP6_FIB_TABLE_NON_FWDING]; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 241 | mask = &ip6_main.fib_masks[len]; |
| 242 | fib = ((u64)((fib_index))<<32); |
| 243 | |
| 244 | kv.key[0] = addr->as_u64[0] & mask->as_u64[0]; |
| 245 | kv.key[1] = addr->as_u64[1] & mask->as_u64[1]; |
| 246 | kv.key[2] = fib | len; |
| 247 | |
Neale Ranns | ae80983 | 2018-11-23 09:00:27 -0800 | [diff] [blame] | 248 | 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] | 249 | if (rv == 0) |
| 250 | return value.value; |
| 251 | |
| 252 | return (FIB_NODE_INDEX_INVALID); |
| 253 | } |
| 254 | |
| 255 | static void |
| 256 | compute_prefix_lengths_in_search_order (ip6_fib_table_instance_t *table) |
| 257 | { |
Neale Ranns | 42845dd | 2020-05-26 13:12:17 +0000 | [diff] [blame] | 258 | u8 *old, *prefix_lengths_in_search_order = NULL; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 259 | int i; |
Neale Ranns | 42845dd | 2020-05-26 13:12:17 +0000 | [diff] [blame] | 260 | |
| 261 | /* |
| 262 | * build the list in a scratch space then cutover so the workers |
| 263 | * can continue uninterrupted. |
| 264 | */ |
| 265 | old = table->prefix_lengths_in_search_order; |
| 266 | |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 267 | /* Note: bitmap reversed so this is in fact a longest prefix match */ |
Damjan Marion | f0ca1e8 | 2020-12-13 23:26:56 +0100 | [diff] [blame] | 268 | clib_bitmap_foreach (i, table->non_empty_dst_address_length_bitmap) |
| 269 | { |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 270 | int dst_address_length = 128 - i; |
Neale Ranns | 42845dd | 2020-05-26 13:12:17 +0000 | [diff] [blame] | 271 | vec_add1(prefix_lengths_in_search_order, dst_address_length); |
Damjan Marion | f0ca1e8 | 2020-12-13 23:26:56 +0100 | [diff] [blame] | 272 | } |
Neale Ranns | 42845dd | 2020-05-26 13:12:17 +0000 | [diff] [blame] | 273 | |
| 274 | table->prefix_lengths_in_search_order = prefix_lengths_in_search_order; |
| 275 | |
| 276 | /* |
| 277 | * let the workers go once round the track before we free the old set |
| 278 | */ |
| 279 | vlib_worker_wait_one_loop(); |
| 280 | vec_free(old); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 281 | } |
| 282 | |
| 283 | void |
| 284 | ip6_fib_table_entry_remove (u32 fib_index, |
| 285 | const ip6_address_t *addr, |
| 286 | u32 len) |
| 287 | { |
| 288 | ip6_fib_table_instance_t *table; |
Neale Ranns | ae80983 | 2018-11-23 09:00:27 -0800 | [diff] [blame] | 289 | clib_bihash_kv_24_8_t kv; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 290 | ip6_address_t *mask; |
| 291 | u64 fib; |
| 292 | |
Neale Ranns | 5a59b2b | 2020-10-19 14:47:20 +0000 | [diff] [blame] | 293 | table = &ip6_fib_table[IP6_FIB_TABLE_NON_FWDING]; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 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 | |
Neale Ranns | ae80983 | 2018-11-23 09:00:27 -0800 | [diff] [blame] | 301 | clib_bihash_add_del_24_8(&table->ip6_hash, &kv, 0); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 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 | |
| 314 | void |
| 315 | ip6_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; |
Neale Ranns | ae80983 | 2018-11-23 09:00:27 -0800 | [diff] [blame] | 321 | clib_bihash_kv_24_8_t kv; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 322 | ip6_address_t *mask; |
| 323 | u64 fib; |
| 324 | |
Neale Ranns | 5a59b2b | 2020-10-19 14:47:20 +0000 | [diff] [blame] | 325 | table = &ip6_fib_table[IP6_FIB_TABLE_NON_FWDING]; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 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 | |
Neale Ranns | ae80983 | 2018-11-23 09:00:27 -0800 | [diff] [blame] | 334 | clib_bihash_add_del_24_8(&table->ip6_hash, &kv, 1); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 335 | |
Neale Ranns | 42845dd | 2020-05-26 13:12:17 +0000 | [diff] [blame] | 336 | if (0 == 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 | } |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 343 | } |
| 344 | |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 345 | u32 ip6_fib_table_fwding_lookup_with_if_index (ip6_main_t * im, |
| 346 | u32 sw_if_index, |
| 347 | const ip6_address_t * dst) |
| 348 | { |
| 349 | 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] | 350 | return ip6_fib_table_fwding_lookup(fib_index, dst); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 351 | } |
| 352 | |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 353 | u32 |
| 354 | ip6_fib_table_get_index_for_sw_if_index (u32 sw_if_index) |
| 355 | { |
| 356 | if (sw_if_index >= vec_len(ip6_main.fib_index_by_sw_if_index)) |
| 357 | { |
| 358 | /* |
| 359 | * This is the case for interfaces that are not yet mapped to |
| 360 | * a IP table |
| 361 | */ |
| 362 | return (~0); |
| 363 | } |
| 364 | return (ip6_main.fib_index_by_sw_if_index[sw_if_index]); |
| 365 | } |
| 366 | |
| 367 | void |
| 368 | ip6_fib_table_fwding_dpo_update (u32 fib_index, |
| 369 | const ip6_address_t *addr, |
| 370 | u32 len, |
| 371 | const dpo_id_t *dpo) |
| 372 | { |
| 373 | ip6_fib_table_instance_t *table; |
Neale Ranns | ae80983 | 2018-11-23 09:00:27 -0800 | [diff] [blame] | 374 | clib_bihash_kv_24_8_t kv; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 375 | ip6_address_t *mask; |
| 376 | u64 fib; |
| 377 | |
Neale Ranns | 5a59b2b | 2020-10-19 14:47:20 +0000 | [diff] [blame] | 378 | table = &ip6_fib_table[IP6_FIB_TABLE_FWDING]; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 379 | mask = &ip6_main.fib_masks[len]; |
| 380 | fib = ((u64)((fib_index))<<32); |
| 381 | |
| 382 | kv.key[0] = addr->as_u64[0] & mask->as_u64[0]; |
| 383 | kv.key[1] = addr->as_u64[1] & mask->as_u64[1]; |
| 384 | kv.key[2] = fib | len; |
| 385 | kv.value = dpo->dpoi_index; |
| 386 | |
Neale Ranns | ae80983 | 2018-11-23 09:00:27 -0800 | [diff] [blame] | 387 | clib_bihash_add_del_24_8(&table->ip6_hash, &kv, 1); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 388 | |
Neale Ranns | 42845dd | 2020-05-26 13:12:17 +0000 | [diff] [blame] | 389 | if (0 == table->dst_address_length_refcounts[len]++) |
| 390 | { |
| 391 | table->non_empty_dst_address_length_bitmap = |
| 392 | clib_bitmap_set (table->non_empty_dst_address_length_bitmap, |
| 393 | 128 - len, 1); |
| 394 | compute_prefix_lengths_in_search_order (table); |
| 395 | } |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 396 | } |
| 397 | |
| 398 | void |
| 399 | ip6_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; |
Neale Ranns | ae80983 | 2018-11-23 09:00:27 -0800 | [diff] [blame] | 405 | clib_bihash_kv_24_8_t kv; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 406 | ip6_address_t *mask; |
| 407 | u64 fib; |
| 408 | |
Neale Ranns | 5a59b2b | 2020-10-19 14:47:20 +0000 | [diff] [blame] | 409 | table = &ip6_fib_table[IP6_FIB_TABLE_FWDING]; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 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 | |
Neale Ranns | ae80983 | 2018-11-23 09:00:27 -0800 | [diff] [blame] | 418 | clib_bihash_add_del_24_8(&table->ip6_hash, &kv, 0); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 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 Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 425 | clib_bitmap_set (table->non_empty_dst_address_length_bitmap, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 426 | 128 - len, 0); |
| 427 | compute_prefix_lengths_in_search_order (table); |
| 428 | } |
| 429 | } |
| 430 | |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 431 | /** |
| 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 | */ |
| 435 | typedef struct ip6_fib_walk_ctx_t_ |
| 436 | { |
| 437 | u32 i6w_fib_index; |
| 438 | fib_table_walk_fn_t i6w_fn; |
| 439 | void *i6w_ctx; |
Neale Ranns | 8954199 | 2017-04-06 04:41:02 -0700 | [diff] [blame] | 440 | fib_prefix_t i6w_root; |
| 441 | fib_prefix_t *i6w_sub_trees; |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 442 | } ip6_fib_walk_ctx_t; |
| 443 | |
| 444 | static int |
| 445 | ip6_fib_walk_cb (clib_bihash_kv_24_8_t * kvp, |
| 446 | void *arg) |
| 447 | { |
| 448 | ip6_fib_walk_ctx_t *ctx = arg; |
Neale Ranns | 8954199 | 2017-04-06 04:41:02 -0700 | [diff] [blame] | 449 | ip6_address_t key; |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 450 | |
| 451 | if ((kvp->key[2] >> 32) == ctx->i6w_fib_index) |
| 452 | { |
Neale Ranns | 8954199 | 2017-04-06 04:41:02 -0700 | [diff] [blame] | 453 | key.as_u64[0] = kvp->key[0]; |
| 454 | key.as_u64[1] = kvp->key[1]; |
| 455 | |
| 456 | if (ip6_destination_matches_route(&ip6_main, |
| 457 | &key, |
| 458 | &ctx->i6w_root.fp_addr.ip6, |
| 459 | ctx->i6w_root.fp_len)) |
| 460 | { |
| 461 | const fib_prefix_t *sub_tree; |
| 462 | int skip = 0; |
| 463 | |
| 464 | /* |
| 465 | * exclude sub-trees the walk does not want to explore |
| 466 | */ |
| 467 | vec_foreach(sub_tree, ctx->i6w_sub_trees) |
| 468 | { |
| 469 | if (ip6_destination_matches_route(&ip6_main, |
| 470 | &key, |
| 471 | &sub_tree->fp_addr.ip6, |
| 472 | sub_tree->fp_len)) |
| 473 | { |
| 474 | skip = 1; |
| 475 | break; |
| 476 | } |
| 477 | } |
| 478 | |
| 479 | if (!skip) |
| 480 | { |
| 481 | switch (ctx->i6w_fn(kvp->value, ctx->i6w_ctx)) |
| 482 | { |
| 483 | case FIB_TABLE_WALK_CONTINUE: |
| 484 | break; |
| 485 | case FIB_TABLE_WALK_SUB_TREE_STOP: { |
| 486 | fib_prefix_t pfx = { |
| 487 | .fp_proto = FIB_PROTOCOL_IP6, |
| 488 | .fp_len = kvp->key[2] & 0xffffffff, |
| 489 | .fp_addr.ip6 = key, |
| 490 | }; |
| 491 | vec_add1(ctx->i6w_sub_trees, pfx); |
| 492 | break; |
| 493 | } |
| 494 | case FIB_TABLE_WALK_STOP: |
| 495 | goto done; |
| 496 | } |
| 497 | } |
| 498 | } |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 499 | } |
Neale Ranns | 8954199 | 2017-04-06 04:41:02 -0700 | [diff] [blame] | 500 | done: |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 501 | |
| 502 | return (1); |
| 503 | } |
| 504 | |
| 505 | void |
| 506 | ip6_fib_table_walk (u32 fib_index, |
| 507 | fib_table_walk_fn_t fn, |
| 508 | void *arg) |
| 509 | { |
| 510 | ip6_fib_walk_ctx_t ctx = { |
| 511 | .i6w_fib_index = fib_index, |
| 512 | .i6w_fn = fn, |
| 513 | .i6w_ctx = arg, |
Neale Ranns | 8954199 | 2017-04-06 04:41:02 -0700 | [diff] [blame] | 514 | .i6w_root = { |
| 515 | .fp_proto = FIB_PROTOCOL_IP6, |
| 516 | }, |
| 517 | .i6w_sub_trees = NULL, |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 518 | }; |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 519 | |
Neale Ranns | ae80983 | 2018-11-23 09:00:27 -0800 | [diff] [blame] | 520 | clib_bihash_foreach_key_value_pair_24_8( |
Neale Ranns | 5a59b2b | 2020-10-19 14:47:20 +0000 | [diff] [blame] | 521 | &ip6_fib_table[IP6_FIB_TABLE_NON_FWDING].ip6_hash, |
Neale Ranns | 8954199 | 2017-04-06 04:41:02 -0700 | [diff] [blame] | 522 | ip6_fib_walk_cb, |
| 523 | &ctx); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 524 | |
Neale Ranns | 8954199 | 2017-04-06 04:41:02 -0700 | [diff] [blame] | 525 | vec_free(ctx.i6w_sub_trees); |
| 526 | } |
| 527 | |
| 528 | void |
| 529 | ip6_fib_table_sub_tree_walk (u32 fib_index, |
| 530 | const fib_prefix_t *root, |
| 531 | fib_table_walk_fn_t fn, |
| 532 | void *arg) |
| 533 | { |
| 534 | ip6_fib_walk_ctx_t ctx = { |
| 535 | .i6w_fib_index = fib_index, |
| 536 | .i6w_fn = fn, |
| 537 | .i6w_ctx = arg, |
| 538 | .i6w_root = *root, |
| 539 | }; |
| 540 | |
Neale Ranns | ae80983 | 2018-11-23 09:00:27 -0800 | [diff] [blame] | 541 | clib_bihash_foreach_key_value_pair_24_8( |
Neale Ranns | 5a59b2b | 2020-10-19 14:47:20 +0000 | [diff] [blame] | 542 | &ip6_fib_table[IP6_FIB_TABLE_NON_FWDING].ip6_hash, |
Neale Ranns | 8954199 | 2017-04-06 04:41:02 -0700 | [diff] [blame] | 543 | ip6_fib_walk_cb, |
| 544 | &ctx); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 545 | } |
| 546 | |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 547 | typedef struct ip6_fib_show_ctx_t_ { |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 548 | fib_node_index_t *entries; |
| 549 | } ip6_fib_show_ctx_t; |
| 550 | |
Neale Ranns | 8954199 | 2017-04-06 04:41:02 -0700 | [diff] [blame] | 551 | static fib_table_walk_rc_t |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 552 | ip6_fib_table_show_walk (fib_node_index_t fib_entry_index, |
| 553 | void *arg) |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 554 | { |
| 555 | ip6_fib_show_ctx_t *ctx = arg; |
| 556 | |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 557 | vec_add1(ctx->entries, fib_entry_index); |
| 558 | |
Neale Ranns | 8954199 | 2017-04-06 04:41:02 -0700 | [diff] [blame] | 559 | return (FIB_TABLE_WALK_CONTINUE); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 560 | } |
| 561 | |
| 562 | static void |
| 563 | ip6_fib_table_show_all (ip6_fib_t *fib, |
| 564 | vlib_main_t * vm) |
| 565 | { |
| 566 | fib_node_index_t *fib_entry_index; |
| 567 | ip6_fib_show_ctx_t ctx = { |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 568 | .entries = NULL, |
| 569 | }; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 570 | |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 571 | ip6_fib_table_walk(fib->index, ip6_fib_table_show_walk, &ctx); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 572 | vec_sort_with_function(ctx.entries, fib_entry_cmp_for_sort); |
| 573 | |
| 574 | vec_foreach(fib_entry_index, ctx.entries) |
| 575 | { |
| 576 | vlib_cli_output(vm, "%U", |
| 577 | format_fib_entry, |
| 578 | *fib_entry_index, |
| 579 | FIB_ENTRY_FORMAT_BRIEF); |
| 580 | } |
| 581 | |
| 582 | vec_free(ctx.entries); |
| 583 | } |
| 584 | |
| 585 | static void |
| 586 | ip6_fib_table_show_one (ip6_fib_t *fib, |
| 587 | vlib_main_t * vm, |
| 588 | ip6_address_t *address, |
Neale Ranns | 88fc83e | 2017-04-05 08:11:14 -0700 | [diff] [blame] | 589 | u32 mask_len, |
| 590 | int detail) |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 591 | { |
| 592 | vlib_cli_output(vm, "%U", |
| 593 | format_fib_entry, |
| 594 | ip6_fib_table_lookup(fib->index, address, mask_len), |
Neale Ranns | 88fc83e | 2017-04-05 08:11:14 -0700 | [diff] [blame] | 595 | (detail ? |
| 596 | FIB_ENTRY_FORMAT_DETAIL2: |
| 597 | FIB_ENTRY_FORMAT_DETAIL)); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 598 | } |
| 599 | |
Neale Ranns | c87aafa | 2017-11-29 00:59:31 -0800 | [diff] [blame] | 600 | u8 * |
| 601 | format_ip6_fib_table_memory (u8 * s, va_list * args) |
| 602 | { |
Dave Barach | 97f5af0 | 2018-02-22 09:48:45 -0500 | [diff] [blame] | 603 | uword bytes_inuse; |
| 604 | |
Neale Ranns | 5a59b2b | 2020-10-19 14:47:20 +0000 | [diff] [blame] | 605 | bytes_inuse = (alloc_arena_next(&(ip6_fib_table[IP6_FIB_TABLE_NON_FWDING].ip6_hash)) + |
| 606 | alloc_arena_next(&(ip6_fib_table[IP6_FIB_TABLE_FWDING].ip6_hash))); |
Dave Barach | 97f5af0 | 2018-02-22 09:48:45 -0500 | [diff] [blame] | 607 | |
Neale Ranns | 05cac30 | 2019-05-28 11:09:40 +0000 | [diff] [blame] | 608 | s = format(s, "%=30s %=6d %=12ld\n", |
Neale Ranns | c87aafa | 2017-11-29 00:59:31 -0800 | [diff] [blame] | 609 | "IPv6 unicast", |
| 610 | pool_elts(ip6_main.fibs), |
Dave Barach | 97f5af0 | 2018-02-22 09:48:45 -0500 | [diff] [blame] | 611 | bytes_inuse); |
Neale Ranns | c87aafa | 2017-11-29 00:59:31 -0800 | [diff] [blame] | 612 | return (s); |
| 613 | } |
| 614 | |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 615 | typedef struct { |
| 616 | u32 fib_index; |
| 617 | u64 count_by_prefix_length[129]; |
| 618 | } count_routes_in_fib_at_prefix_length_arg_t; |
| 619 | |
Neale Ranns | f50bac1 | 2019-12-06 05:53:17 +0000 | [diff] [blame] | 620 | static int |
Neale Ranns | ae80983 | 2018-11-23 09:00:27 -0800 | [diff] [blame] | 621 | 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] | 622 | void *arg) |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 623 | { |
| 624 | count_routes_in_fib_at_prefix_length_arg_t * ap = arg; |
| 625 | int mask_width; |
| 626 | |
| 627 | if ((kvp->key[2]>>32) != ap->fib_index) |
Neale Ranns | f50bac1 | 2019-12-06 05:53:17 +0000 | [diff] [blame] | 628 | return (BIHASH_WALK_CONTINUE); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 629 | |
| 630 | mask_width = kvp->key[2] & 0xFF; |
| 631 | |
| 632 | ap->count_by_prefix_length[mask_width]++; |
Neale Ranns | f50bac1 | 2019-12-06 05:53:17 +0000 | [diff] [blame] | 633 | |
| 634 | return (BIHASH_WALK_CONTINUE); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 635 | } |
| 636 | |
| 637 | static clib_error_t * |
| 638 | ip6_show_fib (vlib_main_t * vm, |
| 639 | unformat_input_t * input, |
| 640 | vlib_cli_command_t * cmd) |
| 641 | { |
| 642 | count_routes_in_fib_at_prefix_length_arg_t _ca, *ca = &_ca; |
| 643 | ip6_main_t * im6 = &ip6_main; |
| 644 | fib_table_t *fib_table; |
| 645 | ip6_fib_t * fib; |
| 646 | int verbose, matching; |
| 647 | ip6_address_t matching_address; |
| 648 | u32 mask_len = 128; |
| 649 | int table_id = -1, fib_index = ~0; |
Neale Ranns | 88fc83e | 2017-04-05 08:11:14 -0700 | [diff] [blame] | 650 | int detail = 0; |
Neale Ranns | 05cac30 | 2019-05-28 11:09:40 +0000 | [diff] [blame] | 651 | int hash = 0; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 652 | |
| 653 | verbose = 1; |
| 654 | matching = 0; |
| 655 | |
| 656 | while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) |
| 657 | { |
| 658 | if (unformat (input, "brief") || |
| 659 | unformat (input, "summary") || |
| 660 | unformat (input, "sum")) |
| 661 | verbose = 0; |
Neale Ranns | 88fc83e | 2017-04-05 08:11:14 -0700 | [diff] [blame] | 662 | |
| 663 | else if (unformat (input, "detail") || |
| 664 | unformat (input, "det")) |
| 665 | detail = 1; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 666 | |
Neale Ranns | 05cac30 | 2019-05-28 11:09:40 +0000 | [diff] [blame] | 667 | else if (unformat (input, "hash") || |
| 668 | unformat (input, "mem") || |
| 669 | unformat (input, "memory")) |
| 670 | hash = 1; |
| 671 | |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 672 | else if (unformat (input, "%U/%d", |
| 673 | unformat_ip6_address, &matching_address, &mask_len)) |
| 674 | matching = 1; |
| 675 | |
| 676 | else if (unformat (input, "%U", unformat_ip6_address, &matching_address)) |
| 677 | matching = 1; |
| 678 | |
| 679 | else if (unformat (input, "table %d", &table_id)) |
| 680 | ; |
| 681 | else if (unformat (input, "index %d", &fib_index)) |
| 682 | ; |
| 683 | else |
| 684 | break; |
| 685 | } |
| 686 | |
Neale Ranns | 05cac30 | 2019-05-28 11:09:40 +0000 | [diff] [blame] | 687 | if (hash) |
| 688 | { |
| 689 | vlib_cli_output (vm, "IPv6 Non-Forwarding Hash Table:\n%U\n", |
| 690 | BV (format_bihash), |
Neale Ranns | 5a59b2b | 2020-10-19 14:47:20 +0000 | [diff] [blame] | 691 | &ip6_fib_table[IP6_FIB_TABLE_NON_FWDING].ip6_hash, |
Neale Ranns | 05cac30 | 2019-05-28 11:09:40 +0000 | [diff] [blame] | 692 | detail); |
| 693 | vlib_cli_output (vm, "IPv6 Forwarding Hash Table:\n%U\n", |
| 694 | BV (format_bihash), |
Neale Ranns | 5a59b2b | 2020-10-19 14:47:20 +0000 | [diff] [blame] | 695 | &ip6_fib_table[IP6_FIB_TABLE_FWDING].ip6_hash, |
Neale Ranns | 05cac30 | 2019-05-28 11:09:40 +0000 | [diff] [blame] | 696 | detail); |
| 697 | return (NULL); |
| 698 | } |
| 699 | |
Damjan Marion | b2c31b6 | 2020-12-13 21:47:40 +0100 | [diff] [blame] | 700 | pool_foreach (fib_table, im6->fibs) |
| 701 | { |
Neale Ranns | 1500254 | 2017-09-10 04:39:11 -0700 | [diff] [blame] | 702 | fib_source_t source; |
| 703 | u8 *s = NULL; |
| 704 | |
Neale Ranns | a3af337 | 2017-03-28 03:49:52 -0700 | [diff] [blame] | 705 | fib = pool_elt_at_index(im6->v6_fibs, fib_table->ft_index); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 706 | if (table_id >= 0 && table_id != (int)fib->table_id) |
| 707 | continue; |
| 708 | if (fib_index != ~0 && fib_index != (int)fib->index) |
| 709 | continue; |
Neale Ranns | 53da221 | 2018-02-24 02:11:19 -0800 | [diff] [blame] | 710 | if (fib_table->ft_flags & FIB_TABLE_FLAG_IP6_LL) |
| 711 | continue; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 712 | |
Neale Ranns | 9db6ada | 2019-11-08 12:42:31 +0000 | [diff] [blame] | 713 | 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] | 714 | format_fib_table_name, fib->index, |
| 715 | FIB_PROTOCOL_IP6, |
| 716 | fib->index, |
| 717 | format_ip_flow_hash_config, |
Neale Ranns | 9db6ada | 2019-11-08 12:42:31 +0000 | [diff] [blame] | 718 | fib_table->ft_flow_hash_config, |
| 719 | fib_table->ft_epoch, |
| 720 | format_fib_table_flags, fib_table->ft_flags); |
| 721 | |
Neale Ranns | 3bab8f9 | 2019-12-04 06:11:00 +0000 | [diff] [blame] | 722 | vec_foreach_index(source, fib_table->ft_locks) |
Neale Ranns | 1500254 | 2017-09-10 04:39:11 -0700 | [diff] [blame] | 723 | { |
| 724 | if (0 != fib_table->ft_locks[source]) |
| 725 | { |
| 726 | s = format(s, "%U:%d, ", |
| 727 | format_fib_source, source, |
| 728 | fib_table->ft_locks[source]); |
| 729 | } |
| 730 | } |
| 731 | s = format (s, "]"); |
Neale Ranns | 2297af0 | 2017-09-12 09:45:04 -0700 | [diff] [blame] | 732 | vlib_cli_output (vm, "%v", s); |
Neale Ranns | 1500254 | 2017-09-10 04:39:11 -0700 | [diff] [blame] | 733 | vec_free(s); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 734 | |
| 735 | /* Show summary? */ |
| 736 | if (! verbose) |
| 737 | { |
Neale Ranns | 5a59b2b | 2020-10-19 14:47:20 +0000 | [diff] [blame] | 738 | clib_bihash_24_8_t * h = &ip6_fib_table[IP6_FIB_TABLE_NON_FWDING].ip6_hash; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 739 | int len; |
| 740 | |
| 741 | vlib_cli_output (vm, "%=20s%=16s", "Prefix length", "Count"); |
| 742 | |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 743 | clib_memset (ca, 0, sizeof(*ca)); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 744 | ca->fib_index = fib->index; |
| 745 | |
Neale Ranns | ae80983 | 2018-11-23 09:00:27 -0800 | [diff] [blame] | 746 | clib_bihash_foreach_key_value_pair_24_8 |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 747 | (h, count_routes_in_fib_at_prefix_length, ca); |
| 748 | |
| 749 | for (len = 128; len >= 0; len--) |
| 750 | { |
| 751 | if (ca->count_by_prefix_length[len]) |
| 752 | vlib_cli_output (vm, "%=20d%=16lld", |
| 753 | len, ca->count_by_prefix_length[len]); |
| 754 | } |
| 755 | continue; |
| 756 | } |
| 757 | |
| 758 | if (!matching) |
| 759 | { |
| 760 | ip6_fib_table_show_all(fib, vm); |
| 761 | } |
| 762 | else |
| 763 | { |
Neale Ranns | 88fc83e | 2017-04-05 08:11:14 -0700 | [diff] [blame] | 764 | ip6_fib_table_show_one(fib, vm, &matching_address, mask_len, detail); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 765 | } |
Damjan Marion | b2c31b6 | 2020-12-13 21:47:40 +0100 | [diff] [blame] | 766 | } |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 767 | |
| 768 | return 0; |
| 769 | } |
| 770 | |
| 771 | /*? |
Billy McFall | 0683c9c | 2016-10-13 08:27:31 -0400 | [diff] [blame] | 772 | * This command displays the IPv6 FIB Tables (VRF Tables) and the route |
| 773 | * entries for each table. |
| 774 | * |
| 775 | * @note This command will run for a long time when the FIB tables are |
Nathan Skrzypczak | da33105 | 2021-09-29 15:28:26 +0200 | [diff] [blame] | 776 | * comprised of millions of entries. For those scenarios, consider displaying |
Billy McFall | 0683c9c | 2016-10-13 08:27:31 -0400 | [diff] [blame] | 777 | * in summary mode. |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 778 | * |
| 779 | * @cliexpar |
Billy McFall | 0683c9c | 2016-10-13 08:27:31 -0400 | [diff] [blame] | 780 | * @parblock |
| 781 | * Example of how to display all the IPv6 FIB tables: |
| 782 | * @cliexstart{show ip6 fib} |
Billy McFall | ebb9a6a | 2016-10-17 11:35:32 -0400 | [diff] [blame] | 783 | * ipv6-VRF:0, fib_index 0, flow hash: src dst sport dport proto |
| 784 | * @::/0 |
| 785 | * unicast-ip6-chain |
| 786 | * [@0]: dpo-load-balance: [index:5 buckets:1 uRPF:5 to:[0:0]] |
| 787 | * [0] [@0]: dpo-drop ip6 |
| 788 | * fe80::/10 |
| 789 | * unicast-ip6-chain |
| 790 | * [@0]: dpo-load-balance: [index:10 buckets:1 uRPF:10 to:[0:0]] |
| 791 | * [0] [@2]: dpo-receive |
| 792 | * ff02::1/128 |
| 793 | * unicast-ip6-chain |
| 794 | * [@0]: dpo-load-balance: [index:8 buckets:1 uRPF:8 to:[0:0]] |
| 795 | * [0] [@2]: dpo-receive |
| 796 | * ff02::2/128 |
| 797 | * unicast-ip6-chain |
| 798 | * [@0]: dpo-load-balance: [index:7 buckets:1 uRPF:7 to:[0:0]] |
| 799 | * [0] [@2]: dpo-receive |
| 800 | * ff02::16/128 |
| 801 | * unicast-ip6-chain |
| 802 | * [@0]: dpo-load-balance: [index:9 buckets:1 uRPF:9 to:[0:0]] |
| 803 | * [0] [@2]: dpo-receive |
| 804 | * ff02::1:ff00:0/104 |
| 805 | * unicast-ip6-chain |
| 806 | * [@0]: dpo-load-balance: [index:6 buckets:1 uRPF:6 to:[0:0]] |
| 807 | * [0] [@2]: dpo-receive |
| 808 | * ipv6-VRF:8, fib_index 1, flow hash: src dst sport dport proto |
| 809 | * @::/0 |
| 810 | * unicast-ip6-chain |
| 811 | * [@0]: dpo-load-balance: [index:21 buckets:1 uRPF:20 to:[0:0]] |
| 812 | * [0] [@0]: dpo-drop ip6 |
| 813 | * @::a:1:1:0:4/126 |
| 814 | * unicast-ip6-chain |
| 815 | * [@0]: dpo-load-balance: [index:27 buckets:1 uRPF:26 to:[0:0]] |
| 816 | * [0] [@4]: ipv6-glean: af_packet0 |
| 817 | * @::a:1:1:0:7/128 |
| 818 | * unicast-ip6-chain |
| 819 | * [@0]: dpo-load-balance: [index:28 buckets:1 uRPF:27 to:[0:0]] |
| 820 | * [0] [@2]: dpo-receive: @::a:1:1:0:7 on af_packet0 |
| 821 | * fe80::/10 |
| 822 | * unicast-ip6-chain |
| 823 | * [@0]: dpo-load-balance: [index:26 buckets:1 uRPF:25 to:[0:0]] |
| 824 | * [0] [@2]: dpo-receive |
| 825 | * fe80::fe:3eff:fe3e:9222/128 |
| 826 | * unicast-ip6-chain |
| 827 | * [@0]: dpo-load-balance: [index:29 buckets:1 uRPF:28 to:[0:0]] |
| 828 | * [0] [@2]: dpo-receive: fe80::fe:3eff:fe3e:9222 on af_packet0 |
| 829 | * ff02::1/128 |
| 830 | * unicast-ip6-chain |
| 831 | * [@0]: dpo-load-balance: [index:24 buckets:1 uRPF:23 to:[0:0]] |
| 832 | * [0] [@2]: dpo-receive |
| 833 | * ff02::2/128 |
| 834 | * unicast-ip6-chain |
| 835 | * [@0]: dpo-load-balance: [index:23 buckets:1 uRPF:22 to:[0:0]] |
| 836 | * [0] [@2]: dpo-receive |
| 837 | * ff02::16/128 |
| 838 | * unicast-ip6-chain |
| 839 | * [@0]: dpo-load-balance: [index:25 buckets:1 uRPF:24 to:[0:0]] |
| 840 | * [0] [@2]: dpo-receive |
| 841 | * ff02::1:ff00:0/104 |
| 842 | * unicast-ip6-chain |
| 843 | * [@0]: dpo-load-balance: [index:22 buckets:1 uRPF:21 to:[0:0]] |
| 844 | * [0] [@2]: dpo-receive |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 845 | * @cliexend |
Billy McFall | ebb9a6a | 2016-10-17 11:35:32 -0400 | [diff] [blame] | 846 | * |
Billy McFall | 0683c9c | 2016-10-13 08:27:31 -0400 | [diff] [blame] | 847 | * Example of how to display a summary of all IPv6 FIB tables: |
| 848 | * @cliexstart{show ip6 fib summary} |
Billy McFall | ebb9a6a | 2016-10-17 11:35:32 -0400 | [diff] [blame] | 849 | * 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] | 850 | * Prefix length Count |
| 851 | * 128 3 |
| 852 | * 104 1 |
Billy McFall | ebb9a6a | 2016-10-17 11:35:32 -0400 | [diff] [blame] | 853 | * 10 1 |
| 854 | * 0 1 |
| 855 | * 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] | 856 | * Prefix length Count |
| 857 | * 128 5 |
| 858 | * 126 1 |
| 859 | * 104 1 |
Billy McFall | ebb9a6a | 2016-10-17 11:35:32 -0400 | [diff] [blame] | 860 | * 10 1 |
| 861 | * 0 1 |
Billy McFall | 0683c9c | 2016-10-13 08:27:31 -0400 | [diff] [blame] | 862 | * @cliexend |
| 863 | * @endparblock |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 864 | ?*/ |
Billy McFall | 0683c9c | 2016-10-13 08:27:31 -0400 | [diff] [blame] | 865 | /* *INDENT-OFF* */ |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 866 | VLIB_CLI_COMMAND (ip6_show_fib_command, static) = { |
| 867 | .path = "show ip6 fib", |
Neale Ranns | 88fc83e | 2017-04-05 08:11:14 -0700 | [diff] [blame] | 868 | .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] | 869 | .function = ip6_show_fib, |
| 870 | }; |
Billy McFall | 0683c9c | 2016-10-13 08:27:31 -0400 | [diff] [blame] | 871 | /* *INDENT-ON* */ |
Neale Ranns | 5a59b2b | 2020-10-19 14:47:20 +0000 | [diff] [blame] | 872 | |
| 873 | static clib_error_t * |
| 874 | ip6_config (vlib_main_t * vm, unformat_input_t * input) |
| 875 | { |
| 876 | uword heapsize = 0; |
| 877 | u32 nbuckets = 0; |
| 878 | |
| 879 | while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) |
| 880 | { |
| 881 | if (unformat (input, "hash-buckets %d", &nbuckets)) |
| 882 | ; |
| 883 | else if (unformat (input, "heap-size %U", |
| 884 | unformat_memory_size, &heapsize)) |
| 885 | ; |
| 886 | else |
| 887 | return clib_error_return (0, "unknown input '%U'", |
| 888 | format_unformat_error, input); |
| 889 | } |
| 890 | |
| 891 | ip6_fib_table_nbuckets = nbuckets; |
| 892 | ip6_fib_table_size = heapsize; |
| 893 | |
| 894 | return 0; |
| 895 | } |
| 896 | |
| 897 | VLIB_EARLY_CONFIG_FUNCTION (ip6_config, "ip6"); |
| 898 | |
| 899 | static clib_error_t * |
| 900 | ip6_fib_init (vlib_main_t * vm) |
| 901 | { |
| 902 | if (ip6_fib_table_nbuckets == 0) |
| 903 | ip6_fib_table_nbuckets = IP6_FIB_DEFAULT_HASH_NUM_BUCKETS; |
| 904 | |
| 905 | ip6_fib_table_nbuckets = 1 << max_log2 (ip6_fib_table_nbuckets); |
| 906 | |
| 907 | if (ip6_fib_table_size == 0) |
| 908 | ip6_fib_table_size = IP6_FIB_DEFAULT_HASH_MEMORY_SIZE; |
| 909 | |
| 910 | clib_bihash_init_24_8 (&(ip6_fib_table[IP6_FIB_TABLE_FWDING].ip6_hash), |
| 911 | "ip6 FIB fwding table", |
| 912 | ip6_fib_table_nbuckets, ip6_fib_table_size); |
| 913 | clib_bihash_init_24_8 (&ip6_fib_table[IP6_FIB_TABLE_NON_FWDING].ip6_hash, |
| 914 | "ip6 FIB non-fwding table", |
| 915 | ip6_fib_table_nbuckets, ip6_fib_table_size); |
| 916 | |
| 917 | return (NULL); |
| 918 | } |
| 919 | |
| 920 | VLIB_INIT_FUNCTION (ip6_fib_init) = |
| 921 | { |
| 922 | .runs_before = VLIB_INITS("ip6_lookup_init"), |
| 923 | }; |