[quagga-dev 13165] [PATCH 1/2] lib: zclient.c remove extern struct thread_master *

Donald Sharp sharpd at cumulusnetworks.com
Thu Sep 24 14:25:19 BST 2015


zclient.c depended upon link time inclusion of a
extern struct thread_master *master.  This is a violation of the
namespace of the calling daemon.  If a library needs the pointer
pass it in and save it for future use.

This code change also makes the zclient code consistent with
the other lib functions that need to schedule work on your behalf

Signed-off-by: Donald Sharp <sharpd at cumulusnetworks.com>
---
 bgpd/bgp_nexthop.c     |  2 +-
 bgpd/bgp_zebra.c       |  4 ++--
 bgpd/bgp_zebra.h       |  2 +-
 bgpd/bgpd.c            |  2 +-
 isisd/isis_main.c      |  2 +-
 isisd/isis_zebra.c     |  4 ++--
 isisd/isis_zebra.h     |  2 +-
 lib/zclient.c          | 19 +++++++++----------
 lib/zclient.h          |  5 ++++-
 ospf6d/ospf6_zebra.c   |  4 ++--
 ospf6d/ospf6_zebra.h   |  2 +-
 ospf6d/ospf6d.c        |  2 +-
 ospfd/ospf_main.c      |  2 +-
 ospfd/ospf_zebra.c     |  4 ++--
 ospfd/ospf_zebra.h     |  2 +-
 pimd/pim_main.c        |  2 +-
 pimd/pim_zebra.c       |  4 ++--
 pimd/pim_zebra.h       |  2 +-
 pimd/pim_zlookup.c     |  2 +-
 ripd/rip_main.c        |  2 +-
 ripd/rip_zebra.c       |  4 ++--
 ripd/ripd.h            |  2 +-
 ripngd/ripng_main.c    |  2 +-
 ripngd/ripng_zebra.c   |  4 ++--
 ripngd/ripngd.h        |  2 +-
 tests/bgp_mpath_test.c |  2 +-
 zebra/client_main.c    |  4 +++-
 27 files changed, 47 insertions(+), 43 deletions(-)

diff --git a/bgpd/bgp_nexthop.c b/bgpd/bgp_nexthop.c
index 7336793..e7768a3 100644
--- a/bgpd/bgp_nexthop.c
+++ b/bgpd/bgp_nexthop.c
@@ -1434,7 +1434,7 @@ bgp_config_write_scan_time (struct vty *vty)
 void
 bgp_scan_init (void)
 {
-  zlookup = zclient_new ();
+  zlookup = zclient_new (master);
   zlookup->sock = -1;
   zlookup->t_connect = thread_add_event (master, zlookup_connect, zlookup, 0);
 
diff --git a/bgpd/bgp_zebra.c b/bgpd/bgp_zebra.c
index 2616351..e534bee 100644
--- a/bgpd/bgp_zebra.c
+++ b/bgpd/bgp_zebra.c
@@ -1094,10 +1094,10 @@ bgp_zebra_connected (struct zclient *zclient)
 }
 
 void
-bgp_zebra_init (void)
+bgp_zebra_init (struct thread_master *master)
 {
   /* Set default values. */
-  zclient = zclient_new ();
+  zclient = zclient_new (master);
   zclient_init (zclient, ZEBRA_ROUTE_BGP);
   zclient->zebra_connected = bgp_zebra_connected;
   zclient->router_id_update = bgp_router_id_update;
diff --git a/bgpd/bgp_zebra.h b/bgpd/bgp_zebra.h
index 8099193..50f727d 100644
--- a/bgpd/bgp_zebra.h
+++ b/bgpd/bgp_zebra.h
@@ -25,7 +25,7 @@ Boston, MA 02111-1307, USA.  */
 
 extern struct stream *bgp_nexthop_buf;
 
-extern void bgp_zebra_init (void);
+extern void bgp_zebra_init (struct thread_master *master);
 extern int bgp_if_update_all (void);
 extern int bgp_config_write_maxpaths (struct vty *, struct bgp *, afi_t,
 				      safi_t, int *);
diff --git a/bgpd/bgpd.c b/bgpd/bgpd.c
index 7a0274c..10c3c10 100644
--- a/bgpd/bgpd.c
+++ b/bgpd/bgpd.c
@@ -5427,7 +5427,7 @@ bgp_init (void)
   bgp_vty_init ();
 
   /* Init zebra. */
-  bgp_zebra_init ();
+  bgp_zebra_init (master);
 
   /* BGP inits. */
   bgp_attr_init ();
diff --git a/isisd/isis_main.c b/isisd/isis_main.c
index e1af71f..fba7b10 100644
--- a/isisd/isis_main.c
+++ b/isisd/isis_main.c
@@ -339,7 +339,7 @@ main (int argc, char **argv, char **envp)
   /* create the global 'isis' instance */
   isis_new (1);
 
-  isis_zebra_init ();
+  isis_zebra_init (master);
 
   /* parse config file */
   /* this is needed three times! because we have interfaces before the areas */
diff --git a/isisd/isis_zebra.c b/isisd/isis_zebra.c
index 6d0c157..8a78417 100644
--- a/isisd/isis_zebra.c
+++ b/isisd/isis_zebra.c
@@ -602,9 +602,9 @@ isis_zebra_connected (struct zclient *zclient)
 }
 
 void
