luci-app-mosdns: Remote DNS add EDNS support (ECS)

This commit is contained in:
sbwml 2023-03-28 04:20:23 +08:00
parent 916183687e
commit e0f74b9b3b
5 changed files with 42 additions and 1 deletions

View File

@ -119,6 +119,11 @@ o.rmempty = false
o.default = false
o:depends("configfile", "/etc/mosdns/config.yaml")
o = s:taboption("advanced", Flag, "enable_ecs_remote", translate("Enable EDNS client subnet"), translate("Add the EDNS Client Subnet option (ECS) to Remote DNS") .. '<br />' .. translate("MosDNS will auto identify the IP address subnet segment of your remote connection (.0/24)") .. '<br />' .. translate("If your remote access network changes, May need restart MosDNS to update the ECS request address"))
o.rmempty = false
o.default = false
o:depends("configfile", "/etc/mosdns/config.yaml")
o = s:taboption("advanced", Value, "cache_size", translate("DNS Cache Size"))
o.datatype = "and(uinteger,min(0))"
o.default = "20000"

View File

@ -176,11 +176,23 @@ msgid "Disable TLS Servers certificate validation, Can be useful if system CA ce
msgstr "禁用 TLS 服务器证书验证,当系统 CA 证书过期或系统时间错乱时,本选项可能会有用"
msgid "Enable HTTP/3"
msgstr "启用 HTTP3"
msgstr "启用 HTTP/3"
msgid "Enable DoH HTTP/3 protocol support for remote DNS, Upstream DNS server support is required (Experimental)"
msgstr "为远程 DNS 启用 DoH HTTP/3 协议支持,需要上游 DNS 服务器支持(实验性,谨慎启用该功能)"
msgid "Enable EDNS client subnet"
msgstr "启用 EDNS 客户端子网"
msgid "Add the EDNS Client Subnet option (ECS) to Remote DNS"
msgstr "在远程 DNS 请求中加入 EDNS 客户端子网(即 ECS选项需要上游 DNS 服务器支持)"
msgid "MosDNS will auto identify the IP address subnet segment of your remote connection (.0/24)"
msgstr "MosDNS 将会自动获取您访问远程连接时使用的 IP 子网段(.0/24"
msgid "If your remote access network changes, May need restart MosDNS to update the ECS request address"
msgstr "如果您的远程访问网络发生改变时可能需要重启 MosDNS 以更新 ECS 请求地址"
msgid "DNS Cache Size"
msgstr "DNS 缓存大小(条)"

View File

@ -60,6 +60,7 @@ get_config() {
config_get insecure_skip_verify $1 insecure_skip_verify 0
config_get idle_timeout $1 idle_timeout 30
config_get enable_http3 $1 enable_http3 0
config_get enable_ecs_remote $1 enable_ecs_remote 0
}
init_yaml() {
@ -87,6 +88,12 @@ init_yaml() {
[ "$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
[ "$dump_file" -eq 0 ] && \cp -a $DUMP_FILE_DEFAULT $DUMP_FILE
if [ "$enable_ecs_remote" -eq 1 ]; then
ecs_remote=$(sh /usr/share/mosdns/mosdns.sh ecs_remote)
sed -i "s,ecs_remote,$ecs_remote,g" $CONF
else
sed -i "/ecs_remote/d;" $CONF
fi
rm -rf $TMPDIR
}

View File

@ -108,6 +108,7 @@ plugins:
type: sequence
args:
- exec: prefer_ipv4
- exec: ecs_remote
- exec: $forward_remote
- tag: has_resp_sequence

View File

@ -84,6 +84,16 @@ restart_service() {
/etc/init.d/mosdns restart
}
ecs_local() {
ipaddr=$(curl -s -4 --connect-timeout 2 -H "Host:ip.3322.org" 118.184.169.32) || ipaddr=119.29.0.0
echo "ecs ${ipaddr%.*}.0/24"
}
ecs_remote() {
ipaddr=$(curl -s -4 --connect-timeout 2 -H "Host:icanhazip.com" 104.18.114.97) || ipaddr=103.103.65.0
echo "ecs ${ipaddr%.*}.0/24"
}
case $script_action in
"dns")
interface_dns
@ -100,6 +110,12 @@ case $script_action in
"adlist_update")
adlist_update && restart_service
;;
"ecs_local")
ecs_local
;;
"ecs_remote")
ecs_remote
;;
"version")
mosdns version
;;