diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2019-06-10 11:10:49 +0200 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2019-06-10 11:10:49 +0200 |
commit | 700860f8e697b187a7bbd7b226469a1de0818456 (patch) | |
tree | a456fde9cb0ffeb73ddbe9ea47e681f277dd37f0 | |
parent | a304f69e0dde3984b131d1cf29d22f19b4e5e083 (diff) |
wintun: simplify error matching and remove dumb comments
-rw-r--r-- | tun/wintun/wintun_windows.go | 23 |
1 files changed, 4 insertions, 19 deletions
diff --git a/tun/wintun/wintun_windows.go b/tun/wintun/wintun_windows.go index e5b768e..7b7a889 100644 --- a/tun/wintun/wintun_windows.go +++ b/tun/wintun/wintun_windows.go @@ -94,23 +94,20 @@ func GetInterface(ifname string) (*Wintun, error) { ifname = strings.ToLower(ifname) for index := 0; ; index++ { - // Get the device from the list. Should anything be wrong with this device, continue with next. deviceData, err := devInfoList.EnumDeviceInfo(index) if err != nil { - if errWin, ok := err.(windows.Errno); ok && errWin == windows.ERROR_NO_MORE_ITEMS { + if err == windows.ERROR_NO_MORE_ITEMS { break } continue } - // Get interface ID. wintun, err := makeWintun(devInfoList, deviceData) if err != nil { continue } // TODO: is there a better way than comparing ifnames? - // Get interface name. ifname2, err := wintun.InterfaceName() if err != nil { continue @@ -126,25 +123,21 @@ func GetInterface(ifname string) (*Wintun, error) { defer devInfoList.DestroyDriverInfoList(deviceData, driverType) for index := 0; ; index++ { - // Get a driver from the list. driverData, err := devInfoList.EnumDriverInfo(deviceData, driverType, index) if err != nil { - if errWin, ok := err.(windows.Errno); ok && errWin == windows.ERROR_NO_MORE_ITEMS { + if err == windows.ERROR_NO_MORE_ITEMS { break } - // Something is wrong with this driver. Skip it. continue } // Get driver info details. driverDetailData, err := devInfoList.DriverInfoDetail(deviceData, driverData) if err != nil { - // Something is wrong with this driver. Skip it. continue } if driverDetailData.IsCompatible(hardwareID) { - // Matching hardware ID found. return wintun, nil } } @@ -204,7 +197,6 @@ func CreateInterface(description string, requestedGUID *windows.GUID) (wintun *W return nil, false, fmt.Errorf("SetupDiSetDeviceRegistryProperty(SPDRP_HARDWAREID) failed: %v", err) } - // Search for the driver. const driverType = setupapi.SPDIT_COMPATDRIVER err = devInfoList.BuildDriverInfoList(deviceData, driverType) // TODO: This takes ~510ms if err != nil { @@ -215,30 +207,24 @@ func CreateInterface(description string, requestedGUID *windows.GUID) (wintun *W driverDate := windows.Filetime{} driverVersion := uint64(0) for index := 0; ; index++ { // TODO: This loop takes ~600ms - // Get a driver from the list. driverData, err := devInfoList.EnumDriverInfo(deviceData, driverType, index) if err != nil { - if errWin, ok := err.(windows.Errno); ok && errWin == windows.ERROR_NO_MORE_ITEMS { + if err == windows.ERROR_NO_MORE_ITEMS { break } - // Something is wrong with this driver. Skip it. continue } // Check the driver version first, since the check is trivial and will save us iterating over hardware IDs for any driver versioned prior our best match. if driverData.IsNewer(driverDate, driverVersion) { - // Get driver info details. driverDetailData, err := devInfoList.DriverInfoDetail(deviceData, driverData) if err != nil { - // Something is wrong with this driver. Skip it. continue } if driverDetailData.IsCompatible(hardwareID) { - // Matching hardware ID found. Select the driver. err := devInfoList.SetSelectedDriver(deviceData, driverData) if err != nil { - // Something is wrong with this driver. Skip it. continue } @@ -521,10 +507,9 @@ func (wintun *Wintun) deviceData() (setupapi.DevInfo, *setupapi.DevInfoData, err } for index := 0; ; index++ { - // Get the device from the list. Should anything be wrong with this device, continue with next. deviceData, err := devInfoList.EnumDeviceInfo(index) if err != nil { - if errWin, ok := err.(windows.Errno); ok && errWin == windows.ERROR_NO_MORE_ITEMS { + if err == windows.ERROR_NO_MORE_ITEMS { break } continue |