blob: cab20a65b0b689ec65491ee32e2b4980224ed92a [file] [log] [blame]
Klement Sekera73884482017-02-23 09:26:30 +01001/*
2 * Copyright (c) 2011-2016 Cisco and/or its affiliates.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at:
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15/**
16 * @file
17 * @brief BFD CLI implementation
18 */
19
20#include <vlib/vlib.h>
21#include <vlib/cli.h>
22#include <vppinfra/format.h>
Gabriel Gannebeb85cc2017-11-07 14:24:56 +010023#include <vppinfra/warnings.h>
Klement Sekera73884482017-02-23 09:26:30 +010024#include <vnet/api_errno.h>
25#include <vnet/ip/format.h>
26#include <vnet/bfd/bfd_api.h>
27#include <vnet/bfd/bfd_main.h>
28
29static u8 *
30format_bfd_session_cli (u8 * s, va_list * args)
31{
Klement Sekerae50e8562017-04-04 16:19:48 +020032 vlib_main_t *vm = va_arg (*args, vlib_main_t *);
Klement Sekera73884482017-02-23 09:26:30 +010033 bfd_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 Sekerae50e8562017-04-04 16:19:48 +020056 s = format (s, "%10s %-32s %20u %20llu\n", "",
Klement Sekera73884482017-02-23 09:26:30 +010057 "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 Sekerae50e8562017-04-04 16:19:48 +020066 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 Sekera73884482017-02-23 09:26:30 +010082 s =
Klement Sekerae50e8562017-04-04 16:19:48 +020083 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 Sekera73884482017-02-23 09:26:30 +0100106 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 Sekerae50e8562017-04-04 16:19:48 +0200112 s = format (s, "%10s %-32s %20u %20u\n", "", "Sequence number",
113 bs->auth.local_seq_number, bs->auth.remote_seq_number);
Klement Sekera73884482017-02-23 09:26:30 +0100114 }
115 return s;
116}
117
118static clib_error_t *
119show_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;
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100124 unformat_input_t _line_input, *line_input = &_line_input;
Klement Sekera73884482017-02-23 09:26:30 +0100125
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100126 /* Get a line of input. */
127 if (!unformat_user (input, unformat_line_input, line_input))
128 return 0;
129
130 if (unformat (line_input, "keys"))
Klement Sekera73884482017-02-23 09:26:30 +0100131 {
132 bfd_auth_key_t *key = NULL;
133 u8 *s = format (NULL, "%=10s %=25s %=10s\n", "Configuration Key ID",
134 "Type", "Use Count");
135 /* *INDENT-OFF* */
136 pool_foreach (key, bm->auth_keys, {
137 s = format (s, "%10u %-25s %10u\n", key->conf_key_id,
138 bfd_auth_type_str (key->auth_type), key->use_count);
139 });
140 /* *INDENT-ON* */
141 vlib_cli_output (vm, "%v\n", s);
Klement Sekerae50e8562017-04-04 16:19:48 +0200142 vec_free (s);
Klement Sekera73884482017-02-23 09:26:30 +0100143 vlib_cli_output (vm, "Number of configured BFD keys: %lu\n",
144 (u64) pool_elts (bm->auth_keys));
145 }
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100146 else if (unformat (line_input, "sessions"))
Klement Sekera73884482017-02-23 09:26:30 +0100147 {
148 u8 *s = format (NULL, "%=10s %=32s %=20s %=20s\n", "Index", "Property",
149 "Local value", "Remote value");
150 /* *INDENT-OFF* */
Klement Sekerae50e8562017-04-04 16:19:48 +0200151 pool_foreach (bs, bm->sessions, {
152 s = format (s, "%U", format_bfd_session_cli, vm, bm, bs);
153 });
Klement Sekera73884482017-02-23 09:26:30 +0100154 /* *INDENT-ON* */
155 vlib_cli_output (vm, "%v", s);
156 vec_free (s);
157 vlib_cli_output (vm, "Number of configured BFD sessions: %lu\n",
158 (u64) pool_elts (bm->sessions));
159 }
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100160 else if (unformat (line_input, "echo-source"))
Klement Sekera73884482017-02-23 09:26:30 +0100161 {
162 int is_set;
163 u32 sw_if_index;
164 int have_usable_ip4;
165 ip4_address_t ip4;
166 int have_usable_ip6;
167 ip6_address_t ip6;
168 bfd_udp_get_echo_source (&is_set, &sw_if_index, &have_usable_ip4, &ip4,
169 &have_usable_ip6, &ip6);
170 if (is_set)
171 {
172 vnet_sw_interface_t *sw_if =
173 vnet_get_sw_interface_safe (&vnet_main, sw_if_index);
174 vnet_hw_interface_t *hw_if =
175 vnet_get_hw_interface (&vnet_main, sw_if->hw_if_index);
176 u8 *s = format (NULL, "UDP echo source is: %v\n", hw_if->name);
177 s = format (s, "IPv4 address usable as echo source: ");
178 if (have_usable_ip4)
179 {
180 s = format (s, "%U\n", format_ip4_address, &ip4);
181 }
182 else
183 {
184 s = format (s, "none\n");
185 }
186 s = format (s, "IPv6 address usable as echo source: ");
187 if (have_usable_ip6)
188 {
189 s = format (s, "%U\n", format_ip6_address, &ip6);
190 }
191 else
192 {
193 s = format (s, "none\n");
194 }
195 vlib_cli_output (vm, "%v", s);
196 vec_free (s);
197 }
198 else
199 {
200 vlib_cli_output (vm, "UDP echo source is not set.\n");
201 }
202 }
203 else
204 {
205 vlib_cli_output (vm, "Number of configured BFD sessions: %lu\n",
206 (u64) pool_elts (bm->sessions));
207 vlib_cli_output (vm, "Number of configured BFD keys: %lu\n",
208 (u64) pool_elts (bm->auth_keys));
209 }
210 return 0;
211}
212
213/* *INDENT-OFF* */
214VLIB_CLI_COMMAND (show_bfd_command, static) = {
215 .path = "show bfd",
216 .short_help = "show bfd [keys|sessions|echo-source]",
217 .function = show_bfd,
218};
219/* *INDENT-ON* */
220
Klement Sekera73884482017-02-23 09:26:30 +0100221static clib_error_t *
222bfd_cli_key_add (vlib_main_t * vm, unformat_input_t * input,
223 CLIB_UNUSED (vlib_cli_command_t * lmd))
224{
225 clib_error_t *ret = NULL;
226 int have_key_id = 0;
227 u32 key_id = 0;
228 u8 *vec_auth_type = NULL;
229 bfd_auth_type_e auth_type = BFD_AUTH_TYPE_reserved;
230 u8 *secret = NULL;
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100231 unformat_input_t _line_input, *line_input = &_line_input;
Klement Sekera73884482017-02-23 09:26:30 +0100232 static const u8 keyed_sha1[] = "keyed-sha1";
233 static const u8 meticulous_keyed_sha1[] = "meticulous-keyed-sha1";
234
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100235 /* Get a line of input. */
236 if (!unformat_user (input, unformat_line_input, line_input))
237 return 0;
238
239 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
Klement Sekera73884482017-02-23 09:26:30 +0100240 {
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100241 if (unformat (line_input, "conf-key-id %u", &key_id))
Klement Sekera73884482017-02-23 09:26:30 +0100242 {
243 have_key_id = 1;
244 }
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100245 else if (unformat (line_input, "type %U", unformat_token, "a-zA-Z0-9-",
Klement Sekera73884482017-02-23 09:26:30 +0100246 &vec_auth_type))
247 {
248 if (vec_len (vec_auth_type) == sizeof (keyed_sha1) - 1 &&
249 0 == memcmp (vec_auth_type, keyed_sha1,
250 sizeof (keyed_sha1) - 1))
251 {
252 auth_type = BFD_AUTH_TYPE_keyed_sha1;
253 }
254 else if (vec_len (vec_auth_type) ==
255 sizeof (meticulous_keyed_sha1) - 1 &&
256 0 == memcmp (vec_auth_type, meticulous_keyed_sha1,
257 sizeof (meticulous_keyed_sha1) - 1))
258 {
259 auth_type = BFD_AUTH_TYPE_meticulous_keyed_sha1;
260 }
261 else
262 {
263 ret = clib_error_return (0, "invalid type `%v'", vec_auth_type);
264 goto out;
265 }
266 }
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100267 else
268 if (unformat (line_input, "secret %U", unformat_hex_string, &secret))
Klement Sekera73884482017-02-23 09:26:30 +0100269 {
270 /* nothing to do here */
271 }
272 else
273 {
274 ret = clib_error_return (0, "Unknown input `%U'",
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100275 format_unformat_error, line_input);
Klement Sekera73884482017-02-23 09:26:30 +0100276 goto out;
277 }
278 }
279
280 if (!have_key_id)
281 {
282 ret =
283 clib_error_return (0, "required parameter missing: `conf-key-id'");
284 goto out;
285 }
286 if (!vec_auth_type)
287 {
288 ret = clib_error_return (0, "required parameter missing: `type'");
289 goto out;
290 }
291 if (!secret)
292 {
293 ret = clib_error_return (0, "required parameter missing: `secret'");
294 goto out;
295 }
296
297 vnet_api_error_t rv =
298 bfd_auth_set_key (key_id, auth_type, vec_len (secret), secret);
299 if (rv)
300 {
301 ret =
302 clib_error_return (0, "`bfd_auth_set_key' API call failed, rv=%d:%U",
303 (int) rv, format_vnet_api_errno, rv);
304 }
305
306out:
307 vec_free (vec_auth_type);
308 return ret;
309}
310
311/* *INDENT-OFF* */
312VLIB_CLI_COMMAND (bfd_cli_key_add_command, static) = {
313 .path = "bfd key set",
314 .short_help = "bfd key set"
315 " conf-key-id <id>"
316 " type <keyed-sha1|meticulous-keyed-sha1> "
317 " secret <secret>",
318 .function = bfd_cli_key_add,
319};
320/* *INDENT-ON* */
321
322static clib_error_t *
323bfd_cli_key_del (vlib_main_t * vm, unformat_input_t * input,
324 CLIB_UNUSED (vlib_cli_command_t * lmd))
325{
326 clib_error_t *ret = NULL;
327 u32 key_id = 0;
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100328 unformat_input_t _line_input, *line_input = &_line_input;
Klement Sekera73884482017-02-23 09:26:30 +0100329
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100330 /* Get a line of input. */
331 if (!unformat_user (input, unformat_line_input, line_input))
332 return 0;
333
334 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
Klement Sekera73884482017-02-23 09:26:30 +0100335 {
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100336 if (!unformat (line_input, "conf-key-id %u", &key_id))
Klement Sekera73884482017-02-23 09:26:30 +0100337 {
338 ret = clib_error_return (0, "Unknown input `%U'",
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100339 format_unformat_error, line_input);
Klement Sekera73884482017-02-23 09:26:30 +0100340 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
352out:
353 return ret;
354}
355
356/* *INDENT-OFF* */
357VLIB_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
375static const unsigned mandatory = 1;
376static 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, ...) \
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100383 if (unformat (line_input, s " " __VA_ARGS__, &n)) \
Klement Sekera73884482017-02-23 09:26:30 +0100384 { \
385 something_parsed = 1; \
386 have_##n = 1; \
387 }
388
389#define CHECK_MANDATORY(t, n, s, r, ...) \
Gabriel Gannebeb85cc2017-11-07 14:24:56 +0100390WARN_OFF(tautological-compare) \
Klement Sekera73884482017-02-23 09:26:30 +0100391 if (mandatory == r && !have_##n) \
392 { \
Gabriel Gannebeb85cc2017-11-07 14:24:56 +0100393 WARN_ON(tautological-compare) \
Klement Sekerae50e8562017-04-04 16:19:48 +0200394 ret = clib_error_return (0, "Required parameter `%s' missing.", s); \
Klement Sekera73884482017-02-23 09:26:30 +0100395 goto out; \
396 }
397
398static clib_error_t *
399bfd_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;
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100403 unformat_input_t _line_input, *line_input = &_line_input;
Klement Sekera73884482017-02-23 09:26:30 +0100404#define foreach_bfd_cli_udp_session_add_cli_param(F) \
405 F (u32, sw_if_index, INTERFACE_STR, mandatory, "%U", \
406 unformat_vnet_sw_interface, &vnet_main) \
407 F (ip46_address_t, local_addr, LOCAL_ADDR_STR, mandatory, "%U", \
408 unformat_ip46_address) \
409 F (ip46_address_t, peer_addr, PEER_ADDR_STR, mandatory, "%U", \
410 unformat_ip46_address) \
411 F (u32, desired_min_tx, DESIRED_MIN_TX_STR, mandatory, "%u") \
412 F (u32, required_min_rx, REQUIRED_MIN_RX_STR, mandatory, "%u") \
413 F (u32, detect_mult, DETECT_MULT_STR, mandatory, "%u") \
414 F (u32, conf_key_id, CONF_KEY_ID_STR, optional, "%u") \
415 F (u32, bfd_key_id, BFD_KEY_ID_STR, optional, "%u")
416
417 foreach_bfd_cli_udp_session_add_cli_param (DECLARE);
418
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100419 /* Get a line of input. */
420 if (!unformat_user (input, unformat_line_input, line_input))
421 return 0;
422
423 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
Klement Sekera73884482017-02-23 09:26:30 +0100424 {
425 int something_parsed = 0;
426 foreach_bfd_cli_udp_session_add_cli_param (UNFORMAT);
427
428 if (!something_parsed)
429 {
430 ret = clib_error_return (0, "Unknown input `%U'",
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100431 format_unformat_error, line_input);
Klement Sekera73884482017-02-23 09:26:30 +0100432 goto out;
433 }
434 }
435
436 foreach_bfd_cli_udp_session_add_cli_param (CHECK_MANDATORY);
437
438 if (1 == have_conf_key_id + have_bfd_key_id)
439 {
440 ret = clib_error_return (0, "Incompatible parameter combination, `%s' "
441 "and `%s' must be either both specified or none",
442 CONF_KEY_ID_STR, BFD_KEY_ID_STR);
443 goto out;
444 }
445
446 if (detect_mult > 255)
447 {
448 ret = clib_error_return (0, "%s value `%u' out of range <1,255>",
449 DETECT_MULT_STR, detect_mult);
450 goto out;
451 }
452
453 if (have_bfd_key_id && bfd_key_id > 255)
454 {
455 ret = clib_error_return (0, "%s value `%u' out of range <1,255>",
456 BFD_KEY_ID_STR, bfd_key_id);
457 goto out;
458 }
459
460 vnet_api_error_t rv =
461 bfd_udp_add_session (sw_if_index, &local_addr, &peer_addr, desired_min_tx,
462 required_min_rx,
463 detect_mult, have_conf_key_id, conf_key_id,
464 bfd_key_id);
465 if (rv)
466 {
467 ret =
468 clib_error_return (0,
469 "`bfd_add_add_session' API call failed, rv=%d:%U",
470 (int) rv, format_vnet_api_errno, rv);
471 goto out;
472 }
473
474out:
475 return ret;
476}
477
478/* *INDENT-OFF* */
479VLIB_CLI_COMMAND (bfd_cli_udp_session_add_command, static) = {
480 .path = "bfd udp session add",
481 .short_help = "bfd udp session add"
482 " interface <interface>"
483 " local-addr <local-address>"
484 " peer-addr <peer-address>"
485 " desired-min-tx <desired min tx interval>"
486 " required-min-rx <required min rx interval>"
487 " detect-mult <detect multiplier> "
488 "["
489 " conf-key-id <config key ID>"
490 " bfd-key-id <BFD key ID>"
491 "]",
492 .function = bfd_cli_udp_session_add,
493};
494/* *INDENT-ON* */
495
496static clib_error_t *
497bfd_cli_udp_session_mod (vlib_main_t * vm, unformat_input_t * input,
498 CLIB_UNUSED (vlib_cli_command_t * lmd))
499{
500 clib_error_t *ret = NULL;
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100501 unformat_input_t _line_input, *line_input = &_line_input;
Klement Sekera73884482017-02-23 09:26:30 +0100502#define foreach_bfd_cli_udp_session_mod_cli_param(F) \
503 F (u32, sw_if_index, INTERFACE_STR, mandatory, "%U", \
504 unformat_vnet_sw_interface, &vnet_main) \
505 F (ip46_address_t, local_addr, LOCAL_ADDR_STR, mandatory, "%U", \
506 unformat_ip46_address) \
507 F (ip46_address_t, peer_addr, PEER_ADDR_STR, mandatory, "%U", \
508 unformat_ip46_address) \
509 F (u32, desired_min_tx, DESIRED_MIN_TX_STR, mandatory, "%u") \
510 F (u32, required_min_rx, REQUIRED_MIN_RX_STR, mandatory, "%u") \
511 F (u32, detect_mult, DETECT_MULT_STR, mandatory, "%u")
512
513 foreach_bfd_cli_udp_session_mod_cli_param (DECLARE);
514
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100515 /* Get a line of input. */
516 if (!unformat_user (input, unformat_line_input, line_input))
517 return 0;
518
519 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
Klement Sekera73884482017-02-23 09:26:30 +0100520 {
521 int something_parsed = 0;
522 foreach_bfd_cli_udp_session_mod_cli_param (UNFORMAT);
523
524 if (!something_parsed)
525 {
526 ret = clib_error_return (0, "Unknown input `%U'",
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100527 format_unformat_error, line_input);
Klement Sekera73884482017-02-23 09:26:30 +0100528 goto out;
529 }
530 }
531
532 foreach_bfd_cli_udp_session_mod_cli_param (CHECK_MANDATORY);
533
534 if (detect_mult > 255)
535 {
536 ret = clib_error_return (0, "%s value `%u' out of range <1,255>",
537 DETECT_MULT_STR, detect_mult);
538 goto out;
539 }
540
541 vnet_api_error_t rv =
542 bfd_udp_mod_session (sw_if_index, &local_addr, &peer_addr,
543 desired_min_tx, required_min_rx, detect_mult);
544 if (rv)
545 {
546 ret =
547 clib_error_return (0,
548 "`bfd_udp_mod_session' API call failed, rv=%d:%U",
549 (int) rv, format_vnet_api_errno, rv);
550 goto out;
551 }
552
553out:
554 return ret;
555}
556
557/* *INDENT-OFF* */
558VLIB_CLI_COMMAND (bfd_cli_udp_session_mod_command, static) = {
559 .path = "bfd udp session mod",
560 .short_help = "bfd udp session mod interface"
561 " <interface> local-addr"
562 " <local-address> peer-addr"
563 " <peer-address> desired-min-tx"
564 " <desired min tx interval> required-min-rx"
565 " <required min rx interval> detect-mult"
566 " <detect multiplier> ",
567 .function = bfd_cli_udp_session_mod,
568};
569/* *INDENT-ON* */
570
571static clib_error_t *
572bfd_cli_udp_session_del (vlib_main_t * vm, unformat_input_t * input,
573 CLIB_UNUSED (vlib_cli_command_t * lmd))
574{
575 clib_error_t *ret = NULL;
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100576 unformat_input_t _line_input, *line_input = &_line_input;
Klement Sekera73884482017-02-23 09:26:30 +0100577#define foreach_bfd_cli_udp_session_del_cli_param(F) \
578 F (u32, sw_if_index, INTERFACE_STR, mandatory, "%U", \
579 unformat_vnet_sw_interface, &vnet_main) \
580 F (ip46_address_t, local_addr, LOCAL_ADDR_STR, mandatory, "%U", \
581 unformat_ip46_address) \
582 F (ip46_address_t, peer_addr, PEER_ADDR_STR, mandatory, "%U", \
583 unformat_ip46_address)
584
585 foreach_bfd_cli_udp_session_del_cli_param (DECLARE);
586
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100587 /* Get a line of input. */
588 if (!unformat_user (input, unformat_line_input, line_input))
589 return 0;
590
591 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
Klement Sekera73884482017-02-23 09:26:30 +0100592 {
593 int something_parsed = 0;
594 foreach_bfd_cli_udp_session_del_cli_param (UNFORMAT);
595
596 if (!something_parsed)
597 {
598 ret = clib_error_return (0, "Unknown input `%U'",
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100599 format_unformat_error, line_input);
Klement Sekera73884482017-02-23 09:26:30 +0100600 goto out;
601 }
602 }
603
604 foreach_bfd_cli_udp_session_del_cli_param (CHECK_MANDATORY);
605
606 vnet_api_error_t rv =
607 bfd_udp_del_session (sw_if_index, &local_addr, &peer_addr);
608 if (rv)
609 {
610 ret =
611 clib_error_return (0,
612 "`bfd_udp_del_session' API call failed, rv=%d:%U",
613 (int) rv, format_vnet_api_errno, rv);
614 goto out;
615 }
616
617out:
618 return ret;
619}
620
621/* *INDENT-OFF* */
622VLIB_CLI_COMMAND (bfd_cli_udp_session_del_command, static) = {
623 .path = "bfd udp session del",
624 .short_help = "bfd udp session del interface"
625 " <interface> local-addr"
626 " <local-address> peer-addr"
627 "<peer-address> ",
628 .function = bfd_cli_udp_session_del,
629};
630/* *INDENT-ON* */
631
632static clib_error_t *
633bfd_cli_udp_session_set_flags (vlib_main_t * vm, unformat_input_t * input,
634 CLIB_UNUSED (vlib_cli_command_t * lmd))
635{
636 clib_error_t *ret = NULL;
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100637 unformat_input_t _line_input, *line_input = &_line_input;
Klement Sekera73884482017-02-23 09:26:30 +0100638#define foreach_bfd_cli_udp_session_set_flags_cli_param(F) \
639 F (u32, sw_if_index, INTERFACE_STR, mandatory, "%U", \
640 unformat_vnet_sw_interface, &vnet_main) \
641 F (ip46_address_t, local_addr, LOCAL_ADDR_STR, mandatory, "%U", \
642 unformat_ip46_address) \
643 F (ip46_address_t, peer_addr, PEER_ADDR_STR, mandatory, "%U", \
644 unformat_ip46_address) \
645 F (u8 *, admin_up_down_token, ADMIN_STR, mandatory, "%v", \
646 &admin_up_down_token)
647
648 foreach_bfd_cli_udp_session_set_flags_cli_param (DECLARE);
649
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100650 /* Get a line of input. */
651 if (!unformat_user (input, unformat_line_input, line_input))
652 return 0;
653
654 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
Klement Sekera73884482017-02-23 09:26:30 +0100655 {
656 int something_parsed = 0;
657 foreach_bfd_cli_udp_session_set_flags_cli_param (UNFORMAT);
658
659 if (!something_parsed)
660 {
661 ret = clib_error_return (0, "Unknown input `%U'",
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100662 format_unformat_error, line_input);
Klement Sekera73884482017-02-23 09:26:30 +0100663 goto out;
664 }
665 }
666
667 foreach_bfd_cli_udp_session_set_flags_cli_param (CHECK_MANDATORY);
668
669 u8 admin_up_down;
670 static const char up[] = "up";
671 static const char down[] = "down";
672 if (!memcmp (admin_up_down_token, up, sizeof (up) - 1))
673 {
674 admin_up_down = 1;
675 }
676 else if (!memcmp (admin_up_down_token, down, sizeof (down) - 1))
677 {
678 admin_up_down = 0;
679 }
680 else
681 {
682 ret =
683 clib_error_return (0, "Unrecognized value for `%s' parameter: `%v'",
684 ADMIN_STR, admin_up_down_token);
685 goto out;
686 }
687 vnet_api_error_t rv = bfd_udp_session_set_flags (sw_if_index, &local_addr,
688 &peer_addr, admin_up_down);
689 if (rv)
690 {
691 ret =
692 clib_error_return (0,
693 "`bfd_udp_session_set_flags' API call failed, rv=%d:%U",
694 (int) rv, format_vnet_api_errno, rv);
695 goto out;
696 }
697
698out:
699 return ret;
700}
701
702/* *INDENT-OFF* */
703VLIB_CLI_COMMAND (bfd_cli_udp_session_set_flags_command, static) = {
704 .path = "bfd udp session set-flags",
705 .short_help = "bfd udp session set-flags"
706 " interface <interface>"
707 " local-addr <local-address>"
708 " peer-addr <peer-address>"
709 " admin <up|down>",
710 .function = bfd_cli_udp_session_set_flags,
711};
712/* *INDENT-ON* */
713
714static clib_error_t *
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100715bfd_cli_udp_session_auth_activate (vlib_main_t * vm,
716 unformat_input_t * input,
Klement Sekera73884482017-02-23 09:26:30 +0100717 CLIB_UNUSED (vlib_cli_command_t * lmd))
718{
719 clib_error_t *ret = NULL;
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100720 unformat_input_t _line_input, *line_input = &_line_input;
Klement Sekera73884482017-02-23 09:26:30 +0100721#define foreach_bfd_cli_udp_session_auth_activate_cli_param(F) \
722 F (u32, sw_if_index, INTERFACE_STR, mandatory, "%U", \
723 unformat_vnet_sw_interface, &vnet_main) \
724 F (ip46_address_t, local_addr, LOCAL_ADDR_STR, mandatory, "%U", \
725 unformat_ip46_address) \
726 F (ip46_address_t, peer_addr, PEER_ADDR_STR, mandatory, "%U", \
727 unformat_ip46_address) \
728 F (u8 *, delayed_token, DELAYED_STR, optional, "%v") \
729 F (u32, conf_key_id, CONF_KEY_ID_STR, mandatory, "%u") \
730 F (u32, bfd_key_id, BFD_KEY_ID_STR, mandatory, "%u")
731
732 foreach_bfd_cli_udp_session_auth_activate_cli_param (DECLARE);
733
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100734 /* Get a line of input. */
735 if (!unformat_user (input, unformat_line_input, line_input))
736 return 0;
737
738 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
Klement Sekera73884482017-02-23 09:26:30 +0100739 {
740 int something_parsed = 0;
741 foreach_bfd_cli_udp_session_auth_activate_cli_param (UNFORMAT);
742
743 if (!something_parsed)
744 {
745 ret = clib_error_return (0, "Unknown input `%U'",
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100746 format_unformat_error, line_input);
Klement Sekera73884482017-02-23 09:26:30 +0100747 goto out;
748 }
749 }
750
751 foreach_bfd_cli_udp_session_auth_activate_cli_param (CHECK_MANDATORY);
752
753 u8 is_delayed = 0;
754 if (have_delayed_token)
755 {
756 static const char yes[] = "yes";
757 static const char no[] = "no";
758 if (!memcmp (delayed_token, yes, sizeof (yes) - 1))
759 {
760 is_delayed = 1;
761 }
762 else if (!memcmp (delayed_token, no, sizeof (no) - 1))
763 {
764 is_delayed = 0;
765 }
766 else
767 {
768 ret =
769 clib_error_return (0,
770 "Unrecognized value for `%s' parameter: `%v'",
771 DELAYED_STR, delayed_token);
772 goto out;
773 }
774 }
775
776 if (have_bfd_key_id && bfd_key_id > 255)
777 {
778 ret = clib_error_return (0, "%s value `%u' out of range <1,255>",
779 BFD_KEY_ID_STR, bfd_key_id);
780 goto out;
781 }
782
783 vnet_api_error_t rv =
784 bfd_udp_auth_activate (sw_if_index, &local_addr, &peer_addr, conf_key_id,
785 bfd_key_id, is_delayed);
786 if (rv)
787 {
788 ret =
789 clib_error_return (0,
790 "`bfd_udp_auth_activate' API call failed, rv=%d:%U",
791 (int) rv, format_vnet_api_errno, rv);
792 goto out;
793 }
794
795out:
796 return ret;
797}
798
799/* *INDENT-OFF* */
800VLIB_CLI_COMMAND (bfd_cli_udp_session_auth_activate_command, static) = {
801 .path = "bfd udp session auth activate",
802 .short_help = "bfd udp session auth activate"
803 " interface <interface>"
804 " local-addr <local-address>"
805 " peer-addr <peer-address>"
806 " conf-key-id <config key ID>"
807 " bfd-key-id <BFD key ID>"
Klement Sekerab16bfe32017-02-28 11:56:48 +0100808 " [ delayed <yes|no> ]",
Klement Sekera73884482017-02-23 09:26:30 +0100809 .function = bfd_cli_udp_session_auth_activate,
810};
811
812static clib_error_t *
813bfd_cli_udp_session_auth_deactivate (vlib_main_t *vm, unformat_input_t *input,
814 CLIB_UNUSED (vlib_cli_command_t *lmd))
815{
816 clib_error_t *ret = NULL;
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100817 unformat_input_t _line_input, *line_input = &_line_input;
Klement Sekera73884482017-02-23 09:26:30 +0100818#define foreach_bfd_cli_udp_session_auth_deactivate_cli_param(F) \
819 F (u32, sw_if_index, INTERFACE_STR, mandatory, "%U", \
820 unformat_vnet_sw_interface, &vnet_main) \
821 F (ip46_address_t, local_addr, LOCAL_ADDR_STR, mandatory, "%U", \
822 unformat_ip46_address) \
823 F (ip46_address_t, peer_addr, PEER_ADDR_STR, mandatory, "%U", \
824 unformat_ip46_address) \
825 F (u8 *, delayed_token, DELAYED_STR, optional, "%v")
826
827 foreach_bfd_cli_udp_session_auth_deactivate_cli_param (DECLARE);
828
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100829 /* Get a line of input. */
830 if (!unformat_user (input, unformat_line_input, line_input))
831 return 0;
832
833 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
Klement Sekera73884482017-02-23 09:26:30 +0100834 {
835 int something_parsed = 0;
836 foreach_bfd_cli_udp_session_auth_deactivate_cli_param (UNFORMAT);
837
838 if (!something_parsed)
839 {
840 ret = clib_error_return (0, "Unknown input `%U'",
841 format_unformat_error, input);
842 goto out;
843 }
844 }
845
846 foreach_bfd_cli_udp_session_auth_deactivate_cli_param (CHECK_MANDATORY);
847
848 u8 is_delayed = 0;
849 if (have_delayed_token)
850 {
851 static const char yes[] = "yes";
852 static const char no[] = "no";
853 if (!memcmp (delayed_token, yes, sizeof (yes) - 1))
854 {
855 is_delayed = 1;
856 }
857 else if (!memcmp (delayed_token, no, sizeof (no) - 1))
858 {
859 is_delayed = 0;
860 }
861 else
862 {
863 ret = clib_error_return (
864 0, "Unrecognized value for `%s' parameter: `%v'", DELAYED_STR,
865 delayed_token);
866 goto out;
867 }
868 }
869
870 vnet_api_error_t rv = bfd_udp_auth_deactivate (sw_if_index, &local_addr,
871 &peer_addr, is_delayed);
872 if (rv)
873 {
874 ret = clib_error_return (
875 0, "`bfd_udp_auth_deactivate' API call failed, rv=%d:%U", (int)rv,
876 format_vnet_api_errno, rv);
877 goto out;
878 }
879
880out:
881 return ret;
882}
883
884/* *INDENT-OFF* */
885VLIB_CLI_COMMAND (bfd_cli_udp_session_auth_deactivate_command, static) = {
886 .path = "bfd udp session auth deactivate",
887 .short_help = "bfd udp session auth deactivate"
888 " interface <interface>"
889 " local-addr <local-address>"
890 " peer-addr <peer-address>"
Klement Sekerab16bfe32017-02-28 11:56:48 +0100891 "[ delayed <yes|no> ]",
Klement Sekera73884482017-02-23 09:26:30 +0100892 .function = bfd_cli_udp_session_auth_deactivate,
893};
894/* *INDENT-ON* */
895
896static clib_error_t *
897bfd_cli_udp_set_echo_source (vlib_main_t * vm, unformat_input_t * input,
898 CLIB_UNUSED (vlib_cli_command_t * lmd))
899{
900 clib_error_t *ret = NULL;
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100901 unformat_input_t _line_input, *line_input = &_line_input;
Klement Sekera73884482017-02-23 09:26:30 +0100902#define foreach_bfd_cli_udp_set_echo_source_cli_param(F) \
903 F (u32, sw_if_index, INTERFACE_STR, mandatory, "%U", \
904 unformat_vnet_sw_interface, &vnet_main)
905
906 foreach_bfd_cli_udp_set_echo_source_cli_param (DECLARE);
907
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100908 /* Get a line of input. */
909 if (!unformat_user (input, unformat_line_input, line_input))
910 return 0;
911
912 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
Klement Sekera73884482017-02-23 09:26:30 +0100913 {
914 int something_parsed = 0;
915 foreach_bfd_cli_udp_set_echo_source_cli_param (UNFORMAT);
916
917 if (!something_parsed)
918 {
919 ret = clib_error_return (0, "Unknown input `%U'",
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100920 format_unformat_error, line_input);
Klement Sekera73884482017-02-23 09:26:30 +0100921 goto out;
922 }
923 }
924
925 foreach_bfd_cli_udp_set_echo_source_cli_param (CHECK_MANDATORY);
926
927 vnet_api_error_t rv = bfd_udp_set_echo_source (sw_if_index);
928 if (rv)
929 {
930 ret =
931 clib_error_return (0,
932 "`bfd_udp_set_echo_source' API call failed, rv=%d:%U",
933 (int) rv, format_vnet_api_errno, rv);
934 goto out;
935 }
936
937out:
938 return ret;
939}
940
941/* *INDENT-OFF* */
942VLIB_CLI_COMMAND (bfd_cli_udp_set_echo_source_cmd, static) = {
943 .path = "bfd udp echo-source set",
944 .short_help = "bfd udp echo-source set interface <interface>",
945 .function = bfd_cli_udp_set_echo_source,
946};
947/* *INDENT-ON* */
948
949static clib_error_t *
950bfd_cli_udp_del_echo_source (vlib_main_t * vm, unformat_input_t * input,
951 CLIB_UNUSED (vlib_cli_command_t * lmd))
952{
953 vnet_api_error_t rv = bfd_udp_del_echo_source ();
954 if (rv)
955 {
956 return clib_error_return (0,
957 "`bfd_udp_del_echo_source' API call failed, rv=%d:%U",
958 (int) rv, format_vnet_api_errno, rv);
959 }
960
961 return 0;
962}
963
964/* *INDENT-OFF* */
965VLIB_CLI_COMMAND (bfd_cli_udp_del_echo_source_cmd, static) = {
966 .path = "bfd udp echo-source del",
967 .short_help = "bfd udp echo-source del",
968 .function = bfd_cli_udp_del_echo_source,
969};
970/* *INDENT-ON* */
971
972/*
973 * fd.io coding-style-patch-verification: ON
974 *
975 * Local Variables:
976 * eval: (c-set-style "gnu")
977 * End:
978 */