mirror of
https://github.com/SagerNet/sing-tun.git
synced 2025-10-07 09:31:11 +08:00
Init commit
This commit is contained in:
22
gvisor_linux.go
Normal file
22
gvisor_linux.go
Normal file
@@ -0,0 +1,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: packetDispatchMode,
|
||||
})
|
||||
}
|
Reference in New Issue
Block a user