Skip to content

Commit 765a91f

Browse files
committed
Make GSO optional
1 parent 8355396 commit 765a91f

File tree

2 files changed

+27
-18
lines changed

2 files changed

+27
-18
lines changed

tun_linux.go

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -328,25 +328,9 @@ func (t *NativeTun) configure(tunLink netlink.Link) error {
328328
}
329329

330330
if t.options.GSO {
331-
var vnetHdrEnabled bool
332-
vnetHdrEnabled, err = checkVNETHDREnabled(t.tunFd, t.options.Name)
331+
err = t.enableGSO()
333332
if err != nil {
334-
return E.Cause(err, "enable offload: check IFF_VNET_HDR enabled")
335-
}
336-
if !vnetHdrEnabled {
337-
return E.Cause(err, "enable offload: IFF_VNET_HDR not enabled")
338-
}
339-
err = setTCPOffload(t.tunFd)
340-
if err != nil {
341-
return err
342-
}
343-
t.vnetHdr = true
344-
t.writeBuffer = make([]byte, virtioNetHdrLen+int(gsoMaxSize))
345-
t.tcpGROTable = newTCPGROTable()
346-
t.udpGROTable = newUDPGROTable()
347-
err = setUDPOffload(t.tunFd)
348-
if err != nil {
349-
t.gro.disableUDPGRO()
333+
t.options.Logger.Warn(err)
350334
}
351335
}
352336

@@ -374,6 +358,30 @@ func (t *NativeTun) configure(tunLink netlink.Link) error {
374358
return nil
375359
}
376360

361+
func (t *NativeTun) enableGSO() error {
362+
vnetHdrEnabled, err := checkVNETHDREnabled(t.tunFd, t.options.Name)
363+
if err != nil {
364+
return E.Cause(err, "enable offload: check IFF_VNET_HDR enabled")
365+
}
366+
if !vnetHdrEnabled {
367+
return E.Cause(err, "enable offload: IFF_VNET_HDR not enabled")
368+
}
369+
err = setTCPOffload(t.tunFd)
370+
if err != nil {
371+
return E.Cause(err, "enable TCP offload")
372+
}
373+
t.vnetHdr = true
374+
t.writeBuffer = make([]byte, virtioNetHdrLen+int(gsoMaxSize))
375+
t.tcpGROTable = newTCPGROTable()
376+
t.udpGROTable = newUDPGROTable()
377+
err = setUDPOffload(t.tunFd)
378+
if err != nil {
379+
t.gro.disableUDPGRO()
380+
return E.Cause(err, "enable UDP offload")
381+
}
382+
return nil
383+
}
384+
377385
func (t *NativeTun) Start() error {
378386
if t.options.FileDescriptor != 0 {
379387
return nil

tun_linux_gvisor.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ func (t *NativeTun) NewEndpoint() (stack.LinkEndpoint, error) {
1515
FDs: []int{t.tunFd},
1616
MTU: t.options.MTU,
1717
GSOMaxSize: gsoMaxSize,
18+
GRO: true,
1819
RXChecksumOffload: true,
1920
TXChecksumOffload: t.txChecksumOffload,
2021
})

0 commit comments

Comments
 (0)