summaryrefslogtreecommitdiff
path: root/zebra
diff options
context:
space:
mode:
Diffstat (limited to 'zebra')
-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
7 files changed, 60 insertions, 49 deletions
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))