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>
This commit is contained in:
Simon Rozman
2019-05-09 10:11:15 +02:00
committed by Jason A. Donenfeld
parent 586112b5d7
commit 7e962a9932
7 changed files with 535 additions and 134 deletions

View File

@@ -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()