FD.io VPP  v17.01.1-3-gc6833f8
Vector Packet Processing
cli.c
Go to the documentation of this file.
1 /*
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:
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 
21 #include <vlib/vlib.h>
22 #include <vlib/unix/unix.h>
23 #include <vnet/ethernet/ethernet.h>
24 
27 
28 static clib_error_t *
30  vlib_cli_command_t * cmd)
31 {
32  unformat_input_t _line_input, *line_input = &_line_input;
33  u8 *host_if_name = NULL;
34  u8 hwaddr[6];
35  u8 *hw_addr_ptr = 0;
36  int r;
37  u8 is_pipe = 0;
38  u8 is_master = 0;
39  u32 sw_if_index = ~0;
40 
41  /* Get a line of input. */
42  if (!unformat_user (input, unformat_line_input, line_input))
43  return 0;
44 
45  while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
46  {
47  if (unformat (line_input, "name %s", &host_if_name))
48  ;
49  else
50  if (unformat
51  (line_input, "hw-addr %U", unformat_ethernet_address, hwaddr))
52  hw_addr_ptr = hwaddr;
53  else if (unformat (line_input, "pipe"))
54  is_pipe = 1;
55  else if (unformat (line_input, "master"))
56  is_master = 1;
57  else if (unformat (line_input, "slave"))
58  is_master = 0;
59  else
60  return clib_error_return (0, "unknown input `%U'",
61  format_unformat_error, input);
62  }
63  unformat_free (line_input);
64 
65  if (host_if_name == NULL)
66  return clib_error_return (0, "missing host interface name");
67 
68  r =
69  netmap_create_if (vm, host_if_name, hw_addr_ptr, is_pipe, is_master,
70  &sw_if_index);
71 
72  if (r == VNET_API_ERROR_SYSCALL_ERROR_1)
73  return clib_error_return (0, "%s (errno %d)", strerror (errno), errno);
74 
75  if (r == VNET_API_ERROR_INVALID_INTERFACE)
76  return clib_error_return (0, "Invalid interface name");
77 
78  if (r == VNET_API_ERROR_SUBIF_ALREADY_EXISTS)
79  return clib_error_return (0, "Interface already exists");
80 
82  sw_if_index);
83  return 0;
84 }
85 
86 /* *INDENT-OFF* */
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,
92 };
93 /* *INDENT-ON* */
94 
95 static clib_error_t *
97  vlib_cli_command_t * cmd)
98 {
99  unformat_input_t _line_input, *line_input = &_line_input;
100  u8 *host_if_name = NULL;
101 
102  /* Get a line of input. */
103  if (!unformat_user (input, unformat_line_input, line_input))
104  return 0;
105 
106  while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
107  {
108  if (unformat (line_input, "name %s", &host_if_name))
109  ;
110  else
111  return clib_error_return (0, "unknown input `%U'",
112  format_unformat_error, input);
113  }
114  unformat_free (line_input);
115 
116  if (host_if_name == NULL)
117  return clib_error_return (0, "missing host interface name");
118 
119  netmap_delete_if (vm, host_if_name);
120 
121  return 0;
122 }
123 
124 /* *INDENT-OFF* */
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,
129 };
130 /* *INDENT-ON* */
131 
132 clib_error_t *
134 {
135  return 0;
136 }
137 
139 
140 /*
141  * fd.io coding-style-patch-verification: ON
142  *
143  * Local Variables:
144  * eval: (c-set-style "gnu")
145  * End:
146  */
static clib_error_t * netmap_delete_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: cli.c:96
clib_error_t * netmap_cli_init(vlib_main_t *vm)
Definition: cli.c:133
uword unformat(unformat_input_t *i, char *fmt,...)
Definition: unformat.c:966
#define UNFORMAT_END_OF_INPUT
Definition: format.h:143
#define NULL
Definition: clib.h:55
format_function_t format_vnet_sw_if_index_name
vnet_main_t * vnet_get_main(void)
Definition: misc.c:46
#define VLIB_INIT_FUNCTION(x)
Definition: init.h:111
static void unformat_free(unformat_input_t *i)
Definition: format.h:161
uword unformat_user(unformat_input_t *input, unformat_function_t *func,...)
Definition: unformat.c:977
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
Definition: cli.c:576
int netmap_create_if(vlib_main_t *vm, u8 *if_name, u8 *hw_addr_set, u8 is_pipe, u8 is_master, u32 *sw_if_index)
Definition: netmap.c:113
#define VLIB_CLI_COMMAND(x,...)
Definition: cli.h:154
uword unformat_ethernet_address(unformat_input_t *input, va_list *args)
Definition: format.c:245
unsigned int u32
Definition: types.h:88
u8 * format_unformat_error(u8 *s, va_list *va)
Definition: unformat.c:91
static clib_error_t * netmap_create_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: cli.c:29
unsigned char u8
Definition: types.h:56
static uword unformat_check_input(unformat_input_t *i)
Definition: format.h:169
#define clib_error_return(e, args...)
Definition: error.h:111
struct _unformat_input_t unformat_input_t
unformat_function_t unformat_line_input
Definition: format.h:281
int netmap_delete_if(vlib_main_t *vm, u8 *host_if_name)
Definition: netmap.c:248