FD.io VPP  v17.10-9-gd594711
Vector Packet Processing
pppoe_tap.c
Go to the documentation of this file.
1 /*
2  *------------------------------------------------------------------
3  * Copyright (c) 2017 Intel 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 <pppoe/pppoe.h>
19 #include <vnet/unix/tapcli.h>
20 
21 static clib_error_t *
23  unformat_input_t * input,
24  vlib_cli_command_t * cmd)
25 {
26  unformat_input_t _line_input, *line_input = &_line_input;
27  pppoe_main_t *pem = &pppoe_main;
28  u8 is_add = 1;
29  u8 tap_if_index_set = 0;
30  u32 tap_if_index = 0;
31  clib_error_t *error = NULL;
32 
33  /* Get a line of input. */
34  if (!unformat_user (input, unformat_line_input, line_input))
35  return 0;
36 
37  while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
38  {
39  if (unformat (line_input, "del"))
40  {
41  is_add = 0;
42  }
43  else if (unformat (line_input, "tap-if-index %d", &tap_if_index))
44  tap_if_index_set = 1;
45  else
46  {
47  error = clib_error_return (0, "parse error: '%U'",
48  format_unformat_error, line_input);
49  goto done;
50  }
51  }
52 
53  if (tap_if_index_set == 0)
54  {
55  error = clib_error_return (0, "tap if index not specified");
56  goto done;
57  }
58 
59  if (is_add)
60  {
61  pem->tap_if_index = tap_if_index;
62  }
63  else
64  {
65  pem->tap_if_index = ~0;
66  }
67 
68 done:
69  unformat_free (line_input);
70 
71  return error;
72 }
73 
74 /* *INDENT-OFF* */
75 VLIB_CLI_COMMAND (create_pppoe_tap_cmd, static) =
76 {
77  .path = "create pppoe tap",
78  .short_help = "create pppoe tap if-name <intfc> [del]",
79  .function = pppoe_add_del_tap_command_fn,
80 };
81 /* *INDENT-ON* */
82 
83 /*
84  * fd.io coding-style-patch-verification: ON
85  *
86  * Local Variables:
87  * eval: (c-set-style "gnu")
88  * End:
89  */
pppoe_main_t pppoe_main
Definition: jvpp_pppoe.h:39
u32 tap_if_index
Definition: pppoe.h:163
#define NULL
Definition: clib.h:55
uword unformat_user(unformat_input_t *input, unformat_function_t *func,...)
Definition: unformat.c:983
static clib_error_t * pppoe_add_del_tap_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: pppoe_tap.c:22
TAPCLI definitions.
#define clib_error_return(e, args...)
Definition: error.h:99
unformat_function_t unformat_line_input
Definition: format.h:281
struct _unformat_input_t unformat_input_t
#define UNFORMAT_END_OF_INPUT
Definition: format.h:143
vlib_main_t * vm
Definition: buffer.c:283
#define VLIB_CLI_COMMAND(x,...)
Definition: cli.h:154
unsigned int u32
Definition: types.h:88
unsigned char u8
Definition: types.h:56
static void unformat_free(unformat_input_t *i)
Definition: format.h:161
u8 * format_unformat_error(u8 *s, va_list *va)
Definition: unformat.c:91
uword unformat(unformat_input_t *i, const char *fmt,...)
Definition: unformat.c:972
static uword unformat_check_input(unformat_input_t *i)
Definition: format.h:169