udp: extract and test the GRO RX splitting

This commit is contained in:
JackDoan
2026-07-27 15:56:47 -05:00
parent 865dc9725c
commit 3fe2cb970e
2 changed files with 89 additions and 12 deletions
+16 -12
View File
@@ -332,24 +332,28 @@ func (u *StdConn) ListenOut(r EncReader, flush func()) error {
segSize, outerECN = parseRecvCmsg(&msgs[i].Hdr, u.groSupported, u.ecnRecvSupported)
}
if segSize <= 0 || segSize >= len(payload) {
r(from, payload, RxMeta{OuterECN: outerECN})
} else {
for off := 0; off < len(payload); off += segSize {
end := off + segSize
if end > len(payload) {
end = len(payload)
}
seg := payload[off:end]
r(from, seg, RxMeta{OuterECN: outerECN})
}
}
deliverSegments(r, from, payload, segSize, RxMeta{OuterECN: outerECN})
}
flush()
}
}
// deliverSegments hands a received superdatagram to r, splitting it back into pre-coalesce packets
func deliverSegments(r EncReader, from netip.AddrPort, payload []byte, segSize int, meta RxMeta) {
if segSize <= 0 || segSize >= len(payload) { //avoid bogus values
r(from, payload, meta)
return
}
for off := 0; off < len(payload); off += segSize {
end := off + segSize
if end > len(payload) {
end = len(payload)
}
r(from, payload[off:end], meta)
}
}
// parseRecvCmsg walks the per-slot ancillary buffer once and extracts up to
// two values of interest in a single pass: the UDP_GRO gso_size (when
// wantGRO is true) and the outer IP-level ECN codepoint stamped on the