dnsmasq: add dns redirect option

Co-authored-by: Lienol <23146169+Lienol@users.noreply.github.com>

(squashed from 99bfa54acfecf409cb46e4f3f31350541ef81891)

Signed-off-by: Liangbin Lian <jjm2473@gmail.com>
This commit is contained in:
Tianling Shen 2025-12-04 12:18:40 +08:00 committed by Liangbin Lian
parent 1fc70d9aa3
commit 395bcde734
2 changed files with 18 additions and 1 deletions

View File

@ -10,7 +10,7 @@ include $(TOPDIR)/rules.mk
PKG_NAME:=dnsmasq
PKG_UPSTREAM_VERSION:=2.90
PKG_VERSION:=$(subst test,~~test,$(subst rc,~rc,$(PKG_UPSTREAM_VERSION)))
PKG_RELEASE:=4
PKG_RELEASE:=5
PKG_SOURCE:=$(PKG_NAME)-$(PKG_UPSTREAM_VERSION).tar.xz
PKG_SOURCE_URL:=https://thekelleys.org.uk/dnsmasq/

View File

@ -1272,6 +1272,14 @@ dnsmasq_start()
[ -e "$hostsfile" ] && procd_add_jail_mount $hostsfile
procd_close_instance
config_get_bool dns_redirect "$cfg" dns_redirect 0
config_get dns_port "$cfg" port 53
if [ "$dns_redirect" = 1 ]; then
nft add table inet dnsmasq
nft add chain inet dnsmasq prerouting "{ type nat hook prerouting priority -95; policy accept; }"
nft add rule inet dnsmasq prerouting "meta nfproto { ipv4, ipv6 } udp dport 53 counter redirect to :$dns_port comment \"DNSMASQ HIJACK\""
fi
}
dnsmasq_stop()
@ -1289,6 +1297,12 @@ dnsmasq_stop()
rm -f ${BASEDHCPSTAMPFILE}.${cfg}.*.dhcp
}
nftables_clear()
{
! nft --check list table inet dnsmasq > "/dev/null" 2>&1 || \
nft delete table inet dnsmasq
}
add_interface_trigger()
{
local interface ifname ignore
@ -1360,6 +1374,7 @@ start_service() {
}
reload_service() {
nftables_clear
rc_procd start_service "$@"
procd_send_signal dnsmasq "$@"
}
@ -1386,4 +1401,6 @@ stop_service() {
else
config_foreach dnsmasq_stop dnsmasq
fi
nftables_clear
}