silly opinionated tweak

This commit is contained in:
JackDoan
2026-07-29 11:54:34 -05:00
parent b39bae57ec
commit 095a421708
2 changed files with 12 additions and 8 deletions
+2 -2
View File
@@ -358,7 +358,8 @@ func (r *Offload) WriteGSO(hdr []byte, transportHdr []byte, pays [][]byte, proto
if gsoType != unix.VIRTIO_NET_HDR_GSO_NONE { if gsoType != unix.VIRTIO_NET_HDR_GSO_NONE {
gsoSize = uint16(segSize) gsoSize = uint16(segSize)
} }
vhdr := virtio.NewHeader( virtio.EncodeHeader(
r.gsoHdrBuf[:],
unix.VIRTIO_NET_HDR_F_NEEDS_CSUM, /*flags*/ unix.VIRTIO_NET_HDR_F_NEEDS_CSUM, /*flags*/
gsoType, /*gsoType*/ gsoType, /*gsoType*/
uint16(len(hdr)+len(transportHdr)), /*hdrLen*/ uint16(len(hdr)+len(transportHdr)), /*hdrLen*/
@@ -366,7 +367,6 @@ func (r *Offload) WriteGSO(hdr []byte, transportHdr []byte, pays [][]byte, proto
uint16(len(hdr)), /*csumStart*/ uint16(len(hdr)), /*csumStart*/
csumOff, /*csumOffset*/ csumOff, /*csumOffset*/
) )
vhdr.Encode(r.gsoHdrBuf[:])
_, err := r.rawWrite(r.gsoIovs) _, err := r.rawWrite(r.gsoIovs)
return err return err
+10 -6
View File
@@ -46,15 +46,19 @@ func (h *Hdr) Decode(b []byte) {
h.CsumOffset = binary.NativeEndian.Uint16(b[8:10]) h.CsumOffset = binary.NativeEndian.Uint16(b[8:10])
} }
func EncodeHeader(b []byte, flags, gsoType uint8, hdrLen, gsoSize, csumStart, csumOffset uint16) {
b[0] = flags
b[1] = gsoType
binary.NativeEndian.PutUint16(b[2:4], hdrLen)
binary.NativeEndian.PutUint16(b[4:6], gsoSize)
binary.NativeEndian.PutUint16(b[6:8], csumStart)
binary.NativeEndian.PutUint16(b[8:10], csumOffset)
}
// Encode is the inverse of Decode: writes the virtio_net_hdr fields into b // Encode is the inverse of Decode: writes the virtio_net_hdr fields into b
// (must be at least Size bytes). Used to emit a TSO superpacket on egress. // (must be at least Size bytes). Used to emit a TSO superpacket on egress.
func (h *Hdr) Encode(b []byte) { func (h *Hdr) Encode(b []byte) {
b[0] = h.Flags EncodeHeader(b, h.Flags, h.gsoType, h.HdrLen, h.GSOSize, h.CsumStart, h.CsumOffset)
b[1] = h.gsoType
binary.NativeEndian.PutUint16(b[2:4], h.HdrLen)
binary.NativeEndian.PutUint16(b[4:6], h.GSOSize)
binary.NativeEndian.PutUint16(b[6:8], h.CsumStart)
binary.NativeEndian.PutUint16(b[8:10], h.CsumOffset)
} }
// GSOType returns gsoType with the ECN-flag masked out // GSOType returns gsoType with the ECN-flag masked out