FD.io VPP  v16.06
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 
18 #include <vlib/vlib.h>
19 #include <vlib/unix/unix.h>
20 #include <vnet/ethernet/ethernet.h>
21 
23 
24 static clib_error_t *
26  vlib_cli_command_t * cmd)
27 {
28  unformat_input_t _line_input, * line_input = &_line_input;
29  u8 * host_if_name = NULL;
30  u8 hwaddr [6];
31  u8 * hw_addr_ptr = 0;
32  int r;
33  u8 is_pipe = 0;
34  u8 is_master = 0;
35 
36  /* Get a line of input. */
37  if (! unformat_user (input, unformat_line_input, line_input))
38  return 0;
39 
40  while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
41  {
42  if (unformat (line_input, "name %s", &host_if_name))
43  ;
44  else if (unformat (line_input, "hw-addr %U", unformat_ethernet_address, hwaddr))
45  hw_addr_ptr = hwaddr;
46  else if (unformat (line_input, "pipe"))
47  is_pipe = 1;
48  else if (unformat (line_input, "master"))
49  is_master = 1;
50  else if (unformat (line_input, "slave"))
51  is_master = 0;
52  else
53  return clib_error_return (0, "unknown input `%U'", format_unformat_error, input);
54  }
55  unformat_free (line_input);
56 
57  if (host_if_name == NULL)
58  return clib_error_return (0, "missing host interface name");
59 
60  r = netmap_create_if(vm, host_if_name, hw_addr_ptr, is_pipe, is_master);
61 
62  if (r == VNET_API_ERROR_SYSCALL_ERROR_1)
63  return clib_error_return(0, "%s (errno %d)", strerror (errno), errno);
64 
65  if (r == VNET_API_ERROR_INVALID_INTERFACE)
66  return clib_error_return(0, "Invalid interface name");
67 
68  if (r == VNET_API_ERROR_SUBIF_ALREADY_EXISTS)
69  return clib_error_return(0, "Interface already exists");
70 
71  return 0;
72 }
73 
74 VLIB_CLI_COMMAND (netmap_create_command, static) = {
75  .path = "create netmap",
76  .short_help = "create netmap name [<intf name>|valeXXX:YYY] "
77  "[hw-addr <mac>] [pipe] [master|slave]",
78  .function = netmap_create_command_fn,
79 };
80 
81 static clib_error_t *
83  vlib_cli_command_t * cmd)
84 {
85  unformat_input_t _line_input, * line_input = &_line_input;
86  u8 * host_if_name = NULL;
87 
88  /* Get a line of input. */
89  if (! unformat_user (input, unformat_line_input, line_input))
90  return 0;
91 
92  while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
93  {
94  if (unformat (line_input, "name %s", &host_if_name))
95  ;
96  else
97  return clib_error_return (0, "unknown input `%U'", format_unformat_error, input);
98  }
99  unformat_free (line_input);
100 
101  if (host_if_name == NULL)
102  return clib_error_return (0, "missing host interface name");
103 
104  netmap_delete_if(vm, host_if_name);
105 
106  return 0;
107 }
108 
109 VLIB_CLI_COMMAND (netmap_delete_command, static) = {
110  .path = "delete netmap",
111  .short_help = "delete netmap name <interface name>",
112  .function = netmap_delete_command_fn,
113 };
114 
115 clib_error_t *
117 {
118  return 0;
119 }
120 
static clib_error_t * netmap_delete_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: cli.c:82
clib_error_t * netmap_cli_init(vlib_main_t *vm)
Definition: cli.c:116
uword unformat(unformat_input_t *i, char *fmt,...)
Definition: unformat.c:942
always_inline void unformat_free(unformat_input_t *i)
Definition: format.h:160
#define UNFORMAT_END_OF_INPUT
Definition: format.h:142
#define NULL
Definition: clib.h:55
always_inline uword unformat_check_input(unformat_input_t *i)
Definition: format.h:168
#define VLIB_INIT_FUNCTION(x)
Definition: init.h:109
uword unformat_user(unformat_input_t *input, unformat_function_t *func,...)
Definition: unformat.c:953
int netmap_create_if(vlib_main_t *vm, u8 *if_name, u8 *hw_addr_set, u8 is_pipe, u8 is_master)
Definition: netmap.c:82
#define VLIB_CLI_COMMAND(x,...)
Definition: cli.h:150
uword unformat_ethernet_address(unformat_input_t *input, va_list *args)
Definition: format.c:187
u8 * format_unformat_error(u8 *s, va_list *va)
Definition: unformat.c:87
static clib_error_t * netmap_create_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: cli.c:25
unsigned char u8
Definition: types.h:56
#define clib_error_return(e, args...)
Definition: error.h:112
struct _unformat_input_t unformat_input_t
unformat_function_t unformat_line_input
Definition: format.h:279
int netmap_delete_if(vlib_main_t *vm, u8 *host_if_name)
Definition: netmap.c:205