mirror of
https://github.com/SagerNet/sing-tun.git
synced 2025-09-27 04:55:53 +08:00
29 lines
720 B
Go
29 lines
720 B
Go
//go:build with_gvisor && darwin
|
|
|
|
package tun
|
|
|
|
import (
|
|
"github.com/sagernet/gvisor/pkg/tcpip/link/qdisc/fifo"
|
|
"github.com/sagernet/gvisor/pkg/tcpip/stack"
|
|
"github.com/sagernet/sing-tun/internal/fdbased_darwin"
|
|
)
|
|
|
|
var _ GVisorTun = (*NativeTun)(nil)
|
|
|
|
func (t *NativeTun) NewEndpoint() (stack.LinkEndpoint, stack.NICOptions, error) {
|
|
ep, err := fdbased.New(&fdbased.Options{
|
|
FDs: []int{t.tunFd},
|
|
MTU: t.options.MTU,
|
|
RXChecksumOffload: true,
|
|
PacketDispatchMode: fdbased.RecvMMsg,
|
|
})
|
|
if err != nil {
|
|
return nil, stack.NICOptions{}, err
|
|
}
|
|
var nicOptions stack.NICOptions
|
|
if t.options.MTU < 49152 {
|
|
nicOptions.QDisc = fifo.New(ep, 1, 1000)
|
|
}
|
|
return ep, nicOptions, nil
|
|
}
|