[pim] debug mroute
diff --git a/pimd/pim_cmd.c b/pimd/pim_cmd.c
index 9553361..2b418cd 100644
--- a/pimd/pim_cmd.c
+++ b/pimd/pim_cmd.c
@@ -3131,6 +3131,33 @@
        DEBUG_IGMP_STR
        DEBUG_IGMP_TRACE_STR)
 
+DEFUN (debug_mroute,
+       debug_mroute_cmd,
+       "debug mroute",
+       DEBUG_STR
+       DEBUG_MROUTE_STR)
+{
+  PIM_DO_DEBUG_MROUTE;
+  return CMD_SUCCESS;
+}
+
+DEFUN (no_debug_mroute,
+       no_debug_mroute_cmd,
+       "no debug mroute",
+       NO_STR
+       DEBUG_STR
+       DEBUG_MROUTE_STR)
+{
+  PIM_DONT_DEBUG_MROUTE;
+  return CMD_SUCCESS;
+}
+
+ALIAS (no_debug_mroute,
+       undebug_mroute_cmd,
+       "undebug mroute",
+       UNDEBUG_STR
+       DEBUG_MROUTE_STR)
+
 DEFUN (debug_pim,
        debug_pim_cmd,
        "debug pim",
@@ -4295,6 +4322,8 @@
   install_element (ENABLE_NODE, &debug_igmp_trace_cmd);
   install_element (ENABLE_NODE, &no_debug_igmp_trace_cmd);
   install_element (ENABLE_NODE, &undebug_igmp_trace_cmd);
+  install_element (ENABLE_NODE, &debug_mroute_cmd);
+  install_element (ENABLE_NODE, &no_debug_mroute_cmd);
   install_element (ENABLE_NODE, &debug_pim_cmd);
   install_element (ENABLE_NODE, &no_debug_pim_cmd);
   install_element (ENABLE_NODE, &undebug_pim_cmd);
@@ -4332,6 +4361,8 @@
   install_element (CONFIG_NODE, &debug_igmp_trace_cmd);
   install_element (CONFIG_NODE, &no_debug_igmp_trace_cmd);
   install_element (CONFIG_NODE, &undebug_igmp_trace_cmd);
+  install_element (CONFIG_NODE, &debug_mroute_cmd);
+  install_element (CONFIG_NODE, &no_debug_mroute_cmd);
   install_element (CONFIG_NODE, &debug_pim_cmd);
   install_element (CONFIG_NODE, &no_debug_pim_cmd);
   install_element (CONFIG_NODE, &undebug_pim_cmd);
diff --git a/pimd/pim_cmd.h b/pimd/pim_cmd.h
index fd1a62f..d83cbc0 100644
--- a/pimd/pim_cmd.h
+++ b/pimd/pim_cmd.h
@@ -38,6 +38,7 @@
 #define DEBUG_IGMP_EVENTS_STR                       "IGMP protocol events\n"
 #define DEBUG_IGMP_PACKETS_STR                      "IGMP protocol packets\n"
 #define DEBUG_IGMP_TRACE_STR                        "IGMP internal daemon activity\n"
+#define DEBUG_MROUTE_STR                            "PIM interaction with kernel MFC cache\n"
 #define DEBUG_PIM_STR                               "PIM protocol activity\n"
 #define DEBUG_PIM_EVENTS_STR                        "PIM protocol events\n"
 #define DEBUG_PIM_PACKETS_STR                       "PIM protocol packets\n"
diff --git a/pimd/pim_vty.c b/pimd/pim_vty.c
index 3a1abf1..bcace95 100644
--- a/pimd/pim_vty.c
+++ b/pimd/pim_vty.c
@@ -49,6 +49,11 @@
     ++writes;
   }
 
