mirror of
https://github.com/kiddin9/op-packages.git
synced 2026-11-01 14:23:56 +08:00
⛄ Sync 2026-07-31 00:26:24
This commit is contained in:
1 parent
0cc8d3b78f
commit
de732529ed
125 files changed
+3954
-140418
No files matched your search
@@ -27,6 +27,24 @@ log() {
|
||||
echo -e "$(date "+%Y-%m-%d %H:%M:%S") [DAEMON] $*" >> "$LOG_PATH"
|
||||
}
|
||||
|
||||
delete_ip_rules() {
|
||||
local mark="$1"
|
||||
local table="$2"
|
||||
|
||||
while ip rule del fwmark "$mark" table "$table" 2>"/dev/null"; do
|
||||
:
|
||||
done
|
||||
}
|
||||
|
||||
delete_ip6_rules() {
|
||||
local mark="$1"
|
||||
local table="$2"
|
||||
|
||||
while ip -6 rule del fwmark "$mark" table "$table" 2>"/dev/null"; do
|
||||
:
|
||||
done
|
||||
}
|
||||
|
||||
start_service() {
|
||||
config_load "$CONF"
|
||||
|
||||
@@ -34,12 +52,10 @@ start_service() {
|
||||
config_get routing_mode "config" "routing_mode" "bypass_mainland_china"
|
||||
config_get proxy_mode "config" "proxy_mode" "redirect_tproxy"
|
||||
|
||||
local outbound_node
|
||||
if [ "$routing_mode" != "custom" ]; then
|
||||
config_get outbound_node "config" "main_node" "nil"
|
||||
else
|
||||
config_get outbound_node "routing" "default_outbound" "nil"
|
||||
fi
|
||||
local outbound_node default_outbound
|
||||
config_get outbound_node "config" "main_node" "nil"
|
||||
config_get default_outbound "routing" "default_outbound" "nil"
|
||||
[ "$outbound_node" != "nil" ] || outbound_node="$default_outbound"
|
||||
|
||||
local server_enabled
|
||||
config_get_bool server_enabled "server" "enabled" "0"
|
||||
@@ -111,18 +127,24 @@ start_service() {
|
||||
config_get table_mark "infra" "table_mark" "100"
|
||||
case "$proxy_mode" in
|
||||
"redirect_tproxy")
|
||||
local outbound_udp_node
|
||||
local outbound_udp_node main_node_for_routing default_outbound_for_routing use_default_outbound_routing
|
||||
config_get outbound_udp_node "config" "main_udp_node" "nil"
|
||||
if [ "$outbound_udp_node" != "nil" ] || [ "$routing_mode" = "custom" ]; then
|
||||
config_get main_node_for_routing "config" "main_node" "nil"
|
||||
config_get default_outbound_for_routing "routing" "default_outbound" "nil"
|
||||
[ "$routing_mode" != "custom" ] && [ "$main_node_for_routing" = "nil" ] && [ "$default_outbound_for_routing" != "nil" ] \
|
||||
&& use_default_outbound_routing="1" || use_default_outbound_routing="0"
|
||||
if [ "$outbound_udp_node" != "nil" ] || [ "$routing_mode" = "custom" ] || [ "$use_default_outbound_routing" = "1" ]; then
|
||||
local tproxy_mark
|
||||
config_get tproxy_mark "infra" "tproxy_mark" "101"
|
||||
|
||||
delete_ip_rules "$tproxy_mark" "$table_mark"
|
||||
ip rule add fwmark "$tproxy_mark" table "$table_mark"
|
||||
ip route add local 0.0.0.0/0 dev lo table "$table_mark"
|
||||
ip route replace local 0.0.0.0/0 dev lo table "$table_mark"
|
||||
|
||||
if [ "$ipv6_support" -eq "1" ]; then
|
||||
delete_ip6_rules "$tproxy_mark" "$table_mark"
|
||||
ip -6 rule add fwmark "$tproxy_mark" table "$table_mark"
|
||||
ip -6 route add local ::/0 dev lo table "$table_mark"
|
||||
ip -6 route replace local ::/0 dev lo table "$table_mark"
|
||||
fi
|
||||
fi
|
||||
;;
|
||||
@@ -131,14 +153,16 @@ start_service() {
|
||||
config_get tun_name "infra" "tun_name" "singtun0"
|
||||
config_get tun_mark "infra" "tun_mark" "102"
|
||||
|
||||
ip tuntap add mode tun user root name "$tun_name"
|
||||
ip link show "$tun_name" >"/dev/null" 2>&1 || ip tuntap add mode tun user root name "$tun_name"
|
||||
sleep 1s
|
||||
ip link set "$tun_name" up
|
||||
|
||||
ip route replace default dev "$tun_name" table "$table_mark"
|
||||
delete_ip_rules "$tun_mark" "$table_mark"
|
||||
ip rule add fwmark "$tun_mark" lookup "$table_mark"
|
||||
|
||||
ip -6 route replace default dev "$tun_name" table "$table_mark"
|
||||
delete_ip6_rules "$tun_mark" "$table_mark"
|
||||
ip -6 rule add fwmark "$tun_mark" lookup "$table_mark"
|
||||
;;
|
||||
esac
|
||||
@@ -173,6 +197,17 @@ start_service() {
|
||||
procd_set_param respawn
|
||||
|
||||
procd_close_instance
|
||||
|
||||
# Clash API display proxy for dashboards.
|
||||
local clash_api_enabled
|
||||
config_get_bool clash_api_enabled "config" "clash_api_enabled" "0"
|
||||
if [ "$clash_api_enabled" = "1" ]; then
|
||||
procd_open_instance "clash-api-proxy"
|
||||
procd_set_param command "/usr/bin/ucode" "$HP_DIR/scripts/clash_api_proxy.uc"
|
||||
procd_set_param stderr 1
|
||||
procd_set_param respawn
|
||||
procd_close_instance
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ "$server_enabled" = "1" ]; then
|
||||
@@ -267,17 +302,17 @@ stop_service() {
|
||||
config_get tun_name "infra" "tun_name" "singtun0"
|
||||
|
||||
# Tproxy
|
||||
ip rule del fwmark "$tproxy_mark" table "$table_mark" 2>"/dev/null"
|
||||
delete_ip_rules "$tproxy_mark" "$table_mark"
|
||||
ip route del local 0.0.0.0/0 dev lo table "$table_mark" 2>"/dev/null"
|
||||
ip -6 rule del fwmark "$tproxy_mark" table "$table_mark" 2>"/dev/null"
|
||||
delete_ip6_rules "$tproxy_mark" "$table_mark"
|
||||
ip -6 route del local ::/0 dev lo table "$table_mark" 2>"/dev/null"
|
||||
|
||||
# TUN
|
||||
ip route del default dev "$tun_name" table "$table_mark" 2>"/dev/null"
|
||||
ip rule del fwmark "$tun_mark" table "$table_mark" 2>"/dev/null"
|
||||
delete_ip_rules "$tun_mark" "$table_mark"
|
||||
|
||||
ip -6 route del default dev "$tun_name" table "$table_mark" 2>"/dev/null"
|
||||
ip -6 rule del fwmark "$tun_mark" table "$table_mark" 2>"/dev/null"
|
||||
delete_ip6_rules "$tun_mark" "$table_mark"
|
||||
|
||||
# Nftables rules
|
||||
for i in "homeproxy_dstnat_redir" "homeproxy_output_redir" \
|
||||
|
||||
Reference in new issue
Block a user