blob: 194c62b507c0c0d09dc23db32ccf095a99996f67 [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
Abdel Baig17a91812024-09-03 11:52:20 -040029#define BFD_MULTIHOP_CLI_CHECK \
30 do \
31 { \
32 multihop = have_multihop; \
33 if (multihop) \
34 { \
35 sw_if_index = ~0; \
36 } \
37 if (multihop && have_sw_if_index) \
38 { \
39 ret = clib_error_return ( \
40 0, "Incompatible parameter combination, " \
41 "interface cannot be specified when multihop is enabled"); \
42 goto out; \
43 } \
44 if (!multihop && !have_sw_if_index) \
45 { \
46 ret = \
47 clib_error_return (0, "Incompatible parameter combination, " \
48 "interface must be set if not multihop"); \
49 goto out; \
50 } \
51 } \
52 while (0);
53
Klement Sekera73884482017-02-23 09:26:30 +010054static u8 *
55format_bfd_session_cli (u8 * s, va_list * args)
56{
Klement Sekerae50e8562017-04-04 16:19:48 +020057 vlib_main_t *vm = va_arg (*args, vlib_main_t *);
Klement Sekera73884482017-02-23 09:26:30 +010058 bfd_session_t *bs = va_arg (*args, bfd_session_t *);
Abdel Baig17a91812024-09-03 11:52:20 -040059 s = format (s, "%10s %-32s %20s\n", "", "Hop Type",
60 bfd_hop_type_string (bs->hop_type));
61
Klement Sekera73884482017-02-23 09:26:30 +010062 switch (bs->transport)
63 {
64 case BFD_TRANSPORT_UDP4:
65 s = format (s, "%=10u %-32s %20U %20U\n", bs->bs_idx, "IPv4 address",
66 format_ip4_address, bs->udp.key.local_addr.ip4.as_u8,
67 format_ip4_address, bs->udp.key.peer_addr.ip4.as_u8);
68 break;
69 case BFD_TRANSPORT_UDP6:
70 s = format (s, "%=10u %-32s %20U %20U\n", bs->bs_idx, "IPv6 address",
71 format_ip6_address, &bs->udp.key.local_addr.ip6,
72 format_ip6_address, &bs->udp.key.peer_addr.ip6);
73 break;
74 }
75 s = format (s, "%10s %-32s %20s %20s\n", "", "Session state",
76 bfd_state_string (bs->local_state),
77 bfd_state_string (bs->remote_state));
78 s = format (s, "%10s %-32s %20s %20s\n", "", "Diagnostic code",
79 bfd_diag_code_string (bs->local_diag),
80 bfd_diag_code_string (bs->remote_diag));
81 s = format (s, "%10s %-32s %20u %20u\n", "", "Detect multiplier",
82 bs->local_detect_mult, bs->remote_detect_mult);
Abdel Baig17a91812024-09-03 11:52:20 -040083 s = format (s, "%10s %-32s %20llu\n", "", "Detection Time (usec)",
84 bfd_nsec_to_usec (bs->detection_time_nsec));
Klement Sekerae50e8562017-04-04 16:19:48 +020085 s = format (s, "%10s %-32s %20u %20llu\n", "",
Klement Sekera73884482017-02-23 09:26:30 +010086 "Required Min Rx Interval (usec)",
87 bs->config_required_min_rx_usec, bs->remote_min_rx_usec);
88 s = format (s, "%10s %-32s %20u %20u\n", "",
89 "Desired Min Tx Interval (usec)",
Klement Sekeraa3167442020-02-10 11:49:52 +000090 bs->config_desired_min_tx_usec,
91 bfd_nsec_to_usec (bs->remote_desired_min_tx_nsec));
Klement Sekera73884482017-02-23 09:26:30 +010092 s =
93 format (s, "%10s %-32s %20u\n", "", "Transmit interval",
Klement Sekeraa3167442020-02-10 11:49:52 +000094 bfd_nsec_to_usec (bs->transmit_interval_nsec));
Klement Sekerae50e8562017-04-04 16:19:48 +020095 u64 now = clib_cpu_time_now ();
96 u8 *tmp = NULL;
Klement Sekeraa3167442020-02-10 11:49:52 +000097 if (bs->last_tx_nsec > 0)
Klement Sekerae50e8562017-04-04 16:19:48 +020098 {
Klement Sekeraa3167442020-02-10 11:49:52 +000099 tmp = format (tmp, "%.2fs ago", (now - bs->last_tx_nsec) *
Klement Sekerae50e8562017-04-04 16:19:48 +0200100 vm->clib_time.seconds_per_clock);
101 s = format (s, "%10s %-32s %20v\n", "", "Last control frame tx", tmp);
102 vec_reset_length (tmp);
103 }
Klement Sekeraa3167442020-02-10 11:49:52 +0000104 if (bs->last_rx_nsec)
Klement Sekerae50e8562017-04-04 16:19:48 +0200105 {
Klement Sekeraa3167442020-02-10 11:49:52 +0000106 tmp = format (tmp, "%.2fs ago", (now - bs->last_rx_nsec) *
Klement Sekerae50e8562017-04-04 16:19:48 +0200107 vm->clib_time.seconds_per_clock);
108 s = format (s, "%10s %-32s %20v\n", "", "Last control frame rx", tmp);
109 vec_reset_length (tmp);
110 }
Klement Sekera73884482017-02-23 09:26:30 +0100111 s =
Klement Sekerae50e8562017-04-04 16:19:48 +0200112 format (s, "%10s %-32s %20u %20llu\n", "", "Min Echo Rx Interval (usec)",
113 1, bs->remote_min_echo_rx_usec);
114 if (bs->echo)
115 {
Klement Sekeraa3167442020-02-10 11:49:52 +0000116 s =
117 format (s, "%10s %-32s %20u\n", "", "Echo transmit interval",
118 bfd_nsec_to_usec (bs->echo_transmit_interval_nsec));
119 tmp =
120 format (tmp, "%.2fs ago",
121 (now -
122 bs->echo_last_tx_nsec) * vm->clib_time.seconds_per_clock);
Klement Sekerae50e8562017-04-04 16:19:48 +0200123 s = format (s, "%10s %-32s %20v\n", "", "Last echo frame tx", tmp);
124 vec_reset_length (tmp);
125 tmp = format (tmp, "%.6fs",
Klement Sekeraa3167442020-02-10 11:49:52 +0000126 (bs->echo_last_rx_nsec - bs->echo_last_tx_nsec) *
Klement Sekerae50e8562017-04-04 16:19:48 +0200127 vm->clib_time.seconds_per_clock);
128 s =
129 format (s, "%10s %-32s %20v\n", "", "Last echo frame roundtrip time",
130 tmp);
131 }
132 vec_free (tmp);
133 tmp = NULL;
134 s = format (s, "%10s %-32s %20s %20s\n", "", "Demand mode", "no",
135 bs->remote_demand ? "yes" : "no");
136 s = format (s, "%10s %-32s %20s\n", "", "Poll state",
137 bfd_poll_state_string (bs->poll_state));
Klement Sekera73884482017-02-23 09:26:30 +0100138 if (bs->auth.curr_key)
139 {
140 s = format (s, "%10s %-32s %20u\n", "", "Authentication config key ID",
141 bs->auth.curr_key->conf_key_id);
142 s = format (s, "%10s %-32s %20u\n", "", "Authentication BFD key ID",
143 bs->auth.curr_bfd_key_id);
Klement Sekerae50e8562017-04-04 16:19:48 +0200144 s = format (s, "%10s %-32s %20u %20u\n", "", "Sequence number",
145 bs->auth.local_seq_number, bs->auth.remote_seq_number);
Klement Sekera73884482017-02-23 09:26:30 +0100146 }
147 return s;
148}
149
150static clib_error_t *
151show_bfd (vlib_main_t * vm, unformat_input_t * input,
152 CLIB_UNUSED (vlib_cli_command_t * lmd))
153{
154 bfd_main_t *bm = &bfd_main;
155 bfd_session_t *bs = NULL;
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100156 unformat_input_t _line_input, *line_input = &_line_input;
Klement Sekera73884482017-02-23 09:26:30 +0100157
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100158 /* Get a line of input. */
159 if (!unformat_user (input, unformat_line_input, line_input))
160 return 0;
161
162 if (unformat (line_input, "keys"))
Klement Sekera73884482017-02-23 09:26:30 +0100163 {
164 bfd_auth_key_t *key = NULL;
165 u8 *s = format (NULL, "%=10s %=25s %=10s\n", "Configuration Key ID",
166 "Type", "Use Count");
Damjan Marionb2c31b62020-12-13 21:47:40 +0100167 pool_foreach (key, bm->auth_keys) {
Klement Sekera73884482017-02-23 09:26:30 +0100168 s = format (s, "%10u %-25s %10u\n", key->conf_key_id,
169 bfd_auth_type_str (key->auth_type), key->use_count);
Damjan Marionb2c31b62020-12-13 21:47:40 +0100170 }
Klement Sekera73884482017-02-23 09:26:30 +0100171 vlib_cli_output (vm, "%v\n", s);
Klement Sekerae50e8562017-04-04 16:19:48 +0200172 vec_free (s);
Klement Sekera73884482017-02-23 09:26:30 +0100173 vlib_cli_output (vm, "Number of configured BFD keys: %lu\n",
174 (u64) pool_elts (bm->auth_keys));
175 }
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100176 else if (unformat (line_input, "sessions"))
Klement Sekera73884482017-02-23 09:26:30 +0100177 {
178 u8 *s = format (NULL, "%=10s %=32s %=20s %=20s\n", "Index", "Property",
179 "Local value", "Remote value");
Damjan Marionb2c31b62020-12-13 21:47:40 +0100180 pool_foreach (bs, bm->sessions) {
Klement Sekeraa3167442020-02-10 11:49:52 +0000181 s = format (s, "%U", format_bfd_session_cli, vm, bs);
Damjan Marionb2c31b62020-12-13 21:47:40 +0100182 }
Klement Sekera73884482017-02-23 09:26:30 +0100183 vlib_cli_output (vm, "%v", s);
184 vec_free (s);
185 vlib_cli_output (vm, "Number of configured BFD sessions: %lu\n",
186 (u64) pool_elts (bm->sessions));
187 }
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100188 else if (unformat (line_input, "echo-source"))
Klement Sekera73884482017-02-23 09:26:30 +0100189 {
190 int is_set;
191 u32 sw_if_index;
192 int have_usable_ip4;
193 ip4_address_t ip4;
194 int have_usable_ip6;
195 ip6_address_t ip6;
196 bfd_udp_get_echo_source (&is_set, &sw_if_index, &have_usable_ip4, &ip4,
197 &have_usable_ip6, &ip6);
198 if (is_set)
199 {
200 vnet_sw_interface_t *sw_if =
Dave Barach3940de32019-07-23 16:28:36 -0400201 vnet_get_sw_interface_or_null (&vnet_main, sw_if_index);
Klement Sekera73884482017-02-23 09:26:30 +0100202 vnet_hw_interface_t *hw_if =
203 vnet_get_hw_interface (&vnet_main, sw_if->hw_if_index);
204 u8 *s = format (NULL, "UDP echo source is: %v\n", hw_if->name);
205 s = format (s, "IPv4 address usable as echo source: ");
206 if (have_usable_ip4)
207 {
208 s = format (s, "%U\n", format_ip4_address, &ip4);
209 }
210 else
211 {
212 s = format (s, "none\n");
213 }
214 s = format (s, "IPv6 address usable as echo source: ");
215 if (have_usable_ip6)
216 {
217 s = format (s, "%U\n", format_ip6_address, &ip6);
218 }
219 else
220 {
221 s = format (s, "none\n");
222 }
223 vlib_cli_output (vm, "%v", s);
224 vec_free (s);
225 }
226 else
227 {
228 vlib_cli_output (vm, "UDP echo source is not set.\n");
229 }
230 }
231 else
232 {
233 vlib_cli_output (vm, "Number of configured BFD sessions: %lu\n",
234 (u64) pool_elts (bm->sessions));
235 vlib_cli_output (vm, "Number of configured BFD keys: %lu\n",
236 (u64) pool_elts (bm->auth_keys));
237 }
238 return 0;
239}
240
Klement Sekera73884482017-02-23 09:26:30 +0100241VLIB_CLI_COMMAND (show_bfd_command, static) = {
242 .path = "show bfd",
243 .short_help = "show bfd [keys|sessions|echo-source]",
244 .function = show_bfd,
245};
Klement Sekera73884482017-02-23 09:26:30 +0100246
Klement Sekera73884482017-02-23 09:26:30 +0100247static clib_error_t *
248bfd_cli_key_add (vlib_main_t * vm, unformat_input_t * input,
249 CLIB_UNUSED (vlib_cli_command_t * lmd))
250{
251 clib_error_t *ret = NULL;
252 int have_key_id = 0;
253 u32 key_id = 0;
254 u8 *vec_auth_type = NULL;
255 bfd_auth_type_e auth_type = BFD_AUTH_TYPE_reserved;
256 u8 *secret = NULL;
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100257 unformat_input_t _line_input, *line_input = &_line_input;
Klement Sekera73884482017-02-23 09:26:30 +0100258 static const u8 keyed_sha1[] = "keyed-sha1";
259 static const u8 meticulous_keyed_sha1[] = "meticulous-keyed-sha1";
260
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100261 /* Get a line of input. */
262 if (!unformat_user (input, unformat_line_input, line_input))
263 return 0;
264
265 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
Klement Sekera73884482017-02-23 09:26:30 +0100266 {
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100267 if (unformat (line_input, "conf-key-id %u", &key_id))
Klement Sekera73884482017-02-23 09:26:30 +0100268 {
269 have_key_id = 1;
270 }
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100271 else if (unformat (line_input, "type %U", unformat_token, "a-zA-Z0-9-",
Klement Sekera73884482017-02-23 09:26:30 +0100272 &vec_auth_type))
273 {
274 if (vec_len (vec_auth_type) == sizeof (keyed_sha1) - 1 &&
275 0 == memcmp (vec_auth_type, keyed_sha1,
276 sizeof (keyed_sha1) - 1))
277 {
278 auth_type = BFD_AUTH_TYPE_keyed_sha1;
279 }
280 else if (vec_len (vec_auth_type) ==
281 sizeof (meticulous_keyed_sha1) - 1 &&
282 0 == memcmp (vec_auth_type, meticulous_keyed_sha1,
283 sizeof (meticulous_keyed_sha1) - 1))
284 {
285 auth_type = BFD_AUTH_TYPE_meticulous_keyed_sha1;
286 }
287 else
288 {
289 ret = clib_error_return (0, "invalid type `%v'", vec_auth_type);
290 goto out;
291 }
292 }
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100293 else
294 if (unformat (line_input, "secret %U", unformat_hex_string, &secret))
Klement Sekera73884482017-02-23 09:26:30 +0100295 {
296 /* nothing to do here */
297 }
298 else
299 {
300 ret = clib_error_return (0, "Unknown input `%U'",
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100301 format_unformat_error, line_input);
Klement Sekera73884482017-02-23 09:26:30 +0100302 goto out;
303 }
304 }
305
306 if (!have_key_id)
307 {
308 ret =
309 clib_error_return (0, "required parameter missing: `conf-key-id'");
310 goto out;
311 }
312 if (!vec_auth_type)
313 {
314 ret = clib_error_return (0, "required parameter missing: `type'");
315 goto out;
316 }
317 if (!secret)
318 {
319 ret = clib_error_return (0, "required parameter missing: `secret'");
320 goto out;
321 }
322
323 vnet_api_error_t rv =
324 bfd_auth_set_key (key_id, auth_type, vec_len (secret), secret);
325 if (rv)
326 {
327 ret =
328 clib_error_return (0, "`bfd_auth_set_key' API call failed, rv=%d:%U",
329 (int) rv, format_vnet_api_errno, rv);
330 }
331
332out:
333 vec_free (vec_auth_type);
334 return ret;
335}
336
Klement Sekera73884482017-02-23 09:26:30 +0100337VLIB_CLI_COMMAND (bfd_cli_key_add_command, static) = {
338 .path = "bfd key set",
339 .short_help = "bfd key set"
340 " conf-key-id <id>"
341 " type <keyed-sha1|meticulous-keyed-sha1> "
342 " secret <secret>",
343 .function = bfd_cli_key_add,
344};
Klement Sekera73884482017-02-23 09:26:30 +0100345
346static clib_error_t *
347bfd_cli_key_del (vlib_main_t * vm, unformat_input_t * input,
348 CLIB_UNUSED (vlib_cli_command_t * lmd))
349{
350 clib_error_t *ret = NULL;
351 u32 key_id = 0;
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100352 unformat_input_t _line_input, *line_input = &_line_input;
Klement Sekera73884482017-02-23 09:26:30 +0100353
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100354 /* Get a line of input. */
355 if (!unformat_user (input, unformat_line_input, line_input))
356 return 0;
357
358 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
Klement Sekera73884482017-02-23 09:26:30 +0100359 {
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100360 if (!unformat (line_input, "conf-key-id %u", &key_id))
Klement Sekera73884482017-02-23 09:26:30 +0100361 {
362 ret = clib_error_return (0, "Unknown input `%U'",
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100363 format_unformat_error, line_input);
Klement Sekera73884482017-02-23 09:26:30 +0100364 goto out;
365 }
366 }
367
368 vnet_api_error_t rv = bfd_auth_del_key (key_id);
369 if (rv)
370 {
371 ret =
372 clib_error_return (0, "`bfd_auth_del_key' API call failed, rv=%d:%U",
373 (int) rv, format_vnet_api_errno, rv);
374 }
375
376out:
377 return ret;
378}
379
Klement Sekera73884482017-02-23 09:26:30 +0100380VLIB_CLI_COMMAND (bfd_cli_key_del_command, static) = {
381 .path = "bfd key del",
382 .short_help = "bfd key del conf-key-id <id>",
383 .function = bfd_cli_key_del,
384};
Klement Sekera73884482017-02-23 09:26:30 +0100385
386#define INTERFACE_STR "interface"
387#define LOCAL_ADDR_STR "local-addr"
388#define PEER_ADDR_STR "peer-addr"
389#define CONF_KEY_ID_STR "conf-key-id"
390#define BFD_KEY_ID_STR "bfd-key-id"
391#define DESIRED_MIN_TX_STR "desired-min-tx"
392#define REQUIRED_MIN_RX_STR "required-min-rx"
393#define DETECT_MULT_STR "detect-mult"
394#define ADMIN_STR "admin"
395#define DELAYED_STR "delayed"
Abdel Baig17a91812024-09-03 11:52:20 -0400396#define MULTIHOP_STR "multihop"
Klement Sekera73884482017-02-23 09:26:30 +0100397
398static const unsigned mandatory = 1;
399static const unsigned optional = 0;
400
401#define DECLARE(t, n, s, r, ...) \
402 int have_##n = 0; \
403 t n;
404
405#define UNFORMAT(t, n, s, r, ...) \
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100406 if (unformat (line_input, s " " __VA_ARGS__, &n)) \
Klement Sekera73884482017-02-23 09:26:30 +0100407 { \
408 something_parsed = 1; \
409 have_##n = 1; \
410 }
411
412#define CHECK_MANDATORY(t, n, s, r, ...) \
Gabriel Gannebeb85cc2017-11-07 14:24:56 +0100413WARN_OFF(tautological-compare) \
Klement Sekera73884482017-02-23 09:26:30 +0100414 if (mandatory == r && !have_##n) \
415 { \
Gabriel Gannebeb85cc2017-11-07 14:24:56 +0100416 WARN_ON(tautological-compare) \
Klement Sekerae50e8562017-04-04 16:19:48 +0200417 ret = clib_error_return (0, "Required parameter `%s' missing.", s); \
Klement Sekera73884482017-02-23 09:26:30 +0100418 goto out; \
419 }
420
Benoît Gannecfaf4402023-01-06 09:58:53 +0100421static uword
422bfd_cli_unformat_ip46_address (unformat_input_t *input, va_list *args)
423{
424 ip46_address_t *ip46 = va_arg (*args, ip46_address_t *);
425 return unformat_user (input, unformat_ip46_address, ip46, IP46_TYPE_ANY);
426}
427
Klement Sekera73884482017-02-23 09:26:30 +0100428static clib_error_t *
429bfd_cli_udp_session_add (vlib_main_t * vm, unformat_input_t * input,
430 CLIB_UNUSED (vlib_cli_command_t * lmd))
431{
432 clib_error_t *ret = NULL;
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100433 unformat_input_t _line_input, *line_input = &_line_input;
Benoît Gannecfaf4402023-01-06 09:58:53 +0100434#define foreach_bfd_cli_udp_session_add_cli_param(F) \
Abdel Baig17a91812024-09-03 11:52:20 -0400435 F (bool, multihop, MULTIHOP_STR, optional, "%_") \
436 F (u32, sw_if_index, INTERFACE_STR, optional, "%U", \
Benoît Gannecfaf4402023-01-06 09:58:53 +0100437 unformat_vnet_sw_interface, &vnet_main) \
438 F (ip46_address_t, local_addr, LOCAL_ADDR_STR, mandatory, "%U", \
439 bfd_cli_unformat_ip46_address) \
440 F (ip46_address_t, peer_addr, PEER_ADDR_STR, mandatory, "%U", \
441 bfd_cli_unformat_ip46_address) \
442 F (u32, desired_min_tx, DESIRED_MIN_TX_STR, mandatory, "%u") \
443 F (u32, required_min_rx, REQUIRED_MIN_RX_STR, mandatory, "%u") \
444 F (u32, detect_mult, DETECT_MULT_STR, mandatory, "%u") \
445 F (u32, conf_key_id, CONF_KEY_ID_STR, optional, "%u") \
Klement Sekera73884482017-02-23 09:26:30 +0100446 F (u32, bfd_key_id, BFD_KEY_ID_STR, optional, "%u")
447
448 foreach_bfd_cli_udp_session_add_cli_param (DECLARE);
449
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100450 /* Get a line of input. */
451 if (!unformat_user (input, unformat_line_input, line_input))
452 return 0;
453
454 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
Klement Sekera73884482017-02-23 09:26:30 +0100455 {
456 int something_parsed = 0;
457 foreach_bfd_cli_udp_session_add_cli_param (UNFORMAT);
458
459 if (!something_parsed)
460 {
461 ret = clib_error_return (0, "Unknown input `%U'",
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100462 format_unformat_error, line_input);
Klement Sekera73884482017-02-23 09:26:30 +0100463 goto out;
464 }
465 }
466
467 foreach_bfd_cli_udp_session_add_cli_param (CHECK_MANDATORY);
Abdel Baig17a91812024-09-03 11:52:20 -0400468 BFD_MULTIHOP_CLI_CHECK
Klement Sekera73884482017-02-23 09:26:30 +0100469
470 if (1 == have_conf_key_id + have_bfd_key_id)
471 {
472 ret = clib_error_return (0, "Incompatible parameter combination, `%s' "
473 "and `%s' must be either both specified or none",
474 CONF_KEY_ID_STR, BFD_KEY_ID_STR);
475 goto out;
476 }
477
478 if (detect_mult > 255)
479 {
480 ret = clib_error_return (0, "%s value `%u' out of range <1,255>",
481 DETECT_MULT_STR, detect_mult);
482 goto out;
483 }
484
485 if (have_bfd_key_id && bfd_key_id > 255)
486 {
487 ret = clib_error_return (0, "%s value `%u' out of range <1,255>",
488 BFD_KEY_ID_STR, bfd_key_id);
489 goto out;
490 }
491
Abdel Baig17a91812024-09-03 11:52:20 -0400492 vnet_api_error_t rv = bfd_udp_add_session (
493 multihop, sw_if_index, &local_addr, &peer_addr, desired_min_tx,
494 required_min_rx, detect_mult, have_conf_key_id, conf_key_id, bfd_key_id);
Klement Sekera73884482017-02-23 09:26:30 +0100495 if (rv)
496 {
497 ret =
498 clib_error_return (0,
499 "`bfd_add_add_session' API call failed, rv=%d:%U",
500 (int) rv, format_vnet_api_errno, rv);
501 goto out;
502 }
503
504out:
505 return ret;
506}
507
Klement Sekera73884482017-02-23 09:26:30 +0100508VLIB_CLI_COMMAND (bfd_cli_udp_session_add_command, static) = {
509 .path = "bfd udp session add",
510 .short_help = "bfd udp session add"
Abdel Baig17a91812024-09-03 11:52:20 -0400511 " <multihop | interface <interface>>"
512 " local-addr <local-address>"
513 " peer-addr <peer-address>"
514 " desired-min-tx <desired min tx interval>"
515 " required-min-rx <required min rx interval>"
516 " detect-mult <detect multiplier> "
517 "["
518 " conf-key-id <config key ID>"
519 " bfd-key-id <BFD key ID>"
520 "]",
Klement Sekera73884482017-02-23 09:26:30 +0100521 .function = bfd_cli_udp_session_add,
522};
Klement Sekera73884482017-02-23 09:26:30 +0100523
524static clib_error_t *
525bfd_cli_udp_session_mod (vlib_main_t * vm, unformat_input_t * input,
526 CLIB_UNUSED (vlib_cli_command_t * lmd))
527{
528 clib_error_t *ret = NULL;
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100529 unformat_input_t _line_input, *line_input = &_line_input;
Benoît Gannecfaf4402023-01-06 09:58:53 +0100530#define foreach_bfd_cli_udp_session_mod_cli_param(F) \
Abdel Baig17a91812024-09-03 11:52:20 -0400531 F (bool, multihop, MULTIHOP_STR, optional, "%_") \
532 F (u32, sw_if_index, INTERFACE_STR, optional, "%U", \
Benoît Gannecfaf4402023-01-06 09:58:53 +0100533 unformat_vnet_sw_interface, &vnet_main) \
534 F (ip46_address_t, local_addr, LOCAL_ADDR_STR, mandatory, "%U", \
535 bfd_cli_unformat_ip46_address) \
536 F (ip46_address_t, peer_addr, PEER_ADDR_STR, mandatory, "%U", \
537 bfd_cli_unformat_ip46_address) \
538 F (u32, desired_min_tx, DESIRED_MIN_TX_STR, mandatory, "%u") \
539 F (u32, required_min_rx, REQUIRED_MIN_RX_STR, mandatory, "%u") \
Klement Sekera73884482017-02-23 09:26:30 +0100540 F (u32, detect_mult, DETECT_MULT_STR, mandatory, "%u")
541
542 foreach_bfd_cli_udp_session_mod_cli_param (DECLARE);
543
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100544 /* Get a line of input. */
545 if (!unformat_user (input, unformat_line_input, line_input))
546 return 0;
547
548 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
Klement Sekera73884482017-02-23 09:26:30 +0100549 {
550 int something_parsed = 0;
551 foreach_bfd_cli_udp_session_mod_cli_param (UNFORMAT);
552
553 if (!something_parsed)
554 {
555 ret = clib_error_return (0, "Unknown input `%U'",
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100556 format_unformat_error, line_input);
Klement Sekera73884482017-02-23 09:26:30 +0100557 goto out;
558 }
559 }
560
561 foreach_bfd_cli_udp_session_mod_cli_param (CHECK_MANDATORY);
Abdel Baig17a91812024-09-03 11:52:20 -0400562 BFD_MULTIHOP_CLI_CHECK
Klement Sekera73884482017-02-23 09:26:30 +0100563
564 if (detect_mult > 255)
565 {
566 ret = clib_error_return (0, "%s value `%u' out of range <1,255>",
567 DETECT_MULT_STR, detect_mult);
568 goto out;
569 }
570
571 vnet_api_error_t rv =
Abdel Baig17a91812024-09-03 11:52:20 -0400572 bfd_udp_mod_session (multihop, sw_if_index, &local_addr, &peer_addr,
Klement Sekera73884482017-02-23 09:26:30 +0100573 desired_min_tx, required_min_rx, detect_mult);
574 if (rv)
575 {
576 ret =
577 clib_error_return (0,
578 "`bfd_udp_mod_session' API call failed, rv=%d:%U",
579 (int) rv, format_vnet_api_errno, rv);
580 goto out;
581 }
582
583out:
584 return ret;
585}
586
Klement Sekera73884482017-02-23 09:26:30 +0100587VLIB_CLI_COMMAND (bfd_cli_udp_session_mod_command, static) = {
588 .path = "bfd udp session mod",
Abdel Baig17a91812024-09-03 11:52:20 -0400589 .short_help = "bfd udp session mod "
590 " <multihop | interface <interface>>"
591 " <local-address> peer-addr"
592 " <peer-address> desired-min-tx"
593 " <desired min tx interval> required-min-rx"
594 " <required min rx interval> detect-mult"
595 " <detect multiplier> ",
Klement Sekera73884482017-02-23 09:26:30 +0100596 .function = bfd_cli_udp_session_mod,
597};
Klement Sekera73884482017-02-23 09:26:30 +0100598
599static clib_error_t *
600bfd_cli_udp_session_del (vlib_main_t * vm, unformat_input_t * input,
601 CLIB_UNUSED (vlib_cli_command_t * lmd))
602{
603 clib_error_t *ret = NULL;
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100604 unformat_input_t _line_input, *line_input = &_line_input;
Benoît Gannecfaf4402023-01-06 09:58:53 +0100605#define foreach_bfd_cli_udp_session_del_cli_param(F) \
Abdel Baig17a91812024-09-03 11:52:20 -0400606 F (bool, multihop, MULTIHOP_STR, optional, "%_") \
607 F (u32, sw_if_index, INTERFACE_STR, optional, "%U", \
Benoît Gannecfaf4402023-01-06 09:58:53 +0100608 unformat_vnet_sw_interface, &vnet_main) \
609 F (ip46_address_t, local_addr, LOCAL_ADDR_STR, mandatory, "%U", \
610 bfd_cli_unformat_ip46_address) \
611 F (ip46_address_t, peer_addr, PEER_ADDR_STR, mandatory, "%U", \
612 bfd_cli_unformat_ip46_address)
Klement Sekera73884482017-02-23 09:26:30 +0100613
614 foreach_bfd_cli_udp_session_del_cli_param (DECLARE);
615
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100616 /* Get a line of input. */
617 if (!unformat_user (input, unformat_line_input, line_input))
618 return 0;
619
620 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
Klement Sekera73884482017-02-23 09:26:30 +0100621 {
622 int something_parsed = 0;
623 foreach_bfd_cli_udp_session_del_cli_param (UNFORMAT);
624
625 if (!something_parsed)
626 {
627 ret = clib_error_return (0, "Unknown input `%U'",
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100628 format_unformat_error, line_input);
Klement Sekera73884482017-02-23 09:26:30 +0100629 goto out;
630 }
631 }
632
633 foreach_bfd_cli_udp_session_del_cli_param (CHECK_MANDATORY);
Abdel Baig17a91812024-09-03 11:52:20 -0400634 BFD_MULTIHOP_CLI_CHECK
Klement Sekera73884482017-02-23 09:26:30 +0100635
636 vnet_api_error_t rv =
Abdel Baig17a91812024-09-03 11:52:20 -0400637 bfd_udp_del_session (multihop, sw_if_index, &local_addr, &peer_addr);
Klement Sekera73884482017-02-23 09:26:30 +0100638 if (rv)
639 {
640 ret =
641 clib_error_return (0,
642 "`bfd_udp_del_session' API call failed, rv=%d:%U",
643 (int) rv, format_vnet_api_errno, rv);
644 goto out;
645 }
646
647out:
648 return ret;
649}
650
Klement Sekera73884482017-02-23 09:26:30 +0100651VLIB_CLI_COMMAND (bfd_cli_udp_session_del_command, static) = {
652 .path = "bfd udp session del",
Abdel Baig17a91812024-09-03 11:52:20 -0400653 .short_help = "bfd udp session del <multihop |"
654 " interface <interface>> local-addr"
655 " <local-address> peer-addr"
656 "<peer-address> ",
Klement Sekera73884482017-02-23 09:26:30 +0100657 .function = bfd_cli_udp_session_del,
658};
Klement Sekera73884482017-02-23 09:26:30 +0100659
660static clib_error_t *
661bfd_cli_udp_session_set_flags (vlib_main_t * vm, unformat_input_t * input,
662 CLIB_UNUSED (vlib_cli_command_t * lmd))
663{
664 clib_error_t *ret = NULL;
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100665 unformat_input_t _line_input, *line_input = &_line_input;
Benoît Gannecfaf4402023-01-06 09:58:53 +0100666#define foreach_bfd_cli_udp_session_set_flags_cli_param(F) \
Abdel Baig17a91812024-09-03 11:52:20 -0400667 F (bool, multihop, MULTIHOP_STR, optional, "%_") \
668 F (u32, sw_if_index, INTERFACE_STR, optional, "%U", \
Benoît Gannecfaf4402023-01-06 09:58:53 +0100669 unformat_vnet_sw_interface, &vnet_main) \
670 F (ip46_address_t, local_addr, LOCAL_ADDR_STR, mandatory, "%U", \
671 bfd_cli_unformat_ip46_address) \
672 F (ip46_address_t, peer_addr, PEER_ADDR_STR, mandatory, "%U", \
673 bfd_cli_unformat_ip46_address) \
674 F (u8 *, admin_up_down_token, ADMIN_STR, mandatory, "%v", \
Klement Sekera73884482017-02-23 09:26:30 +0100675 &admin_up_down_token)
676
677 foreach_bfd_cli_udp_session_set_flags_cli_param (DECLARE);
678
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100679 /* Get a line of input. */
680 if (!unformat_user (input, unformat_line_input, line_input))
681 return 0;
682
683 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
Klement Sekera73884482017-02-23 09:26:30 +0100684 {
685 int something_parsed = 0;
686 foreach_bfd_cli_udp_session_set_flags_cli_param (UNFORMAT);
687
688 if (!something_parsed)
689 {
690 ret = clib_error_return (0, "Unknown input `%U'",
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100691 format_unformat_error, line_input);
Klement Sekera73884482017-02-23 09:26:30 +0100692 goto out;
693 }
694 }
695
696 foreach_bfd_cli_udp_session_set_flags_cli_param (CHECK_MANDATORY);
Abdel Baig17a91812024-09-03 11:52:20 -0400697 BFD_MULTIHOP_CLI_CHECK
Klement Sekera73884482017-02-23 09:26:30 +0100698
699 u8 admin_up_down;
700 static const char up[] = "up";
701 static const char down[] = "down";
702 if (!memcmp (admin_up_down_token, up, sizeof (up) - 1))
703 {
704 admin_up_down = 1;
705 }
706 else if (!memcmp (admin_up_down_token, down, sizeof (down) - 1))
707 {
708 admin_up_down = 0;
709 }
710 else
711 {
712 ret =
713 clib_error_return (0, "Unrecognized value for `%s' parameter: `%v'",
714 ADMIN_STR, admin_up_down_token);
715 goto out;
716 }
Abdel Baig17a91812024-09-03 11:52:20 -0400717 vnet_api_error_t rv = bfd_udp_session_set_flags (
718 vm, multihop, sw_if_index, &local_addr, &peer_addr, admin_up_down);
Klement Sekera73884482017-02-23 09:26:30 +0100719 if (rv)
720 {
721 ret =
722 clib_error_return (0,
723 "`bfd_udp_session_set_flags' API call failed, rv=%d:%U",
724 (int) rv, format_vnet_api_errno, rv);
725 goto out;
726 }
727
728out:
729 return ret;
730}
731
Klement Sekera73884482017-02-23 09:26:30 +0100732VLIB_CLI_COMMAND (bfd_cli_udp_session_set_flags_command, static) = {
733 .path = "bfd udp session set-flags",
734 .short_help = "bfd udp session set-flags"
Abdel Baig17a91812024-09-03 11:52:20 -0400735 " <multihop | interface <interface>>"
736 " local-addr <local-address>"
737 " peer-addr <peer-address>"
738 " admin <up|down>",
Klement Sekera73884482017-02-23 09:26:30 +0100739 .function = bfd_cli_udp_session_set_flags,
740};
Klement Sekera73884482017-02-23 09:26:30 +0100741
742static clib_error_t *
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100743bfd_cli_udp_session_auth_activate (vlib_main_t * vm,
744 unformat_input_t * input,
Klement Sekera73884482017-02-23 09:26:30 +0100745 CLIB_UNUSED (vlib_cli_command_t * lmd))
746{
747 clib_error_t *ret = NULL;
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100748 unformat_input_t _line_input, *line_input = &_line_input;
Benoît Gannecfaf4402023-01-06 09:58:53 +0100749#define foreach_bfd_cli_udp_session_auth_activate_cli_param(F) \
Abdel Baig17a91812024-09-03 11:52:20 -0400750 F (bool, multihop, MULTIHOP_STR, optional, "%_") \
751 F (u32, sw_if_index, INTERFACE_STR, optional, "%U", \
Benoît Gannecfaf4402023-01-06 09:58:53 +0100752 unformat_vnet_sw_interface, &vnet_main) \
753 F (ip46_address_t, local_addr, LOCAL_ADDR_STR, mandatory, "%U", \
754 bfd_cli_unformat_ip46_address) \
755 F (ip46_address_t, peer_addr, PEER_ADDR_STR, mandatory, "%U", \
756 bfd_cli_unformat_ip46_address) \
757 F (u8 *, delayed_token, DELAYED_STR, optional, "%v") \
758 F (u32, conf_key_id, CONF_KEY_ID_STR, mandatory, "%u") \
Klement Sekera73884482017-02-23 09:26:30 +0100759 F (u32, bfd_key_id, BFD_KEY_ID_STR, mandatory, "%u")
760
761 foreach_bfd_cli_udp_session_auth_activate_cli_param (DECLARE);
762
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100763 /* Get a line of input. */
764 if (!unformat_user (input, unformat_line_input, line_input))
765 return 0;
766
767 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
Klement Sekera73884482017-02-23 09:26:30 +0100768 {
769 int something_parsed = 0;
770 foreach_bfd_cli_udp_session_auth_activate_cli_param (UNFORMAT);
771
772 if (!something_parsed)
773 {
774 ret = clib_error_return (0, "Unknown input `%U'",
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100775 format_unformat_error, line_input);
Klement Sekera73884482017-02-23 09:26:30 +0100776 goto out;
777 }
778 }
779
780 foreach_bfd_cli_udp_session_auth_activate_cli_param (CHECK_MANDATORY);
Abdel Baig17a91812024-09-03 11:52:20 -0400781 BFD_MULTIHOP_CLI_CHECK
Klement Sekera73884482017-02-23 09:26:30 +0100782
783 u8 is_delayed = 0;
784 if (have_delayed_token)
785 {
786 static const char yes[] = "yes";
787 static const char no[] = "no";
788 if (!memcmp (delayed_token, yes, sizeof (yes) - 1))
789 {
790 is_delayed = 1;
791 }
792 else if (!memcmp (delayed_token, no, sizeof (no) - 1))
793 {
794 is_delayed = 0;
795 }
796 else
797 {
798 ret =
799 clib_error_return (0,
800 "Unrecognized value for `%s' parameter: `%v'",
801 DELAYED_STR, delayed_token);
802 goto out;
803 }
804 }
805
806 if (have_bfd_key_id && bfd_key_id > 255)
807 {
808 ret = clib_error_return (0, "%s value `%u' out of range <1,255>",
809 BFD_KEY_ID_STR, bfd_key_id);
810 goto out;
811 }
812
813 vnet_api_error_t rv =
Abdel Baig17a91812024-09-03 11:52:20 -0400814 bfd_udp_auth_activate (multihop, sw_if_index, &local_addr, &peer_addr,
815 conf_key_id, bfd_key_id, is_delayed);
Klement Sekera73884482017-02-23 09:26:30 +0100816 if (rv)
817 {
818 ret =
819 clib_error_return (0,
820 "`bfd_udp_auth_activate' API call failed, rv=%d:%U",
821 (int) rv, format_vnet_api_errno, rv);
822 goto out;
823 }
824
825out:
826 return ret;
827}
828
Klement Sekera73884482017-02-23 09:26:30 +0100829VLIB_CLI_COMMAND (bfd_cli_udp_session_auth_activate_command, static) = {
830 .path = "bfd udp session auth activate",
831 .short_help = "bfd udp session auth activate"
Abdel Baig17a91812024-09-03 11:52:20 -0400832 " <multihop | interface <interface>>"
833 " local-addr <local-address>"
834 " peer-addr <peer-address>"
835 " conf-key-id <config key ID>"
836 " bfd-key-id <BFD key ID>"
837 " [ delayed <yes|no> ]",
Klement Sekera73884482017-02-23 09:26:30 +0100838 .function = bfd_cli_udp_session_auth_activate,
839};
840
841static clib_error_t *
842bfd_cli_udp_session_auth_deactivate (vlib_main_t *vm, unformat_input_t *input,
843 CLIB_UNUSED (vlib_cli_command_t *lmd))
844{
845 clib_error_t *ret = NULL;
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100846 unformat_input_t _line_input, *line_input = &_line_input;
Benoît Gannecfaf4402023-01-06 09:58:53 +0100847#define foreach_bfd_cli_udp_session_auth_deactivate_cli_param(F) \
Abdel Baig17a91812024-09-03 11:52:20 -0400848 F (bool, multihop, MULTIHOP_STR, optional, "%_") \
849 F (u32, sw_if_index, INTERFACE_STR, optional, "%U", \
Benoît Gannecfaf4402023-01-06 09:58:53 +0100850 unformat_vnet_sw_interface, &vnet_main) \
851 F (ip46_address_t, local_addr, LOCAL_ADDR_STR, mandatory, "%U", \
852 bfd_cli_unformat_ip46_address) \
853 F (ip46_address_t, peer_addr, PEER_ADDR_STR, mandatory, "%U", \
854 bfd_cli_unformat_ip46_address) \
Klement Sekera73884482017-02-23 09:26:30 +0100855 F (u8 *, delayed_token, DELAYED_STR, optional, "%v")
856
857 foreach_bfd_cli_udp_session_auth_deactivate_cli_param (DECLARE);
858
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100859 /* Get a line of input. */
860 if (!unformat_user (input, unformat_line_input, line_input))
861 return 0;
862
863 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
Klement Sekera73884482017-02-23 09:26:30 +0100864 {
865 int something_parsed = 0;
866 foreach_bfd_cli_udp_session_auth_deactivate_cli_param (UNFORMAT);
867
868 if (!something_parsed)
869 {
870 ret = clib_error_return (0, "Unknown input `%U'",
871 format_unformat_error, input);
872 goto out;
873 }
874 }
875
876 foreach_bfd_cli_udp_session_auth_deactivate_cli_param (CHECK_MANDATORY);
Abdel Baig17a91812024-09-03 11:52:20 -0400877 BFD_MULTIHOP_CLI_CHECK
Klement Sekera73884482017-02-23 09:26:30 +0100878
879 u8 is_delayed = 0;
880 if (have_delayed_token)
881 {
882 static const char yes[] = "yes";
883 static const char no[] = "no";
884 if (!memcmp (delayed_token, yes, sizeof (yes) - 1))
885 {
886 is_delayed = 1;
887 }
888 else if (!memcmp (delayed_token, no, sizeof (no) - 1))
889 {
890 is_delayed = 0;
891 }
892 else
893 {
894 ret = clib_error_return (
895 0, "Unrecognized value for `%s' parameter: `%v'", DELAYED_STR,
896 delayed_token);
897 goto out;
898 }
899 }
900
Abdel Baig17a91812024-09-03 11:52:20 -0400901 vnet_api_error_t rv = bfd_udp_auth_deactivate (
902 multihop, sw_if_index, &local_addr, &peer_addr, is_delayed);
Klement Sekera73884482017-02-23 09:26:30 +0100903 if (rv)
904 {
905 ret = clib_error_return (
906 0, "`bfd_udp_auth_deactivate' API call failed, rv=%d:%U", (int)rv,
907 format_vnet_api_errno, rv);
908 goto out;
909 }
910
911out:
912 return ret;
913}
914
Klement Sekera73884482017-02-23 09:26:30 +0100915VLIB_CLI_COMMAND (bfd_cli_udp_session_auth_deactivate_command, static) = {
916 .path = "bfd udp session auth deactivate",
917 .short_help = "bfd udp session auth deactivate"
Abdel Baig17a91812024-09-03 11:52:20 -0400918 " <multihop | interface <interface>>"
919 " local-addr <local-address>"
920 " peer-addr <peer-address>"
921 "[ delayed <yes|no> ]",
Klement Sekera73884482017-02-23 09:26:30 +0100922 .function = bfd_cli_udp_session_auth_deactivate,
923};
Klement Sekera73884482017-02-23 09:26:30 +0100924
925static clib_error_t *
926bfd_cli_udp_set_echo_source (vlib_main_t * vm, unformat_input_t * input,
927 CLIB_UNUSED (vlib_cli_command_t * lmd))
928{
929 clib_error_t *ret = NULL;
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100930 unformat_input_t _line_input, *line_input = &_line_input;
Klement Sekera73884482017-02-23 09:26:30 +0100931#define foreach_bfd_cli_udp_set_echo_source_cli_param(F) \
932 F (u32, sw_if_index, INTERFACE_STR, mandatory, "%U", \
933 unformat_vnet_sw_interface, &vnet_main)
934
935 foreach_bfd_cli_udp_set_echo_source_cli_param (DECLARE);
936
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100937 /* Get a line of input. */
938 if (!unformat_user (input, unformat_line_input, line_input))
939 return 0;
940
941 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
Klement Sekera73884482017-02-23 09:26:30 +0100942 {
943 int something_parsed = 0;
944 foreach_bfd_cli_udp_set_echo_source_cli_param (UNFORMAT);
945
946 if (!something_parsed)
947 {
948 ret = clib_error_return (0, "Unknown input `%U'",
Klement Sekeradcbea0b2018-02-13 13:14:52 +0100949 format_unformat_error, line_input);
Klement Sekera73884482017-02-23 09:26:30 +0100950 goto out;
951 }
952 }
953
954 foreach_bfd_cli_udp_set_echo_source_cli_param (CHECK_MANDATORY);
955
956 vnet_api_error_t rv = bfd_udp_set_echo_source (sw_if_index);
957 if (rv)
958 {
959 ret =
960 clib_error_return (0,
961 "`bfd_udp_set_echo_source' API call failed, rv=%d:%U",
962 (int) rv, format_vnet_api_errno, rv);
963 goto out;
964 }
965
966out:
967 return ret;
968}
969
Klement Sekera73884482017-02-23 09:26:30 +0100970VLIB_CLI_COMMAND (bfd_cli_udp_set_echo_source_cmd, static) = {
971 .path = "bfd udp echo-source set",
972 .short_help = "bfd udp echo-source set interface <interface>",
973 .function = bfd_cli_udp_set_echo_source,
974};
Klement Sekera73884482017-02-23 09:26:30 +0100975
976static clib_error_t *
977bfd_cli_udp_del_echo_source (vlib_main_t * vm, unformat_input_t * input,
978 CLIB_UNUSED (vlib_cli_command_t * lmd))
979{
980 vnet_api_error_t rv = bfd_udp_del_echo_source ();
981 if (rv)
982 {
983 return clib_error_return (0,
984 "`bfd_udp_del_echo_source' API call failed, rv=%d:%U",
985 (int) rv, format_vnet_api_errno, rv);
986 }
987
988 return 0;
989}
990
Klement Sekera73884482017-02-23 09:26:30 +0100991VLIB_CLI_COMMAND (bfd_cli_udp_del_echo_source_cmd, static) = {
992 .path = "bfd udp echo-source del",
993 .short_help = "bfd udp echo-source del",
994 .function = bfd_cli_udp_del_echo_source,
995};
Klement Sekera73884482017-02-23 09:26:30 +0100996
997/*
998 * fd.io coding-style-patch-verification: ON
999 *
1000 * Local Variables:
1001 * eval: (c-set-style "gnu")
1002 * End:
1003 */