]> git.puffer.fish Git - matthieu/frr.git/commitdiff
vrrpd: add debugging knobs
authorQuentin Young <qlyoung@cumulusnetworks.com>
Tue, 12 Feb 2019 20:39:13 +0000 (20:39 +0000)
committerQuentin Young <qlyoung@cumulusnetworks.com>
Fri, 17 May 2019 00:27:08 +0000 (00:27 +0000)
* Add control structures for debugging
* Add CLI commands for debugging

Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
vrrpd/subdir.am
vrrpd/vrrp_debug.c [new file with mode: 0644]
vrrpd/vrrp_debug.h [new file with mode: 0644]
vrrpd/vrrp_main.c
vrrpd/vrrp_vty.c

index 633a4a8e7345f2c0c31271396b6ca716fb3ebcdc..17c8fc27926affed991611d3e1ebcacafc725bdb 100644 (file)
@@ -13,6 +13,7 @@ endif
 vrrpd_libvrrp_a_SOURCES = \
        vrrpd/vrrp.c \
        vrrpd/vrrp_arp.c \
+       vrrpd/vrrp_debug.c \
        vrrpd/vrrp_memory.c \
        vrrpd/vrrp_ndisc.c \
        vrrpd/vrrp_packet.c \
@@ -23,6 +24,7 @@ vrrpd_libvrrp_a_SOURCES = \
 noinst_HEADERS += \
        vrrpd/vrrp.h \
        vrrpd/vrrp_arp.h \
+       vrrpd/vrrp_debug.h \
        vrrpd/vrrp_memory.h \
        vrrpd/vrrp_ndisc.h \
        vrrpd/vrrp_vty.h \
