Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [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/mfib/ip6_mfib.h> |
| 17 | |
| 18 | #include <vnet/mfib/mfib_table.h> |
| 19 | #include <vnet/mfib/mfib_entry.h> |
| 20 | #include <vnet/fib/ip6_fib.h> |
| 21 | |
Neale Ranns | 5a59b2b | 2020-10-19 14:47:20 +0000 | [diff] [blame] | 22 | ip6_mfib_table_instance_t ip6_mfib_table; |
| 23 | |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 24 | /** |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 25 | * Key and mask for radix |
| 26 | */ |
Neale Ranns | ae80983 | 2018-11-23 09:00:27 -0800 | [diff] [blame] | 27 | typedef clib_bihash_kv_40_8_t ip6_mfib_key_t; |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 28 | |
| 29 | static const mfib_prefix_t all_zeros = { |
| 30 | /* (*,*) */ |
| 31 | .fp_src_addr = { |
| 32 | .ip6.as_u64 = {0, 0}, |
| 33 | }, |
| 34 | .fp_grp_addr = { |
| 35 | .ip6.as_u64 = {0, 0}, |
| 36 | }, |
| 37 | .fp_len = 0, |
| 38 | .fp_proto = FIB_PROTOCOL_IP6, |
| 39 | }; |
| 40 | |
| 41 | typedef enum ip6_mfib_special_type_t_ { |
| 42 | IP6_MFIB_SPECIAL_TYPE_NONE, |
| 43 | IP6_MFIB_SPECIAL_TYPE_SOLICITED, |
| 44 | } ip6_mfib_special_type_t; |
| 45 | |
| 46 | typedef struct ip6_mfib_special_t_ { |
| 47 | /** |
| 48 | * @brief solicited or not |
| 49 | */ |
| 50 | ip6_mfib_special_type_t ims_type; |
| 51 | |
| 52 | /** |
| 53 | * @brief the Prefix length |
| 54 | */ |
| 55 | u8 ims_len; |
| 56 | |
| 57 | /** |
| 58 | * @brief The last byte of the mcast address |
| 59 | */ |
| 60 | u8 ims_byte; |
| 61 | /** |
| 62 | * @brief The scope of the address |
| 63 | */ |
| 64 | u8 ims_scope; |
| 65 | } ip6_mfib_special_t; |
| 66 | |
| 67 | static const ip6_mfib_special_t ip6_mfib_specials[] = |
| 68 | { |
| 69 | { |
| 70 | /* |
| 71 | * Add ff02::1:ff00:0/104 via local route for all tables. |
| 72 | * This is required for neighbor discovery to work. |
| 73 | */ |
| 74 | .ims_type = IP6_MFIB_SPECIAL_TYPE_SOLICITED, |
| 75 | .ims_len = 104, |
| 76 | }, |
| 77 | { |
| 78 | /* |
| 79 | * all-routers multicast address |
| 80 | */ |
| 81 | .ims_type = IP6_MFIB_SPECIAL_TYPE_NONE, |
| 82 | .ims_scope = IP6_MULTICAST_SCOPE_link_local, |
| 83 | .ims_byte = IP6_MULTICAST_GROUP_ID_all_routers, |
| 84 | .ims_len = 128, |
| 85 | }, |
| 86 | { |
| 87 | /* |
| 88 | * all-nodes multicast address |
| 89 | */ |
| 90 | .ims_type = IP6_MFIB_SPECIAL_TYPE_NONE, |
| 91 | .ims_scope = IP6_MULTICAST_SCOPE_link_local, |
| 92 | .ims_byte = IP6_MULTICAST_GROUP_ID_all_hosts, |
| 93 | .ims_len = 128, |
| 94 | }, |
| 95 | { |
| 96 | /* |
| 97 | * Add all-mldv2 multicast address via local route for all tables |
| 98 | */ |
| 99 | .ims_type = IP6_MFIB_SPECIAL_TYPE_NONE, |
| 100 | .ims_len = 128, |
| 101 | .ims_scope = IP6_MULTICAST_SCOPE_link_local, |
| 102 | .ims_byte = IP6_MULTICAST_GROUP_ID_mldv2_routers, |
| 103 | } |
| 104 | }; |
| 105 | |
| 106 | #define FOR_EACH_IP6_SPECIAL(_pfx, _body) \ |
| 107 | { \ |
| 108 | const ip6_mfib_special_t *_spec; \ |
| 109 | u8 _ii; \ |
| 110 | for (_ii = 0; \ |
| 111 | _ii < ARRAY_LEN(ip6_mfib_specials); \ |
| 112 | _ii++) \ |
| 113 | { \ |
| 114 | _spec = &ip6_mfib_specials[_ii]; \ |
| 115 | if (IP6_MFIB_SPECIAL_TYPE_SOLICITED == _spec->ims_type) \ |
| 116 | { \ |
| 117 | ip6_set_solicited_node_multicast_address( \ |
| 118 | &(_pfx)->fp_grp_addr.ip6, 0); \ |
| 119 | } \ |
| 120 | else \ |
| 121 | { \ |
| 122 | ip6_set_reserved_multicast_address ( \ |
| 123 | &(_pfx)->fp_grp_addr.ip6, \ |
| 124 | _spec->ims_scope, \ |
| 125 | _spec->ims_byte); \ |
| 126 | } \ |
| 127 | (_pfx)->fp_len = _spec->ims_len; \ |
| 128 | do { _body; } while (0); \ |
| 129 | } \ |
| 130 | } |
| 131 | |
| 132 | |
| 133 | static u32 |
Neale Ranns | 1500254 | 2017-09-10 04:39:11 -0700 | [diff] [blame] | 134 | ip6_create_mfib_with_table_id (u32 table_id, |
| 135 | mfib_source_t src) |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 136 | { |
| 137 | mfib_table_t *mfib_table; |
| 138 | mfib_prefix_t pfx = { |
| 139 | .fp_proto = FIB_PROTOCOL_IP6, |
| 140 | }; |
| 141 | const fib_route_path_t path_for_us = { |
Neale Ranns | da78f95 | 2017-05-24 09:15:43 -0700 | [diff] [blame] | 142 | .frp_proto = DPO_PROTO_IP6, |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 143 | .frp_addr = zero_addr, |
| 144 | .frp_sw_if_index = 0xffffffff, |
| 145 | .frp_fib_index = ~0, |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 146 | .frp_weight = 1, |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 147 | .frp_flags = FIB_ROUTE_PATH_LOCAL, |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 148 | .frp_mitf_flags = MFIB_ITF_FLAG_FORWARD, |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 149 | }; |
| 150 | |
| 151 | pool_get_aligned(ip6_main.mfibs, mfib_table, CLIB_CACHE_LINE_BYTES); |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 152 | clib_memset(mfib_table, 0, sizeof(*mfib_table)); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 153 | |
| 154 | mfib_table->mft_proto = FIB_PROTOCOL_IP6; |
| 155 | mfib_table->mft_index = |
| 156 | mfib_table->v6.index = |
| 157 | (mfib_table - ip6_main.mfibs); |
| 158 | |
| 159 | hash_set (ip6_main.mfib_index_by_table_id, |
| 160 | table_id, |
| 161 | mfib_table->mft_index); |
| 162 | |
| 163 | mfib_table->mft_table_id = |
| 164 | mfib_table->v6.table_id = |
| 165 | table_id; |
| 166 | |
Neale Ranns | 1500254 | 2017-09-10 04:39:11 -0700 | [diff] [blame] | 167 | mfib_table_lock(mfib_table->mft_index, FIB_PROTOCOL_IP6, src); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 168 | |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 169 | /* |
| 170 | * add the special entries into the new FIB |
| 171 | */ |
| 172 | mfib_table_entry_update(mfib_table->mft_index, |
| 173 | &all_zeros, |
| 174 | MFIB_SOURCE_DEFAULT_ROUTE, |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 175 | MFIB_RPF_ID_NONE, |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 176 | MFIB_ENTRY_FLAG_DROP); |
| 177 | |
| 178 | /* |
| 179 | * Add each of the specials |
| 180 | */ |
| 181 | FOR_EACH_IP6_SPECIAL(&pfx, |
| 182 | ({ |
| 183 | mfib_table_entry_path_update(mfib_table->mft_index, |
| 184 | &pfx, |
| 185 | MFIB_SOURCE_SPECIAL, |
Paul Atkins | 8e2b1b1 | 2021-10-12 14:32:11 +0100 | [diff] [blame] | 186 | MFIB_ENTRY_FLAG_NONE, |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 187 | &path_for_us); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 188 | })); |
| 189 | |
| 190 | return (mfib_table->mft_index); |
| 191 | } |
| 192 | |
| 193 | void |
| 194 | ip6_mfib_table_destroy (ip6_mfib_t *mfib) |
| 195 | { |
| 196 | mfib_table_t *mfib_table = (mfib_table_t*)mfib; |
| 197 | fib_node_index_t mfei; |
| 198 | mfib_prefix_t pfx = { |
| 199 | .fp_proto = FIB_PROTOCOL_IP6, |
| 200 | }; |
| 201 | const fib_route_path_t path_for_us = { |
Neale Ranns | da78f95 | 2017-05-24 09:15:43 -0700 | [diff] [blame] | 202 | .frp_proto = DPO_PROTO_IP6, |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 203 | .frp_addr = zero_addr, |
| 204 | .frp_sw_if_index = 0xffffffff, |
| 205 | .frp_fib_index = ~0, |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 206 | .frp_weight = 1, |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 207 | .frp_flags = FIB_ROUTE_PATH_LOCAL, |
| 208 | }; |
| 209 | |
| 210 | /* |
| 211 | * remove all the specials we added when the table was created. |
| 212 | */ |
| 213 | FOR_EACH_IP6_SPECIAL(&pfx, |
| 214 | { |
| 215 | mfib_table_entry_path_remove(mfib_table->mft_index, |
| 216 | &pfx, |
| 217 | MFIB_SOURCE_SPECIAL, |
| 218 | &path_for_us); |
| 219 | }); |
| 220 | |
| 221 | mfei = mfib_table_lookup_exact_match(mfib_table->mft_index, &all_zeros); |
| 222 | mfib_table_entry_delete_index(mfei, MFIB_SOURCE_DEFAULT_ROUTE); |
| 223 | |
| 224 | /* |
| 225 | * validate no more routes. |
| 226 | */ |
| 227 | ASSERT(0 == mfib_table->mft_total_route_counts); |
| 228 | ASSERT(~0 != mfib_table->mft_table_id); |
| 229 | |
| 230 | hash_unset (ip6_main.mfib_index_by_table_id, mfib_table->mft_table_id); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 231 | pool_put(ip6_main.mfibs, mfib_table); |
| 232 | } |
| 233 | |
| 234 | void |
| 235 | ip6_mfib_interface_enable_disable (u32 sw_if_index, int is_enable) |
| 236 | { |
| 237 | const fib_route_path_t path = { |
Neale Ranns | da78f95 | 2017-05-24 09:15:43 -0700 | [diff] [blame] | 238 | .frp_proto = DPO_PROTO_IP6, |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 239 | .frp_addr = zero_addr, |
| 240 | .frp_sw_if_index = sw_if_index, |
| 241 | .frp_fib_index = ~0, |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 242 | .frp_weight = 1, |
| 243 | .frp_mitf_flags = MFIB_ITF_FLAG_ACCEPT, |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 244 | }; |
| 245 | mfib_prefix_t pfx = { |
| 246 | .fp_proto = FIB_PROTOCOL_IP6, |
| 247 | }; |
| 248 | u32 mfib_index; |
| 249 | |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 250 | mfib_index = ip6_mfib_table_get_index_for_sw_if_index(sw_if_index); |
| 251 | |
| 252 | if (is_enable) |
| 253 | { |
| 254 | FOR_EACH_IP6_SPECIAL(&pfx, |
| 255 | { |
| 256 | mfib_table_entry_path_update(mfib_index, |
| 257 | &pfx, |
| 258 | MFIB_SOURCE_SPECIAL, |
Paul Atkins | 8e2b1b1 | 2021-10-12 14:32:11 +0100 | [diff] [blame] | 259 | MFIB_ENTRY_FLAG_NONE, |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 260 | &path); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 261 | }); |
| 262 | } |
| 263 | else |
| 264 | { |
| 265 | FOR_EACH_IP6_SPECIAL(&pfx, |
| 266 | { |
| 267 | mfib_table_entry_path_remove(mfib_index, |
| 268 | &pfx, |
| 269 | MFIB_SOURCE_SPECIAL, |
| 270 | &path); |
| 271 | }); |
| 272 | } |
| 273 | } |
| 274 | |
| 275 | u32 |
Neale Ranns | 1500254 | 2017-09-10 04:39:11 -0700 | [diff] [blame] | 276 | ip6_mfib_table_find_or_create_and_lock (u32 table_id, |
| 277 | mfib_source_t src) |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 278 | { |
| 279 | u32 index; |
| 280 | |
| 281 | index = ip6_mfib_index_from_table_id(table_id); |
| 282 | if (~0 == index) |
Neale Ranns | 1500254 | 2017-09-10 04:39:11 -0700 | [diff] [blame] | 283 | return ip6_create_mfib_with_table_id(table_id, src); |
| 284 | mfib_table_lock(index, FIB_PROTOCOL_IP6, src); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 285 | |
| 286 | return (index); |
| 287 | } |
| 288 | |
| 289 | u32 |
| 290 | ip6_mfib_table_get_index_for_sw_if_index (u32 sw_if_index) |
| 291 | { |
| 292 | if (sw_if_index >= vec_len(ip6_main.mfib_index_by_sw_if_index)) |
| 293 | { |
| 294 | /* |
| 295 | * This is the case for interfaces that are not yet mapped to |
| 296 | * a IP table |
| 297 | */ |
| 298 | return (~0); |
| 299 | } |
| 300 | return (ip6_main.mfib_index_by_sw_if_index[sw_if_index]); |
| 301 | } |
| 302 | |
Neale Ranns | ae80983 | 2018-11-23 09:00:27 -0800 | [diff] [blame] | 303 | #define IPV6_MFIB_GRP_LEN(_len) \ |
| 304 | (_len > 128 ? 128 : _len) |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 305 | |
Neale Ranns | ae80983 | 2018-11-23 09:00:27 -0800 | [diff] [blame] | 306 | #define IP6_MFIB_MK_KEY(_mfib, _grp, _src, _len, _key) \ |
| 307 | { \ |
| 308 | _key.key[0] = (_grp->as_u64[0] & \ |
| 309 | ip6_main.fib_masks[IPV6_MFIB_GRP_LEN(_len)].as_u64[0]); \ |
| 310 | _key.key[1] = (_grp->as_u64[1] & \ |
| 311 | ip6_main.fib_masks[IPV6_MFIB_GRP_LEN(_len)].as_u64[1]); \ |
| 312 | if (_len == 256) { \ |
| 313 | _key.key[2] = _src->as_u64[0]; \ |
| 314 | _key.key[3] = _src->as_u64[1]; \ |
| 315 | } else { \ |
| 316 | _key.key[2] = 0; \ |
| 317 | _key.key[3] = 0; \ |
| 318 | } \ |
| 319 | _key.key[4] = _mfib->index; \ |
| 320 | _key.key[4] = (_key.key[4] << 32) | len; \ |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 321 | } |
| 322 | |
| 323 | /* |
| 324 | * ip6_fib_table_lookup_exact_match |
| 325 | * |
| 326 | * Exact match prefix lookup |
| 327 | */ |
| 328 | fib_node_index_t |
| 329 | ip6_mfib_table_lookup_exact_match (const ip6_mfib_t *mfib, |
| 330 | const ip6_address_t *grp, |
| 331 | const ip6_address_t *src, |
| 332 | u32 len) |
| 333 | { |
Neale Ranns | ae80983 | 2018-11-23 09:00:27 -0800 | [diff] [blame] | 334 | ip6_mfib_key_t key, value; |
| 335 | int rv; |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 336 | |
Neale Ranns | ae80983 | 2018-11-23 09:00:27 -0800 | [diff] [blame] | 337 | IP6_MFIB_MK_KEY(mfib, grp, src, len, key); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 338 | |
Neale Ranns | 5a59b2b | 2020-10-19 14:47:20 +0000 | [diff] [blame] | 339 | rv = clib_bihash_search_inline_2_40_8(&ip6_mfib_table.ip6_mhash, |
Neale Ranns | ae80983 | 2018-11-23 09:00:27 -0800 | [diff] [blame] | 340 | &key, &value); |
| 341 | if (rv == 0) |
| 342 | return value.value; |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 343 | |
Neale Ranns | ae80983 | 2018-11-23 09:00:27 -0800 | [diff] [blame] | 344 | return (FIB_NODE_INDEX_INVALID); |
| 345 | } |
| 346 | |
| 347 | /* |
| 348 | * ip6_fib_table_lookup |
| 349 | * |
| 350 | * Longest prefix match for the forwarding plane (no mask given) |
| 351 | */ |
| 352 | fib_node_index_t |
| 353 | ip6_mfib_table_fwd_lookup (const ip6_mfib_t *mfib, |
| 354 | const ip6_address_t *src, |
| 355 | const ip6_address_t *grp) |
| 356 | { |
| 357 | ip6_mfib_table_instance_t *table; |
| 358 | ip6_mfib_key_t key, value; |
| 359 | int i, n, len; |
| 360 | int rv; |
| 361 | |
Neale Ranns | 5a59b2b | 2020-10-19 14:47:20 +0000 | [diff] [blame] | 362 | table = &ip6_mfib_table; |
Neale Ranns | ae80983 | 2018-11-23 09:00:27 -0800 | [diff] [blame] | 363 | n = vec_len (table->prefix_lengths_in_search_order); |
| 364 | |
| 365 | for (i = 0; i < n; i++) |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 366 | { |
Neale Ranns | ae80983 | 2018-11-23 09:00:27 -0800 | [diff] [blame] | 367 | len = table->prefix_lengths_in_search_order[i]; |
| 368 | |
| 369 | ASSERT(len >= 0 && len <= 256); |
| 370 | IP6_MFIB_MK_KEY(mfib, grp, src, len, key); |
Neale Ranns | ae80983 | 2018-11-23 09:00:27 -0800 | [diff] [blame] | 371 | rv = clib_bihash_search_inline_2_40_8(&table->ip6_mhash, &key, &value); |
| 372 | if (rv == 0) |
| 373 | return value.value; |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 374 | } |
| 375 | |
Neale Ranns | ae80983 | 2018-11-23 09:00:27 -0800 | [diff] [blame] | 376 | return (FIB_NODE_INDEX_INVALID); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 377 | } |
| 378 | |
Neale Ranns | 9e829a8 | 2018-12-17 05:50:32 -0800 | [diff] [blame] | 379 | |
| 380 | fib_node_index_t |
| 381 | ip6_mfib_table_get_less_specific (const ip6_mfib_t *mfib, |
| 382 | const ip6_address_t *src, |
| 383 | const ip6_address_t *grp, |
| 384 | u32 len) |
| 385 | { |
| 386 | u32 mask_len; |
| 387 | |
| 388 | /* |
| 389 | * in the absence of a tree structure for the table that allows for an O(1) |
| 390 | * parent get, a cheeky way to find the cover is to LPM for the prefix with |
| 391 | * mask-1. |
| 392 | * there should always be a cover, though it may be the default route. the |
| 393 | * default route's cover is the default route. |
| 394 | */ |
| 395 | if (len == 256) |
| 396 | { |
| 397 | /* go from (S,G) to (*,G*) */ |
| 398 | mask_len = 128; |
| 399 | } |
| 400 | else if (len != 0) |
| 401 | { |
| 402 | mask_len = len - 1; |
| 403 | } |
| 404 | else |
| 405 | { |
| 406 | mask_len = len; |
| 407 | } |
| 408 | |
| 409 | return (ip6_mfib_table_lookup(mfib, src, grp, mask_len)); |
| 410 | } |
| 411 | |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 412 | /* |
| 413 | * ip6_fib_table_lookup |
| 414 | * |
| 415 | * Longest prefix match |
| 416 | */ |
| 417 | fib_node_index_t |
| 418 | ip6_mfib_table_lookup (const ip6_mfib_t *mfib, |
| 419 | const ip6_address_t *src, |
| 420 | const ip6_address_t *grp, |
| 421 | u32 len) |
| 422 | { |
Neale Ranns | ae80983 | 2018-11-23 09:00:27 -0800 | [diff] [blame] | 423 | ip6_mfib_table_instance_t *table; |
| 424 | ip6_mfib_key_t key, value; |
| 425 | int i, n, rv; |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 426 | |
Neale Ranns | 5a59b2b | 2020-10-19 14:47:20 +0000 | [diff] [blame] | 427 | table = &ip6_mfib_table; |
Neale Ranns | ae80983 | 2018-11-23 09:00:27 -0800 | [diff] [blame] | 428 | n = vec_len (table->prefix_lengths_in_search_order); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 429 | |
Neale Ranns | ae80983 | 2018-11-23 09:00:27 -0800 | [diff] [blame] | 430 | /* |
| 431 | * start search from a mask length same length or shorter. |
| 432 | * we don't want matches longer than the mask passed |
| 433 | */ |
| 434 | i = 0; |
| 435 | while (i < n && table->prefix_lengths_in_search_order[i] > len) |
| 436 | { |
| 437 | i++; |
| 438 | } |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 439 | |
Neale Ranns | ae80983 | 2018-11-23 09:00:27 -0800 | [diff] [blame] | 440 | for (; i < n; i++) |
| 441 | { |
| 442 | len = table->prefix_lengths_in_search_order[i]; |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 443 | |
Neale Ranns | b7778b6 | 2018-12-21 07:00:56 -0800 | [diff] [blame] | 444 | ASSERT(len <= 256); |
Neale Ranns | ae80983 | 2018-11-23 09:00:27 -0800 | [diff] [blame] | 445 | IP6_MFIB_MK_KEY(mfib, grp, src, len, key); |
| 446 | |
| 447 | rv = clib_bihash_search_inline_2_40_8(&table->ip6_mhash, &key, &value); |
| 448 | if (rv == 0) |
| 449 | return value.value; |
| 450 | } |
| 451 | |
| 452 | return (FIB_NODE_INDEX_INVALID); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 453 | } |
| 454 | |
Neale Ranns | ae80983 | 2018-11-23 09:00:27 -0800 | [diff] [blame] | 455 | static void |
| 456 | compute_prefix_lengths_in_search_order (ip6_mfib_table_instance_t *table) |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 457 | { |
Neale Ranns | ae80983 | 2018-11-23 09:00:27 -0800 | [diff] [blame] | 458 | int i; |
| 459 | vec_reset_length (table->prefix_lengths_in_search_order); |
| 460 | /* Note: bitmap reversed so this is in fact a longest prefix match */ |
Damjan Marion | f0ca1e8 | 2020-12-13 23:26:56 +0100 | [diff] [blame] | 461 | clib_bitmap_foreach (i, table->non_empty_dst_address_length_bitmap) |
| 462 | { |
Neale Ranns | ae80983 | 2018-11-23 09:00:27 -0800 | [diff] [blame] | 463 | vec_add1(table->prefix_lengths_in_search_order, (256 - i)); |
Damjan Marion | f0ca1e8 | 2020-12-13 23:26:56 +0100 | [diff] [blame] | 464 | } |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 465 | } |
| 466 | |
| 467 | void |
| 468 | ip6_mfib_table_entry_insert (ip6_mfib_t *mfib, |
| 469 | const ip6_address_t *grp, |
| 470 | const ip6_address_t *src, |
| 471 | u32 len, |
| 472 | fib_node_index_t mfib_entry_index) |
| 473 | { |
Neale Ranns | ae80983 | 2018-11-23 09:00:27 -0800 | [diff] [blame] | 474 | ip6_mfib_table_instance_t *table; |
| 475 | ip6_mfib_key_t key; |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 476 | |
Neale Ranns | 5a59b2b | 2020-10-19 14:47:20 +0000 | [diff] [blame] | 477 | table = &ip6_mfib_table; |
Neale Ranns | ae80983 | 2018-11-23 09:00:27 -0800 | [diff] [blame] | 478 | IP6_MFIB_MK_KEY(mfib, grp, src, len, key); |
| 479 | key.value = mfib_entry_index; |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 480 | |
Neale Ranns | ae80983 | 2018-11-23 09:00:27 -0800 | [diff] [blame] | 481 | clib_bihash_add_del_40_8(&table->ip6_mhash, &key, 1); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 482 | |
Neale Ranns | ae80983 | 2018-11-23 09:00:27 -0800 | [diff] [blame] | 483 | if (0 == table->dst_address_length_refcounts[len]++) |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 484 | { |
Neale Ranns | ae80983 | 2018-11-23 09:00:27 -0800 | [diff] [blame] | 485 | table->non_empty_dst_address_length_bitmap = |
| 486 | clib_bitmap_set (table->non_empty_dst_address_length_bitmap, |
| 487 | 256 - len, 1); |
| 488 | compute_prefix_lengths_in_search_order (table); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 489 | } |
| 490 | } |
| 491 | |
| 492 | void |
| 493 | ip6_mfib_table_entry_remove (ip6_mfib_t *mfib, |
| 494 | const ip6_address_t *grp, |
| 495 | const ip6_address_t *src, |
| 496 | u32 len) |
| 497 | { |
Neale Ranns | ae80983 | 2018-11-23 09:00:27 -0800 | [diff] [blame] | 498 | ip6_mfib_table_instance_t *table; |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 499 | ip6_mfib_key_t key; |
| 500 | |
Neale Ranns | ae80983 | 2018-11-23 09:00:27 -0800 | [diff] [blame] | 501 | IP6_MFIB_MK_KEY(mfib, grp, src, len, key); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 502 | |
Neale Ranns | 5a59b2b | 2020-10-19 14:47:20 +0000 | [diff] [blame] | 503 | table = &ip6_mfib_table; |
Neale Ranns | ae80983 | 2018-11-23 09:00:27 -0800 | [diff] [blame] | 504 | clib_bihash_add_del_40_8(&table->ip6_mhash, &key, 0); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 505 | |
Neale Ranns | ae80983 | 2018-11-23 09:00:27 -0800 | [diff] [blame] | 506 | ASSERT (table->dst_address_length_refcounts[len] > 0); |
| 507 | if (--table->dst_address_length_refcounts[len] == 0) |
| 508 | { |
| 509 | table->non_empty_dst_address_length_bitmap = |
| 510 | clib_bitmap_set (table->non_empty_dst_address_length_bitmap, |
| 511 | 256 - len, 0); |
| 512 | compute_prefix_lengths_in_search_order (table); |
| 513 | } |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 514 | } |
| 515 | |
| 516 | static clib_error_t * |
| 517 | ip6_mfib_module_init (vlib_main_t * vm) |
| 518 | { |
| 519 | return (NULL); |
| 520 | } |
| 521 | |
| 522 | VLIB_INIT_FUNCTION(ip6_mfib_module_init); |
| 523 | |
Neale Ranns | c87aafa | 2017-11-29 00:59:31 -0800 | [diff] [blame] | 524 | u8 * |
| 525 | format_ip6_mfib_table_memory (u8 * s, va_list * args) |
| 526 | { |
Neale Ranns | 05cac30 | 2019-05-28 11:09:40 +0000 | [diff] [blame] | 527 | u64 bytes_inuse; |
| 528 | |
Neale Ranns | 5a59b2b | 2020-10-19 14:47:20 +0000 | [diff] [blame] | 529 | bytes_inuse = alloc_arena_next(&(ip6_mfib_table.ip6_mhash)); |
Neale Ranns | 05cac30 | 2019-05-28 11:09:40 +0000 | [diff] [blame] | 530 | |
| 531 | s = format(s, "%=30s %=6d %=12ld\n", |
Neale Ranns | c87aafa | 2017-11-29 00:59:31 -0800 | [diff] [blame] | 532 | "IPv6 multicast", |
Neale Ranns | 05cac30 | 2019-05-28 11:09:40 +0000 | [diff] [blame] | 533 | pool_elts(ip6_main.mfibs), |
| 534 | bytes_inuse); |
Neale Ranns | c87aafa | 2017-11-29 00:59:31 -0800 | [diff] [blame] | 535 | |
| 536 | return (s); |
| 537 | } |
| 538 | |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 539 | static void |
| 540 | ip6_mfib_table_show_one (ip6_mfib_t *mfib, |
| 541 | vlib_main_t * vm, |
| 542 | ip6_address_t *src, |
| 543 | ip6_address_t *grp, |
Neale Ranns | 9e829a8 | 2018-12-17 05:50:32 -0800 | [diff] [blame] | 544 | u32 mask_len, |
| 545 | u32 cover) |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 546 | { |
Neale Ranns | 9e829a8 | 2018-12-17 05:50:32 -0800 | [diff] [blame] | 547 | if (cover) |
| 548 | { |
| 549 | vlib_cli_output(vm, "%U", |
| 550 | format_mfib_entry, |
| 551 | ip6_mfib_table_get_less_specific(mfib, src, grp, mask_len), |
| 552 | MFIB_ENTRY_FORMAT_DETAIL); |
| 553 | } |
| 554 | else |
| 555 | { |
| 556 | vlib_cli_output(vm, "%U", |
| 557 | format_mfib_entry, |
| 558 | ip6_mfib_table_lookup(mfib, src, grp, mask_len), |
| 559 | MFIB_ENTRY_FORMAT_DETAIL); |
| 560 | } |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 561 | } |
| 562 | |
| 563 | typedef struct ip6_mfib_show_ctx_t_ { |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 564 | fib_node_index_t *entries; |
| 565 | } ip6_mfib_show_ctx_t; |
| 566 | |
| 567 | |
Neale Ranns | 9db6ada | 2019-11-08 12:42:31 +0000 | [diff] [blame] | 568 | static walk_rc_t |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 569 | ip6_mfib_table_collect_entries (fib_node_index_t mfei, void *arg) |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 570 | { |
| 571 | ip6_mfib_show_ctx_t *ctx = arg; |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 572 | |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 573 | vec_add1(ctx->entries, mfei); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 574 | |
Neale Ranns | 9db6ada | 2019-11-08 12:42:31 +0000 | [diff] [blame] | 575 | return (WALK_CONTINUE); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 576 | } |
| 577 | |
| 578 | static void |
| 579 | ip6_mfib_table_show_all (ip6_mfib_t *mfib, |
| 580 | vlib_main_t * vm) |
| 581 | { |
| 582 | fib_node_index_t *mfib_entry_index; |
| 583 | ip6_mfib_show_ctx_t ctx = { |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 584 | .entries = NULL, |
| 585 | }; |
| 586 | |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 587 | ip6_mfib_table_walk(mfib, |
| 588 | ip6_mfib_table_collect_entries, |
| 589 | &ctx); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 590 | |
| 591 | vec_sort_with_function(ctx.entries, mfib_entry_cmp_for_sort); |
| 592 | |
| 593 | vec_foreach(mfib_entry_index, ctx.entries) |
| 594 | { |
| 595 | vlib_cli_output(vm, "%U", |
| 596 | format_mfib_entry, |
| 597 | *mfib_entry_index, |
| 598 | MFIB_ENTRY_FORMAT_BRIEF); |
| 599 | } |
| 600 | |
| 601 | vec_free(ctx.entries); |
| 602 | } |
| 603 | |
Neale Ranns | ae80983 | 2018-11-23 09:00:27 -0800 | [diff] [blame] | 604 | /** |
| 605 | * @brief Context when walking the IPv6 table. Since all VRFs are in the |
| 606 | * same hash table, we need to filter only those we need as we walk |
| 607 | */ |
| 608 | typedef struct ip6_mfib_walk_ctx_t_ |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 609 | { |
Neale Ranns | ae80983 | 2018-11-23 09:00:27 -0800 | [diff] [blame] | 610 | u32 i6w_mfib_index; |
| 611 | mfib_table_walk_fn_t i6w_fn; |
| 612 | void *i6w_ctx; |
| 613 | } ip6_mfib_walk_ctx_t; |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 614 | |
Neale Ranns | f50bac1 | 2019-12-06 05:53:17 +0000 | [diff] [blame] | 615 | static int |
Neale Ranns | ae80983 | 2018-11-23 09:00:27 -0800 | [diff] [blame] | 616 | ip6_mfib_walk_cb (clib_bihash_kv_40_8_t * kvp, |
| 617 | void *arg) |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 618 | { |
Neale Ranns | ae80983 | 2018-11-23 09:00:27 -0800 | [diff] [blame] | 619 | ip6_mfib_walk_ctx_t *ctx = arg; |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 620 | |
Neale Ranns | ae80983 | 2018-11-23 09:00:27 -0800 | [diff] [blame] | 621 | if ((kvp->key[4] >> 32) == ctx->i6w_mfib_index) |
| 622 | { |
Neale Ranns | 9db6ada | 2019-11-08 12:42:31 +0000 | [diff] [blame] | 623 | ctx->i6w_fn(kvp->value, ctx->i6w_ctx); |
Neale Ranns | ae80983 | 2018-11-23 09:00:27 -0800 | [diff] [blame] | 624 | } |
Neale Ranns | f50bac1 | 2019-12-06 05:53:17 +0000 | [diff] [blame] | 625 | return (BIHASH_WALK_CONTINUE); |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 626 | } |
| 627 | |
| 628 | void |
| 629 | ip6_mfib_table_walk (ip6_mfib_t *mfib, |
| 630 | mfib_table_walk_fn_t fn, |
Neale Ranns | ae80983 | 2018-11-23 09:00:27 -0800 | [diff] [blame] | 631 | void *arg) |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 632 | { |
Neale Ranns | ae80983 | 2018-11-23 09:00:27 -0800 | [diff] [blame] | 633 | ip6_mfib_walk_ctx_t ctx = { |
| 634 | .i6w_mfib_index = mfib->index, |
| 635 | .i6w_fn = fn, |
| 636 | .i6w_ctx = arg, |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 637 | }; |
| 638 | |
Neale Ranns | ae80983 | 2018-11-23 09:00:27 -0800 | [diff] [blame] | 639 | clib_bihash_foreach_key_value_pair_40_8( |
Neale Ranns | 5a59b2b | 2020-10-19 14:47:20 +0000 | [diff] [blame] | 640 | &ip6_mfib_table.ip6_mhash, |
Neale Ranns | ae80983 | 2018-11-23 09:00:27 -0800 | [diff] [blame] | 641 | ip6_mfib_walk_cb, |
| 642 | &ctx); |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 643 | } |
| 644 | |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 645 | static clib_error_t * |
| 646 | ip6_show_mfib (vlib_main_t * vm, |
| 647 | unformat_input_t * input, |
| 648 | vlib_cli_command_t * cmd) |
| 649 | { |
Neale Ranns | c87aafa | 2017-11-29 00:59:31 -0800 | [diff] [blame] | 650 | ip6_main_t * im6 = &ip6_main; |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 651 | mfib_table_t *mfib_table; |
| 652 | int verbose, matching; |
| 653 | ip6_address_t grp, src = {{0}}; |
Neale Ranns | 9e829a8 | 2018-12-17 05:50:32 -0800 | [diff] [blame] | 654 | u32 mask = 128, cover; |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 655 | int table_id = -1, fib_index = ~0; |
| 656 | |
| 657 | verbose = 1; |
| 658 | matching = 0; |
Neale Ranns | 9e829a8 | 2018-12-17 05:50:32 -0800 | [diff] [blame] | 659 | cover = 0; |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 660 | |
| 661 | while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) |
| 662 | { |
| 663 | if (unformat (input, "brief") || unformat (input, "summary") |
| 664 | || unformat (input, "sum")) |
| 665 | verbose = 0; |
| 666 | |
| 667 | else if (unformat (input, "%U %U", |
| 668 | unformat_ip6_address, &src, |
| 669 | unformat_ip6_address, &grp)) |
| 670 | { |
| 671 | matching = 1; |
Neale Ranns | c7409dc | 2017-05-19 02:54:32 -0700 | [diff] [blame] | 672 | mask = 256; |
| 673 | } |
| 674 | else if (unformat (input, "%U/%d", unformat_ip6_address, &grp, &mask)) |
| 675 | { |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 676 | clib_memset(&src, 0, sizeof(src)); |
Neale Ranns | c7409dc | 2017-05-19 02:54:32 -0700 | [diff] [blame] | 677 | matching = 1; |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 678 | } |
| 679 | else if (unformat (input, "%U", unformat_ip6_address, &grp)) |
| 680 | { |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 681 | clib_memset(&src, 0, sizeof(src)); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 682 | matching = 1; |
Neale Ranns | c7409dc | 2017-05-19 02:54:32 -0700 | [diff] [blame] | 683 | mask = 128; |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 684 | } |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 685 | else if (unformat (input, "table %d", &table_id)) |
| 686 | ; |
| 687 | else if (unformat (input, "index %d", &fib_index)) |
| 688 | ; |
Neale Ranns | 9e829a8 | 2018-12-17 05:50:32 -0800 | [diff] [blame] | 689 | else if (unformat (input, "cover")) |
| 690 | cover = 1; |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 691 | else |
| 692 | break; |
| 693 | } |
| 694 | |
Damjan Marion | b2c31b6 | 2020-12-13 21:47:40 +0100 | [diff] [blame] | 695 | pool_foreach (mfib_table, im6->mfibs) |
| 696 | { |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 697 | ip6_mfib_t *mfib = &mfib_table->v6; |
| 698 | |
| 699 | if (table_id >= 0 && table_id != (int)mfib->table_id) |
| 700 | continue; |
| 701 | if (fib_index != ~0 && fib_index != (int)mfib->index) |
| 702 | continue; |
| 703 | |
| 704 | vlib_cli_output (vm, "%U, fib_index %d", |
| 705 | format_mfib_table_name, mfib->index, FIB_PROTOCOL_IP6, |
| 706 | mfib->index); |
| 707 | |
| 708 | /* Show summary? */ |
| 709 | if (! verbose) |
| 710 | { |
| 711 | /* vlib_cli_output (vm, "%=20s%=16s", "Prefix length", "Count"); */ |
| 712 | /* for (i = 0; i < ARRAY_LEN (mfib->fib_entry_by_dst_address); i++) */ |
| 713 | /* { */ |
| 714 | /* uword * hash = mfib->fib_entry_by_dst_address[i]; */ |
| 715 | /* uword n_elts = hash_elts (hash); */ |
| 716 | /* if (n_elts > 0) */ |
| 717 | /* vlib_cli_output (vm, "%20d%16d", i, n_elts); */ |
| 718 | /* } */ |
| 719 | continue; |
| 720 | } |
| 721 | |
| 722 | if (!matching) |
| 723 | { |
| 724 | ip6_mfib_table_show_all(mfib, vm); |
| 725 | } |
| 726 | else |
| 727 | { |
Neale Ranns | 9e829a8 | 2018-12-17 05:50:32 -0800 | [diff] [blame] | 728 | ip6_mfib_table_show_one(mfib, vm, &src, &grp, mask, cover); |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 729 | } |
Damjan Marion | b2c31b6 | 2020-12-13 21:47:40 +0100 | [diff] [blame] | 730 | } |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 731 | |
| 732 | return 0; |
| 733 | } |
| 734 | |
Nathan Skrzypczak | da33105 | 2021-09-29 15:28:26 +0200 | [diff] [blame] | 735 | /* clang-format off */ |
| 736 | /*? |
Neale Ranns | c87aafa | 2017-11-29 00:59:31 -0800 | [diff] [blame] | 737 | * This command displays the IPv6 MulticasrFIB Tables (VRF Tables) and |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 738 | * the route entries for each table. |
| 739 | * |
| 740 | * @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] | 741 | * comprised of millions of entries. For those scenarios, consider displaying |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 742 | * a single table or summary mode. |
| 743 | * |
| 744 | * @cliexpar |
Neale Ranns | c87aafa | 2017-11-29 00:59:31 -0800 | [diff] [blame] | 745 | * Example of how to display all the IPv6 Multicast FIB tables: |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 746 | * @cliexstart{show ip fib} |
Neale Ranns | c87aafa | 2017-11-29 00:59:31 -0800 | [diff] [blame] | 747 | * ipv6-VRF:0, fib_index 0 |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 748 | * (*, 0.0.0.0/0): flags:D, |
| 749 | * Interfaces: |
| 750 | * multicast-ip6-chain |
| 751 | * [@1]: dpo-drop ip6 |
| 752 | * (*, 232.1.1.1/32): |
| 753 | * Interfaces: |
| 754 | * test-eth1: Forward, |
| 755 | * test-eth2: Forward, |
| 756 | * test-eth0: Accept, |
| 757 | * multicast-ip6-chain |
| 758 | * [@2]: dpo-replicate: [index:1 buckets:2 to:[0:0]] |
Neale Ranns | c87aafa | 2017-11-29 00:59:31 -0800 | [diff] [blame] | 759 | * [0] [@1]: ipv6-mcast: test-eth1: IP6: d0:d1:d2:d3:d4:01 -> 01:00:05:00:00:00 |
| 760 | * [1] [@1]: ipv6-mcast: test-eth2: IP6: d0:d1:d2:d3:d4:02 -> 01:00:05:00:00:00 |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 761 | * |
| 762 | * @cliexend |
Neale Ranns | c87aafa | 2017-11-29 00:59:31 -0800 | [diff] [blame] | 763 | * Example of how to display a summary of all IPv6 FIB tables: |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 764 | * @cliexstart{show ip fib summary} |
Neale Ranns | c87aafa | 2017-11-29 00:59:31 -0800 | [diff] [blame] | 765 | * ipv6-VRF:0, fib_index 0, flow hash: src dst sport dport proto |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 766 | * Prefix length Count |
| 767 | * 0 1 |
| 768 | * 8 2 |
| 769 | * 32 4 |
Neale Ranns | c87aafa | 2017-11-29 00:59:31 -0800 | [diff] [blame] | 770 | * ipv6-VRF:7, fib_index 1, flow hash: src dst sport dport proto |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 771 | * Prefix length Count |
| 772 | * 0 1 |
| 773 | * 8 2 |
| 774 | * 24 2 |
| 775 | * 32 4 |
| 776 | * @cliexend |
Nathan Skrzypczak | da33105 | 2021-09-29 15:28:26 +0200 | [diff] [blame] | 777 | ?*/ |
| 778 | /* clang-format on */ |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 779 | VLIB_CLI_COMMAND (ip6_show_fib_command, static) = { |
| 780 | .path = "show ip6 mfib", |
| 781 | .short_help = "show ip mfib [summary] [table <table-id>] [index <fib-id>] [<grp-addr>[/<mask>]] [<grp-addr>] [<src-addr> <grp-addr>]", |
| 782 | .function = ip6_show_mfib, |
| 783 | }; |
Neale Ranns | 5a59b2b | 2020-10-19 14:47:20 +0000 | [diff] [blame] | 784 | |
| 785 | static clib_error_t * |
| 786 | ip6_mfib_init (vlib_main_t * vm) |
| 787 | { |
| 788 | clib_bihash_init_40_8 (&ip6_mfib_table.ip6_mhash, |
| 789 | "ip6 mFIB table", |
| 790 | IP6_MFIB_DEFAULT_HASH_NUM_BUCKETS, |
| 791 | IP6_MFIB_DEFAULT_HASH_MEMORY_SIZE); |
| 792 | |
| 793 | return (NULL); |
| 794 | } |
| 795 | |
| 796 | VLIB_INIT_FUNCTION (ip6_mfib_init) = |
| 797 | { |
| 798 | .runs_before = VLIB_INITS("ip6_lookup_init"), |
| 799 | }; |