Compare commits

...

2 Commits

Author SHA1 Message Date
JackDoan 334dd7a85d NAPI broken on old kernels and also not helpful 2026-04-24 17:36:20 -05:00
JackDoan c9d5a6e35a be safer 2026-04-24 16:48:52 -05:00
2 changed files with 6 additions and 9 deletions
+4 -7
View File
@@ -263,13 +263,12 @@ func (r *Offload) writeWithScratch(buf []byte, iovs *[2]unix.Iovec) (int, error)
// to validVnetHdr during Offload construction so we don't rebuild it here.
iovs[1].Base = &buf[0]
iovs[1].SetLen(len(buf))
iovPtr := unsafe.Pointer(&iovs[0])
return r.rawWrite(iovPtr, 2)
return r.rawWrite(unsafe.Slice(&iovs[0], len(iovs)))
}
func (r *Offload) rawWrite(iovs unsafe.Pointer, iovcnt int) (int, error) {
func (r *Offload) rawWrite(iovs []unix.Iovec) (int, error) {
for {
n, _, errno := syscall.Syscall(unix.SYS_WRITEV, uintptr(r.fd), uintptr(iovs), uintptr(iovcnt))
n, _, errno := syscall.Syscall(unix.SYS_WRITEV, uintptr(r.fd), uintptr(unsafe.Pointer(&iovs[0])), uintptr(len(iovs)))
if errno == 0 {
if int(n) < virtioNetHdrLen {
return 0, io.ErrShortWrite
@@ -352,9 +351,7 @@ func (r *Offload) WriteGSO(hdr []byte, pays [][]byte, gsoSize uint16, isV6 bool,
r.gsoIovs[2+i].SetLen(len(p))
}
iovPtr := unsafe.Pointer(&r.gsoIovs[0])
iovCnt := len(r.gsoIovs)
_, err := r.rawWrite(iovPtr, iovCnt)
_, err := r.rawWrite(r.gsoIovs)
return err
}
+2 -2
View File
@@ -139,7 +139,7 @@ func newTun(c *config.C, l *logrus.Logger, vpnNetworks []netip.Prefix, multiqueu
return nil, err
}
vnetHdr := true
name, err := tunSetIff(fd, nameStr, baseFlags|unix.IFF_VNET_HDR|unix.IFF_NAPI)
name, err := tunSetIff(fd, nameStr, baseFlags|unix.IFF_VNET_HDR)
if err != nil {
_ = unix.Close(fd)
vnetHdr = false
@@ -307,7 +307,7 @@ func (t *tun) NewMultiQueueReader() error {
flags := uint16(unix.IFF_TUN | unix.IFF_NO_PI | unix.IFF_MULTI_QUEUE)
if t.vnetHdr {
flags |= unix.IFF_VNET_HDR | unix.IFF_NAPI
flags |= unix.IFF_VNET_HDR
}
if _, err = tunSetIff(fd, t.Device, flags); err != nil {
_ = unix.Close(fd)