diff --git a/src/yggdrasil/tun_windows.go b/src/yggdrasil/tun_windows.go index edfe6817..005806ca 100644 --- a/src/yggdrasil/tun_windows.go +++ b/src/yggdrasil/tun_windows.go @@ -15,6 +15,28 @@ func (tun *tunDevice) setup(ifname string, addr string, mtu int) error { if err != nil { panic(err) } + // Disable/enable the interface to resets its configuration (invalidating iface) + cmd := exec.Command("netsh", "interface", "set", "interface", iface.Name(), "admin=DISABLED") + tun.core.log.Printf("netsh command: %v", strings.Join(cmd.Args, " ")) + output, err := cmd.CombinedOutput() + if err != nil { + tun.core.log.Printf("Windows netsh failed: %v.", err) + tun.core.log.Println(string(output)) + return err + } + cmd = exec.Command("netsh", "interface", "set", "interface", iface.Name(), "admin=ENABLED") + tun.core.log.Printf("netsh command: %v", strings.Join(cmd.Args, " ")) + output, err = cmd.CombinedOutput() + if err != nil { + tun.core.log.Printf("Windows netsh failed: %v.", err) + tun.core.log.Println(string(output)) + return err + } + // Get a new iface + iface, err = water.New(config) + if err != nil { + panic(err) + } tun.iface = iface tun.mtu = mtu return tun.setupAddress(addr) @@ -23,9 +45,10 @@ func (tun *tunDevice) setup(ifname string, addr string, mtu int) error { func (tun *tunDevice) setupAddress(addr string) error { // Set address // addr = strings.TrimRight(addr, "/8") - cmd := exec.Command("netsh", "interface", "ipv6", "set", "address", + cmd := exec.Command("netsh", "interface", "ipv6", "add", "address", fmt.Sprintf("interface=%s", tun.iface.Name()), - fmt.Sprintf("addr=%s", addr)) + fmt.Sprintf("addr=%s", addr), + "store=active") tun.core.log.Printf("netsh command: %v", strings.Join(cmd.Args, " ")) output, err := cmd.CombinedOutput() if err != nil {