FD.io VPP  v21.01.1
Vector Packet Processing
pppoe_cp.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 
20 int
21 pppoe_add_del_cp (u32 cp_if_index, u8 is_add)
22 {
23  pppoe_main_t *pem = &pppoe_main;
24 
25  if (cp_if_index == 0)
26  {
27  return ~0;
28  }
29 
30  vnet_feature_enable_disable ("device-input", "pppoe-input",
31  cp_if_index, is_add, 0, 0);
32 
33  if (is_add)
34  {
35  pem->cp_if_index = cp_if_index;
36  }
37  else
38  {
39  pem->cp_if_index = ~0;
40  }
41  return 0;
42 }
43 
44 static clib_error_t *
46  unformat_input_t * input,
47  vlib_cli_command_t * cmd)
48 {
49  unformat_input_t _line_input, *line_input = &_line_input;
50  pppoe_main_t *pem = &pppoe_main;
51  u8 is_add = 1;
52  u8 cp_if_index_set = 0;
53  u32 cp_if_index = 0;
54  clib_error_t *error = NULL;
55 
56  /* Get a line of input. */
57  if (!unformat_user (input, unformat_line_input, line_input))
58  return 0;
59 
60  while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
61  {
62  if (unformat (line_input, "del"))
63  {
64  is_add = 0;
65  }
66  else if (unformat (line_input, "cp-if-index %d", &cp_if_index))
67  cp_if_index_set = 1;
68  else
69  {
70  error = clib_error_return (0, "parse error: '%U'",
71  format_unformat_error, line_input);
72  goto done;
73  }
74  }
75 
76  if (cp_if_index_set == 0)
77  {
78  error = clib_error_return (0, "cp if index not specified");
79  goto done;
80  }
81 
82  vnet_feature_enable_disable ("device-input", "pppoe-input",
83  cp_if_index, is_add, 0, 0);
84 
85  if (is_add)
86  {
87  pem->cp_if_index = cp_if_index;
88  }
89  else
90  {
91  pem->cp_if_index = ~0;
92  }
93 
94 done:
95  unformat_free (line_input);
96 
97  return error;
98 }
99 
100 /* *INDENT-OFF* */
101 VLIB_CLI_COMMAND (create_pppoe_cp_cmd, static) =
102 {
103  .path = "create pppoe cp",
104  .short_help = "create pppoe cp-if-index <intfc> [del]",
105  .function = pppoe_add_del_cp_command_fn,
106 };
107 /* *INDENT-ON* */
108 
109 /*
110  * fd.io coding-style-patch-verification: ON
111  *
112  * Local Variables:
113  * eval: (c-set-style "gnu")
114  * End:
115  */
static clib_error_t * pppoe_add_del_cp_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: pppoe_cp.c:45
uword unformat_user(unformat_input_t *input, unformat_function_t *func,...)
Definition: unformat.c:989
vlib_main_t * vm
Definition: in2out_ed.c:1580
unsigned char u8
Definition: types.h:56
#define clib_error_return(e, args...)
Definition: error.h:99
unsigned int u32
Definition: types.h:88
int pppoe_add_del_cp(u32 cp_if_index, u8 is_add)
Definition: pppoe_cp.c:21
unformat_function_t unformat_line_input
Definition: format.h:282
u32 cp_if_index
Definition: pppoe.h:170
Definition: cJSON.c:84
struct _unformat_input_t unformat_input_t
pppoe_main_t pppoe_main
Definition: pppoe.c:38
#define UNFORMAT_END_OF_INPUT
Definition: format.h:144
#define VLIB_CLI_COMMAND(x,...)
Definition: cli.h:158
static void unformat_free(unformat_input_t *i)
Definition: format.h:162
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:978
int vnet_feature_enable_disable(const char *arc_name, const char *node_name, u32 sw_if_index, int enable_disable, void *feature_config, u32 n_feature_config_bytes)
Definition: feature.c:303
static uword unformat_check_input(unformat_input_t *i)
Definition: format.h:170