mirror of
https://github.com/yggdrasil-network/yggdrasil-go.git
synced 2025-04-28 22:25:07 +03:00
Update Windows module a bit - capture TAP setup errors earlier, refer to newer version of water which should fix #456
This commit is contained in:
parent
85881c04fa
commit
1a5c2a4942
3 changed files with 48 additions and 20 deletions
|
@ -1,6 +1,7 @@
|
|||
package tuntap
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"os/exec"
|
||||
"strings"
|
||||
|
@ -27,23 +28,13 @@ func (tun *TunAdapter) setup(ifname string, iftapmode bool, addr string, mtu int
|
|||
}
|
||||
iface, err := water.New(config)
|
||||
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.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
|
||||
}
|
||||
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))
|
||||
if iface.Name() == "" {
|
||||
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 {
|
||||
return err
|
||||
}
|
||||
// Get a new iface
|
||||
|
@ -64,6 +55,29 @@ 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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue