summaryrefslogtreecommitdiffhomepage
path: root/src/dhcpv4.c
diff options
context:
space:
mode:
authorHans Dedecker <dedeckeh@gmail.com>2016-12-14 22:22:22 +0100
committerHans Dedecker <dedeckeh@gmail.com>2016-12-15 15:17:15 +0100
commite05553099c47b92420c21ff30b07709dfa40a84a (patch)
tree199eb5e05966f5a96a064a4fab705ee76529ba2b /src/dhcpv4.c
parent3af23ad72888393a863d7be545d1bd5af99ca442 (diff)
Don't print non bound assignments in the state file
Set bound flag for DHCPv4 and DHCPv6 assignments when the IPv6/IPv4 address is leased to a client. This will prevent the printing of leases and hostname/IPv4/IPv6 address combinations in the state file for for which the IPv4/6 address has not been assigned. Also this will fix the printing of assignments which have been declined by the clients Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
Diffstat (limited to 'src/dhcpv4.c')
-rw-r--r--src/dhcpv4.c26
1 files changed, 20 insertions, 6 deletions
diff --git a/src/dhcpv4.c b/src/dhcpv4.c
index 5220edf..7695d68 100644
--- a/src/dhcpv4.c
+++ b/src/dhcpv4.c
@@ -643,10 +643,17 @@ static struct dhcpv4_assignment* dhcpv4_lease(struct interface *iface,
*leasetime = my_leasetime;
if (assigned) {
+ bool is_discover = (msg == DHCPV4_MSG_DISCOVER);
+
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) ?
+ a->valid_until = (is_discover ? now : ((*leasetime == UINT32_MAX) ?
0 : (time_t)(now + *leasetime)));
+
+ /* Mark assignment as bound */
+ if (!is_discover)
+ a->flags |= OAF_BOUND;
+
} else if (!assigned && a) { // Cleanup failed assignment
free(a);
a = NULL;
@@ -654,12 +661,19 @@ static struct dhcpv4_assignment* dhcpv4_lease(struct interface *iface,
if (assigned && a)
lease = a;
- } else if (msg == DHCPV4_MSG_RELEASE) {
- if (a && !INFINITE_VALID(a->valid_until))
+ } else if (msg == DHCPV4_MSG_RELEASE && a) {
+ a->flags &= ~OAF_BOUND;
+
+ if (!INFINITE_VALID(a->valid_until))
a->valid_until = now - 1;
- } else if (msg == DHCPV4_MSG_DECLINE && a && !INFINITE_VALID(a->valid_until)) {
- memset(a->hwaddr, 0, sizeof(a->hwaddr));
- a->valid_until = now + 3600; // Block address for 1h
+
+ } else if (msg == DHCPV4_MSG_DECLINE && a) {
+ a->flags &= ~OAF_BOUND;
+
+ if (!INFINITE_VALID(a->valid_until)) {
+ memset(a->hwaddr, 0, sizeof(a->hwaddr));
+ a->valid_until = now + 3600; // Block address for 1h
+ }
}
dhcpv6_write_statefile();