2022-07-09 11:18:37 +00:00
|
|
|
//go:build linux
|
|
|
|
|
|
|
|
package tun
|
|
|
|
|
|
|
|
import (
|
2022-07-10 11:17:44 +00:00
|
|
|
"runtime"
|
|
|
|
|
2022-07-09 11:18:37 +00:00
|
|
|
"gvisor.dev/gvisor/pkg/tcpip/link/fdbased"
|
|
|
|
"gvisor.dev/gvisor/pkg/tcpip/stack"
|
|
|
|
)
|
|
|
|
|
|
|
|
func NewEndpoint(tunFd uintptr, tunMtu uint32) (stack.LinkEndpoint, error) {
|
2022-07-10 11:17:44 +00:00
|
|
|
var packetDispatchMode fdbased.PacketDispatchMode
|
|
|
|
if runtime.GOARCH == "amd64" || runtime.GOARCH == "arm64" {
|
|
|
|
packetDispatchMode = fdbased.PacketMMap
|
|
|
|
} else {
|
|
|
|
packetDispatchMode = fdbased.RecvMMsg
|
|
|
|
}
|
2022-07-09 11:18:37 +00:00
|
|
|
return fdbased.New(&fdbased.Options{
|
|
|
|
FDs: []int{int(tunFd)},
|
|
|
|
MTU: tunMtu,
|
2022-07-10 11:17:44 +00:00
|
|
|
PacketDispatchMode: packetDispatchMode,
|
2022-07-09 11:18:37 +00:00
|
|
|
})
|
|
|
|
}
|