From a778af8b3fb3c15d04cadacdc2849fa68b13171e Mon Sep 17 00:00:00 2001 From: florian Date: Fri, 13 Jul 2018 08:32:10 +0000 Subject: [PATCH] pass control socket in from main --- usr.sbin/rad/control.c | 7 ++----- usr.sbin/rad/frontend.c | 24 +++++++++++++----------- usr.sbin/rad/frontend.h | 4 ++-- usr.sbin/rad/rad.c | 10 +++++++--- usr.sbin/rad/rad.h | 3 ++- 5 files changed, 26 insertions(+), 22 deletions(-) diff --git a/usr.sbin/rad/control.c b/usr.sbin/rad/control.c index 4d3a8568d95..bc3bd7e450d 100644 --- a/usr.sbin/rad/control.c +++ b/usr.sbin/rad/control.c @@ -1,4 +1,4 @@ -/* $OpenBSD: control.c,v 1.2 2018/07/10 22:14:19 florian Exp $ */ +/* $OpenBSD: control.c,v 1.3 2018/07/13 08:32:10 florian Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer @@ -84,15 +84,12 @@ control_init(char *path) return (-1); } - control_state.fd = fd; - - return (0); + return (fd); } int control_listen(void) { - if (listen(control_state.fd, CONTROL_BACKLOG) == -1) { log_warn("%s: listen", __func__); return (-1); diff --git a/usr.sbin/rad/frontend.c b/usr.sbin/rad/frontend.c index 713b6c203e0..937761069cb 100644 --- a/usr.sbin/rad/frontend.c +++ b/usr.sbin/rad/frontend.c @@ -1,4 +1,4 @@ -/* $OpenBSD: frontend.c,v 1.6 2018/07/13 08:31:34 florian Exp $ */ +/* $OpenBSD: frontend.c,v 1.7 2018/07/13 08:32:10 florian Exp $ */ /* * Copyright (c) 2018 Florian Obser @@ -166,7 +166,7 @@ frontend_sig_handler(int sig, short event, void *bula) } void -frontend(int debug, int verbose, char *sockname) +frontend(int debug, int verbose) { struct event ev_sigint, ev_sigterm; struct passwd *pw; @@ -175,15 +175,11 @@ frontend(int debug, int verbose, char *sockname) uint8_t *sndcmsgbuf = NULL; frontend_conf = config_new_empty(); + control_state.fd = -1; log_init(debug, LOG_DAEMON); log_setverbose(verbose); - /* XXX pass in from main */ - /* Create rad control socket outside chroot. */ - if (control_init(sockname) == -1) - fatalx("control socket setup failed"); - if ((pw = getpwnam(RAD_USER)) == NULL) fatal("getpwnam"); @@ -264,10 +260,6 @@ frontend(int debug, int verbose, char *sockname) TAILQ_INIT(&ra_interfaces); - /* Listen on control socket. */ - TAILQ_INIT(&ctl_conns); - control_listen(); - event_dispatch(); frontend_shutdown(); @@ -426,6 +418,16 @@ frontend_dispatch_main(int fd, short event, void *bula) fatal("pledge"); frontend_startup(); break; + case IMSG_CONTROLFD: + if ((fd = imsg.fd) == -1) + fatalx("%s: expected to receive imsg " + "control fd but didn't receive any", + __func__); + control_state.fd = fd; + /* Listen on control socket. */ + TAILQ_INIT(&ctl_conns); + control_listen(); + break; case IMSG_SHUTDOWN: frontend_imsg_compose_engine(IMSG_SHUTDOWN, 0, NULL, 0); break; diff --git a/usr.sbin/rad/frontend.h b/usr.sbin/rad/frontend.h index e67aac4274c..067ed7e34a0 100644 --- a/usr.sbin/rad/frontend.h +++ b/usr.sbin/rad/frontend.h @@ -1,4 +1,4 @@ -/* $OpenBSD: frontend.h,v 1.2 2018/07/10 22:14:19 florian Exp $ */ +/* $OpenBSD: frontend.h,v 1.3 2018/07/13 08:32:10 florian Exp $ */ /* * Copyright (c) 2018 Florian Obser @@ -19,7 +19,7 @@ TAILQ_HEAD(ctl_conns, ctl_conn) ctl_conns; -void frontend(int, int, char *); +void frontend(int, int); void frontend_dispatch_main(int, short, void *); void frontend_dispatch_engine(int, short, void *); int frontend_imsg_compose_main(int, pid_t, void *, uint16_t); diff --git a/usr.sbin/rad/rad.c b/usr.sbin/rad/rad.c index 59b3c073a07..60075660e4e 100644 --- a/usr.sbin/rad/rad.c +++ b/usr.sbin/rad/rad.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rad.c,v 1.5 2018/07/13 08:31:34 florian Exp $ */ +/* $OpenBSD: rad.c,v 1.6 2018/07/13 08:32:10 florian Exp $ */ /* * Copyright (c) 2018 Florian Obser @@ -131,6 +131,7 @@ main(int argc, char *argv[]) int pipe_main2engine[2]; int icmp6sock, on = 1; int frontend_routesock, rtfilter; + int control_fd; conffile = CONF_FILE; csock = RAD_SOCKET; @@ -180,7 +181,7 @@ main(int argc, char *argv[]) if (engine_flag) engine(debug, cmd_opts & OPT_VERBOSE); else if (frontend_flag) - frontend(debug, cmd_opts & OPT_VERBOSE, csock); + frontend(debug, cmd_opts & OPT_VERBOSE); /* parse config file */ if ((main_conf = parse_config(conffile)) == NULL) { @@ -292,9 +293,12 @@ main(int argc, char *argv[]) &rtfilter, sizeof(rtfilter)) < 0) fatal("setsockopt(ROUTE_MSGFILTER)"); + if ((control_fd = control_init(csock)) == -1) + fatalx("control socket setup failed"); + main_imsg_compose_frontend_fd(IMSG_ICMP6SOCK, 0, icmp6sock); main_imsg_compose_frontend_fd(IMSG_ROUTESOCK, 0, frontend_routesock); - + main_imsg_compose_frontend_fd(IMSG_CONTROLFD, 0, control_fd); main_imsg_send_config(main_conf); if (pledge("stdio rpath cpath sendfd", NULL) == -1) diff --git a/usr.sbin/rad/rad.h b/usr.sbin/rad/rad.h index 8faa2ee5d2c..e3b8c9aed89 100644 --- a/usr.sbin/rad/rad.h +++ b/usr.sbin/rad/rad.h @@ -1,4 +1,4 @@ -/* $OpenBSD: rad.h,v 1.8 2018/07/13 08:31:34 florian Exp $ */ +/* $OpenBSD: rad.h,v 1.9 2018/07/13 08:32:10 florian Exp $ */ /* * Copyright (c) 2018 Florian Obser @@ -58,6 +58,7 @@ enum imsg_type { IMSG_RECONF_END, IMSG_ICMP6SOCK, IMSG_ROUTESOCK, + IMSG_CONTROLFD, IMSG_STARTUP, IMSG_STARTUP_DONE, IMSG_RA_RS, -- 2.20.1