From ef83d1643c520cf0929dbccf3a83baadc5de34c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=96=E7=95=8C?= Date: Mon, 17 Jun 2024 22:49:09 +0800 Subject: [PATCH] auto-redirect: Fix android rules --- redirect_iptables.go | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/redirect_iptables.go b/redirect_iptables.go index 81aa839..f7df428 100644 --- a/redirect_iptables.go +++ b/redirect_iptables.go @@ -5,6 +5,7 @@ package tun import ( "net/netip" "os/exec" + "runtime" "strings" "github.com/sagernet/sing/common" @@ -49,7 +50,7 @@ func (r *autoRedirect) setupIPTablesForFamily(iptablesPath string) error { if err != nil { return err } - if r.androidSu { + if runtime.GOOS == "android" { return nil } // INPUT @@ -240,14 +241,15 @@ func (r *autoRedirect) cleanupIPTablesForFamily(iptablesPath string) { _ = r.runShell(iptablesPath, "-t nat -D OUTPUT -j", tableNameOutput) _ = r.runShell(iptablesPath, "-t nat -F", tableNameOutput) _ = r.runShell(iptablesPath, "-t nat -X", tableNameOutput) - if !r.androidSu { - _ = r.runShell(iptablesPath, "-D FORWARD -j", tableNameForward) - _ = r.runShell(iptablesPath, "-F", tableNameForward) - _ = r.runShell(iptablesPath, "-X", tableNameForward) - _ = r.runShell(iptablesPath, "-t nat -D PREROUTING -j", tableNamePreRouteing) - _ = r.runShell(iptablesPath, "-t nat -F", tableNamePreRouteing) - _ = r.runShell(iptablesPath, "-t nat -X", tableNamePreRouteing) + if runtime.GOOS == "android" { + return } + _ = r.runShell(iptablesPath, "-D FORWARD -j", tableNameForward) + _ = r.runShell(iptablesPath, "-F", tableNameForward) + _ = r.runShell(iptablesPath, "-X", tableNameForward) + _ = r.runShell(iptablesPath, "-t nat -D PREROUTING -j", tableNamePreRouteing) + _ = r.runShell(iptablesPath, "-t nat -F", tableNamePreRouteing) + _ = r.runShell(iptablesPath, "-t nat -X", tableNamePreRouteing) } func (r *autoRedirect) runShell(commands ...any) error {