mirror of
https://github.com/v2rayA/v2rayA.git
synced 2026-11-20 23:02:25 +03:00
fix(iptables): resolve firewall rule bugs and improve cleanup reliability
- Fix nftTproxy.GetCleanCommands using wrong table name ('ip' instead of
'inet') when IPv6 is disabled, causing nftables table to persist after
teardown
- Fix legacyRedirect.RemoveIPWhitelist not handling IPv6 CIDRs (always
used iptables even for IPv6 addresses, causing silent delete failure)
- Suppress errors in ip rule/route del cleanup commands with
2>/dev/null || true (applies to both legacy and nft TProxy modes)
- Normalize mixed tab/space indentation in nftRedirect's tp_rule chain
for consistency
This commit is contained in:
1 parent
45fabfce39
commit
1bcd63eb1f
2 files changed
+18
-17
No files matched your search
@@ -44,6 +44,10 @@ func (r *legacyRedirect) AddIPWhitelist(cidr string) {
|
||||
func (r *legacyRedirect) RemoveIPWhitelist(cidr string) {
|
||||
var commands string
|
||||
commands = fmt.Sprintf(`iptables -w 2 -t nat -D TP_RULE -d %s -j RETURN`, cidr)
|
||||
if !strings.Contains(cidr, ".") {
|
||||
//ipv6
|
||||
commands = strings.Replace(commands, "iptables", "ip6tables", 1)
|
||||
}
|
||||
cmds.ExecCommands(commands, false)
|
||||
}
|
||||
|
||||
@@ -284,12 +288,12 @@ table inet v2raya {
|
||||
meta l4proto { tcp, udp } th dport 53 redirect to :52353
|
||||
}
|
||||
|
||||
chain tp_rule {
|
||||
ip daddr @whitelist return
|
||||
ip daddr @local_ips return
|
||||
ip6 daddr @whitelist6 return
|
||||
ip6 daddr @local_ips6 return
|
||||
meta mark & 0x80 == 0x80 return
|
||||
chain tp_rule {
|
||||
ip daddr @whitelist return
|
||||
ip daddr @local_ips return
|
||||
ip6 daddr @whitelist6 return
|
||||
ip6 daddr @local_ips6 return
|
||||
meta mark & 0x80 == 0x80 return
|
||||
`
|
||||
for _, v := range GetExcludedInterfaces() {
|
||||
table += fmt.Sprintf(" iifname \"%s\" return\n", v)
|
||||
|
||||
@@ -201,8 +201,8 @@ ip6tables -w 2 -t mangle -A DNS_MARK -j ACCEPT
|
||||
|
||||
func (t *legacyTproxy) GetCleanCommands() Setter {
|
||||
commands := `
|
||||
ip rule del fwmark 0x40/0xc0 table 100
|
||||
ip route del local 0.0.0.0/0 dev lo table 100
|
||||
ip rule del fwmark 0x40/0xc0 table 100 2>/dev/null || true
|
||||
ip route del local 0.0.0.0/0 dev lo table 100 2>/dev/null || true
|
||||
|
||||
iptables -w 2 -t mangle -F TP_OUT
|
||||
iptables -w 2 -t mangle -D OUTPUT -j TP_OUT
|
||||
@@ -223,8 +223,8 @@ iptables -w 2 -t mangle -X DNS_MARK
|
||||
`
|
||||
if IsIPv6Supported() {
|
||||
commands += `
|
||||
ip -6 rule del fwmark 0x40/0xc0 table 100
|
||||
ip -6 route del local ::/0 dev lo table 100
|
||||
ip -6 rule del fwmark 0x40/0xc0 table 100 2>/dev/null || true
|
||||
ip -6 route del local ::/0 dev lo table 100 2>/dev/null || true
|
||||
|
||||
ip6tables -w 2 -t mangle -F TP_OUT
|
||||
ip6tables -w 2 -t mangle -D OUTPUT -j TP_OUT
|
||||
@@ -412,20 +412,17 @@ ip -6 route add local ::/0 dev lo table 100
|
||||
|
||||
func (t *nftTproxy) GetCleanCommands() Setter {
|
||||
command := `
|
||||
ip rule del fwmark 0x40/0xc0 table 100
|
||||
ip route del local 0.0.0.0/0 dev lo table 100
|
||||
ip rule del fwmark 0x40/0xc0 table 100 2>/dev/null || true
|
||||
ip route del local 0.0.0.0/0 dev lo table 100 2>/dev/null || true
|
||||
`
|
||||
if IsIPv6Supported() {
|
||||
command += `
|
||||
ip -6 rule del fwmark 0x40/0xc0 table 100
|
||||
ip -6 route del local ::/0 dev lo table 100
|
||||
ip -6 rule del fwmark 0x40/0xc0 table 100 2>/dev/null || true
|
||||
ip -6 route del local ::/0 dev lo table 100 2>/dev/null || true
|
||||
`
|
||||
}
|
||||
|
||||
command += `nft delete table inet v2raya`
|
||||
if !IsIPv6Supported() {
|
||||
command = strings.Replace(command, "inet", "ip", 1)
|
||||
}
|
||||
command += "\nconntrack -D --mark 0x40 2>/dev/null || true"
|
||||
return Setter{Cmds: command}
|
||||
}
|
||||
Reference in new issue
Block a user