mirror of
https://github.com/cwinfo/yggdrasil-go.git
synced 2024-11-26 20:01:38 +00:00
Fix resetting Windows adapter (reverting previous change)
This commit is contained in:
parent
2aa57750a6
commit
2582df752d
@ -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)
|
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
|
// 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
|
return err
|
||||||
}
|
}
|
||||||
// Get a new iface
|
// Get a new iface
|
||||||
@ -55,29 +69,6 @@ func (tun *TunAdapter) setup(ifname string, iftapmode bool, addr string, mtu int
|
|||||||
return tun.setupAddress(addr)
|
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.
|
// Sets the MTU of the TAP adapter.
|
||||||
func (tun *TunAdapter) setupMTU(mtu int) error {
|
func (tun *TunAdapter) setupMTU(mtu int) error {
|
||||||
// Set MTU
|
// Set MTU
|
||||||
|
Loading…
Reference in New Issue
Block a user