diff options
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() |