diff options
author | Hans Dedecker <dedeckeh@gmail.com> | 2016-11-17 16:11:57 +0100 |
---|---|---|
committer | John Crispin <john@phrozen.org> | 2016-11-21 11:35:42 +0100 |
commit | 44ca70ae6f0fb649cef47d9160ec1ee13e7844f1 (patch) | |
tree | 9110305f7a3e76f81a8c89befed63936c0297885 /src | |
parent | 6c3bc0141dacc88992583d6f2cdc8a360df7422d (diff) |
dhcpv4: Keep DHCPv4 assignment lifetime value in sync with assigned leasetime
Keep the valid_until assignment parameter in sync with the
leasetime assigned to the DHCP client when handling DHCP
request message.
This guarantees the contents of the ubus dhcp ipv4leases valid
parameter is in sync with the client leasetime
Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/dhcpv4.c | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/src/dhcpv4.c b/src/dhcpv4.c index 8469038..618475f 100644 --- a/src/dhcpv4.c +++ b/src/dhcpv4.c @@ -618,6 +618,8 @@ static struct dhcpv4_assignment* dhcpv4_lease(struct interface *iface, } memcpy(a->hwaddr, mac, sizeof(a->hwaddr)); memcpy(a->hostname, hostname, hostlen); + // Don't consider new assignment as infinite + a->valid_until = now; assigned = dhcpv4_assign(iface, a, raddr); } @@ -642,10 +644,11 @@ static struct dhcpv4_assignment* dhcpv4_lease(struct interface *iface, leasetime = iface->dhcpv4_leasetime; } - // Was only a discover; mark binding for removal - if (assigned && a->valid_until < now) { - a->valid_until = ((msg == DHCPV4_MSG_DISCOVER) ? now : ((leasetime == UINT32_MAX) ? - 0 : (time_t)(now + leasetime))); + if (assigned) { + if (!INFINITE_VALID(a->valid_until)) + // Was only a discover; mark binding for removal + a->valid_until = ((msg == DHCPV4_MSG_DISCOVER) ? now : ((leasetime == UINT32_MAX) ? + 0 : (time_t)(now + leasetime))); } else if (!assigned && a) { // Cleanup failed assignment free(a); a = NULL; |