mirror of
https://github.com/SagerNet/sing-tun.git
synced 2025-09-27 13:02:08 +08:00
39 lines
953 B
Go
39 lines
953 B
Go
//go:build with_gvisor && linux
|
|
|
|
package tun
|
|
|
|
import (
|
|
"github.com/sagernet/gvisor/pkg/tcpip/link/fdbased"
|
|
"github.com/sagernet/gvisor/pkg/tcpip/stack"
|
|
)
|
|
|
|
var _ GVisorTun = (*NativeTun)(nil)
|
|
|
|
func (t *NativeTun) NewEndpoint() (stack.LinkEndpoint, stack.NICOptions, error) {
|
|
if t.vnetHdr {
|
|
ep, err := fdbased.New(&fdbased.Options{
|
|
FDs: []int{t.tunFd},
|
|
MTU: t.options.MTU,
|
|
GSOMaxSize: gsoMaxSize,
|
|
GRO: true,
|
|
RXChecksumOffload: true,
|
|
TXChecksumOffload: t.txChecksumOffload,
|
|
})
|
|
if err != nil {
|
|
return nil, stack.NICOptions{}, err
|
|
}
|
|
return ep, stack.NICOptions{}, nil
|
|
} else {
|
|
ep, err := fdbased.New(&fdbased.Options{
|
|
FDs: []int{t.tunFd},
|
|
MTU: t.options.MTU,
|
|
RXChecksumOffload: true,
|
|
TXChecksumOffload: t.txChecksumOffload,
|
|
})
|
|
if err != nil {
|
|
return nil, stack.NICOptions{}, err
|
|
}
|
|
return ep, stack.NICOptions{}, nil
|
|
}
|
|
}
|