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