ldpd_process = PROC_LDP_ENGINE;
log_procname = log_procnames[ldpd_process];
- master = thread_master_create();
+ master = thread_master_create(NULL);
/* setup signal handler */
signal_init(master, array_size(ldpe_signals), ldpe_signals);
void
ldpe_init(struct ldpd_init *init)
{
+#ifdef __OpenBSD__
+ /* This socket must be open before dropping privileges. */
+ global.pfkeysock = pfkey_init();
+ if (sysdep.no_pfkey == 0) {
+ pfkey_ev = NULL;
+ thread_add_read(master, ldpe_dispatch_pfkey, NULL, global.pfkeysock,
+ &pfkey_ev);
+ }
+#endif
+
/* drop privileges */
ldpe_privs.user = init->user;
ldpe_privs.group = init->group;
+ zprivs_preinit(&ldpe_privs);
zprivs_init(&ldpe_privs);
/* listen on ldpd control socket */
TAILQ_INIT(&ctl_conns);
control_listen();
-#ifdef HAVE_PLEDGE
- if (pledge("stdio cpath inet mcast recvfd", NULL) == -1)
- fatal("pledge");
-#endif
-
LIST_INIT(&global.addr_list);
- RB_INIT(&global.adj_tree);
+ RB_INIT(global_adj_head, &global.adj_tree);
TAILQ_INIT(&global.pending_conns);
if (inet_pton(AF_INET, AllRouters_v4, &global.mcast_addr_v4) != 1)
fatal("inet_pton");
if (inet_pton(AF_INET6, AllRouters_v6, &global.mcast_addr_v6) != 1)
fatal("inet_pton");
-#ifdef __OpenBSD__
- global.pfkeysock = pfkey_init();
- if (sysdep.no_pfkey == 0) {
- pfkey_ev = NULL;
- thread_add_read(master, ldpe_dispatch_pfkey, NULL, global.pfkeysock,
- &pfkey_ev);
- }
-#endif
/* mark sockets as closed */
global.ipv4.ldp_disc_socket = -1;
/* close pipes */
if (iev_lde) {
- msgbuf_write(&iev_lde->ibuf.w);
msgbuf_clear(&iev_lde->ibuf.w);
close(iev_lde->ibuf.fd);
+ iev_lde->ibuf.fd = -1;
}
- msgbuf_write(&iev_main->ibuf.w);
msgbuf_clear(&iev_main->ibuf.w);
close(iev_main->ibuf.fd);
+ iev_main->ibuf.fd = -1;
msgbuf_clear(&iev_main_sync->ibuf.w);
close(iev_main_sync->ibuf.fd);
+ iev_main_sync->ibuf.fd = -1;
control_cleanup(ctl_sock_path);
config_clear(leconf);
/* remove addresses from global list */
while ((if_addr = LIST_FIRST(&global.addr_list)) != NULL) {
LIST_REMOVE(if_addr, entry);
+ assert(if_addr != LIST_FIRST(&global.addr_list));
free(if_addr);
}
- while ((adj = RB_ROOT(&global.adj_tree)) != NULL)
+ while (!RB_EMPTY(global_adj_head, &global.adj_tree)) {
+ adj = RB_ROOT(global_adj_head, &global.adj_tree);
+
adj_del(adj, S_SHUTDOWN);
+ }
/* clean up */
if (iev_lde)
int
ldpe_imsg_compose_parent(int type, pid_t pid, void *data, uint16_t datalen)
{
+ if (iev_main->ibuf.fd == -1)
+ return (0);
return (imsg_compose_event(iev_main, type, 0, pid, -1, data, datalen));
}
void
ldpe_imsg_compose_parent_sync(int type, pid_t pid, void *data, uint16_t datalen)
{
+ if (iev_main_sync->ibuf.fd == -1)
+ return;
imsg_compose_event(iev_main_sync, type, 0, pid, -1, data, datalen);
imsg_flush(&iev_main_sync->ibuf);
}
ldpe_imsg_compose_lde(int type, uint32_t peerid, pid_t pid, void *data,
uint16_t datalen)
{
+ if (iev_lde->ibuf.fd == -1)
+ return (0);
return (imsg_compose_event(iev_lde, type, peerid, pid, -1,
data, datalen));
}
struct l2vpn_if *lif, *nlif;
struct l2vpn_pw *pw, *npw;
struct imsg imsg;
- int fd = THREAD_FD(thread);
+ int fd;
struct imsgev *iev = THREAD_ARG(thread);
struct imsgbuf *ibuf = &iev->ibuf;
struct iface *iface = NULL;
fatal(NULL);
memcpy(nconf, imsg.data, sizeof(struct ldpd_conf));
- RB_INIT(&nconf->iface_tree);
- RB_INIT(&nconf->tnbr_tree);
- RB_INIT(&nconf->nbrp_tree);
- RB_INIT(&nconf->l2vpn_tree);
+ RB_INIT(iface_head, &nconf->iface_tree);
+ RB_INIT(tnbr_head, &nconf->tnbr_tree);
+ RB_INIT(nbrp_head, &nconf->nbrp_tree);
+ RB_INIT(l2vpn_head, &nconf->l2vpn_tree);
break;
case IMSG_RECONF_IFACE:
if ((niface = malloc(sizeof(struct iface))) == NULL)
fatal(NULL);
memcpy(nl2vpn, imsg.data, sizeof(struct l2vpn));
- RB_INIT(&nl2vpn->if_tree);
- RB_INIT(&nl2vpn->pw_tree);
- RB_INIT(&nl2vpn->pw_inactive_tree);
+ RB_INIT(l2vpn_if_head, &nl2vpn->if_tree);
+ RB_INIT(l2vpn_pw_head, &nl2vpn->pw_tree);
+ RB_INIT(l2vpn_pw_head, &nl2vpn->pw_inactive_tree);
RB_INSERT(l2vpn_head, &nconf->l2vpn_tree, nl2vpn);
break;
continue;
strlcpy(ictl.name, iface->name, sizeof(ictl.name));
- if (RB_EMPTY(&iface->ipv4.adj_tree) &&
- RB_EMPTY(&iface->ipv6.adj_tree))
+ if (RB_EMPTY(ia_adj_head, &iface->ipv4.adj_tree) &&
+ RB_EMPTY(ia_adj_head, &iface->ipv6.adj_tree))
ictl.no_adj = 1;
imsg_compose_event(&c->iev, IMSG_CTL_SHOW_DISC_IFACE, 0, 0,
-1, &ictl, sizeof(ictl));
while ((me = TAILQ_FIRST(mh)) != NULL) {
TAILQ_REMOVE(mh, me, entry);
+ assert(me != TAILQ_FIRST(mh));
free(me);
}
}