mirror of
https://github.com/SagerNet/sing-box.git
synced 2025-01-24 01:36:36 +00:00
25 lines
577 B
Go
25 lines
577 B
Go
//go:build linux
|
|
|
|
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: packetDispatchMode,
|
|
})
|
|
}
|