}
list_for_each_entry(c, &iface->dhcpv4_assignments, head) {
- if (ntohl(c->addr) > ntohl(raddr)) {
- list_add_tail(&a->head, &c->head);
+ if (ntohl(raddr) == ntohl(c->addr))
+ break;
+
+ if (ntohl(c->addr) > ntohl(raddr) || list_is_last(&c->head, &iface->dhcpv4_assignments)) {
+ list_add_tail(&a->head,
+ ntohl(c->addr) > ntohl(raddr) ? &c->head : &iface->dhcpv4_assignments);
raddr_out:
a->addr = raddr;
((uint8_t *)&a->addr)[2], ((uint8_t *)&a->addr)[3]);
return true;
- } else if (ntohl(raddr) == ntohl(c->addr))
- break;
+ }
}
}
for (uint32_t i = 0, try = (((uint32_t)rand()) % count) + start; i < count;
++i, try = (((try - start) + 1) % count) + start) {
- if (config_find_lease_by_ipaddr(try))
+ if (config_find_lease_by_ipaddr(htonl(try)))
continue;
if (list_empty(&iface->dhcpv4_assignments)) {
}
list_for_each_entry(c, &iface->dhcpv4_assignments, head) {
- if (ntohl(c->addr) > try) {
- list_add_tail(&a->head, &c->head);
+ if (try == ntohl(c->addr))
+ break;
+
+ if (ntohl(c->addr) > try || list_is_last(&c->head, &iface->dhcpv4_assignments)) {
+ list_add_tail(&a->head,
+ ntohl(c->addr) > try ? &c->head : &iface->dhcpv4_assignments);
a->addr = htonl(try);
syslog(LOG_DEBUG, "Assigning mapped IP: %u.%u.%u.%u (try %u of %u)",
i, count);
return true;
- } else if (try == ntohl(c->addr))
- break;
+ }
}
}