FD.io VPP  v21.01.1
Vector Packet Processing
cli.c
Go to the documentation of this file.
1 /*
2  *------------------------------------------------------------------
3  * Copyright (c) 2018 Cisco and/or its affiliates.
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at:
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *------------------------------------------------------------------
16  */
17 #include <stdint.h>
18 #include <net/if.h>
19 #include <sys/ioctl.h>
20 #include <inttypes.h>
21 
22 #include <vlib/vlib.h>
23 #include <vlib/unix/unix.h>
24 #include <vlib/pci/pci.h>
25 #include <vnet/ethernet/ethernet.h>
26 
27 #include <af_xdp/af_xdp.h>
28 
29 static clib_error_t *
31  vlib_cli_command_t * cmd)
32 {
34 
35  if (!unformat_user (input, unformat_af_xdp_create_if_args, &args))
36  return clib_error_return (0, "unknown input `%U'",
37  format_unformat_error, input);
38 
39  af_xdp_create_if (vm, &args);
40 
41  vec_free (args.linux_ifname);
42  vec_free (args.name);
43 
44  return args.error;
45 }
46 
47 /* *INDENT-OFF* */
48 VLIB_CLI_COMMAND (af_xdp_create_command, static) = {
49  .path = "create interface af_xdp",
50  .short_help = "create interface af_xdp <host-if linux-ifname> [name ifname] [rx-queue-size size] [tx-queue-size size] [num-rx-queues <num|all>] [prog pathname] [zero-copy|no-zero-copy]",
51  .function = af_xdp_create_command_fn,
52 };
53 /* *INDENT-ON* */
54 
55 static clib_error_t *
57  vlib_cli_command_t * cmd)
58 {
59  unformat_input_t _line_input, *line_input = &_line_input;
60  u32 sw_if_index = ~0;
63  af_xdp_device_t *ad;
64  vnet_main_t *vnm = vnet_get_main ();
65 
66  /* Get a line of input. */
67  if (!unformat_user (input, unformat_line_input, line_input))
68  return 0;
69 
70  while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
71  {
72  if (unformat (line_input, "sw_if_index %d", &sw_if_index))
73  ;
74  else if (unformat (line_input, "%U", unformat_vnet_sw_interface,
75  vnm, &sw_if_index))
76  ;
77  else
78  return clib_error_return (0, "unknown input `%U'",
79  format_unformat_error, input);
80  }
81  unformat_free (line_input);
82 
83  if (sw_if_index == ~0)
84  return clib_error_return (0,
85  "please specify interface name or sw_if_index");
86 
87  hw = vnet_get_sup_hw_interface (vnm, sw_if_index);
88  if (hw == NULL || af_xdp_device_class.index != hw->dev_class_index)
89  return clib_error_return (0, "not an AVF interface");
90 
91  ad = pool_elt_at_index (am->devices, hw->dev_instance);
92 
93  af_xdp_delete_if (vm, ad);
94 
95  return 0;
96 }
97 
98 /* *INDENT-OFF* */
99 VLIB_CLI_COMMAND (af_xdp_delete_command, static) = {
100  .path = "delete interface af_xdp",
101  .short_help = "delete interface af_xdp "
102  "{<interface> | sw_if_index <sw_idx>}",
103  .function = af_xdp_delete_command_fn,
104 };
105 /* *INDENT-ON* */
106 
107 clib_error_t *
109 {
110  return 0;
111 }
112 
114 
115 /*
116  * fd.io coding-style-patch-verification: ON
117  *
118  * Local Variables:
119  * eval: (c-set-style "gnu")
120  * End:
121  */
vnet_device_class_t af_xdp_device_class
vnet_main_t * vnet_get_main(void)
Definition: misc.c:46
static vnet_hw_interface_t * vnet_get_sup_hw_interface(vnet_main_t *vnm, u32 sw_if_index)
static clib_error_t * af_xdp_create_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: cli.c:30
static clib_error_t * af_xdp_delete_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: cli.c:56
uword unformat_user(unformat_input_t *input, unformat_function_t *func,...)
Definition: unformat.c:989
vlib_main_t * vm
Definition: in2out_ed.c:1580
unformat_function_t unformat_vnet_sw_interface
void af_xdp_delete_if(vlib_main_t *vm, af_xdp_device_t *ad)
Definition: device.c:89
af_xdp_device_t * devices
Definition: af_xdp.h:114
#define VLIB_INIT_FUNCTION(x)
Definition: init.h:173
af_xdp_main_t af_xdp_main
Definition: device.c:30
#define clib_error_return(e, args...)
Definition: error.h:99
unsigned int u32
Definition: types.h:88
unformat_function_t unformat_line_input
Definition: format.h:282
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
Definition: pool.h:546
struct _unformat_input_t unformat_input_t
#define UNFORMAT_END_OF_INPUT
Definition: format.h:144
clib_error_t * af_xdp_cli_init(vlib_main_t *vm)
Definition: cli.c:108
#define vec_free(V)
Free vector&#39;s memory (no header).
Definition: vec.h:380
void af_xdp_create_if(vlib_main_t *vm, af_xdp_create_if_args_t *args)
Definition: device.c:305
unformat_function_t unformat_af_xdp_create_if_args
Definition: af_xdp.h:156
#define VLIB_CLI_COMMAND(x,...)
Definition: cli.h:158
clib_error_t * error
Definition: af_xdp.h:141
static void unformat_free(unformat_input_t *i)
Definition: format.h:162
u8 * format_unformat_error(u8 *s, va_list *va)
Definition: unformat.c:91
vl_api_interface_index_t sw_if_index
Definition: wireguard.api:34
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:170