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:
7 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 * @brief BFD CLI implementation
20 #include <vlib/vlib.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>
29 format_bfd_session_cli (u8 * s, va_list * args)
31 vlib_main_t *vm = va_arg (*args, vlib_main_t *);
32 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)
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);
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);
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);
55 s = format (s, "%10s %-32s %20u %20llu\n", "",
56 "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));
63 format (s, "%10s %-32s %20u\n", "", "Transmit interval",
64 bfd_clocks_to_usec (bm, bs->transmit_interval_clocks));
65 u64 now = clib_cpu_time_now ();
67 if (bs->last_tx_clocks > 0)
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);
74 if (bs->last_rx_clocks)
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);
82 format (s, "%10s %-32s %20u %20llu\n", "", "Min Echo Rx Interval (usec)",
83 1, bs->remote_min_echo_rx_usec);
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);
96 format (s, "%10s %-32s %20v\n", "", "Last echo frame roundtrip time",
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));
105 if (bs->auth.curr_key)
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);
111 s = format (s, "%10s %-32s %20u %20u\n", "", "Sequence number",
112 bs->auth.local_seq_number, bs->auth.remote_seq_number);
117 static clib_error_t *
118 show_bfd (vlib_main_t * vm, unformat_input_t * input,
119 CLIB_UNUSED (vlib_cli_command_t * lmd))
121 bfd_main_t *bm = &bfd_main;
122 bfd_session_t *bs = NULL;
124 if (unformat (input, "keys"))
126 bfd_auth_key_t *key = NULL;
127 u8 *s = format (NULL, "%=10s %=25s %=10s\n", "Configuration Key ID",
128 "Type", "Use Count");
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);
135 vlib_cli_output (vm, "%v\n", s);
137 vlib_cli_output (vm, "Number of configured BFD keys: %lu\n",
138 (u64) pool_elts (bm->auth_keys));
140 else if (unformat (input, "sessions"))
142 u8 *s = format (NULL, "%=10s %=32s %=20s %=20s\n", "Index", "Property",
143 "Local value", "Remote value");
145 pool_foreach (bs, bm->sessions, {
146 s = format (s, "%U", format_bfd_session_cli, vm, bm, bs);
149 vlib_cli_output (vm, "%v", s);
151 vlib_cli_output (vm, "Number of configured BFD sessions: %lu\n",
152 (u64) pool_elts (bm->sessions));
154 else if (unformat (input, "echo-source"))
162 bfd_udp_get_echo_source (&is_set, &sw_if_index, &have_usable_ip4, &ip4,
163 &have_usable_ip6, &ip6);
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: ");
174 s = format (s, "%U\n", format_ip4_address, &ip4);
178 s = format (s, "none\n");
180 s = format (s, "IPv6 address usable as echo source: ");
183 s = format (s, "%U\n", format_ip6_address, &ip6);
187 s = format (s, "none\n");
189 vlib_cli_output (vm, "%v", s);
194 vlib_cli_output (vm, "UDP echo source is not set.\n");
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));
208 VLIB_CLI_COMMAND (show_bfd_command, static) = {
210 .short_help = "show bfd [keys|sessions|echo-source]",
211 .function = show_bfd,
216 format_vnet_api_errno (u8 * s, va_list * args)
218 vnet_api_error_t api_error = va_arg (*args, vnet_api_error_t);
221 s = format (s, "%s", c); \
225 foreach_vnet_api_error default:s = format (s, "UNKNOWN");
231 static clib_error_t *
232 bfd_cli_key_add (vlib_main_t * vm, unformat_input_t * input,
233 CLIB_UNUSED (vlib_cli_command_t * lmd))
235 clib_error_t *ret = NULL;
238 u8 *vec_auth_type = NULL;
239 bfd_auth_type_e auth_type = BFD_AUTH_TYPE_reserved;
241 static const u8 keyed_sha1[] = "keyed-sha1";
242 static const u8 meticulous_keyed_sha1[] = "meticulous-keyed-sha1";
244 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
246 if (unformat (input, "conf-key-id %u", &key_id))
250 else if (unformat (input, "type %U", unformat_token, "a-zA-Z0-9-",
253 if (vec_len (vec_auth_type) == sizeof (keyed_sha1) - 1 &&
254 0 == memcmp (vec_auth_type, keyed_sha1,
255 sizeof (keyed_sha1) - 1))
257 auth_type = BFD_AUTH_TYPE_keyed_sha1;
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))
264 auth_type = BFD_AUTH_TYPE_meticulous_keyed_sha1;
268 ret = clib_error_return (0, "invalid type `%v'", vec_auth_type);
272 else if (unformat (input, "secret %U", unformat_hex_string, &secret))
274 /* nothing to do here */
278 ret = clib_error_return (0, "Unknown input `%U'",
279 format_unformat_error, input);
287 clib_error_return (0, "required parameter missing: `conf-key-id'");
292 ret = clib_error_return (0, "required parameter missing: `type'");
297 ret = clib_error_return (0, "required parameter missing: `secret'");
301 vnet_api_error_t rv =
302 bfd_auth_set_key (key_id, auth_type, vec_len (secret), secret);
306 clib_error_return (0, "`bfd_auth_set_key' API call failed, rv=%d:%U",
307 (int) rv, format_vnet_api_errno, rv);
311 vec_free (vec_auth_type);
316 VLIB_CLI_COMMAND (bfd_cli_key_add_command, static) = {
317 .path = "bfd key set",
318 .short_help = "bfd key set"
320 " type <keyed-sha1|meticulous-keyed-sha1> "
322 .function = bfd_cli_key_add,
326 static clib_error_t *
327 bfd_cli_key_del (vlib_main_t * vm, unformat_input_t * input,
328 CLIB_UNUSED (vlib_cli_command_t * lmd))
330 clib_error_t *ret = NULL;
333 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
335 if (!unformat (input, "conf-key-id %u", &key_id))
337 ret = clib_error_return (0, "Unknown input `%U'",
338 format_unformat_error, input);
343 vnet_api_error_t rv = bfd_auth_del_key (key_id);
347 clib_error_return (0, "`bfd_auth_del_key' API call failed, rv=%d:%U",
348 (int) rv, format_vnet_api_errno, rv);
356 VLIB_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,
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"
374 static const unsigned mandatory = 1;
375 static const unsigned optional = 0;
377 #define DECLARE(t, n, s, r, ...) \
381 #define UNFORMAT(t, n, s, r, ...) \
382 if (unformat (input, s " " __VA_ARGS__, &n)) \
384 something_parsed = 1; \
389 #define PRAGMA_STR1 \
390 _Pragma ("GCC diagnostic ignored \"-Wtautological-compare\"");
391 #define PRAGMA_STR2 _Pragma ("GCC diagnostic pop");
397 #define CHECK_MANDATORY(t, n, s, r, ...) \
399 if (mandatory == r && !have_##n) \
402 ret = clib_error_return (0, "Required parameter `%s' missing.", s); \
406 static clib_error_t *
407 bfd_cli_udp_session_add (vlib_main_t * vm, unformat_input_t * input,
408 CLIB_UNUSED (vlib_cli_command_t * lmd))
410 clib_error_t *ret = NULL;
411 #define foreach_bfd_cli_udp_session_add_cli_param(F) \
412 F (u32, sw_if_index, INTERFACE_STR, mandatory, "%U", \
413 unformat_vnet_sw_interface, &vnet_main) \
414 F (ip46_address_t, local_addr, LOCAL_ADDR_STR, mandatory, "%U", \
415 unformat_ip46_address) \
416 F (ip46_address_t, peer_addr, PEER_ADDR_STR, mandatory, "%U", \
417 unformat_ip46_address) \
418 F (u32, desired_min_tx, DESIRED_MIN_TX_STR, mandatory, "%u") \
419 F (u32, required_min_rx, REQUIRED_MIN_RX_STR, mandatory, "%u") \
420 F (u32, detect_mult, DETECT_MULT_STR, mandatory, "%u") \
421 F (u32, conf_key_id, CONF_KEY_ID_STR, optional, "%u") \
422 F (u32, bfd_key_id, BFD_KEY_ID_STR, optional, "%u")
424 foreach_bfd_cli_udp_session_add_cli_param (DECLARE);
426 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
428 int something_parsed = 0;
429 foreach_bfd_cli_udp_session_add_cli_param (UNFORMAT);
431 if (!something_parsed)
433 ret = clib_error_return (0, "Unknown input `%U'",
434 format_unformat_error, input);
439 foreach_bfd_cli_udp_session_add_cli_param (CHECK_MANDATORY);
441 if (1 == have_conf_key_id + have_bfd_key_id)
443 ret = clib_error_return (0, "Incompatible parameter combination, `%s' "
444 "and `%s' must be either both specified or none",
445 CONF_KEY_ID_STR, BFD_KEY_ID_STR);
449 if (detect_mult > 255)
451 ret = clib_error_return (0, "%s value `%u' out of range <1,255>",
452 DETECT_MULT_STR, detect_mult);
456 if (have_bfd_key_id && bfd_key_id > 255)
458 ret = clib_error_return (0, "%s value `%u' out of range <1,255>",
459 BFD_KEY_ID_STR, bfd_key_id);
463 vnet_api_error_t rv =
464 bfd_udp_add_session (sw_if_index, &local_addr, &peer_addr, desired_min_tx,
466 detect_mult, have_conf_key_id, conf_key_id,
471 clib_error_return (0,
472 "`bfd_add_add_session' API call failed, rv=%d:%U",
473 (int) rv, format_vnet_api_errno, rv);
482 VLIB_CLI_COMMAND (bfd_cli_udp_session_add_command, static) = {
483 .path = "bfd udp session add",
484 .short_help = "bfd udp session add"
485 " interface <interface>"
486 " local-addr <local-address>"
487 " peer-addr <peer-address>"
488 " desired-min-tx <desired min tx interval>"
489 " required-min-rx <required min rx interval>"
490 " detect-mult <detect multiplier> "
492 " conf-key-id <config key ID>"
493 " bfd-key-id <BFD key ID>"
495 .function = bfd_cli_udp_session_add,
499 static clib_error_t *
500 bfd_cli_udp_session_mod (vlib_main_t * vm, unformat_input_t * input,
501 CLIB_UNUSED (vlib_cli_command_t * lmd))
503 clib_error_t *ret = NULL;
504 #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")
515 foreach_bfd_cli_udp_session_mod_cli_param (DECLARE);
517 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
519 int something_parsed = 0;
520 foreach_bfd_cli_udp_session_mod_cli_param (UNFORMAT);
522 if (!something_parsed)
524 ret = clib_error_return (0, "Unknown input `%U'",
525 format_unformat_error, input);
530 foreach_bfd_cli_udp_session_mod_cli_param (CHECK_MANDATORY);
532 if (detect_mult > 255)
534 ret = clib_error_return (0, "%s value `%u' out of range <1,255>",
535 DETECT_MULT_STR, detect_mult);
539 vnet_api_error_t rv =
540 bfd_udp_mod_session (sw_if_index, &local_addr, &peer_addr,
541 desired_min_tx, required_min_rx, detect_mult);
545 clib_error_return (0,
546 "`bfd_udp_mod_session' API call failed, rv=%d:%U",
547 (int) rv, format_vnet_api_errno, rv);
556 VLIB_CLI_COMMAND (bfd_cli_udp_session_mod_command, static) = {
557 .path = "bfd udp session mod",
558 .short_help = "bfd udp session mod interface"
559 " <interface> local-addr"
560 " <local-address> peer-addr"
561 " <peer-address> desired-min-tx"
562 " <desired min tx interval> required-min-rx"
563 " <required min rx interval> detect-mult"
564 " <detect multiplier> ",
565 .function = bfd_cli_udp_session_mod,
569 static clib_error_t *
570 bfd_cli_udp_session_del (vlib_main_t * vm, unformat_input_t * input,
571 CLIB_UNUSED (vlib_cli_command_t * lmd))
573 clib_error_t *ret = NULL;
574 #define foreach_bfd_cli_udp_session_del_cli_param(F) \
575 F (u32, sw_if_index, INTERFACE_STR, mandatory, "%U", \
576 unformat_vnet_sw_interface, &vnet_main) \
577 F (ip46_address_t, local_addr, LOCAL_ADDR_STR, mandatory, "%U", \
578 unformat_ip46_address) \
579 F (ip46_address_t, peer_addr, PEER_ADDR_STR, mandatory, "%U", \
580 unformat_ip46_address)
582 foreach_bfd_cli_udp_session_del_cli_param (DECLARE);
584 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
586 int something_parsed = 0;
587 foreach_bfd_cli_udp_session_del_cli_param (UNFORMAT);
589 if (!something_parsed)
591 ret = clib_error_return (0, "Unknown input `%U'",
592 format_unformat_error, input);
597 foreach_bfd_cli_udp_session_del_cli_param (CHECK_MANDATORY);
599 vnet_api_error_t rv =
600 bfd_udp_del_session (sw_if_index, &local_addr, &peer_addr);
604 clib_error_return (0,
605 "`bfd_udp_del_session' API call failed, rv=%d:%U",
606 (int) rv, format_vnet_api_errno, rv);
615 VLIB_CLI_COMMAND (bfd_cli_udp_session_del_command, static) = {
616 .path = "bfd udp session del",
617 .short_help = "bfd udp session del interface"
618 " <interface> local-addr"
619 " <local-address> peer-addr"
621 .function = bfd_cli_udp_session_del,
625 static clib_error_t *
626 bfd_cli_udp_session_set_flags (vlib_main_t * vm, unformat_input_t * input,
627 CLIB_UNUSED (vlib_cli_command_t * lmd))
629 clib_error_t *ret = NULL;
630 #define foreach_bfd_cli_udp_session_set_flags_cli_param(F) \
631 F (u32, sw_if_index, INTERFACE_STR, mandatory, "%U", \
632 unformat_vnet_sw_interface, &vnet_main) \
633 F (ip46_address_t, local_addr, LOCAL_ADDR_STR, mandatory, "%U", \
634 unformat_ip46_address) \
635 F (ip46_address_t, peer_addr, PEER_ADDR_STR, mandatory, "%U", \
636 unformat_ip46_address) \
637 F (u8 *, admin_up_down_token, ADMIN_STR, mandatory, "%v", \
638 &admin_up_down_token)
640 foreach_bfd_cli_udp_session_set_flags_cli_param (DECLARE);
642 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
644 int something_parsed = 0;
645 foreach_bfd_cli_udp_session_set_flags_cli_param (UNFORMAT);
647 if (!something_parsed)
649 ret = clib_error_return (0, "Unknown input `%U'",
650 format_unformat_error, input);
655 foreach_bfd_cli_udp_session_set_flags_cli_param (CHECK_MANDATORY);
658 static const char up[] = "up";
659 static const char down[] = "down";
660 if (!memcmp (admin_up_down_token, up, sizeof (up) - 1))
664 else if (!memcmp (admin_up_down_token, down, sizeof (down) - 1))
671 clib_error_return (0, "Unrecognized value for `%s' parameter: `%v'",
672 ADMIN_STR, admin_up_down_token);
675 vnet_api_error_t rv = bfd_udp_session_set_flags (sw_if_index, &local_addr,
676 &peer_addr, admin_up_down);
680 clib_error_return (0,
681 "`bfd_udp_session_set_flags' API call failed, rv=%d:%U",
682 (int) rv, format_vnet_api_errno, rv);
691 VLIB_CLI_COMMAND (bfd_cli_udp_session_set_flags_command, static) = {
692 .path = "bfd udp session set-flags",
693 .short_help = "bfd udp session set-flags"
694 " interface <interface>"
695 " local-addr <local-address>"
696 " peer-addr <peer-address>"
698 .function = bfd_cli_udp_session_set_flags,
702 static clib_error_t *
703 bfd_cli_udp_session_auth_activate (vlib_main_t * vm, unformat_input_t * input,
704 CLIB_UNUSED (vlib_cli_command_t * lmd))
706 clib_error_t *ret = NULL;
707 #define foreach_bfd_cli_udp_session_auth_activate_cli_param(F) \
708 F (u32, sw_if_index, INTERFACE_STR, mandatory, "%U", \
709 unformat_vnet_sw_interface, &vnet_main) \
710 F (ip46_address_t, local_addr, LOCAL_ADDR_STR, mandatory, "%U", \
711 unformat_ip46_address) \
712 F (ip46_address_t, peer_addr, PEER_ADDR_STR, mandatory, "%U", \
713 unformat_ip46_address) \
714 F (u8 *, delayed_token, DELAYED_STR, optional, "%v") \
715 F (u32, conf_key_id, CONF_KEY_ID_STR, mandatory, "%u") \
716 F (u32, bfd_key_id, BFD_KEY_ID_STR, mandatory, "%u")
718 foreach_bfd_cli_udp_session_auth_activate_cli_param (DECLARE);
720 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
722 int something_parsed = 0;
723 foreach_bfd_cli_udp_session_auth_activate_cli_param (UNFORMAT);
725 if (!something_parsed)
727 ret = clib_error_return (0, "Unknown input `%U'",
728 format_unformat_error, input);
733 foreach_bfd_cli_udp_session_auth_activate_cli_param (CHECK_MANDATORY);
736 if (have_delayed_token)
738 static const char yes[] = "yes";
739 static const char no[] = "no";
740 if (!memcmp (delayed_token, yes, sizeof (yes) - 1))
744 else if (!memcmp (delayed_token, no, sizeof (no) - 1))
751 clib_error_return (0,
752 "Unrecognized value for `%s' parameter: `%v'",
753 DELAYED_STR, delayed_token);
758 if (have_bfd_key_id && bfd_key_id > 255)
760 ret = clib_error_return (0, "%s value `%u' out of range <1,255>",
761 BFD_KEY_ID_STR, bfd_key_id);
765 vnet_api_error_t rv =
766 bfd_udp_auth_activate (sw_if_index, &local_addr, &peer_addr, conf_key_id,
767 bfd_key_id, is_delayed);
771 clib_error_return (0,
772 "`bfd_udp_auth_activate' API call failed, rv=%d:%U",
773 (int) rv, format_vnet_api_errno, rv);
782 VLIB_CLI_COMMAND (bfd_cli_udp_session_auth_activate_command, static) = {
783 .path = "bfd udp session auth activate",
784 .short_help = "bfd udp session auth activate"
785 " interface <interface>"
786 " local-addr <local-address>"
787 " peer-addr <peer-address>"
788 " conf-key-id <config key ID>"
789 " bfd-key-id <BFD key ID>"
790 " [ delayed <yes|no> ]",
791 .function = bfd_cli_udp_session_auth_activate,
794 static clib_error_t *
795 bfd_cli_udp_session_auth_deactivate (vlib_main_t *vm, unformat_input_t *input,
796 CLIB_UNUSED (vlib_cli_command_t *lmd))
798 clib_error_t *ret = NULL;
799 #define foreach_bfd_cli_udp_session_auth_deactivate_cli_param(F) \
800 F (u32, sw_if_index, INTERFACE_STR, mandatory, "%U", \
801 unformat_vnet_sw_interface, &vnet_main) \
802 F (ip46_address_t, local_addr, LOCAL_ADDR_STR, mandatory, "%U", \
803 unformat_ip46_address) \
804 F (ip46_address_t, peer_addr, PEER_ADDR_STR, mandatory, "%U", \
805 unformat_ip46_address) \
806 F (u8 *, delayed_token, DELAYED_STR, optional, "%v")
808 foreach_bfd_cli_udp_session_auth_deactivate_cli_param (DECLARE);
810 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
812 int something_parsed = 0;
813 foreach_bfd_cli_udp_session_auth_deactivate_cli_param (UNFORMAT);
815 if (!something_parsed)
817 ret = clib_error_return (0, "Unknown input `%U'",
818 format_unformat_error, input);
823 foreach_bfd_cli_udp_session_auth_deactivate_cli_param (CHECK_MANDATORY);
826 if (have_delayed_token)
828 static const char yes[] = "yes";
829 static const char no[] = "no";
830 if (!memcmp (delayed_token, yes, sizeof (yes) - 1))
834 else if (!memcmp (delayed_token, no, sizeof (no) - 1))
840 ret = clib_error_return (
841 0, "Unrecognized value for `%s' parameter: `%v'", DELAYED_STR,
847 vnet_api_error_t rv = bfd_udp_auth_deactivate (sw_if_index, &local_addr,
848 &peer_addr, is_delayed);
851 ret = clib_error_return (
852 0, "`bfd_udp_auth_deactivate' API call failed, rv=%d:%U", (int)rv,
853 format_vnet_api_errno, rv);
862 VLIB_CLI_COMMAND (bfd_cli_udp_session_auth_deactivate_command, static) = {
863 .path = "bfd udp session auth deactivate",
864 .short_help = "bfd udp session auth deactivate"
865 " interface <interface>"
866 " local-addr <local-address>"
867 " peer-addr <peer-address>"
868 "[ delayed <yes|no> ]",
869 .function = bfd_cli_udp_session_auth_deactivate,
873 static clib_error_t *
874 bfd_cli_udp_set_echo_source (vlib_main_t * vm, unformat_input_t * input,
875 CLIB_UNUSED (vlib_cli_command_t * lmd))
877 clib_error_t *ret = NULL;
878 #define foreach_bfd_cli_udp_set_echo_source_cli_param(F) \
879 F (u32, sw_if_index, INTERFACE_STR, mandatory, "%U", \
880 unformat_vnet_sw_interface, &vnet_main)
882 foreach_bfd_cli_udp_set_echo_source_cli_param (DECLARE);
884 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
886 int something_parsed = 0;
887 foreach_bfd_cli_udp_set_echo_source_cli_param (UNFORMAT);
889 if (!something_parsed)
891 ret = clib_error_return (0, "Unknown input `%U'",
892 format_unformat_error, input);
897 foreach_bfd_cli_udp_set_echo_source_cli_param (CHECK_MANDATORY);
899 vnet_api_error_t rv = bfd_udp_set_echo_source (sw_if_index);
903 clib_error_return (0,
904 "`bfd_udp_set_echo_source' API call failed, rv=%d:%U",
905 (int) rv, format_vnet_api_errno, rv);
914 VLIB_CLI_COMMAND (bfd_cli_udp_set_echo_source_cmd, static) = {
915 .path = "bfd udp echo-source set",
916 .short_help = "bfd udp echo-source set interface <interface>",
917 .function = bfd_cli_udp_set_echo_source,
921 static clib_error_t *
922 bfd_cli_udp_del_echo_source (vlib_main_t * vm, unformat_input_t * input,
923 CLIB_UNUSED (vlib_cli_command_t * lmd))
925 vnet_api_error_t rv = bfd_udp_del_echo_source ();
928 return clib_error_return (0,
929 "`bfd_udp_del_echo_source' API call failed, rv=%d:%U",
930 (int) rv, format_vnet_api_errno, rv);
937 VLIB_CLI_COMMAND (bfd_cli_udp_del_echo_source_cmd, static) = {
938 .path = "bfd udp echo-source del",
939 .short_help = "bfd udp echo-source del",
940 .function = bfd_cli_udp_del_echo_source,
945 * fd.io coding-style-patch-verification: ON
948 * eval: (c-set-style "gnu")