From 143af180a959ed4dd7ce4f834f80c514aee43de3 Mon Sep 17 00:00:00 2001 From: krw Date: Tue, 9 Mar 2021 14:32:24 +0000 Subject: [PATCH] Replace time_t startup_time with struct timespec link_timeout. Feedback from otto@ --- sbin/dhclient/dhclient.c | 21 +++++++++++++-------- sbin/dhclient/dhcpd.h | 4 ++-- sbin/dhclient/dispatch.c | 6 ++++-- 3 files changed, 19 insertions(+), 12 deletions(-) diff --git a/sbin/dhclient/dhclient.c b/sbin/dhclient/dhclient.c index 4260a8806fa..b45dc868f6c 100644 --- a/sbin/dhclient/dhclient.c +++ b/sbin/dhclient/dhclient.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dhclient.c,v 1.709 2021/03/04 02:00:42 krw Exp $ */ +/* $OpenBSD: dhclient.c,v 1.710 2021/03/09 14:32:24 krw Exp $ */ /* * Copyright 2004 Henning Brauer @@ -1386,9 +1386,6 @@ set_interval(struct interface_info *ifi, time_t cur_time) break; } - if (cur_time < ifi->startup_time + config->link_interval) - interval = 1; - ifi->interval = interval ? interval : 1; } @@ -1416,17 +1413,22 @@ set_secs(struct interface_info *ifi, time_t cur_time) void send_discover(struct interface_info *ifi) { - time_t cur_time; + struct timespec now; ssize_t rslt; + time_t cur_time; - time(&cur_time); + clock_gettime(CLOCK_REALTIME, &now); + cur_time = now.tv_sec; if (cur_time > ifi->first_sending + config->offer_interval) { state_panic(ifi); return; } - set_interval(ifi, cur_time); + if (timespeccmp(&now, &ifi->link_timeout, <)) + ifi->interval = 1; + else + set_interval(ifi, cur_time); set_secs(ifi, cur_time); rslt = send_packet(ifi, inaddr_any, inaddr_broadcast, "DHCPDISCOVER"); @@ -1530,7 +1532,10 @@ send_request(struct interface_info *ifi) return; } - set_interval(ifi, cur_time); + if (timespeccmp(&now, &ifi->link_timeout, <)) + ifi->interval = 1; + else + set_interval(ifi, cur_time); set_secs(ifi, cur_time); rslt = send_packet(ifi, from, destination.sin_addr, "DHCPREQUEST"); diff --git a/sbin/dhclient/dhcpd.h b/sbin/dhclient/dhcpd.h index 6634baaba25..08ac22f3ddd 100644 --- a/sbin/dhclient/dhcpd.h +++ b/sbin/dhclient/dhcpd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: dhcpd.h,v 1.295 2021/02/24 16:18:59 krw Exp $ */ +/* $OpenBSD: dhcpd.h,v 1.296 2021/03/09 14:32:24 krw Exp $ */ /* * Copyright (c) 2004 Henning Brauer @@ -140,7 +140,7 @@ struct interface_info { void (*timeout_func)(struct interface_info *); uint16_t secs; time_t first_sending; - time_t startup_time; + struct timespec link_timeout; enum dhcp_state state; struct in_addr destination; time_t interval; diff --git a/sbin/dhclient/dispatch.c b/sbin/dhclient/dispatch.c index fe71398702d..8d8eda6d83d 100644 --- a/sbin/dhclient/dispatch.c +++ b/sbin/dhclient/dispatch.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dispatch.c,v 1.170 2021/03/02 16:17:26 krw Exp $ */ +/* $OpenBSD: dispatch.c,v 1.171 2021/03/09 14:32:24 krw Exp $ */ /* * Copyright 2004 Henning Brauer @@ -83,6 +83,7 @@ void flush_unpriv_ibuf(void); void dispatch(struct interface_info *ifi, int routefd) { + const struct timespec link_intvl = {config->link_interval, 0}; struct pollfd fds[3]; struct timespec timeout; struct timespec *ts; @@ -95,7 +96,8 @@ dispatch(struct interface_info *ifi, int routefd) while (quit == 0 || quit == RESTART) { if (quit == RESTART) { quit = 0; - time(&ifi->startup_time); + clock_gettime(CLOCK_REALTIME, &ifi->link_timeout); + timespecadd(&ifi->link_timeout, &link_intvl, &ifi->link_timeout); free(ifi->configured); ifi->configured = NULL; free(ifi->unwind_info); -- 2.20.1