Make initializing smux connection configurable - "smux peer OID" command
initializes connection, and "no smux peer" command terminates it. Fixes
bugzilla #47 and #112.
diff --git a/bgpd/ChangeLog b/bgpd/ChangeLog
index 93feb05..1d16228 100644
--- a/bgpd/ChangeLog
+++ b/bgpd/ChangeLog
@@ -1,3 +1,8 @@
+2004-10-13 Hasso Tepper <hasso at quagga.net>
+
+	* bgp_snmp.c: Remove defaults used to initialize smux connection to
+	  snmpd. Connection is initialized only if smux peer is configured.
+
 2004-10-13 Paul Jakma <paul@dishone.st>
 
 	* (global) more const'ification and fixups of types to clean up code.
diff --git a/bgpd/bgp_snmp.c b/bgpd/bgp_snmp.c
index e5bcd03..6ffadf9 100644
--- a/bgpd/bgp_snmp.c
+++ b/bgpd/bgp_snmp.c
@@ -49,10 +49,6 @@
 #define BGPESTABLISHED			1
 #define BGPBACKWARDTRANSITION		2	
 
-/* Zebra enterprise BGP MIB.  This variable is used for register
-   OSPF MIB to SNMP agent under SMUX protocol.  */
-#define BGPDMIB 1,3,6,1,4,1,3317,1,2,2
-
 /* BGP MIB bgpVersion. */
 #define BGPVERSION			      0
 
@@ -125,7 +121,6 @@
 
 /* BGP-MIB instances. */
 oid bgp_oid [] = { BGP4MIB };
-oid bgpd_oid [] = { BGPDMIB };
 
 /* IP address 0.0.0.0. */
 static struct in_addr bgp_empty_addr = {0};
@@ -880,8 +875,7 @@
   if ( !(bm = bgp_get_master ()) )
     return;
     
-  smux_init (bm->master, bgpd_oid, sizeof bgpd_oid / sizeof (oid));
+  smux_init (bm->master);
   REGISTER_MIB("mibII/bgp", bgp_variables, variable, bgp_oid);
-  smux_start ();
 }
 #endif /* HAVE_SNMP */
diff --git a/lib/ChangeLog b/lib/ChangeLog
index 25f48dd..31fb15b 100644
--- a/lib/ChangeLog
+++ b/lib/ChangeLog
@@ -2,6 +2,10 @@
 
 	* command.c: Make CMD_ERR_NOTHING_TODO nonfatal if reading
 	  configuration from file. Fixes critical bugzilla #113.
+	* smux.c, smux.h: Remove all defaults to initialize smux connection to
+	  snmpd by default even if not configured to do so. "smux peer OID
+	  <password>" initializes now connection and "no smux peer" terminates
+	  it.
 
 2004-10-13 Paul Jakma <paul@dishone.st>
 
diff --git a/lib/smux.c b/lib/smux.c
index 7e443e3..0997700 100644
--- a/lib/smux.c
+++ b/lib/smux.c
@@ -52,16 +52,11 @@
 struct list *treelist;
 
 /* SMUX oid. */
-oid *smux_oid;
+oid *smux_oid = NULL;
 size_t smux_oid_len;
 
-/* SMUX default oid. */
-oid *smux_default_oid;
-size_t smux_default_oid_len;
-
 /* SMUX password. */
-char *smux_passwd;
-const char *smux_default_passwd = "";
+char *smux_passwd = NULL;
 
 /* SMUX read threads. */
 struct thread *smux_read_thread;
@@ -1316,11 +1311,14 @@
       return CMD_WARNING;
     }
 
-  if (smux_oid && smux_oid != smux_default_oid)
-    free (smux_oid);
+  if (smux_oid)
+    {
+      free (smux_oid);
+      smux_oid = NULL;
+    }
 
   /* careful, smux_passwd might point to string constant */
-  if (smux_passwd && smux_passwd != smux_default_passwd)
+  if (smux_passwd)
     {
       free (smux_passwd);
       smux_passwd = NULL;
@@ -1331,8 +1329,10 @@
 
   if (passwd_str)
     smux_passwd = strdup (passwd_str);
+  else
+    smux_passwd = strdup ("");
 
-  return CMD_SUCCESS;
+  return 0;
 }
 
 int