-isis_zebra_init ()
+isis_zebra_init (struct thread_master *master)
 {
-  zclient = zclient_new ();
+  zclient = zclient_new (master);
   zclient_init (zclient, ZEBRA_ROUTE_ISIS);
   zclient->zebra_connected = isis_zebra_connected;
   zclient->router_id_update = isis_router_id_update_zebra;
diff --git a/isisd/isis_zebra.h b/isisd/isis_zebra.h
index 889cd9b..0011478 100644
--- a/isisd/isis_zebra.h
+++ b/isisd/isis_zebra.h
@@ -24,7 +24,7 @@
 
 extern struct zclient *zclient;
 
-void isis_zebra_init (void);
+void isis_zebra_init (struct thread_master *);
 void isis_zebra_route_update (struct prefix *prefix,
 			      struct isis_route_info *route_info);
 int isis_distribute_list_update (int routetype);
diff --git a/lib/zclient.c b/lib/zclient.c
index 8e443e2..ed7f9e7 100644
--- a/lib/zclient.c
+++ b/lib/zclient.c
@@ -39,8 +39,6 @@ enum event {ZCLIENT_SCHEDULE, ZCLIENT_READ, ZCLIENT_CONNECT};
 /* Prototype for event manager. */
 static void zclient_event (enum event, struct zclient *);
 
-extern struct thread_master *master;
-
 const char *zclient_serv_path = NULL;
 
 /* This file local debug flag. */
@@ -48,7 +46,7 @@ int zclient_debug = 0;
 
 /* Allocate zclient structure. */
 struct zclient *
-zclient_new ()
+zclient_new (struct thread_master *master)
 {
   struct zclient *zclient;
   zclient = XCALLOC (MTYPE_ZCLIENT, sizeof (struct zclient));
@@ -56,6 +54,7 @@ zclient_new ()
   zclient->ibuf = stream_new (ZEBRA_MAX_PACKET_SIZ);
   zclient->obuf = stream_new (ZEBRA_MAX_PACKET_SIZ);
   zclient->wb = buffer_new(0);
+  zclient->master = master;
 
   return zclient;
 }
@@ -258,8 +257,8 @@ zclient_flush_data(struct thread *thread)
       return zclient_failed(zclient);
       break;
     case BUFFER_PENDING:
-      zclient->t_write = thread_add_write(master, zclient_flush_data,
-					  zclient, zclient->sock);
+      zclient->t_write = thread_add_write (zclient->master, zclient_flush_data,
+					   zclient, zclient->sock);
       break;
     case BUFFER_EMPTY:
       break;
@@ -284,8 +283,8 @@ zclient_send_message(struct zclient *zclient)
       THREAD_OFF(zclient->t_write);
       break;
     case BUFFER_PENDING:
-      THREAD_WRITE_ON(master, zclient->t_write,
-		      zclient_flush_data, zclient, zclient->sock);
+      THREAD_WRITE_ON (zclient->master, zclient->t_write,
+		       zclient_flush_data, zclient, zclient->sock);
       break;
     }
   return 0;
@@ -1066,7 +1065,7 @@ zclient_event (enum event event, struct zclient *zclient)
     case ZCLIENT_SCHEDULE:
       if (! zclient->t_connect)
 	zclient->t_connect =
