luci-app-mosdns: add Apple domain name optimization option

* Some public DNS upstreams will incorrectly respond to the apple domain name as a foreign CDN (such as encrypted DNSPod & alidns).
* Forcing the apple domain name to use DNSPod udp and XinFeng dns for resolution can avoid the problem of responding to foreign CDN.
This commit is contained in:
sbwml 2023-09-27 17:00:44 +08:00
parent 7d01c798fd
commit d9360a37ec
6 changed files with 50 additions and 2 deletions

View File

@ -1,7 +1,7 @@
include $(TOPDIR)/rules.mk
PKG_NAME:=luci-app-mosdns
PKG_VERSION:=1.5.10
PKG_VERSION:=1.5.11
PKG_RELEASE:=1
LUCI_TITLE:=LuCI Support for mosdns

View File

@ -50,6 +50,11 @@ o.default = true
o = s:taboption("basic", Flag, "custom_local_dns", translate("Local DNS"), translate("Follow WAN interface DNS if not enabled"))
o:depends( "configfile", "/etc/mosdns/config.yaml")
o.default = false
o = s:taboption("basic", Flag, "apple_optimization", translate("Apple domains optimization"), translate("For Apple domains equipped with Chinese mainland CDN, always responsive to Chinese CDN IP addresses"))
o:depends("custom_local_dns", "1")
o.default = true
o = s:taboption("basic", DynamicList, "local_dns", translate("Upstream DNS servers"))
o:value("119.29.29.29", "119.29.29.29 (DNSPod Primary)")
o:value("119.28.28.28", "119.28.28.28 (DNSPod Secondary)")

View File

@ -160,6 +160,12 @@ msgstr "本地 DNS"
msgid "Follow WAN interface DNS if not enabled"
msgstr "不启用则使用 WAN 接口 DNS"
msgid "Apple domains optimization"
msgstr "Apple 域名解析优化"
msgid "For Apple domains equipped with Chinese mainland CDN, always responsive to Chinese CDN IP addresses"
msgstr "配备中国大陆 CDN 的 Apple 域名,始终应答中国大陆 CDN 地址"
msgid "Upstream DNS servers"
msgstr "上游 DNS 服务器"

View File

@ -52,6 +52,7 @@ get_config() {
config_get redirect $1 redirect 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
config_get bootstrap_dns $1 bootstrap_dns "119.29.29.29"
config_get listen_port_api $1 listen_port_api 9091
config_get concurrent $1 concurrent 1
@ -92,6 +93,8 @@ init_yaml() {
s,maximum_ttl_custom,$maximum_ttl_custom,g; \
s,concurrent_num,$concurrent,g;s,api_port,$listen_port_api,g; \
s,remote_dns_pipeline,$enable_pipeline,g" $DEFAULT_CONF > $CONF
# Apple optimization
[ "$apple_optimization" != 1 ] && sed -i '/- exec: \$query_is_apple_domain/,+1d' $CONF
# Adlist
adlist=$($MOSDNS_SCRIPT adlist)
echo "${adlist}" > $TMPDIR/adlist_files.txt

View File

@ -20,6 +20,12 @@ plugins:
files:
- "/var/mosdns/geoip_cn.txt"
- tag: geosite_apple
type: domain_set
args:
files:
- "/var/mosdns/geosite_apple.txt"
- tag: geosite_no_cn
type: domain_set
args:
@ -86,6 +92,22 @@ plugins:
size: cache_size
lazy_cache_ttl: cache_survival_time
- tag: forward_dnspod_udp
type: forward
args:
concurrent: 2
upstreams:
- addr: "119.29.29.29"
- addr: "119.28.28.28"
- tag: forward_xinfeng_udp
type: forward
args:
concurrent: 2
upstreams:
- addr: "114.114.114.114"
- addr: "114.114.115.115"
- tag: forward_local
type: forward
args:
@ -154,6 +176,16 @@ plugins:
threshold: 500
always_standby: true
- tag: query_is_apple_domain
type: sequence
args:
- matches: qname $geosite_apple
exec: $forward_dnspod_udp
- matches: "!resp_ip $geoip_cn"
exec: drop_resp
- matches: "!has_resp"
exec: $forward_xinfeng_udp
- tag: query_is_ddns_domain
type: sequence
args:
@ -211,6 +243,8 @@ plugins:
exec: $lazy_cache
- exec: $redirect
- exec: jump has_resp_sequence
- exec: $query_is_apple_domain
- exec: jump has_resp_sequence
- exec: $query_is_ddns_domain
- exec: jump has_resp_sequence
- exec: $query_is_whitelist_domain

View File

@ -147,7 +147,7 @@ v2dat_dump() {
if [ "$configfile" = "/etc/mosdns/config.yaml" ]; then
# default config
v2dat unpack geoip -o /var/mosdns -f cn $v2dat_dir/geoip.dat
v2dat unpack geosite -o /var/mosdns -f cn -f 'geolocation-!cn' $v2dat_dir/geosite.dat
v2dat unpack geosite -o /var/mosdns -f cn -f apple -f 'geolocation-!cn' $v2dat_dir/geosite.dat
[ "$adblock" -eq 1 ] && [ $(echo $ad_source | grep -c geosite.dat) -ge '1' ] && v2dat unpack geosite -o /var/mosdns -f category-ads-all $v2dat_dir/geosite.dat
else
# custom config