Preserve intended chronological order of leases in
authorkrw <krw@openbsd.org>
Wed, 30 Apr 2014 15:11:00 +0000 (15:11 +0000)
committerkrw <krw@openbsd.org>
Wed, 30 Apr 2014 15:11:00 +0000 (15:11 +0000)
dhclient.leases.<if> files by writing out in reverse the
reverse-chronological-order TAILQ client->leases.

Found while trying to restore static lease functionality.

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

index 894e7e7..e6a7b82 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: dhclient.c,v 1.299 2014/04/21 15:26:50 krw Exp $      */
+/*     $OpenBSD: dhclient.c,v 1.300 2014/04/30 15:11:00 krw Exp $      */
 
 /*
  * Copyright 2004 Henning Brauer <henning@openbsd.org>
@@ -1659,7 +1659,15 @@ rewrite_client_leases(void)
        fflush(leaseFile);
        rewind(leaseFile);
 
-       TAILQ_FOREACH(lp, &client->leases, next) {
+       /*
+        * The leases file is kept in chronological order, with the
+        * most recently bound lease last. When the file was read
+        * leases that were not expired were added to the head of the
+        * TAILQ client->leases as they were read. Therefore write out
+        * the leases in client->leases in reverse order to recreate
+        * the chonological order required.
+        */
+       TAILQ_FOREACH_REVERSE(lp, &client->leases, _leases, next) {
                /* Skip any leases that duplicate the active lease address. */
                if (client->active && lp->address.s_addr ==
                    client->active->address.s_addr)
index 74ea513..435c3ce 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: dhcpd.h,v 1.137 2014/04/17 09:59:30 krw Exp $ */
+/*     $OpenBSD: dhcpd.h,v 1.138 2014/04/30 15:11:00 krw Exp $ */
 
 /*
  * Copyright (c) 2004 Henning Brauer <henning@openbsd.org>
@@ -154,7 +154,7 @@ struct client_state {
        struct client_lease     *active;
        struct client_lease     *new;
        TAILQ_HEAD(, client_lease) offered_leases;
-       TAILQ_HEAD(, client_lease) leases;
+       TAILQ_HEAD(_leases, client_lease) leases;
        enum dhcp_state          state;
        struct in_addr           destination;
        int                      flags;