Forráskód Böngészése

Add tun support for macOS

世界 3 éve
szülő
commit
dfa10d4ebe

+ 1 - 1
common/dialer/default.go

@@ -18,7 +18,7 @@ import (
 
 var warnBindInterfaceOnUnsupportedPlatform = warning.New(
 	func() bool {
-		return !(C.IsLinux || C.IsWindows)
+		return !(C.IsLinux || C.IsWindows || C.IsDarwin)
 	},
 	"outbound option `bind_interface` is only supported on Linux and Windows",
 )

+ 2 - 2
docs/configuration/inbound/tun.md

@@ -1,6 +1,6 @@
 !!! error ""
 
-    Linux and Windows only
+    Only supported on Linux, Windows and macOS.
 
 ### Structure
 
@@ -52,7 +52,7 @@ Set the default route to the Tun.
 
 #### endpoint_independent_nat
 
-Enabled endpoint-independent NAT.
+Enable endpoint-independent NAT.
 
 Performance may degrade slightly, so it is not recommended to enable on when it is not needed.
 

+ 2 - 2
docs/configuration/route/index.md

@@ -30,7 +30,7 @@ Default outbound tag. the first outbound will be used if empty.
 
 !!! error ""
 
-    Only supported on Linux and Windows.
+    Only supported on Linux, Windows and macOS.
 
 Bind outbound connections to the default NIC by default to prevent routing loops under Tun.
 
@@ -40,7 +40,7 @@ Takes no effect if `outbound.bind_interface` is set.
 
 !!! error ""
 
-    Only supported on Linux and Windows.
+    Only supported on Linux, Windows and macOS.
 
 Bind outbound connections to the specified NIC by default to prevent routing loops under Tun.
 

+ 2 - 2
go.mod

@@ -13,10 +13,10 @@ require (
 	github.com/hashicorp/yamux v0.1.1
 	github.com/logrusorgru/aurora v2.0.3+incompatible
 	github.com/oschwald/maxminddb-golang v1.9.0
-	github.com/sagernet/sing v0.0.0-20220804023557-9c64b40e7050
+	github.com/sagernet/sing v0.0.0-20220805082239-f616c4f12600
 	github.com/sagernet/sing-dns v0.0.0-20220803121532-9e1ffb850d91
 	github.com/sagernet/sing-shadowsocks v0.0.0-20220801112336-a91eacdd01e1
-	github.com/sagernet/sing-tun v0.0.0-20220804154459-7ee0d19103d2
+	github.com/sagernet/sing-tun v0.0.0-20220805085423-4a83493b40e2
 	github.com/sagernet/sing-vmess v0.0.0-20220804023624-e829b41c84c2
 	github.com/spf13/cobra v1.5.0
 	github.com/stretchr/testify v1.8.0

+ 4 - 4
go.sum

@@ -149,14 +149,14 @@ github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR
 github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
 github.com/sagernet/netlink v0.0.0-20220803045538-bdac49abf805 h1:hE+vtsjBCCPmxkRz9jZA+CicHgVkDT6H+Av5ZzskVxs=
 github.com/sagernet/netlink v0.0.0-20220803045538-bdac49abf805/go.mod h1:xLnfdiJbSp8rNqYEdIW/6eDO4mVoogml14Bh2hSiFpM=
-github.com/sagernet/sing v0.0.0-20220804023557-9c64b40e7050 h1:Q6PV3tlP7htm9jgebFryXT4HFvEHvb5QHEcuWrf4E2o=
-github.com/sagernet/sing v0.0.0-20220804023557-9c64b40e7050/go.mod h1:QVsS5L/ZA2Q5UhQwLrn0Trw+msNd/NPGEhBKR/ioWiY=
+github.com/sagernet/sing v0.0.0-20220805082239-f616c4f12600 h1:ZyNW19K2vuRxEfjS7fFp4Y2lDFh7sfxzivGalMQdTjw=
+github.com/sagernet/sing v0.0.0-20220805082239-f616c4f12600/go.mod h1:QVsS5L/ZA2Q5UhQwLrn0Trw+msNd/NPGEhBKR/ioWiY=
 github.com/sagernet/sing-dns v0.0.0-20220803121532-9e1ffb850d91 h1:jxt2PYixIkK2i7nUGW3f+PzJagEZcbNyQddBWGuqNnw=
 github.com/sagernet/sing-dns v0.0.0-20220803121532-9e1ffb850d91/go.mod h1:T77zZdE2Cm6VqnFumrpwsq+kxYsbq+vWDhmjtdSl/oM=
 github.com/sagernet/sing-shadowsocks v0.0.0-20220801112336-a91eacdd01e1 h1:RYvOc69eSNMN0dwVugrDts41Nn7Ar/C/n/fvytvFcp4=
 github.com/sagernet/sing-shadowsocks v0.0.0-20220801112336-a91eacdd01e1/go.mod h1:NqZjiXszgVCMQ4gVDa2V+drhS8NMfGqUqDF86EacEFc=
-github.com/sagernet/sing-tun v0.0.0-20220804154459-7ee0d19103d2 h1:har8hmVNhGxp14zLNAoGrgfzgxZQn0KTYJDfJudj0RU=
-github.com/sagernet/sing-tun v0.0.0-20220804154459-7ee0d19103d2/go.mod h1:K1Hfxaa/1zsxZix3ats3k1TJftVwK0l4OoRnUjjhi0g=
+github.com/sagernet/sing-tun v0.0.0-20220805085423-4a83493b40e2 h1:mdYyKefLtjM/5P/poakkBXvqpVOeOOxjIq2eiH3qol8=
+github.com/sagernet/sing-tun v0.0.0-20220805085423-4a83493b40e2/go.mod h1:K1Hfxaa/1zsxZix3ats3k1TJftVwK0l4OoRnUjjhi0g=
 github.com/sagernet/sing-vmess v0.0.0-20220804023624-e829b41c84c2 h1:C8sc2MYiNx0O7uQ0nieJWq5qYeIHj20XHFWPlcgoQeY=
 github.com/sagernet/sing-vmess v0.0.0-20220804023624-e829b41c84c2/go.mod h1:bNXBqSWYaG3ePl6u0xQY5zneE+ZKa3683ZpuE8S1M1w=
 github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo=

+ 1 - 1
inbound/tun.go

@@ -1,4 +1,4 @@
-//go:build (linux || windows) && !no_gvisor
+//go:build (linux || windows || darwin) && !no_gvisor
 
 package inbound
 

+ 1 - 1
inbound/tun_stub.go

@@ -1,4 +1,4 @@
-//go:build !(linux || windows) || no_gvisor
+//go:build !(linux || windows || darwin) || no_gvisor
 
 package inbound
 

+ 1 - 1
route/router.go

@@ -39,7 +39,7 @@ import (
 
 var warnDefaultInterfaceOnUnsupportedPlatform = warning.New(
 	func() bool {
-		return !(C.IsLinux || C.IsWindows)
+		return !(C.IsLinux || C.IsWindows || C.IsDarwin)
 	},
 	"route option `default_mark` is only supported on Linux and Windows",
 )

+ 1 - 1
route/router_dns.go

@@ -25,7 +25,7 @@ func (r *Router) Exchange(ctx context.Context, message *dnsmessage.Message) (*dn
 	if err != nil && len(message.Questions) > 0 {
 		r.dnsLogger.ErrorContext(ctx, E.Cause(err, "exchange failed for ", message.Questions[0].Name.String()))
 	}
-	if response != nil {
+	if len(message.Questions) > 0 && response != nil {
 		LogDNSAnswers(r.dnsLogger, ctx, message.Questions[0].Name.String(), response.Answers)
 	}
 	return response, err

+ 2 - 2
test/go.mod

@@ -10,7 +10,7 @@ require (
 	github.com/docker/docker v20.10.17+incompatible
 	github.com/docker/go-connections v0.4.0
 	github.com/gofrs/uuid v4.2.0+incompatible
-	github.com/sagernet/sing v0.0.0-20220804023557-9c64b40e7050
+	github.com/sagernet/sing v0.0.0-20220805082239-f616c4f12600
 	github.com/sagernet/sing-shadowsocks v0.0.0-20220801112336-a91eacdd01e1
 	github.com/spyzhov/ajson v0.7.1
 	github.com/stretchr/testify v1.8.0
@@ -54,7 +54,7 @@ require (
 	github.com/pmezard/go-difflib v1.0.0 // indirect
 	github.com/sagernet/netlink v0.0.0-20220803045538-bdac49abf805 // indirect
 	github.com/sagernet/sing-dns v0.0.0-20220803121532-9e1ffb850d91 // indirect
-	github.com/sagernet/sing-tun v0.0.0-20220804154459-7ee0d19103d2 // indirect
+	github.com/sagernet/sing-tun v0.0.0-20220805085423-4a83493b40e2 // indirect
 	github.com/sagernet/sing-vmess v0.0.0-20220804023624-e829b41c84c2 // indirect
 	github.com/sirupsen/logrus v1.8.1 // indirect
 	github.com/vishvananda/netns v0.0.0-20211101163701-50045581ed74 // indirect

+ 4 - 4
test/go.sum

@@ -174,14 +174,14 @@ github.com/prometheus/procfs v0.0.0-20180725123919-05ee40e3a273/go.mod h1:c3At6R
 github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g=
 github.com/sagernet/netlink v0.0.0-20220803045538-bdac49abf805 h1:hE+vtsjBCCPmxkRz9jZA+CicHgVkDT6H+Av5ZzskVxs=
 github.com/sagernet/netlink v0.0.0-20220803045538-bdac49abf805/go.mod h1:xLnfdiJbSp8rNqYEdIW/6eDO4mVoogml14Bh2hSiFpM=
-github.com/sagernet/sing v0.0.0-20220804023557-9c64b40e7050 h1:Q6PV3tlP7htm9jgebFryXT4HFvEHvb5QHEcuWrf4E2o=
-github.com/sagernet/sing v0.0.0-20220804023557-9c64b40e7050/go.mod h1:QVsS5L/ZA2Q5UhQwLrn0Trw+msNd/NPGEhBKR/ioWiY=
+github.com/sagernet/sing v0.0.0-20220805082239-f616c4f12600 h1:ZyNW19K2vuRxEfjS7fFp4Y2lDFh7sfxzivGalMQdTjw=
+github.com/sagernet/sing v0.0.0-20220805082239-f616c4f12600/go.mod h1:QVsS5L/ZA2Q5UhQwLrn0Trw+msNd/NPGEhBKR/ioWiY=
 github.com/sagernet/sing-dns v0.0.0-20220803121532-9e1ffb850d91 h1:jxt2PYixIkK2i7nUGW3f+PzJagEZcbNyQddBWGuqNnw=
 github.com/sagernet/sing-dns v0.0.0-20220803121532-9e1ffb850d91/go.mod h1:T77zZdE2Cm6VqnFumrpwsq+kxYsbq+vWDhmjtdSl/oM=
 github.com/sagernet/sing-shadowsocks v0.0.0-20220801112336-a91eacdd01e1 h1:RYvOc69eSNMN0dwVugrDts41Nn7Ar/C/n/fvytvFcp4=
 github.com/sagernet/sing-shadowsocks v0.0.0-20220801112336-a91eacdd01e1/go.mod h1:NqZjiXszgVCMQ4gVDa2V+drhS8NMfGqUqDF86EacEFc=
-github.com/sagernet/sing-tun v0.0.0-20220804154459-7ee0d19103d2 h1:har8hmVNhGxp14zLNAoGrgfzgxZQn0KTYJDfJudj0RU=
-github.com/sagernet/sing-tun v0.0.0-20220804154459-7ee0d19103d2/go.mod h1:K1Hfxaa/1zsxZix3ats3k1TJftVwK0l4OoRnUjjhi0g=
+github.com/sagernet/sing-tun v0.0.0-20220805085423-4a83493b40e2 h1:mdYyKefLtjM/5P/poakkBXvqpVOeOOxjIq2eiH3qol8=
+github.com/sagernet/sing-tun v0.0.0-20220805085423-4a83493b40e2/go.mod h1:K1Hfxaa/1zsxZix3ats3k1TJftVwK0l4OoRnUjjhi0g=
 github.com/sagernet/sing-vmess v0.0.0-20220804023624-e829b41c84c2 h1:C8sc2MYiNx0O7uQ0nieJWq5qYeIHj20XHFWPlcgoQeY=
 github.com/sagernet/sing-vmess v0.0.0-20220804023624-e829b41c84c2/go.mod h1:bNXBqSWYaG3ePl6u0xQY5zneE+ZKa3683ZpuE8S1M1w=
 github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo=