From: David Härdeman Date: Sat, 20 Sep 2025 14:40:32 +0000 (+0200) Subject: odhcpd: break up complex matching logic X-Git-Url: http://git.openwrt.org/?a=commitdiff_plain;h=e42c627259428186716aa295c0506de71b751a3d;p=project%2Fodhcpd.git odhcpd: break up complex matching logic Like Winnie the Pooh, “I am a Bear of Very Little Brain, and long words Bother me”. Simplify the assignment checking logic by breaking it up a bit. This is in preparation for subsequent patches. Signed-off-by: David Härdeman Link: https://github.com/openwrt/odhcpd/pull/255 Signed-off-by: Álvaro Fernández Rojas --- diff --git a/src/dhcpv6-ia.c b/src/dhcpv6-ia.c index 8cc9515..549256f 100644 --- a/src/dhcpv6-ia.c +++ b/src/dhcpv6-ia.c @@ -1499,21 +1499,38 @@ ssize_t dhcpv6_ia_handle_IAs(uint8_t *buf, size_t buflen, struct interface *ifac } } - /* Find assignment */ + /* Find an existing assignment */ struct dhcp_assignment *c, *a = NULL; list_for_each_entry(c, &iface->ia_assignments, head) { - if ((c->clid_len == clid_len && !memcmp(c->clid_data, clid_data, clid_len)) && - c->iaid == ia->iaid && (INFINITE_VALID(c->valid_until) || now < c->valid_until) && - ((is_pd && (c->flags & OAF_DHCPV6_PD)) || (is_na && (c->flags & OAF_DHCPV6_NA)))) { - a = c; + /* If we're looking for a PD, is this a PD? */ + if (is_pd && !(c->flags & OAF_DHCPV6_PD)) + continue; - /* Reset state */ - if (a->flags & OAF_BOUND) - apply_lease(a, false); + /* If we're looking for a NA, is this a NA? */ + if (is_na && !(c->flags & OAF_DHCPV6_NA)) + continue; - stop_reconf(a); - break; - } + /* Is this assignment still valid? */ + if (!INFINITE_VALID(c->valid_until) && now >= c->valid_until) + continue; + + /* Does the DUID match? */ + if (c->clid_len != clid_len || memcmp(c->clid_data, clid_data, clid_len)) + continue; + + /* Does the IAID match? */ + if (c->iaid != ia->iaid) + continue; + + /* We have a match */ + a = c; + + /* Reset state */ + if (a->flags & OAF_BOUND) + apply_lease(a, false); + + stop_reconf(a); + break; } if (l && a && a->lease != l) {