]> git.proxmox.com Git - mirror_frr.git/commitdiff
lib: zclient.c remove extern struct thread_master *
authorDonald Sharp <sharpd@cumulusnetworks.com>
Wed, 23 Sep 2015 20:26:56 +0000 (13:26 -0700)
committerDonald Sharp <sharpd@cumulusnetworks.com>
Wed, 23 Sep 2015 20:26:56 +0000 (13:26 -0700)
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>
25 files changed:
babeld/babel_main.c
babeld/babel_zebra.c
babeld/babel_zebra.h
bgpd/bgp_zebra.c
bgpd/bgp_zebra.h
bgpd/bgpd.c
isisd/isis_main.c
isisd/isis_zebra.c
isisd/isis_zebra.h
lib/zclient.c
lib/zclient.h
ospf6d/ospf6_zebra.c
ospf6d/ospf6_zebra.h
ospf6d/ospf6d.c
ospfd/ospf_main.c
ospfd/ospf_zebra.c
ospfd/ospf_zebra.h
ripd/rip_main.c
ripd/rip_zebra.c
ripd/ripd.h
ripngd/ripng_main.c
ripngd/ripng_zebra.c
ripngd/ripngd.h
tests/bgp_mpath_test.c
zebra/client_main.c

index 0b3e549f3858ce44fb4dc5d2a5712a4ea135a56e..ff9d2ad80497ffb49e6bfdcfd18c87f122825e64 100644 (file)
@@ -275,7 +275,7 @@ babel_init(int argc, char **argv)
     babeld_quagga_init();
     /* init zebra client's structure and it's commands */
     /* this replace kernel_setup && kernel_setup_socket */
-    babelz_zebra_init ();
+    babelz_zebra_init(master);
 
     /* Get zebra configuration file. */
     zlog_set_level (NULL, ZLOG_DEST_STDOUT, ZLOG_DISABLED);
index c7236d3201ca45807114714a0df13cc1210d0d78..e107cca10097d7239f1a04c7c78f14dc1d3fb292 100644 (file)
@@ -48,9 +48,6 @@ THE SOFTWARE.
 #include "xroute.h"
 #include "util.h"
 
-void babelz_zebra_init(void);
-
-
 /* we must use a pointer because of zclient.c's functions (new, free). */
 struct zclient *zclient;
 static int zebra_config_write (struct vty *vty);
@@ -341,9 +338,9 @@ debug_babel_config_write (struct vty * vty)
 #endif /* NO_DEBUG */
 }
 
-void babelz_zebra_init(void)
+void babelz_zebra_init (struct thread_master *master)
 {
-    zclient = zclient_new();
+    zclient = zclient_new(master);
     zclient_init(zclient, ZEBRA_ROUTE_BABEL, 0);
 
     zclient->interface_add = babel_interface_add;
index 99601aa7ce07b61b0e8a283afd2f41139a0c6a70..9504faf4fe61a6f95292fc7c45c82acea8f60672 100644 (file)
@@ -43,7 +43,7 @@ THE SOFTWARE.
 
 extern struct zclient *zclient;
 
-void babelz_zebra_init(void);
+void babelz_zebra_init(struct thread_master *);
 void babel_zebra_close_connexion(void);
 extern int debug_babel_config_write (struct vty *);
 
index 120be0a4e9b2f990251d8c8c3d4b4fd34eeedda8..ee6b32244f2d57ed284503e4cfa291bfecf8559b 100644 (file)
@@ -1682,10 +1682,10 @@ bgp_zclient_reset (void)
 }
 
 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, 0);
   zclient->router_id_update = bgp_router_id_update;
   zclient->interface_add = bgp_interface_add;
index 93f8f229f8273c6059b7b8e8335290e74d625b94..81bd0fb42144dab3d9a0088372c94fec371530fa 100644 (file)
@@ -27,7 +27,7 @@ Boston, MA 02111-1307, USA.  */
 extern struct stream *bgp_nexthop_buf;
 extern struct stream *bgp_ifindices_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 *);
