2 * Copyright (c) 2020 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:
7 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 #include <vnet/udp/udp.h>
17 #include <vnet/session/session_types.h>
20 format_udp_connection_id (u8 * s, va_list * args)
22 udp_connection_t *uc = va_arg (*args, udp_connection_t *);
26 s = format (s, "[%u:%u][%s] %U:%d->%U:%d", uc->c_thread_index,
27 uc->c_s_index, "U", format_ip4_address, &uc->c_lcl_ip4,
28 clib_net_to_host_u16 (uc->c_lcl_port), format_ip4_address,
29 &uc->c_rmt_ip4, clib_net_to_host_u16 (uc->c_rmt_port));
31 s = format (s, "[%u:%u][%s] %U:%d->%U:%d", uc->c_thread_index,
32 uc->c_s_index, "U", format_ip6_address, &uc->c_lcl_ip6,
33 clib_net_to_host_u16 (uc->c_lcl_port), format_ip6_address,
34 &uc->c_rmt_ip6, clib_net_to_host_u16 (uc->c_rmt_port));
38 static const char *udp_connection_flags_str[] = {
39 #define _(sym, str) str,
40 foreach_udp_connection_flag
45 format_udp_connection_flags (u8 * s, va_list * args)
47 udp_connection_t *uc = va_arg (*args, udp_connection_t *);
50 for (i = 0; i < UDP_CONN_N_FLAGS; i++)
51 if (uc->flags & (1 << i))
53 for (i = 0; i < last; i++)
55 if (uc->flags & (1 << i))
56 s = format (s, "%s, ", udp_connection_flags_str[i]);
59 s = format (s, "%s", udp_connection_flags_str[last]);
64 format_udp_vars (u8 * s, va_list * args)
66 udp_connection_t *uc = va_arg (*args, udp_connection_t *);
67 s = format (s, " index %u flags: %U", uc->c_c_index,
68 format_udp_connection_flags, uc);
70 if (!(uc->flags & UDP_CONN_F_LISTEN))
76 format_udp_connection (u8 * s, va_list * args)
78 udp_connection_t *uc = va_arg (*args, udp_connection_t *);
79 u32 verbose = va_arg (*args, u32);
82 s = format (s, "%-" SESSION_CLI_ID_LEN "U", format_udp_connection_id, uc);
85 s = format (s, "%-" SESSION_CLI_STATE_LEN "s",
86 (uc->flags & UDP_CONN_F_LISTEN) ? "LISTEN" : "OPENED", uc);
88 s = format (s, "\n%U", format_udp_vars, uc);
94 udp_config_fn (vlib_main_t * vm, unformat_input_t * input)
96 udp_main_t *um = &udp_main;
99 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
101 if (unformat (input, "mtu %u", &tmp))
102 um->default_mtu = tmp;
103 else if (unformat (input, "icmp-unreachable-disabled"))
104 um->icmp_send_unreachable_disabled = 1;
106 return clib_error_return (0, "unknown input `%U'",
107 format_unformat_error, input);
112 VLIB_CONFIG_FUNCTION (udp_config_fn, "udp");
114 static clib_error_t *
115 show_udp_punt_fn (vlib_main_t * vm, unformat_input_t * input,
116 vlib_cli_command_t * cmd_arg)
118 udp_main_t *um = vnet_get_udp_main ();
120 clib_error_t *error = NULL;
122 if (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
123 return clib_error_return (0, "unknown input `%U'", format_unformat_error,
126 udp_dst_port_info_t *port_info;
127 if (um->punt_unknown4)
129 vlib_cli_output (vm, "IPv4 UDP punt: enabled");
134 vec_foreach (port_info, um->dst_port_infos[UDP_IP4])
136 if (udp_is_valid_dst_port (port_info->dst_port, 1))
138 s = format (s, (!s) ? "%d" : ", %d", port_info->dst_port);
141 s = format (s, "%c", 0);
142 vlib_cli_output (vm, "IPV4 UDP ports punt : %s", s);
145 if (um->punt_unknown6)
147 vlib_cli_output (vm, "IPv6 UDP punt: enabled");
152 vec_foreach (port_info, um->dst_port_infos[UDP_IP6])
154 if (udp_is_valid_dst_port (port_info->dst_port, 01))
156 s = format (s, (!s) ? "%d" : ", %d", port_info->dst_port);
159 s = format (s, "%c", 0);
160 vlib_cli_output (vm, "IPV6 UDP ports punt : %s", s);
166 VLIB_CLI_COMMAND (show_tcp_punt_command, static) =
168 .path = "show udp punt",
169 .short_help = "show udp punt [ipv4|ipv6]",
170 .function = show_udp_punt_fn,
175 * fd.io coding-style-patch-verification: ON
178 * eval: (c-set-style "gnu")