-	  thread_add_event (master, zclient_connect, zclient, 0);
+	  thread_add_event (zclient->master, zclient_connect, zclient, 0);
       break;
     case ZCLIENT_CONNECT:
       if (zclient->fail >= 10)
@@ -1076,12 +1075,12 @@ zclient_event (enum event event, struct zclient *zclient)
 		   zclient->fail < 3 ? 10 : 60);
       if (! zclient->t_connect)
 	zclient->t_connect = 
-	  thread_add_timer (master, zclient_connect, zclient,
+	  thread_add_timer (zclient->master, zclient_connect, zclient,
 			    zclient->fail < 3 ? 10 : 60);
       break;
     case ZCLIENT_READ:
       zclient->t_read = 
-	thread_add_read (master, zclient_read, zclient, zclient->sock);
+	thread_add_read (zclient->master, zclient_read, zclient, zclient->sock);
       break;
     }
 }
diff --git a/lib/zclient.h b/lib/zclient.h
index 19b4f0e..4aaed13 100644
--- a/lib/zclient.h
+++ b/lib/zclient.h
@@ -40,6 +40,9 @@
 /* Structure for the zebra client. */
 struct zclient
 {
+  /* The thread master we schedule ourselves on */
+  struct thread_master *master;
+
   /* Socket to zebra daemon. */
   int sock;
 
@@ -132,7 +135,7 @@ struct zapi_ipv4
 };
 
 /* Prototypes of zebra client service functions. */
-extern struct zclient *zclient_new (void);
+extern struct zclient *zclient_new (struct thread_master *);
 extern void zclient_init (struct zclient *, int);
 extern int zclient_start (struct zclient *);
 extern void zclient_stop (struct zclient *);
diff --git a/ospf6d/ospf6_zebra.c b/ospf6d/ospf6_zebra.c
index 951e11d..d37e508 100644
--- a/ospf6d/ospf6_zebra.c
+++ b/ospf6d/ospf6_zebra.c
@@ -578,10 +578,10 @@ ospf6_zebra_connected (struct zclient *zclient)
 }
 
 void
-ospf6_zebra_init (void)
+ospf6_zebra_init (struct thread_master *master)
 {
   /* Allocate zebra structure. */
-  zclient = zclient_new ();
+  zclient = zclient_new (master);
   zclient_init (zclient, ZEBRA_ROUTE_OSPF6);
   zclient->zebra_connected = ospf6_zebra_connected;
   zclient->router_id_update = ospf6_router_id_update_zebra;
diff --git a/ospf6d/ospf6_zebra.h b/ospf6d/ospf6_zebra.h
index a219450..05694d3 100644
--- a/ospf6d/ospf6_zebra.h
+++ b/ospf6d/ospf6_zebra.h
@@ -44,7 +44,7 @@ extern void ospf6_zebra_redistribute (int);
 extern void ospf6_zebra_no_redistribute (int);
 #define ospf6_zebra_is_redistribute(type) \
     vrf_bitmap_check (zclient->redist[type], VRF_DEFAULT)
-extern void ospf6_zebra_init (void);
+extern void ospf6_zebra_init(struct thread_master *);
 
 extern int config_write_ospf6_debug_zebra (struct vty *vty);
 extern void install_element_ospf6_debug_zebra (void);
diff --git a/ospf6d/ospf6d.c b/ospf6d/ospf6d.c
index 3cdd5c1..c2baa31 100644
--- a/ospf6d/ospf6d.c
+++ b/ospf6d/ospf6d.c
@@ -1764,7 +1764,7 @@ ospf6_init (void)
   ospf6_area_init ();
   ospf6_interface_init ();
   ospf6_neighbor_init ();
-  ospf6_zebra_init ();
+  ospf6_zebra_init (master);
 
   ospf6_lsa_init ();
   ospf6_spf_init ();
diff --git a/ospfd/ospf_main.c b/ospfd/ospf_main.c
index 826fc98..10565fe 100644
--- a/ospfd/ospf_main.c
+++ b/ospfd/ospf_main.c
@@ -298,7 +298,7 @@ main (int argc, char **argv)
 
   /* OSPFd inits. */
   ospf_if_init ();
-  ospf_zebra_init ();
+  ospf_zebra_init (master);
 
   /* OSPF vty inits. */
   ospf_vty_init ();
diff --git a/ospfd/ospf_zebra.c b/ospfd/ospf_zebra.c
index 2704100..cbc7c5d 100644
--- a/ospfd/ospf_zebra.c
+++ b/ospfd/ospf_zebra.c
@@ -1306,10 +1306,10 @@ ospf_zebra_connected (struct zclient *zclient)
 }
 
 void
