signal_init ();
zprivs_init (&bgpd_privs);
cmd_init (1);
- vty_init ();
+ vty_init (master);
memory_init ();
/* BGP related initialization. */
#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. */
#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 */
}
\f
/* 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)
/* 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);
#ifndef _ZEBRA_VTY_H
#define _ZEBRA_VTY_H
+#include "thread.h"
+
#define VTY_BUFSIZ 512
#define VTY_MAXHIST 20
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);
zprivs_init (&ospf6d_privs);
signal_init ();
cmd_init (1);
- vty_init ();
+ vty_init (master);
ospf6_init ();
memory_init ();
sort_node ();
signal_init ();
cmd_init (1);
debug_init ();
- vty_init ();
+ vty_init (master);
memory_init ();
access_list_init ();
zprivs_init (&ripd_privs);
signal_init ();
cmd_init (1);
- vty_init ();
+ vty_init (master);
memory_init ();
keychain_init ();
zprivs_init (&ripngd_privs);
signal_init ();
cmd_init (1);
- vty_init ();
+ vty_init (master);
memory_init ();
/* RIPngd inits. */
#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;
}
/* Make master thread emulator. */
- master = thread_master_create ();
+ zebrad.master = thread_master_create ();
/* privs initialise */
zprivs_init (&zserv_privs);
/* Vty related initialize. */
signal_init ();
cmd_init (1);
- vty_init ();
+ vty_init (zebrad.master);
memory_init ();
/* Zebra related initialize. */
/* 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... */
#include "zebra/redistribute.h"
#include "zebra/debug.h"
+/* master zebra server structure */
+extern struct zebra_t zebrad;
+
int
zebra_check_addr (struct prefix *p)
{
#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))
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))
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);
}
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);
}
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);
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);
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);
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);
{0, NULL}
};
-extern int rtm_table_default;
+extern struct zebra_t zebrad;
extern struct zebra_privs_t zserv_privs;
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
}
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;
}
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;
}
/* 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);
}
#include "zebra/interface.h"
#include "zebra/rtadv.h"
#include "zebra/debug.h"
+#include "zebra/zserv.h"
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);
}
}
-extern struct thread_master *master;
void
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)
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;
#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
{
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);
/* 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;
\f
/* For logging of zebra meesages. */
char *zebra_command_str [] =
}
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;
}
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
thread_cancel (client->t_write);
/* Free client structure. */
- listnode_delete (client_list, client);
+ listnode_delete (zebrad.client_list, client);
XFREE (0, client);
}
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);
zebra_event (ZEBRA_SERV, sock, NULL);
}
\f
-/* Zebra's event management function. */
-extern struct thread_master *master;
void
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:
/**/
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;
}
"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;
}
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);
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;
}
zebra_init ()
{
/* Client list init. */
- client_list = list_new ();
+ zebrad.client_list = list_new ();
/* Forwarding is on by default. */
ipforward_on ();
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))