Tweak handling of HUP and new LLADDR. Just use expose and use sighup()
authorkrw <krw@openbsd.org>
Sat, 24 Jun 2017 23:32:57 +0000 (23:32 +0000)
committerkrw <krw@openbsd.org>
Sat, 24 Jun 2017 23:32:57 +0000 (23:32 +0000)
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
sbin/dhclient/dhcpd.h
sbin/dhclient/dispatch.c
sbin/dhclient/kroute.c
sbin/dhclient/privsep.c
sbin/dhclient/privsep.h

index 64b9155..8e90b3c 100644 (file)
@@ -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 <henning@openbsd.org>
@@ -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) {
index 7c81709..0c20a0e 100644 (file)
@@ -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 <henning@openbsd.org>
@@ -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];
index 3e7a4bd..89b23cb 100644 (file)
@@ -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 <henning@openbsd.org>
@@ -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");
 
index 878496f..b922f97 100644 (file)
@@ -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 <krw@openbsd.org>
@@ -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);
 }
 
index 7e7d220..446570c 100644 (file)
@@ -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 <henning@openbsd.org>
@@ -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);
index ed2f9c6..777b96d 100644 (file)
@@ -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 <henning@openbsd.org>
@@ -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 *);