diff --git a/go.mod b/go.mod index 6030dd1e..3361adf9 100644 --- a/go.mod +++ b/go.mod @@ -24,7 +24,7 @@ require ( github.com/metacubex/sing-quic v0.0.0-20240518034124-7696d3f7da72 github.com/metacubex/sing-shadowsocks v0.2.6 github.com/metacubex/sing-shadowsocks2 v0.2.0 - github.com/metacubex/sing-tun v0.2.7-0.20240617013029-d05cf9df9cfe + github.com/metacubex/sing-tun v0.2.7-0.20240619023810-d442c40abab0 github.com/metacubex/sing-vmess v0.1.9-0.20231207122118-72303677451f github.com/metacubex/sing-wireguard v0.0.0-20240618022557-a6efaa37127a github.com/metacubex/tfo-go v0.0.0-20240228025757-be1269474a66 diff --git a/go.sum b/go.sum index 7f2f105f..95e0404f 100644 --- a/go.sum +++ b/go.sum @@ -116,8 +116,8 @@ github.com/metacubex/sing-shadowsocks v0.2.6 h1:6oEB3QcsFYnNiFeoevcXrCwJ3sAablwV github.com/metacubex/sing-shadowsocks v0.2.6/go.mod h1:zIkMeSnb8Mbf4hdqhw0pjzkn1d99YJ3JQm/VBg5WMTg= github.com/metacubex/sing-shadowsocks2 v0.2.0 h1:hqwT/AfI5d5UdPefIzR6onGHJfDXs5zgOM5QSgaM/9A= github.com/metacubex/sing-shadowsocks2 v0.2.0/go.mod h1:LCKF6j1P94zN8ZS+LXRK1gmYTVGB3squivBSXAFnOg8= -github.com/metacubex/sing-tun v0.2.7-0.20240617013029-d05cf9df9cfe h1:NrWjVEkRmEkdREVSpohMgEBoznS0PrRfJDr6iCV4348= -github.com/metacubex/sing-tun v0.2.7-0.20240617013029-d05cf9df9cfe/go.mod h1:WwJGbCx7bQcBzuQXiDOJvZH27R0kIjKNNlISIWsL6kM= +github.com/metacubex/sing-tun v0.2.7-0.20240619023810-d442c40abab0 h1:J7YWMrEaYM9WF4qG8ZaCCHGw/ylbZc8FvIHr4rdOzP8= +github.com/metacubex/sing-tun v0.2.7-0.20240619023810-d442c40abab0/go.mod h1:WwJGbCx7bQcBzuQXiDOJvZH27R0kIjKNNlISIWsL6kM= github.com/metacubex/sing-vmess v0.1.9-0.20231207122118-72303677451f h1:QjXrHKbTMBip/C+R79bvbfr42xH1gZl3uFb0RELdZiQ= github.com/metacubex/sing-vmess v0.1.9-0.20231207122118-72303677451f/go.mod h1:olVkD4FChQ5gKMHG4ZzuD7+fMkJY1G8vwOKpRehjrmY= github.com/metacubex/sing-wireguard v0.0.0-20240618022557-a6efaa37127a h1:NpSGclHJUYndUwBmyIpFBSoBVg8PoVX7QQKhYg0DjM0= diff --git a/listener/sing_tun/redirect_linux.go b/listener/sing_tun/redirect_linux.go new file mode 100644 index 00000000..6ef6fc96 --- /dev/null +++ b/listener/sing_tun/redirect_linux.go @@ -0,0 +1,3 @@ +package sing_tun + +const supportRedirect = true diff --git a/listener/sing_tun/redirect_stub.go b/listener/sing_tun/redirect_stub.go new file mode 100644 index 00000000..d711af3c --- /dev/null +++ b/listener/sing_tun/redirect_stub.go @@ -0,0 +1,5 @@ +//go:build !linux + +package sing_tun + +const supportRedirect = false diff --git a/listener/sing_tun/server.go b/listener/sing_tun/server.go index 53b88528..e8c2ad28 100644 --- a/listener/sing_tun/server.go +++ b/listener/sing_tun/server.go @@ -132,7 +132,7 @@ func New(options LC.Tun, tunnel C.Tunnel, additions ...inbound.Addition) (l *Lis if options.GSOMaxSize == 0 { options.GSOMaxSize = 65536 } - if runtime.GOOS != "linux" { + if !supportRedirect { options.AutoRedirect = false } tunName := options.Device @@ -453,12 +453,16 @@ func (l *Listener) ruleUpdateCallback(ruleProvider provider.RuleProvider) { } } +type toIpCidr interface { + ToIpCidr() *netipx.IPSet +} + func (l *Listener) updateRule(ruleProvider provider.RuleProvider, exclude bool, update bool) { l.ruleUpdateMutex.Lock() defer l.ruleUpdateMutex.Unlock() name := ruleProvider.Name() switch rp := ruleProvider.Strategy().(type) { - case interface{ ToIpCidr() *netipx.IPSet }: + case toIpCidr: if !exclude { ipCidr := rp.ToIpCidr() if ipCidr != nil {