From 92b9e3a91f8b117255cfe1fc46265ecf40b7ce68 Mon Sep 17 00:00:00 2001 From: florian Date: Wed, 11 Jul 2018 19:05:25 +0000 Subject: [PATCH] cleanly shutdown by sending advertisement with lifetime 0 --- usr.sbin/rad/engine.c | 5 ++++- usr.sbin/rad/frontend.c | 8 +++++++- usr.sbin/rad/rad.c | 12 ++++++++++-- usr.sbin/rad/rad.h | 3 ++- 4 files changed, 23 insertions(+), 5 deletions(-) diff --git a/usr.sbin/rad/engine.c b/usr.sbin/rad/engine.c index 4f568e37ee7..9ecb93da44b 100644 --- a/usr.sbin/rad/engine.c +++ b/usr.sbin/rad/engine.c @@ -1,4 +1,4 @@ -/* $OpenBSD: engine.c,v 1.5 2018/07/11 17:32:05 florian Exp $ */ +/* $OpenBSD: engine.c,v 1.6 2018/07/11 19:05:25 florian Exp $ */ /* * Copyright (c) 2018 Florian Obser @@ -239,6 +239,9 @@ engine_dispatch_frontend(int fd, short event, void *bula) memcpy(&verbose, imsg.data, sizeof(verbose)); log_setverbose(verbose); break; + case IMSG_SHUTDOWN: + engine_imsg_compose_frontend(IMSG_SHUTDOWN, 0, NULL, 0); + break; default: log_debug("%s: unexpected imsg %d", __func__, imsg.hdr.type); diff --git a/usr.sbin/rad/frontend.c b/usr.sbin/rad/frontend.c index e3bc5376b7f..536822bd439 100644 --- a/usr.sbin/rad/frontend.c +++ b/usr.sbin/rad/frontend.c @@ -1,4 +1,4 @@ -/* $OpenBSD: frontend.c,v 1.4 2018/07/11 17:32:05 florian Exp $ */ +/* $OpenBSD: frontend.c,v 1.5 2018/07/11 19:05:25 florian Exp $ */ /* * Copyright (c) 2018 Florian Obser @@ -411,6 +411,9 @@ frontend_dispatch_main(int fd, short event, void *bula) fatal("pledge"); frontend_startup(); break; + case IMSG_SHUTDOWN: + frontend_imsg_compose_engine(IMSG_SHUTDOWN, 0, NULL, 0); + break; default: log_debug("%s: error handling imsg %d", __func__, imsg.hdr.type); @@ -478,6 +481,9 @@ frontend_dispatch_engine(int fd, short event, void *bula) free_ra_iface(ra_iface); } break; + case IMSG_SHUTDOWN: + frontend_imsg_compose_main(IMSG_SHUTDOWN, 0, NULL, 0); + break; default: log_debug("%s: error handling imsg %d", __func__, imsg.hdr.type); diff --git a/usr.sbin/rad/rad.c b/usr.sbin/rad/rad.c index 2339050b71c..96aa5532989 100644 --- a/usr.sbin/rad/rad.c +++ b/usr.sbin/rad/rad.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rad.c,v 1.3 2018/07/11 14:01:44 florian Exp $ */ +/* $OpenBSD: rad.c,v 1.4 2018/07/11 19:05:25 florian Exp $ */ /* * Copyright (c) 2018 Florian Obser @@ -83,6 +83,8 @@ uint32_t cmd_opts; void main_sig_handler(int sig, short event, void *arg) { + struct rad_conf empty_conf; + /* * Normal signal handler rules don't apply because libevent * decouples for us. @@ -91,7 +93,10 @@ main_sig_handler(int sig, short event, void *arg) switch (sig) { case SIGTERM: case SIGINT: - main_shutdown(); + memset(&empty_conf, 0, sizeof(empty_conf)); + (void)main_imsg_send_config(&empty_conf); + (void)main_imsg_compose_frontend(IMSG_SHUTDOWN, 0, NULL, 0); + break; case SIGHUP: if (main_reload() == -1) log_warnx("configuration reload failed"); @@ -414,6 +419,9 @@ main_dispatch_frontend(int fd, short event, void *bula) memcpy(&verbose, imsg.data, sizeof(verbose)); log_setverbose(verbose); break; + case IMSG_SHUTDOWN: + shut = 1; + break; default: log_debug("%s: error handling imsg %d", __func__, imsg.hdr.type); diff --git a/usr.sbin/rad/rad.h b/usr.sbin/rad/rad.h index ee9b32dc86a..cb1d8c8aa71 100644 --- a/usr.sbin/rad/rad.h +++ b/usr.sbin/rad/rad.h @@ -1,4 +1,4 @@ -/* $OpenBSD: rad.h,v 1.5 2018/07/11 17:32:05 florian Exp $ */ +/* $OpenBSD: rad.h,v 1.6 2018/07/11 19:05:25 florian Exp $ */ /* * Copyright (c) 2018 Florian Obser @@ -63,6 +63,7 @@ enum imsg_type { IMSG_SEND_RA, IMSG_UPDATE_IF, IMSG_REMOVE_IF, + IMSG_SHUTDOWN, IMSG_SOCKET_IPC }; -- 2.20.1