diff --git a/endian/big.go b/endian/big.go deleted file mode 100644 index b53035d6e..000000000 --- a/endian/big.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:build mips || mips64 || ppc64 || s390x - -package endian - -import "encoding/binary" - -// Native is the platform's native byte order. -var Native = binary.LittleEndian diff --git a/endian/little.go b/endian/little.go deleted file mode 100644 index e1090071b..000000000 --- a/endian/little.go +++ /dev/null @@ -1,8 +0,0 @@ -//go:build 386 || amd64 || arm || arm64 || mips64le || mipsle || ppc64le || riscv64 || wasm || loong64 - -package endian - -import "encoding/binary" - -// Native is the platform's native byte order. -var Native = binary.LittleEndian diff --git a/tun/tcp_offload_linux.go b/tun/tcp_offload_linux.go index 9f54e996e..757f6730f 100644 --- a/tun/tcp_offload_linux.go +++ b/tun/tcp_offload_linux.go @@ -7,7 +7,6 @@ import ( "unsafe" "github.com/tailscale/wireguard-go/conn" - "github.com/tailscale/wireguard-go/endian" "golang.org/x/sys/unix" ) @@ -50,12 +49,7 @@ func (v *virtioNetHdr) decode(b []byte) error { if len(b) < virtioNetHdrLen { return errors.New("too short") } - v.flags = b[0] - v.gsoType = b[1] - v.hdrLen = endian.Native.Uint16(b[2:]) - v.gsoSize = endian.Native.Uint16(b[4:]) - v.csumStart = endian.Native.Uint16(b[6:]) - v.csumOffset = endian.Native.Uint16(b[8:]) + copy(unsafe.Slice((*byte)(unsafe.Pointer(v)), virtioNetHdrLen), b[:virtioNetHdrLen]) return nil } @@ -63,12 +57,7 @@ func (v *virtioNetHdr) encode(b []byte) error { if len(b) < virtioNetHdrLen { return errors.New("too short") } - b[0] = v.flags - b[1] = v.gsoType - endian.Native.PutUint16(b[2:], v.hdrLen) - endian.Native.PutUint16(b[4:], v.gsoSize) - endian.Native.PutUint16(b[6:], v.csumStart) - endian.Native.PutUint16(b[8:], v.csumOffset) + copy(b[:virtioNetHdrLen], unsafe.Slice((*byte)(unsafe.Pointer(v)), virtioNetHdrLen)) return nil }