diff --git a/src/tuntap/tun_windows.go b/src/tuntap/tun_windows.go index 98508efd..d46b7e5b 100644 --- a/src/tuntap/tun_windows.go +++ b/src/tuntap/tun_windows.go @@ -34,7 +34,21 @@ func (tun *TunAdapter) setup(ifname string, iftapmode bool, addr string, mtu int return errors.New("unable to find TAP adapter with component ID " + config.PlatformSpecificParams.ComponentID) } // Reset the adapter - this invalidates iface so we'll need to get a new one - if err := tun.resetAdapter(); err != nil { + cmd := exec.Command("netsh", "interface", "set", "interface", iface.Name(), "admin=DISABLED") + tun.log.Debugln("netsh command:", strings.Join(cmd.Args, " ")) + output, err := cmd.CombinedOutput() + if err != nil { + tun.log.Errorln("Windows netsh failed:", err) + tun.log.Traceln(string(output)) + return err + } + // Bring the interface back up + cmd = exec.Command("netsh", "interface", "set", "interface", iface.Name(), "admin=ENABLED") + tun.log.Debugln("netsh command:", strings.Join(cmd.Args, " ")) + output, err = cmd.CombinedOutput() + if err != nil { + tun.log.Errorln("Windows netsh failed:", err) + tun.log.Traceln(string(output)) return err } // Get a new iface @@ -55,29 +69,6 @@ func (tun *TunAdapter) setup(ifname string, iftapmode bool, addr string, mtu int return tun.setupAddress(addr) } -// Disable/enable the interface to reset its configuration (invalidating iface). -func (tun *TunAdapter) resetAdapter() error { - // Bring down the interface first - cmd := exec.Command("netsh", "interface", "set", "interface", tun.iface.Name(), "admin=DISABLED") - tun.log.Debugln("netsh command:", strings.Join(cmd.Args, " ")) - output, err := cmd.CombinedOutput() - if err != nil { - tun.log.Errorln("Windows netsh failed:", err) - tun.log.Traceln(string(output)) - return err - } - // Bring the interface back up - cmd = exec.Command("netsh", "interface", "set", "interface", tun.iface.Name(), "admin=ENABLED") - tun.log.Debugln("netsh command:", strings.Join(cmd.Args, " ")) - output, err = cmd.CombinedOutput() - if err != nil { - tun.log.Errorln("Windows netsh failed:", err) - tun.log.Traceln(string(output)) - return err - } - return nil -} - // Sets the MTU of the TAP adapter. func (tun *TunAdapter) setupMTU(mtu int) error { // Set MTU