Skip to content

Commit 4fa1247

Browse files
authored
tun: replace use of binary package with copy() in virtioNetHdr encoding (#3)
This is a cherry-pick of 798bed0. Signed-off-by: Jordan Whited <[email protected]>
1 parent fbc107e commit 4fa1247

File tree

3 files changed

+2
-29
lines changed

3 files changed

+2
-29
lines changed

endian/big.go

Lines changed: 0 additions & 8 deletions
This file was deleted.

endian/little.go

Lines changed: 0 additions & 8 deletions
This file was deleted.

tun/tcp_offload_linux.go

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"unsafe"
88

99
"github.com/tailscale/wireguard-go/conn"
10-
"github.com/tailscale/wireguard-go/endian"
1110
"golang.org/x/sys/unix"
1211
)
1312

@@ -50,25 +49,15 @@ func (v *virtioNetHdr) decode(b []byte) error {
5049
if len(b) < virtioNetHdrLen {
5150
return errors.New("too short")
5251
}
53-
v.flags = b[0]
54-
v.gsoType = b[1]
55-
v.hdrLen = endian.Native.Uint16(b[2:])
56-
v.gsoSize = endian.Native.Uint16(b[4:])
57-
v.csumStart = endian.Native.Uint16(b[6:])
58-
v.csumOffset = endian.Native.Uint16(b[8:])
52+
copy(unsafe.Slice((*byte)(unsafe.Pointer(v)), virtioNetHdrLen), b[:virtioNetHdrLen])
5953
return nil
6054
}
6155

6256
func (v *virtioNetHdr) encode(b []byte) error {
6357
if len(b) < virtioNetHdrLen {
6458
return errors.New("too short")
6559
}
66-
b[0] = v.flags
67-
b[1] = v.gsoType
68-
endian.Native.PutUint16(b[2:], v.hdrLen)
69-
endian.Native.PutUint16(b[4:], v.gsoSize)
70-
endian.Native.PutUint16(b[6:], v.csumStart)
71-
endian.Native.PutUint16(b[8:], v.csumOffset)
60+
copy(b[:virtioNetHdrLen], unsafe.Slice((*byte)(unsafe.Pointer(v)), virtioNetHdrLen))
7261
return nil
7362
}
7463

0 commit comments

Comments
 (0)