From e79a991d75097811cce71eff985d06f8eadbddd2 Mon Sep 17 00:00:00 2001 From: sbwml Date: Tue, 7 Nov 2023 13:15:56 +0800 Subject: [PATCH] luci-app-mosdns: add optional `prefer_ipv4` for remote dns Signed-off-by: sbwml --- luci-app-mosdns/Makefile | 2 +- luci-app-mosdns/luasrc/model/cbi/mosdns/basic.lua | 4 ++++ luci-app-mosdns/po/zh-cn/mosdns.po | 6 ++++++ luci-app-mosdns/root/etc/config/mosdns | 1 + luci-app-mosdns/root/etc/init.d/mosdns | 3 +++ 5 files changed, 15 insertions(+), 1 deletion(-) diff --git a/luci-app-mosdns/Makefile b/luci-app-mosdns/Makefile index 2f726b1..9e81e03 100644 --- a/luci-app-mosdns/Makefile +++ b/luci-app-mosdns/Makefile @@ -1,7 +1,7 @@ include $(TOPDIR)/rules.mk PKG_NAME:=luci-app-mosdns -PKG_VERSION:=1.5.16 +PKG_VERSION:=1.5.17 PKG_RELEASE:=1 LUCI_TITLE:=LuCI Support for mosdns diff --git a/luci-app-mosdns/luasrc/model/cbi/mosdns/basic.lua b/luci-app-mosdns/luasrc/model/cbi/mosdns/basic.lua index 7793889..e10da07 100644 --- a/luci-app-mosdns/luasrc/model/cbi/mosdns/basic.lua +++ b/luci-app-mosdns/luasrc/model/cbi/mosdns/basic.lua @@ -47,6 +47,10 @@ o:depends("configfile", "/etc/mosdns/config.yaml") o = s:taboption("basic", Flag, "redirect", translate("DNS Forward"), translate("Forward Dnsmasq Domain Name resolution requests to MosDNS")) o.default = true +o = s:taboption("basic", Flag, "prefer_ipv4", translate("Remote DNS prefer IPv4"), translate("IPv4 is preferred for remote DNS resolution of dual-stack addresses, and is not affected when the destination is IPv6 only")) +o:depends( "configfile", "/etc/mosdns/config.yaml") +o.default = true + o = s:taboption("basic", Flag, "custom_local_dns", translate("Custom China DNS"), translate("Follow WAN interface DNS if not enabled")) o:depends( "configfile", "/etc/mosdns/config.yaml") o.default = false diff --git a/luci-app-mosdns/po/zh-cn/mosdns.po b/luci-app-mosdns/po/zh-cn/mosdns.po index f2faa11..0785980 100644 --- a/luci-app-mosdns/po/zh-cn/mosdns.po +++ b/luci-app-mosdns/po/zh-cn/mosdns.po @@ -160,6 +160,12 @@ msgstr "自定义" msgid "Log File" msgstr "日志文件" +msgid "Remote DNS prefer IPv4" +msgstr "远程 DNS 首选 IPv4" + +msgid "IPv4 is preferred for remote DNS resolution of dual-stack addresses, and is not affected when the destination is IPv6 only" +msgstr "远程 DNS 解析双栈地址时首选 IPv4,目标仅 IPv6 时不受影响" + msgid "Custom China DNS" msgstr "自定义国内 DNS" diff --git a/luci-app-mosdns/root/etc/config/mosdns b/luci-app-mosdns/root/etc/config/mosdns index d6b3f46..8d3408c 100644 --- a/luci-app-mosdns/root/etc/config/mosdns +++ b/luci-app-mosdns/root/etc/config/mosdns @@ -6,6 +6,7 @@ config mosdns 'config' option geo_update_week_time '*' option geo_update_day_time '2' option redirect '1' + option prefer_ipv4 '1' option adblock '0' option configfile '/etc/mosdns/config.yaml' option log_level 'info' diff --git a/luci-app-mosdns/root/etc/init.d/mosdns b/luci-app-mosdns/root/etc/init.d/mosdns index 8b7c9f9..bed7999 100755 --- a/luci-app-mosdns/root/etc/init.d/mosdns +++ b/luci-app-mosdns/root/etc/init.d/mosdns @@ -49,6 +49,7 @@ get_config() { config_get maximum_ttl_custom $1 maximum_ttl 0 config_get minimal_ttl_custom $1 minimal_ttl 0 config_get redirect $1 redirect 0 + config_get prefer_ipv4 $1 prefer_ipv4 0 config_get remote_dns $1 remote_dns "tls://8.8.8.8 tls://1.1.1.1" config_get custom_local_dns $1 custom_local_dns 0 config_get apple_optimization $1 apple_optimization 0 @@ -111,6 +112,8 @@ init_yaml() { sed -i -e '/- addr: local_dns/{r '$TMPDIR/local_dns.txt -e';d};/- addr: remote_dns/{r '$TMPDIR/remote_dns.txt -e';d}' $CONF # Convert HTTP/3 prefix format sed -i 's/h3:\/\//https:\/\//g' $CONF + # Prefer IPv4 + [ $prefer_ipv4 -ne 1 ] && sed -i "/prefer_ipv4/d" $CONF # Cache dump [ "$dump_file" -eq 1 ] && sed -i "/lazy_cache_ttl/a\ dump_file: $DUMP_FILE\n dump_interval: $dump_interval" $CONF [ "$dump_file" -eq 1 ] && [ ! -f $DUMP_FILE ] && cp -a $DUMP_FILE_DEFAULT $DUMP_FILE