diff --git a/vrrpd/vrrp_debug.c b/vrrpd/vrrp_debug.c
new file mode 100644 (file)
index 0000000..cea2bbf
--- /dev/null
@@ -0,0 +1,131 @@
+/*
+ * VRRP debugging.
+ * Copyright (C) 2019 Cumulus Networks, Inc.
+ * Quentin Young
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the Free
+ * Software Foundation; either version 2 of the License, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; see the file COPYING; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+#include <zebra.h>
+
+#include "lib/command.h"
+#include "lib/debug.h"
+#include "lib/vector.h"
+
+#include "vrrp_debug.h"
+
+/* clang-format off */
+struct debug vrrp_dbg_arp = {0, "VRRP ARP"};
+struct debug vrrp_dbg_auto = {0, "VRRP autoconfiguration events"};
+struct debug vrrp_dbg_ndisc = {0, "VRRP Neighbor Discovery"};
+struct debug vrrp_dbg_pkt = {0, "VRRP packets"};
+struct debug vrrp_dbg_proto = {0, "VRRP protocol events"};
+struct debug vrrp_dbg_sock = {0, "VRRP sockets"};
+struct debug vrrp_dbg_zebra = {0, "VRRP Zebra events"};
+
+struct debug *vrrp_debugs[] = {
+       &vrrp_dbg_arp, 
+       &vrrp_dbg_auto,
+       &vrrp_dbg_ndisc,
+       &vrrp_dbg_pkt,
+       &vrrp_dbg_proto,
+       &vrrp_dbg_sock,
+       &vrrp_dbg_zebra
+};
+
+const char *vrrp_debugs_conflines[] = {
+       "debug vrrp arp",
+       "debug vrrp autoconfigure",
+       "debug vrrp ndisc",
+       "debug vrrp packets",
+       "debug vrrp protocol",
+       "debug vrrp sockets",
+       "debug vrrp zebra",
+};
+/* clang-format on */
+
+/*
+ * Set or unset flags on all debugs for vrrpd.
+ *
+ * flags
+ *    The flags to set
+ *
+ * set
+ *    Whether to set or unset the specified flags
+ */
+static void vrrp_debug_set_all(uint32_t flags, bool set)
+{
+       for (unsigned int i = 0; i < array_size(vrrp_debugs); i++) {
+               DEBUG_FLAGS_SET(vrrp_debugs[i], flags, set);
+
+               /* if all modes have been turned off, don't preserve options */
+               if (!DEBUG_MODE_CHECK(vrrp_debugs[i], DEBUG_MODE_ALL))
+                       DEBUG_CLEAR(vrrp_debugs[i]);
+       }
+}
+
+static int vrrp_debug_config_write_helper(struct vty *vty, bool config)
+{
+       uint32_t mode = DEBUG_MODE_ALL;
+
+       if (config)
+               mode = DEBUG_MODE_CONF;
+
+       for (unsigned int i = 0; i < array_size(vrrp_debugs); i++)
+               if (DEBUG_MODE_CHECK(vrrp_debugs[i], mode))
+                       vty_out(vty, "%s\n", vrrp_debugs_conflines[i]);
+
+       return 0;
+}
+
+int vrrp_debug_config_write(struct vty *vty)
+{
+       return vrrp_debug_config_write_helper(vty, true);
+}
+
+int vrrp_debug_status_write(struct vty *vty)
+{
+       return vrrp_debug_config_write_helper(vty, false);
+}
+
+void vrrp_debug_set(struct interface *ifp, uint8_t vrid, int vtynode,
+                   bool onoff, bool proto, bool autoconf, bool pkt, bool sock,
+                   bool ndisc, bool arp, bool zebra)
+{
+       uint32_t mode = DEBUG_NODE2MODE(vtynode);
+
+       if (proto)
+               DEBUG_MODE_SET(&vrrp_dbg_proto, mode, onoff);
+       if (autoconf)
+               DEBUG_MODE_SET(&vrrp_dbg_auto, mode, onoff);
+       if (pkt)
+               DEBUG_MODE_SET(&vrrp_dbg_pkt, mode, onoff);
+       if (sock)
+               DEBUG_MODE_SET(&vrrp_dbg_sock, mode, onoff);
+       if (ndisc)
+               DEBUG_MODE_SET(&vrrp_dbg_ndisc, mode, onoff);
+       if (arp)
+               DEBUG_MODE_SET(&vrrp_dbg_arp, mode, onoff);
+       if (zebra)
+               DEBUG_MODE_SET(&vrrp_dbg_zebra, mode, onoff);
+}
+
+/* ------------------------------------------------------------------------- */
+
+struct debug_callbacks vrrp_dbg_cbs = {.debug_set_all = vrrp_debug_set_all};
+
+void vrrp_debug_init(void)
+{
+       debug_init(&vrrp_dbg_cbs);
+}
diff --git a/vrrpd/vrrp_debug.h b/vrrpd/vrrp_debug.h
new file mode 100644 (file)
index 0000000..c54b20e
--- /dev/null
@@ -0,0 +1,87 @@
+/*
+ * VRRP debugging.
+ * Copyright (C) 2019 Cumulus Networks, Inc.
+ * Quentin Young
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the Free
+ * Software Foundation; either version 2 of the License, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; see the file COPYING; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+#ifndef __VRRP_DEBUG_H__
+#define __VRRP_DEBUG_H__
+
+#include <zebra.h>
+
+#include "lib/debug.h"
+
+/* VRRP debugging records */
+struct debug vrrp_dbg_arp;
+struct debug vrrp_dbg_auto;
+struct debug vrrp_dbg_ndisc;
+struct debug vrrp_dbg_pkt;
+struct debug vrrp_dbg_proto;
+struct debug vrrp_dbg_sock;
+struct debug vrrp_dbg_zebra;
+
+/*
+ * Initialize VRRP debugging.
+ *
+ * Installs VTY commands and registers callbacks.
+ */
+void vrrp_debug_init(void);
+
+/*
+ * Print VRRP debugging configuration.
+ *
+ * vty
+ *    VTY to print debugging configuration to.
+ */
+int vrrp_debug_config_write(struct vty *vty);
+
+/*
+ * Print VRRP debugging configuration, human readable form.
+ *
+ * vty
+ *    VTY to print debugging configuration to.
+ */
+int vrrp_debug_status_write(struct vty *vty);
+
+/*
+ * Set debugging status.
+ *
+ * ifp
+ *    Interface to set status on
+ *
+ * vrid
+ *    VRID of instance to set status on
+ *
+ * vtynode
+ *    vty->node
+ *
+ * onoff
+ *    Whether to turn the specified debugs on or off
+ *
+ * proto
+ *    Turn protocol debugging on or off
+ *
+ * autoconf
+ *    Turn autoconfiguration debugging on or off
+ *
+ * pkt
+ *    Turn packet debugging on or off
+ */
+void vrrp_debug_set(struct interface *ifp, uint8_t vrid, int vtynode,
+                   bool onoff, bool proto, bool autoconf, bool pkt, bool sock,
+                   bool ndisc, bool arp, bool zebra);
+
+#endif /* __VRRP_DEBUG_H__ */
index daaadffab5f6c5234e016aa298b84715b0e2e0ce..01174975900adb8541c9f1c5e932c700b236b1fb 100644 (file)
@@ -35,6 +35,7 @@
 #include "lib/vrf.h"
 
 #include "vrrp.h"
