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>
This commit is contained in:
Donald Sharp 2015-09-23 13:26:56 -07:00
parent c006e89e9a
commit 4140ca4d15
25 changed files with 43 additions and 42 deletions

View 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);

View 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;

View 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 *);

View 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;

View 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 *);

View 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 ();

View 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 */

View 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;

View 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);

View 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;
}
}

View 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 *);

View 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;

View 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);

View 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 ();

View 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 ();

View 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;

View 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 */

View 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. */

View 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;

View 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);

View 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. */

View 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;

View 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);

View 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);

View 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 ();