summaryrefslogtreecommitdiffstats
path: root/sbin/dhclient
diff options
context:
space:
mode:
authorkrw <krw@openbsd.org>2021-02-22 02:19:03 +0000
committerkrw <krw@openbsd.org>2021-02-22 02:19:03 +0000
commitbf5d9e5078290a1df11f78563221ef5b4348ba3c (patch)
treee5fd68beeacd1dcd4bba2cf3d236913687c37bae /sbin/dhclient
parentUse the F_CHECK_SENT and F_CHECK_DONE flags to determine whether a (diff)
downloadwireguard-openbsd-bf5d9e5078290a1df11f78563221ef5b4348ba3c.tar.xz
wireguard-openbsd-bf5d9e5078290a1df11f78563221ef5b4348ba3c.zip
Switch reboot timing to timespec, the better to handle the
default reboot interval of 1 sec. Gives the DHCP server a fairer shot at replying before the timeout expires. ok millert@
Diffstat (limited to 'sbin/dhclient')
-rw-r--r--sbin/dhclient/dhclient.c16
-rw-r--r--sbin/dhclient/dhcpd.h3
2 files changed, 13 insertions, 6 deletions
diff --git a/sbin/dhclient/dhclient.c b/sbin/dhclient/dhclient.c
index e621494ed81..cc84a8bebe2 100644
--- a/sbin/dhclient/dhclient.c
+++ b/sbin/dhclient/dhclient.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: dhclient.c,v 1.697 2021/02/21 18:16:59 krw Exp $ */
+/* $OpenBSD: dhclient.c,v 1.698 2021/02/22 02:19:03 krw Exp $ */
/*
* Copyright 2004 Henning Brauer <henning@openbsd.org>
@@ -813,7 +813,9 @@ state_preboot(struct interface_info *ifi)
void
state_reboot(struct interface_info *ifi)
{
- struct client_lease *lease;
+ const struct timespec reboot_intvl = {config->reboot_interval, 0};
+ struct timespec now;
+ struct client_lease *lease;
cancel_timeout(ifi);
@@ -836,7 +838,9 @@ state_reboot(struct interface_info *ifi)
make_request(ifi, ifi->active);
ifi->destination.s_addr = INADDR_BROADCAST;
- time(&ifi->first_sending);
+ clock_gettime(CLOCK_REALTIME, &now);
+ ifi->first_sending = now.tv_sec;
+ timespecadd(&now, &reboot_intvl, &ifi->reboot_timeout);
ifi->interval = 0;
send_request(ifi);
@@ -1529,11 +1533,13 @@ send_request(struct interface_info *ifi)
{
struct sockaddr_in destination;
struct in_addr from;
+ struct timespec now;
ssize_t rslt;
time_t cur_time, interval;
cancel_timeout(ifi);
- time(&cur_time);
+ clock_gettime(CLOCK_REALTIME, &now);
+ cur_time = now.tv_sec;
if (log_getverbose())
tick_msg("lease", TICK_WAIT);
@@ -1542,7 +1548,7 @@ send_request(struct interface_info *ifi)
switch (ifi->state) {
case S_REBOOTING:
- if (interval > config->reboot_interval)
+ if (timespeccmp(&now, &ifi->reboot_timeout, >=))
ifi->state = S_INIT;
else {
destination.sin_addr.s_addr = INADDR_BROADCAST;
diff --git a/sbin/dhclient/dhcpd.h b/sbin/dhclient/dhcpd.h
index 9660de954af..e874d04c33c 100644
--- a/sbin/dhclient/dhcpd.h
+++ b/sbin/dhclient/dhcpd.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: dhcpd.h,v 1.292 2021/02/21 18:16:59 krw Exp $ */
+/* $OpenBSD: dhcpd.h,v 1.293 2021/02/22 02:19:03 krw Exp $ */
/*
* Copyright (c) 2004 Henning Brauer <henning@openbsd.org>
@@ -136,6 +136,7 @@ struct interface_info {
int sent_packet_length;
uint32_t xid;
struct timespec timeout;
+ struct timespec reboot_timeout;
time_t expiry, rebind;
void (*timeout_func)(struct interface_info *);
uint16_t secs;