diff options
author | Hans Dedecker <dedeckeh@gmail.com> | 2016-12-15 22:37:47 +0100 |
---|---|---|
committer | Hans Dedecker <dedeckeh@gmail.com> | 2016-12-27 21:53:55 +0100 |
commit | 4c89614ccf5d72ee0c0824e5050a8814748a32c3 (patch) | |
tree | f54a82daadd4ed089ff2b53967a58d98baf436b6 /src/dhcpv4.c | |
parent | 8dc2a59dcaef51be41cf82621c0e00eac88074aa (diff) |
Limit lifetime of non-static leases in case of release and decline
In case infinite leasetime is assigned to a non static DHCPv4/v6 lease
override the infinite lifetime of the lease when either a DHCPv4/v6
decline or release is received.
Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
Diffstat (limited to 'src/dhcpv4.c')
-rw-r--r-- | src/dhcpv4.c | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/src/dhcpv4.c b/src/dhcpv4.c index 7695d68..509b092 100644 --- a/src/dhcpv4.c +++ b/src/dhcpv4.c @@ -181,6 +181,8 @@ int setup_dhcpv4_interface(struct interface *iface, bool enable) a->addr = ntohl(lease->ipaddr.s_addr); memcpy(a->hwaddr, lease->mac.ether_addr_octet, sizeof(a->hwaddr)); memcpy(a->hostname, lease->hostname, hostlen); + /* Static assignment */ + a->flags |= OAF_STATIC; /* Infinite valid */ a->valid_until = 0; @@ -643,17 +645,17 @@ static struct dhcpv4_assignment* dhcpv4_lease(struct interface *iface, *leasetime = my_leasetime; if (assigned) { - bool is_discover = (msg == DHCPV4_MSG_DISCOVER); + if (msg == DHCPV4_MSG_DISCOVER) { + a->flags &= ~OAF_BOUND; - if (!INFINITE_VALID(a->valid_until)) - // Was only a discover; mark binding for removal - a->valid_until = (is_discover ? now : ((*leasetime == UINT32_MAX) ? - 0 : (time_t)(now + *leasetime))); - - /* Mark assignment as bound */ - if (!is_discover) + if (!(a->flags & OAF_STATIC)) + a->valid_until = now; + } else { a->flags |= OAF_BOUND; + if (!(a->flags & OAF_STATIC)) + a->valid_until = ((*leasetime == UINT32_MAX) ? 0 : (time_t)(now + *leasetime)); + } } else if (!assigned && a) { // Cleanup failed assignment free(a); a = NULL; @@ -664,13 +666,13 @@ static struct dhcpv4_assignment* dhcpv4_lease(struct interface *iface, } else if (msg == DHCPV4_MSG_RELEASE && a) { a->flags &= ~OAF_BOUND; - if (!INFINITE_VALID(a->valid_until)) + if (!(a->flags & OAF_STATIC)) a->valid_until = now - 1; } else if (msg == DHCPV4_MSG_DECLINE && a) { a->flags &= ~OAF_BOUND; - if (!INFINITE_VALID(a->valid_until)) { + if (!(a->flags & OAF_STATIC)) { memset(a->hwaddr, 0, sizeof(a->hwaddr)); a->valid_until = now + 3600; // Block address for 1h } |