From patchwork Fri Oct 23 05:02:37 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aleksandr Mezin X-Patchwork-Id: 1386504 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.openwrt.org (client-ip=2001:8b0:10b:1231::1; helo=merlin.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; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=merlin.20170209 header.b=ev0Al4/h; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=Gfl+KJ0I; dkim-atps=neutral Received: from merlin.infradead.org (merlin.infradead.org [IPv6:2001:8b0:10b:1231::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4CHXJx3rHxz9sSn for ; Fri, 23 Oct 2020 16:06:56 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject: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=anicfqO1AEO54yMYijzOPFFT0FQc5VSag8E1TRQ96tk=; b=ev0Al4/hF/SUFdBOgkkYNQEHap A0nYx7Hbw2hmG28kksIZmrCj8wnUeiPpzLAllFaIOoy8UZdrcbFX71kdILeqGQzS53JVsDXjYp6+L ZqVs84LXMdsFPNBHcZZ8QXr4MOJw2e0pEGkMShqbo83CX0KS4CN+UONJ4w8N1wcHP8Jnf5oDZ3vpw iF4KS48Zy8aRCrDLB39wYkFTN/Cb7tuMnDMzVDWMXyhBlBYTclwxf80YcBS7feJlhl8pJv1raaFPj JpncljsmPZwHboncn5Ez7lpZbGARo22hYGCVBI6tyqz+qlCT24O7nEwB5IktAj45VqyRrWzb8vNjo VfKEOpGQ==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kVpFl-00076z-5q; Fri, 23 Oct 2020 05:04:37 +0000 Received: from mail-lj1-x242.google.com ([2a00:1450:4864:20::242]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kVpEO-0006fz-Je for openwrt-devel@lists.openwrt.org; Fri, 23 Oct 2020 05:03:15 +0000 Received: by mail-lj1-x242.google.com with SMTP id c21so152520ljn.13 for ; Thu, 22 Oct 2020 22:03:11 -0700 (PDT) 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=DqPopApa5K4SK0G1tXwDdx0Tp1C2/ZZXKxABtBODvTQ=; b=Gfl+KJ0IIvFYQCuVka84knjlRyDxhjUg7naRSnGV26Pm2Wx55YPCS1MWAH6in/cfVz qDEMaIBltt0xUK/dl8tqimJ41P+L7z02yEEoCc1//FdSewp/tp7qqqmv3IN4YtOgAeTU TtxlPo9OHCKH3xYFS5xMqWiEVo8rINZWTf1bh4ntqxwAATmpRYfX1+18Um3/D7GIBYeH Ocypu70UbXzZzzRwIaYdsBhHVa3WtVxO/HpV40veMkDbnWZ5VM2eJiB3BBcds8a9U3kR b9YT+Q+l9iKD5C0S0JFKW6G4NkEOsUeq4akHd5FTtk5A6W7EZgnEt+QTwJji2rAVl0rI cvvA== 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=DqPopApa5K4SK0G1tXwDdx0Tp1C2/ZZXKxABtBODvTQ=; b=qbG6SnTAe8dWTKof1PuBEa2bnifpOUy5c9U7VCC6Hny+XeipQCiMX0J1QCA9iBhZ1L UOZ3AOd/nApvYaJjzm24FPyVgykSTliGERoRRHm3aXB/5JEwck/TxePRjYcJ/vSweK3e bg4o7ptY+q+P4uJBqyrXmsQT40iOqF3X5yzer5qNoBKFx9ISU2e+8Em5pBYYTfnLHejM FE0v1P26ABHyJbbyE9gOAfHy3e8vPnpX/kn+SLfaNxLKcGhsgD4PWCqHe8KCsdGiFaDL MBPrqA1RzsxHmJzZ8FbFtGo+U9bXwQI4+jtrPIiv2qFR+ODKyKaE57ZDQv3yNTNWLxdd nN5g== X-Gm-Message-State: AOAM532b1UlgrZIpb227FebbhjKvxQ5jtFghG07soRt0AZFUBZo/tASE 2zVLY0CfdWMt8YIgBSJgkxApqjiluAsRXQ== X-Google-Smtp-Source: ABdhPJxyMmDYutVOWanmUd1PD+py4AYVMweE3Q41gVbmJVtI8PJsmyMqs2c3bgJ9iskq55zxhmjghQ== X-Received: by 2002:a05:651c:130d:: with SMTP id u13mr140810lja.265.1603429389564; Thu, 22 Oct 2020 22:03:09 -0700 (PDT) Received: from trx40.lan ([2a02:2698:542a:1500:6b4a:8267:1413:7b63]) by smtp.gmail.com with ESMTPSA id q18sm40557ljm.23.2020.10.22.22.03.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Oct 2020 22:03:08 -0700 (PDT) From: Aleksandr Mezin To: openwrt-devel@lists.openwrt.org Subject: [PATCH] dnsmasq: 'ipset' config sections Date: Fri, 23 Oct 2020 11:02:37 +0600 Message-Id: <20201023050237.1531857-1-mezin.alexander@gmail.com> X-Mailer: git-send-email 2.29.0 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201023_010312_869435_26498B24 X-CRM114-Status: GOOD ( 10.34 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2a00:1450:4864:20:0:0:0:242 listed in] [list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [mezin.alexander[at]gmail.com] -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: OpenWrt Development List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Aleksandr Mezin Sender: "openwrt-devel" Errors-To: openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org Allow configuring ipsets with dedicated config sections: config ipset list name 'ss_rules_dst_forward' list name 'ss_rules6_dst_forward' list domain 't.me' list domain 'telegram.org' instead of current, rather inconvenient syntax: config dnsmasq ... list ipset '/t.me/telegram.org/ss_rules_dst_forward,ss_rules6_dst_forward' Current syntax will still continue to work though. With this change, a LuCI GUI for DNS ipsets should be easy to implement. Signed-off-by: Aleksandr Mezin --- .../services/dnsmasq/files/dnsmasq.init | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/package/network/services/dnsmasq/files/dnsmasq.init b/package/network/services/dnsmasq/files/dnsmasq.init index 0fa3074f92..fff8f8f793 100644 --- a/package/network/services/dnsmasq/files/dnsmasq.init +++ b/package/network/services/dnsmasq/files/dnsmasq.init @@ -769,6 +769,29 @@ dhcp_relay_add() { fi } +dnsmasq_ipset_add() { + local cfg="$1" + local ipsets domains + + add_ipset() { + ipsets="${ipsets:+$ipsets,}$1" + } + + add_domain() { + # leading '/' is expected + domains="$domains/$1" + } + + config_list_foreach "$cfg" "name" add_ipset + config_list_foreach "$cfg" "domain" add_domain + + if [ -z "$ipsets" ] || [ -z "$domains" ]; then + return 0 + fi + + xappend "--ipset=$domains/$ipsets" +} + dnsmasq_start() { local cfg="$1" @@ -1056,6 +1079,10 @@ dnsmasq_start() config_foreach filter_dnsmasq cname dhcp_cname_add "$cfg" echo >> $CONFIGFILE_TMP + echo >> $CONFIGFILE_TMP + config_foreach filter_dnsmasq ipset dnsmasq_ipset_add "$cfg" + echo >> $CONFIGFILE_TMP + echo >> $CONFIGFILE_TMP mv -f $CONFIGFILE_TMP $CONFIGFILE mv -f $HOSTFILE_TMP $HOSTFILE