[PATCH] dnsmasq: Add support for hostdir argument

Niklas Söderlund niklas.soderlund at ragnatech.se
Thu Sep 5 10:49:10 PDT 2024


Add new UCI list 'hostsdir' allowing the usage of the dnsmasq --hostdir
argument while also making sure the path is added to the RO jail for the
dnsmasq process. This is useful e.g. in case of manually maintaining a
set of host-like files that should be monitored for changes that should
be applied immediately. This differers from the --addn-hosts host-like
files which only takes effect after sending a SIGHUP to the dnsmasq
process.

It is important to make sure the directory exists before starting the
dnsmasq process, as any non-existing directory is ignored and won't be
monitored, and a common use-case is to maintain a host-like structure
under /tmp.

Signed-off-by: Niklas Söderlund <niklas.soderlund at ragnatech.se>
---
 package/network/services/dnsmasq/files/dnsmasq.init | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/package/network/services/dnsmasq/files/dnsmasq.init b/package/network/services/dnsmasq/files/dnsmasq.init
index fb061dceed6c..d80578384a57 100755
--- a/package/network/services/dnsmasq/files/dnsmasq.init
+++ b/package/network/services/dnsmasq/files/dnsmasq.init
@@ -213,6 +213,12 @@ append_addnhosts() {
 	xappend "--addn-hosts=$1"
 }
 
+append_hostsdir() {
+	mkdir -p "$1"
+	append_extramount "$1"
+	xappend "--hostsdir=$1"
+}
+
 append_bogusnxdomain() {
 	xappend "--bogus-nxdomain=$1"
 }
@@ -1011,6 +1017,7 @@ dnsmasq_start()
 		append_addnhosts "$HOSTFILE_DIR"
 	fi
 	config_list_foreach "$cfg" "addnhosts" append_addnhosts
+	config_list_foreach "$cfg" "hostsdir" append_hostsdir
 	config_list_foreach "$cfg" "bogusnxdomain" append_bogusnxdomain
 	append_parm "$cfg" "leasefile" "--dhcp-leasefile" "/tmp/dhcp.leases"
 
-- 
2.46.0




More information about the openwrt-devel mailing list