FD.io VPP  v20.05.1-6-gf53edbc3b
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>
17 
18 u8 *
19 format_udp_connection_id (u8 * s, va_list * args)
20 {
21  udp_connection_t *uc = va_arg (*args, udp_connection_t *);
22  if (!uc)
23  return s;
24  if (uc->c_is_ip4)
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));
29  else
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));
34  return s;
35 }
36 
37 static const char *udp_connection_flags_str[] = {
38 #define _(sym, str) str,
40 #undef _
41 };
42 
43 static u8 *
44 format_udp_connection_flags (u8 * s, va_list * args)
45 {
46  udp_connection_t *uc = va_arg (*args, udp_connection_t *);
47  int i, last = -1;
48 
49  for (i = 0; i < UDP_CONN_N_FLAGS; i++)
50  if (uc->flags & (1 << i))
51  last = i;
52  for (i = 0; i < last; i++)
53  {
54  if (uc->flags & (1 << i))
55  s = format (s, "%s, ", udp_connection_flags_str[i]);
56  }
57  if (last >= 0)
58  s = format (s, "%s", udp_connection_flags_str[last]);
59  return s;
60 }
61 
62 static u8 *
63 format_udp_vars (u8 * s, va_list * args)
64 {
65  udp_connection_t *uc = va_arg (*args, udp_connection_t *);
66  s = format (s, " index %u flags: %U", uc->c_c_index,
68 
69  if (!(uc->flags & UDP_CONN_F_LISTEN))
70  s = format (s, "\n");
71  return s;
72 }
73 
74 u8 *
75 format_udp_connection (u8 * s, va_list * args)
76 {
77  udp_connection_t *uc = va_arg (*args, udp_connection_t *);
78  u32 verbose = va_arg (*args, u32);
79  if (!uc)
80  return s;
81  s = format (s, "%-50U", format_udp_connection_id, uc);
82  if (verbose)
83  {
84  s = format (s, "%-15s",
85  (uc->flags & UDP_CONN_F_LISTEN) ? "LISTEN" : "OPENED", uc);
86  if (verbose > 1)
87  s = format (s, "\n%U", format_udp_vars, uc);
88  }
89  return s;
90 }
91 
92 static clib_error_t *
94 {
95  udp_main_t *um = &udp_main;
96  u32 tmp;
97 
99  {
100  if (unformat (input, "mtu %u", &tmp))
101  um->default_mtu = tmp;
102  else
103  return clib_error_return (0, "unknown input `%U'",
104  format_unformat_error, input);
105  }
106  return 0;
107 }
108 
110 
111 static clib_error_t *
113  vlib_cli_command_t * cmd_arg)
114 {
115  udp_main_t *um = vnet_get_udp_main ();
116 
117  clib_error_t *error = NULL;
118 
120  return clib_error_return (0, "unknown input `%U'", format_unformat_error,
121  input);
122 
123  udp_dst_port_info_t *port_info;
124  if (um->punt_unknown4)
125  {
126  vlib_cli_output (vm, "IPv4 UDP punt: enabled");
127  }
128  else
129  {
130  u8 *s = NULL;
131  vec_foreach (port_info, um->dst_port_infos[UDP_IP4])
132  {
133  if (udp_is_valid_dst_port (port_info->dst_port, 1))
134  {
135  s = format (s, (!s) ? "%d" : ", %d", port_info->dst_port);
136  }
137  }
138  s = format (s, "%c", 0);
139  vlib_cli_output (vm, "IPV4 UDP ports punt : %s", s);
140  }
141 
142  if (um->punt_unknown6)
143  {
144  vlib_cli_output (vm, "IPv6 UDP punt: enabled");
145  }
146  else
147  {
148  u8 *s = NULL;
149  vec_foreach (port_info, um->dst_port_infos[UDP_IP6])
150  {
151  if (udp_is_valid_dst_port (port_info->dst_port, 01))
152  {
153  s = format (s, (!s) ? "%d" : ", %d", port_info->dst_port);
154  }
155  }
156  s = format (s, "%c", 0);
157  vlib_cli_output (vm, "IPV6 UDP ports punt : %s", s);
158  }
159 
160  return (error);
161 }
162 /* *INDENT-OFF* */
163 VLIB_CLI_COMMAND (show_tcp_punt_command, static) =
164 {
165  .path = "show udp punt",
166  .short_help = "show udp punt [ipv4|ipv6]",
167  .function = show_udp_punt_fn,
168 };
169 /* *INDENT-ON* */
170 
171 /*
172  * fd.io coding-style-patch-verification: ON
173  *
174  * Local Variables:
175  * eval: (c-set-style "gnu")
176  * End:
177  */
udp_main_t udp_main
Definition: udp.c:22
static heap_elt_t * last(heap_header_t *h)
Definition: heap.c:53
u8 * format(u8 *s, const char *fmt,...)
Definition: format.c:424
u8 punt_unknown6
Definition: udp.h:162
unsigned char u8
Definition: types.h:56
static udp_main_t * vnet_get_udp_main()
Definition: udp.h:200
u8 flags
connection flags
Definition: udp.h:66
static u8 * format_udp_connection_flags(u8 *s, va_list *args)
Definition: udp_cli.c:44
format_function_t format_ip4_address
Definition: format.h:73
u8 * format_udp_connection_id(u8 *s, va_list *args)
Definition: udp_cli.c:19
u8 punt_unknown4
Definition: udp.h:161
#define clib_error_return(e, args...)
Definition: error.h:99
static const char * udp_connection_flags_str[]
Definition: udp_cli.c:37
unsigned int u32
Definition: types.h:88
u8 * format_udp_connection(u8 *s, va_list *args)
Definition: udp_cli.c:75
static clib_error_t * udp_config_fn(vlib_main_t *vm, unformat_input_t *input)
Definition: udp_cli.c:93
udp_dst_port_info_t * dst_port_infos[N_UDP_AF]
Definition: udp.h:151
struct _unformat_input_t unformat_input_t
#define VLIB_CONFIG_FUNCTION(x, n,...)
Definition: init.h:182
vlib_main_t * vm
Definition: in2out_ed.c:1599
Definition: udp.h:144
static u8 * format_udp_vars(u8 *s, va_list *args)
Definition: udp_cli.c:63
#define UNFORMAT_END_OF_INPUT
Definition: format.h:145
format_function_t format_ip6_address
Definition: format.h:91
sll srl srl sll sra u16x4 i
Definition: vector_sse42.h:317
#define VLIB_CLI_COMMAND(x,...)
Definition: cli.h:152
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
Definition: cli.c:689
udp_dst_port_t dst_port
Definition: udp.h:127
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:112
bool udp_is_valid_dst_port(udp_dst_port_t dst_port, u8 is_ip4)
Definition: udp_local.c:529
u16 default_mtu
Definition: udp.h:176
u8 * format_unformat_error(u8 *s, va_list *va)
Definition: unformat.c:91
#define vec_foreach(var, vec)
Vector iterator.
Definition: udp.h:145
uword unformat(unformat_input_t *i, const char *fmt,...)
Definition: unformat.c:978
static uword unformat_check_input(unformat_input_t *i)
Definition: format.h:171