+#include "vrrp_debug.h"
 #include "vrrp_vty.h"
 #include "vrrp_zebra.h"
 
@@ -139,6 +140,7 @@ int main(int argc, char **argv, char **envp)
 
        master = frr_init();
 
+       vrrp_debug_init();
        vrrp_zebra_init();
        vrrp_vty_init();
        vrrp_init();
index 8362a966f840421668a1792a075249525eba3fad..3183315bf4a231dfb79a571fc95aaf63c11c3c26 100644 (file)
@@ -27,8 +27,9 @@
 #include "lib/vty.h"
 
 #include "vrrp.h"
-#include "vrrp_vty.h"
+#include "vrrp_debug.h"
 #include "vrrp_memory.h"
+#include "vrrp_vty.h"
 #ifndef VTYSH_EXTRACT_PL
 #include "vrrpd/vrrp_vty_clippy.c"
 #endif
                }                                                              \
        } while (0);
 
-DEFUN_NOSH (show_debugging_vrrpd,
-           show_debugging_vrrpd_cmd,
-           "show debugging [vrrp]",
-           SHOW_STR
-           DEBUG_STR
-           "VRRP information\n")
-{
-       vty_out(vty, "VRRP debugging status\n");
-
-       return CMD_SUCCESS;
-}
-
 DEFPY(vrrp_vrid,
       vrrp_vrid_cmd,
       "[no] vrrp (1-255)$vrid [version (2-3)]",
@@ -383,17 +372,63 @@ DEFPY(vrrp_vrid_show,
        return CMD_SUCCESS;
 }
 
+
+DEFPY(debug_vrrp,
+      debug_vrrp_cmd,
+      "[no] debug vrrp [{protocol$proto|autoconfigure$ac|packets$pkt|sockets$sock|ndisc$ndisc|arp$arp|zebra$zebra}]",
+      NO_STR
+      DEBUG_STR
+      VRRP_STR
+      "Debug protocol state\n"
+      "Debug autoconfiguration\n"
+      "Debug sent and received packets\n"
+      "Debug socket creation and configuration\n"
+      "Debug Neighbor Discovery\n"
+      "Debug ARP\n"
+      "Debug Zebra events\n")
+{
+       /* If no specific are given on/off them all */
+       if (strmatch(argv[argc - 1]->text, "vrrp"))
+               vrrp_debug_set(NULL, 0, vty->node, !no, true, true, true, true,
+                              true, true, true);
+       else
+               vrrp_debug_set(NULL, 0, vty->node, !no, !!proto, !!ac, !!pkt,
+                              !!sock, !!ndisc, !!arp, !!zebra);
+
+       return CMD_SUCCESS;
+}
+
+DEFUN_NOSH (show_debugging_vrrp,
+           show_debugging_vrrp_cmd,
+           "show debugging [vrrp]",
+           SHOW_STR
+           DEBUG_STR
+           "VRRP information\n")
+{
+       vty_out(vty, "VRRP debugging status:\n");
+
+       vrrp_debug_status_write(vty);
+
+       return CMD_SUCCESS;
+}
+
 static struct cmd_node interface_node = {
        INTERFACE_NODE,
        "%s(config-if)# ", 1
 };
 
+static struct cmd_node debug_node = {DEBUG_NODE, "", 1};
+
 void vrrp_vty_init(void)
 {
+       install_node(&debug_node, vrrp_debug_config_write);
        install_node(&interface_node, NULL);
        if_cmd_init();
-       install_element(VIEW_NODE, &show_debugging_vrrpd_cmd);
+
        install_element(VIEW_NODE, &vrrp_vrid_show_cmd);
+       install_element(VIEW_NODE, &show_debugging_vrrp_cmd);
+       install_element(VIEW_NODE, &debug_vrrp_cmd);
+       install_element(CONFIG_NODE, &debug_vrrp_cmd);
        install_element(CONFIG_NODE, &vrrp_autoconfigure_cmd);
        install_element(INTERFACE_NODE, &vrrp_vrid_cmd);
        install_element(INTERFACE_NODE, &vrrp_priority_cmd);