diff options
author | Simon Rozman <simon@rozman.si> | 2019-05-09 10:11:15 +0200 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2019-05-10 16:43:58 +0200 |
commit | 7e962a9932667f4a161b20aba5ff1c75ab8e578a (patch) | |
tree | 212eb2c6bc55db43c0b982b71195fc3ec61ce659 /tun/tun_windows.go | |
parent | 586112b5d78abc99c9858c9a9a40756d5854d311 (diff) |
wintun: wait for interface registry key on device creation
By using RegNotifyChangeKeyValue(). Also disable dead gateway detection.
Signed-off-by: Simon Rozman <simon@rozman.si>
Diffstat (limited to 'tun/tun_windows.go')
-rw-r--r-- | tun/tun_windows.go | 40 |
1 files changed, 16 insertions, 24 deletions
diff --git a/tun/tun_windows.go b/tun/tun_windows.go index b319c27..8218fc3 100644 --- a/tun/tun_windows.go +++ b/tun/tun_windows.go @@ -62,35 +62,27 @@ func packetAlign(size uint32) uint32 { func CreateTUN(ifname string) (TUNDevice, error) { var err error var wt *wintun.Wintun - for i := 0; i < 3; i++ { - // Does an interface with this name already exist? - wt, err = wintun.GetInterface(ifname, 0) - if wt == nil { - // Interface does not exist or an error occured. Create one. - wt, _, err = wintun.CreateInterface("WireGuard Tunnel Adapter", 0) - if err != nil { - err = fmt.Errorf("wintun.CreateInterface: %v", err) - continue - } - } else if err != nil { - // Foreign interface with the same name found. - // We could create a Wintun interface under a temporary name. But, should our - // process die without deleting this interface first, the interface would remain - // orphaned. - err = fmt.Errorf("wintun.GetInterface: %v", err) - continue - } - err = wt.SetInterfaceName(ifname) //TODO: This is the function that most often fails + // Does an interface with this name already exist? + wt, err = wintun.GetInterface(ifname, 0) + if wt == nil { + // Interface does not exist or an error occurred. Create one. + wt, _, err = wintun.CreateInterface("WireGuard Tunnel Adapter", 0) if err != nil { - wt.DeleteInterface(0) - wt = nil - err = fmt.Errorf("wintun.SetInterfaceName: %v", err) - continue + return nil, fmt.Errorf("wintun.CreateInterface: %v", err) } + } else if err != nil { + // Foreign interface with the same name found. + // We could create a Wintun interface under a temporary name. But, should our + // process die without deleting this interface first, the interface would remain + // orphaned. + return nil, fmt.Errorf("wintun.GetInterface: %v", err) } + + err = wt.SetInterfaceName(ifname) if err != nil { - return nil, err + wt.DeleteInterface(0) + return nil, fmt.Errorf("wintun.SetInterfaceName: %v", err) } err = wt.FlushInterface() |