From: Hans Dedecker Date: Tue, 12 Sep 2017 08:52:12 +0000 (+0200) Subject: dhcpv4: cleanup dhcpv4_test usage X-Git-Url: http://git.lede-project.org./?a=commitdiff_plain;h=e3b49f30d5cd8fa2c6e5b5301d7ffde5fd8b50cc;p=project%2Fodhcpd.git dhcpv4: cleanup dhcpv4_test usage Signed-off-by: Hans Dedecker --- diff --git a/src/dhcpv4.c b/src/dhcpv4.c index 9e862ca..826a1f8 100644 --- a/src/dhcpv4.c +++ b/src/dhcpv4.c @@ -852,17 +852,6 @@ static void handle_dhcpv4(void *addr, void *data, size_t len, (struct sockaddr*)&dest, sizeof(dest)); } -static bool dhcpv4_test(struct interface *iface, uint32_t try) -{ - struct dhcpv4_assignment *c; - list_for_each_entry(c, &iface->dhcpv4_assignments, head) { - if (c->addr == try) - return false; - } - - return true; -} - static bool dhcpv4_assign(struct interface *iface, struct dhcpv4_assignment *assign, uint32_t raddr) { @@ -871,7 +860,8 @@ static bool dhcpv4_assign(struct interface *iface, uint32_t count = end - start + 1; // try to assign the IP the client asked for - if (start <= ntohl(raddr) && ntohl(raddr) <= end && dhcpv4_test(iface, raddr)) { + if (start <= ntohl(raddr) && ntohl(raddr) <= end && + !find_assignment_by_addr(iface, raddr)) { assign->addr = raddr; syslog(LOG_INFO, "assigning the IP the client asked for: %u.%u.%u.%u", ((uint8_t *)&assign->addr)[0], @@ -904,7 +894,7 @@ static bool dhcpv4_assign(struct interface *iface, } for (uint32_t i = 0; i < count; ++i) { - if (dhcpv4_test(iface, htonl(try))) { + if (!find_assignment_by_addr(iface, htonl(try))) { /* test was successful: IP address is not assigned, assign it */ assign->addr = htonl(try); syslog(LOG_DEBUG, "assigning mapped IP: %u.%u.%u.%u (try %u of %u)",