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