diff options
author | 2011-12-10 15:55:43 +0000 | |
---|---|---|
committer | 2011-12-10 15:55:43 +0000 | |
commit | b21596d34ce2878d2cae835773a2eeb3f58a7ed1 (patch) | |
tree | 10439be1c93dd6d38ac39650f9f78c2246d71f51 | |
parent | mail.c was removed 3 yrs 5 months ago. (diff) | |
download | wireguard-openbsd-b21596d34ce2878d2cae835773a2eeb3f58a7ed1.tar.xz wireguard-openbsd-b21596d34ce2878d2cae835773a2eeb3f58a7ed1.zip |
Tweak leases file handling.
1) Write out new leases file every time a lease is obtained. i.e. don't
append 20 leases before cleaning it up.
2) 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.
-rw-r--r-- | sbin/dhclient/dhclient.c | 29 | ||||
-rw-r--r-- | 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 54323f96008..ce3a9fc1f2e 100644 --- a/sbin/dhclient/dhclient.c +++ b/sbin/dhclient/dhclient.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dhclient.c,v 1.141 2011/05/11 14:38:36 krw Exp $ */ +/* $OpenBSD: dhclient.c,v 1.142 2011/12/10 15:55:43 krw Exp $ */ /* * Copyright 2004 Henning Brauer <henning@openbsd.org> @@ -657,9 +657,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" : @@ -675,6 +672,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); @@ -1381,10 +1381,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)); @@ -1392,19 +1397,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 fffb63d1f1b..a8ebc6e8b76 100644 --- a/sbin/dhclient/dhcpd.h +++ b/sbin/dhclient/dhcpd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: dhcpd.h,v 1.73 2011/05/11 14:38:36 krw Exp $ */ +/* $OpenBSD: dhcpd.h,v 1.74 2011/12/10 15:55:43 krw Exp $ */ /* * Copyright (c) 2004 Henning Brauer <henning@openbsd.org> @@ -306,7 +306,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 *); |