mirror of
https://github.com/SagerNet/sing-tun.git
synced 2025-04-02 19:37:40 +03:00
Make GSO optional
This commit is contained in:
parent
2b8115e83b
commit
c1f61d08ba
2 changed files with 27 additions and 18 deletions
44
tun_linux.go
44
tun_linux.go
|
@ -328,25 +328,9 @@ func (t *NativeTun) configure(tunLink netlink.Link) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
if t.options.GSO {
|
if t.options.GSO {
|
||||||
var vnetHdrEnabled bool
|
err = t.enableGSO()
|
||||||
vnetHdrEnabled, err = checkVNETHDREnabled(t.tunFd, t.options.Name)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return E.Cause(err, "enable offload: check IFF_VNET_HDR enabled")
|
t.options.Logger.Warn(err)
|
||||||
}
|
|
||||||
if !vnetHdrEnabled {
|
|
||||||
return E.Cause(err, "enable offload: IFF_VNET_HDR not enabled")
|
|
||||||
}
|
|
||||||
err = setTCPOffload(t.tunFd)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
t.vnetHdr = true
|
|
||||||
t.writeBuffer = make([]byte, virtioNetHdrLen+int(gsoMaxSize))
|
|
||||||
t.tcpGROTable = newTCPGROTable()
|
|
||||||
t.udpGROTable = newUDPGROTable()
|
|
||||||
err = setUDPOffload(t.tunFd)
|
|
||||||
if err != nil {
|
|
||||||
t.gro.disableUDPGRO()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -374,6 +358,30 @@ func (t *NativeTun) configure(tunLink netlink.Link) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (t *NativeTun) enableGSO() error {
|
||||||
|
vnetHdrEnabled, err := checkVNETHDREnabled(t.tunFd, t.options.Name)
|
||||||
|
if err != nil {
|
||||||
|
return E.Cause(err, "enable offload: check IFF_VNET_HDR enabled")
|
||||||
|
}
|
||||||
|
if !vnetHdrEnabled {
|
||||||
|
return E.Cause(err, "enable offload: IFF_VNET_HDR not enabled")
|
||||||
|
}
|
||||||
|
err = setTCPOffload(t.tunFd)
|
||||||
|
if err != nil {
|
||||||
|
return E.Cause(err, "enable TCP offload")
|
||||||
|
}
|
||||||
|
t.vnetHdr = true
|
||||||
|
t.writeBuffer = make([]byte, virtioNetHdrLen+int(gsoMaxSize))
|
||||||
|
t.tcpGROTable = newTCPGROTable()
|
||||||
|
t.udpGROTable = newUDPGROTable()
|
||||||
|
err = setUDPOffload(t.tunFd)
|
||||||
|
if err != nil {
|
||||||
|
t.gro.disableUDPGRO()
|
||||||
|
return E.Cause(err, "enable UDP offload")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (t *NativeTun) Start() error {
|
func (t *NativeTun) Start() error {
|
||||||
if t.options.FileDescriptor != 0 {
|
if t.options.FileDescriptor != 0 {
|
||||||
return nil
|
return nil
|
||||||
|
|
|
@ -15,6 +15,7 @@ func (t *NativeTun) NewEndpoint() (stack.LinkEndpoint, error) {
|
||||||
FDs: []int{t.tunFd},
|
FDs: []int{t.tunFd},
|
||||||
MTU: t.options.MTU,
|
MTU: t.options.MTU,
|
||||||
GSOMaxSize: gsoMaxSize,
|
GSOMaxSize: gsoMaxSize,
|
||||||
|
GRO: true,
|
||||||
RXChecksumOffload: true,
|
RXChecksumOffload: true,
|
||||||
TXChecksumOffload: t.txChecksumOffload,
|
TXChecksumOffload: t.txChecksumOffload,
|
||||||
})
|
})
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue