From 1f043289199d5c524ec53b74976383caddd51171 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=96=E7=95=8C?= Date: Thu, 4 Jul 2024 00:07:40 +0800 Subject: [PATCH] auto-redirect: Fix nftables available check --- redirect_linux.go | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/redirect_linux.go b/redirect_linux.go index e5c8f27..63561f6 100644 --- a/redirect_linux.go +++ b/redirect_linux.go @@ -2,12 +2,6 @@ package tun import ( "context" - "net/netip" - "os" - "os/exec" - "runtime" - "time" - "github.com/sagernet/nftables" "github.com/sagernet/sing/common" "github.com/sagernet/sing/common/control" @@ -15,6 +9,10 @@ import ( "github.com/sagernet/sing/common/logger" M "github.com/sagernet/sing/common/metadata" "github.com/sagernet/sing/common/x/list" + "net/netip" + "os" + "os/exec" + "runtime" "go4.org/netipx" ) @@ -81,7 +79,8 @@ func NewAutoRedirect(options AutoRedirectOptions) (AutoRedirect, error) { if r.useNFTables { err = r.initializeNFTables() if err != nil && err != os.ErrInvalid { - r.logger.Debug("device has no nftables support: ", err) + r.useNFTables = false + r.logger.Debug("missing nftables support: ", err) } } if len(r.tunOptions.Inet4Address) > 0 { @@ -131,7 +130,6 @@ func (r *autoRedirect) Start() error { } r.redirectServer = server } - startAt := time.Now() var err error if r.useNFTables { r.cleanupNFTables() @@ -140,11 +138,7 @@ func (r *autoRedirect) Start() error { r.cleanupIPTables() err = r.setupIPTables() } - if err != nil { - return err - } - r.logger.Debug("auto-redirect configured in ", time.Since(startAt)) - return nil + return err } func (r *autoRedirect) Close() error {