delete postup/down from wg.conf file when gateway is removed

This commit is contained in:
Matthew R. Kasun
2022-08-31 15:29:33 -04:00
parent e49dcc0796
commit 03c2c5ae1e
3 changed files with 37 additions and 33 deletions

View File

@@ -109,7 +109,6 @@ func NodeUpdate(client mqtt.Client, msg mqtt.Message) {
} }
file := ncutils.GetNetclientPathSpecific() + nodeCfg.Node.Interface + ".conf" file := ncutils.GetNetclientPathSpecific() + nodeCfg.Node.Interface + ".conf"
if ifaceDelta { // if a change caused an ifacedelta we need to notify the server to update the peers
if newNode.ListenPort != nodeCfg.Node.LocalListenPort { if newNode.ListenPort != nodeCfg.Node.LocalListenPort {
if err := wireguard.RemoveConf(newNode.Interface, false); err != nil { if err := wireguard.RemoveConf(newNode.Interface, false); err != nil {
logger.Log(0, "error remove interface", newNode.Interface, err.Error()) logger.Log(0, "error remove interface", newNode.Interface, err.Error())
@@ -119,6 +118,7 @@ func NodeUpdate(client mqtt.Client, msg mqtt.Message) {
logger.Log(0, "network:", nodeCfg.Node.Network, "error modifying node port on", newNode.Name, "-", err.Error()) logger.Log(0, "network:", nodeCfg.Node.Network, "error modifying node port on", newNode.Name, "-", err.Error())
return return
} }
ifaceDelta = true
informPortChange(&newNode) informPortChange(&newNode)
} }
if err := wireguard.UpdateWgInterface(file, privateKey, nameserver, newNode); err != nil { if err := wireguard.UpdateWgInterface(file, privateKey, nameserver, newNode); err != nil {
@@ -147,6 +147,7 @@ func NodeUpdate(client mqtt.Client, msg mqtt.Message) {
// } // }
// } // }
// } // }
if ifaceDelta { // if a change caused an ifacedelta we need to notify the server to update the peers
doneErr := publishSignal(&nodeCfg, ncutils.DONE) doneErr := publishSignal(&nodeCfg, ncutils.DONE)
if doneErr != nil { if doneErr != nil {
logger.Log(0, "network:", nodeCfg.Node.Network, "could not notify server to update peers after interface change") logger.Log(0, "network:", nodeCfg.Node.Network, "could not notify server to update peers after interface change")

View File

@@ -23,6 +23,8 @@ func IfaceDelta(currentNode *models.Node, newNode *models.Node) bool {
newNode.PersistentKeepalive != currentNode.PersistentKeepalive || newNode.PersistentKeepalive != currentNode.PersistentKeepalive ||
newNode.DNSOn != currentNode.DNSOn || newNode.DNSOn != currentNode.DNSOn ||
newNode.Connected != currentNode.Connected || newNode.Connected != currentNode.Connected ||
newNode.PostUp != currentNode.PostUp ||
newNode.PostDown != currentNode.PostDown ||
len(newNode.AllowedIPs) != len(currentNode.AllowedIPs) { len(newNode.AllowedIPs) != len(currentNode.AllowedIPs) {
return true return true
} }

View File

@@ -443,6 +443,7 @@ func UpdateWgInterface(file, privateKey, nameserver string, node models.Node) er
if node.UDPHolePunch == "yes" { if node.UDPHolePunch == "yes" {
node.ListenPort = 0 node.ListenPort = 0
} }
wireguard.DeleteSection(section_interface)
wireguard.Section(section_interface).Key("PrivateKey").SetValue(privateKey) wireguard.Section(section_interface).Key("PrivateKey").SetValue(privateKey)
wireguard.Section(section_interface).Key("ListenPort").SetValue(strconv.Itoa(int(node.ListenPort))) wireguard.Section(section_interface).Key("ListenPort").SetValue(strconv.Itoa(int(node.ListenPort)))
addrString := node.Address addrString := node.Address