Line data Source code
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 *
30 0 : af_xdp_create_command_fn (vlib_main_t * vm, unformat_input_t * input,
31 : vlib_cli_command_t * cmd)
32 : {
33 : af_xdp_create_if_args_t args;
34 :
35 0 : if (!unformat_user (input, unformat_af_xdp_create_if_args, &args))
36 0 : return clib_error_return (0, "unknown input `%U'",
37 : format_unformat_error, input);
38 :
39 0 : af_xdp_create_if (vm, &args);
40 :
41 0 : vec_free (args.linux_ifname);
42 0 : vec_free (args.name);
43 0 : vec_free (args.prog);
44 0 : vec_free (args.netns);
45 :
46 0 : return args.error;
47 : }
48 :
49 : /* *INDENT-OFF* */
50 258327 : VLIB_CLI_COMMAND (af_xdp_create_command, static) = {
51 : .path = "create interface af_xdp",
52 : .short_help =
53 : "create interface af_xdp <host-if linux-ifname> [name ifname] "
54 : "[rx-queue-size size] [tx-queue-size size] [num-rx-queues <num|all>] "
55 : "[prog pathname] [netns ns] [zero-copy|no-zero-copy] [no-syscall-lock]",
56 : .function = af_xdp_create_command_fn,
57 : };
58 : /* *INDENT-ON* */
59 :
60 : static clib_error_t *
61 0 : af_xdp_delete_command_fn (vlib_main_t * vm, unformat_input_t * input,
62 : vlib_cli_command_t * cmd)
63 : {
64 0 : unformat_input_t _line_input, *line_input = &_line_input;
65 0 : u32 sw_if_index = ~0;
66 : vnet_hw_interface_t *hw;
67 0 : af_xdp_main_t *am = &af_xdp_main;
68 : af_xdp_device_t *ad;
69 0 : vnet_main_t *vnm = vnet_get_main ();
70 :
71 : /* Get a line of input. */
72 0 : if (!unformat_user (input, unformat_line_input, line_input))
73 0 : return 0;
74 :
75 0 : while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
76 : {
77 0 : if (unformat (line_input, "sw_if_index %d", &sw_if_index))
78 : ;
79 0 : else if (unformat (line_input, "%U", unformat_vnet_sw_interface,
80 : vnm, &sw_if_index))
81 : ;
82 : else
83 0 : return clib_error_return (0, "unknown input `%U'",
84 : format_unformat_error, input);
85 : }
86 0 : unformat_free (line_input);
87 :
88 0 : if (sw_if_index == ~0)
89 0 : return clib_error_return (0,
90 : "please specify interface name or sw_if_index");
91 :
92 0 : hw = vnet_get_sup_hw_interface (vnm, sw_if_index);
93 0 : if (hw == NULL || af_xdp_device_class.index != hw->dev_class_index)
94 0 : return clib_error_return (0, "not an AVF interface");
95 :
96 0 : ad = pool_elt_at_index (am->devices, hw->dev_instance);
97 :
98 0 : af_xdp_delete_if (vm, ad);
99 :
100 0 : return 0;
101 : }
102 :
103 : /* *INDENT-OFF* */
104 258327 : VLIB_CLI_COMMAND (af_xdp_delete_command, static) = {
105 : .path = "delete interface af_xdp",
106 : .short_help = "delete interface af_xdp "
107 : "{<interface> | sw_if_index <sw_idx>}",
108 : .function = af_xdp_delete_command_fn,
109 : };
110 : /* *INDENT-ON* */
111 :
112 : clib_error_t *
113 559 : af_xdp_cli_init (vlib_main_t * vm)
114 : {
115 559 : return 0;
116 : }
117 :
118 1119 : VLIB_INIT_FUNCTION (af_xdp_cli_init);
119 :
120 : /*
121 : * fd.io coding-style-patch-verification: ON
122 : *
123 : * Local Variables:
124 : * eval: (c-set-style "gnu")
125 : * End:
126 : */
|