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 | |
Benoît Ganne | 23c4896 | 2024-04-05 09:45:29 +0200 | [diff] [blame] | 23 | ip6_fib_fwding_table_instance_t ip6_fib_fwding_table; |
Neale Ranns | 5a59b2b | 2020-10-19 14:47:20 +0000 | [diff] [blame] | 24 | |
| 25 | /* ip6 lookup table config parameters */ |
| 26 | u32 ip6_fib_table_nbuckets; |
| 27 | uword ip6_fib_table_size; |
| 28 | |
Benoît Ganne | 23c4896 | 2024-04-05 09:45:29 +0200 | [diff] [blame] | 29 | typedef struct ip6_fib_hash_key_t_ |
| 30 | { |
| 31 | ip6_address_t addr; |
| 32 | u8 len; |
| 33 | } ip6_fib_hash_key_t; |
| 34 | |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 35 | static void |
Benoît Ganne | 23c4896 | 2024-04-05 09:45:29 +0200 | [diff] [blame] | 36 | ip6_fib_hash_load_specials (u32 fib_index) |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 37 | { |
| 38 | fib_prefix_t pfx = { |
| 39 | .fp_proto = FIB_PROTOCOL_IP6, |
| 40 | .fp_len = 0, |
| 41 | .fp_addr = { |
| 42 | .ip6 = { |
| 43 | { 0, 0, }, |
| 44 | }, |
| 45 | } |
| 46 | }; |
| 47 | |
| 48 | /* |
| 49 | * Add the default route. |
| 50 | */ |
| 51 | fib_table_entry_special_add(fib_index, |
| 52 | &pfx, |
| 53 | FIB_SOURCE_DEFAULT_ROUTE, |
Neale Ranns | a055830 | 2017-04-13 00:44:52 -0700 | [diff] [blame] | 54 | FIB_ENTRY_FLAG_DROP); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 55 | |
| 56 | /* |
Neale Ranns | 53da221 | 2018-02-24 02:11:19 -0800 | [diff] [blame] | 57 | * all link local via the link local lookup DPO |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 58 | */ |
| 59 | pfx.fp_addr.ip6.as_u64[0] = clib_host_to_net_u64 (0xFE80000000000000ULL); |
| 60 | pfx.fp_addr.ip6.as_u64[1] = 0; |
| 61 | pfx.fp_len = 10; |
Neale Ranns | 53da221 | 2018-02-24 02:11:19 -0800 | [diff] [blame] | 62 | fib_table_entry_special_dpo_add(fib_index, |
| 63 | &pfx, |
| 64 | FIB_SOURCE_SPECIAL, |
| 65 | FIB_ENTRY_FLAG_NONE, |
| 66 | ip6_ll_dpo_get()); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | static u32 |
Neale Ranns | 1500254 | 2017-09-10 04:39:11 -0700 | [diff] [blame] | 70 | create_fib_with_table_id (u32 table_id, |
Neale Ranns | 53da221 | 2018-02-24 02:11:19 -0800 | [diff] [blame] | 71 | fib_source_t src, |
| 72 | fib_table_flags_t flags, |
| 73 | u8 *desc) |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 74 | { |
| 75 | fib_table_t *fib_table; |
Neale Ranns | a3af337 | 2017-03-28 03:49:52 -0700 | [diff] [blame] | 76 | ip6_fib_t *v6_fib; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 77 | |
Dave Barach | eb987d3 | 2018-05-03 08:26:39 -0400 | [diff] [blame] | 78 | pool_get(ip6_main.fibs, fib_table); |
Neale Ranns | a3af337 | 2017-03-28 03:49:52 -0700 | [diff] [blame] | 79 | 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] | 80 | |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 81 | clib_memset(fib_table, 0, sizeof(*fib_table)); |
| 82 | clib_memset(v6_fib, 0, sizeof(*v6_fib)); |
Neale Ranns | a3af337 | 2017-03-28 03:49:52 -0700 | [diff] [blame] | 83 | |
| 84 | ASSERT((fib_table - ip6_main.fibs) == |
| 85 | (v6_fib - ip6_main.v6_fibs)); |
Benoît Ganne | 23c4896 | 2024-04-05 09:45:29 +0200 | [diff] [blame] | 86 | |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 87 | fib_table->ft_proto = FIB_PROTOCOL_IP6; |
| 88 | fib_table->ft_index = |
Neale Ranns | a3af337 | 2017-03-28 03:49:52 -0700 | [diff] [blame] | 89 | v6_fib->index = |
| 90 | (fib_table - ip6_main.fibs); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 91 | |
| 92 | hash_set(ip6_main.fib_index_by_table_id, table_id, fib_table->ft_index); |
| 93 | |
| 94 | fib_table->ft_table_id = |
Neale Ranns | a3af337 | 2017-03-28 03:49:52 -0700 | [diff] [blame] | 95 | v6_fib->table_id = |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 96 | table_id; |
Neale Ranns | 227038a | 2017-04-21 01:07:59 -0700 | [diff] [blame] | 97 | fib_table->ft_flow_hash_config = IP_FLOW_HASH_DEFAULT; |
Neale Ranns | 53da221 | 2018-02-24 02:11:19 -0800 | [diff] [blame] | 98 | fib_table->ft_flags = flags; |
| 99 | fib_table->ft_desc = desc; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 100 | |
Neale Ranns | 1500254 | 2017-09-10 04:39:11 -0700 | [diff] [blame] | 101 | fib_table_lock(fib_table->ft_index, FIB_PROTOCOL_IP6, src); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 102 | |
Benoît Ganne | 23c4896 | 2024-04-05 09:45:29 +0200 | [diff] [blame] | 103 | v6_fib->fib_entry_by_dst_address = hash_create_mem(2, sizeof(ip6_fib_hash_key_t), sizeof(fib_node_index_t)); |
| 104 | |
| 105 | /* |
| 106 | * add the special entries into the new FIB |
| 107 | */ |
| 108 | ip6_fib_hash_load_specials (fib_table->ft_index); |
| 109 | |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 110 | return (fib_table->ft_index); |
| 111 | } |
| 112 | |
| 113 | u32 |
Neale Ranns | 1500254 | 2017-09-10 04:39:11 -0700 | [diff] [blame] | 114 | ip6_fib_table_find_or_create_and_lock (u32 table_id, |
| 115 | fib_source_t src) |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 116 | { |
| 117 | uword * p; |
| 118 | |
| 119 | p = hash_get (ip6_main.fib_index_by_table_id, table_id); |
| 120 | if (NULL == p) |
Neale Ranns | 53da221 | 2018-02-24 02:11:19 -0800 | [diff] [blame] | 121 | return create_fib_with_table_id(table_id, src, |
| 122 | FIB_TABLE_FLAG_NONE, |
| 123 | NULL); |
| 124 | |
Neale Ranns | 1500254 | 2017-09-10 04:39:11 -0700 | [diff] [blame] | 125 | fib_table_lock(p[0], FIB_PROTOCOL_IP6, src); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 126 | |
| 127 | return (p[0]); |
| 128 | } |
| 129 | |
| 130 | u32 |
Neale Ranns | 53da221 | 2018-02-24 02:11:19 -0800 | [diff] [blame] | 131 | ip6_fib_table_create_and_lock (fib_source_t src, |
| 132 | fib_table_flags_t flags, |
| 133 | u8 *desc) |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 134 | { |
Neale Ranns | 53da221 | 2018-02-24 02:11:19 -0800 | [diff] [blame] | 135 | return (create_fib_with_table_id(~0, src, flags, desc)); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 136 | } |
| 137 | |
| 138 | void |
| 139 | ip6_fib_table_destroy (u32 fib_index) |
| 140 | { |
Neale Ranns | 53da221 | 2018-02-24 02:11:19 -0800 | [diff] [blame] | 141 | /* |
| 142 | * all link local first ... |
| 143 | */ |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 144 | fib_prefix_t pfx = { |
| 145 | .fp_proto = FIB_PROTOCOL_IP6, |
Neale Ranns | 53da221 | 2018-02-24 02:11:19 -0800 | [diff] [blame] | 146 | .fp_len = 10, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 147 | .fp_addr = { |
| 148 | .ip6 = { |
Neale Ranns | 53da221 | 2018-02-24 02:11:19 -0800 | [diff] [blame] | 149 | .as_u8 = { |
| 150 | [0] = 0xFE, |
| 151 | [1] = 0x80, |
| 152 | }, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 153 | }, |
| 154 | } |
| 155 | }; |
Neale Ranns | 53da221 | 2018-02-24 02:11:19 -0800 | [diff] [blame] | 156 | fib_table_entry_delete(fib_index, |
| 157 | &pfx, |
| 158 | FIB_SOURCE_SPECIAL); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 159 | |
| 160 | /* |
Neale Ranns | 53da221 | 2018-02-24 02:11:19 -0800 | [diff] [blame] | 161 | * ... then the default route. |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 162 | */ |
Neale Ranns | 53da221 | 2018-02-24 02:11:19 -0800 | [diff] [blame] | 163 | pfx.fp_addr.ip6.as_u64[0] = 0; |
| 164 | pfx.fp_len = 00; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 165 | fib_table_entry_special_remove(fib_index, |
| 166 | &pfx, |
| 167 | FIB_SOURCE_DEFAULT_ROUTE); |
| 168 | |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 169 | fib_table_t *fib_table = fib_table_get(fib_index, FIB_PROTOCOL_IP6); |
| 170 | fib_source_t source; |
Neale Ranns | 53da221 | 2018-02-24 02:11:19 -0800 | [diff] [blame] | 171 | |
Neale Ranns | 3bab8f9 | 2019-12-04 06:11:00 +0000 | [diff] [blame] | 172 | /* |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 173 | * validate no more routes. |
| 174 | */ |
Benoît Ganne | caaa633 | 2023-09-13 17:21:04 +0200 | [diff] [blame] | 175 | fib_table_assert_empty(fib_table); |
Neale Ranns | cbe25aa | 2019-09-30 10:53:31 +0000 | [diff] [blame] | 176 | |
Neale Ranns | 3bab8f9 | 2019-12-04 06:11:00 +0000 | [diff] [blame] | 177 | vec_foreach_index(source, fib_table->ft_src_route_counts) |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 178 | { |
| 179 | ASSERT(0 == fib_table->ft_src_route_counts[source]); |
| 180 | } |
| 181 | |
| 182 | if (~0 != fib_table->ft_table_id) |
| 183 | { |
| 184 | hash_unset (ip6_main.fib_index_by_table_id, fib_table->ft_table_id); |
| 185 | } |
Steven Luong | 97866a3 | 2022-02-08 07:59:11 -0800 | [diff] [blame] | 186 | vec_free (fib_table->ft_locks); |
Neale Ranns | 3bab8f9 | 2019-12-04 06:11:00 +0000 | [diff] [blame] | 187 | vec_free(fib_table->ft_src_route_counts); |
Benoît Ganne | 23c4896 | 2024-04-05 09:45:29 +0200 | [diff] [blame] | 188 | hash_free(pool_elt_at_index(ip6_main.v6_fibs, fib_index)->fib_entry_by_dst_address); |
Neale Ranns | a3af337 | 2017-03-28 03:49:52 -0700 | [diff] [blame] | 189 | pool_put_index(ip6_main.v6_fibs, fib_table->ft_index); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 190 | pool_put(ip6_main.fibs, fib_table); |
| 191 | } |
| 192 | |
Benoît Ganne | 23c4896 | 2024-04-05 09:45:29 +0200 | [diff] [blame] | 193 | static void |
| 194 | ip6_fib_table_mk_key (ip6_fib_hash_key_t *key, const ip6_address_t *addr, u8 len) |
| 195 | { |
| 196 | const ip6_address_t *mask = &ip6_main.fib_masks[len]; |
| 197 | key->addr.as_u64[0] = addr->as_u64[0] & mask->as_u64[0]; |
| 198 | key->addr.as_u64[1] = addr->as_u64[1] & mask->as_u64[1]; |
| 199 | key->len = len; |
| 200 | } |
| 201 | |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 202 | fib_node_index_t |
| 203 | ip6_fib_table_lookup (u32 fib_index, |
| 204 | const ip6_address_t *addr, |
| 205 | u32 len) |
| 206 | { |
Benoît Ganne | 23c4896 | 2024-04-05 09:45:29 +0200 | [diff] [blame] | 207 | uword *hash = pool_elt_at_index(ip6_main.v6_fibs, fib_index)->fib_entry_by_dst_address; |
| 208 | ip6_fib_hash_key_t key; |
| 209 | i32 mask_len; |
| 210 | uword *result; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 211 | |
Benoît Ganne | 23c4896 | 2024-04-05 09:45:29 +0200 | [diff] [blame] | 212 | for (mask_len = len; mask_len >= 0; mask_len--) |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 213 | { |
Benoît Ganne | 23c4896 | 2024-04-05 09:45:29 +0200 | [diff] [blame] | 214 | ip6_fib_table_mk_key (&key, addr, mask_len); |
| 215 | result = hash_get_mem(hash, &key); |
| 216 | if (result) { |
| 217 | return result[0]; |
| 218 | } |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 219 | } |
| 220 | |
Benoît Ganne | 23c4896 | 2024-04-05 09:45:29 +0200 | [diff] [blame] | 221 | return FIB_NODE_INDEX_INVALID; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 222 | } |
| 223 | |
| 224 | fib_node_index_t |
| 225 | ip6_fib_table_lookup_exact_match (u32 fib_index, |
| 226 | const ip6_address_t *addr, |
| 227 | u32 len) |
| 228 | { |
Benoît Ganne | 23c4896 | 2024-04-05 09:45:29 +0200 | [diff] [blame] | 229 | uword *hash = pool_elt_at_index(ip6_main.v6_fibs, fib_index)->fib_entry_by_dst_address; |
| 230 | ip6_fib_hash_key_t key; |
| 231 | ip6_fib_table_mk_key (&key, addr, len); |
| 232 | uword *result = hash_get(hash, &key); |
| 233 | return result ? result[0] : FIB_NODE_INDEX_INVALID; |
| 234 | } |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 235 | |
Benoît Ganne | 23c4896 | 2024-04-05 09:45:29 +0200 | [diff] [blame] | 236 | void |
| 237 | ip6_fib_table_entry_remove (u32 fib_index, |
| 238 | const ip6_address_t *addr, |
| 239 | u32 len) |
| 240 | { |
| 241 | uword **hash = &pool_elt_at_index(ip6_main.v6_fibs, fib_index)->fib_entry_by_dst_address; |
| 242 | ip6_fib_hash_key_t key; |
| 243 | ip6_fib_table_mk_key (&key, addr, len); |
| 244 | hash_unset_mem_free(hash, &key); |
| 245 | } |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 246 | |
Benoît Ganne | 23c4896 | 2024-04-05 09:45:29 +0200 | [diff] [blame] | 247 | void |
| 248 | ip6_fib_table_entry_insert (u32 fib_index, |
| 249 | const ip6_address_t *addr, |
| 250 | u32 len, |
| 251 | fib_node_index_t fib_entry_index) |
| 252 | { |
| 253 | uword **hash = &pool_elt_at_index(ip6_main.v6_fibs, fib_index)->fib_entry_by_dst_address; |
| 254 | ip6_fib_hash_key_t key; |
| 255 | ip6_fib_table_mk_key (&key, addr, len); |
| 256 | ASSERT (0 == hash_get(*hash, &key) && "entry already exists"); |
| 257 | hash_set_mem_alloc(hash, &key, fib_entry_index); |
| 258 | } |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 259 | |
Benoît Ganne | 23c4896 | 2024-04-05 09:45:29 +0200 | [diff] [blame] | 260 | u32 ip6_fib_table_fwding_lookup_with_if_index (ip6_main_t * im, |
| 261 | u32 sw_if_index, |
| 262 | const ip6_address_t * dst) |
| 263 | { |
| 264 | u32 fib_index = vec_elt (im->fib_index_by_sw_if_index, sw_if_index); |
| 265 | return ip6_fib_table_fwding_lookup(fib_index, dst); |
| 266 | } |
| 267 | |
| 268 | u32 |
| 269 | ip6_fib_table_get_index_for_sw_if_index (u32 sw_if_index) |
| 270 | { |
| 271 | if (sw_if_index >= vec_len(ip6_main.fib_index_by_sw_if_index)) |
| 272 | { |
| 273 | /* |
| 274 | * This is the case for interfaces that are not yet mapped to |
| 275 | * a IP table |
| 276 | */ |
| 277 | return (~0); |
| 278 | } |
| 279 | return (ip6_main.fib_index_by_sw_if_index[sw_if_index]); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 280 | } |
| 281 | |
| 282 | static void |
Benoît Ganne | 23c4896 | 2024-04-05 09:45:29 +0200 | [diff] [blame] | 283 | compute_prefix_lengths_in_search_order (ip6_fib_fwding_table_instance_t *table) |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 284 | { |
Neale Ranns | 42845dd | 2020-05-26 13:12:17 +0000 | [diff] [blame] | 285 | u8 *old, *prefix_lengths_in_search_order = NULL; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 286 | int i; |
Neale Ranns | 42845dd | 2020-05-26 13:12:17 +0000 | [diff] [blame] | 287 | |
| 288 | /* |
| 289 | * build the list in a scratch space then cutover so the workers |
| 290 | * can continue uninterrupted. |
| 291 | */ |
| 292 | old = table->prefix_lengths_in_search_order; |
| 293 | |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 294 | /* Note: bitmap reversed so this is in fact a longest prefix match */ |
Damjan Marion | f0ca1e8 | 2020-12-13 23:26:56 +0100 | [diff] [blame] | 295 | clib_bitmap_foreach (i, table->non_empty_dst_address_length_bitmap) |
| 296 | { |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 297 | int dst_address_length = 128 - i; |
Neale Ranns | 42845dd | 2020-05-26 13:12:17 +0000 | [diff] [blame] | 298 | vec_add1(prefix_lengths_in_search_order, dst_address_length); |
Damjan Marion | f0ca1e8 | 2020-12-13 23:26:56 +0100 | [diff] [blame] | 299 | } |
Neale Ranns | 42845dd | 2020-05-26 13:12:17 +0000 | [diff] [blame] | 300 | |
| 301 | table->prefix_lengths_in_search_order = prefix_lengths_in_search_order; |
| 302 | |
| 303 | /* |
| 304 | * let the workers go once round the track before we free the old set |
| 305 | */ |
| 306 | vlib_worker_wait_one_loop(); |
| 307 | vec_free(old); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 308 | } |
| 309 | |
| 310 | void |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 311 | ip6_fib_table_fwding_dpo_update (u32 fib_index, |
| 312 | const ip6_address_t *addr, |
| 313 | u32 len, |
| 314 | const dpo_id_t *dpo) |
| 315 | { |
Benoît Ganne | 23c4896 | 2024-04-05 09:45:29 +0200 | [diff] [blame] | 316 | ip6_fib_fwding_table_instance_t *table; |
Neale Ranns | ae80983 | 2018-11-23 09:00:27 -0800 | [diff] [blame] | 317 | clib_bihash_kv_24_8_t kv; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 318 | ip6_address_t *mask; |
| 319 | u64 fib; |
| 320 | |
Benoît Ganne | 23c4896 | 2024-04-05 09:45:29 +0200 | [diff] [blame] | 321 | table = &ip6_fib_fwding_table; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 322 | mask = &ip6_main.fib_masks[len]; |
| 323 | fib = ((u64)((fib_index))<<32); |
| 324 | |
| 325 | kv.key[0] = addr->as_u64[0] & mask->as_u64[0]; |
| 326 | kv.key[1] = addr->as_u64[1] & mask->as_u64[1]; |
| 327 | kv.key[2] = fib | len; |
| 328 | kv.value = dpo->dpoi_index; |
| 329 | |
Neale Ranns | ae80983 | 2018-11-23 09:00:27 -0800 | [diff] [blame] | 330 | clib_bihash_add_del_24_8(&table->ip6_hash, &kv, 1); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 331 | |
Neale Ranns | 42845dd | 2020-05-26 13:12:17 +0000 | [diff] [blame] | 332 | if (0 == table->dst_address_length_refcounts[len]++) |
| 333 | { |
| 334 | table->non_empty_dst_address_length_bitmap = |
| 335 | clib_bitmap_set (table->non_empty_dst_address_length_bitmap, |
| 336 | 128 - len, 1); |
| 337 | compute_prefix_lengths_in_search_order (table); |
| 338 | } |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 339 | } |
| 340 | |
| 341 | void |
| 342 | ip6_fib_table_fwding_dpo_remove (u32 fib_index, |
| 343 | const ip6_address_t *addr, |
| 344 | u32 len, |
| 345 | const dpo_id_t *dpo) |
| 346 | { |
Benoît Ganne | 23c4896 | 2024-04-05 09:45:29 +0200 | [diff] [blame] | 347 | ip6_fib_fwding_table_instance_t *table; |
Neale Ranns | ae80983 | 2018-11-23 09:00:27 -0800 | [diff] [blame] | 348 | clib_bihash_kv_24_8_t kv; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 349 | ip6_address_t *mask; |
| 350 | u64 fib; |
| 351 | |
Benoît Ganne | 23c4896 | 2024-04-05 09:45:29 +0200 | [diff] [blame] | 352 | table = &ip6_fib_fwding_table; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 353 | mask = &ip6_main.fib_masks[len]; |
| 354 | fib = ((u64)((fib_index))<<32); |
| 355 | |
| 356 | kv.key[0] = addr->as_u64[0] & mask->as_u64[0]; |
| 357 | kv.key[1] = addr->as_u64[1] & mask->as_u64[1]; |
| 358 | kv.key[2] = fib | len; |
| 359 | kv.value = dpo->dpoi_index; |
| 360 | |
Neale Ranns | ae80983 | 2018-11-23 09:00:27 -0800 | [diff] [blame] | 361 | clib_bihash_add_del_24_8(&table->ip6_hash, &kv, 0); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 362 | |
| 363 | /* refcount accounting */ |
| 364 | ASSERT (table->dst_address_length_refcounts[len] > 0); |
| 365 | if (--table->dst_address_length_refcounts[len] == 0) |
| 366 | { |
| 367 | table->non_empty_dst_address_length_bitmap = |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 368 | clib_bitmap_set (table->non_empty_dst_address_length_bitmap, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 369 | 128 - len, 0); |
| 370 | compute_prefix_lengths_in_search_order (table); |
| 371 | } |
| 372 | } |
| 373 | |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 374 | void |
| 375 | ip6_fib_table_walk (u32 fib_index, |
| 376 | fib_table_walk_fn_t fn, |
| 377 | void *arg) |
| 378 | { |
Benoît Ganne | 23c4896 | 2024-04-05 09:45:29 +0200 | [diff] [blame] | 379 | const fib_prefix_t root = { |
| 380 | .fp_proto = FIB_PROTOCOL_IP6, |
| 381 | // address and length default to all 0 |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 382 | }; |
Benoît Ganne | 23c4896 | 2024-04-05 09:45:29 +0200 | [diff] [blame] | 383 | /* A full tree walk is the dengenerate case of a sub-tree from |
| 384 | * the very root */ |
| 385 | return (ip6_fib_table_sub_tree_walk(fib_index, &root, fn, arg)); |
Neale Ranns | 8954199 | 2017-04-06 04:41:02 -0700 | [diff] [blame] | 386 | } |
| 387 | |
| 388 | void |
| 389 | ip6_fib_table_sub_tree_walk (u32 fib_index, |
| 390 | const fib_prefix_t *root, |
| 391 | fib_table_walk_fn_t fn, |
| 392 | void *arg) |
| 393 | { |
Benoît Ganne | 23c4896 | 2024-04-05 09:45:29 +0200 | [diff] [blame] | 394 | uword *hash = pool_elt_at_index(ip6_main.v6_fibs, fib_index)->fib_entry_by_dst_address; |
| 395 | const ip6_fib_hash_key_t *key, *sub_tree; |
| 396 | ip6_fib_hash_key_t *sub_trees = 0; |
| 397 | u32 fei; |
Neale Ranns | 8954199 | 2017-04-06 04:41:02 -0700 | [diff] [blame] | 398 | |
Benoît Ganne | 23c4896 | 2024-04-05 09:45:29 +0200 | [diff] [blame] | 399 | /* |
| 400 | * There is no efficient way to walk this hash table. |
| 401 | * so we walk over all entries and check it is covered by the root. |
| 402 | */ |
| 403 | hash_foreach_mem(key, fei, hash, ({ |
| 404 | /* check if the prefix is covered by the root */ |
| 405 | if (!ip6_destination_matches_route(&ip6_main, &key->addr, &root->fp_addr.ip6, root->fp_len)) |
| 406 | continue; /* not covered by root, ignore */ |
| 407 | |
| 408 | /* exclude sub-trees the walk does not want to explore */ |
| 409 | vec_foreach (sub_tree, sub_trees) |
| 410 | { |
| 411 | if (ip6_destination_matches_route(&ip6_main, &key->addr, &sub_tree->addr, sub_tree->len)) |
| 412 | goto ignore_sub_tree; |
| 413 | } |
| 414 | |
| 415 | switch (fn(fei, arg)) |
| 416 | { |
| 417 | case FIB_TABLE_WALK_STOP: |
| 418 | goto done; |
| 419 | case FIB_TABLE_WALK_CONTINUE: |
| 420 | break; |
| 421 | case FIB_TABLE_WALK_SUB_TREE_STOP: |
| 422 | vec_add1(sub_trees, *key); |
| 423 | break; |
| 424 | } |
| 425 | |
| 426 | ignore_sub_tree:; |
| 427 | })); |
| 428 | |
| 429 | done: |
| 430 | vec_free(sub_trees); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 431 | } |
| 432 | |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 433 | typedef struct ip6_fib_show_ctx_t_ { |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 434 | fib_node_index_t *entries; |
| 435 | } ip6_fib_show_ctx_t; |
| 436 | |
Neale Ranns | 8954199 | 2017-04-06 04:41:02 -0700 | [diff] [blame] | 437 | static fib_table_walk_rc_t |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 438 | ip6_fib_table_show_walk (fib_node_index_t fib_entry_index, |
| 439 | void *arg) |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 440 | { |
| 441 | ip6_fib_show_ctx_t *ctx = arg; |
| 442 | |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 443 | vec_add1(ctx->entries, fib_entry_index); |
| 444 | |
Neale Ranns | 8954199 | 2017-04-06 04:41:02 -0700 | [diff] [blame] | 445 | return (FIB_TABLE_WALK_CONTINUE); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 446 | } |
| 447 | |
| 448 | static void |
| 449 | ip6_fib_table_show_all (ip6_fib_t *fib, |
| 450 | vlib_main_t * vm) |
| 451 | { |
| 452 | fib_node_index_t *fib_entry_index; |
| 453 | ip6_fib_show_ctx_t ctx = { |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 454 | .entries = NULL, |
| 455 | }; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 456 | |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 457 | ip6_fib_table_walk(fib->index, ip6_fib_table_show_walk, &ctx); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 458 | vec_sort_with_function(ctx.entries, fib_entry_cmp_for_sort); |
| 459 | |
| 460 | vec_foreach(fib_entry_index, ctx.entries) |
| 461 | { |
| 462 | vlib_cli_output(vm, "%U", |
| 463 | format_fib_entry, |
| 464 | *fib_entry_index, |
| 465 | FIB_ENTRY_FORMAT_BRIEF); |
| 466 | } |
| 467 | |
| 468 | vec_free(ctx.entries); |
| 469 | } |
| 470 | |
| 471 | static void |
| 472 | ip6_fib_table_show_one (ip6_fib_t *fib, |
| 473 | vlib_main_t * vm, |
| 474 | ip6_address_t *address, |
Neale Ranns | 88fc83e | 2017-04-05 08:11:14 -0700 | [diff] [blame] | 475 | u32 mask_len, |
| 476 | int detail) |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 477 | { |
| 478 | vlib_cli_output(vm, "%U", |
| 479 | format_fib_entry, |
| 480 | ip6_fib_table_lookup(fib->index, address, mask_len), |
Neale Ranns | 88fc83e | 2017-04-05 08:11:14 -0700 | [diff] [blame] | 481 | (detail ? |
| 482 | FIB_ENTRY_FORMAT_DETAIL2: |
| 483 | FIB_ENTRY_FORMAT_DETAIL)); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 484 | } |
| 485 | |
Neale Ranns | c87aafa | 2017-11-29 00:59:31 -0800 | [diff] [blame] | 486 | u8 * |
| 487 | format_ip6_fib_table_memory (u8 * s, va_list * args) |
| 488 | { |
Dave Barach | 97f5af0 | 2018-02-22 09:48:45 -0500 | [diff] [blame] | 489 | uword bytes_inuse; |
| 490 | |
Benoît Ganne | 23c4896 | 2024-04-05 09:45:29 +0200 | [diff] [blame] | 491 | bytes_inuse = alloc_arena_next(&ip6_fib_fwding_table.ip6_hash); |
Dave Barach | 97f5af0 | 2018-02-22 09:48:45 -0500 | [diff] [blame] | 492 | |
Neale Ranns | 05cac30 | 2019-05-28 11:09:40 +0000 | [diff] [blame] | 493 | s = format(s, "%=30s %=6d %=12ld\n", |
Neale Ranns | c87aafa | 2017-11-29 00:59:31 -0800 | [diff] [blame] | 494 | "IPv6 unicast", |
| 495 | pool_elts(ip6_main.fibs), |
Dave Barach | 97f5af0 | 2018-02-22 09:48:45 -0500 | [diff] [blame] | 496 | bytes_inuse); |
Neale Ranns | c87aafa | 2017-11-29 00:59:31 -0800 | [diff] [blame] | 497 | return (s); |
| 498 | } |
| 499 | |
Benoît Ganne | 23c4896 | 2024-04-05 09:45:29 +0200 | [diff] [blame] | 500 | void |
| 501 | ip6_fib_table_show (vlib_main_t *vm, fib_table_t *fib_table, int summary) |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 502 | { |
Benoît Ganne | 23c4896 | 2024-04-05 09:45:29 +0200 | [diff] [blame] | 503 | ip6_main_t * im6 = &ip6_main; |
| 504 | ip6_fib_t *fib = pool_elt_at_index(im6->v6_fibs, fib_table->ft_index); |
| 505 | fib_source_t source; |
| 506 | u8 *s = NULL; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 507 | |
Benoît Ganne | 23c4896 | 2024-04-05 09:45:29 +0200 | [diff] [blame] | 508 | s = format(s, "%U, fib_index:%d, flow hash:[%U] epoch:%d flags:%U locks:[", |
| 509 | format_fib_table_name, fib->index, |
| 510 | FIB_PROTOCOL_IP6, |
| 511 | fib->index, |
| 512 | format_ip_flow_hash_config, |
| 513 | fib_table->ft_flow_hash_config, |
| 514 | fib_table->ft_epoch, |
| 515 | format_fib_table_flags, fib_table->ft_flags); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 516 | |
Benoît Ganne | 23c4896 | 2024-04-05 09:45:29 +0200 | [diff] [blame] | 517 | vec_foreach_index(source, fib_table->ft_locks) |
| 518 | { |
| 519 | if (0 != fib_table->ft_locks[source]) |
| 520 | { |
| 521 | s = format(s, "%U:%d, ", |
| 522 | format_fib_source, source, |
| 523 | fib_table->ft_locks[source]); |
| 524 | } |
| 525 | } |
| 526 | s = format (s, "]"); |
| 527 | vlib_cli_output (vm, "%v", s); |
| 528 | vec_free(s); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 529 | |
Benoît Ganne | 23c4896 | 2024-04-05 09:45:29 +0200 | [diff] [blame] | 530 | /* Show summary? */ |
| 531 | if (summary) |
| 532 | { |
| 533 | u32 count_by_prefix_length[129]; |
| 534 | const ip6_fib_hash_key_t *key; |
| 535 | u32 fei; |
| 536 | int len; |
Neale Ranns | f50bac1 | 2019-12-06 05:53:17 +0000 | [diff] [blame] | 537 | |
Benoît Ganne | 23c4896 | 2024-04-05 09:45:29 +0200 | [diff] [blame] | 538 | vlib_cli_output (vm, "%=20s%=16s", "Prefix length", "Count"); |
| 539 | |
| 540 | clib_memset (count_by_prefix_length, 0, sizeof(count_by_prefix_length)); |
| 541 | |
| 542 | hash_foreach_mem(key, fei, fib->fib_entry_by_dst_address, ({ |
| 543 | ASSERT(key->len <= 128); |
| 544 | count_by_prefix_length[key->len]++; |
| 545 | })); |
| 546 | |
| 547 | for (len = 128; len >= 0; len--) |
| 548 | { |
| 549 | if (count_by_prefix_length[len]) |
| 550 | vlib_cli_output (vm, "%=20d%=16lld", |
| 551 | len, count_by_prefix_length[len]); |
| 552 | } |
| 553 | } |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 554 | } |
| 555 | |
| 556 | static clib_error_t * |
| 557 | ip6_show_fib (vlib_main_t * vm, |
| 558 | unformat_input_t * input, |
| 559 | vlib_cli_command_t * cmd) |
| 560 | { |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 561 | ip6_main_t * im6 = &ip6_main; |
| 562 | fib_table_t *fib_table; |
| 563 | ip6_fib_t * fib; |
| 564 | int verbose, matching; |
| 565 | ip6_address_t matching_address; |
| 566 | u32 mask_len = 128; |
| 567 | int table_id = -1, fib_index = ~0; |
Neale Ranns | 88fc83e | 2017-04-05 08:11:14 -0700 | [diff] [blame] | 568 | int detail = 0; |
Neale Ranns | 05cac30 | 2019-05-28 11:09:40 +0000 | [diff] [blame] | 569 | int hash = 0; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 570 | |
| 571 | verbose = 1; |
| 572 | matching = 0; |
| 573 | |
| 574 | while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) |
| 575 | { |
| 576 | if (unformat (input, "brief") || |
| 577 | unformat (input, "summary") || |
| 578 | unformat (input, "sum")) |
| 579 | verbose = 0; |
Neale Ranns | 88fc83e | 2017-04-05 08:11:14 -0700 | [diff] [blame] | 580 | |
| 581 | else if (unformat (input, "detail") || |
| 582 | unformat (input, "det")) |
| 583 | detail = 1; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 584 | |
Neale Ranns | 05cac30 | 2019-05-28 11:09:40 +0000 | [diff] [blame] | 585 | else if (unformat (input, "hash") || |
| 586 | unformat (input, "mem") || |
| 587 | unformat (input, "memory")) |
| 588 | hash = 1; |
| 589 | |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 590 | else if (unformat (input, "%U/%d", |
| 591 | unformat_ip6_address, &matching_address, &mask_len)) |
| 592 | matching = 1; |
| 593 | |
| 594 | else if (unformat (input, "%U", unformat_ip6_address, &matching_address)) |
| 595 | matching = 1; |
| 596 | |
| 597 | else if (unformat (input, "table %d", &table_id)) |
| 598 | ; |
| 599 | else if (unformat (input, "index %d", &fib_index)) |
| 600 | ; |
| 601 | else |
| 602 | break; |
| 603 | } |
| 604 | |
Neale Ranns | 05cac30 | 2019-05-28 11:09:40 +0000 | [diff] [blame] | 605 | if (hash) |
| 606 | { |
Neale Ranns | 05cac30 | 2019-05-28 11:09:40 +0000 | [diff] [blame] | 607 | vlib_cli_output (vm, "IPv6 Forwarding Hash Table:\n%U\n", |
| 608 | BV (format_bihash), |
Benoît Ganne | 23c4896 | 2024-04-05 09:45:29 +0200 | [diff] [blame] | 609 | &ip6_fib_fwding_table.ip6_hash, |
Neale Ranns | 05cac30 | 2019-05-28 11:09:40 +0000 | [diff] [blame] | 610 | detail); |
| 611 | return (NULL); |
| 612 | } |
| 613 | |
Damjan Marion | b2c31b6 | 2020-12-13 21:47:40 +0100 | [diff] [blame] | 614 | pool_foreach (fib_table, im6->fibs) |
| 615 | { |
Neale Ranns | a3af337 | 2017-03-28 03:49:52 -0700 | [diff] [blame] | 616 | fib = pool_elt_at_index(im6->v6_fibs, fib_table->ft_index); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 617 | if (table_id >= 0 && table_id != (int)fib->table_id) |
| 618 | continue; |
| 619 | if (fib_index != ~0 && fib_index != (int)fib->index) |
| 620 | continue; |
Neale Ranns | 53da221 | 2018-02-24 02:11:19 -0800 | [diff] [blame] | 621 | if (fib_table->ft_flags & FIB_TABLE_FLAG_IP6_LL) |
| 622 | continue; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 623 | |
Benoît Ganne | 23c4896 | 2024-04-05 09:45:29 +0200 | [diff] [blame] | 624 | ip6_fib_table_show(vm, fib_table, !verbose); |
| 625 | if (!verbose) |
| 626 | continue; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 627 | |
| 628 | if (!matching) |
| 629 | { |
| 630 | ip6_fib_table_show_all(fib, vm); |
| 631 | } |
| 632 | else |
| 633 | { |
Neale Ranns | 88fc83e | 2017-04-05 08:11:14 -0700 | [diff] [blame] | 634 | ip6_fib_table_show_one(fib, vm, &matching_address, mask_len, detail); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 635 | } |
Damjan Marion | b2c31b6 | 2020-12-13 21:47:40 +0100 | [diff] [blame] | 636 | } |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 637 | |
| 638 | return 0; |
| 639 | } |
| 640 | |
| 641 | /*? |
Billy McFall | 0683c9c | 2016-10-13 08:27:31 -0400 | [diff] [blame] | 642 | * This command displays the IPv6 FIB Tables (VRF Tables) and the route |
| 643 | * entries for each table. |
| 644 | * |
| 645 | * @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] | 646 | * comprised of millions of entries. For those scenarios, consider displaying |
Billy McFall | 0683c9c | 2016-10-13 08:27:31 -0400 | [diff] [blame] | 647 | * in summary mode. |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 648 | * |
| 649 | * @cliexpar |
Billy McFall | 0683c9c | 2016-10-13 08:27:31 -0400 | [diff] [blame] | 650 | * @parblock |
| 651 | * Example of how to display all the IPv6 FIB tables: |
| 652 | * @cliexstart{show ip6 fib} |
Billy McFall | ebb9a6a | 2016-10-17 11:35:32 -0400 | [diff] [blame] | 653 | * ipv6-VRF:0, fib_index 0, flow hash: src dst sport dport proto |
| 654 | * @::/0 |
| 655 | * unicast-ip6-chain |
| 656 | * [@0]: dpo-load-balance: [index:5 buckets:1 uRPF:5 to:[0:0]] |
| 657 | * [0] [@0]: dpo-drop ip6 |
| 658 | * fe80::/10 |
| 659 | * unicast-ip6-chain |
| 660 | * [@0]: dpo-load-balance: [index:10 buckets:1 uRPF:10 to:[0:0]] |
| 661 | * [0] [@2]: dpo-receive |
| 662 | * ff02::1/128 |
| 663 | * unicast-ip6-chain |
| 664 | * [@0]: dpo-load-balance: [index:8 buckets:1 uRPF:8 to:[0:0]] |
| 665 | * [0] [@2]: dpo-receive |
| 666 | * ff02::2/128 |
| 667 | * unicast-ip6-chain |
| 668 | * [@0]: dpo-load-balance: [index:7 buckets:1 uRPF:7 to:[0:0]] |
| 669 | * [0] [@2]: dpo-receive |
| 670 | * ff02::16/128 |
| 671 | * unicast-ip6-chain |
| 672 | * [@0]: dpo-load-balance: [index:9 buckets:1 uRPF:9 to:[0:0]] |
| 673 | * [0] [@2]: dpo-receive |
| 674 | * ff02::1:ff00:0/104 |
| 675 | * unicast-ip6-chain |
| 676 | * [@0]: dpo-load-balance: [index:6 buckets:1 uRPF:6 to:[0:0]] |
| 677 | * [0] [@2]: dpo-receive |
| 678 | * ipv6-VRF:8, fib_index 1, flow hash: src dst sport dport proto |
| 679 | * @::/0 |
| 680 | * unicast-ip6-chain |
| 681 | * [@0]: dpo-load-balance: [index:21 buckets:1 uRPF:20 to:[0:0]] |
| 682 | * [0] [@0]: dpo-drop ip6 |
| 683 | * @::a:1:1:0:4/126 |
| 684 | * unicast-ip6-chain |
| 685 | * [@0]: dpo-load-balance: [index:27 buckets:1 uRPF:26 to:[0:0]] |
| 686 | * [0] [@4]: ipv6-glean: af_packet0 |
| 687 | * @::a:1:1:0:7/128 |
| 688 | * unicast-ip6-chain |
| 689 | * [@0]: dpo-load-balance: [index:28 buckets:1 uRPF:27 to:[0:0]] |
| 690 | * [0] [@2]: dpo-receive: @::a:1:1:0:7 on af_packet0 |
| 691 | * fe80::/10 |
| 692 | * unicast-ip6-chain |
| 693 | * [@0]: dpo-load-balance: [index:26 buckets:1 uRPF:25 to:[0:0]] |
| 694 | * [0] [@2]: dpo-receive |
| 695 | * fe80::fe:3eff:fe3e:9222/128 |
| 696 | * unicast-ip6-chain |
| 697 | * [@0]: dpo-load-balance: [index:29 buckets:1 uRPF:28 to:[0:0]] |
| 698 | * [0] [@2]: dpo-receive: fe80::fe:3eff:fe3e:9222 on af_packet0 |
| 699 | * ff02::1/128 |
| 700 | * unicast-ip6-chain |
| 701 | * [@0]: dpo-load-balance: [index:24 buckets:1 uRPF:23 to:[0:0]] |
| 702 | * [0] [@2]: dpo-receive |
| 703 | * ff02::2/128 |
| 704 | * unicast-ip6-chain |
| 705 | * [@0]: dpo-load-balance: [index:23 buckets:1 uRPF:22 to:[0:0]] |
| 706 | * [0] [@2]: dpo-receive |
| 707 | * ff02::16/128 |
| 708 | * unicast-ip6-chain |
| 709 | * [@0]: dpo-load-balance: [index:25 buckets:1 uRPF:24 to:[0:0]] |
| 710 | * [0] [@2]: dpo-receive |
| 711 | * ff02::1:ff00:0/104 |
| 712 | * unicast-ip6-chain |
| 713 | * [@0]: dpo-load-balance: [index:22 buckets:1 uRPF:21 to:[0:0]] |
| 714 | * [0] [@2]: dpo-receive |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 715 | * @cliexend |
Billy McFall | ebb9a6a | 2016-10-17 11:35:32 -0400 | [diff] [blame] | 716 | * |
Billy McFall | 0683c9c | 2016-10-13 08:27:31 -0400 | [diff] [blame] | 717 | * Example of how to display a summary of all IPv6 FIB tables: |
| 718 | * @cliexstart{show ip6 fib summary} |
Billy McFall | ebb9a6a | 2016-10-17 11:35:32 -0400 | [diff] [blame] | 719 | * 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] | 720 | * Prefix length Count |
| 721 | * 128 3 |
| 722 | * 104 1 |
Billy McFall | ebb9a6a | 2016-10-17 11:35:32 -0400 | [diff] [blame] | 723 | * 10 1 |
| 724 | * 0 1 |
| 725 | * 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] | 726 | * Prefix length Count |
| 727 | * 128 5 |
| 728 | * 126 1 |
| 729 | * 104 1 |
Billy McFall | ebb9a6a | 2016-10-17 11:35:32 -0400 | [diff] [blame] | 730 | * 10 1 |
| 731 | * 0 1 |
Billy McFall | 0683c9c | 2016-10-13 08:27:31 -0400 | [diff] [blame] | 732 | * @cliexend |
| 733 | * @endparblock |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 734 | ?*/ |
| 735 | VLIB_CLI_COMMAND (ip6_show_fib_command, static) = { |
| 736 | .path = "show ip6 fib", |
Neale Ranns | 88fc83e | 2017-04-05 08:11:14 -0700 | [diff] [blame] | 737 | .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] | 738 | .function = ip6_show_fib, |
| 739 | }; |
Neale Ranns | 5a59b2b | 2020-10-19 14:47:20 +0000 | [diff] [blame] | 740 | |
| 741 | static clib_error_t * |
| 742 | ip6_config (vlib_main_t * vm, unformat_input_t * input) |
| 743 | { |
| 744 | uword heapsize = 0; |
| 745 | u32 nbuckets = 0; |
Jon Loeliger | d465fd0 | 2024-03-22 12:22:36 -0500 | [diff] [blame] | 746 | char *default_name = 0; |
Neale Ranns | 5a59b2b | 2020-10-19 14:47:20 +0000 | [diff] [blame] | 747 | |
| 748 | while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) |
| 749 | { |
| 750 | if (unformat (input, "hash-buckets %d", &nbuckets)) |
| 751 | ; |
| 752 | else if (unformat (input, "heap-size %U", |
| 753 | unformat_memory_size, &heapsize)) |
| 754 | ; |
Jon Loeliger | d465fd0 | 2024-03-22 12:22:36 -0500 | [diff] [blame] | 755 | else if (unformat (input, "default-table-name %s", &default_name)) |
| 756 | ; |
Neale Ranns | 5a59b2b | 2020-10-19 14:47:20 +0000 | [diff] [blame] | 757 | else |
| 758 | return clib_error_return (0, "unknown input '%U'", |
| 759 | format_unformat_error, input); |
| 760 | } |
| 761 | |
| 762 | ip6_fib_table_nbuckets = nbuckets; |
| 763 | ip6_fib_table_size = heapsize; |
Jon Loeliger | d465fd0 | 2024-03-22 12:22:36 -0500 | [diff] [blame] | 764 | fib_table_default_names[FIB_PROTOCOL_IP6] = default_name; |
Neale Ranns | 5a59b2b | 2020-10-19 14:47:20 +0000 | [diff] [blame] | 765 | |
| 766 | return 0; |
| 767 | } |
| 768 | |
| 769 | VLIB_EARLY_CONFIG_FUNCTION (ip6_config, "ip6"); |
| 770 | |
| 771 | static clib_error_t * |
| 772 | ip6_fib_init (vlib_main_t * vm) |
| 773 | { |
| 774 | if (ip6_fib_table_nbuckets == 0) |
| 775 | ip6_fib_table_nbuckets = IP6_FIB_DEFAULT_HASH_NUM_BUCKETS; |
| 776 | |
| 777 | ip6_fib_table_nbuckets = 1 << max_log2 (ip6_fib_table_nbuckets); |
| 778 | |
| 779 | if (ip6_fib_table_size == 0) |
| 780 | ip6_fib_table_size = IP6_FIB_DEFAULT_HASH_MEMORY_SIZE; |
| 781 | |
Benoît Ganne | 23c4896 | 2024-04-05 09:45:29 +0200 | [diff] [blame] | 782 | clib_bihash_init_24_8 (&(ip6_fib_fwding_table.ip6_hash), |
Neale Ranns | 5a59b2b | 2020-10-19 14:47:20 +0000 | [diff] [blame] | 783 | "ip6 FIB fwding table", |
| 784 | ip6_fib_table_nbuckets, ip6_fib_table_size); |
Neale Ranns | 5a59b2b | 2020-10-19 14:47:20 +0000 | [diff] [blame] | 785 | |
| 786 | return (NULL); |
| 787 | } |
| 788 | |
| 789 | VLIB_INIT_FUNCTION (ip6_fib_init) = |
| 790 | { |
| 791 | .runs_before = VLIB_INITS("ip6_lookup_init"), |
| 792 | }; |