Message ID | 20190223021732.7210-1-yszhou4tech@gmail.com |
---|---|
State | Accepted |
Headers | show |
Series | [OpenWrt-Devel,18.06,1/2] dnsmasq: allow using dnsmasq as the sole resolver | expand |
On Sat, Feb 23, 2019 at 3:17 AM Yousong Zhou <yszhou4tech@gmail.com> wrote: > > Currently it seems impossible to configure /etc/config/dhcp to achieve > the following use case > > - run dnsmasq with no-resolv > - re-generate /etc/resolv.conf with "nameserver 127.0.0.1" > > Before this change, we have to set resolvfile to /tmp/resolv.conf.auto > to achive the 2nd effect above, but setting resolvfile requires noresolv > being false. > > A new boolean option "localuse" is added to indicate that we intend to > use dnsmasq as the local dns resolver. It's false by default and to > align with old behaviour it will be true automatically if resolvfile is > set to /tmp/resolv.conf.auto > > (cherry picked from 2aea1ada65f050d74a064e74466bbe4e8d) > Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com> Acked-by: Hans Dedecker <dedeckeh@gmail.com> > --- > package/network/services/dnsmasq/Makefile | 2 +- > .../services/dnsmasq/files/dnsmasq.init | 30 +++++++++---------- > 2 files changed, 16 insertions(+), 16 deletions(-) > > diff --git a/package/network/services/dnsmasq/Makefile b/package/network/services/dnsmasq/Makefile > index e89ad19f5c..c50717d091 100644 > --- a/package/network/services/dnsmasq/Makefile > +++ b/package/network/services/dnsmasq/Makefile > @@ -9,7 +9,7 @@ include $(TOPDIR)/rules.mk > > PKG_NAME:=dnsmasq > PKG_VERSION:=2.80 > -PKG_RELEASE:=1.2 > +PKG_RELEASE:=1.3 > > PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.xz > PKG_SOURCE_URL:=http://thekelleys.org.uk/dnsmasq > diff --git a/package/network/services/dnsmasq/files/dnsmasq.init b/package/network/services/dnsmasq/files/dnsmasq.init > index 9c922eec6c..b119981cb8 100644 > --- a/package/network/services/dnsmasq/files/dnsmasq.init > +++ b/package/network/services/dnsmasq/files/dnsmasq.init > @@ -731,7 +731,9 @@ dhcp_relay_add() { > > dnsmasq_start() > { > - local cfg="$1" disabled resolvfile user_dhcpscript > + local cfg="$1" > + local disabled user_dhcpscript > + local resolvfile localuse > > config_get_bool disabled "$cfg" disabled 0 > [ "$disabled" -gt 0 ] && return 0 > @@ -881,14 +883,14 @@ dnsmasq_start() > config_get_bool cachelocal "$cfg" cachelocal 1 > > config_get_bool noresolv "$cfg" noresolv 0 > + config_get_bool localuse "$cfg" localuse 0 > if [ "$noresolv" != "1" ]; then > - config_get resolvfile "$cfg" resolvfile "/tmp/resolv.conf.auto" > - # So jail doesn't complain if file missing > - [ -n "$resolvfile" -a \! -e "$resolvfile" ] && touch "$resolvfile" > + config_get resolvfile "$cfg" resolvfile /tmp/resolv.conf.auto > + [ -n "$resolvfile" -a ! -e "$resolvfile" ] && touch "$resolvfile" > + xappend "--resolv-file=$resolvfile" > + [ "$resolvfile" = "/tmp/resolv.conf.auto" ] && localuse=1 > fi > > - [ -n "$resolvfile" ] && xappend "--resolv-file=$resolvfile" > - > config_get hostsfile "$cfg" dhcphostsfile > [ -e "$hostsfile" ] && xappend "--dhcp-hostsfile=$hostsfile" > > @@ -1010,7 +1012,7 @@ dnsmasq_start() > mv -f $CONFIGFILE_TMP $CONFIGFILE > mv -f $HOSTFILE_TMP $HOSTFILE > > - [ "$resolvfile" = "/tmp/resolv.conf.auto" ] && { > + [ "$localuse" -gt 0 ] && { > rm -f /tmp/resolv.conf > [ $ADD_LOCAL_DOMAIN -eq 1 ] && [ -n "$DOMAIN" ] && { > echo "search $DOMAIN" >> /tmp/resolv.conf > @@ -1036,17 +1038,15 @@ dnsmasq_start() > > dnsmasq_stop() > { > - local cfg="$1" resolvfile > + local cfg="$1" > + local noresolv resolvfile localuse > > + config_get_bool noresolv "$cfg" noresolv 0 > + config_get_bool localuse "$cfg" localuse 0 > config_get resolvfile "$cfg" "resolvfile" > > - #relink /tmp/resolve.conf only for main instance > - [ "$resolvfile" = "/tmp/resolv.conf.auto" ] && { > - [ -f /tmp/resolv.conf ] && { > - rm -f /tmp/resolv.conf > - ln -s "$resolvfile" /tmp/resolv.conf > - } > - } > + [ "$noresolv" = 0 -a "$resolvfile" = "/tmp/resolv.conf.auto" ] && localuse=1 > + [ "$localuse" -gt 0 ] && ln -sf "/tmp/resolv.conf.auto" /tmp/resolv.conf > > rm -f ${BASEDHCPSTAMPFILE}.${cfg}.*.dhcp > }
> Op 23 feb. 2019, om 03:17 heeft Yousong Zhou <yszhou4tech@gmail.com> het volgende geschreven: > > Currently it seems impossible to configure /etc/config/dhcp to achieve > the following use case > > - run dnsmasq with no-resolv > - re-generate /etc/resolv.conf with "nameserver 127.0.0.1" > > Before this change, we have to set resolvfile to /tmp/resolv.conf.auto > to achive the 2nd effect above, but setting resolvfile requires noresolv > being false. > > A new boolean option "localuse" is added to indicate that we intend to > use dnsmasq as the local dns resolver. It's false by default and to > align with old behaviour it will be true automatically if resolvfile is > set to /tmp/resolv.conf.auto > > (cherry picked from 2aea1ada65f050d74a064e74466bbe4e8d) > Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com> Tested-by: Paul Oranje <por@oranjevos.nl> > --- > package/network/services/dnsmasq/Makefile | 2 +- > .../services/dnsmasq/files/dnsmasq.init | 30 +++++++++---------- > 2 files changed, 16 insertions(+), 16 deletions(-) > > diff --git a/package/network/services/dnsmasq/Makefile b/package/network/services/dnsmasq/Makefile > index e89ad19f5c..c50717d091 100644 > --- a/package/network/services/dnsmasq/Makefile > +++ b/package/network/services/dnsmasq/Makefile > @@ -9,7 +9,7 @@ include $(TOPDIR)/rules.mk > > PKG_NAME:=dnsmasq > PKG_VERSION:=2.80 > -PKG_RELEASE:=1.2 > +PKG_RELEASE:=1.3 > > PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.xz > PKG_SOURCE_URL:=http://thekelleys.org.uk/dnsmasq > diff --git a/package/network/services/dnsmasq/files/dnsmasq.init b/package/network/services/dnsmasq/files/dnsmasq.init > index 9c922eec6c..b119981cb8 100644 > --- a/package/network/services/dnsmasq/files/dnsmasq.init > +++ b/package/network/services/dnsmasq/files/dnsmasq.init > @@ -731,7 +731,9 @@ dhcp_relay_add() { > > dnsmasq_start() > { > - local cfg="$1" disabled resolvfile user_dhcpscript > + local cfg="$1" > + local disabled user_dhcpscript > + local resolvfile localuse > > config_get_bool disabled "$cfg" disabled 0 > [ "$disabled" -gt 0 ] && return 0 > @@ -881,14 +883,14 @@ dnsmasq_start() > config_get_bool cachelocal "$cfg" cachelocal 1 > > config_get_bool noresolv "$cfg" noresolv 0 > + config_get_bool localuse "$cfg" localuse 0 > if [ "$noresolv" != "1" ]; then > - config_get resolvfile "$cfg" resolvfile "/tmp/resolv.conf.auto" > - # So jail doesn't complain if file missing > - [ -n "$resolvfile" -a \! -e "$resolvfile" ] && touch "$resolvfile" > + config_get resolvfile "$cfg" resolvfile /tmp/resolv.conf.auto > + [ -n "$resolvfile" -a ! -e "$resolvfile" ] && touch "$resolvfile" > + xappend "--resolv-file=$resolvfile" > + [ "$resolvfile" = "/tmp/resolv.conf.auto" ] && localuse=1 > fi > > - [ -n "$resolvfile" ] && xappend "--resolv-file=$resolvfile" > - > config_get hostsfile "$cfg" dhcphostsfile > [ -e "$hostsfile" ] && xappend "--dhcp-hostsfile=$hostsfile" > > @@ -1010,7 +1012,7 @@ dnsmasq_start() > mv -f $CONFIGFILE_TMP $CONFIGFILE > mv -f $HOSTFILE_TMP $HOSTFILE > > - [ "$resolvfile" = "/tmp/resolv.conf.auto" ] && { > + [ "$localuse" -gt 0 ] && { > rm -f /tmp/resolv.conf > [ $ADD_LOCAL_DOMAIN -eq 1 ] && [ -n "$DOMAIN" ] && { > echo "search $DOMAIN" >> /tmp/resolv.conf > @@ -1036,17 +1038,15 @@ dnsmasq_start() > > dnsmasq_stop() > { > - local cfg="$1" resolvfile > + local cfg="$1" > + local noresolv resolvfile localuse > > + config_get_bool noresolv "$cfg" noresolv 0 > + config_get_bool localuse "$cfg" localuse 0 > config_get resolvfile "$cfg" "resolvfile" > > - #relink /tmp/resolve.conf only for main instance > - [ "$resolvfile" = "/tmp/resolv.conf.auto" ] && { > - [ -f /tmp/resolv.conf ] && { > - rm -f /tmp/resolv.conf > - ln -s "$resolvfile" /tmp/resolv.conf > - } > - } > + [ "$noresolv" = 0 -a "$resolvfile" = "/tmp/resolv.conf.auto" ] && localuse=1 > + [ "$localuse" -gt 0 ] && ln -sf "/tmp/resolv.conf.auto" /tmp/resolv.conf > > rm -f ${BASEDHCPSTAMPFILE}.${cfg}.*.dhcp > }
diff --git a/package/network/services/dnsmasq/Makefile b/package/network/services/dnsmasq/Makefile index e89ad19f5c..c50717d091 100644 --- a/package/network/services/dnsmasq/Makefile +++ b/package/network/services/dnsmasq/Makefile @@ -9,7 +9,7 @@ include $(TOPDIR)/rules.mk PKG_NAME:=dnsmasq PKG_VERSION:=2.80 -PKG_RELEASE:=1.2 +PKG_RELEASE:=1.3 PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.xz PKG_SOURCE_URL:=http://thekelleys.org.uk/dnsmasq diff --git a/package/network/services/dnsmasq/files/dnsmasq.init b/package/network/services/dnsmasq/files/dnsmasq.init index 9c922eec6c..b119981cb8 100644 --- a/package/network/services/dnsmasq/files/dnsmasq.init +++ b/package/network/services/dnsmasq/files/dnsmasq.init @@ -731,7 +731,9 @@ dhcp_relay_add() { dnsmasq_start() { - local cfg="$1" disabled resolvfile user_dhcpscript + local cfg="$1" + local disabled user_dhcpscript + local resolvfile localuse config_get_bool disabled "$cfg" disabled 0 [ "$disabled" -gt 0 ] && return 0 @@ -881,14 +883,14 @@ dnsmasq_start() config_get_bool cachelocal "$cfg" cachelocal 1 config_get_bool noresolv "$cfg" noresolv 0 + config_get_bool localuse "$cfg" localuse 0 if [ "$noresolv" != "1" ]; then - config_get resolvfile "$cfg" resolvfile "/tmp/resolv.conf.auto" - # So jail doesn't complain if file missing - [ -n "$resolvfile" -a \! -e "$resolvfile" ] && touch "$resolvfile" + config_get resolvfile "$cfg" resolvfile /tmp/resolv.conf.auto + [ -n "$resolvfile" -a ! -e "$resolvfile" ] && touch "$resolvfile" + xappend "--resolv-file=$resolvfile" + [ "$resolvfile" = "/tmp/resolv.conf.auto" ] && localuse=1 fi - [ -n "$resolvfile" ] && xappend "--resolv-file=$resolvfile" - config_get hostsfile "$cfg" dhcphostsfile [ -e "$hostsfile" ] && xappend "--dhcp-hostsfile=$hostsfile" @@ -1010,7 +1012,7 @@ dnsmasq_start() mv -f $CONFIGFILE_TMP $CONFIGFILE mv -f $HOSTFILE_TMP $HOSTFILE - [ "$resolvfile" = "/tmp/resolv.conf.auto" ] && { + [ "$localuse" -gt 0 ] && { rm -f /tmp/resolv.conf [ $ADD_LOCAL_DOMAIN -eq 1 ] && [ -n "$DOMAIN" ] && { echo "search $DOMAIN" >> /tmp/resolv.conf @@ -1036,17 +1038,15 @@ dnsmasq_start() dnsmasq_stop() { - local cfg="$1" resolvfile + local cfg="$1" + local noresolv resolvfile localuse + config_get_bool noresolv "$cfg" noresolv 0 + config_get_bool localuse "$cfg" localuse 0 config_get resolvfile "$cfg" "resolvfile" - #relink /tmp/resolve.conf only for main instance - [ "$resolvfile" = "/tmp/resolv.conf.auto" ] && { - [ -f /tmp/resolv.conf ] && { - rm -f /tmp/resolv.conf - ln -s "$resolvfile" /tmp/resolv.conf - } - } + [ "$noresolv" = 0 -a "$resolvfile" = "/tmp/resolv.conf.auto" ] && localuse=1 + [ "$localuse" -gt 0 ] && ln -sf "/tmp/resolv.conf.auto" /tmp/resolv.conf rm -f ${BASEDHCPSTAMPFILE}.${cfg}.*.dhcp }
Currently it seems impossible to configure /etc/config/dhcp to achieve the following use case - run dnsmasq with no-resolv - re-generate /etc/resolv.conf with "nameserver 127.0.0.1" Before this change, we have to set resolvfile to /tmp/resolv.conf.auto to achive the 2nd effect above, but setting resolvfile requires noresolv being false. A new boolean option "localuse" is added to indicate that we intend to use dnsmasq as the local dns resolver. It's false by default and to align with old behaviour it will be true automatically if resolvfile is set to /tmp/resolv.conf.auto (cherry picked from 2aea1ada65f050d74a064e74466bbe4e8d) Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com> --- package/network/services/dnsmasq/Makefile | 2 +- .../services/dnsmasq/files/dnsmasq.init | 30 +++++++++---------- 2 files changed, 16 insertions(+), 16 deletions(-)