3 * Copyright (C) 2018 Network Device Education Foundation, Inc. ("NetDEF")
5 * FRR is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2, or (at your option) any
10 * FRR is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with FRR; see the file COPYING. If not, write to the Free
17 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
23 #include "lib/command.h"
26 #include "lib/northbound_cli.h"
31 #ifndef VTYSH_EXTRACT_PL
32 #include "bfdd/bfdd_vty_clippy.c"
36 * Commands help string definitions.
38 #define PEER_IPV4_STR "IPv4 peer address\n"
39 #define PEER_IPV6_STR "IPv6 peer address\n"
40 #define MHOP_STR "Configure multihop\n"
41 #define LOCAL_STR "Configure local address\n"
42 #define LOCAL_IPV4_STR "IPv4 local address\n"
43 #define LOCAL_IPV6_STR "IPv6 local address\n"
44 #define LOCAL_INTF_STR "Configure local interface name to use\n"
49 static int bfd_configure_peer(struct bfd_peer_cfg
*bpc
, bool mhop
,
50 const struct sockaddr_any
*peer
,
51 const struct sockaddr_any
*local
,
52 const char *ifname
, const char *vrfname
,
53 char *ebuf
, size_t ebuflen
);
55 static void _display_peer_header(struct vty
*vty
, struct bfd_session
*bs
);
56 static struct json_object
*__display_peer_json(struct bfd_session
*bs
);
57 static struct json_object
*_peer_json_header(struct bfd_session
*bs
);
58 static void _display_peer_json(struct vty
*vty
, struct bfd_session
*bs
);
59 static void _display_peer(struct vty
*vty
, struct bfd_session
*bs
);
60 static void _display_all_peers(struct vty
*vty
, char *vrfname
, bool use_json
);
61 static void _display_peer_iter(struct hash_bucket
*hb
, void *arg
);
62 static void _display_peer_json_iter(struct hash_bucket
*hb
, void *arg
);
63 static void _display_peer_counter(struct vty
*vty
, struct bfd_session
*bs
);
64 static struct json_object
*__display_peer_counters_json(struct bfd_session
*bs
);
65 static void _display_peer_counters_json(struct vty
*vty
, struct bfd_session
*bs
);
66 static void _display_peer_counter_iter(struct hash_bucket
*hb
, void *arg
);
67 static void _display_peer_counter_json_iter(struct hash_bucket
*hb
, void *arg
);
68 static void _display_peers_counter(struct vty
*vty
, char *vrfname
, bool use_json
);
69 static struct bfd_session
*
70 _find_peer_or_error(struct vty
*vty
, int argc
, struct cmd_token
**argv
,
71 const char *label
, const char *peer_str
,
72 const char *local_str
, const char *ifname
,
77 * Show commands helper functions
79 static void _display_peer_header(struct vty
*vty
, struct bfd_session
*bs
)
81 char addr_buf
[INET6_ADDRSTRLEN
];
83 vty_out(vty
, "\tpeer %s",
84 inet_ntop(bs
->key
.family
, &bs
->key
.peer
, addr_buf
,
87 if (CHECK_FLAG(bs
->flags
, BFD_SESS_FLAG_MH
))
88 vty_out(vty
, " multihop");
90 if (memcmp(&bs
->key
.local
, &zero_addr
, sizeof(bs
->key
.local
)))
91 vty_out(vty
, " local-address %s",
92 inet_ntop(bs
->key
.family
, &bs
->key
.local
, addr_buf
,
95 if (bs
->key
.vrfname
[0])
96 vty_out(vty
, " vrf %s", bs
->key
.vrfname
);
97 if (bs
->key
.ifname
[0])
98 vty_out(vty
, " interface %s", bs
->key
.ifname
);
102 vty_out(vty
, "\t\tlabel: %s\n", bs
->pl
->pl_label
);
105 static void _display_peer(struct vty
*vty
, struct bfd_session
*bs
)
110 _display_peer_header(vty
, bs
);
112 vty_out(vty
, "\t\tID: %u\n", bs
->discrs
.my_discr
);
113 vty_out(vty
, "\t\tRemote ID: %u\n", bs
->discrs
.remote_discr
);
115 vty_out(vty
, "\t\tStatus: ");
116 switch (bs
->ses_state
) {
117 case PTM_BFD_ADM_DOWN
:
118 vty_out(vty
, "shutdown\n");
121 vty_out(vty
, "down\n");
123 now
= monotime(NULL
);
124 integer2timestr(now
- bs
->downtime
.tv_sec
, buf
, sizeof(buf
));
125 vty_out(vty
, "\t\tDowntime: %s\n", buf
);
128 vty_out(vty
, "init\n");
131 vty_out(vty
, "up\n");
133 now
= monotime(NULL
);
134 integer2timestr(now
- bs
->uptime
.tv_sec
, buf
, sizeof(buf
));
135 vty_out(vty
, "\t\tUptime: %s\n", buf
);
139 vty_out(vty
, "unknown\n");
143 vty_out(vty
, "\t\tDiagnostics: %s\n", diag2str(bs
->local_diag
));
144 vty_out(vty
, "\t\tRemote diagnostics: %s\n", diag2str(bs
->remote_diag
));
145 vty_out(vty
, "\t\tPeer Type: %s\n",
146 CHECK_FLAG(bs
->flags
, BFD_SESS_FLAG_CONFIG
) ? "configured" : "dynamic");
148 vty_out(vty
, "\t\tLocal timers:\n");
149 vty_out(vty
, "\t\t\tDetect-multiplier: %u\n",
151 vty_out(vty
, "\t\t\tReceive interval: %ums\n",
152 bs
->timers
.required_min_rx
/ 1000);
153 vty_out(vty
, "\t\t\tTransmission interval: %ums\n",
154 bs
->timers
.desired_min_tx
/ 1000);
155 vty_out(vty
, "\t\t\tEcho transmission interval: %ums\n",
156 bs
->timers
.required_min_echo
/ 1000);
158 vty_out(vty
, "\t\tRemote timers:\n");
159 vty_out(vty
, "\t\t\tDetect-multiplier: %u\n",
160 bs
->remote_detect_mult
);
161 vty_out(vty
, "\t\t\tReceive interval: %ums\n",
162 bs
->remote_timers
.required_min_rx
/ 1000);
163 vty_out(vty
, "\t\t\tTransmission interval: %ums\n",
164 bs
->remote_timers
.desired_min_tx
/ 1000);
165 vty_out(vty
, "\t\t\tEcho transmission interval: %ums\n",
166 bs
->remote_timers
.required_min_echo
/ 1000);
171 static struct json_object
*_peer_json_header(struct bfd_session
*bs
)
173 struct json_object
*jo
= json_object_new_object();
174 char addr_buf
[INET6_ADDRSTRLEN
];
177 json_object_boolean_true_add(jo
, "multihop");
179 json_object_boolean_false_add(jo
, "multihop");
181 json_object_string_add(jo
, "peer",
182 inet_ntop(bs
->key
.family
, &bs
->key
.peer
,
183 addr_buf
, sizeof(addr_buf
)));
184 if (memcmp(&bs
->key
.local
, &zero_addr
, sizeof(bs
->key
.local
)))
185 json_object_string_add(jo
, "local",
186 inet_ntop(bs
->key
.family
, &bs
->key
.local
,
187 addr_buf
, sizeof(addr_buf
)));
189 if (bs
->key
.vrfname
[0])
190 json_object_string_add(jo
, "vrf", bs
->key
.vrfname
);
191 if (bs
->key
.ifname
[0])
192 json_object_string_add(jo
, "interface", bs
->key
.ifname
);
195 json_object_string_add(jo
, "label", bs
->pl
->pl_label
);
200 static struct json_object
*__display_peer_json(struct bfd_session
*bs
)
202 struct json_object
*jo
= _peer_json_header(bs
);
204 json_object_int_add(jo
, "id", bs
->discrs
.my_discr
);
205 json_object_int_add(jo
, "remote-id", bs
->discrs
.remote_discr
);
207 switch (bs
->ses_state
) {
208 case PTM_BFD_ADM_DOWN
:
209 json_object_string_add(jo
, "status", "shutdown");
212 json_object_string_add(jo
, "status", "down");
213 json_object_int_add(jo
, "downtime",
214 monotime(NULL
) - bs
->downtime
.tv_sec
);
217 json_object_string_add(jo
, "status", "init");
220 json_object_string_add(jo
, "status", "up");
221 json_object_int_add(jo
, "uptime",
222 monotime(NULL
) - bs
->uptime
.tv_sec
);
226 json_object_string_add(jo
, "status", "unknown");
230 json_object_string_add(jo
, "diagnostic", diag2str(bs
->local_diag
));
231 json_object_string_add(jo
, "remote-diagnostic",
232 diag2str(bs
->remote_diag
));
234 json_object_int_add(jo
, "receive-interval",
235 bs
->timers
.required_min_rx
/ 1000);
236 json_object_int_add(jo
, "transmit-interval",
237 bs
->timers
.desired_min_tx
/ 1000);
238 if (CHECK_FLAG(bs
->flags
, BFD_SESS_FLAG_ECHO
))
239 json_object_int_add(jo
, "echo-interval",
240 bs
->timers
.required_min_echo
/ 1000);
242 json_object_int_add(jo
, "echo-interval", 0);
244 json_object_int_add(jo
, "detect-multiplier", bs
->detect_mult
);
246 json_object_int_add(jo
, "remote-receive-interval",
247 bs
->remote_timers
.required_min_rx
/ 1000);
248 json_object_int_add(jo
, "remote-transmit-interval",
249 bs
->remote_timers
.desired_min_tx
/ 1000);
250 json_object_int_add(jo
, "remote-echo-interval",
251 bs
->remote_timers
.required_min_echo
/ 1000);
252 json_object_int_add(jo
, "remote-detect-multiplier",
253 bs
->remote_detect_mult
);
258 static void _display_peer_json(struct vty
*vty
, struct bfd_session
*bs
)
260 struct json_object
*jo
= __display_peer_json(bs
);
262 vty_out(vty
, "%s\n", json_object_to_json_string_ext(jo
, 0));
263 json_object_free(jo
);
266 struct bfd_vrf_tuple
{
269 struct json_object
*jo
;
272 static void _display_peer_iter(struct hash_bucket
*hb
, void *arg
)
274 struct bfd_vrf_tuple
*bvt
= (struct bfd_vrf_tuple
*)arg
;
276 struct bfd_session
*bs
= hb
->data
;
283 if (!bs
->key
.vrfname
[0] ||
284 !strmatch(bs
->key
.vrfname
, bvt
->vrfname
))
287 _display_peer(vty
, bs
);
290 static void _display_peer_json_iter(struct hash_bucket
*hb
, void *arg
)
292 struct bfd_vrf_tuple
*bvt
= (struct bfd_vrf_tuple
*)arg
;
293 struct json_object
*jo
, *jon
= NULL
;
294 struct bfd_session
*bs
= hb
->data
;
301 if (!bs
->key
.vrfname
[0] ||
302 !strmatch(bs
->key
.vrfname
, bvt
->vrfname
))
306 jon
= __display_peer_json(bs
);
308 zlog_warn("%s: not enough memory", __func__
);
312 json_object_array_add(jo
, jon
);
315 static void _display_all_peers(struct vty
*vty
, char *vrfname
, bool use_json
)
317 struct json_object
*jo
;
318 struct bfd_vrf_tuple bvt
= {0};
320 bvt
.vrfname
= vrfname
;
324 vty_out(vty
, "BFD Peers:\n");
325 bfd_id_iterate(_display_peer_iter
, &bvt
);
329 jo
= json_object_new_array();
331 bfd_id_iterate(_display_peer_json_iter
, &bvt
);
333 vty_out(vty
, "%s\n", json_object_to_json_string_ext(jo
, 0));
334 json_object_free(jo
);
337 static void _display_peer_counter(struct vty
*vty
, struct bfd_session
*bs
)
339 _display_peer_header(vty
, bs
);
341 vty_out(vty
, "\t\tControl packet input: %" PRIu64
" packets\n",
342 bs
->stats
.rx_ctrl_pkt
);
343 vty_out(vty
, "\t\tControl packet output: %" PRIu64
" packets\n",
344 bs
->stats
.tx_ctrl_pkt
);
345 vty_out(vty
, "\t\tEcho packet input: %" PRIu64
" packets\n",
346 bs
->stats
.rx_echo_pkt
);
347 vty_out(vty
, "\t\tEcho packet output: %" PRIu64
" packets\n",
348 bs
->stats
.tx_echo_pkt
);
349 vty_out(vty
, "\t\tSession up events: %" PRIu64
"\n",
350 bs
->stats
.session_up
);
351 vty_out(vty
, "\t\tSession down events: %" PRIu64
"\n",
352 bs
->stats
.session_down
);
353 vty_out(vty
, "\t\tZebra notifications: %" PRIu64
"\n",
354 bs
->stats
.znotification
);
358 static struct json_object
*__display_peer_counters_json(struct bfd_session
*bs
)
360 struct json_object
*jo
= _peer_json_header(bs
);
362 json_object_int_add(jo
, "control-packet-input", bs
->stats
.rx_ctrl_pkt
);
363 json_object_int_add(jo
, "control-packet-output", bs
->stats
.tx_ctrl_pkt
);
364 json_object_int_add(jo
, "echo-packet-input", bs
->stats
.rx_echo_pkt
);
365 json_object_int_add(jo
, "echo-packet-output", bs
->stats
.tx_echo_pkt
);
366 json_object_int_add(jo
, "session-up", bs
->stats
.session_up
);
367 json_object_int_add(jo
, "session-down", bs
->stats
.session_down
);
368 json_object_int_add(jo
, "zebra-notifications", bs
->stats
.znotification
);
373 static void _display_peer_counters_json(struct vty
*vty
, struct bfd_session
*bs
)
375 struct json_object
*jo
= __display_peer_counters_json(bs
);
377 vty_out(vty
, "%s\n", json_object_to_json_string_ext(jo
, 0));
378 json_object_free(jo
);
381 static void _display_peer_counter_iter(struct hash_bucket
*hb
, void *arg
)
383 struct bfd_vrf_tuple
*bvt
= arg
;
385 struct bfd_session
*bs
= hb
->data
;
392 if (!bs
->key
.vrfname
[0] ||
393 !strmatch(bs
->key
.vrfname
, bvt
->vrfname
))
397 _display_peer_counter(vty
, bs
);
400 static void _display_peer_counter_json_iter(struct hash_bucket
*hb
, void *arg
)
402 struct json_object
*jo
, *jon
= NULL
;
403 struct bfd_session
*bs
= hb
->data
;
404 struct bfd_vrf_tuple
*bvt
= arg
;
411 if (!bs
->key
.vrfname
[0] ||
412 !strmatch(bs
->key
.vrfname
, bvt
->vrfname
))
416 jon
= __display_peer_counters_json(bs
);
418 zlog_warn("%s: not enough memory", __func__
);
422 json_object_array_add(jo
, jon
);
425 static void _display_peers_counter(struct vty
*vty
, char *vrfname
, bool use_json
)
427 struct json_object
*jo
;
428 struct bfd_vrf_tuple bvt
= {0};
430 bvt
.vrfname
= vrfname
;
433 vty_out(vty
, "BFD Peers:\n");
434 bfd_id_iterate(_display_peer_counter_iter
, &bvt
);
438 jo
= json_object_new_array();
440 bfd_id_iterate(_display_peer_counter_json_iter
, jo
);
442 vty_out(vty
, "%s\n", json_object_to_json_string_ext(jo
, 0));
443 json_object_free(jo
);
446 static void _clear_peer_counter(struct bfd_session
*bs
)
448 /* Clear only pkt stats, intention is not to loose system
450 bs
->stats
.rx_ctrl_pkt
= 0;
451 bs
->stats
.tx_ctrl_pkt
= 0;
452 bs
->stats
.rx_echo_pkt
= 0;
453 bs
->stats
.tx_echo_pkt
= 0;
456 static void _display_peer_brief(struct vty
*vty
, struct bfd_session
*bs
)
458 char addr_buf
[INET6_ADDRSTRLEN
];
460 if (CHECK_FLAG(bs
->flags
, BFD_SESS_FLAG_MH
)) {
461 vty_out(vty
, "%-10u", bs
->discrs
.my_discr
);
462 inet_ntop(bs
->key
.family
, &bs
->key
.local
, addr_buf
, sizeof(addr_buf
));
463 vty_out(vty
, " %-40s", addr_buf
);
464 inet_ntop(bs
->key
.family
, &bs
->key
.peer
, addr_buf
, sizeof(addr_buf
));
465 vty_out(vty
, " %-40s", addr_buf
);
466 vty_out(vty
, "%-15s\n", state_list
[bs
->ses_state
].str
);
468 vty_out(vty
, "%-10u", bs
->discrs
.my_discr
);
469 vty_out(vty
, " %-40s", satostr(&bs
->local_address
));
470 inet_ntop(bs
->key
.family
, &bs
->key
.peer
, addr_buf
, sizeof(addr_buf
));
471 vty_out(vty
, " %-40s", addr_buf
);
473 vty_out(vty
, "%-15s\n", state_list
[bs
->ses_state
].str
);
477 static void _display_peer_brief_iter(struct hash_bucket
*hb
, void *arg
)
479 struct bfd_vrf_tuple
*bvt
= arg
;
481 struct bfd_session
*bs
= hb
->data
;
488 if (!bs
->key
.vrfname
[0] ||
489 !strmatch(bs
->key
.vrfname
, bvt
->vrfname
))
493 _display_peer_brief(vty
, bs
);
496 static void _display_peers_brief(struct vty
*vty
, const char *vrfname
, bool use_json
)
498 struct json_object
*jo
;
499 struct bfd_vrf_tuple bvt
= {0};
501 bvt
.vrfname
= vrfname
;
506 vty_out(vty
, "Session count: %lu\n", bfd_get_session_count());
507 vty_out(vty
, "%-10s", "SessionId");
508 vty_out(vty
, " %-40s", "LocalAddress");
509 vty_out(vty
, " %-40s", "PeerAddress");
510 vty_out(vty
, "%-15s\n", "Status");
512 vty_out(vty
, "%-10s", "=========");
513 vty_out(vty
, " %-40s", "============");
514 vty_out(vty
, " %-40s", "===========");
515 vty_out(vty
, "%-15s\n", "======");
517 bfd_id_iterate(_display_peer_brief_iter
, &bvt
);
521 jo
= json_object_new_array();
524 bfd_id_iterate(_display_peer_json_iter
, &bvt
);
526 vty_out(vty
, "%s\n", json_object_to_json_string_ext(jo
, 0));
527 json_object_free(jo
);
530 static struct bfd_session
*
531 _find_peer_or_error(struct vty
*vty
, int argc
, struct cmd_token
**argv
,
532 const char *label
, const char *peer_str
,
533 const char *local_str
, const char *ifname
,
538 struct bfd_session
*bs
= NULL
;
539 struct peer_label
*pl
;
540 struct bfd_peer_cfg bpc
;
541 struct sockaddr_any psa
, lsa
, *lsap
;
544 /* Look up the BFD peer. */
550 strtosa(peer_str
, &psa
);
552 strtosa(local_str
, &lsa
);
558 mhop
= argv_find(argv
, argc
, "multihop", &idx
);
560 if (bfd_configure_peer(&bpc
, mhop
, &psa
, lsap
, ifname
, vrfname
,
561 errormsg
, sizeof(errormsg
))
563 vty_out(vty
, "%% Invalid peer configuration: %s\n",
568 bs
= bs_peer_find(&bpc
);
571 /* Find peer data. */
573 vty_out(vty
, "%% Unable to find 'peer %s",
574 label
? label
: peer_str
);
576 vty_out(vty
, " interface %s", ifname
);
578 vty_out(vty
, " local-address %s", local_str
);
580 vty_out(vty
, " vrf %s", vrfname
);
593 DEFPY(bfd_show_peers
, bfd_show_peers_cmd
, "show bfd [vrf NAME] peers [json]",
595 "Bidirection Forwarding Detection\n"
597 "BFD peers status\n" JSON_STR
)
599 char *vrf_name
= NULL
;
602 if (argv_find(argv
, argc
, "vrf", &idx_vrf
))
603 vrf_name
= argv
[idx_vrf
+ 1]->arg
;
605 _display_all_peers(vty
, vrf_name
, use_json(argc
, argv
));
610 DEFPY(bfd_show_peer
, bfd_show_peer_cmd
,
611 "show bfd [vrf NAME$vrf_name] peer <WORD$label|<A.B.C.D|X:X::X:X>$peer [{multihop|local-address <A.B.C.D|X:X::X:X>$local|interface IFNAME$ifname}]> [json]",
613 "Bidirection Forwarding Detection\n"
616 "Peer label\n" PEER_IPV4_STR PEER_IPV6_STR MHOP_STR LOCAL_STR
617 LOCAL_IPV4_STR LOCAL_IPV6_STR INTERFACE_STR LOCAL_INTF_STR JSON_STR
)
619 struct bfd_session
*bs
;
621 /* Look up the BFD peer. */
622 bs
= _find_peer_or_error(vty
, argc
, argv
, label
, peer_str
, local_str
,
625 return CMD_WARNING_CONFIG_FAILED
;
627 if (use_json(argc
, argv
)) {
628 _display_peer_json(vty
, bs
);
630 vty_out(vty
, "BFD Peer:\n");
631 _display_peer(vty
, bs
);
637 DEFPY(bfd_show_peer_counters
, bfd_show_peer_counters_cmd
,
638 "show bfd [vrf NAME$vrf_name] peer <WORD$label|<A.B.C.D|X:X::X:X>$peer [{multihop|local-address <A.B.C.D|X:X::X:X>$local|interface IFNAME$ifname}]> counters [json]",
640 "Bidirection Forwarding Detection\n"
652 "Show BFD peer counters information\n"
655 struct bfd_session
*bs
;
657 /* Look up the BFD peer. */
658 bs
= _find_peer_or_error(vty
, argc
, argv
, label
, peer_str
, local_str
,
661 return CMD_WARNING_CONFIG_FAILED
;
663 if (use_json(argc
, argv
))
664 _display_peer_counters_json(vty
, bs
);
666 _display_peer_counter(vty
, bs
);
671 DEFPY(bfd_show_peers_counters
, bfd_show_peers_counters_cmd
,
672 "show bfd [vrf NAME] peers counters [json]",
674 "Bidirection Forwarding Detection\n"
677 "Show BFD peer counters information\n"
680 char *vrf_name
= NULL
;
683 if (argv_find(argv
, argc
, "vrf", &idx_vrf
))
684 vrf_name
= argv
[idx_vrf
+ 1]->arg
;
686 _display_peers_counter(vty
, vrf_name
, use_json(argc
, argv
));
691 DEFPY(bfd_clear_peer_counters
, bfd_clear_peer_counters_cmd
,
692 "clear bfd [vrf <NAME$vrfname>] peer <WORD$label|<A.B.C.D|X:X::X:X>$peer [{multihop|local-address <A.B.C.D|X:X::X:X>$local|interface IFNAME$ifname}]> counters",
694 "Bidirection Forwarding Detection\n"
706 "clear BFD peer counters information\n")
708 struct bfd_session
*bs
;
710 /* Look up the BFD peer. */
711 bs
= _find_peer_or_error(vty
, argc
, argv
, label
, peer_str
, local_str
,
714 return CMD_WARNING_CONFIG_FAILED
;
716 _clear_peer_counter(bs
);
721 DEFPY(bfd_show_peers_brief
, bfd_show_peers_brief_cmd
,
722 "show bfd [vrf <NAME$vrfname>] peers brief [json]",
724 "Bidirection Forwarding Detection\n"
727 "Show BFD peer information in tabular form\n"
730 char *vrf_name
= NULL
;
733 if (argv_find(argv
, argc
, "vrf", &idx_vrf
))
734 vrf_name
= argv
[idx_vrf
+ 1]->arg
;
736 _display_peers_brief(vty
, vrf_name
, use_json(argc
, argv
));
742 bfd_debug_peer
, bfd_debug_peer_cmd
,
743 "[no] debug bfd peer",
746 "Bidirection Forwarding Detection\n"
747 "Peer events debugging\n")
749 bglobal
.debug_peer_event
= !no
;
754 bfd_debug_zebra
, bfd_debug_zebra_cmd
,
755 "[no] debug bfd zebra",
758 "Bidirection Forwarding Detection\n"
759 "Zebra events debugging\n")
761 bglobal
.debug_zebra
= !no
;
766 bfd_debug_network
, bfd_debug_network_cmd
,
767 "[no] debug bfd network",
770 "Bidirection Forwarding Detection\n"
771 "Network layer debugging\n")
773 bglobal
.debug_network
= !no
;
778 * Function definitions.
782 * Configuration rules:
785 * peer + (interface name)
788 * peer + local + (optional vrf)
790 * Anything else is misconfiguration.
792 static int bfd_configure_peer(struct bfd_peer_cfg
*bpc
, bool mhop
,
793 const struct sockaddr_any
*peer
,
794 const struct sockaddr_any
*local
,
795 const char *ifname
, const char *vrfname
,
796 char *ebuf
, size_t ebuflen
)
798 memset(bpc
, 0, sizeof(*bpc
));
801 bpc
->bpc_shutdown
= true;
802 bpc
->bpc_detectmultiplier
= BPC_DEF_DETECTMULTIPLIER
;
803 bpc
->bpc_recvinterval
= BPC_DEF_RECEIVEINTERVAL
;
804 bpc
->bpc_txinterval
= BPC_DEF_TRANSMITINTERVAL
;
805 bpc
->bpc_echointerval
= BPC_DEF_ECHOINTERVAL
;
806 bpc
->bpc_lastevent
= monotime(NULL
);
808 /* Safety check: when no error buf is provided len must be zero. */
812 /* Peer is always mandatory. */
814 snprintf(ebuf
, ebuflen
, "peer must not be empty");
818 /* Validate address families. */
819 if (peer
->sa_sin
.sin_family
== AF_INET
) {
820 if (local
&& local
->sa_sin
.sin_family
!= AF_INET
) {
821 snprintf(ebuf
, ebuflen
,
822 "local is IPv6, but peer is IPv4");
826 bpc
->bpc_ipv4
= true;
827 } else if (peer
->sa_sin
.sin_family
== AF_INET6
) {
828 if (local
&& local
->sa_sin
.sin_family
!= AF_INET6
) {
829 snprintf(ebuf
, ebuflen
,
830 "local is IPv4, but peer is IPv6");
834 bpc
->bpc_ipv4
= false;
836 snprintf(ebuf
, ebuflen
, "invalid peer address family");
840 /* Copy local and/or peer addresses. */
842 bpc
->bpc_local
= *local
;
844 bpc
->bpc_peer
= *peer
;
845 bpc
->bpc_mhop
= mhop
;
847 /* Handle interface specification configuration. */
849 bpc
->bpc_has_localif
= true;
850 if (strlcpy(bpc
->bpc_localif
, ifname
, sizeof(bpc
->bpc_localif
))
851 > sizeof(bpc
->bpc_localif
)) {
852 snprintf(ebuf
, ebuflen
, "interface name too long");
857 /* Handle VRF configuration. */
859 bpc
->bpc_has_vrfname
= true;
860 if (strlcpy(bpc
->bpc_vrfname
, vrfname
, sizeof(bpc
->bpc_vrfname
))
861 > sizeof(bpc
->bpc_vrfname
)) {
862 snprintf(ebuf
, ebuflen
, "vrf name too long");
866 bpc
->bpc_has_vrfname
= true;
867 strlcpy(bpc
->bpc_vrfname
, VRF_DEFAULT_NAME
, sizeof(bpc
->bpc_vrfname
));
873 DEFUN_NOSH(show_debugging_bfd
,
874 show_debugging_bfd_cmd
,
875 "show debugging [bfd]",
880 vty_out(vty
, "BFD debugging status:\n");
881 if (bglobal
.debug_peer_event
)
882 vty_out(vty
, " Peer events debugging is on.\n");
883 if (bglobal
.debug_zebra
)
884 vty_out(vty
, " Zebra events debugging is on.\n");
885 if (bglobal
.debug_network
)
886 vty_out(vty
, " Network layer debugging is on.\n");
891 static int bfdd_write_config(struct vty
*vty
);
892 struct cmd_node bfd_node
= {
895 .parent_node
= CONFIG_NODE
,
896 .prompt
= "%s(config-bfd)# ",
897 .config_write
= bfdd_write_config
,
900 struct cmd_node bfd_peer_node
= {
902 .node
= BFD_PEER_NODE
,
903 .parent_node
= BFD_NODE
,
904 .prompt
= "%s(config-bfd-peer)# ",
907 static int bfdd_write_config(struct vty
*vty
)
909 struct lyd_node
*dnode
;
912 if (bglobal
.debug_peer_event
) {
913 vty_out(vty
, "debug bfd peer\n");
917 if (bglobal
.debug_zebra
) {
918 vty_out(vty
, "debug bfd zebra\n");
922 if (bglobal
.debug_network
) {
923 vty_out(vty
, "debug bfd network\n");
927 dnode
= yang_dnode_get(running_config
->dnode
, "/frr-bfdd:bfdd");
929 nb_cli_show_dnode_cmds(vty
, dnode
, false);
936 void bfdd_vty_init(void)
938 install_element(ENABLE_NODE
, &bfd_show_peers_counters_cmd
);
939 install_element(ENABLE_NODE
, &bfd_show_peer_counters_cmd
);
940 install_element(ENABLE_NODE
, &bfd_clear_peer_counters_cmd
);
941 install_element(ENABLE_NODE
, &bfd_show_peers_cmd
);
942 install_element(ENABLE_NODE
, &bfd_show_peer_cmd
);
943 install_element(ENABLE_NODE
, &bfd_show_peers_brief_cmd
);
944 install_element(ENABLE_NODE
, &show_debugging_bfd_cmd
);
946 install_element(ENABLE_NODE
, &bfd_debug_peer_cmd
);
947 install_element(ENABLE_NODE
, &bfd_debug_zebra_cmd
);
948 install_element(ENABLE_NODE
, &bfd_debug_network_cmd
);
950 install_element(CONFIG_NODE
, &bfd_debug_peer_cmd
);
951 install_element(CONFIG_NODE
, &bfd_debug_zebra_cmd
);
952 install_element(CONFIG_NODE
, &bfd_debug_network_cmd
);
954 /* Install BFD node and commands. */
955 install_node(&bfd_node
);
956 install_default(BFD_NODE
);
958 /* Install BFD peer node. */
959 install_node(&bfd_peer_node
);
960 install_default(BFD_PEER_NODE
);