Move timer fields 'expiry" and "rebind" out of struct client_lease
authorkrw <krw@openbsd.org>
Sun, 3 Dec 2017 20:53:28 +0000 (20:53 +0000)
committerkrw <krw@openbsd.org>
Sun, 3 Dec 2017 20:53:28 +0000 (20:53 +0000)
and into struct interface_info. Nuke set_lease_times().

sbin/dhclient/clparse.c
sbin/dhclient/dhclient.c
sbin/dhclient/dhcpd.h

index 3655195..5ad5569 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: clparse.c,v 1.150 2017/11/09 12:34:25 krw Exp $       */
+/*     $OpenBSD: clparse.c,v 1.151 2017/12/03 20:53:28 krw Exp $       */
 
 /* Parser for dhclient config and lease files. */
 
@@ -588,7 +588,6 @@ parse_client_lease_declaration(FILE *cfile, struct client_lease *lease,
                    == 0)
                        return;
                lease->epoch = betoh64(lease->epoch);
-               set_lease_times(lease);
                break;
        case TOK_EXPIRE:
                /* 'expire' is just a comment. See 'epoch'. */
index 5124421..1a41f97 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: dhclient.c,v 1.531 2017/12/03 16:09:14 krw Exp $      */
+/*     $OpenBSD: dhclient.c,v 1.532 2017/12/03 20:53:28 krw Exp $      */
 
 /*
  * Copyright 2004 Henning Brauer <henning@openbsd.org>
@@ -763,6 +763,8 @@ state_reboot(struct interface_info *ifi)
                state_init(ifi);
                return;
        }
+       ifi->expiry = lease_expiry(ifi->active);
+       ifi->rebind = lease_rebind(ifi->active);
 
        ifi->xid = arc4random();
        make_request(ifi, ifi->active);
@@ -996,11 +998,22 @@ bind_lease(struct interface_info *ifi)
        time(&cur_time);
        lease = apply_defaults(ifi->offer);
 
-       set_lease_times(lease);
+       /*
+        * Take the server-provided times if available.  Otherwise
+        * figure them out according to the spec.
+        *
+        * expiry  == time to discard lease.
+        * renewal == time to renew lease from server that provided it.
+        * rebind  == time to renew lease from any server.
+        *
+        * 0 <= renewal <= rebind <= expiry
+        * &&
+        * expiry >= MIN(time_max, 60)
+        */
+       ifi->expiry = lease_expiry(lease);
+       ifi->rebind = lease_rebind(lease);
 
-       ifi->offer->expiry = lease->expiry;
        renewal = lease_renewal(lease) - cur_time;
-       ifi->offer->rebind = lease->rebind;
 
        /*
         * A duplicate proposal once we are responsible & S_RENEWING means we
@@ -1410,8 +1423,7 @@ send_request(struct interface_info *ifi)
        /*
         * If the lease has expired go back to the INIT state.
         */
