openwrt/package/network/services
David Härdeman 7e7770d865 dnsmasq: watch the hosts directory with --hostsdir
dnsmasq reads the hosts files in /tmp/hosts (its own per-instance files
and odhcpd's) via --addn-hosts, which only rereads them on SIGHUP. So
odhcpd's leasetrigger, odhcpd-update, sends SIGHUP to every dnsmasq
instance whenever its leases change, which also clears the whole DNS
cache and rereads all other hosts files. That spams the log (#6454),
has been suspected of leaking memory (#21729) and is slow with large
hosts files such as block lists since dnsmasq 2.93 (#25826); see also
#8271.

Use --hostsdir instead: dnsmasq then watches the directory with inotify
and only rereads the file that changed. odhcpd replaces its hosts files
by renaming a dotfile, which dnsmasq ignores, over them.

This was done before in commit a03035dad1 ("dnsmasq: use "hostsdir"
instead of "addn-hosts"") and reverted in commit bcf20e0583, because
the directory is shared by all instances and odhcpd still sent SIGHUP.

All instances have read the whole directory since commit 942904f7b9
("dnsmasq: Specify directory /tmp/hosts as argument for --addn-hosts"),
so that they get odhcpd's names, and instances can opt out with
ignore_hosts_dir since commit e8a5670122 ("dnsmasq: add ignore hosts
dir to dnsmasq init script"). This is unchanged here, including that
names leak between instances which don't opt out (#6960, #9145). What
made the sharing a problem for --hostsdir is that the temporary hosts
file of an instance is in the same directory: the other instances read
it while it is written and keep its names after it is renamed (dnsmasq
does not handle IN_MOVED_FROM) until they get a SIGHUP. Make it a
dotfile as well.

The SIGHUP was needed then, as dnsmasq only removes the names of
changed or deleted files in a hosts directory since version 2.88. It is
now redundant and odhcpd-update can be dropped in a follow-up.

Addnhosts entries that are directories would lose their names when a
file in the hosts directory changes, due to a dnsmasq bug fixed by the
previous commit.

Signed-off-by: David Härdeman <david@hardeman.nu>
Link: https://github.com/openwrt/openwrt/pull/26658
Signed-off-by: Robert Marko <robimarko@gmail.com>
2026-11-29 11:35:20 +01:00
..
bridger
…
dnsmasq dnsmasq: watch the hosts directory with --hostsdir 2026-11-29 11:35:20 +01:00
dropbear
…
ead
…
hostapd
…
ipset-dns
…
lldpd
…
odhcpd
…
omcproxy
…
ppp
…
relayd
…
uhttpd
…
umdns
…
unetd
…
unetmsg
…
ustp
…