5
0
mirror of https://github.com/cwinfo/yggdrasil-go.git synced 2024-11-10 06:20:26 +00:00

Fix resetting Windows adapter (reverting previous change)

This commit is contained in:
Neil Alexander 2019-07-20 11:43:30 +01:00
parent 2aa57750a6
commit 2582df752d
No known key found for this signature in database
GPG Key ID: A02A2019A2BB0944

View File

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