-ospf_zebra_init ()
+ospf_zebra_init (struct thread_master *master)
 {
   /* Allocate zebra structure. */
-  zclient = zclient_new ();
+  zclient = zclient_new (master);
   zclient_init (zclient, ZEBRA_ROUTE_OSPF);
   zclient->zebra_connected = ospf_zebra_connected;
   zclient->router_id_update = ospf_router_id_update_zebra;
diff --git a/ospfd/ospf_zebra.h b/ospfd/ospf_zebra.h
index 148f652..32a0271 100644
--- a/ospfd/ospf_zebra.h
+++ b/ospfd/ospf_zebra.h
@@ -72,7 +72,7 @@ extern int ospf_distance_set (struct vty *, struct ospf *, const char *,
 			      const char *, const char *);
 extern int ospf_distance_unset (struct vty *, struct ospf *, const char *,
 				const char *, const char *);
-extern void ospf_zebra_init (void);
+extern void ospf_zebra_init (struct thread_master *);
 
 #endif /* _ZEBRA_OSPF_ZEBRA_H */
 
diff --git a/pimd/pim_main.c b/pimd/pim_main.c
index 63dd636..adbfe18 100644
--- a/pimd/pim_main.c
+++ b/pimd/pim_main.c
@@ -221,7 +221,7 @@ int main(int argc, char** argv, char** envp) {
   /*
     Initialize zclient "update" and "lookup" sockets
    */
-  pim_zebra_init(zebra_sock_path);
+  pim_zebra_init (master, zebra_sock_path);
 
   zlog_notice("Loading configuration - begin");
 
diff --git a/pimd/pim_zebra.c b/pimd/pim_zebra.c
index dfc871b..1a39271 100644
--- a/pimd/pim_zebra.c
+++ b/pimd/pim_zebra.c
@@ -655,7 +655,7 @@ static void pim_zebra_connected(struct zclient *zclient)
   zclient_send_requests(zclient, VRF_DEFAULT);
 }
 
-void pim_zebra_init(char *zebra_sock_path)
+void pim_zebra_init (struct thread_master *master, char *zebra_sock_path)
 {
   int i;
 
@@ -669,7 +669,7 @@ void pim_zebra_init(char *zebra_sock_path)
 #endif
 
   /* Socket for receiving updates from Zebra daemon */
-  qpim_zclient_update = zclient_new();
+  qpim_zclient_update = zclient_new (master);
 
   qpim_zclient_update->zebra_connected          = pim_zebra_connected;
   qpim_zclient_update->router_id_update         = pim_router_id_update_zebra;
diff --git a/pimd/pim_zebra.h b/pimd/pim_zebra.h
index d624c86..af5baef 100644
--- a/pimd/pim_zebra.h
+++ b/pimd/pim_zebra.h
@@ -26,7 +26,7 @@
 #include "pim_igmp.h"
 #include "pim_ifchannel.h"
 
-void pim_zebra_init(char *zebra_sock_path);
+void pim_zebra_init (struct thread_master *master, char *zebra_sock_path);
 
 void pim_scan_oil(void);
 
diff --git a/pimd/pim_zlookup.c b/pimd/pim_zlookup.c
index 6000367..52f640c 100644
--- a/pimd/pim_zlookup.c
+++ b/pimd/pim_zlookup.c
@@ -122,7 +122,7 @@ struct zclient *zclient_lookup_new()
 {
   struct zclient *zlookup;
 
-  zlookup = zclient_new();
+  zlookup = zclient_new (master);
   if (!zlookup) {
     zlog_err("%s: zclient_new() failure",
 	     __PRETTY_FUNCTION__);
diff --git a/ripd/rip_main.c b/ripd/rip_main.c
index 95b1f6d..4ead9b0 100644
--- a/ripd/rip_main.c
+++ b/ripd/rip_main.c
@@ -286,7 +286,7 @@ main (int argc, char **argv)
   /* RIP related initialization. */
   rip_init ();
   rip_if_init ();
-  rip_zclient_init ();
+  rip_zclient_init (master);
   rip_peer_init ();
 
   /* Get configuration file. */
diff --git a/ripd/rip_zebra.c b/ripd/rip_zebra.c
index de98162..0b6c22a 100644
--- a/ripd/rip_zebra.c
+++ b/ripd/rip_zebra.c
@@ -710,10 +710,10 @@ rip_zebra_connected (struct zclient *zclient)
 }
 
 void
-rip_zclient_init ()
+rip_zclient_init (struct thread_master *master)
 {
   /* Set default value to the zebra client structure. */
-  zclient = zclient_new ();
+  zclient = zclient_new (master);
   zclient_init (zclient, ZEBRA_ROUTE_RIP);
   zclient->zebra_connected = rip_zebra_connected;
   zclient->interface_add = rip_interface_add;
diff --git a/ripd/ripd.h b/ripd/ripd.h
index 4f40e79..a768ccc 100644
--- a/ripd/ripd.h
+++ b/ripd/ripd.h
@@ -389,7 +389,7 @@ extern void rip_if_down_all (void);
 extern void rip_route_map_init (void);
 extern void rip_route_map_reset (void);
 extern void rip_snmp_init (void);
-extern void rip_zclient_init (void);
+extern void rip_zclient_init (struct thread_master *);
 extern void rip_zclient_start (void);
 extern void rip_zclient_reset (void);
 extern void rip_offset_init (void);
diff --git a/ripngd/ripng_main.c b/ripngd/ripng_main.c
index d8f2241..1c184e2 100644
--- a/ripngd/ripng_main.c
+++ b/ripngd/ripng_main.c
@@ -281,7 +281,7 @@ main (int argc, char **argv)
 
   /* RIPngd inits. */
   ripng_init ();
-  zebra_init ();
+  zebra_init (master);
   ripng_peer_init ();
 
   /* Get configuration file. */
diff --git a/ripngd/ripng_zebra.c b/ripngd/ripng_zebra.c
index 58f8860..13b1853 100644
--- a/ripngd/ripng_zebra.c
+++ b/ripngd/ripng_zebra.c
@@ -541,10 +541,10 @@ ripng_zebra_connected (struct zclient *zclient)
 
 /* Initialize zebra structure and it's commands. */
 void
-zebra_init ()
+zebra_init (struct thread_master *master)
 {
   /* Allocate zebra structure. */
-  zclient = zclient_new ();
+  zclient = zclient_new (master);
   zclient_init (zclient, ZEBRA_ROUTE_RIPNG);
 
   zclient->zebra_connected = ripng_zebra_connected;
diff --git a/ripngd/ripngd.h b/ripngd/ripngd.h
index 28ca41b..6cbbd84 100644
--- a/ripngd/ripngd.h
+++ b/ripngd/ripngd.h
@@ -358,7 +358,7 @@ extern void ripng_route_map_init (void);
 extern void ripng_route_map_reset (void);
 extern void ripng_terminate (void);
  /* zclient_init() is done by ripng_zebra.c:zebra_init() */
-extern void zebra_init (void);
+extern void zebra_init (struct thread_master *);
 extern void ripng_zclient_start (void);
 extern void ripng_zclient_reset (void);
 extern void ripng_offset_init (void);
diff --git a/tests/bgp_mpath_test.c b/tests/bgp_mpath_test.c
index 3594753..ed54d9c 100644
--- a/tests/bgp_mpath_test.c
+++ b/tests/bgp_mpath_test.c
@@ -376,7 +376,7 @@ static int
 global_test_init (void)
 {
   master = thread_master_create ();
-  zclient = zclient_new ();
+  zclient = zclient_new (master);
   bgp_master_init ();
   bgp_option_set (BGP_OPT_NO_LISTEN);
   
diff --git a/zebra/client_main.c b/zebra/client_main.c
index 06afc56..43ab299 100644
--- a/zebra/client_main.c
+++ b/zebra/client_main.c
@@ -193,13 +193,15 @@ zebra_sim (FILE *fp)
 int
 main (int argc, char **argv)
 {
+  struct thread_master *master;
   FILE *fp;
 
   if (argc == 1)
       usage_exit ();
 
+  master = thread_master_create ();
   /* Establish connection to zebra. */
-  zclient = zclient_new ();
+  zclient = zclient_new (master);
   zclient->enable = 1;
 #ifdef HAVE_TCP_ZEBRA
   zclient->sock = zclient_socket ();
-- 
1.9.1





More information about the Quagga-dev mailing list