diff options
Diffstat (limited to 'src/vnet/ip')
-rw-r--r-- | src/vnet/ip/lookup.c | 27 | ||||
-rw-r--r-- | src/vnet/ip/lookup.h | 1 |
2 files changed, 28 insertions, 0 deletions
diff --git a/src/vnet/ip/lookup.c b/src/vnet/ip/lookup.c index 5ac2a9c17e2..80a35fefdfc 100644 --- a/src/vnet/ip/lookup.c +++ b/src/vnet/ip/lookup.c @@ -220,6 +220,27 @@ const ip46_address_t zero_addr = { 0, 0}, }; +bool +fib_prefix_validate (const fib_prefix_t *prefix) +{ + if (FIB_PROTOCOL_IP4 == prefix->fp_proto) + { + if (prefix->fp_len > 32) + { + return false; + } + } + + if (FIB_PROTOCOL_IP6 == prefix->fp_proto) + { + if (prefix->fp_len > 128) + { + return false; + } + } + return true; +} + static clib_error_t * vnet_ip_route_cmd (vlib_main_t * vm, unformat_input_t * main_input, vlib_cli_command_t * cmd) @@ -353,6 +374,12 @@ vnet_ip_route_cmd (vlib_main_t * vm, .fp_addr = prefixs[i].fp_addr, }; + if (!fib_prefix_validate (&rpfx)) + { + vlib_cli_output (vm, "Invalid prefix len: %d", rpfx.fp_len); + continue; + } + if (is_del) fib_table_entry_path_remove2 (fib_index, &rpfx, FIB_SOURCE_CLI, rpaths); diff --git a/src/vnet/ip/lookup.h b/src/vnet/ip/lookup.h index aa998273213..4489df1aed8 100644 --- a/src/vnet/ip/lookup.h +++ b/src/vnet/ip/lookup.h @@ -179,6 +179,7 @@ ip_lookup_set_buffer_fib_index (u32 * fib_index_by_sw_if_index, } void ip_lookup_init (ip_lookup_main_t * lm, u32 ip_lookup_node_index); +bool fib_prefix_validate (const fib_prefix_t *prefix); #endif /* included_ip_lookup_h */ /* |