diff mbox series

[v5,1/3] dnsmasq: distinct Ubus names for multiple instances

Message ID AS8PR09MB54662BE09237B14C0B1635CCF9049@AS8PR09MB5466.eurprd09.prod.outlook.com
State Superseded
Headers show
Series [v5,1/3] dnsmasq: distinct Ubus names for multiple instances | expand

Commit Message

Etan Kissling June 27, 2021, 8:01 p.m. UTC
Currently, when using multiple dnsmasq instances they are all assigned
to the same Ubus instance name. This does not work, as only a single
instance can register with Ubus at a time. In the log, this leads to
`Cannot add object to UBus: Invalid argument` error messages.
Furthermore, upstream 3c93e8eb41952a9c91699386132d6fe83050e9be changes
behaviour so that instead of the log, dnsmasq crashes instead.
This means that dnsmasq versions v2.86test2 and newer no longer apply.

When /etc/config/dhcp defines multiple named dnsmasq instances, this
patch now assigns unique names to each of them. This lets all instances
register with Ubus concurrently under their own names. To avoid breaking
backwards compatibility with packages relying on the old default name,
unnamed dnsmasq instances retain previous behaviour. This works well in
the common scenario of a single dnsmasq instance. With multiple unnamed
instances present, the config should be updated accordingly and Ubus
either disabled on all but one of them, or them being named accordingly.

Signed-off-by: Etan Kissling <etan.kissling@gmail.com>
---
v5: Introduce this patch so that dnsmasq can be updated.

 package/network/services/dnsmasq/files/dnsmasq.init | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/package/network/services/dnsmasq/files/dnsmasq.init b/package/network/services/dnsmasq/files/dnsmasq.init
index 44e7d2d4f9..0a200861a1 100644
--- a/package/network/services/dnsmasq/files/dnsmasq.init
+++ b/package/network/services/dnsmasq/files/dnsmasq.init
@@ -801,6 +801,12 @@  dnsmasq_start()
 	config_get_bool disabled "$cfg" disabled 0
 	[ "$disabled" -gt 0 ] && return 0
 
+	# assign instance name
+	local instancename="dnsmasq"
+	if expr "$cfg" : "cfg[0-9a-f]*" >/dev/null != "9"; then
+		instancename="dnsmasq.$cfg" # named config section
+	fi
+
 	# reset list of DOMAINS and DNS servers (for each dnsmasq instance)
 	DNS_SERVERS=""
 	DOMAIN=""
@@ -879,7 +885,8 @@  dnsmasq_start()
 	append_bool "$cfg" localise_queries "--localise-queries"
 	append_bool "$cfg" readethers "--read-ethers"
 	append_bool "$cfg" dbus "--enable-dbus"
-	append_bool "$cfg" ubus "--enable-ubus"	1
+	config_get_bool ubus "$cfg" "ubus" 1
+	[ $ubus -eq 1 ] && xappend "--enable-ubus=$instancename"
 	append_bool "$cfg" expandhosts "--expand-hosts"
 	config_get tftp_root "$cfg" "tftp_root"
 	[ -n "$tftp_root" ] && mkdir -p "$tftp_root" && append_bool "$cfg" enable_tftp "--enable-tftp"