diff options
-rw-r--r-- | sbin/dhclient/dhclient.c | 29 |
1 files changed, 27 insertions, 2 deletions
diff --git a/sbin/dhclient/dhclient.c b/sbin/dhclient/dhclient.c index 8cda5c69753..e53538eb9dc 100644 --- a/sbin/dhclient/dhclient.c +++ b/sbin/dhclient/dhclient.c @@ -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); @@ -2510,6 +2515,26 @@ cleanup: } 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) { const struct timespec max_timeout = { 9, 0 }; |