blob: a6953bd2687c91623ea88b879b843a24717172a2 [file] [log] [blame]
Klement Sekera73884482017-02-23 09:26:30 +01001/*
2 * Copyright (c) 2011-2016 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 * @file
17 * @brief BFD CLI implementation
18 */
19
20#include <vlib/vlib.h>
21#include <vlib/cli.h>
22#include <vppinfra/format.h>
Gabriel Gannebeb85cc2017-11-07 14:24:56 +010023#include <vppinfra/warnings.h>
Klement Sekera73884482017-02-23 09:26:30 +010024#include <vnet/api_errno.h>
25#include <vnet/ip/format.h>
26#include <vnet/bfd/bfd_api.h>
27#include <vnet/bfd/bfd_main.h>
28
29static u8 *
30format_bfd_session_cli (u8 * s, va_list * args)
31{
Klement Sekerae50e8562017-04-04 16:19:48 +020032 vlib_main_t *vm = va_arg (*args, vlib_main_t *);
Klement Sekera73884482017-02-23 09:26:30 +010033 bfd_session_t *bs = va_arg (*args, bfd_session_t *);
34 switch (bs->transport)
35 {
36 case BFD_TRANSPORT_UDP4:
37 s = format (s, "%=10u %-32s %20U %20U\n", bs->bs_idx, "IPv4 address",
38 format_ip4_address, bs->udp.key.local_addr.ip4.as_u8,
39 format_ip4_address, bs->udp.key.peer_addr.ip4.as_u8);
40 break;
41 case BFD_TRANSPORT_UDP6:
42 s = format (s, "%=10u %-32s %20U %20U\n", bs->bs_idx, "IPv6 address",
43 format_ip6_address, &bs->udp.key.local_addr.ip6,
44 format_ip6_address, &bs->udp.key.peer_addr.ip6);
45 break;
46 }
47 s = format (s, "%10s %-32s %20s %20s\n", "", "Session state",
48 bfd_state_string (bs->local_state),
49 bfd_state_string (bs->remote_state));
50 s = format (s, "%10s %-32s %20s %20s\n", "", "Diagnostic code",
51 bfd_diag_code_string (bs->local_diag),
52 bfd_diag_code_string (bs->remote_diag));
53 s = format (s, "%10s %-32s %20u %20u\n", "", "Detect multiplier",
54 bs->local_detect_mult, bs->remote_detect_mult);
Klement Sekerae50e8562017-04-04 16:19:48 +020055 s = format (s, "%10s %-32s %20u %20llu\n", "",
Klement Sekera73884482017-02-23 09:26:30 +010056 "Required Min Rx Interval (usec)",
57 bs->config_required_min_rx_usec, bs->remote_min_rx_usec);
58 s = format (s, "%10s %-32s %20u %20u\n", "",
59 "Desired Min Tx Interval (usec)",
Klement Sekeraa3167442020-02-10 11:49:52 +000060 bs->config_desired_min_tx_usec,
61 bfd_nsec_to_usec (bs->remote_desired_min_tx_nsec));
Klement Sekera73884482017-02-23 09:26:30 +010062 s =
63 format (s, "%10s %-32s %20u\n", "", "Transmit interval",
Klement Sekeraa3167442020-02-10 11:49:52 +000064 bfd_nsec_to_usec (bs->transmit_interval_nsec));
Klement Sekerae50e8562017-04-04 16:19:48 +020065 u64 now = clib_cpu_time_now ();
66 u8 *tmp = NULL;
Klement Sekeraa3167442020-02-10 11:49:52 +000067 if (bs->last_tx_nsec > 0)
Klement Sekerae50e8562017-04-04 16:19:48 +020068 {
Klement Sekeraa3167442020-02-10 11:49:52 +000069 tmp = format (tmp, "%.2fs ago", (now - bs->last_tx_nsec) *
Klement Sekerae50e8562017-04-04 16:19:48 +020070 vm->clib_time.seconds_per_clock);
71 s = format (s, "%10s %-32s %20v\n", "", "Last control frame tx", tmp);
72 vec_reset_length (tmp);
73 }
Klement Sekeraa3167442020-02-10 11:49:52 +000074 if (bs->last_rx_nsec)
Klement Sekerae50e8562017-04-04 16:19:48 +020075 {
Klement Sekeraa3167442020-02-10 11:49:52 +000076 tmp = format (tmp, "%.2fs ago", (now - bs->last_rx_nsec) *
Klement Sekerae50e8562017-04-04 16:19:48 +020077 vm->clib_time.seconds_per_clock);
78 s = format (s, "%10s %-32s %20v\n", "", "Last control frame rx", tmp);
79 vec_reset_length (tmp);
80 }
Klement Sekera73884482017-02-23 09:26:30 +010081 s =
Klement Sekerae50e8562017-04-04 16:19:48 +020082 format (s, "%10s %-32s %20u %20llu\n", "", "Min Echo Rx Interval (usec)",
83 1, bs->remote_min_echo_rx_usec);
84 if (bs->echo)
85 {
Klement Sekeraa3167442020-02-10 11:49:52 +000086 s =
87 format (s, "%10s %-32s %20u\n", "", "Echo transmit interval",
88 bfd_nsec_to_usec (bs->echo_transmit_interval_nsec));
89 tmp =
90 format (tmp, "%.2fs ago",
91 (now -
92 bs->echo_last_tx_nsec) * vm->clib_time.seconds_per_clock);
Klement Sekerae50e8562017-04-04 16:19:48 +020093 s = format (s, "%10s %-32s %20v\n", "", "Last echo frame tx", tmp);
94 vec_reset_length (tmp);
95 tmp = format (tmp, "%.6fs",
Klement Sekeraa3167442020-02-10 11:49:52 +000096 (bs->echo_last_rx_nsec - bs->echo_last_tx_nsec) *
Klement Sekerae50e8562017-04-04 16:19:48 +020097 vm->clib_time.seconds_per_clock);
98 s =
99 format (s, "%10s %-32s %20v\n", "", "Last echo frame roundtrip time",
100 tmp);
101 }
102 vec_free (tmp);
103 tmp = NULL;
104 s = format (s, "%10s %-32s %20s %20s\n", "", "Demand mode", "no",
105 bs->remote_demand ? "yes" : "no");
106 s = format (s, "%10s %-32s %20s\n", "", "Poll state",
107 bfd_poll_state_string (bs->poll_state));
Klement Sekera73884482017-02-23 09:26:30 +0100108 if (bs->auth.curr_key)
109 {
110 s = format (s, "%10s %-32s %20u\n", "", "Authentication config key ID",
111 bs->auth.curr_key->conf_key_id);
112 s = format (s, "%10s %-32s %20u\n", "", "Authentication BFD key ID",
113 bs->auth.curr_bfd_key_id);
Klement Sekerae50e8562017-04-04 16:19:48 +0200114 s = format (s, "%10s %-32s %20u %20u\n", "", "Sequence number",
115 bs->auth.local_seq_number, bs->auth.remote_seq_number);
Klement Sekera73884482017-02-23 09:26:30 +0100116 }
117 return s;
118}
119
120static clib_error_t *
121show_bfd (vlib_main_t * vm, unformat_input_t * input,
122 CLIB_UNUSED (vlib_cli_command_t * lmd))
123{
124 bfd_main_t *bm = &bfd_main;
125 bfd_session_t *bs = NULL;
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100126 unformat_input_t _line_input, *line_input = &_line_input;
Klement Sekera73884482017-02-23 09:26:30 +0100127
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100128 /* Get a line of input. */
129 if (!unformat_user (input, unformat_line_input, line_input))
130 return 0;
131
132 if (unformat (line_input, "keys"))
Klement Sekera73884482017-02-23 09:26:30 +0100133 {
134 bfd_auth_key_t *key = NULL;
135 u8 *s = format (NULL, "%=10s %=25s %=10s\n", "Configuration Key ID",
136 "Type", "Use Count");
137 /* *INDENT-OFF* */
138 pool_foreach (key, bm->auth_keys, {
139 s = format (s, "%10u %-25s %10u\n", key->conf_key_id,
140 bfd_auth_type_str (key->auth_type), key->use_count);
141 });
142 /* *INDENT-ON* */
143 vlib_cli_output (vm, "%v\n", s);
Klement Sekerae50e8562017-04-04 16:19:48 +0200144 vec_free (s);
Klement Sekera73884482017-02-23 09:26:30 +0100145 vlib_cli_output (vm, "Number of configured BFD keys: %lu\n",
146 (u64) pool_elts (bm->auth_keys));
147 }
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100148 else if (unformat (line_input, "sessions"))
Klement Sekera73884482017-02-23 09:26:30 +0100149 {
150 u8 *s = format (NULL, "%=10s %=32s %=20s %=20s\n", "Index", "Property",
151 "Local value", "Remote value");
152 /* *INDENT-OFF* */
Klement Sekerae50e8562017-04-04 16:19:48 +0200153 pool_foreach (bs, bm->sessions, {
Klement Sekeraa3167442020-02-10 11:49:52 +0000154 s = format (s, "%U", format_bfd_session_cli, vm, bs);
Klement Sekerae50e8562017-04-04 16:19:48 +0200155 });
Klement Sekera73884482017-02-23 09:26:30 +0100156 /* *INDENT-ON* */
157 vlib_cli_output (vm, "%v", s);
158 vec_free (s);
159 vlib_cli_output (vm, "Number of configured BFD sessions: %lu\n",
160 (u64) pool_elts (bm->sessions));
161 }
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100162 else if (unformat (line_input, "echo-source"))
Klement Sekera73884482017-02-23 09:26:30 +0100163 {
164 int is_set;
165 u32 sw_if_index;
166 int have_usable_ip4;
167 ip4_address_t ip4;
168 int have_usable_ip6;
169 ip6_address_t ip6;
170 bfd_udp_get_echo_source (&is_set, &sw_if_index, &have_usable_ip4, &ip4,
171 &have_usable_ip6, &ip6);
172 if (is_set)
173 {
174 vnet_sw_interface_t *sw_if =
Dave Barach3940de32019-07-23 16:28:36 -0400175 vnet_get_sw_interface_or_null (&vnet_main, sw_if_index);
Klement Sekera73884482017-02-23 09:26:30 +0100176 vnet_hw_interface_t *hw_if =
177 vnet_get_hw_interface (&vnet_main, sw_if->hw_if_index);
178 u8 *s = format (NULL, "UDP echo source is: %v\n", hw_if->name);
179 s = format (s, "IPv4 address usable as echo source: ");
180 if (have_usable_ip4)
181 {
182 s = format (s, "%U\n", format_ip4_address, &ip4);
183 }
184 else
185 {
186 s = format (s, "none\n");
187 }
188 s = format (s, "IPv6 address usable as echo source: ");
189 if (have_usable_ip6)
190 {
191 s = format (s, "%U\n", format_ip6_address, &ip6);
192 }
193 else
194 {
195 s = format (s, "none\n");
196 }
197 vlib_cli_output (vm, "%v", s);
198 vec_free (s);
199 }
200 else
201 {
202 vlib_cli_output (vm, "UDP echo source is not set.\n");
203 }
204 }
205 else
206 {
207 vlib_cli_output (vm, "Number of configured BFD sessions: %lu\n",
208 (u64) pool_elts (bm->sessions));
209 vlib_cli_output (vm, "Number of configured BFD keys: %lu\n",
210 (u64) pool_elts (bm->auth_keys));
211 }
212 return 0;
213}
214
215/* *INDENT-OFF* */
216VLIB_CLI_COMMAND (show_bfd_command, static) = {
217 .path = "show bfd",
218 .short_help = "show bfd [keys|sessions|echo-source]",
219 .function = show_bfd,
220};
221/* *INDENT-ON* */
222
Klement Sekera73884482017-02-23 09:26:30 +0100223static clib_error_t *
224bfd_cli_key_add (vlib_main_t * vm, unformat_input_t * input,
225 CLIB_UNUSED (vlib_cli_command_t * lmd))
226{
227 clib_error_t *ret = NULL;
228 int have_key_id = 0;
229 u32 key_id = 0;
230 u8 *vec_auth_type = NULL;
231 bfd_auth_type_e auth_type = BFD_AUTH_TYPE_reserved;
232 u8 *secret = NULL;
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100233 unformat_input_t _line_input, *line_input = &_line_input;
Klement Sekera73884482017-02-23 09:26:30 +0100234 static const u8 keyed_sha1[] = "keyed-sha1";
235 static const u8 meticulous_keyed_sha1[] = "meticulous-keyed-sha1";
236
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100237 /* Get a line of input. */
238 if (!unformat_user (input, unformat_line_input, line_input))
239 return 0;
240
241 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
Klement Sekera73884482017-02-23 09:26:30 +0100242 {
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100243 if (unformat (line_input, "conf-key-id %u", &key_id))
Klement Sekera73884482017-02-23 09:26:30 +0100244 {
245 have_key_id = 1;
246 }
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100247 else if (unformat (line_input, "type %U", unformat_token, "a-zA-Z0-9-",
Klement Sekera73884482017-02-23 09:26:30 +0100248 &vec_auth_type))
249 {
250 if (vec_len (vec_auth_type) == sizeof (keyed_sha1) - 1 &&
251 0 == memcmp (vec_auth_type, keyed_sha1,
252 sizeof (keyed_sha1) - 1))
253 {
254 auth_type = BFD_AUTH_TYPE_keyed_sha1;
255 }
256 else if (vec_len (vec_auth_type) ==
257 sizeof (meticulous_keyed_sha1) - 1 &&
258 0 == memcmp (vec_auth_type, meticulous_keyed_sha1,
259 sizeof (meticulous_keyed_sha1) - 1))
260 {
261 auth_type = BFD_AUTH_TYPE_meticulous_keyed_sha1;
262 }
263 else
264 {
265 ret = clib_error_return (0, "invalid type `%v'", vec_auth_type);
266 goto out;
267 }
268 }
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100269 else
270 if (unformat (line_input, "secret %U", unformat_hex_string, &secret))
Klement Sekera73884482017-02-23 09:26:30 +0100271 {
272 /* nothing to do here */
273 }
274 else
275 {
276 ret = clib_error_return (0, "Unknown input `%U'",
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100277 format_unformat_error, line_input);
Klement Sekera73884482017-02-23 09:26:30 +0100278 goto out;
279 }
280 }
281
282 if (!have_key_id)
283 {
284 ret =
285 clib_error_return (0, "required parameter missing: `conf-key-id'");
286 goto out;
287 }
288 if (!vec_auth_type)
289 {
290 ret = clib_error_return (0, "required parameter missing: `type'");
291 goto out;
292 }
293 if (!secret)
294 {
295 ret = clib_error_return (0, "required parameter missing: `secret'");
296 goto out;
297 }
298
299 vnet_api_error_t rv =
300 bfd_auth_set_key (key_id, auth_type, vec_len (secret), secret);
301 if (rv)
302 {
303 ret =
304 clib_error_return (0, "`bfd_auth_set_key' API call failed, rv=%d:%U",
305 (int) rv, format_vnet_api_errno, rv);
306 }
307
308out:
309 vec_free (vec_auth_type);
310 return ret;
311}
312
313/* *INDENT-OFF* */
314VLIB_CLI_COMMAND (bfd_cli_key_add_command, static) = {
315 .path = "bfd key set",
316 .short_help = "bfd key set"
317 " conf-key-id <id>"
318 " type <keyed-sha1|meticulous-keyed-sha1> "
319 " secret <secret>",
320 .function = bfd_cli_key_add,
321};
322/* *INDENT-ON* */
323
324static clib_error_t *
325bfd_cli_key_del (vlib_main_t * vm, unformat_input_t * input,
326 CLIB_UNUSED (vlib_cli_command_t * lmd))
327{
328 clib_error_t *ret = NULL;
329 u32 key_id = 0;
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100330 unformat_input_t _line_input, *line_input = &_line_input;
Klement Sekera73884482017-02-23 09:26:30 +0100331
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100332 /* Get a line of input. */
333 if (!unformat_user (input, unformat_line_input, line_input))
334 return 0;
335
336 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
Klement Sekera73884482017-02-23 09:26:30 +0100337 {
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100338 if (!unformat (line_input, "conf-key-id %u", &key_id))
Klement Sekera73884482017-02-23 09:26:30 +0100339 {
340 ret = clib_error_return (0, "Unknown input `%U'",
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100341 format_unformat_error, line_input);
Klement Sekera73884482017-02-23 09:26:30 +0100342 goto out;
343 }
344 }
345
346 vnet_api_error_t rv = bfd_auth_del_key (key_id);
347 if (rv)
348 {
349 ret =
350 clib_error_return (0, "`bfd_auth_del_key' API call failed, rv=%d:%U",
351 (int) rv, format_vnet_api_errno, rv);
352 }
353
354out:
355 return ret;
356}
357
358/* *INDENT-OFF* */
359VLIB_CLI_COMMAND (bfd_cli_key_del_command, static) = {
360 .path = "bfd key del",
361 .short_help = "bfd key del conf-key-id <id>",
362 .function = bfd_cli_key_del,
363};
364/* *INDENT-ON* */
365
366#define INTERFACE_STR "interface"
367#define LOCAL_ADDR_STR "local-addr"
368#define PEER_ADDR_STR "peer-addr"
369#define CONF_KEY_ID_STR "conf-key-id"
370#define BFD_KEY_ID_STR "bfd-key-id"
371#define DESIRED_MIN_TX_STR "desired-min-tx"
372#define REQUIRED_MIN_RX_STR "required-min-rx"
373#define DETECT_MULT_STR "detect-mult"
374#define ADMIN_STR "admin"
375#define DELAYED_STR "delayed"
376
377static const unsigned mandatory = 1;
378static const unsigned optional = 0;
379
380#define DECLARE(t, n, s, r, ...) \
381 int have_##n = 0; \
382 t n;
383
384#define UNFORMAT(t, n, s, r, ...) \
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100385 if (unformat (line_input, s " " __VA_ARGS__, &n)) \
Klement Sekera73884482017-02-23 09:26:30 +0100386 { \
387 something_parsed = 1; \
388 have_##n = 1; \
389 }
390
391#define CHECK_MANDATORY(t, n, s, r, ...) \
Gabriel Gannebeb85cc2017-11-07 14:24:56 +0100392WARN_OFF(tautological-compare) \
Klement Sekera73884482017-02-23 09:26:30 +0100393 if (mandatory == r && !have_##n) \
394 { \
Gabriel Gannebeb85cc2017-11-07 14:24:56 +0100395 WARN_ON(tautological-compare) \
Klement Sekerae50e8562017-04-04 16:19:48 +0200396 ret = clib_error_return (0, "Required parameter `%s' missing.", s); \
Klement Sekera73884482017-02-23 09:26:30 +0100397 goto out; \
398 }
399
400static clib_error_t *
401bfd_cli_udp_session_add (vlib_main_t * vm, unformat_input_t * input,
402 CLIB_UNUSED (vlib_cli_command_t * lmd))
403{
404 clib_error_t *ret = NULL;
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100405 unformat_input_t _line_input, *line_input = &_line_input;
Klement Sekera73884482017-02-23 09:26:30 +0100406#define foreach_bfd_cli_udp_session_add_cli_param(F) \
407 F (u32, sw_if_index, INTERFACE_STR, mandatory, "%U", \
408 unformat_vnet_sw_interface, &vnet_main) \
409 F (ip46_address_t, local_addr, LOCAL_ADDR_STR, mandatory, "%U", \
410 unformat_ip46_address) \
411 F (ip46_address_t, peer_addr, PEER_ADDR_STR, mandatory, "%U", \
412 unformat_ip46_address) \
413 F (u32, desired_min_tx, DESIRED_MIN_TX_STR, mandatory, "%u") \
414 F (u32, required_min_rx, REQUIRED_MIN_RX_STR, mandatory, "%u") \
415 F (u32, detect_mult, DETECT_MULT_STR, mandatory, "%u") \
416 F (u32, conf_key_id, CONF_KEY_ID_STR, optional, "%u") \
417 F (u32, bfd_key_id, BFD_KEY_ID_STR, optional, "%u")
418
419 foreach_bfd_cli_udp_session_add_cli_param (DECLARE);
420
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100421 /* Get a line of input. */
422 if (!unformat_user (input, unformat_line_input, line_input))
423 return 0;
424
425 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
Klement Sekera73884482017-02-23 09:26:30 +0100426 {
427 int something_parsed = 0;
428 foreach_bfd_cli_udp_session_add_cli_param (UNFORMAT);
429
430 if (!something_parsed)
431 {
432 ret = clib_error_return (0, "Unknown input `%U'",
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100433 format_unformat_error, line_input);
Klement Sekera73884482017-02-23 09:26:30 +0100434 goto out;
435 }
436 }
437
438 foreach_bfd_cli_udp_session_add_cli_param (CHECK_MANDATORY);
439
440 if (1 == have_conf_key_id + have_bfd_key_id)
441 {
442 ret = clib_error_return (0, "Incompatible parameter combination, `%s' "
443 "and `%s' must be either both specified or none",
444 CONF_KEY_ID_STR, BFD_KEY_ID_STR);
445 goto out;
446 }
447
448 if (detect_mult > 255)
449 {
450 ret = clib_error_return (0, "%s value `%u' out of range <1,255>",
451 DETECT_MULT_STR, detect_mult);
452 goto out;
453 }
454
455 if (have_bfd_key_id && bfd_key_id > 255)
456 {
457 ret = clib_error_return (0, "%s value `%u' out of range <1,255>",
458 BFD_KEY_ID_STR, bfd_key_id);
459 goto out;
460 }
461
462 vnet_api_error_t rv =
463 bfd_udp_add_session (sw_if_index, &local_addr, &peer_addr, desired_min_tx,
464 required_min_rx,
465 detect_mult, have_conf_key_id, conf_key_id,
466 bfd_key_id);
467 if (rv)
468 {
469 ret =
470 clib_error_return (0,
471 "`bfd_add_add_session' API call failed, rv=%d:%U",
472 (int) rv, format_vnet_api_errno, rv);
473 goto out;
474 }
475
476out:
477 return ret;
478}
479
480/* *INDENT-OFF* */
481VLIB_CLI_COMMAND (bfd_cli_udp_session_add_command, static) = {
482 .path = "bfd udp session add",
483 .short_help = "bfd udp session add"
484 " interface <interface>"
485 " local-addr <local-address>"
486 " peer-addr <peer-address>"
487 " desired-min-tx <desired min tx interval>"
488 " required-min-rx <required min rx interval>"
489 " detect-mult <detect multiplier> "
490 "["
491 " conf-key-id <config key ID>"
492 " bfd-key-id <BFD key ID>"
493 "]",
494 .function = bfd_cli_udp_session_add,
495};
496/* *INDENT-ON* */
497
498static clib_error_t *
499bfd_cli_udp_session_mod (vlib_main_t * vm, unformat_input_t * input,
500 CLIB_UNUSED (vlib_cli_command_t * lmd))
501{
502 clib_error_t *ret = NULL;
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100503 unformat_input_t _line_input, *line_input = &_line_input;
Klement Sekera73884482017-02-23 09:26:30 +0100504#define foreach_bfd_cli_udp_session_mod_cli_param(F) \
505 F (u32, sw_if_index, INTERFACE_STR, mandatory, "%U", \
506 unformat_vnet_sw_interface, &vnet_main) \
507 F (ip46_address_t, local_addr, LOCAL_ADDR_STR, mandatory, "%U", \
508 unformat_ip46_address) \
509 F (ip46_address_t, peer_addr, PEER_ADDR_STR, mandatory, "%U", \
510 unformat_ip46_address) \
511 F (u32, desired_min_tx, DESIRED_MIN_TX_STR, mandatory, "%u") \
512 F (u32, required_min_rx, REQUIRED_MIN_RX_STR, mandatory, "%u") \
513 F (u32, detect_mult, DETECT_MULT_STR, mandatory, "%u")
514
515 foreach_bfd_cli_udp_session_mod_cli_param (DECLARE);
516
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100517 /* Get a line of input. */
518 if (!unformat_user (input, unformat_line_input, line_input))
519 return 0;
520
521 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
Klement Sekera73884482017-02-23 09:26:30 +0100522 {
523 int something_parsed = 0;
524 foreach_bfd_cli_udp_session_mod_cli_param (UNFORMAT);
525
526 if (!something_parsed)
527 {
528 ret = clib_error_return (0, "Unknown input `%U'",
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100529 format_unformat_error, line_input);
Klement Sekera73884482017-02-23 09:26:30 +0100530 goto out;
531 }
532 }
533
534 foreach_bfd_cli_udp_session_mod_cli_param (CHECK_MANDATORY);
535
536 if (detect_mult > 255)
537 {
538 ret = clib_error_return (0, "%s value `%u' out of range <1,255>",
539 DETECT_MULT_STR, detect_mult);
540 goto out;
541 }
542
543 vnet_api_error_t rv =
544 bfd_udp_mod_session (sw_if_index, &local_addr, &peer_addr,
545 desired_min_tx, required_min_rx, detect_mult);
546 if (rv)
547 {
548 ret =
549 clib_error_return (0,
550 "`bfd_udp_mod_session' API call failed, rv=%d:%U",
551 (int) rv, format_vnet_api_errno, rv);
552 goto out;
553 }
554
555out:
556 return ret;
557}
558
559/* *INDENT-OFF* */
560VLIB_CLI_COMMAND (bfd_cli_udp_session_mod_command, static) = {
561 .path = "bfd udp session mod",
562 .short_help = "bfd udp session mod interface"
563 " <interface> local-addr"
564 " <local-address> peer-addr"
565 " <peer-address> desired-min-tx"
566 " <desired min tx interval> required-min-rx"
567 " <required min rx interval> detect-mult"
568 " <detect multiplier> ",
569 .function = bfd_cli_udp_session_mod,
570};
571/* *INDENT-ON* */
572
573static clib_error_t *
574bfd_cli_udp_session_del (vlib_main_t * vm, unformat_input_t * input,
575 CLIB_UNUSED (vlib_cli_command_t * lmd))
576{
577 clib_error_t *ret = NULL;
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100578 unformat_input_t _line_input, *line_input = &_line_input;
Klement Sekera73884482017-02-23 09:26:30 +0100579#define foreach_bfd_cli_udp_session_del_cli_param(F) \
580 F (u32, sw_if_index, INTERFACE_STR, mandatory, "%U", \
581 unformat_vnet_sw_interface, &vnet_main) \
582 F (ip46_address_t, local_addr, LOCAL_ADDR_STR, mandatory, "%U", \
583 unformat_ip46_address) \
584 F (ip46_address_t, peer_addr, PEER_ADDR_STR, mandatory, "%U", \
585 unformat_ip46_address)
586
587 foreach_bfd_cli_udp_session_del_cli_param (DECLARE);
588
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100589 /* Get a line of input. */
590 if (!unformat_user (input, unformat_line_input, line_input))
591 return 0;
592
593 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
Klement Sekera73884482017-02-23 09:26:30 +0100594 {
595 int something_parsed = 0;
596 foreach_bfd_cli_udp_session_del_cli_param (UNFORMAT);
597
598 if (!something_parsed)
599 {
600 ret = clib_error_return (0, "Unknown input `%U'",
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100601 format_unformat_error, line_input);
Klement Sekera73884482017-02-23 09:26:30 +0100602 goto out;
603 }
604 }
605
606 foreach_bfd_cli_udp_session_del_cli_param (CHECK_MANDATORY);
607
608 vnet_api_error_t rv =
609 bfd_udp_del_session (sw_if_index, &local_addr, &peer_addr);
610 if (rv)
611 {
612 ret =
613 clib_error_return (0,
614 "`bfd_udp_del_session' API call failed, rv=%d:%U",
615 (int) rv, format_vnet_api_errno, rv);
616 goto out;
617 }
618
619out:
620 return ret;
621}
622
623/* *INDENT-OFF* */
624VLIB_CLI_COMMAND (bfd_cli_udp_session_del_command, static) = {
625 .path = "bfd udp session del",
626 .short_help = "bfd udp session del interface"
627 " <interface> local-addr"
628 " <local-address> peer-addr"
629 "<peer-address> ",
630 .function = bfd_cli_udp_session_del,
631};
632/* *INDENT-ON* */
633
634static clib_error_t *
635bfd_cli_udp_session_set_flags (vlib_main_t * vm, unformat_input_t * input,
636 CLIB_UNUSED (vlib_cli_command_t * lmd))
637{
638 clib_error_t *ret = NULL;
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100639 unformat_input_t _line_input, *line_input = &_line_input;
Klement Sekera73884482017-02-23 09:26:30 +0100640#define foreach_bfd_cli_udp_session_set_flags_cli_param(F) \
641 F (u32, sw_if_index, INTERFACE_STR, mandatory, "%U", \
642 unformat_vnet_sw_interface, &vnet_main) \
643 F (ip46_address_t, local_addr, LOCAL_ADDR_STR, mandatory, "%U", \
644 unformat_ip46_address) \
645 F (ip46_address_t, peer_addr, PEER_ADDR_STR, mandatory, "%U", \
646 unformat_ip46_address) \
647 F (u8 *, admin_up_down_token, ADMIN_STR, mandatory, "%v", \
648 &admin_up_down_token)
649
650 foreach_bfd_cli_udp_session_set_flags_cli_param (DECLARE);
651
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100652 /* Get a line of input. */
653 if (!unformat_user (input, unformat_line_input, line_input))
654 return 0;
655
656 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
Klement Sekera73884482017-02-23 09:26:30 +0100657 {
658 int something_parsed = 0;
659 foreach_bfd_cli_udp_session_set_flags_cli_param (UNFORMAT);
660
661 if (!something_parsed)
662 {
663 ret = clib_error_return (0, "Unknown input `%U'",
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100664 format_unformat_error, line_input);
Klement Sekera73884482017-02-23 09:26:30 +0100665 goto out;
666 }
667 }
668
669 foreach_bfd_cli_udp_session_set_flags_cli_param (CHECK_MANDATORY);
670
671 u8 admin_up_down;
672 static const char up[] = "up";
673 static const char down[] = "down";
674 if (!memcmp (admin_up_down_token, up, sizeof (up) - 1))
675 {
676 admin_up_down = 1;
677 }
678 else if (!memcmp (admin_up_down_token, down, sizeof (down) - 1))
679 {
680 admin_up_down = 0;
681 }
682 else
683 {
684 ret =
685 clib_error_return (0, "Unrecognized value for `%s' parameter: `%v'",
686 ADMIN_STR, admin_up_down_token);
687 goto out;
688 }
Klement Sekeraa3167442020-02-10 11:49:52 +0000689 vnet_api_error_t rv =
690 bfd_udp_session_set_flags (vm, sw_if_index, &local_addr,
691 &peer_addr, admin_up_down);
Klement Sekera73884482017-02-23 09:26:30 +0100692 if (rv)
693 {
694 ret =
695 clib_error_return (0,
696 "`bfd_udp_session_set_flags' API call failed, rv=%d:%U",
697 (int) rv, format_vnet_api_errno, rv);
698 goto out;
699 }
700
701out:
702 return ret;
703}
704
705/* *INDENT-OFF* */
706VLIB_CLI_COMMAND (bfd_cli_udp_session_set_flags_command, static) = {
707 .path = "bfd udp session set-flags",
708 .short_help = "bfd udp session set-flags"
709 " interface <interface>"
710 " local-addr <local-address>"
711 " peer-addr <peer-address>"
712 " admin <up|down>",
713 .function = bfd_cli_udp_session_set_flags,
714};
715/* *INDENT-ON* */
716
717static clib_error_t *
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100718bfd_cli_udp_session_auth_activate (vlib_main_t * vm,
719 unformat_input_t * input,
Klement Sekera73884482017-02-23 09:26:30 +0100720 CLIB_UNUSED (vlib_cli_command_t * lmd))
721{
722 clib_error_t *ret = NULL;
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100723 unformat_input_t _line_input, *line_input = &_line_input;
Klement Sekera73884482017-02-23 09:26:30 +0100724#define foreach_bfd_cli_udp_session_auth_activate_cli_param(F) \
725 F (u32, sw_if_index, INTERFACE_STR, mandatory, "%U", \
726 unformat_vnet_sw_interface, &vnet_main) \
727 F (ip46_address_t, local_addr, LOCAL_ADDR_STR, mandatory, "%U", \
728 unformat_ip46_address) \
729 F (ip46_address_t, peer_addr, PEER_ADDR_STR, mandatory, "%U", \
730 unformat_ip46_address) \
731 F (u8 *, delayed_token, DELAYED_STR, optional, "%v") \
732 F (u32, conf_key_id, CONF_KEY_ID_STR, mandatory, "%u") \
733 F (u32, bfd_key_id, BFD_KEY_ID_STR, mandatory, "%u")
734
735 foreach_bfd_cli_udp_session_auth_activate_cli_param (DECLARE);
736
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100737 /* Get a line of input. */
738 if (!unformat_user (input, unformat_line_input, line_input))
739 return 0;
740
741 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
Klement Sekera73884482017-02-23 09:26:30 +0100742 {
743 int something_parsed = 0;
744 foreach_bfd_cli_udp_session_auth_activate_cli_param (UNFORMAT);
745
746 if (!something_parsed)
747 {
748 ret = clib_error_return (0, "Unknown input `%U'",
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100749 format_unformat_error, line_input);
Klement Sekera73884482017-02-23 09:26:30 +0100750 goto out;
751 }
752 }
753
754 foreach_bfd_cli_udp_session_auth_activate_cli_param (CHECK_MANDATORY);
755
756 u8 is_delayed = 0;
757 if (have_delayed_token)
758 {
759 static const char yes[] = "yes";
760 static const char no[] = "no";
761 if (!memcmp (delayed_token, yes, sizeof (yes) - 1))
762 {
763 is_delayed = 1;
764 }
765 else if (!memcmp (delayed_token, no, sizeof (no) - 1))
766 {
767 is_delayed = 0;
768 }
769 else
770 {
771 ret =
772 clib_error_return (0,
773 "Unrecognized value for `%s' parameter: `%v'",
774 DELAYED_STR, delayed_token);
775 goto out;
776 }
777 }
778
779 if (have_bfd_key_id && bfd_key_id > 255)
780 {
781 ret = clib_error_return (0, "%s value `%u' out of range <1,255>",
782 BFD_KEY_ID_STR, bfd_key_id);
783 goto out;
784 }
785
786 vnet_api_error_t rv =
787 bfd_udp_auth_activate (sw_if_index, &local_addr, &peer_addr, conf_key_id,
788 bfd_key_id, is_delayed);
789 if (rv)
790 {
791 ret =
792 clib_error_return (0,
793 "`bfd_udp_auth_activate' API call failed, rv=%d:%U",
794 (int) rv, format_vnet_api_errno, rv);
795 goto out;
796 }
797
798out:
799 return ret;
800}
801
802/* *INDENT-OFF* */
803VLIB_CLI_COMMAND (bfd_cli_udp_session_auth_activate_command, static) = {
804 .path = "bfd udp session auth activate",
805 .short_help = "bfd udp session auth activate"
806 " interface <interface>"
807 " local-addr <local-address>"
808 " peer-addr <peer-address>"
809 " conf-key-id <config key ID>"
810 " bfd-key-id <BFD key ID>"
Klement Sekerab16bfe32017-02-28 11:56:48 +0100811 " [ delayed <yes|no> ]",
Klement Sekera73884482017-02-23 09:26:30 +0100812 .function = bfd_cli_udp_session_auth_activate,
813};
814
815static clib_error_t *
816bfd_cli_udp_session_auth_deactivate (vlib_main_t *vm, unformat_input_t *input,
817 CLIB_UNUSED (vlib_cli_command_t *lmd))
818{
819 clib_error_t *ret = NULL;
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100820 unformat_input_t _line_input, *line_input = &_line_input;
Klement Sekera73884482017-02-23 09:26:30 +0100821#define foreach_bfd_cli_udp_session_auth_deactivate_cli_param(F) \
822 F (u32, sw_if_index, INTERFACE_STR, mandatory, "%U", \
823 unformat_vnet_sw_interface, &vnet_main) \
824 F (ip46_address_t, local_addr, LOCAL_ADDR_STR, mandatory, "%U", \
825 unformat_ip46_address) \
826 F (ip46_address_t, peer_addr, PEER_ADDR_STR, mandatory, "%U", \
827 unformat_ip46_address) \
828 F (u8 *, delayed_token, DELAYED_STR, optional, "%v")
829
830 foreach_bfd_cli_udp_session_auth_deactivate_cli_param (DECLARE);
831
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100832 /* Get a line of input. */
833 if (!unformat_user (input, unformat_line_input, line_input))
834 return 0;
835
836 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
Klement Sekera73884482017-02-23 09:26:30 +0100837 {
838 int something_parsed = 0;
839 foreach_bfd_cli_udp_session_auth_deactivate_cli_param (UNFORMAT);
840
841 if (!something_parsed)
842 {
843 ret = clib_error_return (0, "Unknown input `%U'",
844 format_unformat_error, input);
845 goto out;
846 }
847 }
848
849 foreach_bfd_cli_udp_session_auth_deactivate_cli_param (CHECK_MANDATORY);
850
851 u8 is_delayed = 0;
852 if (have_delayed_token)
853 {
854 static const char yes[] = "yes";
855 static const char no[] = "no";
856 if (!memcmp (delayed_token, yes, sizeof (yes) - 1))
857 {
858 is_delayed = 1;
859 }
860 else if (!memcmp (delayed_token, no, sizeof (no) - 1))
861 {
862 is_delayed = 0;
863 }
864 else
865 {
866 ret = clib_error_return (
867 0, "Unrecognized value for `%s' parameter: `%v'", DELAYED_STR,
868 delayed_token);
869 goto out;
870 }
871 }
872
873 vnet_api_error_t rv = bfd_udp_auth_deactivate (sw_if_index, &local_addr,
874 &peer_addr, is_delayed);
875 if (rv)
876 {
877 ret = clib_error_return (
878 0, "`bfd_udp_auth_deactivate' API call failed, rv=%d:%U", (int)rv,
879 format_vnet_api_errno, rv);
880 goto out;
881 }
882
883out:
884 return ret;
885}
886
887/* *INDENT-OFF* */
888VLIB_CLI_COMMAND (bfd_cli_udp_session_auth_deactivate_command, static) = {
889 .path = "bfd udp session auth deactivate",
890 .short_help = "bfd udp session auth deactivate"
891 " interface <interface>"
892 " local-addr <local-address>"
893 " peer-addr <peer-address>"
Klement Sekerab16bfe32017-02-28 11:56:48 +0100894 "[ delayed <yes|no> ]",
Klement Sekera73884482017-02-23 09:26:30 +0100895 .function = bfd_cli_udp_session_auth_deactivate,
896};
897/* *INDENT-ON* */
898
899static clib_error_t *
900bfd_cli_udp_set_echo_source (vlib_main_t * vm, unformat_input_t * input,
901 CLIB_UNUSED (vlib_cli_command_t * lmd))
902{
903 clib_error_t *ret = NULL;
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100904 unformat_input_t _line_input, *line_input = &_line_input;
Klement Sekera73884482017-02-23 09:26:30 +0100905#define foreach_bfd_cli_udp_set_echo_source_cli_param(F) \
906 F (u32, sw_if_index, INTERFACE_STR, mandatory, "%U", \
907 unformat_vnet_sw_interface, &vnet_main)
908
909 foreach_bfd_cli_udp_set_echo_source_cli_param (DECLARE);
910
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100911 /* Get a line of input. */
912 if (!unformat_user (input, unformat_line_input, line_input))
913 return 0;
914
915 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
Klement Sekera73884482017-02-23 09:26:30 +0100916 {
917 int something_parsed = 0;
918 foreach_bfd_cli_udp_set_echo_source_cli_param (UNFORMAT);
919
920 if (!something_parsed)
921 {
922 ret = clib_error_return (0, "Unknown input `%U'",
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100923 format_unformat_error, line_input);
Klement Sekera73884482017-02-23 09:26:30 +0100924 goto out;
925 }
926 }
927
928 foreach_bfd_cli_udp_set_echo_source_cli_param (CHECK_MANDATORY);
929
930 vnet_api_error_t rv = bfd_udp_set_echo_source (sw_if_index);
931 if (rv)
932 {
933 ret =
934 clib_error_return (0,
935 "`bfd_udp_set_echo_source' API call failed, rv=%d:%U",
936 (int) rv, format_vnet_api_errno, rv);
937 goto out;
938 }
939
940out:
941 return ret;
942}
943
944/* *INDENT-OFF* */
945VLIB_CLI_COMMAND (bfd_cli_udp_set_echo_source_cmd, static) = {
946 .path = "bfd udp echo-source set",
947 .short_help = "bfd udp echo-source set interface <interface>",
948 .function = bfd_cli_udp_set_echo_source,
949};
950/* *INDENT-ON* */
951
952static clib_error_t *
953bfd_cli_udp_del_echo_source (vlib_main_t * vm, unformat_input_t * input,
954 CLIB_UNUSED (vlib_cli_command_t * lmd))
955{
956 vnet_api_error_t rv = bfd_udp_del_echo_source ();
957 if (rv)
958 {
959 return clib_error_return (0,
960 "`bfd_udp_del_echo_source' API call failed, rv=%d:%U",
961 (int) rv, format_vnet_api_errno, rv);
962 }
963
964 return 0;
965}
966
967/* *INDENT-OFF* */
968VLIB_CLI_COMMAND (bfd_cli_udp_del_echo_source_cmd, static) = {
969 .path = "bfd udp echo-source del",
970 .short_help = "bfd udp echo-source del",
971 .function = bfd_cli_udp_del_echo_source,
972};
973/* *INDENT-ON* */
974
975/*
976 * fd.io coding-style-patch-verification: ON
977 *
978 * Local Variables:
979 * eval: (c-set-style "gnu")
980 * End:
981 */