blob: 33942bb89e6dd17b53513aa78d33edbaeccab6a9 [file] [log] [blame]
Klement Sekera73884482017-02-23 09:26:30 +01001/*
2 * Copyright (c) 2011-2016 Cisco and/or its affiliates.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at:
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15/**
16 * @file
17 * @brief BFD CLI implementation
18 */
19
20#include <vlib/vlib.h>
21#include <vlib/cli.h>
22#include <vppinfra/format.h>
Gabriel Gannebeb85cc2017-11-07 14:24:56 +010023#include <vppinfra/warnings.h>
Klement Sekera73884482017-02-23 09:26:30 +010024#include <vnet/api_errno.h>
25#include <vnet/ip/format.h>
26#include <vnet/bfd/bfd_api.h>
27#include <vnet/bfd/bfd_main.h>
28
29static u8 *
30format_bfd_session_cli (u8 * s, va_list * args)
31{
Klement Sekerae50e8562017-04-04 16:19:48 +020032 vlib_main_t *vm = va_arg (*args, vlib_main_t *);
Klement Sekera73884482017-02-23 09:26:30 +010033 bfd_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",
48 bfd_state_string (bs->local_state),
49 bfd_state_string (bs->remote_state));
50 s = format (s, "%10s %-32s %20s %20s\n", "", "Diagnostic code",
51 bfd_diag_code_string (bs->local_diag),
52 bfd_diag_code_string (bs->remote_diag));
53 s = format (s, "%10s %-32s %20u %20u\n", "", "Detect multiplier",
54 bs->local_detect_mult, bs->remote_detect_mult);
Klement Sekerae50e8562017-04-04 16:19:48 +020055 s = format (s, "%10s %-32s %20u %20llu\n", "",
Klement Sekera73884482017-02-23 09:26:30 +010056 "Required Min Rx Interval (usec)",
57 bs->config_required_min_rx_usec, bs->remote_min_rx_usec);
58 s = format (s, "%10s %-32s %20u %20u\n", "",
59 "Desired Min Tx Interval (usec)",
Klement Sekeraa3167442020-02-10 11:49:52 +000060 bs->config_desired_min_tx_usec,
61 bfd_nsec_to_usec (bs->remote_desired_min_tx_nsec));
Klement Sekera73884482017-02-23 09:26:30 +010062 s =
63 format (s, "%10s %-32s %20u\n", "", "Transmit interval",
Klement Sekeraa3167442020-02-10 11:49:52 +000064 bfd_nsec_to_usec (bs->transmit_interval_nsec));
Klement Sekerae50e8562017-04-04 16:19:48 +020065 u64 now = clib_cpu_time_now ();
66 u8 *tmp = NULL;
Klement Sekeraa3167442020-02-10 11:49:52 +000067 if (bs->last_tx_nsec > 0)
Klement Sekerae50e8562017-04-04 16:19:48 +020068 {
Klement Sekeraa3167442020-02-10 11:49:52 +000069 tmp = format (tmp, "%.2fs ago", (now - bs->last_tx_nsec) *
Klement Sekerae50e8562017-04-04 16:19:48 +020070 vm->clib_time.seconds_per_clock);
71 s = format (s, "%10s %-32s %20v\n", "", "Last control frame tx", tmp);
72 vec_reset_length (tmp);
73 }
Klement Sekeraa3167442020-02-10 11:49:52 +000074 if (bs->last_rx_nsec)
Klement Sekerae50e8562017-04-04 16:19:48 +020075 {
Klement Sekeraa3167442020-02-10 11:49:52 +000076 tmp = format (tmp, "%.2fs ago", (now - bs->last_rx_nsec) *
Klement Sekerae50e8562017-04-04 16:19:48 +020077 vm->clib_time.seconds_per_clock);
78 s = format (s, "%10s %-32s %20v\n", "", "Last control frame rx", tmp);
79 vec_reset_length (tmp);
80 }
Klement Sekera73884482017-02-23 09:26:30 +010081 s =
Klement Sekerae50e8562017-04-04 16:19:48 +020082 format (s, "%10s %-32s %20u %20llu\n", "", "Min Echo Rx Interval (usec)",
83 1, bs->remote_min_echo_rx_usec);
84 if (bs->echo)
85 {
Klement Sekeraa3167442020-02-10 11:49:52 +000086 s =
87 format (s, "%10s %-32s %20u\n", "", "Echo transmit interval",
88 bfd_nsec_to_usec (bs->echo_transmit_interval_nsec));
89 tmp =
90 format (tmp, "%.2fs ago",
91 (now -
92 bs->echo_last_tx_nsec) * vm->clib_time.seconds_per_clock);
Klement Sekerae50e8562017-04-04 16:19:48 +020093 s = format (s, "%10s %-32s %20v\n", "", "Last echo frame tx", tmp);
94 vec_reset_length (tmp);
95 tmp = format (tmp, "%.6fs",
Klement Sekeraa3167442020-02-10 11:49:52 +000096 (bs->echo_last_rx_nsec - bs->echo_last_tx_nsec) *
Klement Sekerae50e8562017-04-04 16:19:48 +020097 vm->clib_time.seconds_per_clock);
98 s =
99 format (s, "%10s %-32s %20v\n", "", "Last echo frame roundtrip time",
100 tmp);
101 }
102 vec_free (tmp);
103 tmp = NULL;
104 s = format (s, "%10s %-32s %20s %20s\n", "", "Demand mode", "no",
105 bs->remote_demand ? "yes" : "no");
106 s = format (s, "%10s %-32s %20s\n", "", "Poll state",
107 bfd_poll_state_string (bs->poll_state));
Klement Sekera73884482017-02-23 09:26:30 +0100108 if (bs->auth.curr_key)
109 {
110 s = format (s, "%10s %-32s %20u\n", "", "Authentication config key ID",
111 bs->auth.curr_key->conf_key_id);
112 s = format (s, "%10s %-32s %20u\n", "", "Authentication BFD key ID",
113 bs->auth.curr_bfd_key_id);
Klement Sekerae50e8562017-04-04 16:19:48 +0200114 s = format (s, "%10s %-32s %20u %20u\n", "", "Sequence number",
115 bs->auth.local_seq_number, bs->auth.remote_seq_number);
Klement Sekera73884482017-02-23 09:26:30 +0100116 }
117 return s;
118}
119
120static clib_error_t *
121show_bfd (vlib_main_t * vm, unformat_input_t * input,
122 CLIB_UNUSED (vlib_cli_command_t * lmd))
123{
124 bfd_main_t *bm = &bfd_main;
125 bfd_session_t *bs = NULL;
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100126 unformat_input_t _line_input, *line_input = &_line_input;
Klement Sekera73884482017-02-23 09:26:30 +0100127
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100128 /* Get a line of input. */
129 if (!unformat_user (input, unformat_line_input, line_input))
130 return 0;
131
132 if (unformat (line_input, "keys"))
Klement Sekera73884482017-02-23 09:26:30 +0100133 {
134 bfd_auth_key_t *key = NULL;
135 u8 *s = format (NULL, "%=10s %=25s %=10s\n", "Configuration Key ID",
136 "Type", "Use Count");
Damjan Marionb2c31b62020-12-13 21:47:40 +0100137 pool_foreach (key, bm->auth_keys) {
Klement Sekera73884482017-02-23 09:26:30 +0100138 s = format (s, "%10u %-25s %10u\n", key->conf_key_id,
139 bfd_auth_type_str (key->auth_type), key->use_count);
Damjan Marionb2c31b62020-12-13 21:47:40 +0100140 }
Klement Sekera73884482017-02-23 09:26:30 +0100141 vlib_cli_output (vm, "%v\n", s);
Klement Sekerae50e8562017-04-04 16:19:48 +0200142 vec_free (s);
Klement Sekera73884482017-02-23 09:26:30 +0100143 vlib_cli_output (vm, "Number of configured BFD keys: %lu\n",
144 (u64) pool_elts (bm->auth_keys));
145 }
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100146 else if (unformat (line_input, "sessions"))
Klement Sekera73884482017-02-23 09:26:30 +0100147 {
148 u8 *s = format (NULL, "%=10s %=32s %=20s %=20s\n", "Index", "Property",
149 "Local value", "Remote value");
Damjan Marionb2c31b62020-12-13 21:47:40 +0100150 pool_foreach (bs, bm->sessions) {
Klement Sekeraa3167442020-02-10 11:49:52 +0000151 s = format (s, "%U", format_bfd_session_cli, vm, bs);
Damjan Marionb2c31b62020-12-13 21:47:40 +0100152 }
Klement Sekera73884482017-02-23 09:26:30 +0100153 vlib_cli_output (vm, "%v", s);
154 vec_free (s);
155 vlib_cli_output (vm, "Number of configured BFD sessions: %lu\n",
156 (u64) pool_elts (bm->sessions));
157 }
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100158 else if (unformat (line_input, "echo-source"))
Klement Sekera73884482017-02-23 09:26:30 +0100159 {
160 int is_set;
161 u32 sw_if_index;
162 int have_usable_ip4;
163 ip4_address_t ip4;
164 int have_usable_ip6;
165 ip6_address_t ip6;
166 bfd_udp_get_echo_source (&is_set, &sw_if_index, &have_usable_ip4, &ip4,
167 &have_usable_ip6, &ip6);
168 if (is_set)
169 {
170 vnet_sw_interface_t *sw_if =
Dave Barach3940de32019-07-23 16:28:36 -0400171 vnet_get_sw_interface_or_null (&vnet_main, sw_if_index);
Klement Sekera73884482017-02-23 09:26:30 +0100172 vnet_hw_interface_t *hw_if =
173 vnet_get_hw_interface (&vnet_main, sw_if->hw_if_index);
174 u8 *s = format (NULL, "UDP echo source is: %v\n", hw_if->name);
175 s = format (s, "IPv4 address usable as echo source: ");
176 if (have_usable_ip4)
177 {
178 s = format (s, "%U\n", format_ip4_address, &ip4);
179 }
180 else
181 {
182 s = format (s, "none\n");
183 }
184 s = format (s, "IPv6 address usable as echo source: ");
185 if (have_usable_ip6)
186 {
187 s = format (s, "%U\n", format_ip6_address, &ip6);
188 }
189 else
190 {
191 s = format (s, "none\n");
192 }
193 vlib_cli_output (vm, "%v", s);
194 vec_free (s);
195 }
196 else
197 {
198 vlib_cli_output (vm, "UDP echo source is not set.\n");
199 }
200 }
201 else
202 {
203 vlib_cli_output (vm, "Number of configured BFD sessions: %lu\n",
204 (u64) pool_elts (bm->sessions));
205 vlib_cli_output (vm, "Number of configured BFD keys: %lu\n",
206 (u64) pool_elts (bm->auth_keys));
207 }
208 return 0;
209}
210
Klement Sekera73884482017-02-23 09:26:30 +0100211VLIB_CLI_COMMAND (show_bfd_command, static) = {
212 .path = "show bfd",
213 .short_help = "show bfd [keys|sessions|echo-source]",
214 .function = show_bfd,
215};
Klement Sekera73884482017-02-23 09:26:30 +0100216
Klement Sekera73884482017-02-23 09:26:30 +0100217static clib_error_t *
218bfd_cli_key_add (vlib_main_t * vm, unformat_input_t * input,
219 CLIB_UNUSED (vlib_cli_command_t * lmd))
220{
221 clib_error_t *ret = NULL;
222 int have_key_id = 0;
223 u32 key_id = 0;
224 u8 *vec_auth_type = NULL;
225 bfd_auth_type_e auth_type = BFD_AUTH_TYPE_reserved;
226 u8 *secret = NULL;
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100227 unformat_input_t _line_input, *line_input = &_line_input;
Klement Sekera73884482017-02-23 09:26:30 +0100228 static const u8 keyed_sha1[] = "keyed-sha1";
229 static const u8 meticulous_keyed_sha1[] = "meticulous-keyed-sha1";
230
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100231 /* Get a line of input. */
232 if (!unformat_user (input, unformat_line_input, line_input))
233 return 0;
234
235 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
Klement Sekera73884482017-02-23 09:26:30 +0100236 {
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100237 if (unformat (line_input, "conf-key-id %u", &key_id))
Klement Sekera73884482017-02-23 09:26:30 +0100238 {
239 have_key_id = 1;
240 }
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100241 else if (unformat (line_input, "type %U", unformat_token, "a-zA-Z0-9-",
Klement Sekera73884482017-02-23 09:26:30 +0100242 &vec_auth_type))
243 {
244 if (vec_len (vec_auth_type) == sizeof (keyed_sha1) - 1 &&
245 0 == memcmp (vec_auth_type, keyed_sha1,
246 sizeof (keyed_sha1) - 1))
247 {
248 auth_type = BFD_AUTH_TYPE_keyed_sha1;
249 }
250 else if (vec_len (vec_auth_type) ==
251 sizeof (meticulous_keyed_sha1) - 1 &&
252 0 == memcmp (vec_auth_type, meticulous_keyed_sha1,
253 sizeof (meticulous_keyed_sha1) - 1))
254 {
255 auth_type = BFD_AUTH_TYPE_meticulous_keyed_sha1;
256 }
257 else
258 {
259 ret = clib_error_return (0, "invalid type `%v'", vec_auth_type);
260 goto out;
261 }
262 }
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100263 else
264 if (unformat (line_input, "secret %U", unformat_hex_string, &secret))
Klement Sekera73884482017-02-23 09:26:30 +0100265 {
266 /* nothing to do here */
267 }
268 else
269 {
270 ret = clib_error_return (0, "Unknown input `%U'",
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100271 format_unformat_error, line_input);
Klement Sekera73884482017-02-23 09:26:30 +0100272 goto out;
273 }
274 }
275
276 if (!have_key_id)
277 {
278 ret =
279 clib_error_return (0, "required parameter missing: `conf-key-id'");
280 goto out;
281 }
282 if (!vec_auth_type)
283 {
284 ret = clib_error_return (0, "required parameter missing: `type'");
285 goto out;
286 }
287 if (!secret)
288 {
289 ret = clib_error_return (0, "required parameter missing: `secret'");
290 goto out;
291 }
292
293 vnet_api_error_t rv =
294 bfd_auth_set_key (key_id, auth_type, vec_len (secret), secret);
295 if (rv)
296 {
297 ret =
298 clib_error_return (0, "`bfd_auth_set_key' API call failed, rv=%d:%U",
299 (int) rv, format_vnet_api_errno, rv);
300 }
301
302out:
303 vec_free (vec_auth_type);
304 return ret;
305}
306
Klement Sekera73884482017-02-23 09:26:30 +0100307VLIB_CLI_COMMAND (bfd_cli_key_add_command, static) = {
308 .path = "bfd key set",
309 .short_help = "bfd key set"
310 " conf-key-id <id>"
311 " type <keyed-sha1|meticulous-keyed-sha1> "
312 " secret <secret>",
313 .function = bfd_cli_key_add,
314};
Klement Sekera73884482017-02-23 09:26:30 +0100315
316static clib_error_t *
317bfd_cli_key_del (vlib_main_t * vm, unformat_input_t * input,
318 CLIB_UNUSED (vlib_cli_command_t * lmd))
319{
320 clib_error_t *ret = NULL;
321 u32 key_id = 0;
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100322 unformat_input_t _line_input, *line_input = &_line_input;
Klement Sekera73884482017-02-23 09:26:30 +0100323
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100324 /* Get a line of input. */
325 if (!unformat_user (input, unformat_line_input, line_input))
326 return 0;
327
328 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
Klement Sekera73884482017-02-23 09:26:30 +0100329 {
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100330 if (!unformat (line_input, "conf-key-id %u", &key_id))
Klement Sekera73884482017-02-23 09:26:30 +0100331 {
332 ret = clib_error_return (0, "Unknown input `%U'",
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100333 format_unformat_error, line_input);
Klement Sekera73884482017-02-23 09:26:30 +0100334 goto out;
335 }
336 }
337
338 vnet_api_error_t rv = bfd_auth_del_key (key_id);
339 if (rv)
340 {
341 ret =
342 clib_error_return (0, "`bfd_auth_del_key' API call failed, rv=%d:%U",
343 (int) rv, format_vnet_api_errno, rv);
344 }
345
346out:
347 return ret;
348}
349
Klement Sekera73884482017-02-23 09:26:30 +0100350VLIB_CLI_COMMAND (bfd_cli_key_del_command, static) = {
351 .path = "bfd key del",
352 .short_help = "bfd key del conf-key-id <id>",
353 .function = bfd_cli_key_del,
354};
Klement Sekera73884482017-02-23 09:26:30 +0100355
356#define INTERFACE_STR "interface"
357#define LOCAL_ADDR_STR "local-addr"
358#define PEER_ADDR_STR "peer-addr"
359#define CONF_KEY_ID_STR "conf-key-id"
360#define BFD_KEY_ID_STR "bfd-key-id"
361#define DESIRED_MIN_TX_STR "desired-min-tx"
362#define REQUIRED_MIN_RX_STR "required-min-rx"
363#define DETECT_MULT_STR "detect-mult"
364#define ADMIN_STR "admin"
365#define DELAYED_STR "delayed"
366
367static const unsigned mandatory = 1;
368static const unsigned optional = 0;
369
370#define DECLARE(t, n, s, r, ...) \
371 int have_##n = 0; \
372 t n;
373
374#define UNFORMAT(t, n, s, r, ...) \
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100375 if (unformat (line_input, s " " __VA_ARGS__, &n)) \
Klement Sekera73884482017-02-23 09:26:30 +0100376 { \
377 something_parsed = 1; \
378 have_##n = 1; \
379 }
380
381#define CHECK_MANDATORY(t, n, s, r, ...) \
Gabriel Gannebeb85cc2017-11-07 14:24:56 +0100382WARN_OFF(tautological-compare) \
Klement Sekera73884482017-02-23 09:26:30 +0100383 if (mandatory == r && !have_##n) \
384 { \
Gabriel Gannebeb85cc2017-11-07 14:24:56 +0100385 WARN_ON(tautological-compare) \
Klement Sekerae50e8562017-04-04 16:19:48 +0200386 ret = clib_error_return (0, "Required parameter `%s' missing.", s); \
Klement Sekera73884482017-02-23 09:26:30 +0100387 goto out; \
388 }
389
Benoît Gannecfaf4402023-01-06 09:58:53 +0100390static uword
391bfd_cli_unformat_ip46_address (unformat_input_t *input, va_list *args)
392{
393 ip46_address_t *ip46 = va_arg (*args, ip46_address_t *);
394 return unformat_user (input, unformat_ip46_address, ip46, IP46_TYPE_ANY);
395}
396
Klement Sekera73884482017-02-23 09:26:30 +0100397static clib_error_t *
398bfd_cli_udp_session_add (vlib_main_t * vm, unformat_input_t * input,
399 CLIB_UNUSED (vlib_cli_command_t * lmd))
400{
401 clib_error_t *ret = NULL;
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100402 unformat_input_t _line_input, *line_input = &_line_input;
Benoît Gannecfaf4402023-01-06 09:58:53 +0100403#define foreach_bfd_cli_udp_session_add_cli_param(F) \
404 F (u32, sw_if_index, INTERFACE_STR, mandatory, "%U", \
405 unformat_vnet_sw_interface, &vnet_main) \
406 F (ip46_address_t, local_addr, LOCAL_ADDR_STR, mandatory, "%U", \
407 bfd_cli_unformat_ip46_address) \
408 F (ip46_address_t, peer_addr, PEER_ADDR_STR, mandatory, "%U", \
409 bfd_cli_unformat_ip46_address) \
410 F (u32, desired_min_tx, DESIRED_MIN_TX_STR, mandatory, "%u") \
411 F (u32, required_min_rx, REQUIRED_MIN_RX_STR, mandatory, "%u") \
412 F (u32, detect_mult, DETECT_MULT_STR, mandatory, "%u") \
413 F (u32, conf_key_id, CONF_KEY_ID_STR, optional, "%u") \
Klement Sekera73884482017-02-23 09:26:30 +0100414 F (u32, bfd_key_id, BFD_KEY_ID_STR, optional, "%u")
415
416 foreach_bfd_cli_udp_session_add_cli_param (DECLARE);
417
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100418 /* Get a line of input. */
419 if (!unformat_user (input, unformat_line_input, line_input))
420 return 0;
421
422 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
Klement Sekera73884482017-02-23 09:26:30 +0100423 {
424 int something_parsed = 0;
425 foreach_bfd_cli_udp_session_add_cli_param (UNFORMAT);
426
427 if (!something_parsed)
428 {
429 ret = clib_error_return (0, "Unknown input `%U'",
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100430 format_unformat_error, line_input);
Klement Sekera73884482017-02-23 09:26:30 +0100431 goto out;
432 }
433 }
434
435 foreach_bfd_cli_udp_session_add_cli_param (CHECK_MANDATORY);
436
437 if (1 == have_conf_key_id + have_bfd_key_id)
438 {
439 ret = clib_error_return (0, "Incompatible parameter combination, `%s' "
440 "and `%s' must be either both specified or none",
441 CONF_KEY_ID_STR, BFD_KEY_ID_STR);
442 goto out;
443 }
444
445 if (detect_mult > 255)
446 {
447 ret = clib_error_return (0, "%s value `%u' out of range <1,255>",
448 DETECT_MULT_STR, detect_mult);
449 goto out;
450 }
451
452 if (have_bfd_key_id && bfd_key_id > 255)
453 {
454 ret = clib_error_return (0, "%s value `%u' out of range <1,255>",
455 BFD_KEY_ID_STR, bfd_key_id);
456 goto out;
457 }
458
459 vnet_api_error_t rv =
460 bfd_udp_add_session (sw_if_index, &local_addr, &peer_addr, desired_min_tx,
461 required_min_rx,
462 detect_mult, have_conf_key_id, conf_key_id,
463 bfd_key_id);
464 if (rv)
465 {
466 ret =
467 clib_error_return (0,
468 "`bfd_add_add_session' API call failed, rv=%d:%U",
469 (int) rv, format_vnet_api_errno, rv);
470 goto out;
471 }
472
473out:
474 return ret;
475}
476
Klement Sekera73884482017-02-23 09:26:30 +0100477VLIB_CLI_COMMAND (bfd_cli_udp_session_add_command, static) = {
478 .path = "bfd udp session add",
479 .short_help = "bfd udp session add"
480 " interface <interface>"
481 " local-addr <local-address>"
482 " peer-addr <peer-address>"
483 " desired-min-tx <desired min tx interval>"
484 " required-min-rx <required min rx interval>"
485 " detect-mult <detect multiplier> "
486 "["
487 " conf-key-id <config key ID>"
488 " bfd-key-id <BFD key ID>"
489 "]",
490 .function = bfd_cli_udp_session_add,
491};
Klement Sekera73884482017-02-23 09:26:30 +0100492
493static clib_error_t *
494bfd_cli_udp_session_mod (vlib_main_t * vm, unformat_input_t * input,
495 CLIB_UNUSED (vlib_cli_command_t * lmd))
496{
497 clib_error_t *ret = NULL;
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100498 unformat_input_t _line_input, *line_input = &_line_input;
Benoît Gannecfaf4402023-01-06 09:58:53 +0100499#define foreach_bfd_cli_udp_session_mod_cli_param(F) \
500 F (u32, sw_if_index, INTERFACE_STR, mandatory, "%U", \
501 unformat_vnet_sw_interface, &vnet_main) \
502 F (ip46_address_t, local_addr, LOCAL_ADDR_STR, mandatory, "%U", \
503 bfd_cli_unformat_ip46_address) \
504 F (ip46_address_t, peer_addr, PEER_ADDR_STR, mandatory, "%U", \
505 bfd_cli_unformat_ip46_address) \
506 F (u32, desired_min_tx, DESIRED_MIN_TX_STR, mandatory, "%u") \
507 F (u32, required_min_rx, REQUIRED_MIN_RX_STR, mandatory, "%u") \
Klement Sekera73884482017-02-23 09:26:30 +0100508 F (u32, detect_mult, DETECT_MULT_STR, mandatory, "%u")
509
510 foreach_bfd_cli_udp_session_mod_cli_param (DECLARE);
511
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100512 /* Get a line of input. */
513 if (!unformat_user (input, unformat_line_input, line_input))
514 return 0;
515
516 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
Klement Sekera73884482017-02-23 09:26:30 +0100517 {
518 int something_parsed = 0;
519 foreach_bfd_cli_udp_session_mod_cli_param (UNFORMAT);
520
521 if (!something_parsed)
522 {
523 ret = clib_error_return (0, "Unknown input `%U'",
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100524 format_unformat_error, line_input);
Klement Sekera73884482017-02-23 09:26:30 +0100525 goto out;
526 }
527 }
528
529 foreach_bfd_cli_udp_session_mod_cli_param (CHECK_MANDATORY);
530
531 if (detect_mult > 255)
532 {
533 ret = clib_error_return (0, "%s value `%u' out of range <1,255>",
534 DETECT_MULT_STR, detect_mult);
535 goto out;
536 }
537
538 vnet_api_error_t rv =
539 bfd_udp_mod_session (sw_if_index, &local_addr, &peer_addr,
540 desired_min_tx, required_min_rx, detect_mult);
541 if (rv)
542 {
543 ret =
544 clib_error_return (0,
545 "`bfd_udp_mod_session' API call failed, rv=%d:%U",
546 (int) rv, format_vnet_api_errno, rv);
547 goto out;
548 }
549
550out:
551 return ret;
552}
553
Klement Sekera73884482017-02-23 09:26:30 +0100554VLIB_CLI_COMMAND (bfd_cli_udp_session_mod_command, static) = {
555 .path = "bfd udp session mod",
556 .short_help = "bfd udp session mod interface"
557 " <interface> local-addr"
558 " <local-address> peer-addr"
559 " <peer-address> desired-min-tx"
560 " <desired min tx interval> required-min-rx"
561 " <required min rx interval> detect-mult"
562 " <detect multiplier> ",
563 .function = bfd_cli_udp_session_mod,
564};
Klement Sekera73884482017-02-23 09:26:30 +0100565
566static clib_error_t *
567bfd_cli_udp_session_del (vlib_main_t * vm, unformat_input_t * input,
568 CLIB_UNUSED (vlib_cli_command_t * lmd))
569{
570 clib_error_t *ret = NULL;
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100571 unformat_input_t _line_input, *line_input = &_line_input;
Benoît Gannecfaf4402023-01-06 09:58:53 +0100572#define foreach_bfd_cli_udp_session_del_cli_param(F) \
573 F (u32, sw_if_index, INTERFACE_STR, mandatory, "%U", \
574 unformat_vnet_sw_interface, &vnet_main) \
575 F (ip46_address_t, local_addr, LOCAL_ADDR_STR, mandatory, "%U", \
576 bfd_cli_unformat_ip46_address) \
577 F (ip46_address_t, peer_addr, PEER_ADDR_STR, mandatory, "%U", \
578 bfd_cli_unformat_ip46_address)
Klement Sekera73884482017-02-23 09:26:30 +0100579
580 foreach_bfd_cli_udp_session_del_cli_param (DECLARE);
581
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100582 /* Get a line of input. */
583 if (!unformat_user (input, unformat_line_input, line_input))
584 return 0;
585
586 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
Klement Sekera73884482017-02-23 09:26:30 +0100587 {
588 int something_parsed = 0;
589 foreach_bfd_cli_udp_session_del_cli_param (UNFORMAT);
590
591 if (!something_parsed)
592 {
593 ret = clib_error_return (0, "Unknown input `%U'",
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100594 format_unformat_error, line_input);
Klement Sekera73884482017-02-23 09:26:30 +0100595 goto out;
596 }
597 }
598
599 foreach_bfd_cli_udp_session_del_cli_param (CHECK_MANDATORY);
600
601 vnet_api_error_t rv =
602 bfd_udp_del_session (sw_if_index, &local_addr, &peer_addr);
603 if (rv)
604 {
605 ret =
606 clib_error_return (0,
607 "`bfd_udp_del_session' API call failed, rv=%d:%U",
608 (int) rv, format_vnet_api_errno, rv);
609 goto out;
610 }
611
612out:
613 return ret;
614}
615
Klement Sekera73884482017-02-23 09:26:30 +0100616VLIB_CLI_COMMAND (bfd_cli_udp_session_del_command, static) = {
617 .path = "bfd udp session del",
618 .short_help = "bfd udp session del interface"
619 " <interface> local-addr"
620 " <local-address> peer-addr"
621 "<peer-address> ",
622 .function = bfd_cli_udp_session_del,
623};
Klement Sekera73884482017-02-23 09:26:30 +0100624
625static clib_error_t *
626bfd_cli_udp_session_set_flags (vlib_main_t * vm, unformat_input_t * input,
627 CLIB_UNUSED (vlib_cli_command_t * lmd))
628{
629 clib_error_t *ret = NULL;
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100630 unformat_input_t _line_input, *line_input = &_line_input;
Benoît Gannecfaf4402023-01-06 09:58:53 +0100631#define foreach_bfd_cli_udp_session_set_flags_cli_param(F) \
632 F (u32, sw_if_index, INTERFACE_STR, mandatory, "%U", \
633 unformat_vnet_sw_interface, &vnet_main) \
634 F (ip46_address_t, local_addr, LOCAL_ADDR_STR, mandatory, "%U", \
635 bfd_cli_unformat_ip46_address) \
636 F (ip46_address_t, peer_addr, PEER_ADDR_STR, mandatory, "%U", \
637 bfd_cli_unformat_ip46_address) \
638 F (u8 *, admin_up_down_token, ADMIN_STR, mandatory, "%v", \
Klement Sekera73884482017-02-23 09:26:30 +0100639 &admin_up_down_token)
640
641 foreach_bfd_cli_udp_session_set_flags_cli_param (DECLARE);
642
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100643 /* Get a line of input. */
644 if (!unformat_user (input, unformat_line_input, line_input))
645 return 0;
646
647 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
Klement Sekera73884482017-02-23 09:26:30 +0100648 {
649 int something_parsed = 0;
650 foreach_bfd_cli_udp_session_set_flags_cli_param (UNFORMAT);
651
652 if (!something_parsed)
653 {
654 ret = clib_error_return (0, "Unknown input `%U'",
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100655 format_unformat_error, line_input);
Klement Sekera73884482017-02-23 09:26:30 +0100656 goto out;
657 }
658 }
659
660 foreach_bfd_cli_udp_session_set_flags_cli_param (CHECK_MANDATORY);
661
662 u8 admin_up_down;
663 static const char up[] = "up";
664 static const char down[] = "down";
665 if (!memcmp (admin_up_down_token, up, sizeof (up) - 1))
666 {
667 admin_up_down = 1;
668 }
669 else if (!memcmp (admin_up_down_token, down, sizeof (down) - 1))
670 {
671 admin_up_down = 0;
672 }
673 else
674 {
675 ret =
676 clib_error_return (0, "Unrecognized value for `%s' parameter: `%v'",
677 ADMIN_STR, admin_up_down_token);
678 goto out;
679 }
Klement Sekeraa3167442020-02-10 11:49:52 +0000680 vnet_api_error_t rv =
681 bfd_udp_session_set_flags (vm, sw_if_index, &local_addr,
682 &peer_addr, admin_up_down);
Klement Sekera73884482017-02-23 09:26:30 +0100683 if (rv)
684 {
685 ret =
686 clib_error_return (0,
687 "`bfd_udp_session_set_flags' API call failed, rv=%d:%U",
688 (int) rv, format_vnet_api_errno, rv);
689 goto out;
690 }
691
692out:
693 return ret;
694}
695
Klement Sekera73884482017-02-23 09:26:30 +0100696VLIB_CLI_COMMAND (bfd_cli_udp_session_set_flags_command, static) = {
697 .path = "bfd udp session set-flags",
698 .short_help = "bfd udp session set-flags"
699 " interface <interface>"
700 " local-addr <local-address>"
701 " peer-addr <peer-address>"
702 " admin <up|down>",
703 .function = bfd_cli_udp_session_set_flags,
704};
Klement Sekera73884482017-02-23 09:26:30 +0100705
706static clib_error_t *
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100707bfd_cli_udp_session_auth_activate (vlib_main_t * vm,
708 unformat_input_t * input,
Klement Sekera73884482017-02-23 09:26:30 +0100709 CLIB_UNUSED (vlib_cli_command_t * lmd))
710{
711 clib_error_t *ret = NULL;
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100712 unformat_input_t _line_input, *line_input = &_line_input;
Benoît Gannecfaf4402023-01-06 09:58:53 +0100713#define foreach_bfd_cli_udp_session_auth_activate_cli_param(F) \
714 F (u32, sw_if_index, INTERFACE_STR, mandatory, "%U", \
715 unformat_vnet_sw_interface, &vnet_main) \
716 F (ip46_address_t, local_addr, LOCAL_ADDR_STR, mandatory, "%U", \
717 bfd_cli_unformat_ip46_address) \
718 F (ip46_address_t, peer_addr, PEER_ADDR_STR, mandatory, "%U", \
719 bfd_cli_unformat_ip46_address) \
720 F (u8 *, delayed_token, DELAYED_STR, optional, "%v") \
721 F (u32, conf_key_id, CONF_KEY_ID_STR, mandatory, "%u") \
Klement Sekera73884482017-02-23 09:26:30 +0100722 F (u32, bfd_key_id, BFD_KEY_ID_STR, mandatory, "%u")
723
724 foreach_bfd_cli_udp_session_auth_activate_cli_param (DECLARE);
725
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100726 /* Get a line of input. */
727 if (!unformat_user (input, unformat_line_input, line_input))
728 return 0;
729
730 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
Klement Sekera73884482017-02-23 09:26:30 +0100731 {
732 int something_parsed = 0;
733 foreach_bfd_cli_udp_session_auth_activate_cli_param (UNFORMAT);
734
735 if (!something_parsed)
736 {
737 ret = clib_error_return (0, "Unknown input `%U'",
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100738 format_unformat_error, line_input);
Klement Sekera73884482017-02-23 09:26:30 +0100739 goto out;
740 }
741 }
742
743 foreach_bfd_cli_udp_session_auth_activate_cli_param (CHECK_MANDATORY);
744
745 u8 is_delayed = 0;
746 if (have_delayed_token)
747 {
748 static const char yes[] = "yes";
749 static const char no[] = "no";
750 if (!memcmp (delayed_token, yes, sizeof (yes) - 1))
751 {
752 is_delayed = 1;
753 }
754 else if (!memcmp (delayed_token, no, sizeof (no) - 1))
755 {
756 is_delayed = 0;
757 }
758 else
759 {
760 ret =
761 clib_error_return (0,
762 "Unrecognized value for `%s' parameter: `%v'",
763 DELAYED_STR, delayed_token);
764 goto out;
765 }
766 }
767
768 if (have_bfd_key_id && bfd_key_id > 255)
769 {
770 ret = clib_error_return (0, "%s value `%u' out of range <1,255>",
771 BFD_KEY_ID_STR, bfd_key_id);
772 goto out;
773 }
774
775 vnet_api_error_t rv =
776 bfd_udp_auth_activate (sw_if_index, &local_addr, &peer_addr, conf_key_id,
777 bfd_key_id, is_delayed);
778 if (rv)
779 {
780 ret =
781 clib_error_return (0,
782 "`bfd_udp_auth_activate' API call failed, rv=%d:%U",
783 (int) rv, format_vnet_api_errno, rv);
784 goto out;
785 }
786
787out:
788 return ret;
789}
790
Klement Sekera73884482017-02-23 09:26:30 +0100791VLIB_CLI_COMMAND (bfd_cli_udp_session_auth_activate_command, static) = {
792 .path = "bfd udp session auth activate",
793 .short_help = "bfd udp session auth activate"
794 " interface <interface>"
795 " local-addr <local-address>"
796 " peer-addr <peer-address>"
797 " conf-key-id <config key ID>"
798 " bfd-key-id <BFD key ID>"
Klement Sekerab16bfe32017-02-28 11:56:48 +0100799 " [ delayed <yes|no> ]",
Klement Sekera73884482017-02-23 09:26:30 +0100800 .function = bfd_cli_udp_session_auth_activate,
801};
802
803static clib_error_t *
804bfd_cli_udp_session_auth_deactivate (vlib_main_t *vm, unformat_input_t *input,
805 CLIB_UNUSED (vlib_cli_command_t *lmd))
806{
807 clib_error_t *ret = NULL;
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100808 unformat_input_t _line_input, *line_input = &_line_input;
Benoît Gannecfaf4402023-01-06 09:58:53 +0100809#define foreach_bfd_cli_udp_session_auth_deactivate_cli_param(F) \
810 F (u32, sw_if_index, INTERFACE_STR, mandatory, "%U", \
811 unformat_vnet_sw_interface, &vnet_main) \
812 F (ip46_address_t, local_addr, LOCAL_ADDR_STR, mandatory, "%U", \
813 bfd_cli_unformat_ip46_address) \
814 F (ip46_address_t, peer_addr, PEER_ADDR_STR, mandatory, "%U", \
815 bfd_cli_unformat_ip46_address) \
Klement Sekera73884482017-02-23 09:26:30 +0100816 F (u8 *, delayed_token, DELAYED_STR, optional, "%v")
817
818 foreach_bfd_cli_udp_session_auth_deactivate_cli_param (DECLARE);
819
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100820 /* Get a line of input. */
821 if (!unformat_user (input, unformat_line_input, line_input))
822 return 0;
823
824 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
Klement Sekera73884482017-02-23 09:26:30 +0100825 {
826 int something_parsed = 0;
827 foreach_bfd_cli_udp_session_auth_deactivate_cli_param (UNFORMAT);
828
829 if (!something_parsed)
830 {
831 ret = clib_error_return (0, "Unknown input `%U'",
832 format_unformat_error, input);
833 goto out;
834 }
835 }
836
837 foreach_bfd_cli_udp_session_auth_deactivate_cli_param (CHECK_MANDATORY);
838
839 u8 is_delayed = 0;
840 if (have_delayed_token)
841 {
842 static const char yes[] = "yes";
843 static const char no[] = "no";
844 if (!memcmp (delayed_token, yes, sizeof (yes) - 1))
845 {
846 is_delayed = 1;
847 }
848 else if (!memcmp (delayed_token, no, sizeof (no) - 1))
849 {
850 is_delayed = 0;
851 }
852 else
853 {
854 ret = clib_error_return (
855 0, "Unrecognized value for `%s' parameter: `%v'", DELAYED_STR,
856 delayed_token);
857 goto out;
858 }
859 }
860
861 vnet_api_error_t rv = bfd_udp_auth_deactivate (sw_if_index, &local_addr,
862 &peer_addr, is_delayed);
863 if (rv)
864 {
865 ret = clib_error_return (
866 0, "`bfd_udp_auth_deactivate' API call failed, rv=%d:%U", (int)rv,
867 format_vnet_api_errno, rv);
868 goto out;
869 }
870
871out:
872 return ret;
873}
874
Klement Sekera73884482017-02-23 09:26:30 +0100875VLIB_CLI_COMMAND (bfd_cli_udp_session_auth_deactivate_command, static) = {
876 .path = "bfd udp session auth deactivate",
877 .short_help = "bfd udp session auth deactivate"
878 " interface <interface>"
879 " local-addr <local-address>"
880 " peer-addr <peer-address>"
Klement Sekerab16bfe32017-02-28 11:56:48 +0100881 "[ delayed <yes|no> ]",
Klement Sekera73884482017-02-23 09:26:30 +0100882 .function = bfd_cli_udp_session_auth_deactivate,
883};
Klement Sekera73884482017-02-23 09:26:30 +0100884
885static clib_error_t *
886bfd_cli_udp_set_echo_source (vlib_main_t * vm, unformat_input_t * input,
887 CLIB_UNUSED (vlib_cli_command_t * lmd))
888{
889 clib_error_t *ret = NULL;
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100890 unformat_input_t _line_input, *line_input = &_line_input;
Klement Sekera73884482017-02-23 09:26:30 +0100891#define foreach_bfd_cli_udp_set_echo_source_cli_param(F) \
892 F (u32, sw_if_index, INTERFACE_STR, mandatory, "%U", \
893 unformat_vnet_sw_interface, &vnet_main)
894
895 foreach_bfd_cli_udp_set_echo_source_cli_param (DECLARE);
896
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100897 /* Get a line of input. */
898 if (!unformat_user (input, unformat_line_input, line_input))
899 return 0;
900
901 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
Klement Sekera73884482017-02-23 09:26:30 +0100902 {
903 int something_parsed = 0;
904 foreach_bfd_cli_udp_set_echo_source_cli_param (UNFORMAT);
905
906 if (!something_parsed)
907 {
908 ret = clib_error_return (0, "Unknown input `%U'",
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100909 format_unformat_error, line_input);
Klement Sekera73884482017-02-23 09:26:30 +0100910 goto out;
911 }
912 }
913
914 foreach_bfd_cli_udp_set_echo_source_cli_param (CHECK_MANDATORY);
915
916 vnet_api_error_t rv = bfd_udp_set_echo_source (sw_if_index);
917 if (rv)
918 {
919 ret =
920 clib_error_return (0,
921 "`bfd_udp_set_echo_source' API call failed, rv=%d:%U",
922 (int) rv, format_vnet_api_errno, rv);
923 goto out;
924 }
925
926out:
927 return ret;
928}
929
Klement Sekera73884482017-02-23 09:26:30 +0100930VLIB_CLI_COMMAND (bfd_cli_udp_set_echo_source_cmd, static) = {
931 .path = "bfd udp echo-source set",
932 .short_help = "bfd udp echo-source set interface <interface>",
933 .function = bfd_cli_udp_set_echo_source,
934};
Klement Sekera73884482017-02-23 09:26:30 +0100935
936static clib_error_t *
937bfd_cli_udp_del_echo_source (vlib_main_t * vm, unformat_input_t * input,
938 CLIB_UNUSED (vlib_cli_command_t * lmd))
939{
940 vnet_api_error_t rv = bfd_udp_del_echo_source ();
941 if (rv)
942 {
943 return clib_error_return (0,
944 "`bfd_udp_del_echo_source' API call failed, rv=%d:%U",
945 (int) rv, format_vnet_api_errno, rv);
946 }
947
948 return 0;
949}
950
Klement Sekera73884482017-02-23 09:26:30 +0100951VLIB_CLI_COMMAND (bfd_cli_udp_del_echo_source_cmd, static) = {
952 .path = "bfd udp echo-source del",
953 .short_help = "bfd udp echo-source del",
954 .function = bfd_cli_udp_del_echo_source,
955};
Klement Sekera73884482017-02-23 09:26:30 +0100956
957/*
958 * fd.io coding-style-patch-verification: ON
959 *
960 * Local Variables:
961 * eval: (c-set-style "gnu")
962 * End:
963 */