1998-05-15 15:56:13 +08:00
|
|
|
/*
|
|
|
|
* BIRD Internet Routing Daemon -- Unix Entry Point
|
|
|
|
*
|
1999-02-06 05:37:34 +08:00
|
|
|
* (c) 1998--1999 Martin Mares <mj@ucw.cz>
|
1998-05-15 15:56:13 +08:00
|
|
|
*
|
|
|
|
* Can be freely distributed and used under the terms of the GNU GPL.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
1998-11-28 03:37:07 +08:00
|
|
|
#include <fcntl.h>
|
|
|
|
#include <unistd.h>
|
1998-05-24 22:50:18 +08:00
|
|
|
#include <sys/signal.h>
|
1998-05-15 15:56:13 +08:00
|
|
|
|
|
|
|
#include "nest/bird.h"
|
|
|
|
#include "lib/lists.h"
|
|
|
|
#include "lib/resource.h"
|
1998-05-24 22:50:18 +08:00
|
|
|
#include "lib/socket.h"
|
1998-05-15 15:56:13 +08:00
|
|
|
#include "nest/route.h"
|
1998-05-24 22:50:18 +08:00
|
|
|
#include "nest/protocol.h"
|
1998-05-27 05:42:05 +08:00
|
|
|
#include "nest/iface.h"
|
1998-11-28 03:37:07 +08:00
|
|
|
#include "conf/conf.h"
|
1999-01-16 00:49:17 +08:00
|
|
|
#include "filter/filter.h"
|
1998-05-24 22:50:18 +08:00
|
|
|
|
|
|
|
#include "unix.h"
|
1998-10-18 20:50:43 +08:00
|
|
|
#include "krt.h"
|
1998-05-24 22:50:18 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Debugging
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void
|
|
|
|
handle_sigusr(int sig)
|
|
|
|
{
|
|
|
|
debug("SIGUSR1: Debugging dump...\n\n");
|
|
|
|
|
|
|
|
sk_dump_all();
|
|
|
|
tm_dump_all();
|
1998-05-27 05:42:05 +08:00
|
|
|
if_dump_all();
|
1998-06-02 05:41:32 +08:00
|
|
|
neigh_dump_all();
|
1998-05-24 22:50:18 +08:00
|
|
|
rta_dump_all();
|
|
|
|
rt_dump_all();
|
1998-07-10 03:37:39 +08:00
|
|
|
protos_dump_all();
|
1998-05-24 22:50:18 +08:00
|
|
|
|
|
|
|
debug("\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
signal_init(void)
|
|
|
|
{
|
|
|
|
static struct sigaction sa;
|
|
|
|
|
|
|
|
sa.sa_handler = handle_sigusr;
|
|
|
|
sa.sa_flags = SA_RESTART;
|
|
|
|
if (sigaction(SIGUSR1, &sa, NULL) < 0)
|
|
|
|
die("sigaction: %m");
|
|
|
|
signal(SIGPIPE, SIG_IGN);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
1998-11-28 03:37:07 +08:00
|
|
|
* Reading the Configuration
|
1998-05-24 22:50:18 +08:00
|
|
|
*/
|
|
|
|
|
1998-11-28 03:37:07 +08:00
|
|
|
static int conf_fd;
|
|
|
|
|
|
|
|
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-06 05:37:34 +08:00
|
|
|
struct config *conf = config_alloc(PATH_CONFIG);
|
|
|
|
|
1998-11-28 03:37:07 +08:00
|
|
|
conf_fd = open(PATH_CONFIG, O_RDONLY);
|
|
|
|
if (conf_fd < 0)
|
|
|
|
die("Unable to open configuration file " PATH_CONFIG ": %m");
|
|
|
|
cf_read_hook = cf_read;
|
1999-02-06 05:37:34 +08:00
|
|
|
if (!config_parse(conf))
|
|
|
|
die(PATH_CONFIG ", line %d: %s", conf->err_lino, conf->err_msg);
|
|
|
|
config_commit(conf);
|
1998-11-28 03:37:07 +08:00
|
|
|
}
|
1999-02-06 05:37:34 +08:00
|
|
|
|
1998-06-03 16:43:44 +08:00
|
|
|
/*
|
|
|
|
* Hic Est main()
|
|
|
|
*/
|
1998-05-15 15:56:13 +08:00
|
|
|
|
|
|
|
int
|
|
|
|
main(void)
|
|
|
|
{
|
1999-01-15 22:40:50 +08:00
|
|
|
log(L_INFO "Launching BIRD 0.0.0...");
|
1998-05-15 15:56:13 +08:00
|
|
|
|
|
|
|
log_init_debug(NULL);
|
1998-11-28 03:37:07 +08:00
|
|
|
|
|
|
|
debug("Initializing.\n");
|
1998-11-28 05:09:57 +08:00
|
|
|
resource_init();
|
1998-05-24 22:50:18 +08:00
|
|
|
io_init();
|
1998-05-20 19:54:33 +08:00
|
|
|
rt_init();
|
1998-05-27 05:42:05 +08:00
|
|
|
if_init();
|
1998-11-28 05:09:57 +08:00
|
|
|
|
1998-10-18 19:53:21 +08:00
|
|
|
protos_build();
|
1998-12-07 01:40:42 +08:00
|
|
|
add_tail(&protocol_list, &proto_unix_kernel.n);
|
1998-11-28 05:09:57 +08:00
|
|
|
|
|
|
|
read_config();
|
1998-05-27 05:42:05 +08:00
|
|
|
|
1998-05-24 22:50:18 +08:00
|
|
|
signal_init();
|
|
|
|
|
1998-10-14 21:38:17 +08:00
|
|
|
scan_if_init();
|
|
|
|
|
1998-10-17 19:05:18 +08:00
|
|
|
protos_start();
|
|
|
|
|
1998-05-27 05:42:05 +08:00
|
|
|
handle_sigusr(0);
|
|
|
|
|
|
|
|
debug("Entering I/O loop.\n");
|
1998-05-15 15:56:13 +08:00
|
|
|
|
1998-05-24 22:50:18 +08:00
|
|
|
io_loop();
|
1998-12-20 22:27:37 +08:00
|
|
|
bug("I/O loop died");
|
1998-05-15 15:56:13 +08:00
|
|
|
}
|