From 2815f817e5b567538ece6cd5f1ef212888c5cd65 Mon Sep 17 00:00:00 2001 From: Christian Franke Date: Fri, 28 Sep 2018 19:35:10 +0200 Subject: [PATCH] isisd: Add debugging for BFD Signed-off-by: Christian Franke --- isisd/isis_bfd.c | 61 ++++++++++++++++++++++++++++++++++++++++++++++++ isisd/isisd.c | 37 +++++++++++++++++++++++++++++ isisd/isisd.h | 1 + 3 files changed, 99 insertions(+) diff --git a/isisd/isis_bfd.c b/isisd/isis_bfd.c index 8b85811fdc..6f89d98735 100644 --- a/isisd/isis_bfd.c +++ b/isisd/isis_bfd.c @@ -63,6 +63,23 @@ static void bfd_session_free(struct bfd_session **session) static int isis_bfd_interface_dest_update(int command, struct zclient *zclient, zebra_size_t length, vrf_id_t vrf_id) { + struct interface *ifp; + struct prefix dst_ip; + int status; + + ifp = bfd_get_peer_info(zclient->ibuf, &dst_ip, NULL, &status, vrf_id); + if (!ifp || dst_ip.family != AF_INET) + return 0; + + if (isis->debugs & DEBUG_BFD) { + char dst_buf[INET6_ADDRSTRLEN]; + inet_ntop(AF_INET, &dst_ip.u.prefix4, + dst_buf, sizeof(dst_buf)); + + zlog_debug("ISIS-BFD: Received update for %s on %s: Changed state to %s", + dst_buf, ifp->name, bfd_get_status_str(status)); + } + return 0; } @@ -74,6 +91,9 @@ static int isis_bfd_nbr_replay(int command, struct zclient *zclient, struct listnode *anode; struct isis_area *area; + if (isis->debugs & DEBUG_BFD) + zlog_debug("ISIS-BFD: Got neighbor replay request, resending neighbors."); + for (ALL_LIST_ELEMENTS_RO(isis->area_list, anode, area)) { struct listnode *cnode; struct isis_circuit *circuit; @@ -82,6 +102,9 @@ static int isis_bfd_nbr_replay(int command, struct zclient *zclient, isis_bfd_circuit_cmd(circuit, ZEBRA_BFD_DEST_UPDATE); } + if (isis->debugs & DEBUG_BFD) + zlog_debug("ISIS-BFD: Done with replay."); + return 0; } @@ -94,11 +117,47 @@ static void isis_bfd_zebra_connected(struct zclient *zclient) bfd_client_sendmsg(zclient, ZEBRA_BFD_CLIENT_REGISTER); } +static void bfd_debug(struct in_addr *dst, struct in_addr *src, + const char *interface, int command) +{ + if (!(isis->debugs & DEBUG_BFD)) + return; + + char dst_str[INET6_ADDRSTRLEN]; + char src_str[INET6_ADDRSTRLEN]; + + inet_ntop(AF_INET, dst, dst_str, sizeof(dst_str)); + inet_ntop(AF_INET, src, src_str, sizeof(src_str)); + + const char *command_str; + + switch (command) { + case ZEBRA_BFD_DEST_REGISTER: + command_str = "Register"; + break; + case ZEBRA_BFD_DEST_DEREGISTER: + command_str = "Deregister"; + break; + case ZEBRA_BFD_DEST_UPDATE: + command_str = "Update"; + break; + default: + command_str = "Unknown-Cmd"; + break; + } + + zlog_debug("ISIS-BFD: %s peer %s on %s (src %s)", + command_str, dst_str, interface, src_str); +} + static void bfd_handle_adj_down(struct isis_adjacency *adj) { if (!adj->bfd_session) return; + bfd_debug(&adj->bfd_session->dst_ip, &adj->bfd_session->src_ip, + adj->circuit->interface->name, ZEBRA_BFD_DEST_DEREGISTER); + bfd_peer_sendmsg(zclient, NULL, AF_INET, &adj->bfd_session->dst_ip, &adj->bfd_session->src_ip, @@ -137,6 +196,8 @@ static void bfd_handle_adj_up(struct isis_adjacency *adj, int command) if (!adj->bfd_session) adj->bfd_session = bfd_session_new(dst_ip, src_ip); + bfd_debug(&adj->bfd_session->dst_ip, &adj->bfd_session->src_ip, + circuit->interface->name, command); bfd_peer_sendmsg(zclient, circuit->bfd_info, AF_INET, &adj->bfd_session->dst_ip, &adj->bfd_session->src_ip, diff --git a/isisd/isisd.c b/isisd/isisd.c index e5e43c4b7d..94e6a63855 100644 --- a/isisd/isisd.c +++ b/isisd/isisd.c @@ -746,6 +746,8 @@ void print_debug(struct vty *vty, int flags, int onoff) vty_out(vty, "IS-IS LSP scheduling debugging is %s\n", onoffs); if (flags & DEBUG_FABRICD_FLOODING) vty_out(vty, "OpenFabric Flooding debugging is %s\n", onoffs); + if (flags & DEBUG_BFD) + vty_out(vty, "IS-IS BFD debugging is %s\n", onoffs); } DEFUN_NOSH (show_debugging, @@ -831,6 +833,10 @@ static int config_write_debug(struct vty *vty) vty_out(vty, "debug " PROTO_NAME " flooding\n"); write++; } + if (flags & DEBUG_BFD) { + vty_out(vty, "debug " PROTO_NAME " bfd\n"); + write++; + } write += spf_backoff_write_config(vty); return write; @@ -1214,6 +1220,33 @@ DEFUN (no_debug_isis_lsp_sched, return CMD_SUCCESS; } +DEFUN (debug_isis_bfd, + debug_isis_bfd_cmd, + "debug " PROTO_NAME " bfd", + DEBUG_STR + PROTO_HELP + PROTO_NAME " interaction with BFD\n") +{ + isis->debugs |= DEBUG_BFD; + print_debug(vty, DEBUG_BFD, 1); + + return CMD_SUCCESS; +} + +DEFUN (no_debug_isis_bfd, + no_debug_isis_bfd_cmd, + "no debug " PROTO_NAME " bfd", + NO_STR + UNDEBUG_STR + PROTO_HELP + PROTO_NAME " interaction with BFD\n") +{ + isis->debugs &= ~DEBUG_BFD; + print_debug(vty, DEBUG_BFD, 0); + + return CMD_SUCCESS; +} + DEFUN (show_hostname, show_hostname_cmd, "show " PROTO_NAME " hostname", @@ -2215,6 +2248,8 @@ void isis_init() install_element(ENABLE_NODE, &no_debug_isis_lsp_gen_cmd); install_element(ENABLE_NODE, &debug_isis_lsp_sched_cmd); install_element(ENABLE_NODE, &no_debug_isis_lsp_sched_cmd); + install_element(ENABLE_NODE, &debug_isis_bfd_cmd); + install_element(ENABLE_NODE, &no_debug_isis_bfd_cmd); install_element(CONFIG_NODE, &debug_isis_adj_cmd); install_element(CONFIG_NODE, &no_debug_isis_adj_cmd); @@ -2244,6 +2279,8 @@ void isis_init() install_element(CONFIG_NODE, &no_debug_isis_lsp_gen_cmd); install_element(CONFIG_NODE, &debug_isis_lsp_sched_cmd); install_element(CONFIG_NODE, &no_debug_isis_lsp_sched_cmd); + install_element(CONFIG_NODE, &debug_isis_bfd_cmd); + install_element(CONFIG_NODE, &no_debug_isis_bfd_cmd); install_element(CONFIG_NODE, &router_isis_cmd); install_element(CONFIG_NODE, &no_router_isis_cmd); diff --git a/isisd/isisd.h b/isisd/isisd.h index 864021428a..7572f55174 100644 --- a/isisd/isisd.h +++ b/isisd/isisd.h @@ -211,6 +211,7 @@ extern struct thread_master *master; #define DEBUG_LSP_GEN (1<<13) #define DEBUG_LSP_SCHED (1<<14) #define DEBUG_FABRICD_FLOODING (1<<15) +#define DEBUG_BFD (1<<16) #define lsp_debug(...) \ do { \ -- 2.39.5