From cc08537da087ebff8723590fc54e2336868d3740 Mon Sep 17 00:00:00 2001 From: Antonio Huete Jimenez Date: Sat, 4 Aug 2012 20:36:23 +0200 Subject: [PATCH] dhclient - Tweak leases file handling. - Write out new leases file every time a lease is obtained. i.e. don't append 20 leases before cleaning it up. - Write new leases file after calling dhclient-script to implement new info. Gets interface configured first, and makes it more likely the leases file reflects most current configuration. Taken-from: OpenBSD --- sbin/dhclient/dhclient.c | 29 +++++++++++++---------------- sbin/dhclient/dhcpd.h | 4 ++-- 2 files changed, 15 insertions(+), 18 deletions(-) diff --git a/sbin/dhclient/dhclient.c b/sbin/dhclient/dhclient.c index 2f5b3ca83f..816ba2c785 100644 --- a/sbin/dhclient/dhclient.c +++ b/sbin/dhclient/dhclient.c @@ -1,4 +1,4 @@ -/* $OpenBSD: src/sbin/dhclient/dhclient.c,v 1.141 2011/05/11 14:38:36 krw Exp $ */ +/* $OpenBSD: src/sbin/dhclient/dhclient.c,v 1.142 2011/12/10 15:55:43 krw Exp $ */ /* * Copyright 2004 Henning Brauer @@ -643,9 +643,6 @@ dhcpack(struct iaddr client_addr, struct option_data *options) void bind_lease(void) { - /* Write out the new lease. */ - write_client_lease(client->new, 0); - /* Run the client script with the new parameters. */ script_init((client->state == S_REQUESTING ? "BOUND" : (client->state == S_RENEWING ? "RENEW" : @@ -661,6 +658,9 @@ bind_lease(void) client->active = client->new; client->new = NULL; + /* Write out new leases file. */ + rewrite_client_leases(); + /* Set up a timeout to start the renewal process. */ add_timeout(client->active->renewal, state_bound); @@ -1371,10 +1371,15 @@ rewrite_client_leases(void) fflush(leaseFile); rewind(leaseFile); - for (lp = client->leases; lp; lp = lp->next) - write_client_lease(lp, 1); + for (lp = client->leases; lp; lp = lp->next) { + if (client->active && addr_eq(lp->address, + client->active->address)) + continue; + write_client_lease(lp); + } + if (client->active) - write_client_lease(client->active, 1); + write_client_lease(client->active); fflush(leaseFile); ftruncate(fileno(leaseFile), ftello(leaseFile)); @@ -1382,19 +1387,11 @@ rewrite_client_leases(void) } void -write_client_lease(struct client_lease *lease, int rewrite) +write_client_lease(struct client_lease *lease) { - static int leases_written; struct tm *t; int i; - if (!rewrite) { - if (leases_written++ > 20) { - rewrite_client_leases(); - leases_written = 0; - } - } - /* If the lease came from the config file, we don't need to stash a copy in the lease database. */ if (lease->is_static) diff --git a/sbin/dhclient/dhcpd.h b/sbin/dhclient/dhcpd.h index 75f4332253..2397f3348a 100644 --- a/sbin/dhclient/dhcpd.h +++ b/sbin/dhclient/dhcpd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: src/sbin/dhclient/dhcpd.h,v 1.73 2011/05/11 14:38:36 krw Exp $ */ +/* $OpenBSD: src/sbin/dhclient/dhcpd.h,v 1.74 2011/12/10 15:55:43 krw Exp $ */ /* * Copyright (c) 2004 Henning Brauer @@ -303,7 +303,7 @@ void make_decline(struct client_lease *); void free_client_lease(struct client_lease *); void rewrite_client_leases(void); -void write_client_lease(struct client_lease *, int); +void write_client_lease(struct client_lease *); void priv_script_init(char *); void priv_script_write_params(char *, struct client_lease *); -- 2.41.0