added better handling of wg ifaces on windows + fix connect issue

This commit is contained in:
0xdcarns 2022-10-13 11:30:21 -04:00
parent 4af1823614
commit 3b1ff49344
5 changed files with 10 additions and 10 deletions

View file

@ -97,7 +97,11 @@ func UpdateNode(client mqtt.Client, msg mqtt.Message) {
logger.Log(1, "error saving node", err.Error())
return
}
updateNodePeers(&currentNode)
if ifaceDelta { // reduce number of unneeded updates, by only sending on iface changes
if err = PublishPeerUpdate(&currentNode, true); err != nil {
logger.Log(0, "error updating peers when node", currentNode.Name, currentNode.ID, "informed the server of an interface change", err.Error())
}
}
logger.Log(1, "updated node", id, newNode.Name)
}()
}

View file

@ -129,9 +129,6 @@ func NodeUpdate(client mqtt.Client, msg mqtt.Message) {
wireguard.UpdateKeepAlive(file, newNode.PersistentKeepalive)
}
logger.Log(0, "applying WG conf to "+file)
if ncutils.IsWindows() {
wireguard.RemoveConfGraceful(nodeCfg.Node.Interface)
}
err = wireguard.ApplyConf(&nodeCfg.Node, nodeCfg.Node.Interface, file)
if err != nil {
logger.Log(0, "error restarting wg after node update -", err.Error())
@ -227,9 +224,6 @@ func UpdatePeers(client mqtt.Client, msg mqtt.Message) {
if err := config.ModNodeConfig(&cfg.Node); err != nil {
logger.Log(0, "failed to save internet gateway", err.Error())
}
if ncutils.IsWindows() {
wireguard.RemoveConfGraceful(cfg.Node.Interface)
}
if err := wireguard.ApplyConf(&cfg.Node, cfg.Node.Interface, file); err != nil {
logger.Log(0, "error applying internet gateway", err.Error())
}

View file

@ -277,7 +277,7 @@ func ApplyConf(node *models.Node, ifacename string, confPath string) error {
var err error
switch os {
case "windows":
ApplyWindowsConf(confPath, isConnected)
ApplyWindowsConf(confPath, ifacename, isConnected)
case "nowgquick":
ApplyWithoutWGQuick(node, ifacename, confPath, isConnected)
default:

View file

@ -11,7 +11,7 @@ import (
// ApplyWGQuickConf - applies wg-quick commands if os supports
func ApplyWGQuickConf(confPath, ifacename string, isConnected bool) error {
if ncutils.IsWindows() {
return ApplyWindowsConf(confPath, isConnected)
return ApplyWindowsConf(confPath, ifacename, isConnected)
} else {
_, err := os.Stat(confPath)
if err != nil {

View file

@ -8,7 +8,9 @@ import (
)
// ApplyWindowsConf - applies the WireGuard configuration file on Windows
func ApplyWindowsConf(confPath string, isConnected bool) error {
func ApplyWindowsConf(confPath, iface string, isConnected bool) error {
RemoveConfGraceful(iface) // have to remove gracefully before applying windows conf
if !isConnected {
return nil
}