mirror of
https://github.com/SagerNet/sing-tun.git
synced 2025-04-02 19:37:40 +03:00
22 lines
559 B
Go
22 lines
559 B
Go
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,
|
|
})
|
|
}
|