From 67b3a141da8bbfd9fc506d043f1e7e1a92e2c7f9 Mon Sep 17 00:00:00 2001 From: Hans Dedecker Date: Mon, 18 Feb 2019 14:11:12 +0100 Subject: [PATCH] dhcpv4: fix assignment of requested IP address Fix assignment of requested IP address by a client in case the assignment list is empty. Signed-off-by: Hans Dedecker --- src/dhcpv4.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/dhcpv4.c b/src/dhcpv4.c index da2c051..252003b 100644 --- a/src/dhcpv4.c +++ b/src/dhcpv4.c @@ -920,9 +920,15 @@ static bool dhcpv4_assign(struct interface *iface, struct dhcp_assignment *a, /* try to assign the IP the client asked for */ if (start <= ntohl(raddr) && ntohl(raddr) <= end && !config_find_lease_by_ipaddr(raddr)) { + if (list_empty(&iface->dhcpv4_assignments)) { + list_add(&a->head, &iface->dhcpv4_assignments); + goto raddr_out; + } + list_for_each_entry(c, &iface->dhcpv4_assignments, head) { if (ntohl(c->addr) > ntohl(raddr)) { list_add_tail(&a->head, &c->head); +raddr_out: a->addr = raddr; syslog(LOG_INFO, "Assigning the IP the client asked for: %u.%u.%u.%u", -- 2.30.2