aboutsummaryrefslogtreecommitdiff
path: root/sbin/dhclient/dhclient.c
diff options
context:
space:
mode:
authorNick Hibma <n_hibma@FreeBSD.org>2017-03-30 17:31:12 +0000
committerNick Hibma <n_hibma@FreeBSD.org>2017-03-30 17:31:12 +0000
commitc13fa60c22beb4bbcd9cb44dd9e78d3173fc564e (patch)
tree7d5ca8248d2dceea8633e988b3479d29b63d1155 /sbin/dhclient/dhclient.c
parent2b2fc97356dc5b6071d4201628e80f2f03798003 (diff)
downloadsrc-c13fa60c22beb4bbcd9cb44dd9e78d3173fc564e.tar.gz
src-c13fa60c22beb4bbcd9cb44dd9e78d3173fc564e.zip
Allow superseding the lease renewal and rebind times.
Also make sure that the renewal is never more than 1/2 * expiry and rebind never more than 7/4 * renewal (the default values in the spec). This should allow adjusting high values from the server as well as making sure the values from the server make sense. Renewal and rebind times will be adjusted down if the expiry time is set very high in a server, not the other way around. This change just makes sure the values keep making sense.
Notes
Notes: svn path=/head/; revision=316283
Diffstat (limited to 'sbin/dhclient/dhclient.c')
-rw-r--r--sbin/dhclient/dhclient.c25
1 files changed, 19 insertions, 6 deletions
diff --git a/sbin/dhclient/dhclient.c b/sbin/dhclient/dhclient.c
index d20585db0dc8..5cf4e4a3d29d 100644
--- a/sbin/dhclient/dhclient.c
+++ b/sbin/dhclient/dhclient.c
@@ -769,21 +769,34 @@ dhcpack(struct packet *packet)
if (ip->client->new->expiry < 60)
ip->client->new->expiry = 60;
- /* Take the server-provided renewal time if there is one;
- otherwise figure it out according to the spec. */
- if (ip->client->new->options[DHO_DHCP_RENEWAL_TIME].len)
+ /* Unless overridden in the config, take the server-provided renewal
+ * time if there is one; otherwise figure it out according to the spec.
+ * Also make sure the renewal time does not exceed the expiry time.
+ */
+ if (ip->client->config->default_actions[DHO_DHCP_RENEWAL_TIME] ==
+ ACTION_SUPERSEDE)
+ ip->client->new->renewal = getULong(
+ ip->client->config->defaults[DHO_DHCP_RENEWAL_TIME].data);
+ else if (ip->client->new->options[DHO_DHCP_RENEWAL_TIME].len)
ip->client->new->renewal = getULong(
ip->client->new->options[DHO_DHCP_RENEWAL_TIME].data);
else
ip->client->new->renewal = ip->client->new->expiry / 2;
+ if (ip->client->new->renewal > ip->client->new->expiry / 2)
+ ip->client->new->renewal = ip->client->new->expiry / 2;
/* Same deal with the rebind time. */
- if (ip->client->new->options[DHO_DHCP_REBINDING_TIME].len)
+ if (ip->client->config->default_actions[DHO_DHCP_REBINDING_TIME] ==
+ ACTION_SUPERSEDE)
+ ip->client->new->rebind = getULong(
+ ip->client->config->defaults[DHO_DHCP_REBINDING_TIME].data);
+ else if (ip->client->new->options[DHO_DHCP_REBINDING_TIME].len)
ip->client->new->rebind = getULong(
ip->client->new->options[DHO_DHCP_REBINDING_TIME].data);
else
- ip->client->new->rebind = ip->client->new->renewal +
- ip->client->new->renewal / 2 + ip->client->new->renewal / 4;
+ ip->client->new->rebind = ip->client->new->renewal * 7 / 4;
+ if (ip->client->new->rebind > ip->client->new->renewal * 7 / 4)
+ ip->client->new->rebind = ip->client->new->renewal * 7 / 4;
ip->client->new->expiry += cur_time;
/* Lease lengths can never be negative. */