index 8340de54bd831337e31b5c811b5071502541cdc2..0136189ecd2981819d444c1b05b8f7642df31bec 100644 (file)
@@ -6889,7 +6889,7 @@ bgp_init (void)
   bgp_scan_init ();
 
   /* Init zebra. */
-  bgp_zebra_init ();
+  bgp_zebra_init(master);
 
   /* BGP VTY commands installation.  */
   bgp_vty_init ();
index f87314859d39b1cc0ab011fbf56a0130989a9dda..fa6552e643c554299d4ea43d146ba0dd78e693c2 100644 (file)
@@ -337,7 +337,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 */
index 5522b378e1994fb1ae1d9ca0bd3a8c4c9dc89f29..f4179e50e040d0815c97fd36ddac3b3c443880b2 100644 (file)
@@ -593,9 +593,9 @@ isis_redistribute_default_set (int routetype, int metric_type,
 #endif /* 0 */
 
 void
-isis_zebra_init ()
+isis_zebra_init (struct thread_master *master)
 {
-  zclient = zclient_new ();
+  zclient = zclient_new(master);
   zclient_init (zclient, ZEBRA_ROUTE_ISIS, 0);
   zclient->router_id_update = isis_router_id_update_zebra;
   zclient->interface_add = isis_zebra_if_add;
index 889cd9b62f80a7dca3a5d886624d6b0deef6e985..cf6a738a1e8e4e3abc57f744fd0b0447dcd63eb6 100644 (file)
@@ -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);
index 35b18cb959df0a365d9cb8ee2274f0b4e6b253fc..e071228cc3f3e101ab16776dc94e779dc527e34d 100644 (file)
@@ -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;
-
 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;
 }
@@ -289,7 +288,7 @@ 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->t_write = thread_add_write(zclient->master, zclient_flush_data,
                                          zclient, zclient->sock);
       break;
     case BUFFER_EMPTY:
@@ -315,7 +314,7 @@ zclient_send_message(struct zclient *zclient)
       THREAD_OFF(zclient->t_write);
       break;
     case BUFFER_PENDING:
-      THREAD_WRITE_ON(master, zclient->t_write,
+      THREAD_WRITE_ON(zclient->master, zclient->t_write,
                      zclient_flush_data, zclient, zclient->sock);
       break;
     }
@@ -1327,7 +1326,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)
@@ -1337,12 +1336,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;
     }
 }
index 6ed4fede46c10d0298ef378541a7e91c66e283a0..1fbb80da90fb51fb19d3b4043dab7568ec5e4459 100644 (file)
@@ -43,6 +43,9 @@ struct redist_proto
 /* Structure for the zebra client. */
 struct zclient
 {
+  /* The thread master we schedule ourselves on */
+  struct thread_master *master;
+
   /* Socket to zebra daemon. */
   int sock;
 
@@ -143,7 +146,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, u_short);
 extern int zclient_start (struct zclient *);
 extern void zclient_stop (struct zclient *);
index f77ebd7f19328f3d08a22a4656ddd0fdfc7a4e0e..a285714937e4afd9962c6c7fbb85ad7950e0447a 100644 (file)
@@ -635,10 +635,10 @@ DEFUN (no_redistribute_ospf6,
 }
 
 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, 0);
   zclient->router_id_update = ospf6_router_id_update_zebra;
   zclient->interface_add = ospf6_zebra_if_add;
index c2e92b67f2745fdcbb428154a85dd29e28f0e9d6..972b44d4a07114e8595ebae113c554761db21873 100644 (file)
@@ -43,7 +43,7 @@ extern void ospf6_zebra_route_update_remove (struct ospf6_route *request);
 extern void ospf6_zebra_redistribute (int);
 extern void ospf6_zebra_no_redistribute (int);
 #define ospf6_zebra_is_redistribute(type) (zclient->redist[AFI_IP6][type].enabled)
