From patchwork Mon Feb 18 14:18:01 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yousong Zhou X-Patchwork-Id: 1044020 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=lists.openwrt.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="TtMv90ro"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="b3bks7Ux"; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4435ZF1qF8z9sNT for ; Tue, 19 Feb 2019 01:18:29 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Subject:MIME-Version:Message-Id:Date:To :From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=2rHQTVdhmbfwM/Mixdsc+sm5IEEi7ayQmm5fMtBb5vI=; b=TtMv90ro5SuyHs KP81gWQk5WSeMwJra8WBFST/S4csgjQQLpTsJuwXVssj72HnJy/qVlTqoquu5HHYnptIfDNAOZSFz 5RR22OhrU8820Wb5U3fymTQ4p+zhk7jwRl1MB1JJ4Vn7KaBYyHur2SrfUa58EBP0mGeRIGLCJw/To Ex0pPopm9B5bnNqtFDBgdQZVRZljbZu9cbo9zJVNNBeelojoW5U8pkcQ158XscVb35f4qw8f98Tf+ u19HVyXqqYwcCtQ/p98q/fFyK/B9h77iDRz5TnbdOVvzMyWuwLmR66f6vwNrBT4c977dR6IY8SQ0b DJILs7f16ZwvMDvv4rwQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1gvjkP-0006Hk-8b; Mon, 18 Feb 2019 14:18:17 +0000 Received: from mail-pf1-x42d.google.com ([2607:f8b0:4864:20::42d]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gvjkM-0006HP-DU for openwrt-devel@lists.openwrt.org; Mon, 18 Feb 2019 14:18:15 +0000 Received: by mail-pf1-x42d.google.com with SMTP id v21so5663291pfm.12 for ; Mon, 18 Feb 2019 06:18:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=zGglvrSxlkSHEbYT8/lGbjWjninJrTHk5lyTnhPQlHE=; b=b3bks7Uxnvom15f2lwTb2kKYUPt/UCbOSczgPzTXHhB8cLa3+YJylXWqtgaDPPr/IX r64PoEqjSdkYYTxANMaIZBsN8Gb/C6/sd87uLVL7Nj+uGZBe/aktn+p4zKhr0Sys6Pvr B7sqvKTPyOqUom/lPr1B1Ce0jnHJZbx5ESRqxAe0LgnB/B7YRqGc7evfAJE4EiG1l9xA VX++aZv9U3rJtHNbc0o6l/xN0bslkuBcala7G+rMGGqkQprwJNPjj5FZuVachMdpJ6Id 1wgtSfRl5EY/gX4o3vJOmKN1PN6j3l7JFa7ocr1LI8vsRLhgXnFK09QTlFmJGKV5G/kj EQJw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=zGglvrSxlkSHEbYT8/lGbjWjninJrTHk5lyTnhPQlHE=; b=MoU7KnculvkHocQouRkonLidSimQPOo0PnjNe1Q90FGZq42YC1220kx/5SOFbF1i8E L7sHPLJD+BGroqyTn1IXiOUn1nhwfxFJcI1QJ+Pw3FWgpKaaBfAjIS83nTKzaKyFsBOz 7zqmyxK6p19NAxECnhJC94BKhluRsLgD3q70MW4s9Vb78EzsLz6HrYtL1oqXkBXOjESa mSMR+jZEYTOcPbyGZ0nsqXEZVSo3vpOGjJJOG3Y7zIEr3vCMXznqid/vAgglsiWerGF2 eMlgLryMix+tdVSTQQz7mt/CUpi+lwyRRDoXQtZny1A2l/lzA+2RrGUXrjO0cfmt2mY9 YSgw== X-Gm-Message-State: AHQUAubT0qGltP9FSj8KnHlB14+So9lfGzKzNsFt1rJ+olxhloO17Jqe zgtYGvsH/I6V2AbmtRKwr6U= X-Google-Smtp-Source: AHgI3IbdL8MI/OTmW3d2NOJrDXu7KEYHqmr6ObNY2Cf/n+OMB/SkjHvYqzTAS9eBiwuKnWWwsLaaFA== X-Received: by 2002:a62:1112:: with SMTP id z18mr24336422pfi.173.1550499491294; Mon, 18 Feb 2019 06:18:11 -0800 (PST) Received: from titan.localdomain.hq.cloud.yunionyun.com ([47.52.22.109]) by smtp.gmail.com with ESMTPSA id a20sm19247470pfj.5.2019.02.18.06.18.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 18 Feb 2019 06:18:10 -0800 (PST) From: Yousong Zhou To: dedeckeh@gmail.com, ldir@darbyshire-bryant.me.uk Date: Mon, 18 Feb 2019 14:18:01 +0000 Message-Id: <20190218141801.7502-1-yszhou4tech@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190218_061814_457453_E4780923 X-CRM114-Status: GOOD ( 11.18 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at http://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:42d listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (yszhou4tech[at]gmail.com) -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain Subject: [OpenWrt-Devel] [PATCH v2] dnsmasq: allow using dnsmasq as the sole resolver X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Yousong Zhou , openwrt-devel@lists.openwrt.org Sender: "openwrt-devel" Errors-To: openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org 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 Signed-off-by: Yousong Zhou Acked-by: Hans Dedecker --- v2 <- v1 - retain /tmp/resolv.conf.auto as the default value of resolvfile when doing config_get, i.e. 2nd patch in the 1st version is now dropped - retain the old behavior of rewriting /tmp/resolv.conf when resolvfile is /tmp/resolv.conf.auto .../services/dnsmasq/files/dnsmasq.init | 30 +++++++++---------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/package/network/services/dnsmasq/files/dnsmasq.init b/package/network/services/dnsmasq/files/dnsmasq.init index f3066627d6..f65736e268 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 @@ -882,14 +884,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" @@ -1011,7 +1013,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 @@ -1037,17 +1039,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 }