FD.io VPP  v17.04.2-2-ga8f93f8
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 #define CHECK_MANDATORY(t, n, s, r, ...) \
389  if (mandatory == r && !have_##n) \
390  { \
391  ret = clib_error_return (0, "Required parameter `%s' missing.", s); \
392  goto out; \
393  }
394 
395 static clib_error_t *
398 {
399  clib_error_t *ret = NULL;
400 #define foreach_bfd_cli_udp_session_add_cli_param(F) \
401  F (u32, sw_if_index, INTERFACE_STR, mandatory, "%U", \
402  unformat_vnet_sw_interface, &vnet_main) \
403  F (ip46_address_t, local_addr, LOCAL_ADDR_STR, mandatory, "%U", \
404  unformat_ip46_address) \
405  F (ip46_address_t, peer_addr, PEER_ADDR_STR, mandatory, "%U", \
406  unformat_ip46_address) \
407  F (u32, desired_min_tx, DESIRED_MIN_TX_STR, mandatory, "%u") \
408  F (u32, required_min_rx, REQUIRED_MIN_RX_STR, mandatory, "%u") \
409  F (u32, detect_mult, DETECT_MULT_STR, mandatory, "%u") \
410  F (u32, conf_key_id, CONF_KEY_ID_STR, optional, "%u") \
411  F (u32, bfd_key_id, BFD_KEY_ID_STR, optional, "%u")
412 
414 
416  {
417  int something_parsed = 0;
419 
420  if (!something_parsed)
421  {
422  ret = clib_error_return (0, "Unknown input `%U'",
423  format_unformat_error, input);
424  goto out;
425  }
426  }
427 
429 
430  if (1 == have_conf_key_id + have_bfd_key_id)
431  {
432  ret = clib_error_return (0, "Incompatible parameter combination, `%s' "
433  "and `%s' must be either both specified or none",
435  goto out;
436  }
437 
438  if (detect_mult > 255)
439  {
440  ret = clib_error_return (0, "%s value `%u' out of range <1,255>",
441  DETECT_MULT_STR, detect_mult);
442  goto out;
443  }
444 
445  if (have_bfd_key_id && bfd_key_id > 255)
446  {
447  ret = clib_error_return (0, "%s value `%u' out of range <1,255>",
448  BFD_KEY_ID_STR, bfd_key_id);
449  goto out;
450  }
451 
452  vnet_api_error_t rv =
453  bfd_udp_add_session (sw_if_index, &local_addr, &peer_addr, desired_min_tx,
454  required_min_rx,
455  detect_mult, have_conf_key_id, conf_key_id,
456  bfd_key_id);
457  if (rv)
458  {
459  ret =
461  "`bfd_add_add_session' API call failed, rv=%d:%U",
462  (int) rv, format_vnet_api_errno, rv);
463  goto out;
464  }
465 
466 out:
467  return ret;
468 }
469 
470 /* *INDENT-OFF* */
471 VLIB_CLI_COMMAND (bfd_cli_udp_session_add_command, static) = {
472  .path = "bfd udp session add",
473  .short_help = "bfd udp session add"
474  " interface <interface>"
475  " local-addr <local-address>"
476  " peer-addr <peer-address>"
477  " desired-min-tx <desired min tx interval>"
478  " required-min-rx <required min rx interval>"
479  " detect-mult <detect multiplier> "
480  "["
481  " conf-key-id <config key ID>"
482  " bfd-key-id <BFD key ID>"
483  "]",
484  .function = bfd_cli_udp_session_add,
485 };
486 /* *INDENT-ON* */
487 
488 static clib_error_t *
491 {
492  clib_error_t *ret = NULL;
493 #define foreach_bfd_cli_udp_session_mod_cli_param(F) \
494  F (u32, sw_if_index, INTERFACE_STR, mandatory, "%U", \
495  unformat_vnet_sw_interface, &vnet_main) \
496  F (ip46_address_t, local_addr, LOCAL_ADDR_STR, mandatory, "%U", \
497  unformat_ip46_address) \
498  F (ip46_address_t, peer_addr, PEER_ADDR_STR, mandatory, "%U", \
499  unformat_ip46_address) \
500  F (u32, desired_min_tx, DESIRED_MIN_TX_STR, mandatory, "%u") \
501  F (u32, required_min_rx, REQUIRED_MIN_RX_STR, mandatory, "%u") \
502  F (u32, detect_mult, DETECT_MULT_STR, mandatory, "%u")
503 
505 
507  {
508  int something_parsed = 0;
510 
511  if (!something_parsed)
512  {
513  ret = clib_error_return (0, "Unknown input `%U'",
514  format_unformat_error, input);
515  goto out;
516  }
517  }
518 
520 
521  if (detect_mult > 255)
522  {
523  ret = clib_error_return (0, "%s value `%u' out of range <1,255>",
524  DETECT_MULT_STR, detect_mult);
525  goto out;
526  }
527 
528  vnet_api_error_t rv =
529  bfd_udp_mod_session (sw_if_index, &local_addr, &peer_addr,
530  desired_min_tx, required_min_rx, detect_mult);
531  if (rv)
532  {
533  ret =
535  "`bfd_udp_mod_session' API call failed, rv=%d:%U",
536  (int) rv, format_vnet_api_errno, rv);
537  goto out;
538  }
539 
540 out:
541  return ret;
542 }
543 
544 /* *INDENT-OFF* */
545 VLIB_CLI_COMMAND (bfd_cli_udp_session_mod_command, static) = {
546  .path = "bfd udp session mod",
547  .short_help = "bfd udp session mod interface"
548  " <interface> local-addr"
549  " <local-address> peer-addr"
550  " <peer-address> desired-min-tx"
551  " <desired min tx interval> required-min-rx"
552  " <required min rx interval> detect-mult"
553  " <detect multiplier> ",
554  .function = bfd_cli_udp_session_mod,
555 };
556 /* *INDENT-ON* */
557 
558 static clib_error_t *
561 {
562  clib_error_t *ret = NULL;
563 #define foreach_bfd_cli_udp_session_del_cli_param(F) \
564  F (u32, sw_if_index, INTERFACE_STR, mandatory, "%U", \
565  unformat_vnet_sw_interface, &vnet_main) \
566  F (ip46_address_t, local_addr, LOCAL_ADDR_STR, mandatory, "%U", \
567  unformat_ip46_address) \
568  F (ip46_address_t, peer_addr, PEER_ADDR_STR, mandatory, "%U", \
569  unformat_ip46_address)
570 
572 
574  {
575  int something_parsed = 0;
577 
578  if (!something_parsed)
579  {
580  ret = clib_error_return (0, "Unknown input `%U'",
581  format_unformat_error, input);
582  goto out;
583  }
584  }
585 
587 
588  vnet_api_error_t rv =
589  bfd_udp_del_session (sw_if_index, &local_addr, &peer_addr);
590  if (rv)
591  {
592  ret =
594  "`bfd_udp_del_session' API call failed, rv=%d:%U",
595  (int) rv, format_vnet_api_errno, rv);
596  goto out;
597  }
598 
599 out:
600  return ret;
601 }
602 
603 /* *INDENT-OFF* */
604 VLIB_CLI_COMMAND (bfd_cli_udp_session_del_command, static) = {
605  .path = "bfd udp session del",
606  .short_help = "bfd udp session del interface"
607  " <interface> local-addr"
608  " <local-address> peer-addr"
609  "<peer-address> ",
610  .function = bfd_cli_udp_session_del,
611 };
612 /* *INDENT-ON* */
613 
614 static clib_error_t *
617 {
618  clib_error_t *ret = NULL;
619 #define foreach_bfd_cli_udp_session_set_flags_cli_param(F) \
620  F (u32, sw_if_index, INTERFACE_STR, mandatory, "%U", \
621  unformat_vnet_sw_interface, &vnet_main) \
622  F (ip46_address_t, local_addr, LOCAL_ADDR_STR, mandatory, "%U", \
623  unformat_ip46_address) \
624  F (ip46_address_t, peer_addr, PEER_ADDR_STR, mandatory, "%U", \
625  unformat_ip46_address) \
626  F (u8 *, admin_up_down_token, ADMIN_STR, mandatory, "%v", \
627  &admin_up_down_token)
628 
630 
632  {
633  int something_parsed = 0;
635 
636  if (!something_parsed)
637  {
638  ret = clib_error_return (0, "Unknown input `%U'",
639  format_unformat_error, input);
640  goto out;
641  }
642  }
643 
645 
646  u8 admin_up_down;
647  static const char up[] = "up";
648  static const char down[] = "down";
649  if (!memcmp (admin_up_down_token, up, sizeof (up) - 1))
650  {
651  admin_up_down = 1;
652  }
653  else if (!memcmp (admin_up_down_token, down, sizeof (down) - 1))
654  {
655  admin_up_down = 0;
656  }
657  else
658  {
659  ret =
660  clib_error_return (0, "Unrecognized value for `%s' parameter: `%v'",
661  ADMIN_STR, admin_up_down_token);
662  goto out;
663  }
664  vnet_api_error_t rv = bfd_udp_session_set_flags (sw_if_index, &local_addr,
665  &peer_addr, admin_up_down);
666  if (rv)
667  {
668  ret =
670  "`bfd_udp_session_set_flags' API call failed, rv=%d:%U",
671  (int) rv, format_vnet_api_errno, rv);
672  goto out;
673  }
674 
675 out:
676  return ret;
677 }
678 
679 /* *INDENT-OFF* */
680 VLIB_CLI_COMMAND (bfd_cli_udp_session_set_flags_command, static) = {
681  .path = "bfd udp session set-flags",
682  .short_help = "bfd udp session set-flags"
683  " interface <interface>"
684  " local-addr <local-address>"
685  " peer-addr <peer-address>"
686  " admin <up|down>",
687  .function = bfd_cli_udp_session_set_flags,
688 };
689 /* *INDENT-ON* */
690 
691 static clib_error_t *
694 {
695  clib_error_t *ret = NULL;
696 #define foreach_bfd_cli_udp_session_auth_activate_cli_param(F) \
697  F (u32, sw_if_index, INTERFACE_STR, mandatory, "%U", \
698  unformat_vnet_sw_interface, &vnet_main) \
699  F (ip46_address_t, local_addr, LOCAL_ADDR_STR, mandatory, "%U", \
700  unformat_ip46_address) \
701  F (ip46_address_t, peer_addr, PEER_ADDR_STR, mandatory, "%U", \
702  unformat_ip46_address) \
703  F (u8 *, delayed_token, DELAYED_STR, optional, "%v") \
704  F (u32, conf_key_id, CONF_KEY_ID_STR, mandatory, "%u") \
705  F (u32, bfd_key_id, BFD_KEY_ID_STR, mandatory, "%u")
706 
708 
710  {
711  int something_parsed = 0;
713 
714  if (!something_parsed)
715  {
716  ret = clib_error_return (0, "Unknown input `%U'",
717  format_unformat_error, input);
718  goto out;
719  }
720  }
721 
723 
724  u8 is_delayed = 0;
725  if (have_delayed_token)
726  {
727  static const char yes[] = "yes";
728  static const char no[] = "no";
729  if (!memcmp (delayed_token, yes, sizeof (yes) - 1))
730  {
731  is_delayed = 1;
732  }
733  else if (!memcmp (delayed_token, no, sizeof (no) - 1))
734  {
735  is_delayed = 0;
736  }
737  else
738  {
739  ret =
741  "Unrecognized value for `%s' parameter: `%v'",
742  DELAYED_STR, delayed_token);
743  goto out;
744  }
745  }
746 
747  if (have_bfd_key_id && bfd_key_id > 255)
748  {
749  ret = clib_error_return (0, "%s value `%u' out of range <1,255>",
750  BFD_KEY_ID_STR, bfd_key_id);
751  goto out;
752  }
753 
754  vnet_api_error_t rv =
755  bfd_udp_auth_activate (sw_if_index, &local_addr, &peer_addr, conf_key_id,
756  bfd_key_id, is_delayed);
757  if (rv)
758  {
759  ret =
761  "`bfd_udp_auth_activate' API call failed, rv=%d:%U",
762  (int) rv, format_vnet_api_errno, rv);
763  goto out;
764  }
765 
766 out:
767  return ret;
768 }
769 
770 /* *INDENT-OFF* */
771 VLIB_CLI_COMMAND (bfd_cli_udp_session_auth_activate_command, static) = {
772  .path = "bfd udp session auth activate",
773  .short_help = "bfd udp session auth activate"
774  " interface <interface>"
775  " local-addr <local-address>"
776  " peer-addr <peer-address>"
777  " conf-key-id <config key ID>"
778  " bfd-key-id <BFD key ID>"
779  " [ delayed <yes|no> ]",
781 };
782 
783 static clib_error_t *
786 {
787  clib_error_t *ret = NULL;
788 #define foreach_bfd_cli_udp_session_auth_deactivate_cli_param(F) \
789  F (u32, sw_if_index, INTERFACE_STR, mandatory, "%U", \
790  unformat_vnet_sw_interface, &vnet_main) \
791  F (ip46_address_t, local_addr, LOCAL_ADDR_STR, mandatory, "%U", \
792  unformat_ip46_address) \
793  F (ip46_address_t, peer_addr, PEER_ADDR_STR, mandatory, "%U", \
794  unformat_ip46_address) \
795  F (u8 *, delayed_token, DELAYED_STR, optional, "%v")
796 
798 
800  {
801  int something_parsed = 0;
803 
804  if (!something_parsed)
805  {
806  ret = clib_error_return (0, "Unknown input `%U'",
807  format_unformat_error, input);
808  goto out;
809  }
810  }
811 
813 
814  u8 is_delayed = 0;
815  if (have_delayed_token)
816  {
817  static const char yes[] = "yes";
818  static const char no[] = "no";
819  if (!memcmp (delayed_token, yes, sizeof (yes) - 1))
820  {
821  is_delayed = 1;
822  }
823  else if (!memcmp (delayed_token, no, sizeof (no) - 1))
824  {
825  is_delayed = 0;
826  }
827  else
828  {
829  ret = clib_error_return (
830  0, "Unrecognized value for `%s' parameter: `%v'", DELAYED_STR,
831  delayed_token);
832  goto out;
833  }
834  }
835 
836  vnet_api_error_t rv = bfd_udp_auth_deactivate (sw_if_index, &local_addr,
837  &peer_addr, is_delayed);
838  if (rv)
839  {
840  ret = clib_error_return (
841  0, "`bfd_udp_auth_deactivate' API call failed, rv=%d:%U", (int)rv,
843  goto out;
844  }
845 
846 out:
847  return ret;
848 }
849 
850 /* *INDENT-OFF* */
851 VLIB_CLI_COMMAND (bfd_cli_udp_session_auth_deactivate_command, static) = {
852  .path = "bfd udp session auth deactivate",
853  .short_help = "bfd udp session auth deactivate"
854  " interface <interface>"
855  " local-addr <local-address>"
856  " peer-addr <peer-address>"
857  "[ delayed <yes|no> ]",
859 };
860 /* *INDENT-ON* */
861 
862 static clib_error_t *
865 {
866  clib_error_t *ret = NULL;
867 #define foreach_bfd_cli_udp_set_echo_source_cli_param(F) \
868  F (u32, sw_if_index, INTERFACE_STR, mandatory, "%U", \
869  unformat_vnet_sw_interface, &vnet_main)
870 
872 
874  {
875  int something_parsed = 0;
877 
878  if (!something_parsed)
879  {
880  ret = clib_error_return (0, "Unknown input `%U'",
881  format_unformat_error, input);
882  goto out;
883  }
884  }
885 
887 
888  vnet_api_error_t rv = bfd_udp_set_echo_source (sw_if_index);
889  if (rv)
890  {
891  ret =
893  "`bfd_udp_set_echo_source' API call failed, rv=%d:%U",
894  (int) rv, format_vnet_api_errno, rv);
895  goto out;
896  }
897 
898 out:
899  return ret;
900 }
901 
902 /* *INDENT-OFF* */
903 VLIB_CLI_COMMAND (bfd_cli_udp_set_echo_source_cmd, static) = {
904  .path = "bfd udp echo-source set",
905  .short_help = "bfd udp echo-source set interface <interface>",
906  .function = bfd_cli_udp_set_echo_source,
907 };
908 /* *INDENT-ON* */
909 
910 static clib_error_t *
913 {
915  if (rv)
916  {
917  return clib_error_return (0,
918  "`bfd_udp_del_echo_source' API call failed, rv=%d:%U",
919  (int) rv, format_vnet_api_errno, rv);
920  }
921 
922  return 0;
923 }
924 
925 /* *INDENT-OFF* */
926 VLIB_CLI_COMMAND (bfd_cli_udp_del_echo_source_cmd, static) = {
927  .path = "bfd udp echo-source del",
928  .short_help = "bfd udp echo-source del",
929  .function = bfd_cli_udp_del_echo_source,
930 };
931 /* *INDENT-ON* */
932 
933 /*
934  * fd.io coding-style-patch-verification: ON
935  *
936  * Local Variables:
937  * eval: (c-set-style "gnu")
938  * End:
939  */
static u8 * format_vnet_api_errno(u8 *s, va_list *args)
Definition: bfd_cli.c:216
vnet_api_error_t
Definition: api_errno.h:109
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:201
#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:489
bfd_main_t bfd_main
Definition: bfd_main.c:2027
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:162
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:81
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:1991
u64 last_tx_clocks
timestamp of last packet transmitted
Definition: bfd_main.h:147
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:615
u8 * format(u8 *s, const char *fmt,...)
Definition: format.c:418
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:195
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:144
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:863
u64 remote_min_rx_usec
remote min rx interval (microseconds)
Definition: bfd_main.h:111
#define clib_error_return(e, args...)
Definition: error.h:111
#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:1937
#define foreach_bfd_cli_udp_session_auth_deactivate_cli_param(F)
#define CHECK_MANDATORY(t, n, s, r,...)
Definition: bfd_cli.c:388
u8 remote_demand
1 if remote system sets demand mode, 0 otherwise
Definition: bfd_main.h:129
bfd_session_t * sessions
pool of bfd sessions context data
Definition: bfd_main.h:226
bfd_auth_key_t * auth_keys
pool of authentication keys
Definition: bfd_main.h:257
bfd_udp_key_t key
key identifying this session
Definition: bfd_udp.h:43
bfd_transport_e transport
transport type for this session
Definition: bfd_main.h:214
#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:159
bfd_poll_state_e poll_state
state info regarding poll sequence
Definition: bfd_main.h:171
struct bfd_session_s::@35 auth
authentication information
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:784
#define foreach_bfd_cli_udp_session_set_flags_cli_param(F)
u8 local_detect_mult
configured detect multiplier
Definition: bfd_main.h:126
#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:150
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:219
#define DETECT_MULT_STR
Definition: bfd_cli.c:370
bfd_diag_code_e remote_diag
remote diagnostics
Definition: bfd_main.h:84
u64 transmit_interval_clocks
transmit interval
Definition: bfd_main.h:141
#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:93
#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:692
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:911
#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:135
u64 remote_desired_min_tx_clocks
remote desired min tx interval (clocks)
Definition: bfd_main.h:123
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:75
#define CONF_KEY_ID_STR
Definition: bfd_cli.c:366
u64 echo_transmit_interval_clocks
transmit interval for echo packets
Definition: bfd_main.h:153
u32 local_seq_number
sequence number incremented occasionally or always (if meticulous)
Definition: bfd_main.h:192
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:102
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:559
#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:72
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:117
bfd_state_e remote_state
remote session state
Definition: bfd_main.h:78
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:396
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:183
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
Definition: cli.c:577
#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:132
#define ADMIN_STR
Definition: bfd_cli.c:371
uword unformat(unformat_input_t *i, const char *fmt,...)
Definition: unformat.c:971
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