aboutsummaryrefslogtreecommitdiffstats
path: root/tun/tun_windows.go
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2019-07-05 07:53:19 +0200
committerJason A. Donenfeld <Jason@zx2c4.com>2019-07-05 07:53:19 +0200
commitd8448f8a0298b16cc128bf0e64963852964d2e78 (patch)
tree1471065fe3d8134a9aac3e43dcc6bfc161b9032d /tun/tun_windows.go
parenttun: windows: delay initial write (diff)
downloadwireguard-go-d8448f8a0298b16cc128bf0e64963852964d2e78.tar.xz
wireguard-go-d8448f8a0298b16cc128bf0e64963852964d2e78.zip
tun: windows: decrease alignment to 4
Diffstat (limited to 'tun/tun_windows.go')
-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 613bc9f..f0acc09 100644
--- a/tun/tun_windows.go
+++ b/tun/tun_windows.go
@@ -20,7 +20,7 @@ import (
)
const (
- packetExchangeAlignment uint32 = 16 // Number of bytes packets are aligned to in exchange buffers
+ packetExchangeAlignment uint32 = 4 // Number of bytes packets are aligned to in exchange buffers
packetSizeMax uint32 = 0xf000 - packetExchangeAlignment // Maximum packet size
packetExchangeSize uint32 = 0x100000 // Exchange buffer size (defaults to 1MiB)
retryRate = 4 // Number of retries per second to reopen device pipe
@@ -255,7 +255,7 @@ func (tun *NativeTun) Read(buff []byte, offset int) (int, error) {
// Get packet from the exchange buffer.
packet := tun.rdBuff.data[tun.rdBuff.offset:]
size := *(*uint32)(unsafe.Pointer(&packet[0]))
- pSize := packetAlign(packetExchangeAlignment + size)
+ pSize := packetAlign(size) + packetExchangeAlignment
if packetSizeMax < size || tun.rdBuff.avail < tun.rdBuff.offset+pSize {
// Invalid packet size.
tun.rdBuff.avail = 0
@@ -363,7 +363,7 @@ func (tun *NativeTun) putTunPacket(buff []byte) error {
if size > packetSizeMax {
return errors.New("Packet too big")
}
- pSize := packetAlign(packetExchangeAlignment + size)
+ pSize := packetAlign(size) + packetExchangeAlignment
if tun.wrBuff.offset+pSize >= packetExchangeSize {
// Exchange buffer is full -> flush first.