-extern void ospf6_zebra_init (void);
+extern void ospf6_zebra_init (struct thread_master *);
 extern void ospf6_zebra_add_discard (struct ospf6_route *request);
 extern void ospf6_zebra_delete_discard (struct ospf6_route *request);
 
index 98d4e1787d66ae675a1ba944094b37eab1f13f6e..a60c5b0821dda8367ea721253028d19cc0378a22 100644 (file)
@@ -1769,7 +1769,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 ();
index 77490b310a7f23a2e09a9e51928d472dc1a3bfbd..e1f5a9a9bb8c9eb462a70d78b6da1c25a7b27361 100644 (file)
@@ -306,7 +306,7 @@ main (int argc, char **argv)
 
   /* OSPFd inits. */
   ospf_if_init ();
-  ospf_zebra_init (instance);
+  ospf_zebra_init(master, instance);
 
   /* OSPF vty inits. */
   ospf_vty_init ();
index 2bc46ca8786abb942f732d1425fac67619e8678b..fff38a34a315c568e008fe9d6b3b0cc378d3805d 100644 (file)
@@ -1530,10 +1530,10 @@ ospf_distance_apply (struct prefix_ipv4 *p, struct ospf_route *or)
 }
 
 void
-ospf_zebra_init (u_short instance)
+ospf_zebra_init (struct thread_master *master, u_short instance)
 {
   /* Allocate zebra structure. */
-  zclient = zclient_new ();
+  zclient = zclient_new(master);
   zclient_init (zclient, ZEBRA_ROUTE_OSPF, instance);
   zclient->router_id_update = ospf_router_id_update_zebra;
   zclient->interface_add = ospf_interface_add;
index 1cebb3d6d295f181b6452a70882e3f2b9d65251d..7cfae417e3de87fd24c5a21bd6d149274752101c 100644 (file)
@@ -79,7 +79,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 (u_short);
+extern void ospf_zebra_init(struct thread_master *, u_short);
 
 #endif /* _ZEBRA_OSPF_ZEBRA_H */
 
index dbb9b46fe1ede9a964f9648ca9edda7a0764913b..0db5634840cf7bbdf8c6a6ebe2c510bc015f61d7 100644 (file)
@@ -284,7 +284,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. */
index 22514d5fe7ebba18435e8b9870f4fb5a20c790f8..e0092f5422aa9847180c50af0b2a933e614a382c 100644 (file)
@@ -670,10 +670,10 @@ static struct cmd_node zebra_node =
 };
 
 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, 0);
   zclient->interface_add = rip_interface_add;
   zclient->interface_delete = rip_interface_delete;
index 45b07b9cb6b486c0603eb90f893d3416b415b55e..fe1345c6f5645b3cca8967b43513c9f1cf80e526 100644 (file)
@@ -386,7 +386,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);
index 522c48272724504a3f039589e9c98212703d2720..01590d96d1b3958e23c8326c32db6962702c64ba 100644 (file)
@@ -279,7 +279,7 @@ main (int argc, char **argv)
 
   /* RIPngd inits. */
   ripng_init ();
-  zebra_init ();
+  zebra_init(master);
   ripng_peer_init ();
 
   /* Get configuration file. */
index 09dd3390f4ad8792d878251d263b8526daf5fcc1..278ca7671586dc575d2b58f4bcf43eba25b99e90 100644 (file)
@@ -502,10 +502,10 @@ static struct cmd_node zebra_node =
 
 /* 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, 0);
 
   zclient->interface_up = ripng_interface_up;
index ab06d81bfdeb350a6a6a5a9b49f3c0dfcde6887c..884f3ed9bb851a35540b4ce95008c7659f37b15a 100644 (file)
@@ -355,7 +355,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);
index aa20ae4069b794c12f1e51811b9ecdd33515c202..7053ad764288ea7bf4d1e860a5bcb47b2be130d4 100644 (file)
@@ -377,7 +377,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);
   
index 8b95907bc6c49bc7d4414d37dbe3fa19836ed003..cc69ef761b146c8dec77df851b83a87db26f7930 100644 (file)
@@ -192,13 +192,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 ();