pass control socket in from main
authorflorian <florian@openbsd.org>
Fri, 13 Jul 2018 08:32:10 +0000 (08:32 +0000)
committerflorian <florian@openbsd.org>
Fri, 13 Jul 2018 08:32:10 +0000 (08:32 +0000)
usr.sbin/rad/control.c
usr.sbin/rad/frontend.c
usr.sbin/rad/frontend.h
usr.sbin/rad/rad.c
usr.sbin/rad/rad.h

index 4d3a856..bc3bd7e 100644 (file)
@@ -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 <henning@openbsd.org>
@@ -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);
index 713b6c2..9377610 100644 (file)
@@ -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 <florian@openbsd.org>
@@ -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;
index e67aac4..067ed7e 100644 (file)
@@ -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 <florian@openbsd.org>
@@ -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);
index 59b3c07..6007566 100644 (file)
@@ -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 <florian@openbsd.org>
@@ -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)
index 8faa2ee..e3b8c9a 100644 (file)
@@ -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 <florian@openbsd.org>
@@ -58,6 +58,7 @@ enum imsg_type {
        IMSG_RECONF_END,
        IMSG_ICMP6SOCK,
        IMSG_ROUTESOCK,
+       IMSG_CONTROLFD,
        IMSG_STARTUP,
        IMSG_STARTUP_DONE,
        IMSG_RA_RS,