Browse Source

Fix create gVisor endpoint

世界 3 years ago
parent
commit
0ef2e330e3
3 changed files with 11 additions and 3 deletions
  1. 9 1
      common/tun/gvisor_linux.go
  2. 1 1
      test/box_test.go
  3. 1 1
      test/docker_test.go

+ 9 - 1
common/tun/gvisor_linux.go

@@ -3,14 +3,22 @@
 package tun
 
 import (
+	"runtime"
+
 	"gvisor.dev/gvisor/pkg/tcpip/link/fdbased"
 	"gvisor.dev/gvisor/pkg/tcpip/stack"
 )
 
 func NewEndpoint(tunFd uintptr, tunMtu uint32) (stack.LinkEndpoint, error) {
+	var packetDispatchMode fdbased.PacketDispatchMode
+	if runtime.GOARCH == "amd64" || runtime.GOARCH == "arm64" {
+		packetDispatchMode = fdbased.PacketMMap
+	} else {
+		packetDispatchMode = fdbased.RecvMMsg
+	}
 	return fdbased.New(&fdbased.Options{
 		FDs:                []int{int(tunFd)},
 		MTU:                tunMtu,
-		PacketDispatchMode: fdbased.PacketMMap,
+		PacketDispatchMode: packetDispatchMode,
 	})
 }

+ 1 - 1
test/box_test.go

@@ -4,6 +4,7 @@ import (
 	"context"
 	"net"
 	"testing"
+	"time"
 
 	"github.com/sagernet/sing-box"
 	"github.com/sagernet/sing-box/option"
@@ -13,7 +14,6 @@ import (
 	"github.com/sagernet/sing/protocol/socks"
 
 	"github.com/stretchr/testify/require"
-	"time"
 )
 
 func mkPort(t *testing.T) uint16 {

+ 1 - 1
test/docker_test.go

@@ -3,6 +3,7 @@ package main
 import (
 	"context"
 	"testing"
+	"time"
 
 	F "github.com/sagernet/sing/common/format"
 
@@ -11,7 +12,6 @@ import (
 	"github.com/docker/docker/client"
 	"github.com/docker/go-connections/nat"
 	"github.com/stretchr/testify/require"
-	"time"
 )
 
 type DockerOptions struct {