diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2019-06-18 16:08:28 +0200 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2019-06-18 17:51:29 +0200 |
commit | c69d02664924e11ffc5e6728638216a26b81c4ce (patch) | |
tree | caec0bf19c41c8b120028d976e9683f318f19f65 | |
parent | 1f48971a80f48257e478e532f6971d0557026120 (diff) |
tun: windows: never retry open on Windows 10
-rw-r--r-- | go.mod | 6 | ||||
-rw-r--r-- | go.sum | 12 | ||||
-rw-r--r-- | tun/tun_windows.go | 15 | ||||
-rw-r--r-- | tun/wintun/wintun_windows.go | 2 |
4 files changed, 22 insertions, 13 deletions
@@ -3,7 +3,7 @@ module golang.zx2c4.com/wireguard go 1.12 require ( - golang.org/x/crypto v0.0.0-20190513172903-22d7a77e9e5f - golang.org/x/net v0.0.0-20190522155817-f3200d17e092 - golang.org/x/sys v0.0.0-20190606203320-7fc4e5ec1444 + golang.org/x/crypto v0.0.0-20190617133340-57b3e21c3d56 + golang.org/x/net v0.0.0-20190613194153-d28f0bde5980 + golang.org/x/sys v0.0.0-20190618155005-516e3c20635f ) @@ -1,11 +1,11 @@ golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/crypto v0.0.0-20190513172903-22d7a77e9e5f h1:R423Cnkcp5JABoeemiGEPlt9tHXFfw5kvc0yqlxRPWo= -golang.org/x/crypto v0.0.0-20190513172903-22d7a77e9e5f/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20190617133340-57b3e21c3d56 h1:ZpKuNIejY8P0ExLOVyKhb0WsgG8UdvHXe6TWjY7eL6k= +golang.org/x/crypto v0.0.0-20190617133340-57b3e21c3d56/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/net v0.0.0-20190522155817-f3200d17e092 h1:4QSRKanuywn15aTZvI/mIDEgPQpswuFndXpOj3rKEco= -golang.org/x/net v0.0.0-20190522155817-f3200d17e092/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks= +golang.org/x/net v0.0.0-20190613194153-d28f0bde5980 h1:dfGZHvZk057jK2MCeWus/TowKpJ8y4AmooUzdBSR9GU= +golang.org/x/net v0.0.0-20190613194153-d28f0bde5980/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20190606203320-7fc4e5ec1444 h1:/d2cWp6PSamH4jDPFLyO150psQdqvtoNX8Zjg3AQ31g= -golang.org/x/sys v0.0.0-20190606203320-7fc4e5ec1444/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190618155005-516e3c20635f h1:dHNZYIYdq2QuU6w73vZ/DzesPbVlZVYZTtTZmrnsbQ8= +golang.org/x/sys v0.0.0-20190618155005-516e3c20635f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= 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 ) |