diff options
author | Alexander Popovsky (apopovsk) <apopovsk@cisco.com> | 2016-11-15 15:36:23 -0800 |
---|---|---|
committer | John Lo <loj@cisco.com> | 2016-11-16 07:24:26 +0000 |
commit | 740bcdbd2b13bef4f5c9b487ed0dcbbee6a760c9 (patch) | |
tree | 88ccaafef0c9e57d046830cb591c9450f9a1185e /vnet/vnet/ip/punt.c | |
parent | 25e26dc5136137c771715145dd5b2884060ff9eb (diff) |
Add an ability to punt all unknown UDP traffic to the host
By default, VPP replies with ICMP error: port unreachable when receives
an ‘unknown’ UDP (destination port with no registered listener) packet.
An existing punt() API is extended to accept ALL (~0) as a L4 port
number and if used redirects all ‘unknown’ UDP packets to the host.
New ‘all’ option is added to the “set punt udp” CLI as well.
Change-Id: I444fc5e32ffa3f0f085bb17708bf32b883ba09df
Signed-off-by: Alexander Popovsky (apopovsk) <apopovsk@cisco.com>
Diffstat (limited to 'vnet/vnet/ip/punt.c')
-rw-r--r-- | vnet/vnet/ip/punt.c | 64 |
1 files changed, 38 insertions, 26 deletions
diff --git a/vnet/vnet/ip/punt.c b/vnet/vnet/ip/punt.c index 188d03a82cc..30d3deb6fa5 100644 --- a/vnet/vnet/ip/punt.c +++ b/vnet/vnet/ip/punt.c @@ -219,38 +219,39 @@ clib_error_t * vnet_punt_add_del (vlib_main_t * vm, u8 ipv, u8 protocol, u16 port, int is_add) { - /* For now we only support adding specific UDP port punt */ - { - if (!is_add) - return clib_error_return (0, "punt delete is not supported yet"); + /* For now we only support UDP punt */ + if (protocol != IP_PROTOCOL_UDP) + return clib_error_return (0, + "only UDP protocol (%d) is supported, got %d", + IP_PROTOCOL_UDP, protocol); - if (protocol != IP_PROTOCOL_UDP) - return clib_error_return (0, - "only UDP protocol (%d) is supported, got %d", - IP_PROTOCOL_UDP, protocol); + if (ipv != (u8) ~ 0 && ipv != 4 && ipv != 6) + return clib_error_return (0, "IP version must be 4 or 6, got %d", ipv); - if (port == (u16) ~ 0) - return clib_error_return (0, "TCP/UDP port must be specified"); - } + if (port == (u16) ~ 0) + { + if (ipv == 4 || ipv == (u8) ~ 0) + udp_punt_unknown (vm, 1, is_add); + + if (ipv == 6 || ipv == (u8) ~ 0) + udp_punt_unknown (vm, 0, is_add); - if (ipv != (u8) ~ 0) + return 0; + } + + else if (is_add) { - if (ipv == 4) + if (ipv == 4 || ipv == (u8) ~ 0) udp_register_dst_port (vm, port, udp4_punt_node.index, 1); - else if (ipv == 6) + + if (ipv == 6 || ipv == (u8) ~ 0) udp_register_dst_port (vm, port, udp6_punt_node.index, 0); - else - return clib_error_return (0, "IP version must be 4 or 6, got %d", - ipv); - } - else - { - udp_register_dst_port (vm, port, udp4_punt_node.index, 1); - udp_register_dst_port (vm, port, udp6_punt_node.index, 0); - } - return 0; + return 0; + } + else + return clib_error_return (0, "punt delete is not supported yet"); } static clib_error_t * @@ -265,6 +266,13 @@ udp_punt_cli (vlib_main_t * vm, { if (unformat (input, "del")) is_add = 0; + if (unformat (input, "all")) + { + /* punt both IPv6 and IPv4 when used in CLI */ + error = vnet_punt_add_del (vm, ~0, IP_PROTOCOL_UDP, ~0, is_add); + if (error) + clib_error_report (error); + } else if (unformat (input, "%d", &udp_port)) { /* punt both IPv6 and IPv4 when used in CLI */ @@ -284,7 +292,6 @@ udp_punt_cli (vlib_main_t * vm, * * @em Note * - UDP is the only protocol supported in the current implementation - * - When requesting UDP punt port number(s) must be specified * - All TCP traffic is currently punted to the host by default * * @cliexpar @@ -292,12 +299,17 @@ udp_punt_cli (vlib_main_t * vm, * Example of how to request NTP traffic to be punted * @cliexcmd{set punt udp 125} * + * Example of how to request all 'unknown' UDP traffic to be punted + * @cliexcmd{set punt udp all} + * + * Example of how to stop all 'unknown' UDP traffic to be punted + * @cliexcmd{set punt udp del all} * @endparblock ?*/ /* *INDENT-OFF* */ VLIB_CLI_COMMAND (punt_udp_command, static) = { .path = "set punt udp", - .short_help = "set punt udp [del] port-num1 [port-num2 ...]", + .short_help = "set punt udp [del] <all | port-num1 [port-num2 ...]>", .function = udp_punt_cli, }; /* *INDENT-ON* */ |