sppmasterspp 9e457b1166 Use binary search to find next shorter domain length in lookup_domain()
When a binary search in lookup_domain() misses on a domain of length
old, serverarray[try] points to the last entry sorting before qdomain.
To find the length of the next shorter domain bucket, the existing code
linearly walks serverarray[++try] until domain_len changes.

With large local=/ or address=/ blocklists (e.g. 400k+ entries),
common domain lengths contain 20k-35k entries each, so every non-exact
label lookup linearly scans tens of thousands of scattered struct server
pointers. Multi-label misses (such as search-domain retries like
a.b.c.lan) repeat this scan once per label.

Since serverarray is sorted monotonically non-increasing by domain_len
(order()/order_servers(), with SERV_FOR_NODOTS always having
domain_len == 0 and sorting last), replace the linear walk with a binary
search in O(log N) time. Because qlen strictly decreases on the next
outer iteration and qlen <= old whenever rc > 0, no entry with
domain_len >= old can match any shorter substring, so advancing
low = b_lo when b_lo < daemon->serverarraysz is also safe.

On an ARMv8 router (Asus RT-AX89X, IPQ8074A) with 413k local=/ domains:
- Blocked subdomain (50 queries): 100 ms -> 10 ms (10x faster)
- 4-label .lan suffix retry (50 queries): 300 ms -> 10 ms (30x faster)
- 25 unique uncached forwarded queries (50 queries): 190 ms -> 30 ms
- Live 15s dnsmasq CPU time: 610 ms -> 10 ms

Verified bit-for-bit identical (rc, lowout, highout) against the
original implementation across 503,402 differential test cases covering
SERV_FOR_NODOTS, SERV_WILDCARD, SERV_USE_RESOLV, F_DS, F_DNSSECOK,
F_CONFIG, F_SERVER, F_DOMAINSRV, empty queries, and length gaps.

Assisted-by: Gemini
Tested-by: sppmasterspp <46223847+sppmasterspp@users.noreply.github.com>
Signed-off-by: sppmasterspp <46223847+sppmasterspp@users.noreply.github.com>
2026-11-29 12:45:00 +00:00
2012-04-02 20:40:34 +01:00
2025-12-07 13:44:40 +00:00
2012-01-05 17:31:15 +00:00
2018-01-14 17:32:52 +00:00
2022-05-13 21:22:11 +01:00
2012-01-05 17:31:13 +00:00
2025-07-20 15:29:43 +01:00
2021-06-15 23:14:59 +01:00
2026-04-08 12:08:18 +01:00
2025-07-20 15:29:43 +01:00
2012-01-05 22:00:08 +00:00
S
Description
No description provided
GPL-2.0
6.5 MiB
0 Stars 1 Watchers 0 Forks
Languages
C 94.3%
Perl 2.2%
HTML 1.2%
Shell 1%
Makefile 0.6%
Other 0.6%