From: krw Date: Tue, 27 Jul 2021 18:35:30 +0000 (+0000) Subject: Having 'taken charge' of the interface by eliminating other X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=480796664355b2cdc76b0f050c171c33e93533ed;p=openbsd Having 'taken charge' of the interface by eliminating other 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@ --- 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 @@ -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) {