2 *------------------------------------------------------------------
3 * Copyright (c) 2016 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:
8 * http://www.apache.org/licenses/LICENSE-2.0
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 *------------------------------------------------------------------
19 #include <sys/ioctl.h>
21 #include <vlib/vlib.h>
22 #include <vlib/unix/unix.h>
23 #include <vnet/ethernet/ethernet.h>
25 #include <vnet/devices/netmap/net_netmap.h>
26 #include <vnet/devices/netmap/netmap.h>
29 netmap_create_command_fn (vlib_main_t * vm, unformat_input_t * input,
30 vlib_cli_command_t * cmd)
32 unformat_input_t _line_input, *line_input = &_line_input;
33 u8 *host_if_name = NULL;
41 /* Get a line of input. */
42 if (!unformat_user (input, unformat_line_input, line_input))
45 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
47 if (unformat (line_input, "name %s", &host_if_name))
51 (line_input, "hw-addr %U", unformat_ethernet_address, hwaddr))
53 else if (unformat (line_input, "pipe"))
55 else if (unformat (line_input, "master"))
57 else if (unformat (line_input, "slave"))
60 return clib_error_return (0, "unknown input `%U'",
61 format_unformat_error, input);
63 unformat_free (line_input);
65 if (host_if_name == NULL)
66 return clib_error_return (0, "missing host interface name");
69 netmap_create_if (vm, host_if_name, hw_addr_ptr, is_pipe, is_master,
72 if (r == VNET_API_ERROR_SYSCALL_ERROR_1)
73 return clib_error_return (0, "%s (errno %d)", strerror (errno), errno);
75 if (r == VNET_API_ERROR_INVALID_INTERFACE)
76 return clib_error_return (0, "Invalid interface name");
78 if (r == VNET_API_ERROR_SUBIF_ALREADY_EXISTS)
79 return clib_error_return (0, "Interface already exists");
81 vlib_cli_output (vm, "%U\n", format_vnet_sw_if_index_name, vnet_get_main (),
87 VLIB_CLI_COMMAND (netmap_create_command, static) = {
88 .path = "create netmap",
89 .short_help = "create netmap name [<intf name>|valeXXX:YYY] "
90 "[hw-addr <mac>] [pipe] [master|slave]",
91 .function = netmap_create_command_fn,
96 netmap_delete_command_fn (vlib_main_t * vm, unformat_input_t * input,
97 vlib_cli_command_t * cmd)
99 unformat_input_t _line_input, *line_input = &_line_input;
100 u8 *host_if_name = NULL;
102 /* Get a line of input. */
103 if (!unformat_user (input, unformat_line_input, line_input))
106 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
108 if (unformat (line_input, "name %s", &host_if_name))
111 return clib_error_return (0, "unknown input `%U'",
112 format_unformat_error, input);
114 unformat_free (line_input);
116 if (host_if_name == NULL)
117 return clib_error_return (0, "missing host interface name");
119 netmap_delete_if (vm, host_if_name);
125 VLIB_CLI_COMMAND (netmap_delete_command, static) = {
126 .path = "delete netmap",
127 .short_help = "delete netmap name <interface name>",
128 .function = netmap_delete_command_fn,
133 netmap_cli_init (vlib_main_t * vm)
138 VLIB_INIT_FUNCTION (netmap_cli_init);
141 * fd.io coding-style-patch-verification: ON
144 * eval: (c-set-style "gnu")