Skip to content

Commit 3e4f77c

Browse files
committed
chore(scripts): remove tun_forward support
Hotspot issue in sing-tun might have already been fixed: https://github.com/SagerNet/sing-tun
1 parent bafca21 commit 3e4f77c

File tree

1 file changed

+1
-94
lines changed

1 file changed

+1
-94
lines changed

box/scripts/box.iptables

Lines changed: 1 addition & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ table="2024"
1313
pref="100"
1414
# disable or enable QUIC using iptables rules. Note that this may cause some websites to become inaccessible.
1515
quic="enable"
16-
tun_forward="enable"
1716
clash_dns_forward="enable"
1817
fake_ip_range=""
1918

@@ -137,13 +136,6 @@ find_packages_uid() {
137136
done
138137
}
139138

140-
# find_packages_uid() {
141-
# echo -n "" > "${uid_list}"
142-
# for package in "${packages_list[@]}"; do
143-
# busybox awk -v p="${package}" '$1~p{print $2}' "${system_packages_file}" >> "${uid_list}"
144-
# done
145-
# }
146-
147139
probe_user_group() {
148140
if PID=$(busybox pidof ${bin_name}) ; then
149141
box_user=$(stat -c %U /proc/$PID)
@@ -229,100 +221,17 @@ probe_tun_device() {
229221
busybox ifconfig | grep -q "${tun_device}" || return 1
230222
}
231223

232-
probe_tun_index() {
233-
while [ ! -f "/data/misc/net/rt_tables" ]; do
234-
sleep 1
235-
done
236-
237-
while read -r index name; do
238-
if [ "${name}" = "${tun_device}" ]; then
239-
tun_table_index=${index}
240-
return 0
241-
fi
242-
done < /data/misc/net/rt_tables
243-
244-
return 1
245-
}
246-
247-
tun_forward_ip_rules() {
248-
local action=$1
249-
ipv4_rules=(
250-
"iif lo goto 6000 pref 5000"
251-
"iif ${tun_device} lookup main suppress_prefixlength 0 pref 5010"
252-
"iif ${tun_device} goto 6000 pref 5020"
253-
"from 10.0.0.0/8 lookup ${tun_table_index} pref 5030"
254-
"from 172.16.0.0/12 lookup ${tun_table_index} pref 5040"
255-
"from 192.168.0.0/16 lookup ${tun_table_index} pref 5050"
256-
"nop pref 6000"
257-
)
258-
259-
ipv6_rules=(
260-
"iif lo goto 6000 pref 5000"
261-
"iif ${tun_device} lookup main suppress_prefixlength 0 pref 5010"
262-
"iif ${tun_device} goto 6000 pref 5020"
263-
"from fc00::/7 lookup ${tun_table_index} pref 5030" # ULA
264-
"from fd00::/8 lookup ${tun_table_index} pref 5040" # Subset of ULA
265-
"from fe80::/10 lookup ${tun_table_index} pref 5050" # Link-local
266-
# "from 2000::/3 lookup ${tun_table_index} pref 5060"
267-
"nop pref 6000"
268-
)
269-
270-
if [ "${iptables}" = "$IPV" ]; then
271-
for rule in "${ipv4_rules[@]}"; do
272-
ip -4 rule "${action}" ${rule}
273-
done
274-
else
275-
for rule in "${ipv6_rules[@]}"; do
276-
ip -6 rule "${action}" ${rule}
277-
done
278-
fi
279-
}
280-
281-
tun_forward_ip_rules_del() {
282-
for pref in 5000 5010 5020 5030 5040 5050 6000; do
283-
ip -4 rule del pref $pref >/dev/null 2>&1
284-
ip -6 rule del pref $pref >/dev/null 2>&1
285-
done
286-
}
287-
288-
sing_tun_ip_rules() {
289-
ip -4 rule $1 from all iif ${tun_device} lookup main suppress_prefixlength 0 pref 8000
290-
ip -4 rule $1 lookup main pref 7000
291-
ip -6 rule $1 from all iif ${tun_device} lookup main suppress_prefixlength 0 pref 8000
292-
ip -6 rule $1 lookup main pref 7000
293-
}
294-
295224
forward() {
296225
local action=$1
297226

298-
${iptables} -t nat "${action}" POSTROUTING -o ${tun_device} -j MASQUERADE
299-
227+
# ${iptables} -t nat ${action} POSTROUTING -o ${tun_device} -j MASQUERADE
300228
${iptables} "${action}" FORWARD -i "${tun_device}" -j ACCEPT
301229
${iptables} "${action}" FORWARD -o "${tun_device}" -j ACCEPT
302230

303231
sysctl -w net.ipv4.ip_forward=1
304232
sysctl -w net.ipv4.conf.default.rp_filter=2
305233
sysctl -w net.ipv4.conf.all.rp_filter=2
306234

307-
probe_tun_index
308-
309-
if [ "${tun_forward}" = "enable" ]; then
310-
if probe_tun_device; then
311-
tun_forward_ip_rules_del
312-
tun_forward_ip_rules "${action}"
313-
if [ "${action}" = "-I" ]; then
314-
sing_tun_ip_rules "add"
315-
else
316-
sing_tun_ip_rules "del"
317-
fi
318-
return 0
319-
else
320-
tun_forward_ip_rules_del
321-
tun_forward_ip_rules -D
322-
sing_tun_ip_rules "del"
323-
return 1
324-
fi
325-
fi
326235
} >/dev/null 2>&1
327236

328237
start_redirect() {
@@ -827,7 +736,6 @@ if [[ "${network_mode}" == @(redirect|mixed|tproxy|enhance) ]]; then
827736
iptables="$IPV"
828737
probe_tun_device || log Error "tun device: (${tun_device}) not found"
829738
forward -I || forward -D >/dev/null 2>&1
830-
[ "${tun_forward}" = "enable" ] && log Info "tun hotspot support is enabled." || log Warning "tun hotspot support is disabled."
831739

832740
if start_redirect; then
833741
log Info "Creating iptables transparent proxy rules done."
@@ -951,7 +859,6 @@ else
951859
disable_ipv6
952860
log Warning "Disable IPv6."
953861
fi
954-
[ "${tun_forward}" = "enable" ] && log Info "tun hotspot support is enabled." || log Warning "tun hotspot support is disabled."
955862
[ $1 = "renew" ] && log Info "Restart iptables tun rules done."
956863
bin_alive && log Info "${bin_name} connected."
957864
;;

0 commit comments

Comments
 (0)