Browse Source

lib: zclient.c remove extern struct thread_master *

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@cumulusnetworks.com>
Donald Sharp 4 years ago
parent
commit
7125293d65

+ 1 - 1
bgpd/bgp_nexthop.c

@@ -1402,7 +1402,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);
 

+ 2 - 2
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;

+ 1 - 1
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 *);

+ 1 - 1
bgpd/bgpd.c

@@ -5421,7 +5421,7 @@ bgp_init (void)
   bgp_vty_init ();
 
   /* Init zebra. */
-  bgp_zebra_init ();
+  bgp_zebra_init (master);
 
   /* BGP inits. */
   bgp_attr_init ();

+ 1 - 1
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 */

+ 2 - 2
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;

+ 1 - 1
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);

+ 9 - 10
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;
@@ -1092,7 +1091,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)
@@ -1102,12 +1101,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;
     }
 }

+ 4 - 1
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 *);

+ 2 - 2
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;

+ 1 - 1
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);

+ 1 - 1
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 ();

+ 1 - 1
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 ();

+ 2 - 2
ospfd/ospf_zebra.c

@@ -1304,10 +1304,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;

+ 1 - 1
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 */
 

+ 1 - 1
pimd/pim_main.c

@@ -205,7 +205,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");
 

+ 2 - 2
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;

+ 1 - 1
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);
 

+ 1 - 1
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__);

+ 1 - 1
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. */

+ 2 - 2
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;

+ 1 - 1
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);

+ 1 - 1
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. */

+ 2 - 2
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;

+ 1 - 1
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);

+ 1 - 1
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);
   

+ 3 - 1
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 ();