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 vty_out(vty
, "\t\t\tEcho transmission interval: %ums\n",
162 bs
->timers
.required_min_echo
/ 1000);
164 vty_out(vty
, "\t\tRemote timers:\n");
165 vty_out(vty
, "\t\t\tDetect-multiplier: %u\n",
166 bs
->remote_detect_mult
);
167 vty_out(vty
, "\t\t\tReceive interval: %ums\n",
168 bs
->remote_timers
.required_min_rx
/ 1000);
169 vty_out(vty
, "\t\t\tTransmission interval: %ums\n",
170 bs
->remote_timers
.desired_min_tx
/ 1000);
171 vty_out(vty
, "\t\t\tEcho transmission interval: %ums\n",
172 bs
->remote_timers
.required_min_echo
/ 1000);
177 static struct json_object
*_peer_json_header(struct bfd_session
*bs
)
179 struct json_object
*jo
= json_object_new_object();
180 char addr_buf
[INET6_ADDRSTRLEN
];
183 json_object_boolean_true_add(jo
, "multihop");
185 json_object_boolean_false_add(jo
, "multihop");
187 json_object_string_add(jo
, "peer",
188 inet_ntop(bs
->key
.family
, &bs
->key
.peer
,
189 addr_buf
, sizeof(addr_buf
)));
190 if (memcmp(&bs
->key
.local
, &zero_addr
, sizeof(bs
->key
.local
)))
191 json_object_string_add(jo
, "local",
192 inet_ntop(bs
->key
.family
, &bs
->key
.local
,
193 addr_buf
, sizeof(addr_buf
)));
195 if (bs
->key
.vrfname
[0])
196 json_object_string_add(jo
, "vrf", bs
->key
.vrfname
);
197 if (bs
->key
.ifname
[0])
198 json_object_string_add(jo
, "interface", bs
->key
.ifname
);
201 json_object_string_add(jo
, "label", bs
->pl
->pl_label
);
206 static struct json_object
*__display_peer_json(struct bfd_session
*bs
)
208 struct json_object
*jo
= _peer_json_header(bs
);
210 json_object_int_add(jo
, "id", bs
->discrs
.my_discr
);
211 json_object_int_add(jo
, "remote-id", bs
->discrs
.remote_discr
);
212 json_object_boolean_add(jo
, "passive-mode",
213 CHECK_FLAG(bs
->flags
, BFD_SESS_FLAG_PASSIVE
));
214 if (CHECK_FLAG(bs
->flags
, BFD_SESS_FLAG_MH
))
215 json_object_int_add(jo
, "minimum-ttl", bs
->mh_ttl
);
217 switch (bs
->ses_state
) {
218 case PTM_BFD_ADM_DOWN
:
219 json_object_string_add(jo
, "status", "shutdown");
222 json_object_string_add(jo
, "status", "down");
223 json_object_int_add(jo
, "downtime",
224 monotime(NULL
) - bs
->downtime
.tv_sec
);
227 json_object_string_add(jo
, "status", "init");
230 json_object_string_add(jo
, "status", "up");
231 json_object_int_add(jo
, "uptime",
232 monotime(NULL
) - bs
->uptime
.tv_sec
);
236 json_object_string_add(jo
, "status", "unknown");
240 json_object_string_add(jo
, "diagnostic", diag2str(bs
->local_diag
));
241 json_object_string_add(jo
, "remote-diagnostic",
242 diag2str(bs
->remote_diag
));
244 json_object_int_add(jo
, "receive-interval",
245 bs
->timers
.required_min_rx
/ 1000);
246 json_object_int_add(jo
, "transmit-interval",
247 bs
->timers
.desired_min_tx
/ 1000);
248 if (CHECK_FLAG(bs
->flags
, BFD_SESS_FLAG_ECHO
))
249 json_object_int_add(jo
, "echo-interval",
250 bs
->timers
.required_min_echo
/ 1000);
252 json_object_int_add(jo
, "echo-interval", 0);
254 json_object_int_add(jo
, "detect-multiplier", bs
->detect_mult
);
256 json_object_int_add(jo
, "remote-receive-interval",
257 bs
->remote_timers
.required_min_rx
/ 1000);
258 json_object_int_add(jo
, "remote-transmit-interval",
259 bs
->remote_timers
.desired_min_tx
/ 1000);
260 json_object_int_add(jo
, "remote-echo-interval",
261 bs
->remote_timers
.required_min_echo
/ 1000);
262 json_object_int_add(jo
, "remote-detect-multiplier",
263 bs
->remote_detect_mult
);
268 static void _display_peer_json(struct vty
*vty
, struct bfd_session
*bs
)
270 struct json_object
*jo
= __display_peer_json(bs
);
272 vty_out(vty
, "%s\n", json_object_to_json_string_ext(jo
, 0));
273 json_object_free(jo
);
276 struct bfd_vrf_tuple
{
279 struct json_object
*jo
;
282 static void _display_peer_iter(struct hash_bucket
*hb
, void *arg
)
284 struct bfd_vrf_tuple
*bvt
= (struct bfd_vrf_tuple
*)arg
;
286 struct bfd_session
*bs
= hb
->data
;
293 if (!bs
->key
.vrfname
[0] ||
294 !strmatch(bs
->key
.vrfname
, bvt
->vrfname
))
297 _display_peer(vty
, bs
);
300 static void _display_peer_json_iter(struct hash_bucket
*hb
, void *arg
)
302 struct bfd_vrf_tuple
*bvt
= (struct bfd_vrf_tuple
*)arg
;
303 struct json_object
*jo
, *jon
= NULL
;
304 struct bfd_session
*bs
= hb
->data
;
311 if (!bs
->key
.vrfname
[0] ||
312 !strmatch(bs
->key
.vrfname
, bvt
->vrfname
))
316 jon
= __display_peer_json(bs
);
318 zlog_warn("%s: not enough memory", __func__
);
322 json_object_array_add(jo
, jon
);
325 static void _display_all_peers(struct vty
*vty
, char *vrfname
, bool use_json
)
327 struct json_object
*jo
;
328 struct bfd_vrf_tuple bvt
= {0};
330 bvt
.vrfname
= vrfname
;
334 vty_out(vty
, "BFD Peers:\n");
335 bfd_id_iterate(_display_peer_iter
, &bvt
);
339 jo
= json_object_new_array();
341 bfd_id_iterate(_display_peer_json_iter
, &bvt
);
343 vty_out(vty
, "%s\n", json_object_to_json_string_ext(jo
, 0));
344 json_object_free(jo
);
347 static void _display_peer_counter(struct vty
*vty
, struct bfd_session
*bs
)
349 _display_peer_header(vty
, bs
);
351 vty_out(vty
, "\t\tControl packet input: %" PRIu64
" packets\n",
352 bs
->stats
.rx_ctrl_pkt
);
353 vty_out(vty
, "\t\tControl packet output: %" PRIu64
" packets\n",
354 bs
->stats
.tx_ctrl_pkt
);
355 vty_out(vty
, "\t\tEcho packet input: %" PRIu64
" packets\n",
356 bs
->stats
.rx_echo_pkt
);
357 vty_out(vty
, "\t\tEcho packet output: %" PRIu64
" packets\n",
358 bs
->stats
.tx_echo_pkt
);
359 vty_out(vty
, "\t\tSession up events: %" PRIu64
"\n",
360 bs
->stats
.session_up
);
361 vty_out(vty
, "\t\tSession down events: %" PRIu64
"\n",
362 bs
->stats
.session_down
);
363 vty_out(vty
, "\t\tZebra notifications: %" PRIu64
"\n",
364 bs
->stats
.znotification
);
368 static struct json_object
*__display_peer_counters_json(struct bfd_session
*bs
)
370 struct json_object
*jo
= _peer_json_header(bs
);
372 json_object_int_add(jo
, "control-packet-input", bs
->stats
.rx_ctrl_pkt
);
373 json_object_int_add(jo
, "control-packet-output", bs
->stats
.tx_ctrl_pkt
);
374 json_object_int_add(jo
, "echo-packet-input", bs
->stats
.rx_echo_pkt
);
375 json_object_int_add(jo
, "echo-packet-output", bs
->stats
.tx_echo_pkt
);
376 json_object_int_add(jo
, "session-up", bs
->stats
.session_up
);
377 json_object_int_add(jo
, "session-down", bs
->stats
.session_down
);
378 json_object_int_add(jo
, "zebra-notifications", bs
->stats
.znotification
);
383 static void _display_peer_counters_json(struct vty
*vty
, struct bfd_session
*bs
)
385 struct json_object
*jo
= __display_peer_counters_json(bs
);
387 vty_out(vty
, "%s\n", json_object_to_json_string_ext(jo
, 0));
388 json_object_free(jo
);
391 static void _display_peer_counter_iter(struct hash_bucket
*hb
, void *arg
)
393 struct bfd_vrf_tuple
*bvt
= arg
;
395 struct bfd_session
*bs
= hb
->data
;
402 if (!bs
->key
.vrfname
[0] ||
403 !strmatch(bs
->key
.vrfname
, bvt
->vrfname
))
407 _display_peer_counter(vty
, bs
);
410 static void _display_peer_counter_json_iter(struct hash_bucket
*hb
, void *arg
)
412 struct json_object
*jo
, *jon
= NULL
;
413 struct bfd_session
*bs
= hb
->data
;
414 struct bfd_vrf_tuple
*bvt
= arg
;
421 if (!bs
->key
.vrfname
[0] ||
422 !strmatch(bs
->key
.vrfname
, bvt
->vrfname
))
426 jon
= __display_peer_counters_json(bs
);
428 zlog_warn("%s: not enough memory", __func__
);
432 json_object_array_add(jo
, jon
);
435 static void _display_peers_counter(struct vty
*vty
, char *vrfname
, bool use_json
)
437 struct json_object
*jo
;
438 struct bfd_vrf_tuple bvt
= {0};
440 bvt
.vrfname
= vrfname
;
443 vty_out(vty
, "BFD Peers:\n");
444 bfd_id_iterate(_display_peer_counter_iter
, &bvt
);
448 jo
= json_object_new_array();
450 bfd_id_iterate(_display_peer_counter_json_iter
, jo
);
452 vty_out(vty
, "%s\n", json_object_to_json_string_ext(jo
, 0));
453 json_object_free(jo
);
456 static void _clear_peer_counter(struct bfd_session
*bs
)
458 /* Clear only pkt stats, intention is not to loose system
460 bs
->stats
.rx_ctrl_pkt
= 0;
461 bs
->stats
.tx_ctrl_pkt
= 0;
462 bs
->stats
.rx_echo_pkt
= 0;
463 bs
->stats
.tx_echo_pkt
= 0;
466 static void _display_peer_brief(struct vty
*vty
, struct bfd_session
*bs
)
468 char addr_buf
[INET6_ADDRSTRLEN
];
470 if (CHECK_FLAG(bs
->flags
, BFD_SESS_FLAG_MH
)) {
471 vty_out(vty
, "%-10u", bs
->discrs
.my_discr
);
472 inet_ntop(bs
->key
.family
, &bs
->key
.local
, addr_buf
, sizeof(addr_buf
));
473 vty_out(vty
, " %-40s", addr_buf
);
474 inet_ntop(bs
->key
.family
, &bs
->key
.peer
, addr_buf
, sizeof(addr_buf
));
475 vty_out(vty
, " %-40s", addr_buf
);
476 vty_out(vty
, "%-15s\n", state_list
[bs
->ses_state
].str
);
478 vty_out(vty
, "%-10u", bs
->discrs
.my_discr
);
479 vty_out(vty
, " %-40s", satostr(&bs
->local_address
));
480 inet_ntop(bs
->key
.family
, &bs
->key
.peer
, addr_buf
, sizeof(addr_buf
));
481 vty_out(vty
, " %-40s", addr_buf
);
483 vty_out(vty
, "%-15s\n", state_list
[bs
->ses_state
].str
);
487 static void _display_peer_brief_iter(struct hash_bucket
*hb
, void *arg
)
489 struct bfd_vrf_tuple
*bvt
= arg
;
491 struct bfd_session
*bs
= hb
->data
;
498 if (!bs
->key
.vrfname
[0] ||
499 !strmatch(bs
->key
.vrfname
, bvt
->vrfname
))
503 _display_peer_brief(vty
, bs
);
506 static void _display_peers_brief(struct vty
*vty
, const char *vrfname
, bool use_json
)
508 struct json_object
*jo
;
509 struct bfd_vrf_tuple bvt
= {0};
511 bvt
.vrfname
= vrfname
;
516 vty_out(vty
, "Session count: %lu\n", bfd_get_session_count());
517 vty_out(vty
, "%-10s", "SessionId");
518 vty_out(vty
, " %-40s", "LocalAddress");
519 vty_out(vty
, " %-40s", "PeerAddress");
520 vty_out(vty
, "%-15s\n", "Status");
522 vty_out(vty
, "%-10s", "=========");
523 vty_out(vty
, " %-40s", "============");
524 vty_out(vty
, " %-40s", "===========");
525 vty_out(vty
, "%-15s\n", "======");
527 bfd_id_iterate(_display_peer_brief_iter
, &bvt
);
531 jo
= json_object_new_array();
534 bfd_id_iterate(_display_peer_json_iter
, &bvt
);
536 vty_out(vty
, "%s\n", json_object_to_json_string_ext(jo
, 0));
537 json_object_free(jo
);
540 static struct bfd_session
*
541 _find_peer_or_error(struct vty
*vty
, int argc
, struct cmd_token
**argv
,
542 const char *label
, const char *peer_str
,
543 const char *local_str
, const char *ifname
,
548 struct bfd_session
*bs
= NULL
;
549 struct peer_label
*pl
;
550 struct bfd_peer_cfg bpc
;
551 struct sockaddr_any psa
, lsa
, *lsap
;
554 /* Look up the BFD peer. */
560 strtosa(peer_str
, &psa
);
562 strtosa(local_str
, &lsa
);
568 mhop
= argv_find(argv
, argc
, "multihop", &idx
);
570 if (bfd_configure_peer(&bpc
, mhop
, &psa
, lsap
, ifname
, vrfname
,
571 errormsg
, sizeof(errormsg
))
573 vty_out(vty
, "%% Invalid peer configuration: %s\n",
578 bs
= bs_peer_find(&bpc
);
581 /* Find peer data. */
583 vty_out(vty
, "%% Unable to find 'peer %s",
584 label
? label
: peer_str
);
586 vty_out(vty
, " interface %s", ifname
);
588 vty_out(vty
, " local-address %s", local_str
);
590 vty_out(vty
, " vrf %s", vrfname
);
603 DEFPY(bfd_show_peers
, bfd_show_peers_cmd
, "show bfd [vrf NAME] peers [json]",
605 "Bidirection Forwarding Detection\n"
607 "BFD peers status\n" JSON_STR
)
609 char *vrf_name
= NULL
;
612 if (argv_find(argv
, argc
, "vrf", &idx_vrf
))
613 vrf_name
= argv
[idx_vrf
+ 1]->arg
;
615 _display_all_peers(vty
, vrf_name
, use_json(argc
, argv
));
620 DEFPY(bfd_show_peer
, bfd_show_peer_cmd
,
621 "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]",
623 "Bidirection Forwarding Detection\n"
626 "Peer label\n" PEER_IPV4_STR PEER_IPV6_STR MHOP_STR LOCAL_STR
627 LOCAL_IPV4_STR LOCAL_IPV6_STR INTERFACE_STR LOCAL_INTF_STR JSON_STR
)
629 struct bfd_session
*bs
;
631 /* Look up the BFD peer. */
632 bs
= _find_peer_or_error(vty
, argc
, argv
, label
, peer_str
, local_str
,
635 return CMD_WARNING_CONFIG_FAILED
;
637 if (use_json(argc
, argv
)) {
638 _display_peer_json(vty
, bs
);
640 vty_out(vty
, "BFD Peer:\n");
641 _display_peer(vty
, bs
);
647 DEFPY(bfd_show_peer_counters
, bfd_show_peer_counters_cmd
,
648 "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]",
650 "Bidirection Forwarding Detection\n"
662 "Show BFD peer counters information\n"
665 struct bfd_session
*bs
;
667 /* Look up the BFD peer. */
668 bs
= _find_peer_or_error(vty
, argc
, argv
, label
, peer_str
, local_str
,
671 return CMD_WARNING_CONFIG_FAILED
;
673 if (use_json(argc
, argv
))
674 _display_peer_counters_json(vty
, bs
);
676 _display_peer_counter(vty
, bs
);
681 DEFPY(bfd_show_peers_counters
, bfd_show_peers_counters_cmd
,
682 "show bfd [vrf NAME] peers counters [json]",
684 "Bidirection Forwarding Detection\n"
687 "Show BFD peer counters information\n"
690 char *vrf_name
= NULL
;
693 if (argv_find(argv
, argc
, "vrf", &idx_vrf
))
694 vrf_name
= argv
[idx_vrf
+ 1]->arg
;
696 _display_peers_counter(vty
, vrf_name
, use_json(argc
, argv
));
701 DEFPY(bfd_clear_peer_counters
, bfd_clear_peer_counters_cmd
,
702 "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",
704 "Bidirection Forwarding Detection\n"
716 "clear BFD peer counters information\n")
718 struct bfd_session
*bs
;
720 /* Look up the BFD peer. */
721 bs
= _find_peer_or_error(vty
, argc
, argv
, label
, peer_str
, local_str
,
724 return CMD_WARNING_CONFIG_FAILED
;
726 _clear_peer_counter(bs
);
731 DEFPY(bfd_show_peers_brief
, bfd_show_peers_brief_cmd
,
732 "show bfd [vrf <NAME$vrfname>] peers brief [json]",
734 "Bidirection Forwarding Detection\n"
737 "Show BFD peer information in tabular form\n"
740 char *vrf_name
= NULL
;
743 if (argv_find(argv
, argc
, "vrf", &idx_vrf
))
744 vrf_name
= argv
[idx_vrf
+ 1]->arg
;
746 _display_peers_brief(vty
, vrf_name
, use_json(argc
, argv
));
752 bfd_debug_peer
, bfd_debug_peer_cmd
,
753 "[no] debug bfd peer",
756 "Bidirection Forwarding Detection\n"
757 "Peer events debugging\n")
759 bglobal
.debug_peer_event
= !no
;
764 bfd_debug_zebra
, bfd_debug_zebra_cmd
,
765 "[no] debug bfd zebra",
768 "Bidirection Forwarding Detection\n"
769 "Zebra events debugging\n")
771 bglobal
.debug_zebra
= !no
;
776 bfd_debug_network
, bfd_debug_network_cmd
,
777 "[no] debug bfd network",
780 "Bidirection Forwarding Detection\n"
781 "Network layer debugging\n")
783 bglobal
.debug_network
= !no
;
788 * Function definitions.
792 * Configuration rules:
795 * peer + (interface name)
798 * peer + local + (optional vrf)
800 * Anything else is misconfiguration.
802 static int bfd_configure_peer(struct bfd_peer_cfg
*bpc
, bool mhop
,
803 const struct sockaddr_any
*peer
,
804 const struct sockaddr_any
*local
,
805 const char *ifname
, const char *vrfname
,
806 char *ebuf
, size_t ebuflen
)
808 memset(bpc
, 0, sizeof(*bpc
));
811 bpc
->bpc_shutdown
= true;
812 bpc
->bpc_detectmultiplier
= BPC_DEF_DETECTMULTIPLIER
;
813 bpc
->bpc_recvinterval
= BPC_DEF_RECEIVEINTERVAL
;
814 bpc
->bpc_txinterval
= BPC_DEF_TRANSMITINTERVAL
;
815 bpc
->bpc_echointerval
= BPC_DEF_ECHOINTERVAL
;
816 bpc
->bpc_lastevent
= monotime(NULL
);
818 /* Safety check: when no error buf is provided len must be zero. */
822 /* Peer is always mandatory. */
824 snprintf(ebuf
, ebuflen
, "peer must not be empty");
828 /* Validate address families. */
829 if (peer
->sa_sin
.sin_family
== AF_INET
) {
830 if (local
&& local
->sa_sin
.sin_family
!= AF_INET
) {
831 snprintf(ebuf
, ebuflen
,
832 "local is IPv6, but peer is IPv4");
836 bpc
->bpc_ipv4
= true;
837 } else if (peer
->sa_sin
.sin_family
== AF_INET6
) {
838 if (local
&& local
->sa_sin
.sin_family
!= AF_INET6
) {
839 snprintf(ebuf
, ebuflen
,
840 "local is IPv4, but peer is IPv6");
844 bpc
->bpc_ipv4
= false;
846 snprintf(ebuf
, ebuflen
, "invalid peer address family");
850 /* Copy local and/or peer addresses. */
852 bpc
->bpc_local
= *local
;
854 bpc
->bpc_peer
= *peer
;
855 bpc
->bpc_mhop
= mhop
;
857 /* Handle interface specification configuration. */
859 bpc
->bpc_has_localif
= true;
860 if (strlcpy(bpc
->bpc_localif
, ifname
, sizeof(bpc
->bpc_localif
))
861 > sizeof(bpc
->bpc_localif
)) {
862 snprintf(ebuf
, ebuflen
, "interface name too long");
867 /* Handle VRF configuration. */
869 bpc
->bpc_has_vrfname
= true;
870 if (strlcpy(bpc
->bpc_vrfname
, vrfname
, sizeof(bpc
->bpc_vrfname
))
871 > sizeof(bpc
->bpc_vrfname
)) {
872 snprintf(ebuf
, ebuflen
, "vrf name too long");
876 bpc
->bpc_has_vrfname
= true;
877 strlcpy(bpc
->bpc_vrfname
, VRF_DEFAULT_NAME
, sizeof(bpc
->bpc_vrfname
));
883 DEFUN_NOSH(show_debugging_bfd
,
884 show_debugging_bfd_cmd
,
885 "show debugging [bfd]",
890 vty_out(vty
, "BFD debugging status:\n");
891 if (bglobal
.debug_peer_event
)
892 vty_out(vty
, " Peer events debugging is on.\n");
893 if (bglobal
.debug_zebra
)
894 vty_out(vty
, " Zebra events debugging is on.\n");
895 if (bglobal
.debug_network
)
896 vty_out(vty
, " Network layer debugging is on.\n");
901 static int bfdd_write_config(struct vty
*vty
);
902 struct cmd_node bfd_node
= {
905 .parent_node
= CONFIG_NODE
,
906 .prompt
= "%s(config-bfd)# ",
907 .config_write
= bfdd_write_config
,
910 struct cmd_node bfd_peer_node
= {
912 .node
= BFD_PEER_NODE
,
913 .parent_node
= BFD_NODE
,
914 .prompt
= "%s(config-bfd-peer)# ",
917 static int bfdd_write_config(struct vty
*vty
)
919 struct lyd_node
*dnode
;
922 if (bglobal
.debug_peer_event
) {
923 vty_out(vty
, "debug bfd peer\n");
927 if (bglobal
.debug_zebra
) {
928 vty_out(vty
, "debug bfd zebra\n");
932 if (bglobal
.debug_network
) {
933 vty_out(vty
, "debug bfd network\n");
937 dnode
= yang_dnode_get(running_config
->dnode
, "/frr-bfdd:bfdd");
939 nb_cli_show_dnode_cmds(vty
, dnode
, false);
946 void bfdd_vty_init(void)
948 install_element(ENABLE_NODE
, &bfd_show_peers_counters_cmd
);
949 install_element(ENABLE_NODE
, &bfd_show_peer_counters_cmd
);
950 install_element(ENABLE_NODE
, &bfd_clear_peer_counters_cmd
);
951 install_element(ENABLE_NODE
, &bfd_show_peers_cmd
);
952 install_element(ENABLE_NODE
, &bfd_show_peer_cmd
);
953 install_element(ENABLE_NODE
, &bfd_show_peers_brief_cmd
);
954 install_element(ENABLE_NODE
, &show_debugging_bfd_cmd
);
956 install_element(ENABLE_NODE
, &bfd_debug_peer_cmd
);
957 install_element(ENABLE_NODE
, &bfd_debug_zebra_cmd
);
958 install_element(ENABLE_NODE
, &bfd_debug_network_cmd
);
960 install_element(CONFIG_NODE
, &bfd_debug_peer_cmd
);
961 install_element(CONFIG_NODE
, &bfd_debug_zebra_cmd
);
962 install_element(CONFIG_NODE
, &bfd_debug_network_cmd
);
964 /* Install BFD node and commands. */
965 install_node(&bfd_node
);
966 install_default(BFD_NODE
);
968 /* Install BFD peer node. */
969 install_node(&bfd_peer_node
);
970 install_default(BFD_PEER_NODE
);