aboutsummaryrefslogtreecommitdiffstats
path: root/tun/wintun/wintun_windows.go
diff options
context:
space:
mode:
authorAvery Pennarun <apenwarr@gmail.com>2019-04-05 02:26:40 -0400
committerJason A. Donenfeld <Jason@zx2c4.com>2019-10-17 15:19:20 +0200
commitc85e4a410f27986a2967a49c0155633c716bf3ca (patch)
treea854070549a114ba3e9522269872e4e6dd8b0812 /tun/wintun/wintun_windows.go
parenttun: match windows CreateTUN signature to the Linux variant (diff)
downloadwireguard-go-c85e4a410f27986a2967a49c0155633c716bf3ca.tar.xz
wireguard-go-c85e4a410f27986a2967a49c0155633c716bf3ca.zip
wintun: quickly ignore non-Wintun devices
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]
Diffstat (limited to 'tun/wintun/wintun_windows.go')
-rw-r--r--tun/wintun/wintun_windows.go18
1 files changed, 18 insertions, 0 deletions
diff --git a/tun/wintun/wintun_windows.go b/tun/wintun/wintun_windows.go
index e6dc141..a49242f 100644
--- a/tun/wintun/wintun_windows.go
+++ b/tun/wintun/wintun_windows.go
@@ -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