net/batching: reset Buffers len in WriteBatchTo

In case we land on this branch during a goto retry. Also, protect
Geneve offset from mutation across retries.

Fixes #19927

Signed-off-by: Jordan Whited <jordan@tailscale.com>
This commit is contained in:
Jordan Whited
2026-05-31 06:12:53 -07:00
committed by Jordan Whited
parent 3e34e721e8
commit 8a294e3c34
2 changed files with 163 additions and 2 deletions
+7 -2
View File
@@ -296,15 +296,20 @@ retry:
if c.txOffload.Load() && (!neverGSOEqualTail || len(buffs) >= appendSentinelTailBatchSizeThreshold) {
n = c.coalesceMessages(batch.ua, geneve, buffs, batch.msgs, offset, neverGSOEqualTail)
} else {
mutableOffset := offset // don't mutate offset across retries
vniIsSet := geneve.VNI.IsSet()
if vniIsSet {
offset -= packet.GeneveFixedHeaderLength
mutableOffset -= packet.GeneveFixedHeaderLength
}
for i := range buffs {
if vniIsSet {
geneve.Encode(buffs[i])
}
batch.msgs[i].Buffers[0] = buffs[i][offset:]
batch.msgs[i].Buffers[0] = buffs[i][mutableOffset:]
// Buffers length may be > 1 (scatter-gather) if we passed through
// coalesceMessages during a first pass, and landed here as part of
// goto retry.
batch.msgs[i].Buffers = batch.msgs[i].Buffers[:1]
batch.msgs[i].Addr = batch.ua
batch.msgs[i].OOB = batch.msgs[i].OOB[:0]
}