diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2019-05-17 16:06:02 +0200 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2019-05-17 16:06:02 +0200 |
commit | a6dbe4f4754de333a7ab4df6549d681edbb297fd (patch) | |
tree | 729056e339f5d90b1c806d2479a9667e0198bfa7 /tun/tun_windows.go | |
parent | c718f3940d6546f83cc14c4f121d52470a705c31 (diff) |
wintun: don't try to flush interface, but rather delete
Diffstat (limited to 'tun/tun_windows.go')
-rw-r--r-- | tun/tun_windows.go | 24 |
1 files changed, 8 insertions, 16 deletions
diff --git a/tun/tun_windows.go b/tun/tun_windows.go index 4ddf5fe..6215cc7 100644 --- a/tun/tun_windows.go +++ b/tun/tun_windows.go @@ -65,30 +65,22 @@ func CreateTUN(ifname string) (TUNDevice, error) { // 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 { + // If so, we delete it, in case it has weird residual configuration. + _, _, err = wt.DeleteInterface(0) if err != nil { - return nil, fmt.Errorf("wintun.CreateInterface: %v", err) + return nil, fmt.Errorf("Unable to delete already existing Wintun interface: %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) + wt, _, err = wintun.CreateInterface("WireGuard Tunnel Adapter", 0) if err != nil { - wt.DeleteInterface(0) - return nil, fmt.Errorf("wintun.SetInterfaceName: %v", err) + return nil, fmt.Errorf("Unable to create Wintun interface: %v", err) } - err = wt.FlushInterface() + err = wt.SetInterfaceName(ifname) if err != nil { wt.DeleteInterface(0) - return nil, fmt.Errorf("wintun.FlushInterface: %v", err) + return nil, fmt.Errorf("Unable to set name of Wintun interface: %v", err) } return &NativeTun{ |