summaryrefslogtreecommitdiffhomepage
path: root/src/dhcpv4.c
diff options
context:
space:
mode:
authorSteven Barth <stbarth@cisco.com>2016-05-19 08:54:24 +0200
committerSteven Barth <stbarth@cisco.com>2016-05-19 08:54:24 +0200
commite63a2837acfaf54c97a9db466bf485e9f7024fe8 (patch)
tree1a73d72c653da69905a68042d77241e83a778747 /src/dhcpv4.c
parent1fcf0388078c7675187ff4f2f644aaf65138f261 (diff)
Add per-host leasetime support
Patch by Daniel Dickinson Signed-off-by: Steven Barth <steven@midlink.org>
Diffstat (limited to 'src/dhcpv4.c')
-rw-r--r--src/dhcpv4.c26
1 files changed, 22 insertions, 4 deletions
diff --git a/src/dhcpv4.c b/src/dhcpv4.c
index a657e13..f277a67 100644
--- a/src/dhcpv4.c
+++ b/src/dhcpv4.c
@@ -176,6 +176,8 @@ int setup_dhcpv4_interface(struct interface *iface, bool enable)
iface->ifname);
return -1;
}
+ if (lease->dhcpv4_leasetime >= 60)
+ a->leasetime = lease->dhcpv4_leasetime;
a->addr = ntohl(lease->ipaddr.s_addr);
memcpy(a->hwaddr, lease->mac.ether_addr_octet, sizeof(a->hwaddr));
memcpy(a->hostname, lease->hostname, hostlen);
@@ -382,13 +384,22 @@ static void handle_dhcpv4(void *addr, void *data, size_t len,
if (lease) {
reply.yiaddr.s_addr = htonl(lease->addr);
- uint32_t val = htonl(iface->dhcpv4_leasetime);
+ uint32_t val;
+ uint32_t leasetime;
+
+ if (lease->leasetime >= 60) {
+ leasetime = lease->leasetime;
+ } else {
+ leasetime = iface->dhcpv4_leasetime;
+ }
+
+ val = htonl(leasetime);
dhcpv4_put(&reply, &cookie, DHCPV4_OPT_LEASETIME, 4, &val);
- val = htonl(500 * iface->dhcpv4_leasetime / 1000);
+ val = htonl(500 * leasetime / 1000);
dhcpv4_put(&reply, &cookie, DHCPV4_OPT_RENEW, 4, &val);
- val = htonl(875 * iface->dhcpv4_leasetime / 1000);
+ val = htonl(875 * leasetime / 1000);
dhcpv4_put(&reply, &cookie, DHCPV4_OPT_REBIND, 4, &val);
dhcpv4_put(&reply, &cookie, DHCPV4_OPT_NETMASK, 4, &ifnetmask.sin_addr);
@@ -622,10 +633,17 @@ static struct dhcpv4_assignment* dhcpv4_lease(struct interface *iface,
a->head.prev->next = &a->head;
}
+ uint32_t leasetime;
+ if (a->leasetime) {
+ leasetime = a->leasetime;
+ } else {
+ leasetime = iface->dhcpv4_leasetime;
+ }
+
// Was only a solicitation: mark binding for removal
if (assigned && a->valid_until < now) {
a->valid_until = (msg == DHCPV4_MSG_DISCOVER) ? 0 :
- (now + iface->dhcpv4_leasetime);
+ (now + leasetime);
} else if (!assigned && a) { // Cleanup failed assignment
free(a);
a = NULL;