summaryrefslogtreecommitdiff
path: root/sysdep/unix/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'sysdep/unix/main.c')
-rw-r--r--sysdep/unix/main.c62
1 files changed, 37 insertions, 25 deletions
diff --git a/sysdep/unix/main.c b/sysdep/unix/main.c
index c326ba2b..0337c755 100644
--- a/sysdep/unix/main.c
+++ b/sysdep/unix/main.c
@@ -31,7 +31,7 @@
#include "lib/locking.h"
#include "lib/timer.h"
#include "lib/string.h"
-#include "nest/route.h"
+#include "nest/rt.h"
#include "nest/protocol.h"
#include "nest/iface.h"
#include "nest/cli.h"
@@ -52,12 +52,12 @@ async_dump(void)
{
debug("INTERNAL STATE DUMP\n\n");
- rp_dump(&root_pool);
+ rdump(&root_pool, 0);
sk_dump_all();
// XXXX tm_dump_all();
if_dump_all();
neigh_dump_all();
- rta_dump_all();
+ ea_dump_all();
rt_dump_all();
protos_dump_all();
@@ -117,7 +117,7 @@ add_num_const(char *name, int val, const char *file, const uint line)
struct f_val *v = cfg_alloc(sizeof(struct f_val));
*v = (struct f_val) { .type = T_INT, .val.i = val };
struct symbol *sym = cf_get_symbol(name);
- if (sym->class && (sym->scope == conf_this_scope))
+ if (sym->class && cf_symbol_is_local(sym))
cf_error("Error reading value for %s from %s:%d: already defined", name, file, line);
cf_define_symbol(sym, SYM_CONSTANT | T_INT, val, v);
@@ -200,10 +200,10 @@ sysdep_preconfig(struct config *c)
}
int
-sysdep_commit(struct config *new, struct config *old UNUSED)
+sysdep_commit(struct config *new, struct config *old)
{
- if (!new->shutdown)
- log_switch(0, &new->logfiles, new->syslog_name);
+ log_switch(0, &new->logfiles, new->syslog_name);
+ bird_thread_commit(new, old);
return 0;
}
@@ -245,6 +245,8 @@ async_config(void)
{
struct config *conf;
+ config_free_old();
+
log(L_INFO "Reconfiguration requested by SIGHUP");
if (!unix_read_config(&conf, config_name))
{
@@ -283,6 +285,9 @@ cmd_read_config(const char *name)
void
cmd_check_config(const char *name)
{
+ if (cli_access_restricted())
+ return;
+
struct config *conf = cmd_read_config(name);
if (!conf)
return;
@@ -327,6 +332,8 @@ cmd_reconfig(const char *name, int type, uint timeout)
if (cli_access_restricted())
return;
+ config_free_old();
+
struct config *conf = cmd_read_config(name);
if (!conf)
return;
@@ -397,7 +404,8 @@ static char *path_control_socket = PATH_CONTROL_SOCKET;
static void
cli_write(cli *c)
{
- sock *s = c->priv;
+ sock *s = c->sock;
+ ASSERT_DIE(c->sock);
while (c->tx_pos)
{
@@ -421,7 +429,9 @@ cli_write(cli *c)
void
cli_write_trigger(cli *c)
{
- sock *s = c->priv;
+ sock *s = c->sock;
+ if (!s)
+ return;
if (s->tbuf == NULL)
cli_write(c);
@@ -436,8 +446,9 @@ cli_tx(sock *s)
int
cli_get_command(cli *c)
{
- sock *s = c->priv;
- byte *t = c->rx_aux ? : s->rbuf;
+ sock *s = c->sock;
+ ASSERT_DIE(c->sock);
+ byte *t = s->rbuf;
byte *tend = s->rpos;
byte *d = c->rx_pos;
byte *dend = c->rx_buf + CLI_RX_BUF_SIZE - 2;
@@ -448,16 +459,22 @@ cli_get_command(cli *c)
t++;
else if (*t == '\n')
{
+ *d = 0;
t++;
+
+ /* Move remaining data and reset pointers */
+ uint rest = (t < tend) ? (tend - t) : 0;
+ memmove(s->rbuf, t, rest);
+ s->rpos = s->rbuf + rest;
c->rx_pos = c->rx_buf;
- c->rx_aux = t;
- *d = 0;
+
return (d < dend) ? 1 : -1;
}
else if (d < dend)
*d++ = *t++;
}
- c->rx_aux = s->rpos = s->rbuf;
+
+ s->rpos = s->rbuf;
c->rx_pos = d;
return 0;
}
@@ -479,6 +496,7 @@ cli_err(sock *s, int err)
else
log(L_INFO "CLI connection closed");
}
+
cli_free(s->data);
}
@@ -504,7 +522,6 @@ cli_connect(sock *s, uint size UNUSED)
s->pool = c->pool; /* We need to have all the socket buffers allocated in the cli pool */
s->fast_rx = 1;
c->rx_pos = c->rx_buf;
- c->rx_aux = NULL;
rmove(s, c->pool);
return 1;
}
@@ -525,7 +542,7 @@ cli_init_unix(uid_t use_uid, gid_t use_gid)
/* Return value intentionally ignored */
unlink(path_control_socket);
- if (sk_open_unix(s, path_control_socket) < 0)
+ if (sk_open_unix(s, &main_birdloop, path_control_socket) < 0)
die("Cannot create control socket %s: %m", path_control_socket);
if (use_uid || use_gid)
@@ -615,7 +632,6 @@ sysdep_shutdown_done(void)
unlink_pid_file();
unlink(path_control_socket);
log_msg(L_FATAL "Shutdown completed");
- log_cleanup(1);
exit(0);
}
@@ -686,7 +702,7 @@ signal_init(void)
* Parsing of command-line arguments
*/
-static char *opt_list = "c:dD:ps:P:u:g:flRh";
+static char *opt_list = "bc:dD:ps:P:u:g:flRh";
int parse_and_exit;
char *bird_name;
static char *use_user;
@@ -865,8 +881,6 @@ parse_args(int argc, char **argv)
}
}
-void resource_sys_init(void);
-
/*
* Hic Est main()
*/
@@ -880,19 +894,17 @@ main(int argc, char **argv)
#endif
times_update();
- resource_sys_init();
parse_args(argc, argv);
log_switch(1, NULL, NULL);
the_bird_lock();
random_init();
- net_init();
resource_init();
birdloop_init();
olock_init();
- io_init();
rt_init();
+ io_init();
if_init();
// roa_init();
config_init();
@@ -916,14 +928,14 @@ main(int argc, char **argv)
open_pid_file();
protos_build();
- proto_build(&proto_unix_kernel);
- proto_build(&proto_unix_iface);
struct config *conf = read_config();
if (parse_and_exit)
exit(0);
+ flush_local_pages();
+
if (!run_in_foreground)
{
pid_t pid = fork();