summaryrefslogtreecommitdiffhomepage
path: root/tun
diff options
context:
space:
mode:
authorSimon Rozman <simon@rozman.si>2019-08-02 15:48:41 +0200
committerSimon Rozman <simon@rozman.si>2019-08-02 16:08:49 +0200
commit1ff37e2b0706143c5da7131ae13f45d0d1882344 (patch)
tree336e9487a122aa38b01397e72cb2d6ca1ccb8c3a /tun
parentf5e54932e600ca94ef498a6f98c73c184979533b (diff)
wintun: merge opening device registry key
This also introduces waiting for key to appear on initial access. See if this resolves the issue caused by HDD power-up delay resulting in failure to create the adapter. Signed-off-by: Simon Rozman <simon@rozman.si>
Diffstat (limited to 'tun')
-rw-r--r--tun/wintun/wintun_windows.go36
1 files changed, 15 insertions, 21 deletions
diff --git a/tun/wintun/wintun_windows.go b/tun/wintun/wintun_windows.go
index 7550263..55d4ed0 100644
--- a/tun/wintun/wintun_windows.go
+++ b/tun/wintun/wintun_windows.go
@@ -262,14 +262,23 @@ func CreateInterface(description string, requestedGUID *windows.GUID) (wintun *W
devInfoList.CallClassInstaller(setupapi.DIF_REGISTER_COINSTALLERS, deviceData)
var key registry.Key
- if requestedGUID != nil {
- key, err = devInfoList.OpenDevRegKey(deviceData, setupapi.DICS_FLAG_GLOBAL, 0, setupapi.DIREG_DRV, registry.SET_VALUE)
- if err != nil {
- err = fmt.Errorf("OpenDevRegKey failed: %v", err)
- return
+ const pollTimeout = time.Millisecond * 50
+ for i := 0; i < int(waitForRegistryTimeout/pollTimeout); i++ {
+ if i != 0 {
+ time.Sleep(pollTimeout)
+ }
+ key, err = devInfoList.OpenDevRegKey(deviceData, setupapi.DICS_FLAG_GLOBAL, 0, setupapi.DIREG_DRV, registry.SET_VALUE|registry.QUERY_VALUE|registry.NOTIFY)
+ if err == nil {
+ break
}
+ }
+ if err != nil {
+ err = fmt.Errorf("SetupDiOpenDevRegKey failed: %v", err)
+ return
+ }
+ defer key.Close()
+ if requestedGUID != nil {
err = key.SetStringValue("NetSetupAnticipatedInstanceId", requestedGUID.String())
- key.Close()
if err != nil {
err = fmt.Errorf("SetStringValue(NetSetupAnticipatedInstanceId) failed: %v", err)
return
@@ -309,21 +318,6 @@ func CreateInterface(description string, requestedGUID *windows.GUID) (wintun *W
// DIF_INSTALLDEVICE returns almost immediately, while the device installation
// continues in the background. It might take a while, before all registry
// keys and values are populated.
- const pollTimeout = time.Millisecond * 50
- for i := 0; i < int(waitForRegistryTimeout/pollTimeout); i++ {
- if i != 0 {
- time.Sleep(pollTimeout)
- }
- key, err = devInfoList.OpenDevRegKey(deviceData, setupapi.DICS_FLAG_GLOBAL, 0, setupapi.DIREG_DRV, registry.QUERY_VALUE|registry.NOTIFY)
- if err == nil {
- break
- }
- }
- if err != nil {
- err = fmt.Errorf("SetupDiOpenDevRegKey failed: %v", err)
- return
- }
- defer key.Close()
_, err = registryEx.GetStringValueWait(key, "NetCfgInstanceId", waitForRegistryTimeout)
if err != nil {
err = fmt.Errorf("GetStringValueWait(NetCfgInstanceId) failed: %v", err)