aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Rozman <simon@rozman.si>2019-02-22 16:16:14 +0100
committerSimon Rozman <simon@rozman.si>2019-02-22 16:16:14 +0100
commitd002eff15589ffc384c8d7e8da5d7bd7e75720e4 (patch)
tree2d51d13be2d835d7d65d40d708ce46384a344e95
parentwintun: Make two-step slicing a one step (diff)
downloadwireguard-go-d002eff15589ffc384c8d7e8da5d7bd7e75720e4.tar.xz
wireguard-go-d002eff15589ffc384c8d7e8da5d7bd7e75720e4.zip
wintun: Read/write packet size from/to exchange buffer directly
Driver <-> user-space communication is local and using native endian. Signed-off-by: Simon Rozman <simon@rozman.si>
-rw-r--r--tun/tun_windows.go6
1 files changed, 3 insertions, 3 deletions
diff --git a/tun/tun_windows.go b/tun/tun_windows.go
index 65c32f2..e9bf0b7 100644
--- a/tun/tun_windows.go
+++ b/tun/tun_windows.go
@@ -6,10 +6,10 @@
package tun
import (
- "encoding/binary"
"errors"
"os"
"sync"
+ "unsafe"
"golang.org/x/sys/windows"
"golang.zx2c4.com/wireguard/tun/wintun"
@@ -230,7 +230,7 @@ func (tun *nativeTun) Read(buff []byte, offset int) (int, error) {
if tun.rdBuff.offset+packetExchangeAlignment <= tun.rdBuff.avail {
// Get packet from the exchange buffer.
packet := tun.rdBuff.data[tun.rdBuff.offset:]
- size := binary.LittleEndian.Uint32(packet[:4])
+ size := *(*uint32)(unsafe.Pointer(&packet[0]))
pSize := packetAlign(packetExchangeAlignment + size)
if packetSizeMax < size || tun.rdBuff.avail < tun.rdBuff.offset+pSize {
// Invalid packet size.
@@ -332,7 +332,7 @@ func (tun *nativeTun) putTunPacket(buff []byte) error {
// Write packet to the exchange buffer.
packet := tun.wrBuff.data[tun.wrBuff.offset : tun.wrBuff.offset+pSize]
- binary.LittleEndian.PutUint32(packet[:4], size)
+ *(*uint32)(unsafe.Pointer(&packet[0])) = size
copy(packet[packetExchangeAlignment:packetExchangeAlignment+size], buff)
tun.wrBuff.packetNum++