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