From 3d918ce54dacc4b6d36237b450d8b62b29d8131d Mon Sep 17 00:00:00 2001 From: Tianling Shen Date: Mon, 23 Jan 2023 18:31:27 +0800 Subject: [PATCH] dnsmasq: cleanup nftables hijack commands Signed-off-by: Tianling Shen --- .../network/services/dnsmasq/files/dnsmasq.init | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/package/network/services/dnsmasq/files/dnsmasq.init b/package/network/services/dnsmasq/files/dnsmasq.init index 334adabb66..a36aa5ee8e 100755 --- a/package/network/services/dnsmasq/files/dnsmasq.init +++ b/package/network/services/dnsmasq/files/dnsmasq.init @@ -1220,15 +1220,9 @@ dnsmasq_start() config_get_bool dns_redirect "$cfg" dns_redirect 0 config_get dns_port "$cfg" port 53 if [ "$dns_redirect" = 1 ]; then - cat <<-EOF > /tmp/dnsmasq-dns-redirect.nft - table inet dnsmasq { - chain prerouting { - type nat hook prerouting priority -105; policy accept; - meta nfproto {ipv4, ipv6} udp dport 53 counter redirect to :$dns_port comment "DNSMASQ"; - } - } - EOF - nft -f /tmp/dnsmasq-dns-redirect.nft + nft add table inet dnsmasq + nft add chain inet dnsmasq prerouting "{ type nat hook prerouting priority -105; policy accept; }" + nft add rule inet dnsmasq prerouting "meta nfproto { ipv4, ipv6 } udp dport 53 counter redirect to :53 comment \"DNSMASQ HIJACK\"" fi } @@ -1249,11 +1243,8 @@ dnsmasq_stop() nftables_clear() { - nft --check list table inet dnsmasq > /dev/null 2>&1 - if [ $? -eq "0" ]; then - echo "Remove dnsmasq nat table" + ! nft --check list table inet dnsmasq > "/dev/null" 2>&1 || \ nft delete table inet dnsmasq - fi } add_interface_trigger()