Fix create gVisor endpoint

This commit is contained in:
世界 2022-07-10 19:17:44 +08:00
parent b417bd5be4
commit 0ef2e330e3
No known key found for this signature in database
GPG key ID: CD109927C34A63C4
3 changed files with 11 additions and 3 deletions

View file

@ -3,14 +3,22 @@
package tun package tun
import ( import (
"runtime"
"gvisor.dev/gvisor/pkg/tcpip/link/fdbased" "gvisor.dev/gvisor/pkg/tcpip/link/fdbased"
"gvisor.dev/gvisor/pkg/tcpip/stack" "gvisor.dev/gvisor/pkg/tcpip/stack"
) )
func NewEndpoint(tunFd uintptr, tunMtu uint32) (stack.LinkEndpoint, error) { 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{ return fdbased.New(&fdbased.Options{
FDs: []int{int(tunFd)}, FDs: []int{int(tunFd)},
MTU: tunMtu, MTU: tunMtu,
PacketDispatchMode: fdbased.PacketMMap, PacketDispatchMode: packetDispatchMode,
}) })
} }

View file

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

View file

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