From 0ef2e330e31e0deb9e057e4c27fecb329137628c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=96=E7=95=8C?= Date: Sun, 10 Jul 2022 19:17:44 +0800 Subject: [PATCH] Fix create gVisor endpoint --- common/tun/gvisor_linux.go | 10 +++++++++- test/box_test.go | 2 +- test/docker_test.go | 2 +- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/common/tun/gvisor_linux.go b/common/tun/gvisor_linux.go index f09171d1..6fa98495 100644 --- a/common/tun/gvisor_linux.go +++ b/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, }) } diff --git a/test/box_test.go b/test/box_test.go index 25a47758..beac2575 100644 --- a/test/box_test.go +++ b/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 { diff --git a/test/docker_test.go b/test/docker_test.go index 243c5486..87bfbc15 100644 --- a/test/docker_test.go +++ b/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 {