@@ -8,7 +8,6 @@ table="2024"
88pref=" 100"
99# 使用 iptables 规则禁用或启用 QUIC。注意,这可能导致部分网站无法访问。
1010quic=" enable"
11- tun_forward=" enable"
1211mihomo_dns_forward=" enable"
1312fake_ip_range=" "
1413
@@ -46,7 +45,6 @@ case "${bin_name}" in
4645 fake_ip6_range=$( busybox awk -F' "' ' /inet6_range/ {print $4}' " ${sing_config} " )
4746 ;;
4847 " hysteria" )
49- # 验证 hysteria 的 network_mode
5048 case " ${network_mode} " in
5149 redirect|tproxy|enhance)
5250 # 支持的模式,无需操作
@@ -192,73 +190,10 @@ probe_tun_device() {
192190 busybox ifconfig | grep -q " ${tun_device} " || return 1
193191}
194192
195- probe_tun_index () {
196- while [ ! -f " /data/misc/net/rt_tables" ]; do
197- sleep 1
198- done
199-
200- while read -r index name; do
201- if [ " ${name} " = " ${tun_device} " ]; then
202- tun_table_index=${index}
203- return 0
204- fi
205- done < /data/misc/net/rt_tables
206-
207- return 1
208- }
209-
210- tun_forward_ip_rules () {
211- local action=$1
212- ipv4_rules=(
213- " iif lo goto 6000 pref 5000"
214- " iif ${tun_device} lookup main suppress_prefixlength 0 pref 5010"
215- " iif ${tun_device} goto 6000 pref 5020"
216- " from 10.0.0.0/8 lookup ${tun_table_index} pref 5030"
217- " from 172.16.0.0/12 lookup ${tun_table_index} pref 5040"
218- " from 192.168.0.0/16 lookup ${tun_table_index} pref 5050"
219- " nop pref 6000"
220- )
221-
222- ipv6_rules=(
223- " iif lo goto 6000 pref 5000"
224- " iif ${tun_device} lookup main suppress_prefixlength 0 pref 5010"
225- " iif ${tun_device} goto 6000 pref 5020"
226- " from fc00::/7 lookup ${tun_table_index} pref 5030" # ULA
227- " from fd00::/8 lookup ${tun_table_index} pref 5040" # ULA 子集
228- " from fe80::/10 lookup ${tun_table_index} pref 5050" # 链路本地
229- # "from 2000::/3 lookup ${tun_table_index} pref 5060"
230- " nop pref 6000"
231- )
232-
233- if [ " ${iptables} " = " $IPV " ]; then
234- for rule in " ${ipv4_rules[@]} " ; do
235- ip -4 rule " ${action} " ${rule}
236- done
237- else
238- for rule in " ${ipv6_rules[@]} " ; do
239- ip -6 rule " ${action} " ${rule}
240- done
241- fi
242- }
243-
244- tun_forward_ip_rules_del () {
245- for pref in 5000 5010 5020 5030 5040 5050 6000; do
246- ip -4 rule del pref $pref > /dev/null 2>&1
247- ip -6 rule del pref $pref > /dev/null 2>&1
248- done
249- }
250-
251- sing_tun_ip_rules () {
252- ip -4 rule $1 from all iif ${tun_device} lookup main suppress_prefixlength 0 pref 8000
253- ip -4 rule $1 lookup main pref 7000
254- ip -6 rule $1 from all iif ${tun_device} lookup main suppress_prefixlength 0 pref 8000
255- ip -6 rule $1 lookup main pref 7000
256- }
257-
258193forward () {
259194 local action=$1
260195
261- ${iptables} -t nat " ${action} " POSTROUTING -o ${tun_device} -j MASQUERADE
196+ # ${iptables} -t nat "${action}" POSTROUTING -o ${tun_device} -j MASQUERADE
262197
263198 ${iptables} " ${action} " FORWARD -i " ${tun_device} " -j ACCEPT
264199 ${iptables} " ${action} " FORWARD -o " ${tun_device} " -j ACCEPT
@@ -267,28 +202,8 @@ forward() {
267202 sysctl -w net.ipv4.conf.default.rp_filter=2
268203 sysctl -w net.ipv4.conf.all.rp_filter=2
269204
270- probe_tun_index
271-
272- if [ " ${tun_forward} " = " enable" ]; then
273- if probe_tun_device; then
274- tun_forward_ip_rules_del
275- tun_forward_ip_rules " ${action} "
276- if [ " ${action} " = " -I" ]; then
277- sing_tun_ip_rules " add"
278- else
279- sing_tun_ip_rules " del"
280- fi
281- return 0
282- else
283- tun_forward_ip_rules_del
284- tun_forward_ip_rules -D
285- sing_tun_ip_rules " del"
286- return 1
287- fi
288- fi
289205} > /dev/null 2>&1
290206
291- # 下面所有日志和注释均已汉化
292207start_redirect () {
293208 if [ " ${iptables} " = " $IPV " ]; then
294209 ${iptables} -t nat -N BOX_EXTERNAL
@@ -329,6 +244,9 @@ start_redirect() {
329244 ${iptables} -t nat -A BOX_EXTERNAL -p tcp -i lo -j REDIRECT --to-ports " ${redir_port} "
330245
331246 if [ " ${ap_list} " != " " ]; then
247+ for ap in " ${ap_list[@]} " ; do
248+ ${iptables} -t nat -A BOX_EXTERNAL -p tcp -i " ${ap} " -j REDIRECT --to-ports " ${redir_port} "
249+ done
332250 [ ${network_mode} = " enhance" ] || log Info " ${ap_list[*]} 透明代理。"
333251 fi
334252
@@ -458,9 +376,9 @@ start_tproxy() {
458376 fi
459377
460378 # 跳过已被 TProxy 处理的流量,若默认路由接口有公网 IP,省略这些规则会导致本地流量代理异常,可能拖慢全网
461- [ ${network_mode} = " enhance" ] || ${iptables} -t mangle -A BOX_EXTERNAL -p tcp -m socket --transparent -j MARK --set-xmark ${fwmark}
462- ${iptables} -t mangle -A BOX_EXTERNAL -p udp -m socket --transparent -j MARK --set-xmark ${fwmark}
463- ${iptables} -t mangle -A BOX_EXTERNAL -m socket -j RETURN
379+ # [ ${network_mode} = "enhance" ] || ${iptables} -t mangle -A BOX_EXTERNAL -p tcp -m socket --transparent -j MARK --set-xmark ${fwmark}
380+ # ${iptables} -t mangle -A BOX_EXTERNAL -p udp -m socket --transparent -j MARK --set-xmark ${fwmark}
381+ # ${iptables} -t mangle -A BOX_EXTERNAL -m socket -j RETURN
464382
465383 # 跳过内网,兼容性可用 su -c 'zcat /proc/config.gz | grep -i addrtype' 检查
466384 # ${iptables} -t mangle -A BOX_EXTERNAL -m addrtype --dst-type LOCAL -j RETURN
@@ -496,10 +414,6 @@ start_tproxy() {
496414 ${iptables} -t mangle -N BOX_LOCAL
497415 ${iptables} -t mangle -F BOX_LOCAL
498416
499- if [ " ${iptables} " = " $IP6V " ]; then
500- ${iptables} -t mangle -A BOX_LOCAL -o lo -j RETURN
501- ${iptables} -t mangle -A BOX_LOCAL -d ::1/128 -j RETURN
502- fi
503417 ${iptables} -t mangle -A BOX_LOCAL -m owner --uid-owner ${box_user} --gid-owner ${box_group} -j RETURN
504418 # ${iptables} -t mangle -A BOX_LOCAL -m mark --mark ${routing_mark} -j RETURN
505419
@@ -587,11 +501,11 @@ start_tproxy() {
587501
588502 ${iptables} -t mangle -I OUTPUT -j BOX_LOCAL
589503
590- # ${iptables} -t mangle -N DIVERT
591- # ${iptables} -t mangle -F DIVERT
592- # ${iptables} -t mangle -A DIVERT -j MARK --set-xmark "${fwmark}"
593- # ${iptables} -t mangle -A DIVERT -j ACCEPT
594- # [ ${network_mode} = "enhance" ] || ${iptables} -t mangle -I PREROUTING -p tcp -m socket -j DIVERT
504+ ${iptables} -t mangle -N DIVERT
505+ ${iptables} -t mangle -F DIVERT
506+ ${iptables} -t mangle -A DIVERT -j MARK --set-xmark " ${fwmark} "
507+ ${iptables} -t mangle -A DIVERT -j ACCEPT
508+ [ ${network_mode} = " enhance" ] || ${iptables} -t mangle -I PREROUTING -p tcp -m socket -j DIVERT
595509
596510 # 禁用 QUIC
597511 if [ " ${quic} " = " disable" ]; then
941855 disable_ipv6
942856 log Warning " 已禁用 IPv6。"
943857 fi
944- [ " ${tun_forward} " = " enable" ] && log Info " TUN 热点支持已启用。" || log Warning " TUN 热点支持已禁用。"
945858 [ $1 = " renew" ] && log Info " 重启 iptables TUN 规则完成。"
946859 bin_alive && log Info " ${bin_name} 已连接。"
947860 ;;
0 commit comments