dhcpv4: fix assignment of requested IP address
authorHans Dedecker <dedeckeh@gmail.com>
Mon, 18 Feb 2019 13:11:12 +0000 (14:11 +0100)
committerHans Dedecker <dedeckeh@gmail.com>
Mon, 18 Feb 2019 13:11:12 +0000 (14:11 +0100)
Fix assignment of requested IP address by a client in case the
assignment list is empty.

Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
src/dhcpv4.c

index da2c051e46656e329712d5a253faad9884458723..252003b064c2804104f548a51c4ee5318954fccc 100644 (file)
@@ -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",