dnsmasq: skip options that are not compiled in
authorYousong Zhou <yszhou4tech@gmail.com>
Sat, 25 May 2019 09:58:18 +0000 (09:58 +0000)
committerYousong Zhou <yszhou4tech@gmail.com>
Sun, 9 Jun 2019 08:17:52 +0000 (08:17 +0000)
This is to make life easier for users with customized build of
dnsmasq-full variant.  Currently dnsmasq config generated by current
service script will be rejected by dnsmasq build lacking DHCP feature

 - Options like --dhcp-leasefile have default values.  Deleting them
   from uci config or setting them to empty value will make them take on
   default value in the end
 - Options like --dhcp-broadcast are output unconditionally

Tackle this by

 - Check availablility of features from output of "dnsmasq --version"
 - Make a list of options guarded by HAVE_xx macros in src/options.c of
   dnsmasq source code
 - Ignore these options in xappend()

Two things to note in this implementation

 - The option list is not exhaustive.  Supposedly only those options that
   may cause dnsmasq to reject with "unsupported option (check that
   dnsmasq was compiled with DHCP/TFTP/DNSSEC/DBus support)" are taken
   into account here
 - This provides a way out but users' cooperation is still needed.  E.g.
   option dnssec needs to be turned off, otherwise the service script
   will try to add --conf-file pointing to dnssec specific anchor file
   which dnsmasq lacking dnssec support will reject

Resolves FS#2281

Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>
package/network/services/dnsmasq/Makefile
package/network/services/dnsmasq/files/dnsmasq.init

index 1710ded5f88ed1e0b46a8ae2d37f553a91d4bf23..419526bdd868c58282d8e52809b2bd65679e2f5c 100644 (file)
@@ -10,7 +10,7 @@ include $(TOPDIR)/rules.mk
 PKG_NAME:=dnsmasq
 PKG_UPSTREAM_VERSION:=2.80
 PKG_VERSION:=$(subst test,~~test,$(subst rc,~rc,$(PKG_UPSTREAM_VERSION)))
-PKG_RELEASE:=11
+PKG_RELEASE:=12
 
 PKG_SOURCE:=$(PKG_NAME)-$(PKG_UPSTREAM_VERSION).tar.xz
 PKG_SOURCE_URL:=http://thekelleys.org.uk/dnsmasq
index 93a8f9a108092bba17fbbae90c9dfaf02478fcc1..e19c56f6a92348a3dda66d96a1bb475178712fb3 100644 (file)
@@ -22,10 +22,42 @@ DHCPSCRIPT="/usr/lib/dnsmasq/dhcp-script.sh"
 
 DNSMASQ_DHCP_VER=4
 
+dnsmasq_features="$(dnsmasq --version | grep -m1 'Compile time options:' | cut -d: -f2) "
+[ "${dnsmasq_features#* DHCP }" = "$dnsmasq_features" ] || dnsmasq_has_dhcp=1
+[ "${dnsmasq_features#* DHCPv6 }" = "$dnsmasq_features" ] || dnsmasq_has_dhcp6=1
+[ "${dnsmasq_features#* DNSSEC }" = "$dnsmasq_features" ] || dnsmasq_has_dnssec=1
+[ "${dnsmasq_features#* TFTP }" = "$dnsmasq_features" ] || dnsmasq_has_tftp=1
+[ "${dnsmasq_features#* ipset }" = "$dnsmasq_features" ] || dnsmasq_has_ipset=1
+dnsmasq_ignore_opt() {
+       local opt="$1"
+
+       case "$opt" in
+               dhcp-duid|\
+               ra-param)
+                       [ -z "$dnsmasq_has_dhcp6" ] ;;
+               dhcp-*|\
+               bootp-*|\
+               pxe-*)
+                       [ -z "$dnsmasq_has_dhcp" ] ;;
+               dnssec-*|\
+               trust-anchor)
+                       [ -z "$dnsmasq_has_dnssec" ] ;;
+               tftp-*)
+                       [ -z "$dnsmasq_has_tftp" ] ;;
+               ipset)
+                       [ -z "$dnsmasq_has_ipset" ] ;;
+               *)
+                       return 1
+       esac
+}
+
 xappend() {
-       local value="$1"
+       local value="${1#--}"
+       local opt="${value%%=*}"
 
-       echo "${value#--}" >> $CONFIGFILE_TMP
+       if ! dnsmasq_ignore_opt "$opt"; then
+               echo "$value" >>$CONFIGFILE_TMP
+       fi
 }
 
 hex_to_hostid() {