From: Hans Dedecker Date: Sun, 16 Feb 2020 20:15:28 +0000 (+0100) Subject: dhcpv4: avoid setting lifetime to infinite for static assignments X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=bb07fa4b6d0d48cb2e67a4e9979412af8b05e883;p=oweals%2Fodhcpd.git dhcpv4: avoid setting lifetime to infinite for static assignments Don't set the valid lifetime to infinite for static assignments but rather set it to the leasetime given to the client. This makes it possible to display the leasetime for static assigments and simplifies the code in several places Signed-off-by: Hans Dedecker --- diff --git a/src/dhcpv4.c b/src/dhcpv4.c index 24a4fea..51236d2 100644 --- a/src/dhcpv4.c +++ b/src/dhcpv4.c @@ -1081,8 +1081,7 @@ dhcpv4_lease(struct interface *iface, enum dhcpv4_msg msg, const uint8_t *mac, a->flags &= ~OAF_BOUND; *incl_fr_opt = accept_fr_nonce; - if (!(a->flags & OAF_STATIC)) - a->valid_until = now; + a->valid_until = now; } else { if ((!(a->flags & OAF_STATIC) || !a->hostname) && hostname_len > 0) { a->hostname = realloc(a->hostname, hostname_len + 1); @@ -1113,8 +1112,7 @@ dhcpv4_lease(struct interface *iface, enum dhcpv4_msg msg, const uint8_t *mac, } else *incl_fr_opt = false; - if (!(a->flags & OAF_STATIC)) - a->valid_until = ((*leasetime == UINT32_MAX) ? 0 : (time_t)(now + *leasetime)); + a->valid_until = ((*leasetime == UINT32_MAX) ? 0 : (time_t)(now + *leasetime)); } } else if (!assigned && a) { /* Cleanup failed assignment */ @@ -1124,17 +1122,16 @@ dhcpv4_lease(struct interface *iface, enum dhcpv4_msg msg, const uint8_t *mac, } else if (msg == DHCPV4_MSG_RELEASE && a) { a->flags &= ~OAF_BOUND; - - if (!(a->flags & OAF_STATIC)) - a->valid_until = now - 1; + a->valid_until = now - 1; } else if (msg == DHCPV4_MSG_DECLINE && a) { a->flags &= ~OAF_BOUND; - if (!(a->flags & OAF_STATIC)) { + if (!(a->flags & OAF_STATIC) || a->lease->ipaddr != a->addr) { memset(a->hwaddr, 0, sizeof(a->hwaddr)); a->valid_until = now + 3600; /* Block address for 1h */ - } + } else + a->valid_until = now - 1; } dhcpv6_ia_write_statefile();