From d90a64fc87311a0394eaaf458c0dafa35e96c63a Mon Sep 17 00:00:00 2001 From: krw Date: Wed, 30 Apr 2014 15:11:00 +0000 Subject: [PATCH] Preserve intended chronological order of leases in dhclient.leases. 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 | 12 ++++++++++-- sbin/dhclient/dhcpd.h | 4 ++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/sbin/dhclient/dhclient.c b/sbin/dhclient/dhclient.c index 894e7e7d3d2..e6a7b82303e 100644 --- a/sbin/dhclient/dhclient.c +++ b/sbin/dhclient/dhclient.c @@ -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 @@ -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) diff --git a/sbin/dhclient/dhcpd.h b/sbin/dhclient/dhcpd.h index 74ea51314e8..435c3cebd65 100644 --- a/sbin/dhclient/dhcpd.h +++ b/sbin/dhclient/dhcpd.h @@ -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 @@ -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; -- 2.20.1