-       if (ifi->state != S_REQUESTING &&
-           cur_time > ifi->active->expiry) {
+       if (ifi->state != S_REQUESTING && cur_time > ifi->expiry) {
                ifi->active = NULL;
                ifi->state = S_INIT;
                state_init(ifi);
@@ -1436,8 +1448,8 @@ send_request(struct interface_info *ifi)
         * timeout to the expiry time.
         */
        if (ifi->state != S_REQUESTING && cur_time + ifi->interval >
-           ifi->active->expiry)
-               ifi->interval = ifi->active->expiry - cur_time + 1;
+           ifi->expiry)
+               ifi->interval = ifi->expiry - cur_time + 1;
 
        /*
         * If the reboot timeout has expired, or the lease rebind time has
@@ -1447,13 +1459,13 @@ send_request(struct interface_info *ifi)
        memset(&destination, 0, sizeof(destination));
        if (ifi->state == S_REQUESTING ||
            ifi->state == S_REBOOTING ||
-           cur_time > ifi->active->rebind ||
+           cur_time > ifi->rebind ||
            interval > config->reboot_timeout)
                destination.sin_addr.s_addr = INADDR_BROADCAST;
        else
                destination.sin_addr.s_addr = ifi->destination.s_addr;
 
-       if (ifi->state != S_REQUESTING)
+       if (ifi->state != S_REQUESTING && ifi->active != NULL)
                from.s_addr = ifi->active->address.s_addr;
        else
                from.s_addr = INADDR_ANY;
@@ -2359,8 +2371,6 @@ clone_lease(struct client_lease *oldlease)
                goto cleanup;
 
        newlease->epoch = oldlease->epoch;
-       newlease->expiry = oldlease->expiry;
-       newlease->rebind = oldlease->rebind;
        newlease->is_static = oldlease->is_static;
        newlease->address = oldlease->address;
        newlease->next_server = oldlease->next_server;
@@ -2439,28 +2449,6 @@ apply_ignore_list(char *ignore_list)
        memcpy(config->ignored_options, list, sizeof(config->ignored_options));
 }
 
-void
-set_lease_times(struct client_lease *lease)
-{
-       if (lease->epoch == 0)
-               time(&lease->epoch);
-
-       /*
-        * Take the server-provided times if available.  Otherwise
-        * figure them out according to the spec.
-        *
-        * expiry  == time to discard lease.
-        * renewal == time to renew lease from server that provided it.
-        * rebind  == time to renew lease from any server.
-        *
-        * 0 <= renewal <= rebind <= expiry
-        * &&
-        * expiry >= MIN(time_max, 60)
-        */
-       lease->expiry = lease_expiry(lease);
-       lease->rebind = lease_rebind(lease);
-}
-
 void
 take_charge(struct interface_info *ifi, int routefd)
 {
@@ -2547,13 +2535,15 @@ get_recorded_lease(struct interface_info *ifi)
                if (lease_expiry(lp) <= cur_time)
                        continue;
 
-               if (lp->is_static != 0) {
-                       time(&lp->epoch);
-                       set_lease_times(lp);
-               }
+               if (lp->is_static != 0)
+                       lp->epoch = 0;
+
                break;
        }
 
+       if (lp->epoch == 0)
+               time(&lp->epoch);
+
        return lp;
 }
 
@@ -2603,6 +2593,7 @@ lease_expiry(struct client_lease *lease)
 
        return lease->epoch + expiry;
 }
+
 time_t
 lease_renewal(struct client_lease *lease)
 {
index ac95374..e0185f7 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: dhcpd.h,v 1.237 2017/11/24 01:39:29 krw Exp $ */
+/*     $OpenBSD: dhcpd.h,v 1.238 2017/12/03 20:53:28 krw Exp $ */
 
 /*
  * Copyright (c) 2004 Henning Brauer <henning@openbsd.org>
@@ -58,7 +58,6 @@ struct client_lease {
        TAILQ_ENTRY(client_lease) next;
        char                    *interface;
        time_t                   epoch;
-       time_t                   expiry, rebind;
        struct in_addr           address;
        struct in_addr           next_server;
        char                    *server_name;
@@ -140,6 +139,7 @@ struct interface_info {
        int                      sent_packet_length;
        uint32_t                 xid;
        time_t                   timeout;
+       time_t                   expiry, rebind;
        void                    (*timeout_func)(struct interface_info *);
        uint16_t                 secs;
        time_t                   first_sending;
@@ -223,7 +223,6 @@ void                 dhcpack(struct interface_info *, struct option_data *,char *);
 void            dhcpnak(struct interface_info *, struct option_data *,char *);
 void            free_client_lease(struct client_lease *);
 void            routehandler(struct interface_info *, int);
-void            set_lease_times(struct client_lease *);
 
 /* packet.c */
 void            assemble_eh_header(struct ether_addr, struct ether_header *);