diff options
author | Hans Dedecker <dedeckeh@gmail.com> | 2019-02-25 10:48:44 +0100 |
---|---|---|
committer | Hans Dedecker <dedeckeh@gmail.com> | 2019-02-25 11:20:31 +0100 |
commit | 9e9389c9c6ebd29d61fd35c563c365195d263848 (patch) | |
tree | 80d0343036ba94c7d415c39a2261d36dc91c63d2 /src/dhcpv4.c | |
parent | e69265b4bb20a018193aa107833b147def2e6cfd (diff) |
dhcpv4: fix adding assignment in list (FS#2142)
Add assignment to the tail of the list in case the last element
is not bigger
Signed-off-by: Hans Dedecker <dedeckeh@gmail.com>
Diffstat (limited to 'src/dhcpv4.c')
-rw-r--r-- | src/dhcpv4.c | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/src/dhcpv4.c b/src/dhcpv4.c index ff2d8c2..5016390 100644 --- a/src/dhcpv4.c +++ b/src/dhcpv4.c @@ -917,8 +917,12 @@ static bool dhcpv4_assign(struct interface *iface, struct dhcp_assignment *a, } 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; @@ -927,8 +931,7 @@ raddr_out: ((uint8_t *)&a->addr)[2], ((uint8_t *)&a->addr)[3]); return true; - } else if (ntohl(raddr) == ntohl(c->addr)) - break; + } } } @@ -959,8 +962,12 @@ raddr_out: } 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)", @@ -969,8 +976,7 @@ raddr_out: i, count); return true; - } else if (try == ntohl(c->addr)) - break; + } } } |