FD.io VPP  v21.06-3-gbb25fbf28
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* */
49  .path = "create interface af_xdp",
50  .short_help =
51  "create interface af_xdp <host-if linux-ifname> [name ifname] "
52  "[rx-queue-size size] [tx-queue-size size] [num-rx-queues <num|all>] "
53  "[prog pathname] [zero-copy|no-zero-copy] [no-syscall-lock]",
54  .function = af_xdp_create_command_fn,
55 };
56 /* *INDENT-ON* */
57 
58 static clib_error_t *
60  vlib_cli_command_t * cmd)
61 {
62  unformat_input_t _line_input, *line_input = &_line_input;
63  u32 sw_if_index = ~0;
66  af_xdp_device_t *ad;
67  vnet_main_t *vnm = vnet_get_main ();
68 
69  /* Get a line of input. */
70  if (!unformat_user (input, unformat_line_input, line_input))
71  return 0;
72 
73  while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
74  {
75  if (unformat (line_input, "sw_if_index %d", &sw_if_index))
76  ;
77  else if (unformat (line_input, "%U", unformat_vnet_sw_interface,
78  vnm, &sw_if_index))
79  ;
80  else
81  return clib_error_return (0, "unknown input `%U'",
82  format_unformat_error, input);
83  }
84  unformat_free (line_input);
85 
86  if (sw_if_index == ~0)
87  return clib_error_return (0,
88  "please specify interface name or sw_if_index");
89 
91  if (hw == NULL || af_xdp_device_class.index != hw->dev_class_index)
92  return clib_error_return (0, "not an AVF interface");
93 
94  ad = pool_elt_at_index (am->devices, hw->dev_instance);
95 
96  af_xdp_delete_if (vm, ad);
97 
98  return 0;
99 }
100 
101 /* *INDENT-OFF* */
103  .path = "delete interface af_xdp",
104  .short_help = "delete interface af_xdp "
105  "{<interface> | sw_if_index <sw_idx>}",
106  .function = af_xdp_delete_command_fn,
107 };
108 /* *INDENT-ON* */
109 
110 clib_error_t *
112 {
113  return 0;
114 }
115 
117 
118 /*
119  * fd.io coding-style-patch-verification: ON
120  *
121  * Local Variables:
122  * eval: (c-set-style "gnu")
123  * End:
124  */
af_xdp_create_command
static vlib_cli_command_t af_xdp_create_command
(constructor) VLIB_CLI_COMMAND (af_xdp_create_command)
Definition: cli.c:48
vlib.h
af_xdp_delete_command_fn
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:59
unformat_user
uword unformat_user(unformat_input_t *input, unformat_function_t *func,...)
Definition: unformat.c:989
af_xdp_main_t
Definition: af_xdp.h:126
af_xdp.h
unformat_line_input
unformat_function_t unformat_line_input
Definition: format.h:275
pool_elt_at_index
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
Definition: pool.h:553
clib_error_return
#define clib_error_return(e, args...)
Definition: error.h:99
vlib_cli_command_t::path
char * path
Definition: cli.h:96
am
app_main_t * am
Definition: application.c:489
vm
vlib_main_t * vm
X-connect all packets from the HOST to the PHY.
Definition: nat44_ei.c:3047
af_xdp_device_class
vnet_device_class_t af_xdp_device_class
unformat_input_t
struct _unformat_input_t unformat_input_t
vnet_hw_interface_t::dev_instance
u32 dev_instance
Definition: interface.h:660
af_xdp_delete_if
void af_xdp_delete_if(vlib_main_t *vm, af_xdp_device_t *ad)
Definition: device.c:90
ethernet.h
unformat
uword unformat(unformat_input_t *i, const char *fmt,...)
Definition: unformat.c:978
af_xdp_main
af_xdp_main_t af_xdp_main
Definition: device.c:31
unformat_free
static void unformat_free(unformat_input_t *i)
Definition: format.h:155
vnet_get_main
vnet_main_t * vnet_get_main(void)
Definition: pnat_test_stubs.h:56
unformat_check_input
static uword unformat_check_input(unformat_input_t *i)
Definition: format.h:163
af_xdp_create_if_args_t::linux_ifname
char * linux_ifname
Definition: af_xdp.h:149
af_xdp_device_t
Definition: af_xdp.h:91
vnet_hw_interface_t::dev_class_index
u32 dev_class_index
Definition: interface.h:659
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
af_xdp_create_command_fn
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
af_xdp_create_if_args_t::name
char * name
Definition: af_xdp.h:150
unformat_af_xdp_create_if_args
unformat_function_t unformat_af_xdp_create_if_args
Definition: af_xdp.h:178
vnet_hw_interface_t
Definition: interface.h:638
vnet_main_t
Definition: vnet.h:76
vec_free
#define vec_free(V)
Free vector's memory (no header).
Definition: vec.h:395
af_xdp_create_if_args_t::error
clib_error_t * error
Definition: af_xdp.h:161
af_xdp_create_if
void af_xdp_create_if(vlib_main_t *vm, af_xdp_create_if_args_t *args)
Definition: device.c:365
af_xdp_create_if_args_t
Definition: af_xdp.h:147
unformat_vnet_sw_interface
unformat_function_t unformat_vnet_sw_interface
Definition: interface_funcs.h:459
u32
unsigned int u32
Definition: types.h:88
VLIB_INIT_FUNCTION
#define VLIB_INIT_FUNCTION(x)
Definition: init.h:172
vnet_get_sup_hw_interface
static vnet_hw_interface_t * vnet_get_sup_hw_interface(vnet_main_t *vnm, u32 sw_if_index)
Definition: interface_funcs.h:92
pci.h
vlib_main_t
Definition: main.h:102
clib_error_t
Definition: clib_error.h:21
unix.h
vlib_init_function_t
clib_error_t *() vlib_init_function_t(struct vlib_main_t *vm)
Definition: init.h:51
af_xdp_delete_command
static vlib_cli_command_t af_xdp_delete_command
(constructor) VLIB_CLI_COMMAND (af_xdp_delete_command)
Definition: cli.c:102
vlib_cli_command_t
Definition: cli.h:92
sw_if_index
vl_api_interface_index_t sw_if_index
Definition: wireguard.api:34
af_xdp_cli_init
clib_error_t * af_xdp_cli_init(vlib_main_t *vm)
Definition: cli.c:111
UNFORMAT_END_OF_INPUT
#define UNFORMAT_END_OF_INPUT
Definition: format.h:137