-/* $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>
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)
-/* $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>
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;