Skip to content

Commit

Permalink
auto-redirect: Fix android rules
Browse files Browse the repository at this point in the history
  • Loading branch information
nekohasekai committed Jun 17, 2024
1 parent 9cf07a2 commit ef83d16
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions redirect_iptables.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package tun
import (
"net/netip"
"os/exec"
"runtime"
"strings"

"github.com/sagernet/sing/common"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit ef83d16

Please sign in to comment.