]> git.ipfire.org Git - thirdparty/wireguard-go.git/commitdiff
wintun: quickly ignore non-Wintun devices
authorAvery Pennarun <apenwarr@gmail.com>
Fri, 5 Apr 2019 06:26:40 +0000 (02:26 -0400)
committerJason A. Donenfeld <Jason@zx2c4.com>
Thu, 17 Oct 2019 13:19:20 +0000 (15:19 +0200)
Some devices take ~2 seconds to enumerate on Windows if we try to get
their instance name.  The hardware id property, on the other hand,
is available right away.

Signed-off-by: Avery Pennarun <apenwarr@gmail.com>
[zx2c4: inlined this to where it makes sense, reused setupapi const]

tun/wintun/wintun_windows.go

index e6dc141c9409caf6507f9b9133897b16893eb659..a49242f45e9b3326d8b990f8e7043842b3978ba0 100644 (file)
@@ -131,6 +131,15 @@ func (pool Pool) GetInterface(ifname string) (*Interface, error) {
                        continue
                }
 
+               // Check the Hardware ID to make sure it's a real Wintun device first. This avoids doing slow operations on non-Wintun devices.
+               property, err := devInfoList.DeviceRegistryProperty(deviceData, setupapi.SPDRP_HARDWAREID)
+               if err != nil {
+                       continue
+               }
+               if hwids, ok := property.([]string); ok && len(hwids) > 0 && hwids[0] != hardwareID {
+                       continue
+               }
+
                wintun, err := makeWintun(devInfoList, deviceData, pool)
                if err != nil {
                        continue
@@ -494,6 +503,15 @@ func (pool Pool) DeleteMatchingInterfaces(matches func(wintun *Interface) bool)
                        continue
                }
 
+               // Check the Hardware ID to make sure it's a real Wintun device first. This avoids doing slow operations on non-Wintun devices.
+               property, err := devInfoList.DeviceRegistryProperty(deviceData, setupapi.SPDRP_HARDWAREID)
+               if err != nil {
+                       continue
+               }
+               if hwids, ok := property.([]string); ok && len(hwids) > 0 && hwids[0] != hardwareID {
+                       continue
+               }
+
                err = devInfoList.BuildDriverInfoList(deviceData, setupapi.SPDIT_COMPATDRIVER)
                if err != nil {
                        continue