Replace time_t startup_time with struct timespec link_timeout.
authorkrw <krw@openbsd.org>
Tue, 9 Mar 2021 14:32:24 +0000 (14:32 +0000)
committerkrw <krw@openbsd.org>
Tue, 9 Mar 2021 14:32:24 +0000 (14:32 +0000)
Feedback from otto@

sbin/dhclient/dhclient.c
sbin/dhclient/dhcpd.h
sbin/dhclient/dispatch.c

index 4260a88..b45dc86 100644 (file)
@@ -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 <henning@openbsd.org>
@@ -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");
index 6634baa..08ac22f 100644 (file)
@@ -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 <henning@openbsd.org>
@@ -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;
index fe71398..8d8eda6 100644 (file)
@@ -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 <henning@openbsd.org>
@@ -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);