diff --git a/network/network_windows.go b/network/network_windows.go index 9921af0..9b77fd2 100644 --- a/network/network_windows.go +++ b/network/network_windows.go @@ -3,10 +3,12 @@ package network import ( "context" "fmt" + "log" "net" "os" "os/exec" "path/filepath" + "time" ) func (network *Network) postConfigure(ctx context.Context, config *Config, tincBin string) error { @@ -21,6 +23,7 @@ func (network *Network) postConfigure(ctx context.Context, config *Config, tincB if iface.Name == config.Interface { return nil } + log.Println("Found interface:", iface.Name) interfaces[iface.Name] = true } @@ -41,16 +44,23 @@ func (network *Network) postConfigure(ctx context.Context, config *Config, tincB } // find new interface - list, err = net.Interfaces() - if err != nil { - return err - } - var newInterface string - for _, iface := range list { - if !interfaces[iface.Name] { - newInterface = iface.Name - break + for newInterface == "" { + log.Println("Looking for a new interface") + select { + case <-time.After(1 * time.Second): + case <-ctx.Done(): + } + list, err = net.Interfaces() + if err != nil { + return err + } + for _, iface := range list { + if !interfaces[iface.Name] { + newInterface = iface.Name + log.Println("New interface:", iface.Name) + break + } } } @@ -59,7 +69,7 @@ func (network *Network) postConfigure(ctx context.Context, config *Config, tincB } // rename - cmd = exec.CommandContext(ctx, "netsh", "interface", "set", "name", + cmd = exec.CommandContext(ctx, "netsh", "interface", "set", "interface", "name", "=", newInterface, "newname", "=", config.Interface) cmd.Stderr = os.Stderr cmd.Stdout = os.Stdout diff --git a/network/scripts_windows.go b/network/scripts_windows.go index b7370ef..1a7375e 100644 --- a/network/scripts_windows.go +++ b/network/scripts_windows.go @@ -3,17 +3,17 @@ package network const scriptSuffix = ".bat" const tincUpTxt = ` -netsh interface ipv4 set address name="%INTERFACE%" static {{.Subnet}} store=persistent +netsh interface ipv4 set address name=%INTERFACE% static {{.Subnet}} store=persistent ` const tincDownText = `` const subnetUpText = ` -{{.Executable}} subnet add && route add "$SUBNET" {{.Node.IP}} +{{.Executable}} subnet add && route add %SUBNET% {{.Node.IP}} ` const subnetDownText = ` -{{.Executable}} subnet remove && route delete "$SUBNET" +{{.Executable}} subnet remove && route delete %SUBNET% ` func postProcessScript(filename string) error { return nil } diff --git a/tincd/net.go b/tincd/net.go index 8f02e17..07fe4fe 100644 --- a/tincd/net.go +++ b/tincd/net.go @@ -6,6 +6,7 @@ import ( "log" "os" "os/exec" + "path/filepath" "sync" "time" "tinc-web-boot/network" @@ -95,14 +96,19 @@ func (impl *netImpl) run(global context.Context) error { return fmt.Errorf("configure: %w", err) } + absDir, err := filepath.Abs(impl.definition.Root) + if err != nil { + return err + } + ctx, abort := context.WithCancel(global) defer abort() cmd := exec.CommandContext(ctx, impl.tincBin, "-D", "-d", "-d", "-d", "--pidfile", impl.definition.Pidfile(), "--logfile", impl.definition.Logfile(), - "-c", ".") - cmd.Dir = impl.definition.Root + "-c", absDir) + cmd.Dir = absDir cmd.Stdout = os.Stdout cmd.Stderr = os.Stderr utils.SetCmdAttrs(cmd)