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>
19 format_udp_connection_id (u8 * s, va_list * args)
21 udp_connection_t *uc = va_arg (*args, udp_connection_t *);
25 s = format (s, "[%u:%u][%s] %U:%d->%U:%d", uc->c_thread_index,
26 uc->c_s_index, "U", format_ip4_address, &uc->c_lcl_ip4,
27 clib_net_to_host_u16 (uc->c_lcl_port), format_ip4_address,
28 &uc->c_rmt_ip4, clib_net_to_host_u16 (uc->c_rmt_port));
30 s = format (s, "[%u:%u][%s] %U:%d->%U:%d", uc->c_thread_index,
31 uc->c_s_index, "U", format_ip6_address, &uc->c_lcl_ip6,
32 clib_net_to_host_u16 (uc->c_lcl_port), format_ip6_address,
33 &uc->c_rmt_ip6, clib_net_to_host_u16 (uc->c_rmt_port));
37 static const char *udp_connection_flags_str[] = {
38 #define _(sym, str) str,
39 foreach_udp_connection_flag
44 format_udp_connection_flags (u8 * s, va_list * args)
46 udp_connection_t *uc = va_arg (*args, udp_connection_t *);
49 for (i = 0; i < UDP_CONN_N_FLAGS; i++)
50 if (uc->flags & (1 << i))
52 for (i = 0; i < last; i++)
54 if (uc->flags & (1 << i))
55 s = format (s, "%s, ", udp_connection_flags_str[i]);
58 s = format (s, "%s", udp_connection_flags_str[last]);
63 format_udp_vars (u8 * s, va_list * args)
65 udp_connection_t *uc = va_arg (*args, udp_connection_t *);
66 s = format (s, " index %u flags: %U", uc->c_c_index,
67 format_udp_connection_flags, uc);
69 if (!(uc->flags & UDP_CONN_F_LISTEN))
75 format_udp_connection (u8 * s, va_list * args)
77 udp_connection_t *uc = va_arg (*args, udp_connection_t *);
78 u32 verbose = va_arg (*args, u32);
81 s = format (s, "%-50U", format_udp_connection_id, uc);
84 s = format (s, "%-15s",
85 (uc->flags & UDP_CONN_F_LISTEN) ? "LISTEN" : "OPENED", uc);
87 s = format (s, "\n%U", format_udp_vars, uc);
93 udp_config_fn (vlib_main_t * vm, unformat_input_t * input)
95 udp_main_t *um = &udp_main;
98 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
100 if (unformat (input, "mtu %u", &tmp))
101 um->default_mtu = tmp;
103 return clib_error_return (0, "unknown input `%U'",
104 format_unformat_error, input);
109 VLIB_CONFIG_FUNCTION (udp_config_fn, "udp");
111 static clib_error_t *
112 show_udp_punt_fn (vlib_main_t * vm, unformat_input_t * input,
113 vlib_cli_command_t * cmd_arg)
115 udp_main_t *um = vnet_get_udp_main ();
117 clib_error_t *error = NULL;
119 if (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
120 return clib_error_return (0, "unknown input `%U'", format_unformat_error,
123 udp_dst_port_info_t *port_info;
124 if (um->punt_unknown4)
126 vlib_cli_output (vm, "IPv4 UDP punt: enabled");
131 vec_foreach (port_info, um->dst_port_infos[UDP_IP4])
133 if (udp_is_valid_dst_port (port_info->dst_port, 1))
135 s = format (s, (!s) ? "%d" : ", %d", port_info->dst_port);
138 s = format (s, "%c", 0);
139 vlib_cli_output (vm, "IPV4 UDP ports punt : %s", s);
142 if (um->punt_unknown6)
144 vlib_cli_output (vm, "IPv6 UDP punt: enabled");
149 vec_foreach (port_info, um->dst_port_infos[UDP_IP6])
151 if (udp_is_valid_dst_port (port_info->dst_port, 01))
153 s = format (s, (!s) ? "%d" : ", %d", port_info->dst_port);
156 s = format (s, "%c", 0);
157 vlib_cli_output (vm, "IPV6 UDP ports punt : %s", s);
163 VLIB_CLI_COMMAND (show_tcp_punt_command, static) =
165 .path = "show udp punt",
166 .short_help = "show udp punt [ipv4|ipv6]",
167 .function = show_udp_punt_fn,
172 * fd.io coding-style-patch-verification: ON
175 * eval: (c-set-style "gnu")