]> git.ipfire.org Git - thirdparty/wireguard-go.git/commitdiff
tun: windows: never retry open on Windows 10
authorJason A. Donenfeld <Jason@zx2c4.com>
Tue, 18 Jun 2019 14:08:28 +0000 (16:08 +0200)
committerJason A. Donenfeld <Jason@zx2c4.com>
Tue, 18 Jun 2019 15:51:29 +0000 (17:51 +0200)
go.mod
go.sum
tun/tun_windows.go
tun/wintun/wintun_windows.go

diff --git a/go.mod b/go.mod
index 64042c9389e559c10c6b6b5515aa9a73fdd3d763..5c37b809aebf875c0227174641a88440256a6d04 100644 (file)
--- a/go.mod
+++ b/go.mod
@@ -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
 )
diff --git a/go.sum b/go.sum
index c645ad2d568c831a7fce2c4c84807411a036fca3..fbaac9a209cb70feb081cb043f548566bd88ee02 100644 (file)
--- a/go.sum
+++ b/go.sum
@@ -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=
index b88129d0c265e56583c0880ea80d3e5239a2519f..05fc3dff25548dbb110fedb2ba29941d6a81336c 100644 (file)
@@ -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.
index 281ab375e31092a6782a815702d576e9d88b7136..b8aabf39159d25b246d5632da514120a2941baf1 100644 (file)
@@ -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
 )