1998-05-15 07:56:13 +00:00
|
|
|
/*
|
|
|
|
* BIRD Internet Routing Daemon -- Unix Entry Point
|
|
|
|
*
|
1999-02-05 21:37:34 +00:00
|
|
|
* (c) 1998--1999 Martin Mares <mj@ucw.cz>
|
1998-05-15 07:56:13 +00:00
|
|
|
*
|
|
|
|
* Can be freely distributed and used under the terms of the GNU GPL.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
1999-02-13 19:43:21 +00:00
|
|
|
#include <string.h>
|
1999-03-04 11:36:26 +00:00
|
|
|
#include <stdlib.h>
|
1998-11-27 19:37:07 +00:00
|
|
|
#include <fcntl.h>
|
|
|
|
#include <unistd.h>
|
1998-05-24 14:50:18 +00:00
|
|
|
#include <sys/signal.h>
|
1998-05-15 07:56:13 +00:00
|
|
|
|
|
|
|
#include "nest/bird.h"
|
|
|
|
#include "lib/lists.h"
|
|
|
|
#include "lib/resource.h"
|
1998-05-24 14:50:18 +00:00
|
|
|
#include "lib/socket.h"
|
1999-02-11 22:51:15 +00:00
|
|
|
#include "lib/event.h"
|
1998-05-15 07:56:13 +00:00
|
|
|
#include "nest/route.h"
|
1998-05-24 14:50:18 +00:00
|
|
|
#include "nest/protocol.h"
|
1998-05-26 21:42:05 +00:00
|
|
|
#include "nest/iface.h"
|
1998-11-27 19:37:07 +00:00
|
|
|
#include "conf/conf.h"
|
1999-01-15 16:49:17 +00:00
|
|
|
#include "filter/filter.h"
|
1998-05-24 14:50:18 +00:00
|
|
|
|
|
|
|
#include "unix.h"
|
1998-10-18 12:50:43 +00:00
|
|
|
#include "krt.h"
|
1998-05-24 14:50:18 +00:00
|
|
|
|
1999-02-13 20:15:36 +00:00
|
|
|
int shutting_down;
|
|
|
|
|
1998-05-24 14:50:18 +00:00
|
|
|
/*
|
|
|
|
* Debugging
|
|
|
|
*/
|
|
|
|
|
1999-02-13 19:43:21 +00:00
|
|
|
void
|
|
|
|
async_dump(void)
|
1998-05-24 14:50:18 +00:00
|
|
|
{
|
1999-02-13 19:43:21 +00:00
|
|
|
debug("INTERNAL STATE DUMP\n\n");
|
1998-05-24 14:50:18 +00:00
|
|
|
|
|
|
|
sk_dump_all();
|
|
|
|
tm_dump_all();
|
1998-05-26 21:42:05 +00:00
|
|
|
if_dump_all();
|
1998-06-01 21:41:32 +00:00
|
|
|
neigh_dump_all();
|
1998-05-24 14:50:18 +00:00
|
|
|
rta_dump_all();
|
|
|
|
rt_dump_all();
|
1998-07-09 19:37:39 +00:00
|
|
|
protos_dump_all();
|
1998-05-24 14:50:18 +00:00
|
|
|
|
|
|
|
debug("\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
1998-11-27 19:37:07 +00:00
|
|
|
* Reading the Configuration
|
1998-05-24 14:50:18 +00:00
|
|
|
*/
|
|
|
|
|
1998-11-27 19:37:07 +00:00
|
|
|
static int conf_fd;
|
1999-02-13 19:43:21 +00:00
|
|
|
static char *config_name = PATH_CONFIG;
|
1998-11-27 19:37:07 +00:00
|
|
|
|
|
|
|
static int
|
|
|
|
cf_read(byte *dest, unsigned int len)
|
|
|
|
{
|
|
|
|
int l = read(conf_fd, dest, len);
|
|
|
|
if (l < 0)
|
|
|
|
cf_error("Read error");
|
|
|
|
return l;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
read_config(void)
|
|
|
|
{
|
1999-02-13 19:43:21 +00:00
|
|
|
struct config *conf = config_alloc(config_name);
|
1999-02-05 21:37:34 +00:00
|
|
|
|
1999-02-13 19:43:21 +00:00
|
|
|
conf_fd = open(config_name, O_RDONLY);
|
1998-11-27 19:37:07 +00:00
|
|
|
if (conf_fd < 0)
|
1999-02-13 19:43:21 +00:00
|
|
|
die("Unable to open configuration file %s: %m", config_name);
|
1998-11-27 19:37:07 +00:00
|
|
|
cf_read_hook = cf_read;
|
1999-02-05 21:37:34 +00:00
|
|
|
if (!config_parse(conf))
|
1999-02-13 19:43:21 +00:00
|
|
|
die("%s, line %d: %s", config_name, conf->err_lino, conf->err_msg);
|
1999-02-05 21:37:34 +00:00
|
|
|
config_commit(conf);
|
1998-11-27 19:37:07 +00:00
|
|
|
}
|
1999-02-05 21:37:34 +00:00
|
|
|
|
1999-02-13 19:43:21 +00:00
|
|
|
void
|
|
|
|
async_config(void)
|
|
|
|
{
|
|
|
|
debug("Asynchronous reconfigurations are not supported in demo version\n");
|
|
|
|
}
|
|
|
|
|
1999-02-13 20:15:36 +00:00
|
|
|
/*
|
|
|
|
* Shutdown
|
|
|
|
*/
|
|
|
|
|
|
|
|
void
|
|
|
|
async_shutdown(void)
|
|
|
|
{
|
|
|
|
debug("Shutting down...\n");
|
|
|
|
shutting_down = 1;
|
|
|
|
protos_shutdown();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
protos_shutdown_notify(void)
|
|
|
|
{
|
|
|
|
die("System shutdown completed");
|
|
|
|
}
|
|
|
|
|
1999-02-13 19:43:21 +00:00
|
|
|
/*
|
|
|
|
* Signals
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void
|
|
|
|
handle_sighup(int sig)
|
|
|
|
{
|
|
|
|
debug("Caught SIGHUP...\n");
|
|
|
|
async_config_flag = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
handle_sigusr(int sig)
|
|
|
|
{
|
|
|
|
debug("Caught SIGUSR...\n");
|
|
|
|
async_dump_flag = 1;
|
|
|
|
}
|
|
|
|
|
1999-02-13 20:15:36 +00:00
|
|
|
static void
|
|
|
|
handle_sigterm(int sig)
|
|
|
|
{
|
|
|
|
debug("Caught SIGTERM...\n");
|
|
|
|
async_shutdown_flag = 1;
|
|
|
|
}
|
|
|
|
|
1999-02-13 19:43:21 +00:00
|
|
|
static void
|
|
|
|
signal_init(void)
|
|
|
|
{
|
|
|
|
struct sigaction sa;
|
|
|
|
|
|
|
|
bzero(&sa, sizeof(sa));
|
|
|
|
sa.sa_handler = handle_sigusr;
|
|
|
|
sa.sa_flags = SA_RESTART;
|
|
|
|
sigaction(SIGUSR1, &sa, NULL);
|
|
|
|
sa.sa_handler = handle_sighup;
|
|
|
|
sa.sa_flags = SA_RESTART;
|
|
|
|
sigaction(SIGHUP, &sa, NULL);
|
1999-02-13 20:15:36 +00:00
|
|
|
sa.sa_handler = handle_sigterm;
|
|
|
|
sa.sa_flags = SA_RESTART;
|
|
|
|
sigaction(SIGTERM, &sa, NULL);
|
1999-02-13 19:43:21 +00:00
|
|
|
signal(SIGPIPE, SIG_IGN);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Parsing of command-line arguments
|
|
|
|
*/
|
|
|
|
|
|
|
|
static char *opt_list = "c:d:";
|
|
|
|
|
|
|
|
static void
|
|
|
|
usage(void)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "Usage: bird [-c <config-file>] [-d <debug-file>]\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
parse_args(int argc, char **argv)
|
|
|
|
{
|
|
|
|
int c;
|
|
|
|
|
|
|
|
while ((c = getopt(argc, argv, opt_list)) >= 0)
|
|
|
|
switch (c)
|
|
|
|
{
|
|
|
|
case 'c':
|
|
|
|
config_name = optarg;
|
|
|
|
break;
|
|
|
|
case 'd':
|
|
|
|
log_init_debug(optarg);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
usage();
|
|
|
|
}
|
|
|
|
if (optind < argc)
|
|
|
|
usage();
|
|
|
|
}
|
|
|
|
|
1998-06-03 08:43:44 +00:00
|
|
|
/*
|
|
|
|
* Hic Est main()
|
|
|
|
*/
|
1998-05-15 07:56:13 +00:00
|
|
|
|
|
|
|
int
|
1999-02-13 19:43:21 +00:00
|
|
|
main(int argc, char **argv)
|
1998-05-15 07:56:13 +00:00
|
|
|
{
|
1999-03-04 11:36:26 +00:00
|
|
|
#ifdef HAVE_LIBDMALLOC
|
|
|
|
if (!getenv("DMALLOC_OPTIONS"))
|
|
|
|
dmalloc_debug(0x2f03d00);
|
|
|
|
#endif
|
|
|
|
|
1998-05-15 07:56:13 +00:00
|
|
|
log_init_debug(NULL);
|
1999-02-13 19:43:21 +00:00
|
|
|
parse_args(argc, argv);
|
|
|
|
|
|
|
|
log(L_INFO "Launching BIRD 0.0.0...");
|
1998-11-27 19:37:07 +00:00
|
|
|
|
|
|
|
debug("Initializing.\n");
|
1998-11-27 21:09:57 +00:00
|
|
|
resource_init();
|
1998-05-24 14:50:18 +00:00
|
|
|
io_init();
|
1998-05-20 11:54:33 +00:00
|
|
|
rt_init();
|
1998-05-26 21:42:05 +00:00
|
|
|
if_init();
|
1998-11-27 21:09:57 +00:00
|
|
|
|
1998-10-18 11:53:21 +00:00
|
|
|
protos_build();
|
1998-12-06 17:40:42 +00:00
|
|
|
add_tail(&protocol_list, &proto_unix_kernel.n);
|
1998-11-27 21:09:57 +00:00
|
|
|
|
|
|
|
read_config();
|
1998-05-26 21:42:05 +00:00
|
|
|
|
1998-05-24 14:50:18 +00:00
|
|
|
signal_init();
|
|
|
|
|
1998-10-17 11:05:18 +00:00
|
|
|
protos_start();
|
|
|
|
|
1999-02-11 22:51:15 +00:00
|
|
|
ev_run_list(&global_event_list);
|
1999-02-13 19:43:21 +00:00
|
|
|
async_dump();
|
1998-05-26 21:42:05 +00:00
|
|
|
|
|
|
|
debug("Entering I/O loop.\n");
|
1998-05-15 07:56:13 +00:00
|
|
|
|
1998-05-24 14:50:18 +00:00
|
|
|
io_loop();
|
1998-12-20 14:27:37 +00:00
|
|
|
bug("I/O loop died");
|
1998-05-15 07:56:13 +00:00
|
|
|
}
|