@@ -1364,19 +1364,19 @@
 int
 smux_peer_default ()
 {
-  if (smux_oid != smux_default_oid)
+  if (smux_oid)
     {
       free (smux_oid);
-      smux_oid = smux_default_oid;
-      smux_oid_len = smux_default_oid_len;
+      smux_oid = NULL;
     }
   
   /* careful, smux_passwd might be pointing at string constant */
-  if (smux_passwd != smux_default_passwd)
+  if (smux_passwd)
     {
       free (smux_passwd);
-      smux_passwd = (char *)smux_default_passwd;
+      smux_passwd = NULL;
     }
+
   return CMD_SUCCESS;
 }
 
@@ -1387,7 +1387,13 @@
        "SNMP MUX peer settings\n"
        "Object ID used in SMUX peering\n")
 {
-  return smux_peer_oid (vty, argv[0], NULL);
+  if (smux_peer_oid (vty, argv[0], NULL) == 0)
+    {
+      smux_start();
+      return CMD_SUCCESS;
+    }
+  else
+    return CMD_WARNING;
 }
 
 DEFUN (smux_peer_password,
@@ -1398,31 +1404,42 @@
        "SMUX peering object ID\n"
        "SMUX peering password\n")
 {
-  return smux_peer_oid (vty, argv[0], argv[1]);
+  if (smux_peer_oid (vty, argv[0], argv[1]) == 0)
+    {
+      smux_start();
+      return CMD_SUCCESS;
+    }
+  else
+    return CMD_WARNING;
 }
 
 DEFUN (no_smux_peer,
        no_smux_peer_cmd,
+       "no smux peer",
+       NO_STR
+       "SNMP MUX protocol settings\n"
+       "SNMP MUX peer settings\n")
+{
+  smux_stop();
+  return smux_peer_default ();
+}
+
+ALIAS (no_smux_peer,
+       no_smux_peer_oid_cmd,
        "no smux peer OID",
        NO_STR
        "SNMP MUX protocol settings\n"
        "SNMP MUX peer settings\n"
-       "Object ID used in SMUX peering\n")
-{
-  return smux_peer_default ();
-}
+       "SMUX peering object ID\n")
 
