Skip to content

Commit

Permalink
auto-redirect: Fix nftables available check
Browse files Browse the repository at this point in the history
  • Loading branch information
nekohasekai committed Jul 3, 2024
1 parent 60a8276 commit 4de9674
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions redirect_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,17 @@ 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"
E "github.com/sagernet/sing/common/exceptions"
"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"
)
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -131,7 +130,6 @@ func (r *autoRedirect) Start() error {
}
r.redirectServer = server
}
startAt := time.Now()
var err error
if r.useNFTables {
r.cleanupNFTables()
Expand All @@ -143,7 +141,6 @@ func (r *autoRedirect) Start() error {
if err != nil {
return err
}
r.logger.Debug("auto-redirect configured in ", time.Since(startAt))
return nil
}

Expand Down

0 comments on commit 4de9674

Please sign in to comment.