summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkrw <krw@openbsd.org>2017-11-09 12:34:25 +0000
committerkrw <krw@openbsd.org>2017-11-09 12:34:25 +0000
commit5def7f514bb13d8232c6f65a1b6ac43c11a24454 (patch)
treef3abbf013978e44bc5ad48b7d43ca8cee8ba4975
parentkill trailing whitespace introduced in previous commit (diff)
downloadwireguard-openbsd-5def7f514bb13d8232c6f65a1b6ac43c11a24454.tar.xz
wireguard-openbsd-5def7f514bb13d8232c6f65a1b6ac43c11a24454.zip
Use lease 'epoch' (time lease was acquired) to calculate timers for
renew/rebind/expiry. Treat renew/rebind/expiry statements in leases as comments for human consumption.
-rw-r--r--sbin/dhclient/clparse.c18
-rw-r--r--sbin/dhclient/dhclient.c23
-rw-r--r--sbin/dhclient/dhclient.leases.542
-rw-r--r--sbin/dhclient/dhcpd.h4
-rw-r--r--sbin/dhclient/parse.c61
5 files changed, 62 insertions, 86 deletions
diff --git a/sbin/dhclient/clparse.c b/sbin/dhclient/clparse.c
index c21287b3ef0..3655195059a 100644
--- a/sbin/dhclient/clparse.c
+++ b/sbin/dhclient/clparse.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: clparse.c,v 1.149 2017/11/06 13:27:19 krw Exp $ */
+/* $OpenBSD: clparse.c,v 1.150 2017/11/09 12:34:25 krw Exp $ */
/* Parser for dhclient config and lease files. */
@@ -588,11 +588,12 @@ parse_client_lease_declaration(FILE *cfile, struct client_lease *lease,
== 0)
return;
lease->epoch = betoh64(lease->epoch);
+ set_lease_times(lease);
break;
case TOK_EXPIRE:
- if (parse_date(cfile, &lease->expiry) == 0)
- return;
- break;
+ /* 'expire' is just a comment. See 'epoch'. */
+ skip_to_semi(cfile);
+ return;
case TOK_FILENAME:
if (parse_string(cfile, NULL, &val) == 0)
return;
@@ -618,13 +619,10 @@ parse_client_lease_declaration(FILE *cfile, struct client_lease *lease,
return;
break;
case TOK_REBIND:
- if (parse_date(cfile, &lease->rebind) == 0)
- return;
- break;
case TOK_RENEW:
- if (parse_date(cfile, &lease->renewal) == 0)
- return;
- break;
+ /* 'rebind' & 'renew' are just comments. See 'epoch'. */
+ skip_to_semi(cfile);
+ return;
case TOK_SERVER_NAME:
if (parse_string(cfile, NULL, &val) == 0)
return;
diff --git a/sbin/dhclient/dhclient.c b/sbin/dhclient/dhclient.c
index 13e33c5dd52..b74cacf84ff 100644
--- a/sbin/dhclient/dhclient.c
+++ b/sbin/dhclient/dhclient.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: dhclient.c,v 1.520 2017/11/06 13:27:19 krw Exp $ */
+/* $OpenBSD: dhclient.c,v 1.521 2017/11/09 12:34:25 krw Exp $ */
/*
* Copyright 2004 Henning Brauer <henning@openbsd.org>
@@ -144,8 +144,6 @@ struct client_lease *apply_defaults(struct client_lease *);
struct client_lease *clone_lease(struct client_lease *);
void apply_ignore_list(char *);
-void set_lease_times(struct client_lease *);
-
void state_preboot(struct interface_info *);
void state_reboot(struct interface_info *);
void state_init(struct interface_info *);
@@ -1964,6 +1962,12 @@ lease_as_string(char *ifname, char *type, struct client_lease *lease)
append_statement(string, sizeof(string), " ", buf);
}
+ i = asprintf(&buf, "%lld", (long long)lease->epoch);
+ if (i == -1)
+ return NULL;
+ append_statement(string, sizeof(string), " epoch ", buf);
+ free(buf);
+
rslt = strftime(timebuf, sizeof(timebuf), DB_TIMEFMT,
gmtime(&lease->renewal));
if (rslt == 0)
@@ -2475,6 +2479,9 @@ set_lease_times(struct client_lease *lease)
if (time_max > UINT32_MAX)
time_max = UINT32_MAX;
+ if (lease->epoch == 0)
+ lease->epoch = cur_time;
+
/*
* Take the server-provided times if available. Otherwise
* figure them out according to the spec.
@@ -2521,9 +2528,9 @@ set_lease_times(struct client_lease *lease)
lease->rebind = lease->renewal;
/* Convert lease lengths to times. */
- lease->expiry += cur_time;
- lease->renewal += cur_time;
- lease->rebind += cur_time;
+ lease->expiry += lease->epoch;
+ lease->renewal += lease->epoch;
+ lease->rebind += lease->epoch;
}
void
@@ -2612,8 +2619,10 @@ get_recorded_lease(struct interface_info *ifi)
if (lp->is_static == 0 && lp->expiry <= cur_time)
continue;
- if (lp->is_static != 0)
+ if (lp->is_static != 0) {
+ time(&lp->epoch);
set_lease_times(lp);
+ }
break;
}
diff --git a/sbin/dhclient/dhclient.leases.5 b/sbin/dhclient/dhclient.leases.5
index 6412ae5b727..77fbfaa1b2f 100644
--- a/sbin/dhclient/dhclient.leases.5
+++ b/sbin/dhclient/dhclient.leases.5
@@ -1,4 +1,4 @@
-.\" $OpenBSD: dhclient.leases.5,v 1.11 2017/10/23 13:01:20 krw Exp $
+.\" $OpenBSD: dhclient.leases.5,v 1.12 2017/11/09 12:34:25 krw Exp $
.\"
.\" Copyright (c) 1997 The Internet Software Consortium.
.\" All rights reserved.
@@ -36,7 +36,7 @@
.\" see ``http://www.isc.org/isc''. To learn more about Vixie
.\" Enterprises, see ``http://www.vix.com''.
.\"
-.Dd $Mdocdate: October 23 2017 $
+.Dd $Mdocdate: November 9 2017 $
.Dt DHCLIENT.LEASES 5
.Os
.Sh NAME
@@ -77,21 +77,36 @@ is one of:
The lease was acquired using the
BOOTP protocol rather than the DHCP protocol.
.Pp
+.It Ic epoch
+The
+.Xr time 3
+when the lease was obtained.
+This value is used to convert the values of the DHCP options
+.Ic dhcp-lease-time ,
+.Ic dhcp-renewal-time ,
+.Ic dhcp-rebinding-time
+to times.
+A value of 0 will cause
+.Ic epoch
+to be set to the current time when
+.Nm
+is processed.
+.Pp
.It Ic expire Ar date
.It Ic rebind Ar date
.It Ic renew Ar date
.Ic expire
-defines when
+is when
.Xr dhclient 8
will no longer use the lease to configure the interface.
.Ic rebind
-specifies when
+is when
.Xr dhclient 8
-begins tring to renew the lease with broadcasts to any server.
+will begin tring to renew the lease with broadcasts to any server.
.Ic renew
-specifies when
+is when
.Xr dhclient 8
-begins trying to renew the lease with unicasts to the originating server.
+will begin trying to renew the lease with unicasts to the originating server.
.Pp
Dates are specified in accordance with the
.Xr strptime 3
@@ -103,6 +118,19 @@ For example:
.Pp
.Dl renew 1 2017/10/16 14:03:49 UTC
.Pp
+.Ic expire ,
+.Ic rebind ,
+.Ic renew
+are just comments that are ignored when processing
+.Nm .
+The values used by
+.Xr dhclient 8
+are always recalculated based on
+.Ic epoch
+when
+.Nm
+is processed.
+.Pp
.It Ic filename Qq Ar string
The boot filename.
.Pp
diff --git a/sbin/dhclient/dhcpd.h b/sbin/dhclient/dhcpd.h
index 4a6fa4bb5d7..45ec2525355 100644
--- a/sbin/dhclient/dhcpd.h
+++ b/sbin/dhclient/dhcpd.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: dhcpd.h,v 1.235 2017/11/06 13:27:19 krw Exp $ */
+/* $OpenBSD: dhcpd.h,v 1.236 2017/11/09 12:34:25 krw Exp $ */
/*
* Copyright (c) 2004 Henning Brauer <henning@openbsd.org>
@@ -187,7 +187,6 @@ int parse_cidr(FILE *, unsigned char *);
int parse_lease_time(FILE *, time_t *);
int parse_decimal(FILE *, unsigned char *, char);
int parse_boolean(FILE *, unsigned char *);
-int parse_date(FILE *, time_t *);
void parse_warn(char *);
/* bpf.c */
@@ -224,6 +223,7 @@ void dhcpack(struct interface_info *, struct option_data *,char *);
void dhcpnak(struct interface_info *, struct option_data *,char *);
void free_client_lease(struct client_lease *);
void routehandler(struct interface_info *, int);
+void set_lease_times(struct client_lease *);
/* packet.c */
void assemble_eh_header(struct ether_addr, struct ether_header *);
diff --git a/sbin/dhclient/parse.c b/sbin/dhclient/parse.c
index a9ea6f86e25..6d597f3709d 100644
--- a/sbin/dhclient/parse.c
+++ b/sbin/dhclient/parse.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: parse.c,v 1.76 2017/11/06 12:51:53 krw Exp $ */
+/* $OpenBSD: parse.c,v 1.77 2017/11/09 12:34:25 krw Exp $ */
/* Common parser code for dhcpd and dhclient. */
@@ -337,65 +337,6 @@ parse_decimal(FILE *cfile, unsigned char *buf, char fmt)
return 0;
}
-/*
- * date :== NUMBER NUMBER SLASH NUMBER SLASH NUMBER
- * NUMBER COLON NUMBER COLON NUMBER UTC SEMI
- *
- * Dates are always in UTC; first number is day of week; next is
- * year/month/day; next is hours:minutes:seconds on a 24-hour
- * clock.
- *
- * XXX Will break after year 9999!
- */
-int
-parse_date(FILE *cfile, time_t *date)
-{
- char timestr[23]; /* "wyyyy/mm/ddhh:mm:ssUTC" */
- struct tm tm;
- char *val, *p;
- size_t n;
- time_t guess;
- int token;
-
- memset(timestr, 0, sizeof(timestr));
-
- n = 0;
- do {
- token = peek_token(&val, cfile);
-
- switch (token) {
- case EOF:
- n = sizeof(timestr);
- break;
- case';':
- /* strptime() ignores tm_isdt so ensure it is 0. */
- memset(&tm, 0, sizeof(tm));
- p = strptime(timestr, DB_TIMEFMT, &tm);
- if (p != NULL && *p == '\0') {
- guess = timegm(&tm);
- if (guess != -1) {
- *date = guess;
- return 1;
- }
- }
- token = next_token(NULL, cfile);
- break;
- default:
- n = strlcat(timestr, val, sizeof(timestr));
- token = next_token(NULL, cfile);
- break;
-
- }
- } while (n < sizeof(timestr) && token != ';');
-
- parse_warn("expecting UTC time.");
-
- if (token != ';')
- skip_to_semi(cfile);
-
- return 0;
-}
-
void
parse_warn(char *msg)
{