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