This commit is contained in:
2026-01-26 12:28:08 +08:00
parent 7602aae2a0
commit 2891ac911e
2 changed files with 54 additions and 16 deletions

View File

@@ -1,7 +1,7 @@
# 公网处理 => inet4/6
protocol pipe unet4_inet4_sync {
table unet4;
peer table master4;
peer table inet4;
export filter {
if bgp_large_community ~ [(UNET_ASN, 3,*)] then reject;
if is_bogon_prefix() then reject;

View File

@@ -1,6 +1,5 @@
#!/sbin/openrc-run
description="Custom IP Policy Route Rules for Alpine"
description="Custom IP Policy Route for Alpine"
depend() {
need net networking
@@ -11,7 +10,7 @@ depend() {
trigger() {
case "$1" in
restart)
ebegin "Triggered by networking restart, reloading IP policy rules"
ebegin "Triggered by network restart, reloading IP policy rules"
restart
eend $?
;;
@@ -22,21 +21,52 @@ trigger() {
esac
}
#空格来分隔不同的前缀
ALL_TUNNEL_SUBNETS="44.32.191.0/24"
BASE_PRIORITY=200
LAN_SUBNET_V4="172.20.0.0/14"
LAN_SUBNET_V6_FD="fd00::/8"
TUNNEL_SUBNET_V6="2000::/3"
add_rules() {
local current_prio=${BASE_PRIORITY}
for subnet in ${ALL_TUNNEL_SUBNETS}; do
ip rule add from ${subnet} lookup 102 priority ${current_prio} 2>/dev/null
ip rule add to ${subnet} lookup 102 priority $((current_prio + 1)) 2>/dev/null
current_prio=$((current_prio + 2))
done
ip rule add from ${LAN_SUBNET_V4} to ${LAN_SUBNET_V4} lookup 105 priority ${current_prio} 2>/dev/null
current_prio=$((current_prio + 10))
ip -6 rule add from ${TUNNEL_SUBNET_V6} to ${TUNNEL_SUBNET_V6} lookup 102 priority ${BASE_PRIORITY} 2>/dev/null
ip -6 rule add from ${LAN_SUBNET_V6_FD} to ${LAN_SUBNET_V6_FD} lookup 105 priority $((BASE_PRIORITY + 10)) 2>/dev/null
}
del_rules() {
local current_prio=${BASE_PRIORITY}
for subnet in ${ALL_TUNNEL_SUBNETS}; do
ip rule del from ${subnet} lookup 102 priority ${current_prio} 2>/dev/null
ip rule del to ${subnet} lookup 102 priority $((current_prio + 1)) 2>/dev/null
current_prio=$((current_prio + 2))
done
ip rule del from ${LAN_SUBNET_V4} to ${LAN_SUBNET_V4} lookup 105 priority ${current_prio} 2>/dev/null
current_prio=$((current_prio + 10))
ip -6 rule del from ${TUNNEL_SUBNET_V6} to ${TUNNEL_SUBNET_V6} lookup 102 priority ${BASE_PRIORITY} 2>/dev/null
ip -6 rule del from ${LAN_SUBNET_V6_FD} to ${LAN_SUBNET_V6_FD} lookup 105 priority $((BASE_PRIORITY + 10)) 2>/dev/null
}
start() {
ebegin "Loading custom IP policy rules"
ip rule add from 44.32.191.0/24 to 0.0.0.0/0 lookup 102 priority 200
ip rule add from 172.20.0.0/14 to 172.20.0.0/14 lookup 105 priority 300
ip -6 rule add from 2000::/3 to 2000::/3 lookup 102 priority 200
ip -6 rule add from fd00::/8 to fd00::/8 lookup 105 priority 300
ebegin "Loading static IP policy rules (tunnel + downstream)"
add_rules
eend $? "Failed to load IP policy rules"
}
stop() {
ebegin "Removing custom IP policy rules"
ip rule del from 44.32.191.0/24 to 0.0.0.0/0 lookup 102 priority 200
ip rule del from 172.20.0.0/14 to 172.20.0.0/14 lookup 105 priority 300
ip -6 rule del from 2000::/3 to 2000::/3 lookup 102 priority 200
ip -6 rule del from fd00::/8 to fd00::/8 lookup 105 priority 300
ebegin "Removing static IP policy rules (tunnel + downstream)"
del_rules
eend $? "Failed to remove IP policy rules"
}
@@ -45,3 +75,11 @@ restart() {
sleep 1
start
}
reload() {
ebegin "Refreshing static IP policy rules"
del_rules
sleep 0.5
add_rules
eend $? "Failed to refresh IP policy rules"
}