FD.io VPP  v21.10.1-2-g0a485f517
Vector Packet Processing
teib_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 <vnet/teib/teib.h>
17 
18 static clib_error_t *
20  unformat_input_t * input, vlib_cli_command_t * cmd)
21 {
22  unformat_input_t _line_input, *line_input = &_line_input;
26  clib_error_t *error = NULL;
27  int rv;
28 
29  sw_if_index = ~0;
30  nh_table_id = 0;
31 
32  /* Get a line of input. */
33  if (!unformat_user (input, unformat_line_input, line_input))
34  return 0;
35 
36  while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
37  {
38  if (unformat (line_input, "%U", unformat_vnet_sw_interface,
40  ;
41  else if (unformat (line_input, "peer %U", unformat_ip_address, &peer))
42  ;
43  else if (unformat (line_input, "nh-table-id %d", &nh_table_id))
44  ;
45  else if (unformat (line_input, "nh %U", unformat_ip_address, &nh))
46  ;
47  else
48  {
49  error = clib_error_return (0, "unknown input `%U'",
50  format_unformat_error, line_input);
51  goto done;
52  }
53  }
54 
55  if (~0 == sw_if_index)
56  {
57  error = clib_error_return (0, "interface required'",
58  format_unformat_error, line_input);
59  goto done;
60  }
61  if (ip_address_is_zero (&peer))
62  {
63  error = clib_error_return (0, "peer required'",
64  format_unformat_error, line_input);
65  goto done;
66  }
67  if (ip_address_is_zero (&nh))
68  {
69  error = clib_error_return (0, "next-hop required'",
70  format_unformat_error, line_input);
71  goto done;
72  }
73 
75 
76  if (rv)
77  {
78  error = clib_error_return_code (NULL, rv, 0, "TEIB error",
79  format_unformat_error, line_input);
80  }
81 
82 done:
83  unformat_free (line_input);
84 
85  return error;
86 }
87 
88 /* *INDENT-OFF* */
90  .path = "create teib",
91  .short_help = "create teib <interface> peer <addr> nh <addr> [nh-table-id <ID>]",
92  .function = teib_add,
93 };
94 /* *INDENT-ON* */
95 
96 static clib_error_t *
98  unformat_input_t * input, vlib_cli_command_t * cmd)
99 {
100  unformat_input_t _line_input, *line_input = &_line_input;
102  clib_error_t *error = NULL;
104  int rv;
105 
106  sw_if_index = ~0;
107 
108  /* Get a line of input. */
109  if (!unformat_user (input, unformat_line_input, line_input))
110  return 0;
111 
112  while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
113  {
114  if (unformat (line_input, "%U", unformat_vnet_sw_interface,
116  ;
117  else if (unformat (line_input, "peer %U", unformat_ip_address, &peer))
118  ;
119  else
120  {
121  error = clib_error_return (0, "unknown input `%U'",
122  format_unformat_error, line_input);
123  goto done;
124  }
125  }
126 
127  if (~0 == sw_if_index)
128  {
129  error = clib_error_return (0, "interface required'",
130  format_unformat_error, line_input);
131  }
132  if (ip_address_is_zero (&peer))
133  {
134  error = clib_error_return (0, "peer required'",
135  format_unformat_error, line_input);
136  goto done;
137  }
138 
140 
141  if (rv)
142  {
143  error = clib_error_return_code (NULL, rv, 0, "TEIB error",
144  format_unformat_error, line_input);
145  }
146 
147 done:
148  unformat_free (line_input);
149 
150  return error;
151 }
152 
153 /* *INDENT-OFF* */
155  .path = "delete teib",
156  .short_help = "delete teib <interface> peer <addr>",
157  .function = teib_del,
158 };
159 /* *INDENT-ON* */
160 
161 static walk_rc_t
163 {
164  vlib_cli_output (ctx, "%U", format_teib_entry, nei);
165 
166  return (WALK_CONTINUE);
167 }
168 
169 
170 static clib_error_t *
172  unformat_input_t * input, vlib_cli_command_t * cmd)
173 {
175  return (NULL);
176 }
177 
178 /* *INDENT-OFF* */
180  .path = "show teib",
181  .short_help = "show teib",
182  .function = teib_show,
183 };
184 /* *INDENT-ON* */
185 
186 /*
187  * fd.io coding-style-patch-verification: ON
188  *
189  * Local Variables:
190  * eval: (c-set-style "gnu")
191  * End:
192  */
ip_address
Definition: ip_types.h:79
unformat_user
uword unformat_user(unformat_input_t *input, unformat_function_t *func,...)
Definition: unformat.c:989
WALK_CONTINUE
@ WALK_CONTINUE
Definition: interface_funcs.h:174
unformat_line_input
unformat_function_t unformat_line_input
Definition: format.h:275
clib_error_return
#define clib_error_return(e, args...)
Definition: error.h:99
vlib_cli_command_t::path
char * path
Definition: cli.h:96
vm
vlib_main_t * vm
X-connect all packets from the HOST to the PHY.
Definition: nat44_ei.c:3047
teib_show_command
static vlib_cli_command_t teib_show_command
(constructor) VLIB_CLI_COMMAND (teib_show_command)
Definition: teib_cli.c:179
unformat_input_t
struct _unformat_input_t unformat_input_t
teib_entry_add
int teib_entry_add(u32 sw_if_index, const ip_address_t *peer, u32 nh_table_id, const ip_address_t *nh)
Create a new TEIB entry.
Definition: teib.c:200
error
Definition: cJSON.c:88
teib_add
static clib_error_t * teib_add(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: teib_cli.c:19
unformat
uword unformat(unformat_input_t *i, const char *fmt,...)
Definition: unformat.c:978
teib.h
unformat_ip_address
uword unformat_ip_address(unformat_input_t *input, va_list *args)
Definition: ip_types.c:41
clib_error_return_code
#define clib_error_return_code(e, code, flags, args...)
Definition: error.h:93
teib_create_command
static vlib_cli_command_t teib_create_command
(constructor) VLIB_CLI_COMMAND (teib_create_command)
Definition: teib_cli.c:89
unformat_free
static void unformat_free(unformat_input_t *i)
Definition: format.h:155
teib_show_one
static walk_rc_t teib_show_one(index_t nei, void *ctx)
Definition: teib_cli.c:162
vnet_get_main
vnet_main_t * vnet_get_main(void)
Definition: pnat_test_stubs.h:56
unformat_check_input
static uword unformat_check_input(unformat_input_t *i)
Definition: format.h:163
index_t
u32 index_t
A Data-Path Object is an object that represents actions that are applied to packets are they are swit...
Definition: dpo.h:43
peer
vl_api_address_t peer
Definition: teib.api:28
ip_address_initializer
#define ip_address_initializer
Definition: ip_types.h:88
format_teib_entry
u8 * format_teib_entry(u8 *s, va_list *args)
Definition: teib.c:294
format_unformat_error
u8 * format_unformat_error(u8 *s, va_list *va)
Definition: unformat.c:91
VLIB_CLI_COMMAND
#define VLIB_CLI_COMMAND(x,...)
Definition: cli.h:163
nh
vl_api_fib_path_nh_t nh
Definition: fib_types.api:126
vlib_cli_output
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
Definition: cli.c:716
ip_address_is_zero
bool ip_address_is_zero(const ip_address_t *ip)
Definition: ip_types.c:102
teib_del
static clib_error_t * teib_del(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: teib_cli.c:97
unformat_vnet_sw_interface
unformat_function_t unformat_vnet_sw_interface
Definition: interface_funcs.h:462
u32
unsigned int u32
Definition: types.h:88
ctx
long ctx[MAX_CONNS]
Definition: main.c:144
vlib_main_t
Definition: main.h:102
teib_entry_del
int teib_entry_del(u32 sw_if_index, const ip_address_t *peer)
Definition: teib.c:258
clib_error_t
Definition: clib_error.h:21
teib_walk
void teib_walk(teib_walk_cb_t fn, void *ctx)
Definition: teib.c:315
rv
int __clib_unused rv
Definition: application.c:491
nh_table_id
u32 nh_table_id
Definition: teib.api:30
vlib_cli_command_t
Definition: cli.h:92
sw_if_index
vl_api_interface_index_t sw_if_index
Definition: wireguard.api:34
teib_show
static clib_error_t * teib_show(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: teib_cli.c:171
teib_delete_command
static vlib_cli_command_t teib_delete_command
(constructor) VLIB_CLI_COMMAND (teib_delete_command)
Definition: teib_cli.c:154
walk_rc_t
enum walk_rc_t_ walk_rc_t
Walk return code.
UNFORMAT_END_OF_INPUT
#define UNFORMAT_END_OF_INPUT
Definition: format.h:137