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
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,
})
}

View File

@ -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 {

View File

@ -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 {