mirror of
https://github.com/SagerNet/sing-box.git
synced 2024-11-29 12:01:29 +00:00
Fix create gVisor endpoint
This commit is contained in:
parent
b417bd5be4
commit
0ef2e330e3
|
@ -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,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -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 {
|
||||||
|
|
|
@ -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 {
|
||||||
|
|
Loading…
Reference in a new issue