blob: 44e671c534e16365feca8067533f84188db55293 [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>
23#include <vnet/api_errno.h>
24#include <vnet/ip/format.h>
25#include <vnet/bfd/bfd_api.h>
26#include <vnet/bfd/bfd_main.h>
27
28static u8 *
29format_bfd_session_cli (u8 * s, va_list * args)
30{
Klement Sekerae50e8562017-04-04 16:19:48 +020031 vlib_main_t *vm = va_arg (*args, vlib_main_t *);
Klement Sekera73884482017-02-23 09:26:30 +010032 bfd_main_t *bm = va_arg (*args, bfd_main_t *);
33 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)",
60 bs->config_desired_min_tx_usec, bfd_clocks_to_usec (bm,
61 bs->remote_desired_min_tx_clocks));
62 s =
63 format (s, "%10s %-32s %20u\n", "", "Transmit interval",
64 bfd_clocks_to_usec (bm, bs->transmit_interval_clocks));
Klement Sekerae50e8562017-04-04 16:19:48 +020065 u64 now = clib_cpu_time_now ();
66 u8 *tmp = NULL;
67 if (bs->last_tx_clocks > 0)
68 {
69 tmp = format (tmp, "%.2fs ago", (now - bs->last_tx_clocks) *
70 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 }
74 if (bs->last_rx_clocks)
75 {
76 tmp = format (tmp, "%.2fs ago", (now - bs->last_rx_clocks) *
77 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 {
86 s = format (s, "%10s %-32s %20u\n", "", "Echo transmit interval",
87 bfd_clocks_to_usec (bm, bs->echo_transmit_interval_clocks));
88 tmp = format (tmp, "%.2fs ago", (now - bs->echo_last_tx_clocks) *
89 vm->clib_time.seconds_per_clock);
90 s = format (s, "%10s %-32s %20v\n", "", "Last echo frame tx", tmp);
91 vec_reset_length (tmp);
92 tmp = format (tmp, "%.6fs",
93 (bs->echo_last_rx_clocks - bs->echo_last_tx_clocks) *
94 vm->clib_time.seconds_per_clock);
95 s =
96 format (s, "%10s %-32s %20v\n", "", "Last echo frame roundtrip time",
97 tmp);
98 }
99 vec_free (tmp);
100 tmp = NULL;
101 s = format (s, "%10s %-32s %20s %20s\n", "", "Demand mode", "no",
102 bs->remote_demand ? "yes" : "no");
103 s = format (s, "%10s %-32s %20s\n", "", "Poll state",
104 bfd_poll_state_string (bs->poll_state));
Klement Sekera73884482017-02-23 09:26:30 +0100105 if (bs->auth.curr_key)
106 {
107 s = format (s, "%10s %-32s %20u\n", "", "Authentication config key ID",
108 bs->auth.curr_key->conf_key_id);
109 s = format (s, "%10s %-32s %20u\n", "", "Authentication BFD key ID",
110 bs->auth.curr_bfd_key_id);
Klement Sekerae50e8562017-04-04 16:19:48 +0200111 s = format (s, "%10s %-32s %20u %20u\n", "", "Sequence number",
112 bs->auth.local_seq_number, bs->auth.remote_seq_number);
Klement Sekera73884482017-02-23 09:26:30 +0100113 }
114 return s;
115}
116
117static clib_error_t *
118show_bfd (vlib_main_t * vm, unformat_input_t * input,
119 CLIB_UNUSED (vlib_cli_command_t * lmd))
120{
121 bfd_main_t *bm = &bfd_main;
122 bfd_session_t *bs = NULL;
123
124 if (unformat (input, "keys"))
125 {
126 bfd_auth_key_t *key = NULL;
127 u8 *s = format (NULL, "%=10s %=25s %=10s\n", "Configuration Key ID",
128 "Type", "Use Count");
129 /* *INDENT-OFF* */
130 pool_foreach (key, bm->auth_keys, {
131 s = format (s, "%10u %-25s %10u\n", key->conf_key_id,
132 bfd_auth_type_str (key->auth_type), key->use_count);
133 });
134 /* *INDENT-ON* */
135 vlib_cli_output (vm, "%v\n", s);
Klement Sekerae50e8562017-04-04 16:19:48 +0200136 vec_free (s);
Klement Sekera73884482017-02-23 09:26:30 +0100137 vlib_cli_output (vm, "Number of configured BFD keys: %lu\n",
138 (u64) pool_elts (bm->auth_keys));
139 }
140 else if (unformat (input, "sessions"))
141 {
142 u8 *s = format (NULL, "%=10s %=32s %=20s %=20s\n", "Index", "Property",
143 "Local value", "Remote value");
144 /* *INDENT-OFF* */
Klement Sekerae50e8562017-04-04 16:19:48 +0200145 pool_foreach (bs, bm->sessions, {
146 s = format (s, "%U", format_bfd_session_cli, vm, bm, bs);
147 });
Klement Sekera73884482017-02-23 09:26:30 +0100148 /* *INDENT-ON* */
149 vlib_cli_output (vm, "%v", s);
150 vec_free (s);
151 vlib_cli_output (vm, "Number of configured BFD sessions: %lu\n",
152 (u64) pool_elts (bm->sessions));
153 }
154 else if (unformat (input, "echo-source"))
155 {
156 int is_set;
157 u32 sw_if_index;
158 int have_usable_ip4;
159 ip4_address_t ip4;
160 int have_usable_ip6;
161 ip6_address_t ip6;
162 bfd_udp_get_echo_source (&is_set, &sw_if_index, &have_usable_ip4, &ip4,
163 &have_usable_ip6, &ip6);
164 if (is_set)
165 {
166 vnet_sw_interface_t *sw_if =
167 vnet_get_sw_interface_safe (&vnet_main, sw_if_index);
168 vnet_hw_interface_t *hw_if =
169 vnet_get_hw_interface (&vnet_main, sw_if->hw_if_index);
170 u8 *s = format (NULL, "UDP echo source is: %v\n", hw_if->name);
171 s = format (s, "IPv4 address usable as echo source: ");
172 if (have_usable_ip4)
173 {
174 s = format (s, "%U\n", format_ip4_address, &ip4);
175 }
176 else
177 {
178 s = format (s, "none\n");
179 }
180 s = format (s, "IPv6 address usable as echo source: ");
181 if (have_usable_ip6)
182 {
183 s = format (s, "%U\n", format_ip6_address, &ip6);
184 }
185 else
186 {
187 s = format (s, "none\n");
188 }
189 vlib_cli_output (vm, "%v", s);
190 vec_free (s);
191 }
192 else
193 {
194 vlib_cli_output (vm, "UDP echo source is not set.\n");
195 }
196 }
197 else
198 {
199 vlib_cli_output (vm, "Number of configured BFD sessions: %lu\n",
200 (u64) pool_elts (bm->sessions));
201 vlib_cli_output (vm, "Number of configured BFD keys: %lu\n",
202 (u64) pool_elts (bm->auth_keys));
203 }
204 return 0;
205}
206
207/* *INDENT-OFF* */
208VLIB_CLI_COMMAND (show_bfd_command, static) = {
209 .path = "show bfd",
210 .short_help = "show bfd [keys|sessions|echo-source]",
211 .function = show_bfd,
212};
213/* *INDENT-ON* */
214
215static u8 *
216format_vnet_api_errno (u8 * s, va_list * args)
217{
218 vnet_api_error_t api_error = va_arg (*args, vnet_api_error_t);
219#define _(a, b, c) \
220 case b: \
221 s = format (s, "%s", c); \
222 break;
223 switch (api_error)
224 {
225 foreach_vnet_api_error default:s = format (s, "UNKNOWN");
226 break;
227 }
228 return s;
229}
230
231static clib_error_t *
232bfd_cli_key_add (vlib_main_t * vm, unformat_input_t * input,
233 CLIB_UNUSED (vlib_cli_command_t * lmd))
234{
235 clib_error_t *ret = NULL;
236 int have_key_id = 0;
237 u32 key_id = 0;
238 u8 *vec_auth_type = NULL;
239 bfd_auth_type_e auth_type = BFD_AUTH_TYPE_reserved;
240 u8 *secret = NULL;
241 static const u8 keyed_sha1[] = "keyed-sha1";
242 static const u8 meticulous_keyed_sha1[] = "meticulous-keyed-sha1";
243
244 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
245 {
246 if (unformat (input, "conf-key-id %u", &key_id))
247 {
248 have_key_id = 1;
249 }
250 else if (unformat (input, "type %U", unformat_token, "a-zA-Z0-9-",
251 &vec_auth_type))
252 {
253 if (vec_len (vec_auth_type) == sizeof (keyed_sha1) - 1 &&
254 0 == memcmp (vec_auth_type, keyed_sha1,
255 sizeof (keyed_sha1) - 1))
256 {
257 auth_type = BFD_AUTH_TYPE_keyed_sha1;
258 }
259 else if (vec_len (vec_auth_type) ==
260 sizeof (meticulous_keyed_sha1) - 1 &&
261 0 == memcmp (vec_auth_type, meticulous_keyed_sha1,
262 sizeof (meticulous_keyed_sha1) - 1))
263 {
264 auth_type = BFD_AUTH_TYPE_meticulous_keyed_sha1;
265 }
266 else
267 {
268 ret = clib_error_return (0, "invalid type `%v'", vec_auth_type);
269 goto out;
270 }
271 }
272 else if (unformat (input, "secret %U", unformat_hex_string, &secret))
273 {
274 /* nothing to do here */
275 }
276 else
277 {
278 ret = clib_error_return (0, "Unknown input `%U'",
279 format_unformat_error, input);
280 goto out;
281 }
282 }
283
284 if (!have_key_id)
285 {
286 ret =
287 clib_error_return (0, "required parameter missing: `conf-key-id'");
288 goto out;
289 }
290 if (!vec_auth_type)
291 {
292 ret = clib_error_return (0, "required parameter missing: `type'");
293 goto out;
294 }
295 if (!secret)
296 {
297 ret = clib_error_return (0, "required parameter missing: `secret'");
298 goto out;
299 }
300
301 vnet_api_error_t rv =
302 bfd_auth_set_key (key_id, auth_type, vec_len (secret), secret);
303 if (rv)
304 {
305 ret =
306 clib_error_return (0, "`bfd_auth_set_key' API call failed, rv=%d:%U",
307 (int) rv, format_vnet_api_errno, rv);
308 }
309
310out:
311 vec_free (vec_auth_type);
312 return ret;
313}
314
315/* *INDENT-OFF* */
316VLIB_CLI_COMMAND (bfd_cli_key_add_command, static) = {
317 .path = "bfd key set",
318 .short_help = "bfd key set"
319 " conf-key-id <id>"
320 " type <keyed-sha1|meticulous-keyed-sha1> "
321 " secret <secret>",
322 .function = bfd_cli_key_add,
323};
324/* *INDENT-ON* */
325
326static clib_error_t *
327bfd_cli_key_del (vlib_main_t * vm, unformat_input_t * input,
328 CLIB_UNUSED (vlib_cli_command_t * lmd))
329{
330 clib_error_t *ret = NULL;
331 u32 key_id = 0;
332
333 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
334 {
335 if (!unformat (input, "conf-key-id %u", &key_id))
336 {
337 ret = clib_error_return (0, "Unknown input `%U'",
338 format_unformat_error, input);
339 goto out;
340 }
341 }
342
343 vnet_api_error_t rv = bfd_auth_del_key (key_id);
344 if (rv)
345 {
346 ret =
347 clib_error_return (0, "`bfd_auth_del_key' API call failed, rv=%d:%U",
348 (int) rv, format_vnet_api_errno, rv);
349 }
350
351out:
352 return ret;
353}
354
355/* *INDENT-OFF* */
356VLIB_CLI_COMMAND (bfd_cli_key_del_command, static) = {
357 .path = "bfd key del",
358 .short_help = "bfd key del conf-key-id <id>",
359 .function = bfd_cli_key_del,
360};
361/* *INDENT-ON* */
362
363#define INTERFACE_STR "interface"
364#define LOCAL_ADDR_STR "local-addr"
365#define PEER_ADDR_STR "peer-addr"
366#define CONF_KEY_ID_STR "conf-key-id"
367#define BFD_KEY_ID_STR "bfd-key-id"
368#define DESIRED_MIN_TX_STR "desired-min-tx"
369#define REQUIRED_MIN_RX_STR "required-min-rx"
370#define DETECT_MULT_STR "detect-mult"
371#define ADMIN_STR "admin"
372#define DELAYED_STR "delayed"
373
374static const unsigned mandatory = 1;
375static const unsigned optional = 0;
376
377#define DECLARE(t, n, s, r, ...) \
378 int have_##n = 0; \
379 t n;
380
381#define UNFORMAT(t, n, s, r, ...) \
382 if (unformat (input, s " " __VA_ARGS__, &n)) \
383 { \
384 something_parsed = 1; \
385 have_##n = 1; \
386 }
387
388#define CHECK_MANDATORY(t, n, s, r, ...) \
389 if (mandatory == r && !have_##n) \
390 { \
Klement Sekerae50e8562017-04-04 16:19:48 +0200391 ret = clib_error_return (0, "Required parameter `%s' missing.", s); \
Klement Sekera73884482017-02-23 09:26:30 +0100392 goto out; \
393 }
394
395static clib_error_t *
396bfd_cli_udp_session_add (vlib_main_t * vm, unformat_input_t * input,
397 CLIB_UNUSED (vlib_cli_command_t * lmd))
398{
399 clib_error_t *ret = NULL;
400#define foreach_bfd_cli_udp_session_add_cli_param(F) \
401 F (u32, sw_if_index, INTERFACE_STR, mandatory, "%U", \
402 unformat_vnet_sw_interface, &vnet_main) \
403 F (ip46_address_t, local_addr, LOCAL_ADDR_STR, mandatory, "%U", \
404 unformat_ip46_address) \
405 F (ip46_address_t, peer_addr, PEER_ADDR_STR, mandatory, "%U", \
406 unformat_ip46_address) \
407 F (u32, desired_min_tx, DESIRED_MIN_TX_STR, mandatory, "%u") \
408 F (u32, required_min_rx, REQUIRED_MIN_RX_STR, mandatory, "%u") \
409 F (u32, detect_mult, DETECT_MULT_STR, mandatory, "%u") \
410 F (u32, conf_key_id, CONF_KEY_ID_STR, optional, "%u") \
411 F (u32, bfd_key_id, BFD_KEY_ID_STR, optional, "%u")
412
413 foreach_bfd_cli_udp_session_add_cli_param (DECLARE);
414
415 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
416 {
417 int something_parsed = 0;
418 foreach_bfd_cli_udp_session_add_cli_param (UNFORMAT);
419
420 if (!something_parsed)
421 {
422 ret = clib_error_return (0, "Unknown input `%U'",
423 format_unformat_error, input);
424 goto out;
425 }
426 }
427
428 foreach_bfd_cli_udp_session_add_cli_param (CHECK_MANDATORY);
429
430 if (1 == have_conf_key_id + have_bfd_key_id)
431 {
432 ret = clib_error_return (0, "Incompatible parameter combination, `%s' "
433 "and `%s' must be either both specified or none",
434 CONF_KEY_ID_STR, BFD_KEY_ID_STR);
435 goto out;
436 }
437
438 if (detect_mult > 255)
439 {
440 ret = clib_error_return (0, "%s value `%u' out of range <1,255>",
441 DETECT_MULT_STR, detect_mult);
442 goto out;
443 }
444
445 if (have_bfd_key_id && bfd_key_id > 255)
446 {
447 ret = clib_error_return (0, "%s value `%u' out of range <1,255>",
448 BFD_KEY_ID_STR, bfd_key_id);
449 goto out;
450 }
451
452 vnet_api_error_t rv =
453 bfd_udp_add_session (sw_if_index, &local_addr, &peer_addr, desired_min_tx,
454 required_min_rx,
455 detect_mult, have_conf_key_id, conf_key_id,
456 bfd_key_id);
457 if (rv)
458 {
459 ret =
460 clib_error_return (0,
461 "`bfd_add_add_session' API call failed, rv=%d:%U",
462 (int) rv, format_vnet_api_errno, rv);
463 goto out;
464 }
465
466out:
467 return ret;
468}
469
470/* *INDENT-OFF* */
471VLIB_CLI_COMMAND (bfd_cli_udp_session_add_command, static) = {
472 .path = "bfd udp session add",
473 .short_help = "bfd udp session add"
474 " interface <interface>"
475 " local-addr <local-address>"
476 " peer-addr <peer-address>"
477 " desired-min-tx <desired min tx interval>"
478 " required-min-rx <required min rx interval>"
479 " detect-mult <detect multiplier> "
480 "["
481 " conf-key-id <config key ID>"
482 " bfd-key-id <BFD key ID>"
483 "]",
484 .function = bfd_cli_udp_session_add,
485};
486/* *INDENT-ON* */
487
488static clib_error_t *
489bfd_cli_udp_session_mod (vlib_main_t * vm, unformat_input_t * input,
490 CLIB_UNUSED (vlib_cli_command_t * lmd))
491{
492 clib_error_t *ret = NULL;
493#define foreach_bfd_cli_udp_session_mod_cli_param(F) \
494 F (u32, sw_if_index, INTERFACE_STR, mandatory, "%U", \
495 unformat_vnet_sw_interface, &vnet_main) \
496 F (ip46_address_t, local_addr, LOCAL_ADDR_STR, mandatory, "%U", \
497 unformat_ip46_address) \
498 F (ip46_address_t, peer_addr, PEER_ADDR_STR, mandatory, "%U", \
499 unformat_ip46_address) \
500 F (u32, desired_min_tx, DESIRED_MIN_TX_STR, mandatory, "%u") \
501 F (u32, required_min_rx, REQUIRED_MIN_RX_STR, mandatory, "%u") \
502 F (u32, detect_mult, DETECT_MULT_STR, mandatory, "%u")
503
504 foreach_bfd_cli_udp_session_mod_cli_param (DECLARE);
505
506 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
507 {
508 int something_parsed = 0;
509 foreach_bfd_cli_udp_session_mod_cli_param (UNFORMAT);
510
511 if (!something_parsed)
512 {
513 ret = clib_error_return (0, "Unknown input `%U'",
514 format_unformat_error, input);
515 goto out;
516 }
517 }
518
519 foreach_bfd_cli_udp_session_mod_cli_param (CHECK_MANDATORY);
520
521 if (detect_mult > 255)
522 {
523 ret = clib_error_return (0, "%s value `%u' out of range <1,255>",
524 DETECT_MULT_STR, detect_mult);
525 goto out;
526 }
527
528 vnet_api_error_t rv =
529 bfd_udp_mod_session (sw_if_index, &local_addr, &peer_addr,
530 desired_min_tx, required_min_rx, detect_mult);
531 if (rv)
532 {
533 ret =
534 clib_error_return (0,
535 "`bfd_udp_mod_session' API call failed, rv=%d:%U",
536 (int) rv, format_vnet_api_errno, rv);
537 goto out;
538 }
539
540out:
541 return ret;
542}
543
544/* *INDENT-OFF* */
545VLIB_CLI_COMMAND (bfd_cli_udp_session_mod_command, static) = {
546 .path = "bfd udp session mod",
547 .short_help = "bfd udp session mod interface"
548 " <interface> local-addr"
549 " <local-address> peer-addr"
550 " <peer-address> desired-min-tx"
551 " <desired min tx interval> required-min-rx"
552 " <required min rx interval> detect-mult"
553 " <detect multiplier> ",
554 .function = bfd_cli_udp_session_mod,
555};
556/* *INDENT-ON* */
557
558static clib_error_t *
559bfd_cli_udp_session_del (vlib_main_t * vm, unformat_input_t * input,
560 CLIB_UNUSED (vlib_cli_command_t * lmd))
561{
562 clib_error_t *ret = NULL;
563#define foreach_bfd_cli_udp_session_del_cli_param(F) \
564 F (u32, sw_if_index, INTERFACE_STR, mandatory, "%U", \
565 unformat_vnet_sw_interface, &vnet_main) \
566 F (ip46_address_t, local_addr, LOCAL_ADDR_STR, mandatory, "%U", \
567 unformat_ip46_address) \
568 F (ip46_address_t, peer_addr, PEER_ADDR_STR, mandatory, "%U", \
569 unformat_ip46_address)
570
571 foreach_bfd_cli_udp_session_del_cli_param (DECLARE);
572
573 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
574 {
575 int something_parsed = 0;
576 foreach_bfd_cli_udp_session_del_cli_param (UNFORMAT);
577
578 if (!something_parsed)
579 {
580 ret = clib_error_return (0, "Unknown input `%U'",
581 format_unformat_error, input);
582 goto out;
583 }
584 }
585
586 foreach_bfd_cli_udp_session_del_cli_param (CHECK_MANDATORY);
587
588 vnet_api_error_t rv =
589 bfd_udp_del_session (sw_if_index, &local_addr, &peer_addr);
590 if (rv)
591 {
592 ret =
593 clib_error_return (0,
594 "`bfd_udp_del_session' API call failed, rv=%d:%U",
595 (int) rv, format_vnet_api_errno, rv);
596 goto out;
597 }
598
599out:
600 return ret;
601}
602
603/* *INDENT-OFF* */
604VLIB_CLI_COMMAND (bfd_cli_udp_session_del_command, static) = {
605 .path = "bfd udp session del",
606 .short_help = "bfd udp session del interface"
607 " <interface> local-addr"
608 " <local-address> peer-addr"
609 "<peer-address> ",
610 .function = bfd_cli_udp_session_del,
611};
612/* *INDENT-ON* */
613
614static clib_error_t *
615bfd_cli_udp_session_set_flags (vlib_main_t * vm, unformat_input_t * input,
616 CLIB_UNUSED (vlib_cli_command_t * lmd))
617{
618 clib_error_t *ret = NULL;
619#define foreach_bfd_cli_udp_session_set_flags_cli_param(F) \
620 F (u32, sw_if_index, INTERFACE_STR, mandatory, "%U", \
621 unformat_vnet_sw_interface, &vnet_main) \
622 F (ip46_address_t, local_addr, LOCAL_ADDR_STR, mandatory, "%U", \
623 unformat_ip46_address) \
624 F (ip46_address_t, peer_addr, PEER_ADDR_STR, mandatory, "%U", \
625 unformat_ip46_address) \
626 F (u8 *, admin_up_down_token, ADMIN_STR, mandatory, "%v", \
627 &admin_up_down_token)
628
629 foreach_bfd_cli_udp_session_set_flags_cli_param (DECLARE);
630
631 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
632 {
633 int something_parsed = 0;
634 foreach_bfd_cli_udp_session_set_flags_cli_param (UNFORMAT);
635
636 if (!something_parsed)
637 {
638 ret = clib_error_return (0, "Unknown input `%U'",
639 format_unformat_error, input);
640 goto out;
641 }
642 }
643
644 foreach_bfd_cli_udp_session_set_flags_cli_param (CHECK_MANDATORY);
645
646 u8 admin_up_down;
647 static const char up[] = "up";
648 static const char down[] = "down";
649 if (!memcmp (admin_up_down_token, up, sizeof (up) - 1))
650 {
651 admin_up_down = 1;
652 }
653 else if (!memcmp (admin_up_down_token, down, sizeof (down) - 1))
654 {
655 admin_up_down = 0;
656 }
657 else
658 {
659 ret =
660 clib_error_return (0, "Unrecognized value for `%s' parameter: `%v'",
661 ADMIN_STR, admin_up_down_token);
662 goto out;
663 }
664 vnet_api_error_t rv = bfd_udp_session_set_flags (sw_if_index, &local_addr,
665 &peer_addr, admin_up_down);
666 if (rv)
667 {
668 ret =
669 clib_error_return (0,
670 "`bfd_udp_session_set_flags' API call failed, rv=%d:%U",
671 (int) rv, format_vnet_api_errno, rv);
672 goto out;
673 }
674
675out:
676 return ret;
677}
678
679/* *INDENT-OFF* */
680VLIB_CLI_COMMAND (bfd_cli_udp_session_set_flags_command, static) = {
681 .path = "bfd udp session set-flags",
682 .short_help = "bfd udp session set-flags"
683 " interface <interface>"
684 " local-addr <local-address>"
685 " peer-addr <peer-address>"
686 " admin <up|down>",
687 .function = bfd_cli_udp_session_set_flags,
688};
689/* *INDENT-ON* */
690
691static clib_error_t *
692bfd_cli_udp_session_auth_activate (vlib_main_t * vm, unformat_input_t * input,
693 CLIB_UNUSED (vlib_cli_command_t * lmd))
694{
695 clib_error_t *ret = NULL;
696#define foreach_bfd_cli_udp_session_auth_activate_cli_param(F) \
697 F (u32, sw_if_index, INTERFACE_STR, mandatory, "%U", \
698 unformat_vnet_sw_interface, &vnet_main) \
699 F (ip46_address_t, local_addr, LOCAL_ADDR_STR, mandatory, "%U", \
700 unformat_ip46_address) \
701 F (ip46_address_t, peer_addr, PEER_ADDR_STR, mandatory, "%U", \
702 unformat_ip46_address) \
703 F (u8 *, delayed_token, DELAYED_STR, optional, "%v") \
704 F (u32, conf_key_id, CONF_KEY_ID_STR, mandatory, "%u") \
705 F (u32, bfd_key_id, BFD_KEY_ID_STR, mandatory, "%u")
706
707 foreach_bfd_cli_udp_session_auth_activate_cli_param (DECLARE);
708
709 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
710 {
711 int something_parsed = 0;
712 foreach_bfd_cli_udp_session_auth_activate_cli_param (UNFORMAT);
713
714 if (!something_parsed)
715 {
716 ret = clib_error_return (0, "Unknown input `%U'",
717 format_unformat_error, input);
718 goto out;
719 }
720 }
721
722 foreach_bfd_cli_udp_session_auth_activate_cli_param (CHECK_MANDATORY);
723
724 u8 is_delayed = 0;
725 if (have_delayed_token)
726 {
727 static const char yes[] = "yes";
728 static const char no[] = "no";
729 if (!memcmp (delayed_token, yes, sizeof (yes) - 1))
730 {
731 is_delayed = 1;
732 }
733 else if (!memcmp (delayed_token, no, sizeof (no) - 1))
734 {
735 is_delayed = 0;
736 }
737 else
738 {
739 ret =
740 clib_error_return (0,
741 "Unrecognized value for `%s' parameter: `%v'",
742 DELAYED_STR, delayed_token);
743 goto out;
744 }
745 }
746
747 if (have_bfd_key_id && bfd_key_id > 255)
748 {
749 ret = clib_error_return (0, "%s value `%u' out of range <1,255>",
750 BFD_KEY_ID_STR, bfd_key_id);
751 goto out;
752 }
753
754 vnet_api_error_t rv =
755 bfd_udp_auth_activate (sw_if_index, &local_addr, &peer_addr, conf_key_id,
756 bfd_key_id, is_delayed);
757 if (rv)
758 {
759 ret =
760 clib_error_return (0,
761 "`bfd_udp_auth_activate' API call failed, rv=%d:%U",
762 (int) rv, format_vnet_api_errno, rv);
763 goto out;
764 }
765
766out:
767 return ret;
768}
769
770/* *INDENT-OFF* */
771VLIB_CLI_COMMAND (bfd_cli_udp_session_auth_activate_command, static) = {
772 .path = "bfd udp session auth activate",
773 .short_help = "bfd udp session auth activate"
774 " interface <interface>"
775 " local-addr <local-address>"
776 " peer-addr <peer-address>"
777 " conf-key-id <config key ID>"
778 " bfd-key-id <BFD key ID>"
Klement Sekerab16bfe32017-02-28 11:56:48 +0100779 " [ delayed <yes|no> ]",
Klement Sekera73884482017-02-23 09:26:30 +0100780 .function = bfd_cli_udp_session_auth_activate,
781};
782
783static clib_error_t *
784bfd_cli_udp_session_auth_deactivate (vlib_main_t *vm, unformat_input_t *input,
785 CLIB_UNUSED (vlib_cli_command_t *lmd))
786{
787 clib_error_t *ret = NULL;
788#define foreach_bfd_cli_udp_session_auth_deactivate_cli_param(F) \
789 F (u32, sw_if_index, INTERFACE_STR, mandatory, "%U", \
790 unformat_vnet_sw_interface, &vnet_main) \
791 F (ip46_address_t, local_addr, LOCAL_ADDR_STR, mandatory, "%U", \
792 unformat_ip46_address) \
793 F (ip46_address_t, peer_addr, PEER_ADDR_STR, mandatory, "%U", \
794 unformat_ip46_address) \
795 F (u8 *, delayed_token, DELAYED_STR, optional, "%v")
796
797 foreach_bfd_cli_udp_session_auth_deactivate_cli_param (DECLARE);
798
799 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
800 {
801 int something_parsed = 0;
802 foreach_bfd_cli_udp_session_auth_deactivate_cli_param (UNFORMAT);
803
804 if (!something_parsed)
805 {
806 ret = clib_error_return (0, "Unknown input `%U'",
807 format_unformat_error, input);
808 goto out;
809 }
810 }
811
812 foreach_bfd_cli_udp_session_auth_deactivate_cli_param (CHECK_MANDATORY);
813
814 u8 is_delayed = 0;
815 if (have_delayed_token)
816 {
817 static const char yes[] = "yes";
818 static const char no[] = "no";
819 if (!memcmp (delayed_token, yes, sizeof (yes) - 1))
820 {
821 is_delayed = 1;
822 }
823 else if (!memcmp (delayed_token, no, sizeof (no) - 1))
824 {
825 is_delayed = 0;
826 }
827 else
828 {
829 ret = clib_error_return (
830 0, "Unrecognized value for `%s' parameter: `%v'", DELAYED_STR,
831 delayed_token);
832 goto out;
833 }
834 }
835
836 vnet_api_error_t rv = bfd_udp_auth_deactivate (sw_if_index, &local_addr,
837 &peer_addr, is_delayed);
838 if (rv)
839 {
840 ret = clib_error_return (
841 0, "`bfd_udp_auth_deactivate' API call failed, rv=%d:%U", (int)rv,
842 format_vnet_api_errno, rv);
843 goto out;
844 }
845
846out:
847 return ret;
848}
849
850/* *INDENT-OFF* */
851VLIB_CLI_COMMAND (bfd_cli_udp_session_auth_deactivate_command, static) = {
852 .path = "bfd udp session auth deactivate",
853 .short_help = "bfd udp session auth deactivate"
854 " interface <interface>"
855 " local-addr <local-address>"
856 " peer-addr <peer-address>"
Klement Sekerab16bfe32017-02-28 11:56:48 +0100857 "[ delayed <yes|no> ]",
Klement Sekera73884482017-02-23 09:26:30 +0100858 .function = bfd_cli_udp_session_auth_deactivate,
859};
860/* *INDENT-ON* */
861
862static clib_error_t *
863bfd_cli_udp_set_echo_source (vlib_main_t * vm, unformat_input_t * input,
864 CLIB_UNUSED (vlib_cli_command_t * lmd))
865{
866 clib_error_t *ret = NULL;
867#define foreach_bfd_cli_udp_set_echo_source_cli_param(F) \
868 F (u32, sw_if_index, INTERFACE_STR, mandatory, "%U", \
869 unformat_vnet_sw_interface, &vnet_main)
870
871 foreach_bfd_cli_udp_set_echo_source_cli_param (DECLARE);
872
873 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
874 {
875 int something_parsed = 0;
876 foreach_bfd_cli_udp_set_echo_source_cli_param (UNFORMAT);
877
878 if (!something_parsed)
879 {
880 ret = clib_error_return (0, "Unknown input `%U'",
881 format_unformat_error, input);
882 goto out;
883 }
884 }
885
886 foreach_bfd_cli_udp_set_echo_source_cli_param (CHECK_MANDATORY);
887
888 vnet_api_error_t rv = bfd_udp_set_echo_source (sw_if_index);
889 if (rv)
890 {
891 ret =
892 clib_error_return (0,
893 "`bfd_udp_set_echo_source' API call failed, rv=%d:%U",
894 (int) rv, format_vnet_api_errno, rv);
895 goto out;
896 }
897
898out:
899 return ret;
900}
901
902/* *INDENT-OFF* */
903VLIB_CLI_COMMAND (bfd_cli_udp_set_echo_source_cmd, static) = {
904 .path = "bfd udp echo-source set",
905 .short_help = "bfd udp echo-source set interface <interface>",
906 .function = bfd_cli_udp_set_echo_source,
907};
908/* *INDENT-ON* */
909
910static clib_error_t *
911bfd_cli_udp_del_echo_source (vlib_main_t * vm, unformat_input_t * input,
912 CLIB_UNUSED (vlib_cli_command_t * lmd))
913{
914 vnet_api_error_t rv = bfd_udp_del_echo_source ();
915 if (rv)
916 {
917 return clib_error_return (0,
918 "`bfd_udp_del_echo_source' API call failed, rv=%d:%U",
919 (int) rv, format_vnet_api_errno, rv);
920 }
921
922 return 0;
923}
924
925/* *INDENT-OFF* */
926VLIB_CLI_COMMAND (bfd_cli_udp_del_echo_source_cmd, static) = {
927 .path = "bfd udp echo-source del",
928 .short_help = "bfd udp echo-source del",
929 .function = bfd_cli_udp_del_echo_source,
930};
931/* *INDENT-ON* */
932
933/*
934 * fd.io coding-style-patch-verification: ON
935 *
936 * Local Variables:
937 * eval: (c-set-style "gnu")
938 * End:
939 */