summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorHans Dedecker <dedeckeh@gmail.com>2020-02-16 21:15:28 +0100
committerHans Dedecker <dedeckeh@gmail.com>2020-02-16 21:27:16 +0100
commitbb07fa4b6d0d48cb2e67a4e9979412af8b05e883 (patch)
tree8d01a7524f2c842ae38568575b1cb66b7d13d4c3
parent6db312a698e920ff61505ef1f42469880829774d (diff)
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 <dedeckeh@gmail.com>
-rw-r--r--src/dhcpv4.c15
1 files changed, 6 insertions, 9 deletions
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();