]> git.puffer.fish Git - mirror/frr.git/commitdiff
zebra: Add `debug zebra kernel msgdump` functionality
authorQuentin Young <qlyoung@cumulusnetworks.com>
Tue, 21 Jun 2016 18:43:40 +0000 (18:43 +0000)
committerQuentin Young <qlyoung@cumulusnetworks.com>
Tue, 21 Jun 2016 18:55:01 +0000 (18:55 +0000)
Add command and associated functionality to enable dumping
raw netlink messages.

Ticket: CM-6568

Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
Reviewed-by: Don Slice <dslice@cumulusnetworks.com>
Reviewed-by: Donald Sharp <sharpd@cumulusnetworks.com>
zebra/debug.c
zebra/debug.h
zebra/rt_netlink.c

index 4411be9b9963b8fcc3a3b3278f092e1a1df74a09..cdf233879a22d12f47a76024d3ae8642ae417643 100644 (file)
@@ -67,6 +67,10 @@ DEFUN (show_debugging_zebra,
 
   if (IS_ZEBRA_DEBUG_KERNEL)
     vty_out (vty, "  Zebra kernel debugging is on%s", VTY_NEWLINE);
+  if (IS_ZEBRA_DEBUG_KERNEL_MSGDUMP_SEND)
+    vty_out (vty, "  Zebra kernel netlink message dumps (send) are on%s", VTY_NEWLINE);
+  if (IS_ZEBRA_DEBUG_KERNEL_MSGDUMP_RECV)
+    vty_out (vty, "  Zebra kernel netlink message dumps (recv) are on%s", VTY_NEWLINE);
 
   /* Check here using flags as the 'macro' does an OR */
   if (CHECK_FLAG (zebra_debug_rib, ZEBRA_DEBUG_RIB))
@@ -162,7 +166,24 @@ DEFUN (debug_zebra_kernel,
        "Zebra configuration\n"
        "Debug option set for zebra between kernel interface\n")
 {
-  zebra_debug_kernel = ZEBRA_DEBUG_KERNEL;
+  SET_FLAG(zebra_debug_kernel, ZEBRA_DEBUG_KERNEL);
+  return CMD_SUCCESS;
+}
+
+DEFUN (debug_zebra_kernel_msgdump,
+       debug_zebra_kernel_msgdump_cmd,
+       "debug zebra kernel msgdump {recv|send}",
+       DEBUG_STR
+       "Zebra configuration\n"
+       "Debug option set for zebra between kernel interface\n"
+       "Dump raw netlink messages, sent and received\n"
+       "Dump raw netlink messages received\n"
+       "Dump raw netlink messages sent\n")
+{
+  if (!argv[1] || (argv[0] && strncmp(argv[0], "recv", strlen(argv[0])) == 0))
+    SET_FLAG(zebra_debug_kernel, ZEBRA_DEBUG_KERNEL_MSGDUMP_RECV);
+  if (!argv[0] || (argv[1] && strncmp(argv[1], "send", strlen(argv[1])) == 0))
+    SET_FLAG(zebra_debug_kernel, ZEBRA_DEBUG_KERNEL_MSGDUMP_SEND);
   return CMD_SUCCESS;
 }
 
@@ -261,7 +282,24 @@ DEFUN (no_debug_zebra_kernel,
        "Zebra configuration\n"
        "Debug option set for zebra between kernel interface\n")
 {
-  zebra_debug_kernel = 0;
+  UNSET_FLAG(zebra_debug_kernel, ZEBRA_DEBUG_KERNEL);
+  return CMD_SUCCESS;
+}
+
+DEFUN (no_debug_zebra_kernel_msgdump,
+       no_debug_zebra_kernel_msgdump_cmd,
+       "no debug zebra kernel msgdump {recv|send}",
+       DEBUG_STR
+       "Zebra configuration\n"
+       "Debug option set for zebra between kernel interface\n"
+       "Dump raw netlink messages, sent and received\n"
+       "Dump raw netlink messages received\n"
+       "Dump raw netlink messages sent\n")
+{
+  if (!argv[1] || (argv[0] && strncmp(argv[0], "recv", strlen(argv[0])) == 0))
+    UNSET_FLAG(zebra_debug_kernel, ZEBRA_DEBUG_KERNEL_MSGDUMP_RECV);
+  if (!argv[0] || (argv[1] && strncmp(argv[1], "send", strlen(argv[1])) == 0))
+    UNSET_FLAG(zebra_debug_kernel, ZEBRA_DEBUG_KERNEL_MSGDUMP_SEND);
   return CMD_SUCCESS;
 }
 
@@ -386,6 +424,7 @@ zebra_debug_init (void)
   install_element (ENABLE_NODE, &debug_zebra_packet_direct_cmd);
   install_element (ENABLE_NODE, &debug_zebra_packet_detail_cmd);
   install_element (ENABLE_NODE, &debug_zebra_kernel_cmd);
+  install_element (ENABLE_NODE, &debug_zebra_kernel_msgdump_cmd);
   install_element (ENABLE_NODE, &debug_zebra_rib_cmd);
   install_element (ENABLE_NODE, &debug_zebra_rib_detailed_cmd);
   install_element (ENABLE_NODE, &debug_zebra_fpm_cmd);
@@ -393,6 +432,7 @@ zebra_debug_init (void)
   install_element (ENABLE_NODE, &no_debug_zebra_nht_cmd);
   install_element (ENABLE_NODE, &no_debug_zebra_packet_cmd);
   install_element (ENABLE_NODE, &no_debug_zebra_kernel_cmd);
+  install_element (ENABLE_NODE, &no_debug_zebra_kernel_msgdump_cmd);
   install_element (ENABLE_NODE, &no_debug_zebra_rib_cmd);
   install_element (ENABLE_NODE, &no_debug_zebra_rib_detailed_cmd);
   install_element (ENABLE_NODE, &no_debug_zebra_fpm_cmd);
@@ -403,6 +443,7 @@ zebra_debug_init (void)
   install_element (CONFIG_NODE, &debug_zebra_packet_direct_cmd);
   install_element (CONFIG_NODE, &debug_zebra_packet_detail_cmd);
   install_element (CONFIG_NODE, &debug_zebra_kernel_cmd);
+  install_element (CONFIG_NODE, &debug_zebra_kernel_msgdump_cmd);
   install_element (CONFIG_NODE, &debug_zebra_rib_cmd);
   install_element (CONFIG_NODE, &debug_zebra_rib_detailed_cmd);
   install_element (CONFIG_NODE, &debug_zebra_fpm_cmd);
@@ -410,6 +451,7 @@ zebra_debug_init (void)
   install_element (CONFIG_NODE, &no_debug_zebra_nht_cmd);
   install_element (CONFIG_NODE, &no_debug_zebra_packet_cmd);
   install_element (CONFIG_NODE, &no_debug_zebra_kernel_cmd);
+  install_element (CONFIG_NODE, &no_debug_zebra_kernel_msgdump_cmd);
   install_element (CONFIG_NODE, &no_debug_zebra_rib_cmd);
   install_element (CONFIG_NODE, &no_debug_zebra_rib_detailed_cmd);
   install_element (CONFIG_NODE, &no_debug_zebra_fpm_cmd);
index 42af53f0d886dc9ddbbb149a2eb3f4e1c3cc333c..4416068bf2ac1377450851d59e4f1c12d15f90fe 100644 (file)
@@ -32,6 +32,8 @@
 #define ZEBRA_DEBUG_DETAIL  0x80
 
 #define ZEBRA_DEBUG_KERNEL  0x01
+#define ZEBRA_DEBUG_KERNEL_MSGDUMP_SEND 0x20
+#define ZEBRA_DEBUG_KERNEL_MSGDUMP_RECV 0x40
 
 #define ZEBRA_DEBUG_RIB     0x01
 #define ZEBRA_DEBUG_RIB_DETAILED   0x02
 #define IS_ZEBRA_DEBUG_DETAIL (zebra_debug_packet & ZEBRA_DEBUG_DETAIL)
 
 #define IS_ZEBRA_DEBUG_KERNEL (zebra_debug_kernel & ZEBRA_DEBUG_KERNEL)
+#define IS_ZEBRA_DEBUG_KERNEL_MSGDUMP_SEND \
+        (zebra_debug_kernel & ZEBRA_DEBUG_KERNEL_MSGDUMP_SEND)
+#define IS_ZEBRA_DEBUG_KERNEL_MSGDUMP_RECV \
+        (zebra_debug_kernel & ZEBRA_DEBUG_KERNEL_MSGDUMP_RECV)
 
 #define IS_ZEBRA_DEBUG_RIB \
         (zebra_debug_rib & (ZEBRA_DEBUG_RIB | ZEBRA_DEBUG_RIB_DETAILED))
index 0e336fe974d33f30f9361f624c58de24f106ad95..72951322ff8258f94688b830c8c3116887ff7a64 100644 (file)
@@ -349,6 +349,12 @@ netlink_parse_info (int (*filter) (struct sockaddr_nl *, struct nlmsghdr *,
           return -1;
         }
 
+      if (IS_ZEBRA_DEBUG_KERNEL_MSGDUMP_RECV)
+        {
+          zlog_debug("%s: << netlink message dump [recv]", __func__);
+          zlog_hexdump(&msg, sizeof(msg));
+        }
+
       read_in++;
       for (h = (struct nlmsghdr *) buf; NLMSG_OK (h, (unsigned int) status);
            h = NLMSG_NEXT (h, status))
@@ -378,9 +384,7 @@ netlink_parse_info (int (*filter) (struct sockaddr_nl *, struct nlmsghdr *,
 
                   /* return if not a multipart message, otherwise continue */
                   if (!(h->nlmsg_flags & NLM_F_MULTI))
-                    {
-                      return 0;
-                    }
+                    return 0;
                   continue;
                 }
 
@@ -1650,6 +1654,12 @@ netlink_talk (struct nlmsghdr *n, struct nlsock *nl, struct zebra_ns *zns)
   if (zserv_privs.change (ZPRIVS_LOWER))
     zlog (NULL, LOG_ERR, "Can't lower privileges");
 
+  if (IS_ZEBRA_DEBUG_KERNEL_MSGDUMP_SEND)
+    {
+      zlog_debug("%s: >> netlink message dump [sent]", __func__);
+      zlog_hexdump(&msg, sizeof(msg));
+    }
+
   if (status < 0)
     {
       zlog (NULL, LOG_ERR, "netlink_talk sendmsg() error: %s",