aboutsummaryrefslogtreecommitdiffstats
path: root/tun/tun_windows.go
diff options
context:
space:
mode:
authorSimon Rozman <simon@rozman.si>2019-05-09 10:11:15 +0200
committerJason A. Donenfeld <Jason@zx2c4.com>2019-05-10 16:43:58 +0200
commit7e962a9932667f4a161b20aba5ff1c75ab8e578a (patch)
tree212eb2c6bc55db43c0b982b71195fc3ec61ce659 /tun/tun_windows.go
parentconn: remove scope when sanity checking IP address format (diff)
downloadwireguard-go-7e962a9932667f4a161b20aba5ff1c75ab8e578a.tar.xz
wireguard-go-7e962a9932667f4a161b20aba5ff1c75ab8e578a.zip
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.go40
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()