Skip to content

Commit

Permalink
Make GSO optional
Browse files Browse the repository at this point in the history
  • Loading branch information
nekohasekai committed Nov 22, 2024
1 parent 8355396 commit c0024dd
Showing 1 changed file with 26 additions and 18 deletions.
44 changes: 26 additions & 18 deletions tun_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit c0024dd

Please sign in to comment.