github.com/sagernet/sing-tun@v0.3.0-beta.5/tun_linux_gvisor.go (about)

     1  //go:build with_gvisor && linux
     2  
     3  package tun
     4  
     5  import (
     6  	"github.com/sagernet/gvisor/pkg/tcpip/link/fdbased"
     7  	"github.com/sagernet/gvisor/pkg/tcpip/stack"
     8  )
     9  
    10  var _ GVisorTun = (*NativeTun)(nil)
    11  
    12  func (t *NativeTun) NewEndpoint() (stack.LinkEndpoint, error) {
    13  	if t.gsoEnabled {
    14  		return fdbased.New(&fdbased.Options{
    15  			FDs:               []int{t.tunFd},
    16  			MTU:               t.options.MTU,
    17  			GSOMaxSize:        gsoMaxSize,
    18  			RXChecksumOffload: true,
    19  			TXChecksumOffload: t.txChecksumOffload,
    20  		})
    21  	}
    22  	return fdbased.New(&fdbased.Options{
    23  		FDs:               []int{t.tunFd},
    24  		MTU:               t.options.MTU,
    25  		RXChecksumOffload: true,
    26  		TXChecksumOffload: t.txChecksumOffload,
    27  	})
    28  }