Why aren't you just deleting the lease file on shutdown?
On Dec 8, 2014 10:04 AM, Jurjen Oskam jur...@osk.am wrote:
Hi,
My (residential) ISP assigns me an IP address using DHCP. The lease time
is 7
days or so. I just put dhcp in hostname.re1 and everything works, except
for
a minor annoyance.
When re1 goes down (e.g. because of a reboot) the ISP *requires* a
successful
DHCP exchange to occur before it enables the link on a layer 3 level. It
does
not matter whether there still is a valid lease or not: after re1 goes
down,
there *has* to be a DHCP exchange otherwise the link won't work.
What makes this worse is that the DHCP server does not always immediately
respond after re1 comes back up. It regularly happens that dhclient
concludes
that the DHCP server is unreachable, finds that it still has a valid lease
in the lease file, and it'll use that. The problem with this is that
dhclient
doesn't seem to try to contact the server anymore. With long lease times,
it
could take days for dhclient to try to renew the lease.
I've tried using timeout 0 in dhclient.conf, but that only causes
dhclient
to immediately using the lease from the lease file (after trying to
reacquire
its previous address for ten seconds). Using an arbitrarily high timeout
value doesn't seem right.
The retry setting doesn't seem to help in this case: by default it's set to
5 minutes, but in my testing I noticed that once dhclient is bound to a
lease
from the lease file, this setting doesn't seem to be used anymore.
Perhaps I've missed something, but I concluded that in my scenario lease
files are never useful. I modified dhclient to accept a new option called
no-lease-file in dhclient.conf. A diff against -current is below. I've
tested it lightly on a laptop, and it seems to work OK. I've been using
roughly the same diff against -stable for a day or two.
Index: sbin/dhclient/clparse.c
===
RCS file: /cvs/src/sbin/dhclient/clparse.c,v
retrieving revision 1.90
diff -u -p -r1.90 clparse.c
--- sbin/dhclient/clparse.c 3 Nov 2014 22:06:39 - 1.90
+++ sbin/dhclient/clparse.c 8 Dec 2014 10:07:39 -
@@ -67,6 +67,7 @@ read_client_conf(void)
new_parse(path_dhclient_conf);
/* Set some defaults. */
+ config-use_lease_file = 1;
config-link_timeout = 10;
config-timeout = 60;
config-select_interval = 0;
@@ -153,6 +154,7 @@ read_client_leases(void)
* TOK_BACKOFF_CUTOFF number |
* TOK_INITIAL_INTERVAL number |
* interface-declaration |
+ * TOK_NO_LEASE_FILE |
* TOK_LEASE client-lease-statement |
* TOK_ALIAS client-lease-statement |
* TOK_REJECT reject-statement
@@ -240,6 +242,10 @@ parse_client_statement(FILE *cfile)
break;
case TOK_INTERFACE:
parse_interface_declaration(cfile);
+ break;
+ case TOK_NO_LEASE_FILE:
+ config-use_lease_file = 0;
+ parse_semi(cfile);
break;
case TOK_LEASE:
parse_client_lease_statement(cfile, 1);
Index: sbin/dhclient/conflex.c
===
RCS file: /cvs/src/sbin/dhclient/conflex.c,v
retrieving revision 1.29
diff -u -p -r1.29 conflex.c
--- sbin/dhclient/conflex.c 5 May 2014 18:02:49 - 1.29
+++ sbin/dhclient/conflex.c 8 Dec 2014 10:07:39 -
@@ -352,6 +352,7 @@ static const struct keywords {
{ media, TOK_MEDIA },
{ medium, TOK_MEDIUM },
{ next-server,TOK_NEXT_SERVER },
+ { no-lease-file, TOK_NO_LEASE_FILE },
{ option, TOK_OPTION },
{ prepend,TOK_PREPEND },
{ rebind, TOK_REBIND },
Index: sbin/dhclient/dhclient.c
===
RCS file: /cvs/src/sbin/dhclient/dhclient.c,v
retrieving revision 1.343
diff -u -p -r1.343 dhclient.c
--- sbin/dhclient/dhclient.c8 Dec 2014 02:04:58 - 1.343
+++ sbin/dhclient/dhclient.c8 Dec 2014 10:07:39 -
@@ -549,15 +549,17 @@ main(int argc, char *argv[])
close(tailfd);
}
- if ((fd = open(path_dhclient_db,
- O_RDONLY|O_EXLOCK|O_CREAT|O_NOFOLLOW, 0640)) == -1)
- error(can't open and lock %s: %s, path_dhclient_db,
- strerror(errno));
- read_client_leases();
- if ((leaseFile = fopen(path_dhclient_db, w)) == NULL)
- error(can't open %s: %s, path_dhclient_db,
strerror(errno));
- rewrite_client_leases();
- close(fd);
+ if (config-use_lease_file) {
+ if ((fd = open(path_dhclient_db,
+