summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--bgpd/bgp_main.c2
-rw-r--r--lib/command.c5
-rw-r--r--lib/vty.c10
-rw-r--r--lib/vty.h4
-rw-r--r--ospf6d/ospf6_main.c2
-rw-r--r--ospfd/ospf_main.c2
-rw-r--r--ripd/rip_main.c2
-rw-r--r--ripngd/ripng_main.c2
-rw-r--r--zebra/main.c13
-rw-r--r--zebra/redistribute.c21
-rw-r--r--zebra/rt_netlink.c10
-rw-r--r--zebra/rtadv.c12
-rw-r--r--zebra/zebra_rib.c4
-rw-r--r--zebra/zserv.c37
-rw-r--r--zebra/zserv.h12
15 files changed, 78 insertions, 60 deletions
diff --git a/bgpd/bgp_main.c b/bgpd/bgp_main.c
index 3e1d80f6..933ca571 100644
--- a/bgpd/bgp_main.c
+++ b/bgpd/bgp_main.c
@@ -282,7 +282,7 @@ main (int argc, char **argv)
signal_init ();
zprivs_init (&bgpd_privs);
cmd_init (1);
- vty_init ();
+ vty_init (master);
memory_init ();
/* BGP related initialization. */
diff --git a/lib/command.c b/lib/command.c
index 5d429338..ade413bb 100644
--- a/lib/command.c
+++ b/lib/command.c
@@ -20,11 +20,14 @@ Boston, MA 02111-1307, USA. */
#include <zebra.h>
-#include "command.h"
+
#include "memory.h"
#include "log.h"
#include "version.h"
#include "thread.h"
+#include "vector.h"
+#include "vty.h"
+#include "command.h"
/* Command vector which includes some level of command lists. Normally
each daemon maintains each own cmdvec. */
diff --git a/lib/vty.c b/lib/vty.c
index 4d6eb304..c38ae946 100644
--- a/lib/vty.c
+++ b/lib/vty.c
@@ -23,16 +23,17 @@
#include <zebra.h>
#include "linklist.h"
+#include "thread.h"
#include "buffer.h"
#include "version.h"
#include "command.h"
#include "sockunion.h"
-#include "thread.h"
#include "memory.h"
#include "str.h"
#include "log.h"
#include "prefix.h"
#include "filter.h"
+#include "vty.h"
#include "privs.h"
/* Vty events */
@@ -2342,8 +2343,7 @@ vty_config_unlock (struct vty *vty)
}
/* Master of the threads. */
-extern struct thread_master *master;
-/* struct thread_master *master; */
+static struct thread_master *master;
static void
vty_event (enum event event, int sock, struct vty *vty)
@@ -2791,13 +2791,15 @@ vty_init_vtysh ()
/* Install vty's own commands like `who' command. */
void
-vty_init ()
+vty_init (struct thread_master *master_thread)
{
/* For further configuration read, preserve current directory. */
vty_save_cwd ();
vtyvec = vector_init (VECTOR_MIN_SIZE);
+ master = master_thread;
+
/* Initilize server thread vector. */
Vvty_serv_thread = vector_init (VECTOR_MIN_SIZE);
diff --git a/lib/vty.h b/lib/vty.h
index 4d2a6a03..aaf8a5b1 100644
--- a/lib/vty.h
+++ b/lib/vty.h
@@ -21,6 +21,8 @@ Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
#ifndef _ZEBRA_VTY_H
#define _ZEBRA_VTY_H
+#include "thread.h"
+
#define VTY_BUFSIZ 512
#define VTY_MAXHIST 20
@@ -184,7 +186,7 @@ struct vty
extern char integrate_default[];
/* Prototypes. */
-void vty_init (void);
+void vty_init (struct thread_master *);
void vty_init_vtysh (void);
void vty_reset (void);
void vty_finish (void);
diff --git a/ospf6d/ospf6_main.c b/ospf6d/ospf6_main.c
index e6cd6aaa..519cde77 100644
--- a/ospf6d/ospf6_main.c
+++ b/ospf6d/ospf6_main.c
@@ -317,7 +317,7 @@ main (int argc, char *argv[], char *envp[])
zprivs_init (&ospf6d_privs);
signal_init ();
cmd_init (1);
- vty_init ();
+ vty_init (master);
ospf6_init ();
memory_init ();
sort_node ();
diff --git a/ospfd/ospf_main.c b/ospfd/ospf_main.c
index b1d1fd4c..236d8c28 100644
--- a/ospfd/ospf_main.c
+++ b/ospfd/ospf_main.c
@@ -288,7 +288,7 @@ main (int argc, char **argv)
signal_init ();
cmd_init (1);
debug_init ();
- vty_init ();
+ vty_init (master);
memory_init ();
access_list_init ();
diff --git a/ripd/rip_main.c b/ripd/rip_main.c
index 9526d7ae..84ea75c5 100644
--- a/ripd/rip_main.c
+++ b/ripd/rip_main.c
@@ -270,7 +270,7 @@ main (int argc, char **argv)
zprivs_init (&ripd_privs);
signal_init ();
cmd_init (1);
- vty_init ();
+ vty_init (master);
memory_init ();
keychain_init ();
diff --git a/ripngd/ripng_main.c b/ripngd/ripng_main.c
index bd1972a1..5fb04448 100644
--- a/ripngd/ripng_main.c
+++ b/ripngd/ripng_main.c
@@ -274,7 +274,7 @@ main (int argc, char **argv)
zprivs_init (&ripngd_privs);
signal_init ();
cmd_init (1);
- vty_init ();
+ vty_init (master);
memory_init ();
/* RIPngd inits. */
diff --git a/zebra/main.c b/zebra/main.c
index 85707f42..c47b83e3 100644
--- a/zebra/main.c
+++ b/zebra/main.c
@@ -36,8 +36,11 @@
#include "zebra/debug.h"
#include "zebra/rib.h"
-/* Master of threads. */
-struct thread_master *master;
+/* Zebra instance */
+struct zebra_t zebrad =
+{
+ .rtm_table_default = 0,
+};
/* process id. */
pid_t old_pid;
@@ -280,7 +283,7 @@ main (int argc, char **argv)
}
/* Make master thread emulator. */
- master = thread_master_create ();
+ zebrad.master = thread_master_create ();
/* privs initialise */
zprivs_init (&zserv_privs);
@@ -288,7 +291,7 @@ main (int argc, char **argv)
/* Vty related initialize. */
signal_init ();
cmd_init (1);
- vty_init ();
+ vty_init (zebrad.master);
memory_init ();
/* Zebra related initialize. */
@@ -345,7 +348,7 @@ main (int argc, char **argv)
/* Make vty server socket. */
vty_serv_sock (vty_addr, vty_port, ZEBRA_VTYSH_PATH);
- while (thread_fetch (master, &thread))
+ while (thread_fetch (zebrad.master, &thread))
thread_call (&thread);
/* Not reached... */
diff --git a/zebra/redistribute.c b/zebra/redistribute.c
index a3d4bad1..2d30f790 100644
--- a/zebra/redistribute.c
+++ b/zebra/redistribute.c
@@ -36,6 +36,9 @@
#include "zebra/redistribute.h"
#include "zebra/debug.h"
+/* master zebra server structure */
+extern struct zebra_t zebrad;
+
int
zebra_check_addr (struct prefix *p)
{
@@ -162,15 +165,13 @@ zebra_redistribute (struct zserv *client, int type)
#endif /* HAVE_IPV6 */
}
-extern list client_list;
-
void
redistribute_add (struct prefix *p, struct rib *rib)
{
listnode node;
struct zserv *client;
- for (node = listhead (client_list); node; nextnode (node))
+ for (node = listhead (zebrad.client_list); node; nextnode (node))
if ((client = getdata (node)) != NULL)
{
if (is_default (p))
@@ -207,7 +208,7 @@ redistribute_delete (struct prefix *p, struct rib *rib)
if (rib->distance == DISTANCE_INFINITY)
return;
- for (node = listhead (client_list); node; nextnode (node))
+ for (node = listhead (zebrad.client_list); node; nextnode (node))
if ((client = getdata (node)) != NULL)
{
if (is_default (p))
@@ -310,7 +311,7 @@ zebra_interface_up_update (struct interface *ifp)
if (IS_ZEBRA_DEBUG_EVENT)
zlog_info ("MESSAGE: ZEBRA_INTERFACE_UP %s", ifp->name);
- for (node = listhead (client_list); node; nextnode (node))
+ for (node = listhead (zebrad.client_list); node; nextnode (node))
if ((client = getdata (node)) != NULL)
zsend_interface_up (client, ifp);
}
@@ -325,7 +326,7 @@ zebra_interface_down_update (struct interface *ifp)
if (IS_ZEBRA_DEBUG_EVENT)
zlog_info ("MESSAGE: ZEBRA_INTERFACE_DOWN %s", ifp->name);
- for (node = listhead (client_list); node; nextnode (node))
+ for (node = listhead (zebrad.client_list); node; nextnode (node))
if ((client = getdata (node)) != NULL)
zsend_interface_down (client, ifp);
}
@@ -340,7 +341,7 @@ zebra_interface_add_update (struct interface *ifp)
if (IS_ZEBRA_DEBUG_EVENT)
zlog_info ("MESSAGE: ZEBRA_INTERFACE_ADD %s", ifp->name);
- for (node = listhead (client_list); node; nextnode (node))
+ for (node = listhead (zebrad.client_list); node; nextnode (node))
if ((client = getdata (node)) != NULL)
if (client->ifinfo)
zsend_interface_add (client, ifp);
@@ -355,7 +356,7 @@ zebra_interface_delete_update (struct interface *ifp)
if (IS_ZEBRA_DEBUG_EVENT)
zlog_info ("MESSAGE: ZEBRA_INTERFACE_DELETE %s", ifp->name);
- for (node = listhead (client_list); node; nextnode (node))
+ for (node = listhead (zebrad.client_list); node; nextnode (node))
if ((client = getdata (node)) != NULL)
if (client->ifinfo)
zsend_interface_delete (client, ifp);
@@ -379,7 +380,7 @@ zebra_interface_address_add_update (struct interface *ifp,
p->prefixlen, ifc->ifp->name);
}
- for (node = listhead (client_list); node; nextnode (node))
+ for (node = listhead (zebrad.client_list); node; nextnode (node))
if ((client = getdata (node)) != NULL)
if (client->ifinfo && CHECK_FLAG (ifc->conf, ZEBRA_IFC_REAL))
zsend_interface_address_add (client, ifp, ifc);
@@ -403,7 +404,7 @@ zebra_interface_address_delete_update (struct interface *ifp,
p->prefixlen, ifc->ifp->name);
}
- for (node = listhead (client_list); node; nextnode (node))
+ for (node = listhead (zebrad.client_list); node; nextnode (node))
if ((client = getdata (node)) != NULL)
if (client->ifinfo && CHECK_FLAG (ifc->conf, ZEBRA_IFC_REAL))
zsend_interface_address_delete (client, ifp, ifc);
diff --git a/zebra/rt_netlink.c b/zebra/rt_netlink.c
index e1514623..6a3df192 100644
--- a/zebra/rt_netlink.c
+++ b/zebra/rt_netlink.c
@@ -66,7 +66,7 @@ struct message nlmsg_str[] =
{0, NULL}
};
-extern int rtm_table_default;
+extern struct zebra_t zebrad;
extern struct zebra_privs_t zserv_privs;
@@ -615,7 +615,7 @@ netlink_routing_table (struct sockaddr_nl *snl, struct nlmsghdr *h)
table = rtm->rtm_table;
#if 0 /* we weed them out later in rib_weed_tables () */
- if (table != RT_TABLE_MAIN && table != rtm_table_default)
+ if (table != RT_TABLE_MAIN && table != zebrad.rtm_table_default)
return 0;
#endif
@@ -734,7 +734,7 @@ netlink_route_change (struct sockaddr_nl *snl, struct nlmsghdr *h)
}
table = rtm->rtm_table;
- if (table != RT_TABLE_MAIN && table != rtm_table_default)
+ if (table != RT_TABLE_MAIN && table != zebrad.rtm_table_default)
{
return 0;
}
@@ -1600,7 +1600,7 @@ kernel_read (struct thread *thread)
sock = THREAD_FD (thread);
ret = netlink_parse_info (netlink_information_fetch, &netlink);
- thread_add_read (master, kernel_read, NULL, netlink.sock);
+ thread_add_read (zebrad.master, kernel_read, NULL, netlink.sock);
return 0;
}
@@ -1621,5 +1621,5 @@ kernel_init ()
/* Register kernel socket. */
if (netlink.sock > 0)
- thread_add_read (master, kernel_read, NULL, netlink.sock);
+ thread_add_read (zebrad.master, kernel_read, NULL, netlink.sock);
}
diff --git a/zebra/rtadv.c b/zebra/rtadv.c
index ab0d49f0..a6e2d920 100644
--- a/zebra/rtadv.c
+++ b/zebra/rtadv.c
@@ -34,6 +34,7 @@
#include "zebra/interface.h"
#include "zebra/rtadv.h"
#include "zebra/debug.h"
+#include "zebra/zserv.h"
extern struct zebra_privs_t zserv_privs;
@@ -50,6 +51,8 @@ extern struct zebra_privs_t zserv_privs;
#define ALLNODE "ff02::1"
#define ALLROUTER "ff02::2"
+extern struct zebra_t zebrad;
+
enum rtadv_event {RTADV_START, RTADV_STOP, RTADV_TIMER, RTADV_READ};
void rtadv_event (enum rtadv_event, int);
@@ -999,7 +1002,6 @@ rtadv_config_write (struct vty *vty, struct interface *ifp)
}
}
-extern struct thread_master *master;
void
rtadv_event (enum rtadv_event event, int val)
@@ -1008,9 +1010,9 @@ rtadv_event (enum rtadv_event event, int val)
{
case RTADV_START:
if (! rtadv->ra_read)
- rtadv->ra_read = thread_add_read (master, rtadv_read, NULL, val);
+ rtadv->ra_read = thread_add_read (zebrad.master, rtadv_read, NULL, val);
if (! rtadv->ra_timer)
- rtadv->ra_timer = thread_add_event (master, rtadv_timer, NULL, 0);
+ rtadv->ra_timer = thread_add_event (zebrad.master, rtadv_timer, NULL, 0);
break;
case RTADV_STOP:
if (rtadv->ra_timer)
@@ -1026,11 +1028,11 @@ rtadv_event (enum rtadv_event event, int val)
break;
case RTADV_TIMER:
if (! rtadv->ra_timer)
- rtadv->ra_timer = thread_add_timer (master, rtadv_timer, NULL, val);
+ rtadv->ra_timer = thread_add_timer (zebrad.master, rtadv_timer, NULL, val);
break;
case RTADV_READ:
if (! rtadv->ra_read)
- rtadv->ra_read = thread_add_read (master, rtadv_read, NULL, val);
+ rtadv->ra_read = thread_add_read (zebrad.master, rtadv_read, NULL, val);
break;
default:
break;
diff --git a/zebra/zebra_rib.c b/zebra/zebra_rib.c
index 4098db26..2209364c 100644
--- a/zebra/zebra_rib.c
+++ b/zebra/zebra_rib.c
@@ -37,7 +37,7 @@
#include "zebra/debug.h"
/* Default rtm_table for all clients */
-extern int rtm_table_default;
+extern struct zebra_t zebrad;
/* Each route type's string and default distance value. */
struct
@@ -2147,7 +2147,7 @@ rib_weed_table (struct route_table *table)
{
next = rib->next;
- if (rib->table != rtm_table_default &&
+ if (rib->table != zebrad.rtm_table_default &&
rib->table != RT_TABLE_MAIN)
{
rib_delnode (rn, rib);
diff --git a/zebra/zserv.c b/zebra/zserv.c
index 975574af..3ea1a168 100644
--- a/zebra/zserv.c
+++ b/zebra/zserv.c
@@ -43,17 +43,11 @@
/* Event list of zebra. */
enum event { ZEBRA_SERV, ZEBRA_READ, ZEBRA_WRITE };
-/* Zebra client list. */
-list client_list;
-
-/* Default rtm_table for all clients */
-int rtm_table_default = 0;
+extern struct zebra_t zebrad;
void zebra_event (enum event event, int sock, struct zserv *client);
extern struct zebra_privs_t zserv_privs;
-
-extern struct thread_master *master;
/* For logging of zebra meesages. */
char *zebra_command_str [] =
@@ -126,7 +120,8 @@ zebra_server_dequeue (struct thread *t)
}
if (FIFO_TOP (&message_queue))
- THREAD_WRITE_ON (master, t_write, zebra_server_dequeue, NULL, sock);
+ THREAD_WRITE_ON (zebrad.master, t_write, zebra_server_dequeue,
+ NULL, sock);
return 0;
}
@@ -146,7 +141,7 @@ zebra_server_enqueue (int sock, u_char *buf, unsigned long length,
FIFO_ADD (&message_queue, queue);
- THREAD_WRITE_ON (master, t_write, zebra_server_dequeue, NULL, sock);
+ THREAD_WRITE_ON (zebrad.master, t_write, zebra_server_dequeue, NULL, sock);
}
int
@@ -1422,7 +1417,7 @@ zebra_client_close (struct zserv *client)
thread_cancel (client->t_write);
/* Free client structure. */
- listnode_delete (client_list, client);
+ listnode_delete (zebrad.client_list, client);
XFREE (0, client);
}
@@ -1440,10 +1435,10 @@ zebra_client_create (int sock)
client->obuf = stream_new (ZEBRA_MAX_PACKET_SIZ);
/* Set table number. */
- client->rtm_table = rtm_table_default;
+ client->rtm_table = zebrad.rtm_table_default;
/* Add this client to linked list. */
- listnode_add (client_list, client);
+ listnode_add (zebrad.client_list, client);
/* Make new read thread. */
zebra_event (ZEBRA_READ, sock, client);
@@ -1726,8 +1721,6 @@ zebra_serv_un (char *path)
zebra_event (ZEBRA_SERV, sock, NULL);
}
-/* Zebra's event management function. */
-extern struct thread_master *master;
void
zebra_event (enum event event, int sock, struct zserv *client)
@@ -1735,11 +1728,11 @@ zebra_event (enum event event, int sock, struct zserv *client)
switch (event)
{
case ZEBRA_SERV:
- thread_add_read (master, zebra_accept, client, sock);
+ thread_add_read (zebrad.master, zebra_accept, client, sock);
break;
case ZEBRA_READ:
client->t_read =
- thread_add_read (master, zebra_client_read, client, sock);
+ thread_add_read (zebrad.master, zebra_client_read, client, sock);
break;
case ZEBRA_WRITE:
/**/
@@ -1754,7 +1747,7 @@ DEFUN (show_table,
SHOW_STR
"default routing table to use for all clients\n")
{
- vty_out (vty, "table %d%s", rtm_table_default,
+ vty_out (vty, "table %d%s", zebrad.rtm_table_default,
VTY_NEWLINE);
return CMD_SUCCESS;
}
@@ -1765,7 +1758,7 @@ DEFUN (config_table,
"Configure target kernel routing table\n"
"TABLE integer\n")
{
- rtm_table_default = strtol (argv[0], (char**)0, 10);
+ zebrad.rtm_table_default = strtol (argv[0], (char**)0, 10);
return CMD_SUCCESS;
}
@@ -1833,7 +1826,7 @@ DEFUN (show_zebra_client,
listnode node;
struct zserv *client;
- for (node = listhead (client_list); node; nextnode (node))
+ for (node = listhead (zebrad.client_list); node; nextnode (node))
{
client = getdata (node);
vty_out (vty, "Client fd %d%s", client->sock, VTY_NEWLINE);
@@ -1845,8 +1838,8 @@ DEFUN (show_zebra_client,
int
config_write_table (struct vty *vty)
{
- if (rtm_table_default)
- vty_out (vty, "table %d%s", rtm_table_default,
+ if (zebrad.rtm_table_default)
+ vty_out (vty, "table %d%s", zebrad.rtm_table_default,
VTY_NEWLINE);
return 0;
}
@@ -1958,7 +1951,7 @@ void
zebra_init ()
{
/* Client list init. */
- client_list = list_new ();
+ zebrad.client_list = list_new ();
/* Forwarding is on by default. */
ipforward_on ();
diff --git a/zebra/zserv.h b/zebra/zserv.h
index ec3c9f4b..42fb64c6 100644
--- a/zebra/zserv.h
+++ b/zebra/zserv.h
@@ -56,6 +56,18 @@ struct zserv
u_char ifinfo;
};
+/* Zebra instance */
+struct zebra_t
+{
+ /* Thread master */
+ struct thread_master *master;
+ list client_list;
+
+ /* default table */
+ int rtm_table_default;
+
+};
+
/* Count prefix size from mask length */
#define PSIZE(a) (((a) + 7) / (8))