summaryrefslogtreecommitdiffhomepage
path: root/tun
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2020-01-07 11:40:45 -0500
committerJason A. Donenfeld <Jason@zx2c4.com>2020-01-07 11:40:45 -0500
commit4fa2ea6a2dabad50eb5585d0a56c3a6966604fa6 (patch)
treecf3a611b4e4a0b6a87f9b933a5db08abedcfe044 /tun
parent89dd065e53e986234289a0ace66539873be8b075 (diff)
tun: windows: serialize write calls
Diffstat (limited to 'tun')
-rw-r--r--tun/tun_windows.go5
1 files changed, 5 insertions, 0 deletions
diff --git a/tun/tun_windows.go b/tun/tun_windows.go
index 8fc5174..b16dbb7 100644
--- a/tun/tun_windows.go
+++ b/tun/tun_windows.go
@@ -9,6 +9,7 @@ import (
"errors"
"fmt"
"os"
+ "sync"
"sync/atomic"
"time"
"unsafe"
@@ -40,6 +41,7 @@ type NativeTun struct {
forcedMTU int
rate rateJuggler
rings *wintun.RingDescriptor
+ writeLock sync.Mutex
}
const WintunPool = wintun.Pool("WireGuard")
@@ -219,6 +221,9 @@ func (tun *NativeTun) Write(buff []byte, offset int) (int, error) {
tun.rate.update(uint64(packetSize))
alignedPacketSize := wintun.PacketAlign(uint32(unsafe.Sizeof(wintun.PacketHeader{})) + packetSize)
+ tun.writeLock.Lock()
+ defer tun.writeLock.Unlock()
+
buffHead := atomic.LoadUint32(&tun.rings.Receive.Ring.Head)
if buffHead >= wintun.PacketCapacity {
return 0, os.ErrClosed