diff options
Diffstat (limited to 'tun')
-rw-r--r-- | tun/tun_windows.go | 15 | ||||
-rw-r--r-- | tun/wintun/wintun_windows.go | 2 |
2 files changed, 13 insertions, 4 deletions
diff --git a/tun/tun_windows.go b/tun/tun_windows.go index b88129d..05fc3df 100644 --- a/tun/tun_windows.go +++ b/tun/tun_windows.go @@ -55,6 +55,15 @@ func packetAlign(size uint32) uint32 { return (size + (packetExchangeAlignment - 1)) &^ (packetExchangeAlignment - 1) } +var shouldRetryOpen = windows.RtlGetVersion().MajorVersion < 10 + +func maybeRetry(x int) int { + if shouldRetryOpen { + return x + } + return 0 +} + // // CreateTUN creates a Wintun adapter with the given name. Should a Wintun // adapter with the same name exist, it is reused. @@ -104,7 +113,7 @@ func CreateTUNWithRequestedGUID(ifname string, requestedGUID *windows.GUID) (Dev } func (tun *NativeTun) openTUN() error { - retries := retryTimeout * retryRate + retries := maybeRetry(retryTimeout * retryRate) if tun.close { return os.ErrClosed } @@ -238,7 +247,7 @@ func (tun *NativeTun) Read(buff []byte, offset int) (int, error) { default: } - retries := 1000 + retries := maybeRetry(1000) for { if tun.rdBuff.offset+packetExchangeAlignment <= tun.rdBuff.avail { // Get packet from the exchange buffer. @@ -302,7 +311,7 @@ func (tun *NativeTun) Flush() error { tun.wrBuff.packetNum = 0 tun.wrBuff.offset = 0 }() - retries := 1000 + retries := maybeRetry(1000) for { // Get TUN data pipe. diff --git a/tun/wintun/wintun_windows.go b/tun/wintun/wintun_windows.go index 281ab37..b8aabf3 100644 --- a/tun/wintun/wintun_windows.go +++ b/tun/wintun/wintun_windows.go @@ -30,7 +30,7 @@ type Wintun struct { var deviceClassNetGUID = windows.GUID{Data1: 0x4d36e972, Data2: 0xe325, Data3: 0x11ce, Data4: [8]byte{0xbf, 0xc1, 0x08, 0x00, 0x2b, 0xe1, 0x03, 0x18}} const ( - hardwareID = "Wintun" + hardwareID = "Wintun" waitForRegistryTimeout = time.Second * 10 ) |