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
);
114 if (CHECK_FLAG(bs
->flags
, BFD_SESS_FLAG_PASSIVE
))
115 vty_out(vty
, "\t\tPassive mode\n");
117 vty_out(vty
, "\t\tActive mode\n");
118 if (CHECK_FLAG(bs
->flags
, BFD_SESS_FLAG_MH
))
119 vty_out(vty
, "\t\tMinimum TTL: %d\n", bs
->mh_ttl
);
121 vty_out(vty
, "\t\tStatus: ");
122 switch (bs
->ses_state
) {
123 case PTM_BFD_ADM_DOWN
:
124 vty_out(vty
, "shutdown\n");
127 vty_out(vty
, "down\n");
129 now
= monotime(NULL
);
130 integer2timestr(now
- bs
->downtime
.tv_sec
, buf
, sizeof(buf
));
131 vty_out(vty
, "\t\tDowntime: %s\n", buf
);
134 vty_out(vty
, "init\n");
137 vty_out(vty
, "up\n");
139 now
= monotime(NULL
);
140 integer2timestr(now
- bs
->uptime
.tv_sec
, buf
, sizeof(buf
));
141 vty_out(vty
, "\t\tUptime: %s\n", buf
);
145 vty_out(vty
, "unknown\n");
149 vty_out(vty
, "\t\tDiagnostics: %s\n", diag2str(bs
->local_diag
));
150 vty_out(vty
, "\t\tRemote diagnostics: %s\n", diag2str(bs
->remote_diag
));
151 vty_out(vty
, "\t\tPeer Type: %s\n",
152 CHECK_FLAG(bs
->flags
, BFD_SESS_FLAG_CONFIG
) ? "configured" : "dynamic");
154 vty_out(vty
, "\t\tLocal timers:\n");
155 vty_out(vty
, "\t\t\tDetect-multiplier: %u\n",
157 vty_out(vty
, "\t\t\tReceive interval: %ums\n",
158 bs
->timers
.required_min_rx
/ 1000);
159 vty_out(vty
, "\t\t\tTransmission interval: %ums\n",
160 bs
->timers
.desired_min_tx
/ 1000);
161 if (bs
->timers
.required_min_echo_rx
!= 0)
162 vty_out(vty
, "\t\t\tEcho receive interval: %ums\n",
163 bs
->timers
.required_min_echo_rx
/ 1000);
165 vty_out(vty
, "\t\t\tEcho receive interval: disabled\n");
166 if (CHECK_FLAG(bs
->flags
, BFD_SESS_FLAG_ECHO
))
167 vty_out(vty
, "\t\t\tEcho transmission interval: %ums\n",
168 bs
->timers
.desired_min_echo_tx
/ 1000);
170 vty_out(vty
, "\t\t\tEcho transmission interval: disabled\n");
172 vty_out(vty
, "\t\tRemote timers:\n");
173 vty_out(vty
, "\t\t\tDetect-multiplier: %u\n",
174 bs
->remote_detect_mult
);
175 vty_out(vty
, "\t\t\tReceive interval: %ums\n",
176 bs
->remote_timers
.required_min_rx
/ 1000);
177 vty_out(vty
, "\t\t\tTransmission interval: %ums\n",
178 bs
->remote_timers
.desired_min_tx
/ 1000);
179 if (bs
->remote_timers
.required_min_echo
!= 0)
180 vty_out(vty
, "\t\t\tEcho receive interval: %ums\n",
181 bs
->remote_timers
.required_min_echo
/ 1000);
183 vty_out(vty
, "\t\t\tEcho receive interval: disabled\n");
188 static struct json_object
*_peer_json_header(struct bfd_session
*bs
)
190 struct json_object
*jo
= json_object_new_object();
191 char addr_buf
[INET6_ADDRSTRLEN
];
194 json_object_boolean_true_add(jo
, "multihop");
196 json_object_boolean_false_add(jo
, "multihop");
198 json_object_string_add(jo
, "peer",
199 inet_ntop(bs
->key
.family
, &bs
->key
.peer
,
200 addr_buf
, sizeof(addr_buf
)));
201 if (memcmp(&bs
->key
.local
, &zero_addr
, sizeof(bs
->key
.local
)))
202 json_object_string_add(jo
, "local",
203 inet_ntop(bs
->key
.family
, &bs
->key
.local
,
204 addr_buf
, sizeof(addr_buf
)));
206 if (bs
->key
.vrfname
[0])
207 json_object_string_add(jo
, "vrf", bs
->key
.vrfname
);
208 if (bs
->key
.ifname
[0])
209 json_object_string_add(jo
, "interface", bs
->key
.ifname
);
212 json_object_string_add(jo
, "label", bs
->pl
->pl_label
);
217 static struct json_object
*__display_peer_json(struct bfd_session
*bs
)
219 struct json_object
*jo
= _peer_json_header(bs
);
221 json_object_int_add(jo
, "id", bs
->discrs
.my_discr
);
222 json_object_int_add(jo
, "remote-id", bs
->discrs
.remote_discr
);
223 json_object_boolean_add(jo
, "passive-mode",
224 CHECK_FLAG(bs
->flags
, BFD_SESS_FLAG_PASSIVE
));
225 if (CHECK_FLAG(bs
->flags
, BFD_SESS_FLAG_MH
))
226 json_object_int_add(jo
, "minimum-ttl", bs
->mh_ttl
);
228 switch (bs
->ses_state
) {
229 case PTM_BFD_ADM_DOWN
:
230 json_object_string_add(jo
, "status", "shutdown");
233 json_object_string_add(jo
, "status", "down");
234 json_object_int_add(jo
, "downtime",
235 monotime(NULL
) - bs
->downtime
.tv_sec
);
238 json_object_string_add(jo
, "status", "init");
241 json_object_string_add(jo
, "status", "up");
242 json_object_int_add(jo
, "uptime",
243 monotime(NULL
) - bs
->uptime
.tv_sec
);
247 json_object_string_add(jo
, "status", "unknown");
251 json_object_string_add(jo
, "diagnostic", diag2str(bs
->local_diag
));
252 json_object_string_add(jo
, "remote-diagnostic",
253 diag2str(bs
->remote_diag
));
255 json_object_int_add(jo
, "receive-interval",
256 bs
->timers
.required_min_rx
/ 1000);
257 json_object_int_add(jo
, "transmit-interval",
258 bs
->timers
.desired_min_tx
/ 1000);
259 json_object_int_add(jo
, "echo-receive-interval",
260 bs
->timers
.required_min_echo_rx
/ 1000);
261 if (CHECK_FLAG(bs
->flags
, BFD_SESS_FLAG_ECHO
))
262 json_object_int_add(jo
, "echo-transmit-interval",
263 bs
->timers
.desired_min_echo_tx
/ 1000);
265 json_object_int_add(jo
, "echo-transmit-interval", 0);
267 json_object_int_add(jo
, "detect-multiplier", bs
->detect_mult
);
269 json_object_int_add(jo
, "remote-receive-interval",
270 bs
->remote_timers
.required_min_rx
/ 1000);
271 json_object_int_add(jo
, "remote-transmit-interval",
272 bs
->remote_timers
.desired_min_tx
/ 1000);
273 json_object_int_add(jo
, "remote-echo-receive-interval",
274 bs
->remote_timers
.required_min_echo
/ 1000);
275 json_object_int_add(jo
, "remote-detect-multiplier",
276 bs
->remote_detect_mult
);
281 static void _display_peer_json(struct vty
*vty
, struct bfd_session
*bs
)
283 struct json_object
*jo
= __display_peer_json(bs
);
288 struct bfd_vrf_tuple
{
291 struct json_object
*jo
;
294 static void _display_peer_iter(struct hash_bucket
*hb
, void *arg
)
296 struct bfd_vrf_tuple
*bvt
= (struct bfd_vrf_tuple
*)arg
;
298 struct bfd_session
*bs
= hb
->data
;
305 if (!bs
->key
.vrfname
[0] ||
306 !strmatch(bs
->key
.vrfname
, bvt
->vrfname
))
309 _display_peer(vty
, bs
);
312 static void _display_peer_json_iter(struct hash_bucket
*hb
, void *arg
)
314 struct bfd_vrf_tuple
*bvt
= (struct bfd_vrf_tuple
*)arg
;
315 struct json_object
*jo
, *jon
= NULL
;
316 struct bfd_session
*bs
= hb
->data
;
323 if (!bs
->key
.vrfname
[0] ||
324 !strmatch(bs
->key
.vrfname
, bvt
->vrfname
))
328 jon
= __display_peer_json(bs
);
330 zlog_warn("%s: not enough memory", __func__
);
334 json_object_array_add(jo
, jon
);
337 static void _display_all_peers(struct vty
*vty
, char *vrfname
, bool use_json
)
339 struct json_object
*jo
;
340 struct bfd_vrf_tuple bvt
= {0};
342 bvt
.vrfname
= vrfname
;
346 vty_out(vty
, "BFD Peers:\n");
347 bfd_id_iterate(_display_peer_iter
, &bvt
);
351 jo
= json_object_new_array();
353 bfd_id_iterate(_display_peer_json_iter
, &bvt
);
358 static void _display_peer_counter(struct vty
*vty
, struct bfd_session
*bs
)
360 _display_peer_header(vty
, bs
);
362 /* Ask data plane for updated counters. */
363 if (bfd_dplane_update_session_counters(bs
) == -1)
364 zlog_debug("%s: failed to update BFD session counters (%s)",
365 __func__
, bs_to_string(bs
));
367 vty_out(vty
, "\t\tControl packet input: %" PRIu64
" packets\n",
368 bs
->stats
.rx_ctrl_pkt
);
369 vty_out(vty
, "\t\tControl packet output: %" PRIu64
" packets\n",
370 bs
->stats
.tx_ctrl_pkt
);
371 vty_out(vty
, "\t\tEcho packet input: %" PRIu64
" packets\n",
372 bs
->stats
.rx_echo_pkt
);
373 vty_out(vty
, "\t\tEcho packet output: %" PRIu64
" packets\n",
374 bs
->stats
.tx_echo_pkt
);
375 vty_out(vty
, "\t\tSession up events: %" PRIu64
"\n",
376 bs
->stats
.session_up
);
377 vty_out(vty
, "\t\tSession down events: %" PRIu64
"\n",
378 bs
->stats
.session_down
);
379 vty_out(vty
, "\t\tZebra notifications: %" PRIu64
"\n",
380 bs
->stats
.znotification
);
384 static struct json_object
*__display_peer_counters_json(struct bfd_session
*bs
)
386 struct json_object
*jo
= _peer_json_header(bs
);
388 /* Ask data plane for updated counters. */
389 if (bfd_dplane_update_session_counters(bs
) == -1)
390 zlog_debug("%s: failed to update BFD session counters (%s)",
391 __func__
, bs_to_string(bs
));
393 json_object_int_add(jo
, "control-packet-input", bs
->stats
.rx_ctrl_pkt
);
394 json_object_int_add(jo
, "control-packet-output", bs
->stats
.tx_ctrl_pkt
);
395 json_object_int_add(jo
, "echo-packet-input", bs
->stats
.rx_echo_pkt
);
396 json_object_int_add(jo
, "echo-packet-output", bs
->stats
.tx_echo_pkt
);
397 json_object_int_add(jo
, "session-up", bs
->stats
.session_up
);
398 json_object_int_add(jo
, "session-down", bs
->stats
.session_down
);
399 json_object_int_add(jo
, "zebra-notifications", bs
->stats
.znotification
);
404 static void _display_peer_counters_json(struct vty
*vty
, struct bfd_session
*bs
)
406 struct json_object
*jo
= __display_peer_counters_json(bs
);
411 static void _display_peer_counter_iter(struct hash_bucket
*hb
, void *arg
)
413 struct bfd_vrf_tuple
*bvt
= arg
;
415 struct bfd_session
*bs
= hb
->data
;
422 if (!bs
->key
.vrfname
[0] ||
423 !strmatch(bs
->key
.vrfname
, bvt
->vrfname
))
427 _display_peer_counter(vty
, bs
);
430 static void _display_peer_counter_json_iter(struct hash_bucket
*hb
, void *arg
)
432 struct json_object
*jo
, *jon
= NULL
;
433 struct bfd_session
*bs
= hb
->data
;
434 struct bfd_vrf_tuple
*bvt
= arg
;
441 if (!bs
->key
.vrfname
[0] ||
442 !strmatch(bs
->key
.vrfname
, bvt
->vrfname
))
446 jon
= __display_peer_counters_json(bs
);
448 zlog_warn("%s: not enough memory", __func__
);
452 json_object_array_add(jo
, jon
);
455 static void _display_peers_counter(struct vty
*vty
, char *vrfname
, bool use_json
)
457 struct json_object
*jo
;
458 struct bfd_vrf_tuple bvt
= {0};
460 bvt
.vrfname
= vrfname
;
463 vty_out(vty
, "BFD Peers:\n");
464 bfd_id_iterate(_display_peer_counter_iter
, &bvt
);
468 jo
= json_object_new_array();
470 bfd_id_iterate(_display_peer_counter_json_iter
, &bvt
);
475 static void _clear_peer_counter(struct bfd_session
*bs
)
477 /* Clear only pkt stats, intention is not to loose system
479 bs
->stats
.rx_ctrl_pkt
= 0;
480 bs
->stats
.tx_ctrl_pkt
= 0;
481 bs
->stats
.rx_echo_pkt
= 0;
482 bs
->stats
.tx_echo_pkt
= 0;
485 static void _display_peer_brief(struct vty
*vty
, struct bfd_session
*bs
)
487 char addr_buf
[INET6_ADDRSTRLEN
];
489 if (CHECK_FLAG(bs
->flags
, BFD_SESS_FLAG_MH
)) {
490 vty_out(vty
, "%-10u", bs
->discrs
.my_discr
);
491 inet_ntop(bs
->key
.family
, &bs
->key
.local
, addr_buf
, sizeof(addr_buf
));
492 vty_out(vty
, " %-40s", addr_buf
);
493 inet_ntop(bs
->key
.family
, &bs
->key
.peer
, addr_buf
, sizeof(addr_buf
));
494 vty_out(vty
, " %-40s", addr_buf
);
495 vty_out(vty
, "%-15s\n", state_list
[bs
->ses_state
].str
);
497 vty_out(vty
, "%-10u", bs
->discrs
.my_discr
);
498 vty_out(vty
, " %-40s", satostr(&bs
->local_address
));
499 inet_ntop(bs
->key
.family
, &bs
->key
.peer
, addr_buf
, sizeof(addr_buf
));
500 vty_out(vty
, " %-40s", addr_buf
);
502 vty_out(vty
, "%-15s\n", state_list
[bs
->ses_state
].str
);
506 static void _display_peer_brief_iter(struct hash_bucket
*hb
, void *arg
)
508 struct bfd_vrf_tuple
*bvt
= arg
;
510 struct bfd_session
*bs
= hb
->data
;
517 if (!bs
->key
.vrfname
[0] ||
518 !strmatch(bs
->key
.vrfname
, bvt
->vrfname
))
522 _display_peer_brief(vty
, bs
);
525 static void _display_peers_brief(struct vty
*vty
, const char *vrfname
, bool use_json
)
527 struct json_object
*jo
;
528 struct bfd_vrf_tuple bvt
= {0};
530 bvt
.vrfname
= vrfname
;
535 vty_out(vty
, "Session count: %lu\n", bfd_get_session_count());
536 vty_out(vty
, "%-10s", "SessionId");
537 vty_out(vty
, " %-40s", "LocalAddress");
538 vty_out(vty
, " %-40s", "PeerAddress");
539 vty_out(vty
, "%-15s\n", "Status");
541 vty_out(vty
, "%-10s", "=========");
542 vty_out(vty
, " %-40s", "============");
543 vty_out(vty
, " %-40s", "===========");
544 vty_out(vty
, "%-15s\n", "======");
546 bfd_id_iterate(_display_peer_brief_iter
, &bvt
);
550 jo
= json_object_new_array();
553 bfd_id_iterate(_display_peer_json_iter
, &bvt
);
558 static struct bfd_session
*
559 _find_peer_or_error(struct vty
*vty
, int argc
, struct cmd_token
**argv
,
560 const char *label
, const char *peer_str
,
561 const char *local_str
, const char *ifname
,
566 struct bfd_session
*bs
= NULL
;
567 struct peer_label
*pl
;
568 struct bfd_peer_cfg bpc
;
569 struct sockaddr_any psa
, lsa
, *lsap
;
572 /* Look up the BFD peer. */
577 } else if (peer_str
) {
578 strtosa(peer_str
, &psa
);
580 strtosa(local_str
, &lsa
);
586 mhop
= argv_find(argv
, argc
, "multihop", &idx
);
588 if (bfd_configure_peer(&bpc
, mhop
, &psa
, lsap
, ifname
, vrfname
,
589 errormsg
, sizeof(errormsg
))
591 vty_out(vty
, "%% Invalid peer configuration: %s\n",
596 bs
= bs_peer_find(&bpc
);
598 vty_out(vty
, "%% Invalid arguments\n");
602 /* Find peer data. */
604 vty_out(vty
, "%% Unable to find 'peer %s",
605 label
? label
: peer_str
);
607 vty_out(vty
, " interface %s", ifname
);
609 vty_out(vty
, " local-address %s", local_str
);
611 vty_out(vty
, " vrf %s", vrfname
);
624 DEFPY(bfd_show_peers
, bfd_show_peers_cmd
, "show bfd [vrf NAME] peers [json]",
626 "Bidirection Forwarding Detection\n"
628 "BFD peers status\n" JSON_STR
)
630 char *vrf_name
= NULL
;
633 if (argv_find(argv
, argc
, "vrf", &idx_vrf
))
634 vrf_name
= argv
[idx_vrf
+ 1]->arg
;
636 _display_all_peers(vty
, vrf_name
, use_json(argc
, argv
));
641 DEFPY(bfd_show_peer
, bfd_show_peer_cmd
,
642 "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]",
644 "Bidirection Forwarding Detection\n"
647 "Peer label\n" PEER_IPV4_STR PEER_IPV6_STR MHOP_STR LOCAL_STR
648 LOCAL_IPV4_STR LOCAL_IPV6_STR INTERFACE_STR LOCAL_INTF_STR JSON_STR
)
650 struct bfd_session
*bs
;
652 /* Look up the BFD peer. */
653 bs
= _find_peer_or_error(vty
, argc
, argv
, label
, peer_str
, local_str
,
656 return CMD_WARNING_CONFIG_FAILED
;
658 if (use_json(argc
, argv
)) {
659 _display_peer_json(vty
, bs
);
661 vty_out(vty
, "BFD Peer:\n");
662 _display_peer(vty
, bs
);
668 DEFPY(bfd_show_peer_counters
, bfd_show_peer_counters_cmd
,
669 "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]",
671 "Bidirection Forwarding Detection\n"
683 "Show BFD peer counters information\n"
686 struct bfd_session
*bs
;
688 /* Look up the BFD peer. */
689 bs
= _find_peer_or_error(vty
, argc
, argv
, label
, peer_str
, local_str
,
692 return CMD_WARNING_CONFIG_FAILED
;
694 if (use_json(argc
, argv
))
695 _display_peer_counters_json(vty
, bs
);
697 _display_peer_counter(vty
, bs
);
702 DEFPY(bfd_show_peers_counters
, bfd_show_peers_counters_cmd
,
703 "show bfd [vrf NAME] peers counters [json]",
705 "Bidirection Forwarding Detection\n"
708 "Show BFD peer counters information\n"
711 char *vrf_name
= NULL
;
714 if (argv_find(argv
, argc
, "vrf", &idx_vrf
))
715 vrf_name
= argv
[idx_vrf
+ 1]->arg
;
717 _display_peers_counter(vty
, vrf_name
, use_json(argc
, argv
));
722 DEFPY(bfd_clear_peer_counters
, bfd_clear_peer_counters_cmd
,
723 "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",
725 "Bidirection Forwarding Detection\n"
737 "clear BFD peer counters information\n")
739 struct bfd_session
*bs
;
741 /* Look up the BFD peer. */
742 bs
= _find_peer_or_error(vty
, argc
, argv
, label
, peer_str
, local_str
,
745 return CMD_WARNING_CONFIG_FAILED
;
747 _clear_peer_counter(bs
);
752 DEFPY(bfd_show_peers_brief
, bfd_show_peers_brief_cmd
,
753 "show bfd [vrf <NAME$vrfname>] peers brief [json]",
755 "Bidirection Forwarding Detection\n"
758 "Show BFD peer information in tabular form\n"
761 char *vrf_name
= NULL
;
764 if (argv_find(argv
, argc
, "vrf", &idx_vrf
))
765 vrf_name
= argv
[idx_vrf
+ 1]->arg
;
767 _display_peers_brief(vty
, vrf_name
, use_json(argc
, argv
));
772 DEFPY(show_bfd_distributed
, show_bfd_distributed_cmd
,
773 "show bfd distributed",
775 "Bidirection Forwarding Detection\n"
776 "Show BFD data plane (distributed BFD) statistics\n")
778 bfd_dplane_show_counters(vty
);
783 bfd_debug_distributed
, bfd_debug_distributed_cmd
,
784 "[no] debug bfd distributed",
787 "Bidirection Forwarding Detection\n"
788 "BFD data plane (distributed BFD) debugging\n")
790 bglobal
.debug_dplane
= !no
;
795 bfd_debug_peer
, bfd_debug_peer_cmd
,
796 "[no] debug bfd peer",
799 "Bidirection Forwarding Detection\n"
800 "Peer events debugging\n")
802 bglobal
.debug_peer_event
= !no
;
807 bfd_debug_zebra
, bfd_debug_zebra_cmd
,
808 "[no] debug bfd zebra",
811 "Bidirection Forwarding Detection\n"
812 "Zebra events debugging\n")
814 bglobal
.debug_zebra
= !no
;
819 bfd_debug_network
, bfd_debug_network_cmd
,
820 "[no] debug bfd network",
823 "Bidirection Forwarding Detection\n"
824 "Network layer debugging\n")
826 bglobal
.debug_network
= !no
;
831 * Function definitions.
835 * Configuration rules:
838 * peer + (interface name)
841 * peer + local + (optional vrf)
843 * Anything else is misconfiguration.
845 static int bfd_configure_peer(struct bfd_peer_cfg
*bpc
, bool mhop
,
846 const struct sockaddr_any
*peer
,
847 const struct sockaddr_any
*local
,
848 const char *ifname
, const char *vrfname
,
849 char *ebuf
, size_t ebuflen
)
851 memset(bpc
, 0, sizeof(*bpc
));
854 bpc
->bpc_shutdown
= false;
855 bpc
->bpc_detectmultiplier
= BPC_DEF_DETECTMULTIPLIER
;
856 bpc
->bpc_recvinterval
= BPC_DEF_RECEIVEINTERVAL
;
857 bpc
->bpc_txinterval
= BPC_DEF_TRANSMITINTERVAL
;
858 bpc
->bpc_echorecvinterval
= BPC_DEF_ECHORECEIVEINTERVAL
;
859 bpc
->bpc_echotxinterval
= BPC_DEF_ECHOTRANSMITINTERVAL
;
860 bpc
->bpc_lastevent
= monotime(NULL
);
862 /* Safety check: when no error buf is provided len must be zero. */
866 /* Peer is always mandatory. */
868 snprintf(ebuf
, ebuflen
, "peer must not be empty");
872 /* Validate address families. */
873 if (peer
->sa_sin
.sin_family
== AF_INET
) {
874 if (local
&& local
->sa_sin
.sin_family
!= AF_INET
) {
875 snprintf(ebuf
, ebuflen
,
876 "local is IPv6, but peer is IPv4");
880 bpc
->bpc_ipv4
= true;
881 } else if (peer
->sa_sin
.sin_family
== AF_INET6
) {
882 if (local
&& local
->sa_sin
.sin_family
!= AF_INET6
) {
883 snprintf(ebuf
, ebuflen
,
884 "local is IPv4, but peer is IPv6");
888 bpc
->bpc_ipv4
= false;
890 snprintf(ebuf
, ebuflen
, "invalid peer address family");
894 /* Copy local and/or peer addresses. */
896 bpc
->bpc_local
= *local
;
898 bpc
->bpc_peer
= *peer
;
899 bpc
->bpc_mhop
= mhop
;
901 /* Handle interface specification configuration. */
903 bpc
->bpc_has_localif
= true;
904 if (strlcpy(bpc
->bpc_localif
, ifname
, sizeof(bpc
->bpc_localif
))
905 > sizeof(bpc
->bpc_localif
)) {
906 snprintf(ebuf
, ebuflen
, "interface name too long");
911 /* Handle VRF configuration. */
913 bpc
->bpc_has_vrfname
= true;
914 if (strlcpy(bpc
->bpc_vrfname
, vrfname
, sizeof(bpc
->bpc_vrfname
))
915 > sizeof(bpc
->bpc_vrfname
)) {
916 snprintf(ebuf
, ebuflen
, "vrf name too long");
920 bpc
->bpc_has_vrfname
= true;
921 strlcpy(bpc
->bpc_vrfname
, VRF_DEFAULT_NAME
, sizeof(bpc
->bpc_vrfname
));
927 DEFUN_NOSH(show_debugging_bfd
,
928 show_debugging_bfd_cmd
,
929 "show debugging [bfd]",
934 vty_out(vty
, "BFD debugging status:\n");
935 if (bglobal
.debug_dplane
)
936 vty_out(vty
, " Distributed BFD debugging is on.\n");
937 if (bglobal
.debug_peer_event
)
938 vty_out(vty
, " Peer events debugging is on.\n");
939 if (bglobal
.debug_zebra
)
940 vty_out(vty
, " Zebra events debugging is on.\n");
941 if (bglobal
.debug_network
)
942 vty_out(vty
, " Network layer debugging is on.\n");
947 static int bfdd_write_config(struct vty
*vty
);
948 struct cmd_node bfd_node
= {
951 .parent_node
= CONFIG_NODE
,
952 .prompt
= "%s(config-bfd)# ",
953 .config_write
= bfdd_write_config
,
956 struct cmd_node bfd_peer_node
= {
958 .node
= BFD_PEER_NODE
,
959 .parent_node
= BFD_NODE
,
960 .prompt
= "%s(config-bfd-peer)# ",
963 static int bfdd_write_config(struct vty
*vty
)
965 struct lyd_node
*dnode
;
968 if (bglobal
.debug_dplane
) {
969 vty_out(vty
, "debug bfd distributed\n");
973 if (bglobal
.debug_peer_event
) {
974 vty_out(vty
, "debug bfd peer\n");
978 if (bglobal
.debug_zebra
) {
979 vty_out(vty
, "debug bfd zebra\n");
983 if (bglobal
.debug_network
) {
984 vty_out(vty
, "debug bfd network\n");
988 dnode
= yang_dnode_get(running_config
->dnode
, "/frr-bfdd:bfdd");
990 nb_cli_show_dnode_cmds(vty
, dnode
, false);
997 void bfdd_vty_init(void)
999 install_element(ENABLE_NODE
, &bfd_show_peers_counters_cmd
);
1000 install_element(ENABLE_NODE
, &bfd_show_peer_counters_cmd
);
1001 install_element(ENABLE_NODE
, &bfd_clear_peer_counters_cmd
);
1002 install_element(ENABLE_NODE
, &bfd_show_peers_cmd
);
1003 install_element(ENABLE_NODE
, &bfd_show_peer_cmd
);
1004 install_element(ENABLE_NODE
, &bfd_show_peers_brief_cmd
);
1005 install_element(ENABLE_NODE
, &show_bfd_distributed_cmd
);
1006 install_element(ENABLE_NODE
, &show_debugging_bfd_cmd
);
1008 install_element(ENABLE_NODE
, &bfd_debug_distributed_cmd
);
1009 install_element(ENABLE_NODE
, &bfd_debug_peer_cmd
);
1010 install_element(ENABLE_NODE
, &bfd_debug_zebra_cmd
);
1011 install_element(ENABLE_NODE
, &bfd_debug_network_cmd
);
1013 install_element(CONFIG_NODE
, &bfd_debug_distributed_cmd
);
1014 install_element(CONFIG_NODE
, &bfd_debug_peer_cmd
);
1015 install_element(CONFIG_NODE
, &bfd_debug_zebra_cmd
);
1016 install_element(CONFIG_NODE
, &bfd_debug_network_cmd
);
1018 /* Install BFD node and commands. */
1019 install_node(&bfd_node
);
1020 install_default(BFD_NODE
);
1022 /* Install BFD peer node. */
1023 install_node(&bfd_peer_node
);
1024 install_default(BFD_PEER_NODE
);