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/fib_table.h> |
| 17 | #include <vnet/fib/fib_entry.h> |
| 18 | #include <vnet/fib/ip4_fib.h> |
| 19 | |
| 20 | /* |
| 21 | * A table of pefixes to be added to tables and the sources for them |
| 22 | */ |
| 23 | typedef struct ip4_fib_table_special_prefix_t_ { |
| 24 | fib_prefix_t ift_prefix; |
| 25 | fib_source_t ift_source; |
| 26 | fib_entry_flag_t ift_flag; |
| 27 | } ip4_fib_table_special_prefix_t; |
| 28 | |
| 29 | static const ip4_fib_table_special_prefix_t ip4_specials[] = { |
| 30 | { |
| 31 | /* 0.0.0.0/0*/ |
| 32 | .ift_prefix = { |
| 33 | .fp_addr = { |
| 34 | .ip4.data_u32 = 0, |
| 35 | }, |
| 36 | .fp_len = 0, |
| 37 | .fp_proto = FIB_PROTOCOL_IP4, |
| 38 | }, |
| 39 | .ift_source = FIB_SOURCE_DEFAULT_ROUTE, |
| 40 | .ift_flag = FIB_ENTRY_FLAG_DROP, |
| 41 | }, |
| 42 | { |
| 43 | /* 0.0.0.0/32*/ |
| 44 | .ift_prefix = { |
| 45 | .fp_addr = { |
| 46 | .ip4.data_u32 = 0, |
| 47 | }, |
| 48 | .fp_len = 32, |
| 49 | .fp_proto = FIB_PROTOCOL_IP4, |
| 50 | }, |
| 51 | .ift_source = FIB_SOURCE_DEFAULT_ROUTE, |
| 52 | .ift_flag = FIB_ENTRY_FLAG_DROP, |
| 53 | }, |
| 54 | { |
| 55 | /* |
Neale Ranns | 86fb04d | 2016-12-01 17:03:25 +0000 | [diff] [blame] | 56 | * 240.0.0.0/4 |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 57 | * drop class E |
| 58 | */ |
| 59 | .ift_prefix = { |
| 60 | .fp_addr = { |
| 61 | .ip4.data_u32 = 0xf0000000, |
| 62 | }, |
Neale Ranns | 86fb04d | 2016-12-01 17:03:25 +0000 | [diff] [blame] | 63 | .fp_len = 4, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 64 | .fp_proto = FIB_PROTOCOL_IP4, |
| 65 | }, |
| 66 | .ift_source = FIB_SOURCE_SPECIAL, |
| 67 | .ift_flag = FIB_ENTRY_FLAG_DROP, |
| 68 | |
| 69 | }, |
| 70 | { |
| 71 | /* |
Neale Ranns | 86fb04d | 2016-12-01 17:03:25 +0000 | [diff] [blame] | 72 | * 224.0.0.0/4 |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 73 | * drop all mcast |
| 74 | */ |
| 75 | .ift_prefix = { |
| 76 | .fp_addr = { |
| 77 | .ip4.data_u32 = 0xe0000000, |
| 78 | }, |
Neale Ranns | 86fb04d | 2016-12-01 17:03:25 +0000 | [diff] [blame] | 79 | .fp_len = 4, |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 80 | .fp_proto = FIB_PROTOCOL_IP4, |
| 81 | }, |
| 82 | .ift_source = FIB_SOURCE_SPECIAL, |
| 83 | .ift_flag = FIB_ENTRY_FLAG_DROP, |
| 84 | }, |
| 85 | { |
| 86 | /* |
| 87 | * 255.255.255.255/32 |
| 88 | * drop, but we'll allow it to be usurped by the likes of DHCP |
| 89 | */ |
| 90 | .ift_prefix = { |
| 91 | .fp_addr = { |
| 92 | .ip4.data_u32 = 0xffffffff, |
| 93 | }, |
| 94 | .fp_len = 32, |
| 95 | .fp_proto = FIB_PROTOCOL_IP4, |
| 96 | }, |
| 97 | .ift_source = FIB_SOURCE_DEFAULT_ROUTE, |
| 98 | .ift_flag = FIB_ENTRY_FLAG_DROP, |
| 99 | } |
| 100 | }; |
| 101 | |
| 102 | |
| 103 | static u32 |
| 104 | ip4_create_fib_with_table_id (u32 table_id) |
| 105 | { |
| 106 | fib_table_t *fib_table; |
| 107 | |
| 108 | pool_get_aligned(ip4_main.fibs, fib_table, CLIB_CACHE_LINE_BYTES); |
| 109 | memset(fib_table, 0, sizeof(*fib_table)); |
| 110 | |
| 111 | fib_table->ft_proto = FIB_PROTOCOL_IP4; |
| 112 | fib_table->ft_index = |
| 113 | fib_table->v4.index = |
| 114 | (fib_table - ip4_main.fibs); |
| 115 | |
| 116 | hash_set (ip4_main.fib_index_by_table_id, table_id, fib_table->ft_index); |
| 117 | |
| 118 | fib_table->ft_table_id = |
| 119 | fib_table->v4.table_id = |
| 120 | table_id; |
| 121 | fib_table->ft_flow_hash_config = |
| 122 | fib_table->v4.flow_hash_config = |
| 123 | IP_FLOW_HASH_DEFAULT; |
| 124 | fib_table->v4.fwd_classify_table_index = ~0; |
| 125 | fib_table->v4.rev_classify_table_index = ~0; |
| 126 | |
| 127 | fib_table_lock(fib_table->ft_index, FIB_PROTOCOL_IP4); |
| 128 | |
| 129 | ip4_mtrie_init(&fib_table->v4.mtrie); |
| 130 | |
| 131 | /* |
| 132 | * add the special entries into the new FIB |
| 133 | */ |
| 134 | int ii; |
| 135 | |
| 136 | for (ii = 0; ii < ARRAY_LEN(ip4_specials); ii++) |
| 137 | { |
| 138 | fib_prefix_t prefix = ip4_specials[ii].ift_prefix; |
| 139 | |
| 140 | prefix.fp_addr.ip4.data_u32 = |
| 141 | clib_host_to_net_u32(prefix.fp_addr.ip4.data_u32); |
| 142 | |
| 143 | fib_table_entry_special_add(fib_table->ft_index, |
| 144 | &prefix, |
| 145 | ip4_specials[ii].ift_source, |
| 146 | ip4_specials[ii].ift_flag, |
| 147 | ADJ_INDEX_INVALID); |
| 148 | } |
| 149 | |
| 150 | return (fib_table->ft_index); |
| 151 | } |
| 152 | |
| 153 | void |
| 154 | ip4_fib_table_destroy (ip4_fib_t *fib) |
| 155 | { |
| 156 | fib_table_t *fib_table = (fib_table_t*)fib; |
| 157 | int ii; |
| 158 | |
| 159 | /* |
| 160 | * remove all the specials we added when the table was created. |
| 161 | */ |
| 162 | for (ii = 0; ii < ARRAY_LEN(ip4_specials); ii++) |
| 163 | { |
| 164 | fib_prefix_t prefix = ip4_specials[ii].ift_prefix; |
| 165 | |
| 166 | prefix.fp_addr.ip4.data_u32 = |
| 167 | clib_host_to_net_u32(prefix.fp_addr.ip4.data_u32); |
| 168 | |
| 169 | fib_table_entry_special_remove(fib_table->ft_index, |
| 170 | &prefix, |
| 171 | ip4_specials[ii].ift_source); |
| 172 | } |
| 173 | |
| 174 | /* |
| 175 | * validate no more routes. |
| 176 | */ |
| 177 | ASSERT(0 == fib_table->ft_total_route_counts); |
| 178 | FOR_EACH_FIB_SOURCE(ii) |
| 179 | { |
| 180 | ASSERT(0 == fib_table->ft_src_route_counts[ii]); |
| 181 | } |
| 182 | |
| 183 | if (~0 != fib_table->ft_table_id) |
| 184 | { |
| 185 | hash_unset (ip4_main.fib_index_by_table_id, fib_table->ft_table_id); |
| 186 | } |
| 187 | pool_put(ip4_main.fibs, fib_table); |
| 188 | } |
| 189 | |
| 190 | |
| 191 | u32 |
| 192 | ip4_fib_table_find_or_create_and_lock (u32 table_id) |
| 193 | { |
| 194 | u32 index; |
| 195 | |
| 196 | index = ip4_fib_index_from_table_id(table_id); |
| 197 | if (~0 == index) |
| 198 | return ip4_create_fib_with_table_id(table_id); |
| 199 | |
| 200 | fib_table_lock(index, FIB_PROTOCOL_IP4); |
| 201 | |
| 202 | return (index); |
| 203 | } |
| 204 | |
| 205 | u32 |
| 206 | ip4_fib_table_create_and_lock (void) |
| 207 | { |
| 208 | return (ip4_create_fib_with_table_id(~0)); |
| 209 | } |
| 210 | |
| 211 | u32 |
| 212 | ip4_fib_table_get_index_for_sw_if_index (u32 sw_if_index) |
| 213 | { |
| 214 | if (sw_if_index >= vec_len(ip4_main.fib_index_by_sw_if_index)) |
| 215 | { |
| 216 | /* |
| 217 | * This is the case for interfaces that are not yet mapped to |
| 218 | * a IP table |
| 219 | */ |
| 220 | return (~0); |
| 221 | } |
| 222 | return (ip4_main.fib_index_by_sw_if_index[sw_if_index]); |
| 223 | } |
| 224 | |
| 225 | flow_hash_config_t |
| 226 | ip4_fib_table_get_flow_hash_config (u32 fib_index) |
| 227 | { |
| 228 | return (ip4_fib_get(fib_index)->flow_hash_config); |
| 229 | } |
| 230 | |
| 231 | /* |
| 232 | * ip4_fib_table_lookup_exact_match |
| 233 | * |
| 234 | * Exact match prefix lookup |
| 235 | */ |
| 236 | fib_node_index_t |
| 237 | ip4_fib_table_lookup_exact_match (const ip4_fib_t *fib, |
| 238 | const ip4_address_t *addr, |
| 239 | u32 len) |
| 240 | { |
| 241 | uword * hash, * result; |
| 242 | u32 key; |
| 243 | |
| 244 | hash = fib->fib_entry_by_dst_address[len]; |
| 245 | key = (addr->data_u32 & ip4_main.fib_masks[len]); |
| 246 | |
| 247 | result = hash_get(hash, key); |
| 248 | |
| 249 | if (NULL != result) { |
| 250 | return (result[0]); |
| 251 | } |
| 252 | return (FIB_NODE_INDEX_INVALID); |
| 253 | } |
| 254 | |
| 255 | /* |
| 256 | * ip4_fib_table_lookup_adj |
| 257 | * |
| 258 | * Longest prefix match |
| 259 | */ |
| 260 | index_t |
| 261 | ip4_fib_table_lookup_lb (ip4_fib_t *fib, |
| 262 | const ip4_address_t *addr) |
| 263 | { |
| 264 | fib_node_index_t fei; |
| 265 | |
| 266 | fei = ip4_fib_table_lookup(fib, addr, 32); |
| 267 | |
| 268 | if (FIB_NODE_INDEX_INVALID != fei) |
| 269 | { |
| 270 | const dpo_id_t *dpo; |
| 271 | |
| 272 | dpo = fib_entry_contribute_ip_forwarding(fei); |
| 273 | |
| 274 | return (dpo->dpoi_index); |
| 275 | } |
| 276 | return (INDEX_INVALID); |
| 277 | } |
| 278 | |
| 279 | /* |
| 280 | * ip4_fib_table_lookup |
| 281 | * |
| 282 | * Longest prefix match |
| 283 | */ |
| 284 | fib_node_index_t |
| 285 | ip4_fib_table_lookup (const ip4_fib_t *fib, |
| 286 | const ip4_address_t *addr, |
| 287 | u32 len) |
| 288 | { |
| 289 | uword * hash, * result; |
| 290 | i32 mask_len; |
| 291 | u32 key; |
| 292 | |
| 293 | for (mask_len = len; mask_len >= 0; mask_len--) |
| 294 | { |
| 295 | hash = fib->fib_entry_by_dst_address[mask_len]; |
| 296 | key = (addr->data_u32 & ip4_main.fib_masks[mask_len]); |
| 297 | |
| 298 | result = hash_get (hash, key); |
| 299 | |
| 300 | if (NULL != result) { |
| 301 | return (result[0]); |
| 302 | } |
| 303 | } |
| 304 | return (FIB_NODE_INDEX_INVALID); |
| 305 | } |
| 306 | |
| 307 | void |
| 308 | ip4_fib_table_entry_insert (ip4_fib_t *fib, |
| 309 | const ip4_address_t *addr, |
| 310 | u32 len, |
| 311 | fib_node_index_t fib_entry_index) |
| 312 | { |
| 313 | uword * hash, * result; |
| 314 | u32 key; |
| 315 | |
| 316 | key = (addr->data_u32 & ip4_main.fib_masks[len]); |
| 317 | hash = fib->fib_entry_by_dst_address[len]; |
| 318 | result = hash_get (hash, key); |
| 319 | |
| 320 | if (NULL == result) { |
| 321 | /* |
| 322 | * adding a new entry |
| 323 | */ |
| 324 | if (NULL == hash) { |
| 325 | hash = hash_create (32 /* elts */, sizeof (uword)); |
| 326 | hash_set_flags (hash, HASH_FLAG_NO_AUTO_SHRINK); |
| 327 | } |
| 328 | hash = hash_set(hash, key, fib_entry_index); |
| 329 | fib->fib_entry_by_dst_address[len] = hash; |
| 330 | } |
| 331 | else |
| 332 | { |
| 333 | ASSERT(0); |
| 334 | } |
| 335 | } |
| 336 | |
| 337 | void |
| 338 | ip4_fib_table_entry_remove (ip4_fib_t *fib, |
| 339 | const ip4_address_t *addr, |
| 340 | u32 len) |
| 341 | { |
| 342 | uword * hash, * result; |
| 343 | u32 key; |
| 344 | |
| 345 | key = (addr->data_u32 & ip4_main.fib_masks[len]); |
| 346 | hash = fib->fib_entry_by_dst_address[len]; |
| 347 | result = hash_get (hash, key); |
| 348 | |
| 349 | if (NULL == result) |
| 350 | { |
| 351 | /* |
| 352 | * removing a non-existant entry. i'll allow it. |
| 353 | */ |
| 354 | } |
| 355 | else |
| 356 | { |
| 357 | hash_unset(hash, key); |
| 358 | } |
| 359 | |
| 360 | fib->fib_entry_by_dst_address[len] = hash; |
| 361 | } |
| 362 | |
| 363 | void |
| 364 | ip4_fib_table_fwding_dpo_update (ip4_fib_t *fib, |
| 365 | const ip4_address_t *addr, |
| 366 | u32 len, |
| 367 | const dpo_id_t *dpo) |
| 368 | { |
| 369 | ip4_fib_mtrie_add_del_route(fib, *addr, len, dpo->dpoi_index, 0); // ADD |
| 370 | } |
| 371 | |
| 372 | void |
| 373 | ip4_fib_table_fwding_dpo_remove (ip4_fib_t *fib, |
| 374 | const ip4_address_t *addr, |
| 375 | u32 len, |
| 376 | const dpo_id_t *dpo) |
| 377 | { |
| 378 | ip4_fib_mtrie_add_del_route(fib, *addr, len, dpo->dpoi_index, 1); // DELETE |
| 379 | } |
| 380 | |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 381 | void |
| 382 | ip4_fib_table_walk (ip4_fib_t *fib, |
| 383 | fib_table_walk_fn_t fn, |
| 384 | void *ctx) |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 385 | { |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 386 | int i; |
| 387 | |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 388 | for (i = 0; i < ARRAY_LEN (fib->fib_entry_by_dst_address); i++) |
| 389 | { |
| 390 | uword * hash = fib->fib_entry_by_dst_address[i]; |
| 391 | |
| 392 | if (NULL != hash) |
| 393 | { |
| 394 | hash_pair_t * p; |
| 395 | |
| 396 | hash_foreach_pair (p, hash, |
| 397 | ({ |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 398 | fn(p->value[0], ctx); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 399 | })); |
| 400 | } |
| 401 | } |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 402 | } |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 403 | |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 404 | /** |
| 405 | * Walk show context |
| 406 | */ |
| 407 | typedef struct ip4_fib_show_walk_ctx_t_ |
| 408 | { |
| 409 | fib_node_index_t *ifsw_indicies; |
| 410 | } ip4_fib_show_walk_ctx_t; |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 411 | |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 412 | static int |
| 413 | ip4_fib_show_walk_cb (fib_node_index_t fib_entry_index, |
| 414 | void *arg) |
| 415 | { |
| 416 | ip4_fib_show_walk_ctx_t *ctx = arg; |
| 417 | |
| 418 | vec_add1(ctx->ifsw_indicies, fib_entry_index); |
| 419 | |
| 420 | return (1); |
| 421 | } |
| 422 | |
| 423 | static void |
| 424 | ip4_fib_table_show_all (ip4_fib_t *fib, |
| 425 | vlib_main_t * vm) |
| 426 | { |
| 427 | ip4_fib_show_walk_ctx_t ctx = { |
| 428 | .ifsw_indicies = NULL, |
| 429 | }; |
| 430 | fib_node_index_t *fib_entry_index; |
| 431 | |
| 432 | ip4_fib_table_walk(fib, ip4_fib_show_walk_cb, &ctx); |
| 433 | vec_sort_with_function(ctx.ifsw_indicies, |
| 434 | fib_entry_cmp_for_sort); |
| 435 | |
| 436 | vec_foreach(fib_entry_index, ctx.ifsw_indicies) |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 437 | { |
| 438 | vlib_cli_output(vm, "%U", |
| 439 | format_fib_entry, |
| 440 | *fib_entry_index, |
| 441 | FIB_ENTRY_FORMAT_BRIEF); |
| 442 | } |
| 443 | |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 444 | vec_free(ctx.ifsw_indicies); |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 445 | } |
| 446 | |
| 447 | static void |
| 448 | ip4_fib_table_show_one (ip4_fib_t *fib, |
| 449 | vlib_main_t * vm, |
| 450 | ip4_address_t *address, |
| 451 | u32 mask_len) |
| 452 | { |
| 453 | vlib_cli_output(vm, "%U", |
| 454 | format_fib_entry, |
| 455 | ip4_fib_table_lookup(fib, address, mask_len), |
| 456 | FIB_ENTRY_FORMAT_DETAIL); |
| 457 | } |
| 458 | |
| 459 | static clib_error_t * |
| 460 | ip4_show_fib (vlib_main_t * vm, |
| 461 | unformat_input_t * input, |
| 462 | vlib_cli_command_t * cmd) |
| 463 | { |
| 464 | ip4_main_t * im4 = &ip4_main; |
| 465 | fib_table_t * fib_table; |
| 466 | int verbose, matching, mtrie; |
| 467 | ip4_address_t matching_address; |
| 468 | u32 matching_mask = 32; |
| 469 | int i, table_id = -1, fib_index = ~0; |
| 470 | |
| 471 | verbose = 1; |
| 472 | matching = 0; |
| 473 | mtrie = 0; |
| 474 | while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) |
| 475 | { |
| 476 | if (unformat (input, "brief") || unformat (input, "summary") |
| 477 | || unformat (input, "sum")) |
| 478 | verbose = 0; |
| 479 | |
| 480 | else if (unformat (input, "mtrie")) |
| 481 | mtrie = 1; |
| 482 | |
| 483 | else if (unformat (input, "%U/%d", |
| 484 | unformat_ip4_address, &matching_address, &matching_mask)) |
| 485 | matching = 1; |
| 486 | |
| 487 | else if (unformat (input, "%U", unformat_ip4_address, &matching_address)) |
| 488 | matching = 1; |
| 489 | |
| 490 | else if (unformat (input, "table %d", &table_id)) |
| 491 | ; |
| 492 | else if (unformat (input, "index %d", &fib_index)) |
| 493 | ; |
| 494 | else |
| 495 | break; |
| 496 | } |
| 497 | |
| 498 | pool_foreach (fib_table, im4->fibs, |
| 499 | ({ |
| 500 | ip4_fib_t *fib = &fib_table->v4; |
| 501 | |
| 502 | if (table_id >= 0 && table_id != (int)fib->table_id) |
| 503 | continue; |
| 504 | if (fib_index != ~0 && fib_index != (int)fib->index) |
| 505 | continue; |
| 506 | |
| 507 | vlib_cli_output (vm, "%U, fib_index %d, flow hash: %U", |
| 508 | format_fib_table_name, fib->index, FIB_PROTOCOL_IP4, |
| 509 | fib->index, |
| 510 | format_ip_flow_hash_config, fib->flow_hash_config); |
| 511 | |
| 512 | /* Show summary? */ |
| 513 | if (! verbose) |
| 514 | { |
| 515 | vlib_cli_output (vm, "%=20s%=16s", "Prefix length", "Count"); |
| 516 | for (i = 0; i < ARRAY_LEN (fib->fib_entry_by_dst_address); i++) |
| 517 | { |
| 518 | uword * hash = fib->fib_entry_by_dst_address[i]; |
| 519 | uword n_elts = hash_elts (hash); |
| 520 | if (n_elts > 0) |
| 521 | vlib_cli_output (vm, "%20d%16d", i, n_elts); |
| 522 | } |
| 523 | continue; |
| 524 | } |
| 525 | |
| 526 | if (!matching) |
| 527 | { |
| 528 | ip4_fib_table_show_all(fib, vm); |
| 529 | } |
| 530 | else |
| 531 | { |
| 532 | ip4_fib_table_show_one(fib, vm, &matching_address, matching_mask); |
| 533 | } |
| 534 | |
| 535 | if (mtrie) |
| 536 | vlib_cli_output (vm, "%U", format_ip4_fib_mtrie, &fib->mtrie); |
| 537 | })); |
| 538 | |
| 539 | return 0; |
| 540 | } |
| 541 | |
| 542 | /*? |
Billy McFall | 0683c9c | 2016-10-13 08:27:31 -0400 | [diff] [blame] | 543 | * This command displays the IPv4 FIB Tables (VRF Tables) and the route |
| 544 | * entries for each table. |
| 545 | * |
| 546 | * @note This command will run for a long time when the FIB tables are |
| 547 | * comprised of millions of entries. For those senarios, consider displaying |
| 548 | * a single table or summary mode. |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 549 | * |
| 550 | * @cliexpar |
Billy McFall | 0683c9c | 2016-10-13 08:27:31 -0400 | [diff] [blame] | 551 | * Example of how to display all the IPv4 FIB tables: |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 552 | * @cliexstart{show ip fib} |
Billy McFall | ebb9a6a | 2016-10-17 11:35:32 -0400 | [diff] [blame] | 553 | * ipv4-VRF:0, fib_index 0, flow hash: src dst sport dport proto |
| 554 | * 0.0.0.0/0 |
| 555 | * unicast-ip4-chain |
| 556 | * [@0]: dpo-load-balance: [index:0 buckets:1 uRPF:0 to:[0:0]] |
| 557 | * [0] [@0]: dpo-drop ip6 |
| 558 | * 0.0.0.0/32 |
| 559 | * unicast-ip4-chain |
| 560 | * [@0]: dpo-load-balance: [index:1 buckets:1 uRPF:1 to:[0:0]] |
| 561 | * [0] [@0]: dpo-drop ip6 |
| 562 | * 6.0.1.2/32 |
| 563 | * unicast-ip4-chain |
| 564 | * [@0]: dpo-load-balance: [index:30 buckets:1 uRPF:29 to:[0:0]] |
| 565 | * [0] [@3]: arp-ipv4: via 6.0.0.1 af_packet0 |
| 566 | * 7.0.0.1/32 |
| 567 | * unicast-ip4-chain |
| 568 | * [@0]: dpo-load-balance: [index:31 buckets:4 uRPF:30 to:[0:0]] |
| 569 | * [0] [@3]: arp-ipv4: via 6.0.0.2 af_packet0 |
| 570 | * [1] [@3]: arp-ipv4: via 6.0.0.2 af_packet0 |
| 571 | * [2] [@3]: arp-ipv4: via 6.0.0.2 af_packet0 |
| 572 | * [3] [@3]: arp-ipv4: via 6.0.0.1 af_packet0 |
| 573 | * 224.0.0.0/8 |
| 574 | * unicast-ip4-chain |
| 575 | * [@0]: dpo-load-balance: [index:3 buckets:1 uRPF:3 to:[0:0]] |
| 576 | * [0] [@0]: dpo-drop ip6 |
| 577 | * 240.0.0.0/8 |
| 578 | * unicast-ip4-chain |
| 579 | * [@0]: dpo-load-balance: [index:2 buckets:1 uRPF:2 to:[0:0]] |
| 580 | * [0] [@0]: dpo-drop ip6 |
| 581 | * 255.255.255.255/32 |
| 582 | * unicast-ip4-chain |
| 583 | * [@0]: dpo-load-balance: [index:4 buckets:1 uRPF:4 to:[0:0]] |
| 584 | * [0] [@0]: dpo-drop ip6 |
| 585 | * ipv4-VRF:7, fib_index 1, flow hash: src dst sport dport proto |
| 586 | * 0.0.0.0/0 |
| 587 | * unicast-ip4-chain |
| 588 | * [@0]: dpo-load-balance: [index:12 buckets:1 uRPF:11 to:[0:0]] |
| 589 | * [0] [@0]: dpo-drop ip6 |
| 590 | * 0.0.0.0/32 |
| 591 | * unicast-ip4-chain |
| 592 | * [@0]: dpo-load-balance: [index:13 buckets:1 uRPF:12 to:[0:0]] |
| 593 | * [0] [@0]: dpo-drop ip6 |
| 594 | * 172.16.1.0/24 |
| 595 | * unicast-ip4-chain |
| 596 | * [@0]: dpo-load-balance: [index:17 buckets:1 uRPF:16 to:[0:0]] |
| 597 | * [0] [@4]: ipv4-glean: af_packet0 |
| 598 | * 172.16.1.1/32 |
| 599 | * unicast-ip4-chain |
| 600 | * [@0]: dpo-load-balance: [index:18 buckets:1 uRPF:17 to:[1:84]] |
| 601 | * [0] [@2]: dpo-receive: 172.16.1.1 on af_packet0 |
| 602 | * 172.16.1.2/32 |
| 603 | * unicast-ip4-chain |
| 604 | * [@0]: dpo-load-balance: [index:21 buckets:1 uRPF:20 to:[0:0]] |
| 605 | * [0] [@5]: ipv4 via 172.16.1.2 af_packet0: IP4: 02:fe:9e:70:7a:2b -> 26:a5:f6:9c:3a:36 |
| 606 | * 172.16.2.0/24 |
| 607 | * unicast-ip4-chain |
| 608 | * [@0]: dpo-load-balance: [index:19 buckets:1 uRPF:18 to:[0:0]] |
| 609 | * [0] [@4]: ipv4-glean: af_packet1 |
| 610 | * 172.16.2.1/32 |
| 611 | * unicast-ip4-chain |
| 612 | * [@0]: dpo-load-balance: [index:20 buckets:1 uRPF:19 to:[0:0]] |
| 613 | * [0] [@2]: dpo-receive: 172.16.2.1 on af_packet1 |
| 614 | * 224.0.0.0/8 |
| 615 | * unicast-ip4-chain |
| 616 | * [@0]: dpo-load-balance: [index:15 buckets:1 uRPF:14 to:[0:0]] |
| 617 | * [0] [@0]: dpo-drop ip6 |
| 618 | * 240.0.0.0/8 |
| 619 | * unicast-ip4-chain |
| 620 | * [@0]: dpo-load-balance: [index:14 buckets:1 uRPF:13 to:[0:0]] |
| 621 | * [0] [@0]: dpo-drop ip6 |
| 622 | * 255.255.255.255/32 |
| 623 | * unicast-ip4-chain |
| 624 | * [@0]: dpo-load-balance: [index:16 buckets:1 uRPF:15 to:[0:0]] |
| 625 | * [0] [@0]: dpo-drop ip6 |
Billy McFall | 0683c9c | 2016-10-13 08:27:31 -0400 | [diff] [blame] | 626 | * @cliexend |
| 627 | * Example of how to display a single IPv4 FIB table: |
| 628 | * @cliexstart{show ip fib table 7} |
Billy McFall | ebb9a6a | 2016-10-17 11:35:32 -0400 | [diff] [blame] | 629 | * ipv4-VRF:7, fib_index 1, flow hash: src dst sport dport proto |
| 630 | * 0.0.0.0/0 |
| 631 | * unicast-ip4-chain |
| 632 | * [@0]: dpo-load-balance: [index:12 buckets:1 uRPF:11 to:[0:0]] |
| 633 | * [0] [@0]: dpo-drop ip6 |
| 634 | * 0.0.0.0/32 |
| 635 | * unicast-ip4-chain |
| 636 | * [@0]: dpo-load-balance: [index:13 buckets:1 uRPF:12 to:[0:0]] |
| 637 | * [0] [@0]: dpo-drop ip6 |
| 638 | * 172.16.1.0/24 |
| 639 | * unicast-ip4-chain |
| 640 | * [@0]: dpo-load-balance: [index:17 buckets:1 uRPF:16 to:[0:0]] |
| 641 | * [0] [@4]: ipv4-glean: af_packet0 |
| 642 | * 172.16.1.1/32 |
| 643 | * unicast-ip4-chain |
| 644 | * [@0]: dpo-load-balance: [index:18 buckets:1 uRPF:17 to:[1:84]] |
| 645 | * [0] [@2]: dpo-receive: 172.16.1.1 on af_packet0 |
| 646 | * 172.16.1.2/32 |
| 647 | * unicast-ip4-chain |
| 648 | * [@0]: dpo-load-balance: [index:21 buckets:1 uRPF:20 to:[0:0]] |
| 649 | * [0] [@5]: ipv4 via 172.16.1.2 af_packet0: IP4: 02:fe:9e:70:7a:2b -> 26:a5:f6:9c:3a:36 |
| 650 | * 172.16.2.0/24 |
| 651 | * unicast-ip4-chain |
| 652 | * [@0]: dpo-load-balance: [index:19 buckets:1 uRPF:18 to:[0:0]] |
| 653 | * [0] [@4]: ipv4-glean: af_packet1 |
| 654 | * 172.16.2.1/32 |
| 655 | * unicast-ip4-chain |
| 656 | * [@0]: dpo-load-balance: [index:20 buckets:1 uRPF:19 to:[0:0]] |
| 657 | * [0] [@2]: dpo-receive: 172.16.2.1 on af_packet1 |
| 658 | * 224.0.0.0/8 |
| 659 | * unicast-ip4-chain |
| 660 | * [@0]: dpo-load-balance: [index:15 buckets:1 uRPF:14 to:[0:0]] |
| 661 | * [0] [@0]: dpo-drop ip6 |
| 662 | * 240.0.0.0/8 |
| 663 | * unicast-ip4-chain |
| 664 | * [@0]: dpo-load-balance: [index:14 buckets:1 uRPF:13 to:[0:0]] |
| 665 | * [0] [@0]: dpo-drop ip6 |
| 666 | * 255.255.255.255/32 |
| 667 | * unicast-ip4-chain |
| 668 | * [@0]: dpo-load-balance: [index:16 buckets:1 uRPF:15 to:[0:0]] |
| 669 | * [0] [@0]: dpo-drop ip6 |
Billy McFall | 0683c9c | 2016-10-13 08:27:31 -0400 | [diff] [blame] | 670 | * @cliexend |
| 671 | * Example of how to display a summary of all IPv4 FIB tables: |
| 672 | * @cliexstart{show ip fib summary} |
Billy McFall | ebb9a6a | 2016-10-17 11:35:32 -0400 | [diff] [blame] | 673 | * ipv4-VRF:0, fib_index 0, flow hash: src dst sport dport proto |
Billy McFall | 0683c9c | 2016-10-13 08:27:31 -0400 | [diff] [blame] | 674 | * Prefix length Count |
Billy McFall | ebb9a6a | 2016-10-17 11:35:32 -0400 | [diff] [blame] | 675 | * 0 1 |
| 676 | * 8 2 |
| 677 | * 32 4 |
| 678 | * ipv4-VRF:7, fib_index 1, flow hash: src dst sport dport proto |
Billy McFall | 0683c9c | 2016-10-13 08:27:31 -0400 | [diff] [blame] | 679 | * Prefix length Count |
Billy McFall | ebb9a6a | 2016-10-17 11:35:32 -0400 | [diff] [blame] | 680 | * 0 1 |
| 681 | * 8 2 |
| 682 | * 24 2 |
| 683 | * 32 4 |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 684 | * @cliexend |
| 685 | ?*/ |
Billy McFall | 0683c9c | 2016-10-13 08:27:31 -0400 | [diff] [blame] | 686 | /* *INDENT-OFF* */ |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 687 | VLIB_CLI_COMMAND (ip4_show_fib_command, static) = { |
| 688 | .path = "show ip fib", |
Billy McFall | ebb9a6a | 2016-10-17 11:35:32 -0400 | [diff] [blame] | 689 | .short_help = "show ip fib [summary] [table <table-id>] [index <fib-id>] [<ip4-addr>[/<mask>]] [mtrie]", |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 690 | .function = ip4_show_fib, |
| 691 | }; |
Billy McFall | 0683c9c | 2016-10-13 08:27:31 -0400 | [diff] [blame] | 692 | /* *INDENT-ON* */ |