Skip to content

Commit 20a52bb

Browse files
NumbersfFanju6
authored andcommitted
fix(tproxy): 修复路由规则残留导致启动报错
修复设备重启后类似于 [Info]: Setting up routing rules for IPv4 RTNETLINK answers: File exists [Error]: Failed to add IPv4 routing rule 的报错
1 parent aeacc20 commit 20a52bb

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

src/module/scripts/network/tproxy.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1440,11 +1440,12 @@ setup_redirect_chain6() {
14401440
setup_routing4() {
14411441
log Info "Setting up routing rules for IPv4"
14421442

1443+
ip_rule del fwmark "$MARK_VALUE" table "$TABLE_ID" pref "$TABLE_ID" 2>/dev/null
14431444
ip_rule add fwmark "$MARK_VALUE" table "$TABLE_ID" pref "$TABLE_ID" || {
14441445
log Error "Failed to add IPv4 routing rule"
14451446
return 1
14461447
}
1447-
ip_route add local 0.0.0.0/0 dev lo table "$TABLE_ID" || {
1448+
ip_route replace local 0.0.0.0/0 dev lo table "$TABLE_ID" || {
14481449
log Error "Failed to add IPv4 route"
14491450
return 1
14501451
}
@@ -1458,11 +1459,12 @@ setup_routing4() {
14581459
setup_routing6() {
14591460
log Info "Setting up routing rules for IPv6"
14601461

1462+
ip6_rule del fwmark "$MARK_VALUE6" table "$TABLE_ID" pref "$TABLE_ID" 2>/dev/null
14611463
ip6_rule add fwmark "$MARK_VALUE6" table "$TABLE_ID" pref "$TABLE_ID" || {
14621464
log Error "Failed to add IPv6 routing rule"
14631465
return 1
14641466
}
1465-
ip6_route add local ::/0 dev lo table "$TABLE_ID" || {
1467+
ip6_route replace local ::/0 dev lo table "$TABLE_ID" || {
14661468
log Error "Failed to add IPv6 route"
14671469
return 1
14681470
}

0 commit comments

Comments
 (0)