-DEFUN (no_smux_peer_password,
-       no_smux_peer_password_cmd,
+ALIAS (no_smux_peer,
+       no_smux_peer_oid_password_cmd,
        "no smux peer OID PASSWORD",
        NO_STR
        "SNMP MUX protocol settings\n"
        "SNMP MUX peer settings\n"
        "SMUX peering object ID\n"
        "SMUX peering password\n")
-{
-  return smux_peer_default ();
-}
 
 int
 config_write_smux (struct vty *vty)
@@ -1430,7 +1447,7 @@
   int first = 1;
   unsigned int i;
 
-  if (smux_oid != smux_default_oid || smux_passwd != smux_default_passwd)
+  if (smux_oid)
     {
       vty_out (vty, "smux peer ");
       for (i = 0; i < smux_oid_len; i++)
@@ -1478,18 +1495,8 @@
 
 /* Initialize some values then schedule first SMUX connection. */
 void
-smux_init (struct thread_master *tm, oid defoid[], size_t defoid_len)
+smux_init (struct thread_master *tm)
 {
-  /* Set default SMUX oid. */
-  smux_default_oid = defoid;
-  smux_default_oid_len = defoid_len;
-
-  smux_oid = smux_default_oid;
-  smux_oid_len = smux_default_oid_len;
-
-  /* be careful with smux_passwd, points to string constant by default */
-  smux_passwd = (char *)smux_default_passwd;
-
   /* copy callers thread master */
   master = tm;
   
@@ -1503,7 +1510,8 @@
   install_element (CONFIG_NODE, &smux_peer_cmd);
   install_element (CONFIG_NODE, &smux_peer_password_cmd);
   install_element (CONFIG_NODE, &no_smux_peer_cmd);
-  install_element (CONFIG_NODE, &no_smux_peer_password_cmd);
+  install_element (CONFIG_NODE, &no_smux_peer_oid_cmd);
+  install_element (CONFIG_NODE, &no_smux_peer_oid_password_cmd);
 }
 
 void
diff --git a/lib/smux.h b/lib/smux.h
index 975cf8b..dd44a31 100644
--- a/lib/smux.h
+++ b/lib/smux.h
@@ -144,7 +144,7 @@
     (u_char *) &snmp_in_addr_val \
   )
 
-void smux_init (struct thread_master *tm, oid [], size_t);
+void smux_init (struct thread_master *tm);
 void smux_start (void);
 void smux_register_mib(const char *, struct variable *, size_t, int, oid [], size_t);
 int smux_header_generic (struct variable *, oid [], size_t *, int, size_t *, 
diff --git a/ospf6d/ChangeLog b/ospf6d/ChangeLog
index 17da81d..5e16c70 100644
--- a/ospf6d/ChangeLog
+++ b/ospf6d/ChangeLog
@@ -1,3 +1,8 @@
+2004-10-12 Hasso Tepper <hasso at quagga.net>
+
+	* ospf6_snmp.c: Remove defaults used to initialize smux connection to
+	  snmpd. Connection is initialized only if smux peer is configured.
+
 2004-10-11 Hasso Tepper <hasso at quagga.net>
 
 	* osp6_top.c, ospf6_top.h: Better handling for router-id. If we use
diff --git a/ospf6d/ospf6_snmp.c b/ospf6d/ospf6_snmp.c
index 98a7f5a..edc8bc4 100644
--- a/ospf6d/ospf6_snmp.c
+++ b/ospf6d/ospf6_snmp.c
@@ -50,9 +50,6 @@
 /* OSPFv3-MIB */
 #define OSPFv3MIB 1,3,6,1,3,102
 
-/* Zebra enterprise ospf6d MIB */
-#define OSPF6DOID 1,3,6,1,4,1,3317,1,2,6
-
 /* OSPFv3 MIB General Group values. */
 #define OSPFv3ROUTERID                   1
 #define OSPFv3ADMINSTAT                  2
@@ -101,7 +98,6 @@
 
 /* OSPFv3-MIB instances. */
 oid ospfv3_oid [] = { OSPFv3MIB };
-oid ospf6d_oid [] = { OSPF6DOID };
 
 /* empty ID 0.0.0.0 e.g. empty router-id */
 static struct in_addr ospf6_empty_id = {0};
@@ -295,9 +291,8 @@
 void
 ospf6_snmp_init (struct thread_master *master)
 {
-  smux_init (master, ospf6d_oid, sizeof (ospf6d_oid) / sizeof (oid));
+  smux_init (master);
   REGISTER_MIB ("OSPFv3MIB", ospfv3_variables, variable, ospfv3_oid);
-  smux_start ();
 }
 
 #endif /* HAVE_SNMP */
diff --git a/ospfd/ChangeLog b/ospfd/ChangeLog
index 10d2658..914ed93 100644
--- a/ospfd/ChangeLog
+++ b/ospfd/ChangeLog
@@ -1,6 +1,8 @@
 2004-10-13 Hasso Tepper <hasso at quagga.net>
 
 	* ospf_main.c: Unbreak compilation with ospfapi disabled.
+	* ospf_snmp.c: Remove defaults used to initialize smux connection to
+	  snmpd. Connection is initialized only if smux peer is configured.
 
 2004-10-12 Hasso Tepper <hasso at quagga.net>
 
diff --git a/ospfd/ospf_snmp.c b/ospfd/ospf_snmp.c
index ccb6498..db0aaf6 100644
--- a/ospfd/ospf_snmp.c
+++ b/ospfd/ospf_snmp.c
@@ -52,10 +52,6 @@
 /* OSPF2-MIB. */
 #define OSPF2MIB 1,3,6,1,2,1,14
 
-/* Zebra enterprise OSPF MIB.  This variable is used for register
-   OSPF MIB to SNMP agent under SMUX protocol.  */
-#define OSPFDOID 1,3,6,1,4,1,3317,1,2,5
-
 /* OSPF MIB General Group values. */
 #define OSPFROUTERID                     1
 #define OSPFADMINSTAT                    2
@@ -214,7 +210,6 @@
 
 /* OSPF-MIB instances. */
 oid ospf_oid [] = { OSPF2MIB };
-oid ospfd_oid [] = { OSPFDOID };
 
 /* IP address 0.0.0.0. */
 static struct in_addr ospf_empty_addr = {0};
@@ -2479,8 +2474,7 @@
 {
   ospf_snmp_iflist = list_new ();
   ospf_snmp_vl_table = route_table_init ();
-  smux_init (om->master, ospfd_oid, sizeof (ospfd_oid) / sizeof (oid));
+  smux_init (om->master);
   REGISTER_MIB("mibII/ospf", ospf_variables, variable, ospf_oid);
-  smux_start ();
 }
 #endif /* HAVE_SNMP */
diff --git a/ripd/ChangeLog b/ripd/ChangeLog
index 8327abf..ee878ff 100644
--- a/ripd/ChangeLog
+++ b/ripd/ChangeLog
@@ -1,3 +1,8 @@
+2004-10-13 Hasso Tepper <hasso at quagga.net>
+
+	* ripd_snmp.c: Remove defaults used to initialize smux connection to
+	  snmpd. Connection is initialized only if smux peer is configured.
+
 2004-10-11 Hasso Tepper <hasso at quagga.net>
 
 	* *.c: Make more strings const.
diff --git a/ripd/rip_snmp.c b/ripd/rip_snmp.c
index 72f0ff2..93773bc 100644
--- a/ripd/rip_snmp.c
+++ b/ripd/rip_snmp.c
@@ -41,10 +41,6 @@
 /* RIPv2-MIB. */
 #define RIPV2MIB 1,3,6,1,2,1,23
 
-/* Zebra enterprise RIP MIB.  This variable is used for register
-   RIPv2-MIB to SNMP agent under SMUX protocol.  */
-#define RIPDOID 1,3,6,1,4,1,3317,1,2,3
-
 /* RIPv2-MIB rip2Globals values. */
 #define RIP2GLOBALROUTECHANGES  1
 #define RIP2GLOBALQUERIES       2
@@ -90,7 +86,6 @@
 
 /* RIP-MIB instances. */
 oid rip_oid [] = { RIPV2MIB };
-oid ripd_oid [] = { RIPDOID };
 
 /* Interface cache table sorted by interface's address. */
 struct route_table *rip_ifaddr_table;
@@ -575,8 +570,7 @@
 {
   rip_ifaddr_table = route_table_init ();
 
-  smux_init (master, ripd_oid, sizeof (ripd_oid) / sizeof (oid));
+  smux_init (master);
   REGISTER_MIB("mibII/rip", rip_variables, variable, rip_oid);
-  smux_start ();
 }
 #endif /* HAVE_SNMP */
diff --git a/zebra/ChangeLog b/zebra/ChangeLog
index fad80a1..081cffe 100644
--- a/zebra/ChangeLog
+++ b/zebra/ChangeLog
@@ -1,3 +1,8 @@
+2004-10-13 Hasso Tepper <hasso at quagga.net>
+
+	* zebra_snmp.c: Remove defaults used to initialize smux connection to
+	  snmpd. Connection is initialized only if smux peer is configured.
+
 2004-10-12 Hasso Tepper <hasso at quagga.net>
 
 	* zebra_vty.c: Unbreak "show ip route" command help and make it work
diff --git a/zebra/zebra_snmp.c b/zebra/zebra_snmp.c
index dece89e..4536026 100644
--- a/zebra/zebra_snmp.c
+++ b/zebra/zebra_snmp.c
@@ -40,7 +40,6 @@
 #include "zebra/zserv.h"
 
 #define IPFWMIB 1,3,6,1,2,1,4,24
-#define ZEBRAOID 1,3,6,1,4,1,3317,1,2,1
 
 /* ipForwardTable */
 #define IPFORWARDDEST                         1
@@ -87,7 +86,6 @@
 extern struct zebra_t zebrad;
 
 oid ipfw_oid [] = { IPFWMIB };
-oid zebra_oid [] = { ZEBRAOID };
 
 /* Hook functions. */
 u_char * ipFwNumber ();
@@ -564,8 +562,7 @@
 void
 zebra_snmp_init ()
 {
-  smux_init (zebrad.master, zebra_oid, sizeof (zebra_oid) / sizeof (oid));
+  smux_init (zebrad.master);
   REGISTER_MIB("mibII/ipforward", zebra_variables, variable, ipfw_oid);
-  smux_start ();
 }
 #endif /* HAVE_SNMP */