aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Rozman <simon@rozman.si>2020-05-03 07:56:28 +0200
committerSimon Rozman <simon@rozman.si>2020-06-30 08:16:28 +0200
commit60ddf1ac3e266cd3a26305a7e0b25006a10566d8 (patch)
treeff56eee1145caedb7807aac9784473c3e5b7f68d
parentdevice: export Bind and remove socketfd shims for android (diff)
downloadwireguard-go-60ddf1ac3e266cd3a26305a7e0b25006a10566d8.tar.xz
wireguard-go-60ddf1ac3e266cd3a26305a7e0b25006a10566d8.zip
wintun: remove excessive driver validation when enumerating adapterssr/master
c85e4a410f27986a2967a49c0155633c716bf3ca introduced simple and fast preliminary network adapter device hardware ID check to speed up Wintun adapter enumeration. This check preceded a full fledged SetupAPI driver validation which initially verified the driver is installed in the driver store and the hardware ID is "Wintun". Assuming the quick check verifies the hardware ID reliably and the validation the driver is installed in the driver store is not really necessary, this commit removes now excessive and timely expensive driver validation. Signed-off-by: Simon Rozman <simon@rozman.si>
-rw-r--r--tun/wintun/wintun_windows.go68
1 files changed, 7 insertions, 61 deletions
diff --git a/tun/wintun/wintun_windows.go b/tun/wintun/wintun_windows.go
index eed4f01..9afd2f8 100644
--- a/tun/wintun/wintun_windows.go
+++ b/tun/wintun/wintun_windows.go
@@ -154,42 +154,14 @@ func (pool Pool) GetInterface(ifname string) (*Interface, error) {
ifname3 := removeNumberedSuffix(ifname2)
if ifname == ifname2 || ifname == ifname3 {
- err = devInfo.BuildDriverInfoList(devInfoData, setupapi.SPDIT_COMPATDRIVER)
+ isMember, err := pool.isMember(devInfo, devInfoData)
if err != nil {
- return nil, fmt.Errorf("SetupDiBuildDriverInfoList failed: %v", err)
+ return nil, err
}
- defer devInfo.DestroyDriverInfoList(devInfoData, setupapi.SPDIT_COMPATDRIVER)
-
- for index := 0; ; index++ {
- driverData, err := devInfo.EnumDriverInfo(devInfoData, setupapi.SPDIT_COMPATDRIVER, index)
- if err != nil {
- if err == windows.ERROR_NO_MORE_ITEMS {
- break
- }
- continue
- }
-
- // Get driver info details.
- driverDetailData, err := devInfo.DriverInfoDetail(devInfoData, driverData)
- if err != nil {
- continue
- }
-
- if driverDetailData.IsCompatible(hardwareID) {
- isMember, err := pool.isMember(devInfo, devInfoData)
- if err != nil {
- return nil, err
- }
- if !isMember {
- return nil, windows.ERROR_ALREADY_EXISTS
- }
-
- return wintun, nil
- }
+ if !isMember {
+ return nil, windows.ERROR_ALREADY_EXISTS
}
-
- // This interface is not using Wintun driver.
- return nil, windows.ERROR_ALREADY_EXISTS
+ return wintun, nil
}
}
@@ -512,34 +484,6 @@ func (pool Pool) DeleteMatchingInterfaces(matches func(wintun *Interface) bool)
continue
}
- err = devInfo.BuildDriverInfoList(devInfoData, setupapi.SPDIT_COMPATDRIVER)
- if err != nil {
- continue
- }
- defer devInfo.DestroyDriverInfoList(devInfoData, setupapi.SPDIT_COMPATDRIVER)
-
- isWintun := false
- for j := 0; ; j++ {
- driverData, err := devInfo.EnumDriverInfo(devInfoData, setupapi.SPDIT_COMPATDRIVER, j)
- if err != nil {
- if err == windows.ERROR_NO_MORE_ITEMS {
- break
- }
- continue
- }
- driverDetailData, err := devInfo.DriverInfoDetail(devInfoData, driverData)
- if err != nil {
- continue
- }
- if driverDetailData.IsCompatible(hardwareID) {
- isWintun = true
- break
- }
- }
- if !isWintun {
- continue
- }
-
isMember, err := pool.isMember(devInfo, devInfoData)
if err != nil {
errors = append(errors, err)
@@ -802,6 +746,8 @@ func (wintun *Interface) LUID() uint64 {
return ((uint64(wintun.luidIndex) & ((1 << 24) - 1)) << 24) | ((uint64(wintun.ifType) & ((1 << 16) - 1)) << 48)
}
+// isOurHardwareID tests SPDRP_HARDWAREID device registry property against expected hardware ID
+// string.
func isOurHardwareID(property interface{}) bool {
hwidLC := strings.ToLower(hardwareID)