]> git.proxmox.com Git - mirror_frr.git/blob - bfdd/bfdd_cli.c
Merge pull request #12797 from jvidalallende/ubi8_minimal_dockerfile
[mirror_frr.git] / bfdd / bfdd_cli.c
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * BFD daemon CLI implementation.
4 *
5 * Copyright (C) 2019 Network Device Education Foundation, Inc. ("NetDEF")
6 * Rafael Zalamena
7 */
8
9 #include <zebra.h>
10
11 #include "lib/command.h"
12 #include "lib/log.h"
13 #include "lib/northbound_cli.h"
14
15 #include "bfdd/bfdd_cli_clippy.c"
16
17 #include "bfd.h"
18 #include "bfdd_nb.h"
19
20 /*
21 * Definitions.
22 */
23 #define PEER_STR "Configure peer\n"
24 #define INTERFACE_NAME_STR "Configure interface name to use\n"
25 #define PEER_IPV4_STR "IPv4 peer address\n"
26 #define PEER_IPV6_STR "IPv6 peer address\n"
27 #define MHOP_STR "Configure multihop\n"
28 #define LOCAL_STR "Configure local address\n"
29 #define LOCAL_IPV4_STR "IPv4 local address\n"
30 #define LOCAL_IPV6_STR "IPv6 local address\n"
31 #define LOCAL_INTF_STR "Configure local interface name to use\n"
32 #define VRF_STR "Configure VRF\n"
33 #define VRF_NAME_STR "Configure VRF name\n"
34
35 /*
36 * Prototypes.
37 */
38 static bool
39 bfd_cli_is_single_hop(struct vty *vty)
40 {
41 return strstr(VTY_CURR_XPATH, "/single-hop") != NULL;
42 }
43
44 static bool
45 bfd_cli_is_profile(struct vty *vty)
46 {
47 return strstr(VTY_CURR_XPATH, "/bfd/profile") != NULL;
48 }
49
50 /*
51 * Functions.
52 */
53 DEFPY_YANG_NOSH(
54 bfd_enter, bfd_enter_cmd,
55 "bfd",
56 "Configure BFD peers\n")
57 {
58 int ret;
59
60 nb_cli_enqueue_change(vty, "/frr-bfdd:bfdd/bfd", NB_OP_CREATE, NULL);
61 ret = nb_cli_apply_changes(vty, NULL);
62 if (ret == CMD_SUCCESS)
63 VTY_PUSH_XPATH(BFD_NODE, "/frr-bfdd:bfdd/bfd");
64
65 return ret;
66 }
67
68 DEFUN_YANG(
69 bfd_config_reset, bfd_config_reset_cmd,
70 "no bfd",
71 NO_STR
72 "Configure BFD peers\n")
73 {
74 nb_cli_enqueue_change(vty, "/frr-bfdd:bfdd/bfd", NB_OP_DESTROY, NULL);
75 return nb_cli_apply_changes(vty, NULL);
76 }
77
78 void bfd_cli_show_header(struct vty *vty,
79 const struct lyd_node *dnode
80 __attribute__((__unused__)),
81 bool show_defaults __attribute__((__unused__)))
82 {
83 vty_out(vty, "!\nbfd\n");
84 }
85
86 void bfd_cli_show_header_end(struct vty *vty, const struct lyd_node *dnode
87 __attribute__((__unused__)))
88 {
89 vty_out(vty, "exit\n");
90 vty_out(vty, "!\n");
91 }
92
93 DEFPY_YANG_NOSH(
94 bfd_peer_enter, bfd_peer_enter_cmd,
95 "peer <A.B.C.D|X:X::X:X> [{multihop$multihop|local-address <A.B.C.D|X:X::X:X>|interface IFNAME$ifname|vrf NAME}]",
96 PEER_STR
97 PEER_IPV4_STR
98 PEER_IPV6_STR
99 MHOP_STR
100 LOCAL_STR
101 LOCAL_IPV4_STR
102 LOCAL_IPV6_STR
103 INTERFACE_STR
104 LOCAL_INTF_STR
105 VRF_STR
106 VRF_NAME_STR)
107 {
108 int ret, slen;
109 char source_str[INET6_ADDRSTRLEN + 32];
110 char xpath[XPATH_MAXLEN], xpath_srcaddr[XPATH_MAXLEN + 32];
111
112 if (multihop) {
113 if (!local_address_str) {
114 vty_out(vty,
115 "%% local-address is required when using multihop\n");
116 return CMD_WARNING_CONFIG_FAILED;
117 }
118 if (ifname) {
119 vty_out(vty,
120 "%% interface is prohibited when using multihop\n");
121 return CMD_WARNING_CONFIG_FAILED;
122 }
123 snprintf(source_str, sizeof(source_str), "[source-addr='%s']",
124 local_address_str);
125 } else
126 source_str[0] = 0;
127
128 slen = snprintf(xpath, sizeof(xpath),
129 "/frr-bfdd:bfdd/bfd/sessions/%s%s[dest-addr='%s']",
130 multihop ? "multi-hop" : "single-hop", source_str,
131 peer_str);
132 if (ifname)
133 slen += snprintf(xpath + slen, sizeof(xpath) - slen,
134 "[interface='%s']", ifname);
135 else if (!multihop)
136 slen += snprintf(xpath + slen, sizeof(xpath) - slen,
137 "[interface='*']");
138 if (vrf)
139 snprintf(xpath + slen, sizeof(xpath) - slen, "[vrf='%s']", vrf);
140 else
141 snprintf(xpath + slen, sizeof(xpath) - slen, "[vrf='%s']",
142 VRF_DEFAULT_NAME);
143
144 nb_cli_enqueue_change(vty, xpath, NB_OP_CREATE, NULL);
145 if (multihop == NULL && local_address_str != NULL) {
146 snprintf(xpath_srcaddr, sizeof(xpath_srcaddr),
147 "%s/source-addr", xpath);
148 nb_cli_enqueue_change(vty, xpath_srcaddr, NB_OP_MODIFY,
149 local_address_str);
150 }
151
152 /* Apply settings immediately. */
153 ret = nb_cli_apply_changes(vty, NULL);
154 if (ret == CMD_SUCCESS)
155 VTY_PUSH_XPATH(BFD_PEER_NODE, xpath);
156
157 return ret;
158 }
159
160 DEFPY_YANG(
161 bfd_no_peer, bfd_no_peer_cmd,
162 "no peer <A.B.C.D|X:X::X:X> [{multihop$multihop|local-address <A.B.C.D|X:X::X:X>|interface IFNAME$ifname|vrf NAME}]",
163 NO_STR
164 PEER_STR
165 PEER_IPV4_STR
166 PEER_IPV6_STR
167 MHOP_STR
168 LOCAL_STR
169 LOCAL_IPV4_STR
170 LOCAL_IPV6_STR
171 INTERFACE_STR
172 LOCAL_INTF_STR
173 VRF_STR
174 VRF_NAME_STR)
175 {
176 int slen;
177 char xpath[XPATH_MAXLEN];
178 char source_str[INET6_ADDRSTRLEN + 32];
179
180 if (multihop) {
181 if (!local_address_str) {
182 vty_out(vty,
183 "%% local-address is required when using multihop\n");
184 return CMD_WARNING_CONFIG_FAILED;
185 }
186 if (ifname) {
187 vty_out(vty,
188 "%% interface is prohibited when using multihop\n");
189 return CMD_WARNING_CONFIG_FAILED;
190 }
191 snprintf(source_str, sizeof(source_str), "[source-addr='%s']",
192 local_address_str);
193 } else
194 source_str[0] = 0;
195
196 slen = snprintf(xpath, sizeof(xpath),
197 "/frr-bfdd:bfdd/bfd/sessions/%s%s[dest-addr='%s']",
198 multihop ? "multi-hop" : "single-hop", source_str,
199 peer_str);
200 if (ifname)
201 slen += snprintf(xpath + slen, sizeof(xpath) - slen,
202 "[interface='%s']", ifname);
203 else if (!multihop)
204 slen += snprintf(xpath + slen, sizeof(xpath) - slen,
205 "[interface='*']");
206 if (vrf)
207 snprintf(xpath + slen, sizeof(xpath) - slen, "[vrf='%s']", vrf);
208 else
209 snprintf(xpath + slen, sizeof(xpath) - slen, "[vrf='%s']",
210 VRF_DEFAULT_NAME);
211
212 nb_cli_enqueue_change(vty, xpath, NB_OP_DESTROY, NULL);
213
214 /* Apply settings immediatly. */
215 return nb_cli_apply_changes(vty, NULL);
216 }
217
218 static void _bfd_cli_show_peer(struct vty *vty, const struct lyd_node *dnode,
219 bool show_defaults __attribute__((__unused__)),
220 bool mhop)
221 {
222 const char *vrf = yang_dnode_get_string(dnode, "./vrf");
223
224 vty_out(vty, " peer %s",
225 yang_dnode_get_string(dnode, "./dest-addr"));
226
227 if (mhop)
228 vty_out(vty, " multihop");
229
230 if (yang_dnode_exists(dnode, "./source-addr"))
231 vty_out(vty, " local-address %s",
232 yang_dnode_get_string(dnode, "./source-addr"));
233
234 if (strcmp(vrf, VRF_DEFAULT_NAME))
235 vty_out(vty, " vrf %s", vrf);
236
237 if (!mhop) {
238 const char *ifname =
239 yang_dnode_get_string(dnode, "./interface");
240 if (strcmp(ifname, "*"))
241 vty_out(vty, " interface %s", ifname);
242 }
243
244 vty_out(vty, "\n");
245 }
246
247 void bfd_cli_show_single_hop_peer(struct vty *vty, const struct lyd_node *dnode,
248 bool show_defaults)
249 {
250 _bfd_cli_show_peer(vty, dnode, show_defaults, false);
251 }
252
253 void bfd_cli_show_multi_hop_peer(struct vty *vty, const struct lyd_node *dnode,
254 bool show_defaults)
255 {
256 _bfd_cli_show_peer(vty, dnode, show_defaults, true);
257 }
258
259 void bfd_cli_show_peer_end(struct vty *vty, const struct lyd_node *dnode
260 __attribute__((__unused__)))
261 {
262 vty_out(vty, " exit\n");
263 vty_out(vty, " !\n");
264 }
265
266 DEFPY_YANG(
267 bfd_peer_shutdown, bfd_peer_shutdown_cmd,
268 "[no] shutdown",
269 NO_STR
270 "Disable BFD peer\n")
271 {
272 nb_cli_enqueue_change(vty, "./administrative-down", NB_OP_MODIFY,
273 no ? "false" : "true");
274 return nb_cli_apply_changes(vty, NULL);
275 }
276
277 void bfd_cli_show_shutdown(struct vty *vty, const struct lyd_node *dnode,
278 bool show_defaults)
279 {
280 vty_out(vty, " %sshutdown\n",
281 yang_dnode_get_bool(dnode, NULL) ? "" : "no ");
282 }
283
284 DEFPY_YANG(
285 bfd_peer_passive, bfd_peer_passive_cmd,
286 "[no] passive-mode",
287 NO_STR
288 "Don't attempt to start sessions\n")
289 {
290 nb_cli_enqueue_change(vty, "./passive-mode", NB_OP_MODIFY,
291 no ? "false" : "true");
292 return nb_cli_apply_changes(vty, NULL);
293 }
294
295 void bfd_cli_show_passive(struct vty *vty, const struct lyd_node *dnode,
296 bool show_defaults)
297 {
298 vty_out(vty, " %spassive-mode\n",
299 yang_dnode_get_bool(dnode, NULL) ? "" : "no ");
300 }
301
302 DEFPY_YANG(
303 bfd_peer_minimum_ttl, bfd_peer_minimum_ttl_cmd,
304 "[no] minimum-ttl (1-254)$ttl",
305 NO_STR
306 "Expect packets with at least this TTL\n"
307 "Minimum TTL expected\n")
308 {
309 if (bfd_cli_is_single_hop(vty)) {
310 vty_out(vty, "%% Minimum TTL is only available for multi hop sessions.\n");
311 return CMD_WARNING_CONFIG_FAILED;
312 }
313
314 if (no)
315 nb_cli_enqueue_change(vty, "./minimum-ttl", NB_OP_DESTROY,
316 NULL);
317 else
318 nb_cli_enqueue_change(vty, "./minimum-ttl", NB_OP_MODIFY,
319 ttl_str);
320 return nb_cli_apply_changes(vty, NULL);
321 }
322
323 DEFPY_YANG(
324 no_bfd_peer_minimum_ttl, no_bfd_peer_minimum_ttl_cmd,
325 "no minimum-ttl",
326 NO_STR
327 "Expect packets with at least this TTL\n")
328 {
329 nb_cli_enqueue_change(vty, "./minimum-ttl", NB_OP_DESTROY, NULL);
330 return nb_cli_apply_changes(vty, NULL);
331 }
332
333 void bfd_cli_show_minimum_ttl(struct vty *vty, const struct lyd_node *dnode,
334 bool show_defaults)
335 {
336 vty_out(vty, " minimum-ttl %s\n", yang_dnode_get_string(dnode, NULL));
337 }
338
339 DEFPY_YANG(
340 bfd_peer_mult, bfd_peer_mult_cmd,
341 "detect-multiplier (2-255)$multiplier",
342 "Configure peer detection multiplier\n"
343 "Configure peer detection multiplier value\n")
344 {
345 nb_cli_enqueue_change(vty, "./detection-multiplier", NB_OP_MODIFY,
346 multiplier_str);
347 return nb_cli_apply_changes(vty, NULL);
348 }
349
350 void bfd_cli_show_mult(struct vty *vty, const struct lyd_node *dnode,
351 bool show_defaults)
352 {
353 vty_out(vty, " detect-multiplier %s\n",
354 yang_dnode_get_string(dnode, NULL));
355 }
356
357 DEFPY_YANG(
358 bfd_peer_rx, bfd_peer_rx_cmd,
359 "receive-interval (10-60000)$interval",
360 "Configure peer receive interval\n"
361 "Configure peer receive interval value in milliseconds\n")
362 {
363 char value[32];
364
365 snprintf(value, sizeof(value), "%ld", interval * 1000);
366 nb_cli_enqueue_change(vty, "./required-receive-interval", NB_OP_MODIFY,
367 value);
368
369 return nb_cli_apply_changes(vty, NULL);
370 }
371
372 void bfd_cli_show_rx(struct vty *vty, const struct lyd_node *dnode,
373 bool show_defaults)
374 {
375 uint32_t value = yang_dnode_get_uint32(dnode, NULL);
376
377 vty_out(vty, " receive-interval %u\n", value / 1000);
378 }
379
380 DEFPY_YANG(
381 bfd_peer_tx, bfd_peer_tx_cmd,
382 "transmit-interval (10-60000)$interval",
383 "Configure peer transmit interval\n"
384 "Configure peer transmit interval value in milliseconds\n")
385 {
386 char value[32];
387
388 snprintf(value, sizeof(value), "%ld", interval * 1000);
389 nb_cli_enqueue_change(vty, "./desired-transmission-interval",
390 NB_OP_MODIFY, value);
391
392 return nb_cli_apply_changes(vty, NULL);
393 }
394
395 void bfd_cli_show_tx(struct vty *vty, const struct lyd_node *dnode,
396 bool show_defaults)
397 {
398 uint32_t value = yang_dnode_get_uint32(dnode, NULL);
399
400 vty_out(vty, " transmit-interval %u\n", value / 1000);
401 }
402
403 DEFPY_YANG(
404 bfd_peer_echo, bfd_peer_echo_cmd,
405 "[no] echo-mode",
406 NO_STR
407 "Configure echo mode\n")
408 {
409 if (!bfd_cli_is_profile(vty) && !bfd_cli_is_single_hop(vty)) {
410 vty_out(vty,
411 "%% Echo mode is only available for single hop sessions.\n");
412 return CMD_WARNING_CONFIG_FAILED;
413 }
414
415 if (!no && !bglobal.bg_use_dplane) {
416 #ifdef BFD_LINUX
417 vty_out(vty,
418 "%% Echo mode works correctly for IPv4, but only works when the peer is also FRR for IPv6.\n");
419 #else
420 vty_out(vty,
421 "%% Current implementation of echo mode works only when the peer is also FRR.\n");
422 #endif /* BFD_LINUX */
423 }
424
425 nb_cli_enqueue_change(vty, "./echo-mode", NB_OP_MODIFY,
426 no ? "false" : "true");
427 return nb_cli_apply_changes(vty, NULL);
428 }
429
430 void bfd_cli_show_echo(struct vty *vty, const struct lyd_node *dnode,
431 bool show_defaults)
432 {
433 vty_out(vty, " %secho-mode\n",
434 yang_dnode_get_bool(dnode, NULL) ? "" : "no ");
435 }
436
437 DEFPY_YANG(
438 bfd_peer_echo_interval, bfd_peer_echo_interval_cmd,
439 "echo-interval (10-60000)$interval",
440 "Configure peer echo intervals\n"
441 "Configure peer echo rx/tx intervals value in milliseconds\n")
442 {
443 char value[32];
444
445 if (!bfd_cli_is_profile(vty) && !bfd_cli_is_single_hop(vty)) {
446 vty_out(vty, "%% Echo mode is only available for single hop sessions.\n");
447 return CMD_WARNING_CONFIG_FAILED;
448 }
449
450 snprintf(value, sizeof(value), "%ld", interval * 1000);
451 nb_cli_enqueue_change(vty, "./desired-echo-transmission-interval",
452 NB_OP_MODIFY, value);
453 nb_cli_enqueue_change(vty, "./required-echo-receive-interval",
454 NB_OP_MODIFY, value);
455
456 return nb_cli_apply_changes(vty, NULL);
457 }
458
459 DEFPY_YANG(
460 bfd_peer_echo_transmit_interval, bfd_peer_echo_transmit_interval_cmd,
461 "echo transmit-interval (10-60000)$interval",
462 "Configure peer echo intervals\n"
463 "Configure desired transmit interval\n"
464 "Configure interval value in milliseconds\n")
465 {
466 char value[32];
467
468 if (!bfd_cli_is_profile(vty) && !bfd_cli_is_single_hop(vty)) {
469 vty_out(vty, "%% Echo mode is only available for single hop sessions.\n");
470 return CMD_WARNING_CONFIG_FAILED;
471 }
472
473 snprintf(value, sizeof(value), "%ld", interval * 1000);
474 nb_cli_enqueue_change(vty, "./desired-echo-transmission-interval",
475 NB_OP_MODIFY, value);
476
477 return nb_cli_apply_changes(vty, NULL);
478 }
479
480 void bfd_cli_show_desired_echo_transmission_interval(
481 struct vty *vty, const struct lyd_node *dnode, bool show_defaults)
482 {
483 uint32_t value = yang_dnode_get_uint32(dnode, NULL);
484
485 vty_out(vty, " echo transmit-interval %u\n", value / 1000);
486 }
487
488 DEFPY_YANG(
489 bfd_peer_echo_receive_interval, bfd_peer_echo_receive_interval_cmd,
490 "echo receive-interval <disabled$disabled|(10-60000)$interval>",
491 "Configure peer echo intervals\n"
492 "Configure required receive interval\n"
493 "Disable echo packets receive\n"
494 "Configure interval value in milliseconds\n")
495 {
496 char value[32];
497
498 if (!bfd_cli_is_profile(vty) && !bfd_cli_is_single_hop(vty)) {
499 vty_out(vty, "%% Echo mode is only available for single hop sessions.\n");
500 return CMD_WARNING_CONFIG_FAILED;
501 }
502
503 if (disabled)
504 snprintf(value, sizeof(value), "0");
505 else
506 snprintf(value, sizeof(value), "%ld", interval * 1000);
507
508 nb_cli_enqueue_change(vty, "./required-echo-receive-interval",
509 NB_OP_MODIFY, value);
510
511 return nb_cli_apply_changes(vty, NULL);
512 }
513
514 void bfd_cli_show_required_echo_receive_interval(struct vty *vty,
515 const struct lyd_node *dnode,
516 bool show_defaults)
517 {
518 uint32_t value = yang_dnode_get_uint32(dnode, NULL);
519
520 if (value)
521 vty_out(vty, " echo receive-interval %u\n", value / 1000);
522 else
523 vty_out(vty, " echo receive-interval disabled\n");
524 }
525
526 /*
527 * Profile commands.
528 */
529 DEFPY_YANG_NOSH(bfd_profile, bfd_profile_cmd,
530 "profile BFDPROF$name",
531 BFD_PROFILE_STR
532 BFD_PROFILE_NAME_STR)
533 {
534 char xpath[XPATH_MAXLEN];
535 int rv;
536
537 snprintf(xpath, sizeof(xpath), "/frr-bfdd:bfdd/bfd/profile[name='%s']",
538 name);
539
540 nb_cli_enqueue_change(vty, xpath, NB_OP_CREATE, NULL);
541
542 /* Apply settings immediately. */
543 rv = nb_cli_apply_changes(vty, NULL);
544 if (rv == CMD_SUCCESS)
545 VTY_PUSH_XPATH(BFD_PROFILE_NODE, xpath);
546
547 return CMD_SUCCESS;
548 }
549
550 DEFPY_YANG(no_bfd_profile, no_bfd_profile_cmd,
551 "no profile BFDPROF$name",
552 NO_STR
553 BFD_PROFILE_STR
554 BFD_PROFILE_NAME_STR)
555 {
556 char xpath[XPATH_MAXLEN];
557
558 snprintf(xpath, sizeof(xpath), "/frr-bfdd:bfdd/bfd/profile[name='%s']",
559 name);
560
561 nb_cli_enqueue_change(vty, xpath, NB_OP_DESTROY, NULL);
562
563 /* Apply settings immediately. */
564 return nb_cli_apply_changes(vty, NULL);
565 }
566
567 void bfd_cli_show_profile(struct vty *vty, const struct lyd_node *dnode,
568 bool show_defaults)
569 {
570 vty_out(vty, " profile %s\n", yang_dnode_get_string(dnode, "./name"));
571 }
572
573 ALIAS_YANG(bfd_peer_mult, bfd_profile_mult_cmd,
574 "detect-multiplier (2-255)$multiplier",
575 "Configure peer detection multiplier\n"
576 "Configure peer detection multiplier value\n")
577
578 ALIAS_YANG(bfd_peer_tx, bfd_profile_tx_cmd,
579 "transmit-interval (10-60000)$interval",
580 "Configure peer transmit interval\n"
581 "Configure peer transmit interval value in milliseconds\n")
582
583 ALIAS_YANG(bfd_peer_rx, bfd_profile_rx_cmd,
584 "receive-interval (10-60000)$interval",
585 "Configure peer receive interval\n"
586 "Configure peer receive interval value in milliseconds\n")
587
588 ALIAS_YANG(bfd_peer_shutdown, bfd_profile_shutdown_cmd,
589 "[no] shutdown",
590 NO_STR
591 "Disable BFD peer\n")
592
593 ALIAS_YANG(bfd_peer_passive, bfd_profile_passive_cmd,
594 "[no] passive-mode",
595 NO_STR
596 "Don't attempt to start sessions\n")
597
598 ALIAS_YANG(bfd_peer_minimum_ttl, bfd_profile_minimum_ttl_cmd,
599 "[no] minimum-ttl (1-254)$ttl",
600 NO_STR
601 "Expect packets with at least this TTL\n"
602 "Minimum TTL expected\n")
603
604 ALIAS_YANG(no_bfd_peer_minimum_ttl, no_bfd_profile_minimum_ttl_cmd,
605 "no minimum-ttl",
606 NO_STR
607 "Expect packets with at least this TTL\n")
608
609 ALIAS_YANG(bfd_peer_echo, bfd_profile_echo_cmd,
610 "[no] echo-mode",
611 NO_STR
612 "Configure echo mode\n")
613
614 ALIAS_YANG(bfd_peer_echo_interval, bfd_profile_echo_interval_cmd,
615 "echo-interval (10-60000)$interval",
616 "Configure peer echo interval\n"
617 "Configure peer echo interval value in milliseconds\n")
618
619 ALIAS_YANG(
620 bfd_peer_echo_transmit_interval, bfd_profile_echo_transmit_interval_cmd,
621 "echo transmit-interval (10-60000)$interval",
622 "Configure peer echo intervals\n"
623 "Configure desired transmit interval\n"
624 "Configure interval value in milliseconds\n")
625
626 ALIAS_YANG(
627 bfd_peer_echo_receive_interval, bfd_profile_echo_receive_interval_cmd,
628 "echo receive-interval <disabled$disabled|(10-60000)$interval>",
629 "Configure peer echo intervals\n"
630 "Configure required receive interval\n"
631 "Disable echo packets receive\n"
632 "Configure interval value in milliseconds\n")
633
634 DEFPY_YANG(bfd_peer_profile, bfd_peer_profile_cmd,
635 "[no] profile BFDPROF$pname",
636 NO_STR
637 "Use BFD profile settings\n"
638 BFD_PROFILE_NAME_STR)
639 {
640 if (no)
641 nb_cli_enqueue_change(vty, "./profile", NB_OP_DESTROY, NULL);
642 else
643 nb_cli_enqueue_change(vty, "./profile", NB_OP_MODIFY, pname);
644
645 return nb_cli_apply_changes(vty, NULL);
646 }
647
648 void bfd_cli_peer_profile_show(struct vty *vty, const struct lyd_node *dnode,
649 bool show_defaults)
650 {
651 vty_out(vty, " profile %s\n", yang_dnode_get_string(dnode, NULL));
652 }
653
654 struct cmd_node bfd_profile_node = {
655 .name = "bfd profile",
656 .node = BFD_PROFILE_NODE,
657 .parent_node = BFD_NODE,
658 .prompt = "%s(config-bfd-profile)# ",
659 };
660
661 static void bfd_profile_var(vector comps, struct cmd_token *token)
662 {
663 extern struct bfdproflist bplist;
664 struct bfd_profile *bp;
665
666 TAILQ_FOREACH (bp, &bplist, entry) {
667 vector_set(comps, XSTRDUP(MTYPE_COMPLETION, bp->name));
668 }
669 }
670
671 static const struct cmd_variable_handler bfd_vars[] = {
672 {.tokenname = "BFDPROF", .completions = bfd_profile_var},
673 {.completions = NULL}
674 };
675
676 void
677 bfdd_cli_init(void)
678 {
679 install_element(CONFIG_NODE, &bfd_enter_cmd);
680 install_element(CONFIG_NODE, &bfd_config_reset_cmd);
681
682 install_element(BFD_NODE, &bfd_peer_enter_cmd);
683 install_element(BFD_NODE, &bfd_no_peer_cmd);
684
685 install_element(BFD_PEER_NODE, &bfd_peer_shutdown_cmd);
686 install_element(BFD_PEER_NODE, &bfd_peer_mult_cmd);
687 install_element(BFD_PEER_NODE, &bfd_peer_rx_cmd);
688 install_element(BFD_PEER_NODE, &bfd_peer_tx_cmd);
689 install_element(BFD_PEER_NODE, &bfd_peer_echo_cmd);
690 install_element(BFD_PEER_NODE, &bfd_peer_echo_interval_cmd);
691 install_element(BFD_PEER_NODE, &bfd_peer_echo_transmit_interval_cmd);
692 install_element(BFD_PEER_NODE, &bfd_peer_echo_receive_interval_cmd);
693 install_element(BFD_PEER_NODE, &bfd_peer_profile_cmd);
694 install_element(BFD_PEER_NODE, &bfd_peer_passive_cmd);
695 install_element(BFD_PEER_NODE, &bfd_peer_minimum_ttl_cmd);
696 install_element(BFD_PEER_NODE, &no_bfd_peer_minimum_ttl_cmd);
697
698 /* Profile commands. */
699 cmd_variable_handler_register(bfd_vars);
700
701 install_node(&bfd_profile_node);
702 install_default(BFD_PROFILE_NODE);
703
704 install_element(BFD_NODE, &bfd_profile_cmd);
705 install_element(BFD_NODE, &no_bfd_profile_cmd);
706
707 install_element(BFD_PROFILE_NODE, &bfd_profile_mult_cmd);
708 install_element(BFD_PROFILE_NODE, &bfd_profile_tx_cmd);
709 install_element(BFD_PROFILE_NODE, &bfd_profile_rx_cmd);
710 install_element(BFD_PROFILE_NODE, &bfd_profile_shutdown_cmd);
711 install_element(BFD_PROFILE_NODE, &bfd_profile_echo_cmd);
712 install_element(BFD_PROFILE_NODE, &bfd_profile_echo_interval_cmd);
713 install_element(BFD_PROFILE_NODE, &bfd_profile_echo_transmit_interval_cmd);
714 install_element(BFD_PROFILE_NODE, &bfd_profile_echo_receive_interval_cmd);
715 install_element(BFD_PROFILE_NODE, &bfd_profile_passive_cmd);
716 install_element(BFD_PROFILE_NODE, &bfd_profile_minimum_ttl_cmd);
717 install_element(BFD_PROFILE_NODE, &no_bfd_profile_minimum_ttl_cmd);
718 }