Having 'taken charge' of the interface by eliminating other
authorkrw <krw@openbsd.org>
Tue, 27 Jul 2021 18:35:30 +0000 (18:35 +0000)
committerkrw <krw@openbsd.org>
Tue, 27 Jul 2021 18:35:30 +0000 (18:35 +0000)
dhclient instances for the interface, check if the IPv4
AUTOCONF flag is set. If it is, go quietly into that good
night and let dhcpleased do its thing, comforted by the fact
that dhcpleased knows that a new lease has been requested.

requested, tested & ok florian@

sbin/dhclient/dhclient.c

index 8cda5c6..e53538e 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: dhclient.c,v 1.723 2021/07/12 15:09:18 beck Exp $     */
+/*     $OpenBSD: dhclient.c,v 1.724 2021/07/27 18:35:30 krw Exp $      */
 
 /*
  * Copyright 2004 Henning Brauer <henning@openbsd.org>
@@ -173,6 +173,7 @@ struct client_lease *packet_to_lease(struct interface_info *,
 void go_daemon(void);
 int rdaemon(int);
 int take_charge(struct interface_info *, int, char *);
+int autoconf(struct interface_info *);
 struct client_lease *get_recorded_lease(struct interface_info *);
 
 #define ROUNDUP(a)     \
@@ -720,7 +721,11 @@ main(int argc, char *argv[])
                fatal("path_lease_db");
 
        routefd = get_routefd(ifi->rdomain);
-       fd = take_charge(ifi, routefd, path_lease_db);
+       fd = take_charge(ifi, routefd, path_lease_db);  /* Kill other dhclients. */
+       if (autoconf(ifi)) {
+               /* dhcpleased has been notified to request a new lease. */
+               return 0;
+       }
        if (fd != -1)
                read_lease_db(&ifi->lease_db);
 
@@ -2509,6 +2514,26 @@ cleanup:
        return NULL;
 }
 
+int
+autoconf(struct interface_info *ifi)
+{
+       struct ifreq            ifr;
+       int                     ioctlfd;
+
+       if ((ioctlfd = socket(AF_INET, SOCK_DGRAM, 0)) == -1)
+               fatal("socket(AF_INET, SOCK_DGRAM)");
+
+       memset(&ifr, 0, sizeof(ifr));
+       strlcpy(ifr.ifr_name, ifi->name, sizeof(ifr.ifr_name));
+
+       if (ioctl(ioctlfd, SIOCGIFXFLAGS, (caddr_t)&ifr) < 0)
+               fatal("SIOGIFXFLAGS");
+
+       close(ioctlfd);
+
+       return ifr.ifr_flags & IFXF_AUTOCONF4;
+}
+
 int
 take_charge(struct interface_info *ifi, int routefd, char *leasespath)
 {