diff --git a/tun_linux.go b/tun_linux.go index 841bbea..5c7df19 100644 --- a/tun_linux.go +++ b/tun_linux.go @@ -328,25 +328,9 @@ func (t *NativeTun) configure(tunLink netlink.Link) error { } if t.options.GSO { - var vnetHdrEnabled bool - vnetHdrEnabled, err = checkVNETHDREnabled(t.tunFd, t.options.Name) + err = t.enableGSO() 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 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() + t.options.Logger.Warn(err) } } @@ -374,6 +358,30 @@ func (t *NativeTun) configure(tunLink netlink.Link) error { 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 { if t.options.FileDescriptor != 0 { return nil diff --git a/tun_linux_gvisor.go b/tun_linux_gvisor.go index 064f740..f82d762 100644 --- a/tun_linux_gvisor.go +++ b/tun_linux_gvisor.go @@ -15,6 +15,7 @@ func (t *NativeTun) NewEndpoint() (stack.LinkEndpoint, error) { FDs: []int{t.tunFd}, MTU: t.options.MTU, GSOMaxSize: gsoMaxSize, + GRO: true, RXChecksumOffload: true, TXChecksumOffload: t.txChecksumOffload, })