FD.io VPP  v21.01.1
Vector Packet Processing
cli.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2019 Cisco and/or its affiliates.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at:
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include <vlib/vlib.h>
17 #include <vnet/vnet.h>
18 #include <vppinfra/error.h>
19 #include <vnet/ethernet/ethernet.h>
20 #include <vnet/feature/feature.h>
21 #include <vnet/gso/gso.h>
22 
23 static clib_error_t *
25  unformat_input_t * input,
26  vlib_cli_command_t * cmd)
27 {
28  vnet_main_t *vnm = vnet_get_main ();
29  unformat_input_t _line_input, *line_input = &_line_input;
30  clib_error_t *error = 0;
31 
32  u32 sw_if_index = ~0;
33  u8 enable = 0;
34 
35  /* Get a line of input. */
36  if (!unformat_user (input, unformat_line_input, line_input))
37  return 0;
38 
39  while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
40  {
41  if (unformat
42  (line_input, "%U", unformat_vnet_sw_interface, vnm, &sw_if_index))
43  ;
44  else if (unformat (line_input, "enable"))
45  enable = 1;
46  else if (unformat (line_input, "disable"))
47  enable = 0;
48  else
49  {
50  error = unformat_parse_error (line_input);
51  goto done;
52  }
53  }
54 
55  if (sw_if_index == ~0)
56  {
57  error = clib_error_return (0, "Interface not specified...");
58  goto done;
59  }
60  int rv = vnet_sw_interface_gso_enable_disable (sw_if_index, enable);
61 
62  switch (rv)
63  {
64  case VNET_API_ERROR_INVALID_VALUE:
65  error = clib_error_return (0, "interface type is not hardware");
66  break;
67  case VNET_API_ERROR_FEATURE_DISABLED:
68  error = clib_error_return (0, "interface should be ethernet interface");
69  break;
70  default:
71  ;
72  }
73 
74 done:
75  unformat_free (line_input);
76  return error;
77 }
78 
79 /* *INDENT-OFF* */
80 VLIB_CLI_COMMAND (set_interface_feature_gso_command, static) = {
81  .path = "set interface feature gso",
82  .short_help = "set interface feature gso <intfc> [enable | disable]",
84 };
85 /* *INDENT-ON* */
86 
87 /*
88  * fd.io coding-style-patch-verification: ON
89  *
90  * Local Variables:
91  * eval: (c-set-style "gnu")
92  * End:
93  */
static clib_error_t * set_interface_feature_gso_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: cli.c:24
vnet_main_t * vnet_get_main(void)
Definition: misc.c:46
int vnet_sw_interface_gso_enable_disable(u32 sw_if_index, u8 enable)
Definition: gso.c:27
uword unformat_user(unformat_input_t *input, unformat_function_t *func,...)
Definition: unformat.c:989
vlib_main_t * vm
Definition: in2out_ed.c:1580
unformat_function_t unformat_vnet_sw_interface
unsigned char u8
Definition: types.h:56
#define clib_error_return(e, args...)
Definition: error.h:99
unsigned int u32
Definition: types.h:88
unformat_function_t unformat_line_input
Definition: format.h:282
Definition: cJSON.c:84
struct _unformat_input_t unformat_input_t
#define UNFORMAT_END_OF_INPUT
Definition: format.h:144
#define VLIB_CLI_COMMAND(x,...)
Definition: cli.h:158
#define unformat_parse_error(input)
Definition: format.h:268
static void unformat_free(unformat_input_t *i)
Definition: format.h:162
vl_api_interface_index_t sw_if_index
Definition: wireguard.api:34
uword unformat(unformat_input_t *i, const char *fmt,...)
Definition: unformat.c:978
static uword unformat_check_input(unformat_input_t *i)
Definition: format.h:170