wgengine/magicsock: use binary.NativeEndian for UDP GSO control data (#9640)

Updates #cleanup

Signed-off-by: Jordan Whited <jordan@tailscale.com>
pull/9641/head
Jordan Whited 1 year ago committed by GitHub
parent efac2cb8d6
commit eb22c0dfc7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -361,10 +361,7 @@ func getGSOSizeFromControl(control []byte) (int, error) {
return 0, fmt.Errorf("error parsing socket control message: %w", err) return 0, fmt.Errorf("error parsing socket control message: %w", err)
} }
if hdr.Level == unix.SOL_UDP && hdr.Type == unix.UDP_GRO && len(data) >= 2 { if hdr.Level == unix.SOL_UDP && hdr.Type == unix.UDP_GRO && len(data) >= 2 {
var gso uint16 return int(binary.NativeEndian.Uint16(data[:2])), nil
// TODO(jwhited): replace with encoding/binary.NativeEndian when it's available
copy(unsafe.Slice((*byte)(unsafe.Pointer(&gso)), 2), data[:2])
return int(gso), nil
} }
} }
return 0, nil return 0, nil
@ -385,8 +382,7 @@ func setGSOSizeInControl(control *[]byte, gsoSize uint16) {
hdr.Level = unix.SOL_UDP hdr.Level = unix.SOL_UDP
hdr.Type = unix.UDP_SEGMENT hdr.Type = unix.UDP_SEGMENT
hdr.SetLen(unix.CmsgLen(2)) hdr.SetLen(unix.CmsgLen(2))
// TODO(jwhited): replace with encoding/binary.NativeEndian when it's available binary.NativeEndian.PutUint16((*control)[unix.SizeofCmsghdr:], gsoSize)
copy((*control)[unix.SizeofCmsghdr:], unsafe.Slice((*byte)(unsafe.Pointer(&gsoSize)), 2))
*control = (*control)[:unix.CmsgSpace(2)] *control = (*control)[:unix.CmsgSpace(2)]
} }

Loading…
Cancel
Save