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