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]
This commit is contained in:
parent
1b6c8ddbe8
commit
c85e4a410f
|
@ -131,6 +131,15 @@ func (pool Pool) GetInterface(ifname string) (*Interface, error) {
|
||||||
continue
|
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)
|
wintun, err := makeWintun(devInfoList, deviceData, pool)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
continue
|
continue
|
||||||
|
@ -494,6 +503,15 @@ func (pool Pool) DeleteMatchingInterfaces(matches func(wintun *Interface) bool)
|
||||||
continue
|
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)
|
err = devInfoList.BuildDriverInfoList(deviceData, setupapi.SPDIT_COMPATDRIVER)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
continue
|
continue
|
||||||
|
|
Loading…
Reference in a new issue