Fix flowoffload and SFE disable DNS acceleration without deleting DNS forwarding errors (#6086)

This commit is contained in:
Mattraks 2020-12-23 12:31:24 +08:00 committed by GitHub
parent f0da89a98b
commit af6a5cc7a4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 323 additions and 318 deletions

View File

@ -16,32 +16,33 @@ pdnsd_genconfig() {
if [ ! -f /var/dnscache/pdnsd.cache ]; then if [ ! -f /var/dnscache/pdnsd.cache ]; then
mkdir -p /var/dnscache mkdir -p /var/dnscache
echo -ne "pd13\000\000\000\000" > /var/dnscache/pdnsd.cache echo -ne "pd13\000\000\000\000" >/var/dnscache/pdnsd.cache
chown -R nobody.nogroup /var/dnscache chown -R nobody.nogroup /var/dnscache
fi fi
cat > /var/etc/dnscache.conf <<EOF cat <<-EOF >/var/etc/dnscache.conf
global { global {
perm_cache=1024; # dns缓存大小单位KB建议不要写的太大 perm_cache=1024; # dns缓存大小单位KB建议不要写的太大
cache_dir="/var/dnscache"; # 缓存文件的位置 cache_dir="/var/dnscache"; # 缓存文件的位置
pid_file = /var/run/dnscache.pid; pid_file = /var/run/dnscache.pid;
server_ip = 0.0.0.0; # pdnsd监听的网卡0.0.0.0是全部网卡 run_as="nobody";
server_port=5333; # pdnsd监听的端口不要和别的服务冲突即可 server_ip = 0.0.0.0; # pdnsd监听的网卡0.0.0.0是全部网卡
server_port=5333; # pdnsd监听的端口不要和别的服务冲突即可
status_ctl = on; status_ctl = on;
paranoid=on; # 二次请求模式如果请求主DNS服务器返回的是垃圾地址就向备用服务器请求 paranoid=on; # 二次请求模式如果请求主DNS服务器返回的是垃圾地址就向备用服务器请求
query_method=udp_only; query_method=udp_only;
neg_domain_pol = off; neg_domain_pol = off;
par_queries = 400; # 最多同时请求数 par_queries = 400; # 最多同时请求数
min_ttl = 1h; # DNS结果最短缓存时间 min_ttl = 1h; # DNS结果最短缓存时间
max_ttl = 1w; # DNS结果最长缓存时间 max_ttl = 1w; # DNS结果最长缓存时间
timeout = 10; # DNS请求超时时间单位秒 timeout = 10; # DNS请求超时时间单位秒
} }
server { server {
label = "routine"; label = "routine";
ip = $DNS_SERVER; # 这里为主要上级 dns 的 ip 地址建议填写一个当地最快的DNS地址 ip = $DNS_SERVER; # 这里为主要上级 dns 的 ip 地址建议填写一个当地最快的DNS地址
timeout = 5; # DNS请求超时时间 timeout = 5; # DNS请求超时时间
reject = 74.125.127.102, # 以下是脏IP也就是DNS污染一般会返回的结果如果收到如下DNS结果会触发二次请求TCP协议一般不会碰到脏IP reject = 74.125.127.102, # 以下是脏IP也就是DNS污染一般会返回的结果如果收到如下DNS结果会触发二次请求TCP协议一般不会碰到脏IP
74.125.155.102, 74.125.155.102,
74.125.39.102, 74.125.39.102,
74.125.39.113, 74.125.39.113,
@ -101,33 +102,33 @@ server {
249.129.46.48, 249.129.46.48,
253.157.14.165; 253.157.14.165;
reject_policy = fail; reject_policy = fail;
} }
server { server {
label = "special"; # 这个随便写 label = "special"; # 这个随便写
ip = 208.67.222.222,208.67.220.220; # 这里为备用DNS服务器的 ip 地址 ip = 208.67.222.222,208.67.220.220; # 这里为备用DNS服务器的 ip 地址
port = 5353; # 推荐使用53以外的端口DNS服务器必须支持 port = 5353; # 推荐使用53以外的端口DNS服务器必须支持
proxy_only = on; proxy_only = on;
timeout = 5; timeout = 5;
} }
source { source {
owner=localhost; owner=localhost;
// serve_aliases=on; // serve_aliases=on;
file="/etc/hosts"; file="/etc/hosts";
} }
rr { rr {
name=localhost; name=localhost;
reverse=on; reverse=on;
a=127.0.0.1; a=127.0.0.1;
owner=localhost; owner=localhost;
soa=localhost,root.localhost,42,86400,900,86400,86400; soa=localhost,root.localhost,42,86400,900,86400,86400;
} }
EOF EOF
[ -d /var/sbin ] || mkdir -p /var/sbin [ -d /var/sbin ] || mkdir -p /var/sbin
[ -f /var/sbin/dnscache ] || cp -a /usr/sbin/pdnsd /var/sbin/dnscache [ -f /var/sbin/dnscache ] || ln -s /usr/sbin/pdnsd /var/sbin/dnscache
echo "Start DNS Cache" echo "Start DNS Cache"
} }
@ -151,7 +152,7 @@ revert_dns() {
uci commit dhcp uci commit dhcp
} }
start_service(){ start_service() {
dns=$(uci get flowoffload.@flow[0].dns 2>/dev/null) dns=$(uci get flowoffload.@flow[0].dns 2>/dev/null)
bbr=$(uci get flowoffload.@flow[0].bbr 2>/dev/null) bbr=$(uci get flowoffload.@flow[0].bbr 2>/dev/null)
if [ $dns -eq 1 ]; then if [ $dns -eq 1 ]; then
@ -162,6 +163,8 @@ start_service(){
procd_set_param stderr 1 procd_set_param stderr 1
procd_close_instance procd_close_instance
change_dns change_dns
else
revert_dns
fi fi
if [ $bbr -eq 1 ]; then if [ $bbr -eq 1 ]; then
sysctl -w net.ipv4.tcp_congestion_control=bbr sysctl -w net.ipv4.tcp_congestion_control=bbr
@ -177,7 +180,7 @@ start_service(){
fi fi
} }
stop_service(){ stop_service() {
dns=$(uci get firewall.@defaults[0].dns 2>/dev/null) dns=$(uci get firewall.@defaults[0].dns 2>/dev/null)
revert_dns revert_dns
uci set firewall.@defaults[0].flow_offloading=$(uci get flowoffload.@flow[0].flow_offloading) uci set firewall.@defaults[0].flow_offloading=$(uci get flowoffload.@flow[0].flow_offloading)
@ -189,11 +192,10 @@ stop_service(){
fi fi
} }
restart(){ restart() {
DNSMASQ_RESTART=Y DNSMASQ_RESTART=Y
stop stop
start start
/etc/init.d/dnsmasq restart && echo "DNSMASQ restart" /etc/init.d/dnsmasq restart && echo "DNSMASQ restart"
/etc/init.d/firewall restart >/dev/null 2>&1 /etc/init.d/firewall restart >/dev/null 2>&1
} }

View File

@ -16,15 +16,16 @@ pdnsd_genconfig() {
if [ ! -f /var/dnscache/pdnsd.cache ]; then if [ ! -f /var/dnscache/pdnsd.cache ]; then
mkdir -p /var/dnscache mkdir -p /var/dnscache
echo -ne "pd13\000\000\000\000" > /var/dnscache/pdnsd.cache echo -ne "pd13\000\000\000\000" >/var/dnscache/pdnsd.cache
chown -R nobody.nogroup /var/dnscache chown -R nobody.nogroup /var/dnscache
fi fi
cat > /var/etc/dnscache.conf <<EOF cat <<-EOF >/var/etc/dnscache.conf
global { global {
perm_cache=1024; # dns缓存大小单位KB建议不要写的太大 perm_cache=1024; # dns缓存大小单位KB建议不要写的太大
cache_dir="/var/dnscache"; # 缓存文件的位置 cache_dir="/var/dnscache"; # 缓存文件的位置
pid_file = /var/run/dnscache.pid; pid_file="/var/run/dnscache.pid";
run_as="nobody";
server_ip = 0.0.0.0; # pdnsd监听的网卡0.0.0.0是全部网卡 server_ip = 0.0.0.0; # pdnsd监听的网卡0.0.0.0是全部网卡
server_port=5333; # pdnsd监听的端口不要和别的服务冲突即可 server_port=5333; # pdnsd监听的端口不要和别的服务冲突即可
status_ctl = on; status_ctl = on;
@ -35,9 +36,9 @@ global {
min_ttl = 1h; # DNS结果最短缓存时间 min_ttl = 1h; # DNS结果最短缓存时间
max_ttl = 1w; # DNS结果最长缓存时间 max_ttl = 1w; # DNS结果最长缓存时间
timeout = 10; # DNS请求超时时间单位秒 timeout = 10; # DNS请求超时时间单位秒
} }
server { server {
label = "routine"; label = "routine";
ip = $DNS_SERVER; # 这里为主要上级 dns 的 ip 地址建议填写一个当地最快的DNS地址 ip = $DNS_SERVER; # 这里为主要上级 dns 的 ip 地址建议填写一个当地最快的DNS地址
timeout = 5; # DNS请求超时时间 timeout = 5; # DNS请求超时时间
@ -101,33 +102,33 @@ server {
249.129.46.48, 249.129.46.48,
253.157.14.165; 253.157.14.165;
reject_policy = fail; reject_policy = fail;
} }
server { server {
label = "special"; # 这个随便写 label = "special"; # 这个随便写
ip = 208.67.222.222,208.67.220.220; # 这里为备用DNS服务器的 ip 地址 ip = 208.67.222.222,208.67.220.220; # 这里为备用DNS服务器的 ip 地址
port = 5353; # 推荐使用53以外的端口DNS服务器必须支持 port = 5353; # 推荐使用53以外的端口DNS服务器必须支持
proxy_only = on; proxy_only = on;
timeout = 5; timeout = 5;
} }
source { source {
owner=localhost; owner=localhost;
// serve_aliases=on; // serve_aliases=on;
file="/etc/hosts"; file="/etc/hosts";
} }
rr { rr {
name=localhost; name=localhost;
reverse=on; reverse=on;
a=127.0.0.1; a=127.0.0.1;
owner=localhost; owner=localhost;
soa=localhost,root.localhost,42,86400,900,86400,86400; soa=localhost,root.localhost,42,86400,900,86400,86400;
} }
EOF EOF
[ -d /var/sbin ] || mkdir -p /var/sbin [ -d /var/sbin ] || mkdir -p /var/sbin
[ -f /var/sbin/dnscache ] || cp -a /usr/sbin/pdnsd /var/sbin/dnscache [ -f /var/sbin/dnscache ] || ln -s /usr/sbin/pdnsd /var/sbin/dnscache
} }
change_dns() { change_dns() {
@ -154,10 +155,10 @@ start_service() {
if [ $enable -eq 1 ]; then if [ $enable -eq 1 ]; then
! (lsmod | grep fast_classifier >/dev/null) && (modprobe fast_classifier) ! (lsmod | grep fast_classifier >/dev/null) && (modprobe fast_classifier)
if [ $wifi -eq 1 ] ; then if [ $wifi -eq 1 ]; then
echo 1 > /sys/fast_classifier/skip_to_bridge_ingress echo 1 >/sys/fast_classifier/skip_to_bridge_ingress
else else
echo 0 > /sys/fast_classifier/skip_to_bridge_ingress echo 0 >/sys/fast_classifier/skip_to_bridge_ingress
fi fi
if [ $ipv6 -eq 1 ]; then if [ $ipv6 -eq 1 ]; then
sfe_ipv6=$(cat /sys/sfe_ipv6/debug_dev) sfe_ipv6=$(cat /sys/sfe_ipv6/debug_dev)
@ -177,6 +178,8 @@ start_service() {
procd_set_param stderr 1 procd_set_param stderr 1
procd_close_instance procd_close_instance
change_dns change_dns
else
revert_dns
fi fi
if [ $bbr -eq 1 ]; then if [ $bbr -eq 1 ]; then
@ -189,7 +192,7 @@ start_service() {
fi fi
} }
stop_service(){ stop_service() {
enable=$(uci get sfe.config.enabled 2>/dev/null) enable=$(uci get sfe.config.enabled 2>/dev/null)
[ $enable -ne 1 ] && rmmod fast_classifier >/dev/null 2>&1 [ $enable -ne 1 ] && rmmod fast_classifier >/dev/null 2>&1
revert_dns revert_dns
@ -198,7 +201,7 @@ stop_service(){
fi fi
} }
restart(){ restart() {
DNSMASQ_RESTART=Y DNSMASQ_RESTART=Y
stop stop
start start