From a1ae353a379c52a65c469ecb23fb0d29b2907432 Mon Sep 17 00:00:00 2001 From: krw Date: Sat, 24 Jun 2017 23:32:57 +0000 Subject: [PATCH] Tweak handling of HUP and new LLADDR. Just use expose and use sighup() function. Don't exit dispatch() loop on SIGHUP, wait for privileged child to execvp() dhclient. Eliminate struct imsg_hup since its contents were not being used except in priv_cleanup(). And 'active_addr' works just as well there. Cleaner and eliminates some extraneous log entries. --- sbin/dhclient/dhclient.c | 19 ++++++------------- sbin/dhclient/dhcpd.h | 3 ++- sbin/dhclient/dispatch.c | 31 +++++++++++-------------------- sbin/dhclient/kroute.c | 8 ++++---- sbin/dhclient/privsep.c | 5 ++--- sbin/dhclient/privsep.h | 8 ++------ 6 files changed, 27 insertions(+), 47 deletions(-) diff --git a/sbin/dhclient/dhclient.c b/sbin/dhclient/dhclient.c index 64b915531ce..8e90b3c5bfb 100644 --- a/sbin/dhclient/dhclient.c +++ b/sbin/dhclient/dhclient.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dhclient.c,v 1.446 2017/06/24 10:09:26 krw Exp $ */ +/* $OpenBSD: dhclient.c,v 1.447 2017/06/24 23:32:57 krw Exp $ */ /* * Copyright 2004 Henning Brauer @@ -227,7 +227,7 @@ void routehandler(struct interface_info *ifi) { char ntoabuf[INET_ADDRSTRLEN]; - struct in_addr a, b; + struct in_addr a; struct sockaddr *sa; struct ifa_msghdr *ifam; struct ether_addr hw; @@ -343,12 +343,8 @@ routehandler(struct interface_info *ifi) /* Tell the priv process active_addr is gone. */ log_warnx("Active address (%s) deleted; exiting", inet_ntoa(ifi->active->address)); - memset(&b, 0, sizeof(b)); - add_address(b, b); - /* No need to write resolv.conf now. */ - ifi->flags &= ~IFI_IS_RESPONSIBLE; - quit = INTERNALSIG; - break; + sendhup(); + goto done; } if (deleting.s_addr != INADDR_ANY) { strlcpy(ntoabuf, inet_ntoa(a), sizeof(ntoabuf)); @@ -375,7 +371,7 @@ routehandler(struct interface_info *ifi) get_hw_address(ifi); if (memcmp(&hw, &ifi->hw_address, sizeof(hw))) { log_warnx("LLADDR changed; restarting"); - quit = SIGHUP; + sendhup(); goto done; } } @@ -2030,7 +2026,6 @@ res_hnok_list(const char *names) void fork_privchld(struct interface_info *ifi, int fd, int fd2) { - struct imsg_hup imsg; struct pollfd pfd[1]; struct imsgbuf *priv_ibuf; ssize_t n; @@ -2106,9 +2101,7 @@ fork_privchld(struct interface_info *ifi, int fd, int fd2) * routes, possibly preventing NFS from properly shutting down. */ if (quit != SIGTERM) { - memset(&imsg, 0, sizeof(imsg)); - imsg.addr = active_addr; - priv_cleanup(ifi, &imsg); + priv_cleanup(ifi); } if (quit == SIGHUP) { diff --git a/sbin/dhclient/dhcpd.h b/sbin/dhclient/dhcpd.h index 7c8170959d7..0c20a0ea824 100644 --- a/sbin/dhclient/dhcpd.h +++ b/sbin/dhclient/dhcpd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: dhcpd.h,v 1.194 2017/06/24 10:09:26 krw Exp $ */ +/* $OpenBSD: dhcpd.h,v 1.195 2017/06/24 23:32:57 krw Exp $ */ /* * Copyright (c) 2004 Henning Brauer @@ -212,6 +212,7 @@ void interface_link_forceup(char *); int interface_status(struct interface_info *); int get_rdomain(char *); void get_hw_address(struct interface_info *); +void sendhup(void); /* tables.c */ extern const struct option dhcp_options[256]; diff --git a/sbin/dhclient/dispatch.c b/sbin/dhclient/dispatch.c index 3e7a4bdbd98..89b23cb6815 100644 --- a/sbin/dhclient/dispatch.c +++ b/sbin/dhclient/dispatch.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dispatch.c,v 1.126 2017/06/21 15:24:34 krw Exp $ */ +/* $OpenBSD: dispatch.c,v 1.127 2017/06/24 23:32:57 krw Exp $ */ /* * Copyright 2004 Henning Brauer @@ -71,7 +71,6 @@ void packethandler(struct interface_info *ifi); -void sendhup(struct client_lease *); void get_hw_address(struct interface_info *ifi) @@ -123,7 +122,12 @@ dispatch(struct interface_info *ifi) time_t cur_time, howlong; void (*func)(struct interface_info *); - while (quit == 0) { + while (quit == 0 || quit == SIGHUP) { + if (quit == SIGHUP) { + log_warnx("%s; restarting", strsignal(quit)); + sendhup(); + } + if (ifi->timeout_func) { time(&cur_time); if (ifi->timeout <= cur_time) { @@ -183,14 +187,8 @@ dispatch(struct interface_info *ifi) } } - if (quit == SIGHUP) { - /* Tell [priv] process that HUP has occurred. */ - sendhup(ifi->active); - log_warnx("%s; restarting", strsignal(quit)); - exit (0); - } else if (quit != INTERNALSIG) { + if (quit != INTERNALSIG) fatalx("%s", strsignal(quit)); - } } void @@ -310,21 +308,14 @@ get_rdomain(char *name) } /* - * Inform the [priv] process a HUP was received and it should restart. + * Inform the [priv] process a HUP was received. */ void -sendhup(struct client_lease *active) +sendhup(void) { - struct imsg_hup imsg; int rslt; - if (active) - imsg.addr = active->address; - else - imsg.addr.s_addr = INADDR_ANY; - - rslt = imsg_compose(unpriv_ibuf, IMSG_HUP, 0, 0, -1, - &imsg, sizeof(imsg)); + rslt = imsg_compose(unpriv_ibuf, IMSG_HUP, 0, 0, -1, NULL, 0); if (rslt == -1) log_warn("sendhup: imsg_compose"); diff --git a/sbin/dhclient/kroute.c b/sbin/dhclient/kroute.c index 878496f8293..b922f976b9b 100644 --- a/sbin/dhclient/kroute.c +++ b/sbin/dhclient/kroute.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kroute.c,v 1.92 2017/06/23 15:40:56 krw Exp $ */ +/* $OpenBSD: kroute.c,v 1.93 2017/06/24 23:32:57 krw Exp $ */ /* * Copyright 2012 Kenneth R Westerback @@ -750,7 +750,7 @@ priv_add_address(struct interface_info *ifi, struct imsg_add_address *imsg) * priv_cleanup removes dhclient installed routes and address. */ void -priv_cleanup(struct interface_info *ifi, struct imsg_hup *imsg) +priv_cleanup(struct interface_info *ifi) { struct imsg_flush_routes fimsg; struct imsg_delete_address dimsg; @@ -758,10 +758,10 @@ priv_cleanup(struct interface_info *ifi, struct imsg_hup *imsg) fimsg.zapzombies = 0; /* Only zapzombies when binding a lease. */ priv_flush_routes(ifi, &fimsg); - if (imsg->addr.s_addr == INADDR_ANY) + if (active_addr.s_addr == INADDR_ANY) return; - dimsg.addr = imsg->addr; + dimsg.addr = active_addr; priv_delete_address(ifi, &dimsg); } diff --git a/sbin/dhclient/privsep.c b/sbin/dhclient/privsep.c index 7e7d2205d47..446570c3f3d 100644 --- a/sbin/dhclient/privsep.c +++ b/sbin/dhclient/privsep.c @@ -1,4 +1,4 @@ -/* $OpenBSD: privsep.c,v 1.49 2017/06/24 10:09:26 krw Exp $ */ +/* $OpenBSD: privsep.c,v 1.50 2017/06/24 23:32:57 krw Exp $ */ /* * Copyright (c) 2004 Henning Brauer @@ -98,8 +98,7 @@ dispatch_imsg(struct interface_info *ifi, struct imsgbuf *ibuf) break; case IMSG_HUP: - if (imsg.hdr.len != IMSG_HEADER_SIZE + - sizeof(struct imsg_hup)) + if (imsg.hdr.len != IMSG_HEADER_SIZE) log_warnx("bad IMSG_HUP"); else { imsg_free(&imsg); diff --git a/sbin/dhclient/privsep.h b/sbin/dhclient/privsep.h index ed2f9c652f6..777b96d7ae4 100644 --- a/sbin/dhclient/privsep.h +++ b/sbin/dhclient/privsep.h @@ -1,4 +1,4 @@ -/* $OpenBSD: privsep.h,v 1.37 2017/06/24 10:09:26 krw Exp $ */ +/* $OpenBSD: privsep.h,v 1.38 2017/06/24 23:32:57 krw Exp $ */ /* * Copyright (c) 2004 Henning Brauer @@ -27,10 +27,6 @@ enum imsg_code { IMSG_WRITE_RESOLV_CONF }; -struct imsg_hup { - struct in_addr addr; -}; - struct imsg_delete_address { struct in_addr addr; }; @@ -78,4 +74,4 @@ void priv_add_address(struct interface_info *, struct imsg_add_address *); void priv_set_interface_mtu(struct interface_info *, struct imsg_set_interface_mtu *); -void priv_cleanup(struct interface_info *, struct imsg_hup *); +void priv_cleanup(struct interface_info *); -- 2.20.1