+  if (PIM_DEBUG_MROUTE) {
+    vty_out(vty, "debug mroute%s", VTY_NEWLINE);
+    ++writes;
+  }
+
   if (PIM_DEBUG_PIM_EVENTS) {
     vty_out(vty, "debug pim events%s", VTY_NEWLINE);
     ++writes;
diff --git a/pimd/pim_zebra.c b/pimd/pim_zebra.c
index 3530434..e18b7ac 100644
--- a/pimd/pim_zebra.c
+++ b/pimd/pim_zebra.c
@@ -754,6 +754,17 @@
 
   pim_ifp = oif->info;
 
+  if (PIM_DEBUG_MROUTE) {
+    char group_str[100]; 
+    char source_str[100];
+    pim_inet4_dump("<group?>", channel_oil->oil.mfcc_mcastgrp, group_str, sizeof(group_str));
+    pim_inet4_dump("<source?>", channel_oil->oil.mfcc_origin, source_str, sizeof(source_str));
+    zlog_debug("%s %s: (S,G)=(%s,%s): proto_mask=%u OIF=%s vif_index=%d",
+	       __FILE__, __PRETTY_FUNCTION__,
+	       source_str, group_str,
+	       proto_mask, oif->name, pim_ifp->mroute_vif_index);
+  }
+
   if (pim_ifp->mroute_vif_index < 1) {
     zlog_warn("%s %s: interface %s vif_index=%d < 1",
 	      __FILE__, __PRETTY_FUNCTION__,
@@ -860,6 +871,17 @@
   ++channel_oil->oil_size;
   channel_oil->oif_flags[pim_ifp->mroute_vif_index] |= proto_mask;
 
+  if (PIM_DEBUG_MROUTE) {
+    char group_str[100]; 
+    char source_str[100];
+    pim_inet4_dump("<group?>", channel_oil->oil.mfcc_mcastgrp, group_str, sizeof(group_str));
+    pim_inet4_dump("<source?>", channel_oil->oil.mfcc_origin, source_str, sizeof(source_str));
+    zlog_debug("%s %s: (S,G)=(%s,%s): proto_mask=%u OIF=%s vif_index=%d: DONE",
+	       __FILE__, __PRETTY_FUNCTION__,
+	       source_str, group_str,
+	       proto_mask, oif->name, pim_ifp->mroute_vif_index);
+  }
+
   return 0;
 }
 
@@ -878,6 +900,17 @@
   zassert(qpim_mroute_oif_highest_vif_index < MAXVIFS);
   zassert(pim_ifp->mroute_vif_index <= qpim_mroute_oif_highest_vif_index);
 
+  if (PIM_DEBUG_MROUTE) {
+    char group_str[100]; 
+    char source_str[100];
+    pim_inet4_dump("<group?>", channel_oil->oil.mfcc_mcastgrp, group_str, sizeof(group_str));
+    pim_inet4_dump("<source?>", channel_oil->oil.mfcc_origin, source_str, sizeof(source_str));
+    zlog_debug("%s %s: (S,G)=(%s,%s): proto_mask=%u OIF=%s vif_index=%d",
+	       __FILE__, __PRETTY_FUNCTION__,
+	       source_str, group_str,
+	       proto_mask, oif->name, pim_ifp->mroute_vif_index);
+  }
+
   /* Prevent single protocol from unsubscribing same interface from
      channel (S,G) multiple times */
   if (!(channel_oil->oif_flags[pim_ifp->mroute_vif_index] & proto_mask)) {
@@ -963,6 +996,17 @@
     }
   }
 
+  if (PIM_DEBUG_MROUTE) {
+    char group_str[100]; 
+    char source_str[100];
+    pim_inet4_dump("<group?>", channel_oil->oil.mfcc_mcastgrp, group_str, sizeof(group_str));
+    pim_inet4_dump("<source?>", channel_oil->oil.mfcc_origin, source_str, sizeof(source_str));
+    zlog_debug("%s %s: (S,G)=(%s,%s): proto_mask=%u OIF=%s vif_index=%d: DONE",
+	       __FILE__, __PRETTY_FUNCTION__,
+	       source_str, group_str,
+	       proto_mask, oif->name, pim_ifp->mroute_vif_index);
+  }
+
   return 0;
 }
 
diff --git a/pimd/pimd.h b/pimd/pimd.h
index 1dcd865..e11d5ba 100644
--- a/pimd/pimd.h
+++ b/pimd/pimd.h
@@ -63,6 +63,7 @@
 #define PIM_MASK_IGMP_TRACE          (1 << 7)
 #define PIM_MASK_ZEBRA               (1 << 8)
 #define PIM_MASK_SSMPINGD            (1 << 9)
+#define PIM_MASK_MROUTE              (1 << 10)
 
 const char *const PIM_ALL_SYSTEMS;
 const char *const PIM_ALL_ROUTERS;
@@ -105,6 +106,7 @@
 #define PIM_DEBUG_IGMP_TRACE          (qpim_debugs & PIM_MASK_IGMP_TRACE)
 #define PIM_DEBUG_ZEBRA               (qpim_debugs & PIM_MASK_ZEBRA)
 #define PIM_DEBUG_SSMPINGD            (qpim_debugs & PIM_MASK_SSMPINGD)
+#define PIM_DEBUG_MROUTE              (qpim_debugs & PIM_MASK_MROUTE)
 
 #define PIM_DEBUG_EVENTS       (qpim_debugs & (PIM_MASK_PIM_EVENTS | PIM_MASK_IGMP_EVENTS))
 #define PIM_DEBUG_PACKETS      (qpim_debugs & (PIM_MASK_PIM_PACKETS | PIM_MASK_IGMP_PACKETS))
@@ -120,6 +122,7 @@
 #define PIM_DO_DEBUG_IGMP_TRACE          (qpim_debugs |= PIM_MASK_IGMP_TRACE)
 #define PIM_DO_DEBUG_ZEBRA               (qpim_debugs |= PIM_MASK_ZEBRA)
 #define PIM_DO_DEBUG_SSMPINGD            (qpim_debugs |= PIM_MASK_SSMPINGD)
+#define PIM_DO_DEBUG_MROUTE              (qpim_debugs |= PIM_MASK_MROUTE)
 
 #define PIM_DONT_DEBUG_PIM_EVENTS          (qpim_debugs &= ~PIM_MASK_PIM_EVENTS)
 #define PIM_DONT_DEBUG_PIM_PACKETS         (qpim_debugs &= ~PIM_MASK_PIM_PACKETS)
@@ -131,6 +134,7 @@
 #define PIM_DONT_DEBUG_IGMP_TRACE          (qpim_debugs &= ~PIM_MASK_IGMP_TRACE)
 #define PIM_DONT_DEBUG_ZEBRA               (qpim_debugs &= ~PIM_MASK_ZEBRA)
 #define PIM_DONT_DEBUG_SSMPINGD            (qpim_debugs &= ~PIM_MASK_SSMPINGD)
+#define PIM_DONT_DEBUG_MROUTE              (qpim_debugs &= ~PIM_MASK_MROUTE)
 
 void pim_init(void);
 void pim_terminate(void);