-/* $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>
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);
-/* $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>
}
void
-frontend(int debug, int verbose, char *sockname)
+frontend(int debug, int verbose)
{
struct event ev_sigint, ev_sigterm;
struct passwd *pw;
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");
TAILQ_INIT(&ra_interfaces);
- /* Listen on control socket. */
- TAILQ_INIT(&ctl_conns);
- control_listen();
-
event_dispatch();
frontend_shutdown();
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;
-/* $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>
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);
-/* $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>
int pipe_main2engine[2];
int icmp6sock, on = 1;
int frontend_routesock, rtfilter;
+ int control_fd;
conffile = CONF_FILE;
csock = RAD_SOCKET;
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) {
&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)
-/* $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>
IMSG_RECONF_END,
IMSG_ICMP6SOCK,
IMSG_ROUTESOCK,
+ IMSG_CONTROLFD,
IMSG_STARTUP,
IMSG_STARTUP_DONE,
IMSG_RA_RS,