FD.io VPP  v21.10.1-2-g0a485f517
Vector Packet Processing
udp_cli.c
Go to the documentation of this file.
1 /*
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:
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/udp/udp.h>
18 
19 u8 *
20 format_udp_connection_id (u8 * s, va_list * args)
21 {
22  udp_connection_t *uc = va_arg (*args, udp_connection_t *);
23  if (!uc)
24  return s;
25  if (uc->c_is_ip4)
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));
30  else
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));
35  return s;
36 }
37 
38 static const char *udp_connection_flags_str[] = {
39 #define _(sym, str) str,
41 #undef _
42 };
43 
44 static u8 *
45 format_udp_connection_flags (u8 * s, va_list * args)
46 {
47  udp_connection_t *uc = va_arg (*args, udp_connection_t *);
48  int i, last = -1;
49 
50  for (i = 0; i < UDP_CONN_N_FLAGS; i++)
51  if (uc->flags & (1 << i))
52  last = i;
53  for (i = 0; i < last; i++)
54  {
55  if (uc->flags & (1 << i))
56  s = format (s, "%s, ", udp_connection_flags_str[i]);
57  }
58  if (last >= 0)
59  s = format (s, "%s", udp_connection_flags_str[last]);
60  return s;
61 }
62 
63 static u8 *
64 format_udp_vars (u8 * s, va_list * args)
65 {
66  udp_connection_t *uc = va_arg (*args, udp_connection_t *);
67  s = format (s, " index %u flags: %U", uc->c_c_index,
69 
70  if (!(uc->flags & UDP_CONN_F_LISTEN))
71  s = format (s, "\n");
72  return s;
73 }
74 
75 u8 *
76 format_udp_connection (u8 * s, va_list * args)
77 {
78  udp_connection_t *uc = va_arg (*args, udp_connection_t *);
79  u32 verbose = va_arg (*args, u32);
80  if (!uc)
81  return s;
82  s = format (s, "%-" SESSION_CLI_ID_LEN "U", format_udp_connection_id, uc);
83  if (verbose)
84  {
85  s = format (s, "%-" SESSION_CLI_STATE_LEN "s",
86  (uc->flags & UDP_CONN_F_LISTEN) ? "LISTEN" : "OPENED", uc);
87  if (verbose > 1)
88  s = format (s, "\n%U", format_udp_vars, uc);
89  }
90  return s;
91 }
92 
93 static clib_error_t *
95 {
96  udp_main_t *um = &udp_main;
97  u32 tmp;
98 
100  {
101  if (unformat (input, "mtu %u", &tmp))
102  um->default_mtu = tmp;
103  else if (unformat (input, "icmp-unreachable-disabled"))
105  else
106  return clib_error_return (0, "unknown input `%U'",
107  format_unformat_error, input);
108  }
109  return 0;
110 }
111 
113 
114 static clib_error_t *
116  vlib_cli_command_t * cmd_arg)
117 {
118  udp_main_t *um = vnet_get_udp_main ();
119 
120  clib_error_t *error = NULL;
121 
123  return clib_error_return (0, "unknown input `%U'", format_unformat_error,
124  input);
125 
126  udp_dst_port_info_t *port_info;
127  if (um->punt_unknown4)
128  {
129  vlib_cli_output (vm, "IPv4 UDP punt: enabled");
130  }
131  else
132  {
133  u8 *s = NULL;
134  vec_foreach (port_info, um->dst_port_infos[UDP_IP4])
135  {
136  if (udp_is_valid_dst_port (port_info->dst_port, 1))
137  {
138  s = format (s, (!s) ? "%d" : ", %d", port_info->dst_port);
139  }
140  }
141  s = format (s, "%c", 0);
142  vlib_cli_output (vm, "IPV4 UDP ports punt : %s", s);
143  }
144 
145  if (um->punt_unknown6)
146  {
147  vlib_cli_output (vm, "IPv6 UDP punt: enabled");
148  }
149  else
150  {
151  u8 *s = NULL;
152  vec_foreach (port_info, um->dst_port_infos[UDP_IP6])
153  {
154  if (udp_is_valid_dst_port (port_info->dst_port, 01))
155  {
156  s = format (s, (!s) ? "%d" : ", %d", port_info->dst_port);
157  }
158  }
159  s = format (s, "%c", 0);
160  vlib_cli_output (vm, "IPV6 UDP ports punt : %s", s);
161  }
162 
163  return (error);
164 }
165 /* *INDENT-OFF* */
167 {
168  .path = "show udp punt",
169  .short_help = "show udp punt [ipv4|ipv6]",
170  .function = show_udp_punt_fn,
171 };
172 /* *INDENT-ON* */
173 
174 /*
175  * fd.io coding-style-patch-verification: ON
176  *
177  * Local Variables:
178  * eval: (c-set-style "gnu")
179  * End:
180  */
tmp
u32 * tmp
Definition: interface_output.c:1096
SESSION_CLI_STATE_LEN
#define SESSION_CLI_STATE_LEN
Definition: session_types.h:508
foreach_udp_connection_flag
@ foreach_udp_connection_flag
Definition: udp.h:55
udp_connection_t::flags
u8 flags
connection flags
Definition: udp.h:65
udp_dst_port_info_t
Definition: udp.h:69
session_types.h
format_ip4_address
format_function_t format_ip4_address
Definition: format.h:73
SESSION_CLI_ID_LEN
#define SESSION_CLI_ID_LEN
Definition: session_types.h:507
UDP_CONN_N_FLAGS
@ UDP_CONN_N_FLAGS
Definition: udp.h:49
format_udp_connection_flags
static u8 * format_udp_connection_flags(u8 *s, va_list *args)
Definition: udp_cli.c:45
clib_error_return
#define clib_error_return(e, args...)
Definition: error.h:99
vlib_cli_command_t::path
char * path
Definition: cli.h:96
udp_main_t::punt_unknown4
u8 punt_unknown4
Definition: udp.h:109
vm
vlib_main_t * vm
X-connect all packets from the HOST to the PHY.
Definition: nat44_ei.c:3047
unformat_input_t
struct _unformat_input_t unformat_input_t
udp_connection_t
Definition: udp.h:59
error
Definition: cJSON.c:88
format_udp_connection
u8 * format_udp_connection(u8 *s, va_list *args)
Definition: udp_cli.c:76
VLIB_CONFIG_FUNCTION
#define VLIB_CONFIG_FUNCTION(x, n,...)
Definition: init.h:181
unformat
uword unformat(unformat_input_t *i, const char *fmt,...)
Definition: unformat.c:978
UDP_IP4
@ UDP_IP4
Definition: udp.h:93
udp_main_t::dst_port_infos
udp_dst_port_info_t * dst_port_infos[N_UDP_AF]
Definition: udp.h:99
format_udp_connection_id
u8 * format_udp_connection_id(u8 *s, va_list *args)
Definition: udp_cli.c:20
udp_main_t::punt_unknown6
u8 punt_unknown6
Definition: udp.h:110
udp_dst_port_info_t::dst_port
udp_dst_port_t dst_port
Definition: udp.h:75
unformat_check_input
static uword unformat_check_input(unformat_input_t *i)
Definition: format.h:163
vlib_config_function_runtime_t
Definition: init.h:68
udp_connection_flags_str
static const char * udp_connection_flags_str[]
Definition: udp_cli.c:38
last
static heap_elt_t * last(heap_header_t *h)
Definition: heap.c:53
udp_main_t::icmp_send_unreachable_disabled
u8 icmp_send_unreachable_disabled
Definition: udp.h:127
format_udp_vars
static u8 * format_udp_vars(u8 *s, va_list *args)
Definition: udp_cli.c:64
format_unformat_error
u8 * format_unformat_error(u8 *s, va_list *va)
Definition: unformat.c:91
VLIB_CLI_COMMAND
#define VLIB_CLI_COMMAND(x,...)
Definition: cli.h:163
udp_is_valid_dst_port
u8 udp_is_valid_dst_port(udp_dst_port_t dst_port, u8 is_ip4)
Definition: udp_local.c:492
UDP_IP6
@ UDP_IP6
Definition: udp.h:92
vlib_cli_output
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
Definition: cli.c:716
show_udp_punt_fn
static clib_error_t * show_udp_punt_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd_arg)
Definition: udp_cli.c:115
udp_main
udp_main_t udp_main
Definition: udp.c:23
format
description fragment has unexpected format
Definition: map.api:433
u32
unsigned int u32
Definition: types.h:88
show_tcp_punt_command
static vlib_cli_command_t show_tcp_punt_command
(constructor) VLIB_CLI_COMMAND (show_tcp_punt_command)
Definition: udp_cli.c:166
vec_foreach
#define vec_foreach(var, vec)
Vector iterator.
Definition: vec_bootstrap.h:213
udp.h
vlib_main_t
Definition: main.h:102
udp_main_t
Definition: udp.h:97
u8
unsigned char u8
Definition: types.h:56
clib_error_t
Definition: clib_error.h:21
format_ip6_address
format_function_t format_ip6_address
Definition: format.h:91
i
int i
Definition: flowhash_template.h:376
udp_main_t::default_mtu
u16 default_mtu
Definition: udp.h:124
vlib_cli_command_t
Definition: cli.h:92
udp_config_fn
static clib_error_t * udp_config_fn(vlib_main_t *vm, unformat_input_t *input)
Definition: udp_cli.c:94
vnet_get_udp_main
static udp_main_t * vnet_get_udp_main()
Definition: udp.h:154
UNFORMAT_END_OF_INPUT
#define UNFORMAT_END_OF_INPUT
Definition: format.h:137