[bgpd] Implement 'debug bgp zebra' to log all messages to and from zebra.

2006-11-30 Andrew J. Schorr <ajschorr@alumni.princeton.edu>

	* bgp_debug.h: Declare new bgp_debug_zebra conf and term flags,
	  and define BGP_DEBUG_ZEBRA.
	* bgp_debug.c: Declare conf_bgp_debug_zebra and term_bgp_debug_zebra.
	  (debug_bgp_zebra, no_debug_bgp_zebra, undebug_bgp_zebra) New
	  functions to enable/disable bgp zebra debugging.
	  (no_debug_bgp_all) Turn off zebra debugging.
	  (show_debugging_bgp) Show whether zebra debugging is on.
	  (bgp_config_write_debug) Add 'debug bgp zebra' if configured.
	  (bgp_debug_init) Add new zebra debugging commands.
	* bgp_zebra.c: (bgp_router_id_update, bgp_interface_add,
	  bgp_interface_delete, bgp_interface_up, bgp_interface_down,
	  bgp_interface_address_add, bgp_interface_address_delete,
	  zebra_read_ipv4, zebra_read_ipv6, bgp_zebra_announce,
	  bgp_zebra_withdraw, bgp_redistribute_set, bgp_redistribute_unset)
	  If zebra debugging is enabled, log an appropriate debug message.
diff --git a/bgpd/bgp_debug.c b/bgpd/bgp_debug.c
index 1e0fcd1..1986b35 100644
--- a/bgpd/bgp_debug.c
+++ b/bgpd/bgp_debug.c
@@ -43,6 +43,7 @@
 unsigned long conf_bgp_debug_keepalive;
 unsigned long conf_bgp_debug_update;
 unsigned long conf_bgp_debug_normal;
+unsigned long conf_bgp_debug_zebra;
 
 unsigned long term_bgp_debug_fsm;
 unsigned long term_bgp_debug_events;
@@ -51,6 +52,7 @@
 unsigned long term_bgp_debug_keepalive;
 unsigned long term_bgp_debug_update;
 unsigned long term_bgp_debug_normal;
+unsigned long term_bgp_debug_zebra;
 
 /* messages for BGP-4 status */
 struct message bgp_status_msg[] = 
@@ -590,6 +592,49 @@
        UNDEBUG_STR
        BGP_STR)
 
+DEFUN (debug_bgp_zebra,
+       debug_bgp_zebra_cmd,
+       "debug bgp zebra",
+       DEBUG_STR
+       BGP_STR
+       "BGP Zebra messages\n")
+{
+  if (vty->node == CONFIG_NODE)
+    DEBUG_ON (zebra, ZEBRA);
+  else
+    {
+      TERM_DEBUG_ON (zebra, ZEBRA);
+      vty_out (vty, "BGP zebra debugging is on%s", VTY_NEWLINE);
+    }
+  return CMD_SUCCESS;
+}
+
+DEFUN (no_debug_bgp_zebra,
+       no_debug_bgp_zebra_cmd,
+       "no debug bgp zebra",
+       NO_STR
+       DEBUG_STR
+       BGP_STR
+       "BGP Zebra messages\n")
+{
+  if (vty->node == CONFIG_NODE)
+    DEBUG_OFF (zebra, ZEBRA);
+  else
+    {
+      TERM_DEBUG_OFF (zebra, ZEBRA);
+      vty_out (vty, "BGP zebra debugging is off%s", VTY_NEWLINE);
+    }
+  return CMD_SUCCESS;
+}
+
+ALIAS (no_debug_bgp_zebra,
+       undebug_bgp_zebra_cmd,
+       "undebug bgp zebra",
+       UNDEBUG_STR
+       DEBUG_STR
+       BGP_STR
+       "BGP Zebra messages\n")
+
 DEFUN (no_debug_bgp_all,
        no_debug_bgp_all_cmd,
        "no debug all bgp",
@@ -605,6 +650,7 @@
   TERM_DEBUG_OFF (update, UPDATE_OUT);
   TERM_DEBUG_OFF (fsm, FSM);
   TERM_DEBUG_OFF (filter, FILTER);
+  TERM_DEBUG_OFF (zebra, ZEBRA);
   vty_out (vty, "All possible debugging has been turned off%s", VTY_NEWLINE);
       
   return CMD_SUCCESS;
@@ -642,6 +688,8 @@
     vty_out (vty, "  BGP fsm debugging is on%s", VTY_NEWLINE);
   if (BGP_DEBUG (filter, FILTER))
     vty_out (vty, "  BGP filter debugging is on%s", VTY_NEWLINE);
+  if (BGP_DEBUG (zebra, ZEBRA))
+    vty_out (vty, "  BGP zebra debugging is on%s", VTY_NEWLINE);
   vty_out (vty, "%s", VTY_NEWLINE);
   return CMD_SUCCESS;
 }
@@ -697,6 +745,12 @@
       write++;
     }
 
+  if (CONF_BGP_DEBUG (zebra, ZEBRA))
+    {
+      vty_out (vty, "debug bgp zebra%s", VTY_NEWLINE);
+      write++;
+    }
+
   return write;
 }
 
@@ -728,6 +782,8 @@
   install_element (CONFIG_NODE, &debug_bgp_update_direct_cmd);
   install_element (ENABLE_NODE, &debug_bgp_normal_cmd);
   install_element (CONFIG_NODE, &debug_bgp_normal_cmd);
+  install_element (ENABLE_NODE, &debug_bgp_zebra_cmd);
+  install_element (CONFIG_NODE, &debug_bgp_zebra_cmd);
 
   install_element (ENABLE_NODE, &no_debug_bgp_fsm_cmd);
   install_element (ENABLE_NODE, &undebug_bgp_fsm_cmd);
@@ -747,6 +803,9 @@
   install_element (ENABLE_NODE, &no_debug_bgp_normal_cmd);
   install_element (ENABLE_NODE, &undebug_bgp_normal_cmd);
   install_element (CONFIG_NODE, &no_debug_bgp_normal_cmd);
+  install_element (ENABLE_NODE, &no_debug_bgp_zebra_cmd);
+  install_element (ENABLE_NODE, &undebug_bgp_zebra_cmd);
+  install_element (CONFIG_NODE, &no_debug_bgp_zebra_cmd);
   install_element (ENABLE_NODE, &no_debug_bgp_all_cmd);
   install_element (ENABLE_NODE, &undebug_bgp_all_cmd);
 }