mirror of
https://github.com/gravitl/netmaker.git
synced 2025-10-05 16:57:51 +08:00
Merge pull request #929 from gravitl/bugfix_v0.12.0_keepalive
keepalive handling updates
This commit is contained in:
@@ -283,7 +283,7 @@ func (newNode *Node) Fill(currentNode *Node) {
|
|||||||
if newNode.AllowedIPs == nil {
|
if newNode.AllowedIPs == nil {
|
||||||
newNode.AllowedIPs = currentNode.AllowedIPs
|
newNode.AllowedIPs = currentNode.AllowedIPs
|
||||||
}
|
}
|
||||||
if newNode.PersistentKeepalive == 0 {
|
if newNode.PersistentKeepalive < 0 {
|
||||||
newNode.PersistentKeepalive = currentNode.PersistentKeepalive
|
newNode.PersistentKeepalive = currentNode.PersistentKeepalive
|
||||||
}
|
}
|
||||||
if newNode.AccessKey == "" {
|
if newNode.AccessKey == "" {
|
||||||
|
@@ -59,6 +59,7 @@ func NodeUpdate(client mqtt.Client, msg mqtt.Message) {
|
|||||||
ifaceDelta := ncutils.IfaceDelta(&nodeCfg.Node, &newNode)
|
ifaceDelta := ncutils.IfaceDelta(&nodeCfg.Node, &newNode)
|
||||||
shouldDNSChange := nodeCfg.Node.DNSOn != newNode.DNSOn
|
shouldDNSChange := nodeCfg.Node.DNSOn != newNode.DNSOn
|
||||||
hubChange := nodeCfg.Node.IsHub != newNode.IsHub
|
hubChange := nodeCfg.Node.IsHub != newNode.IsHub
|
||||||
|
keepaliveChange := nodeCfg.Node.PersistentKeepalive != newNode.PersistentKeepalive
|
||||||
|
|
||||||
nodeCfg.Node = newNode
|
nodeCfg.Node = newNode
|
||||||
switch newNode.Action {
|
switch newNode.Action {
|
||||||
@@ -107,6 +108,9 @@ func NodeUpdate(client mqtt.Client, msg mqtt.Message) {
|
|||||||
ncutils.Log("error updating wireguard config " + err.Error())
|
ncutils.Log("error updating wireguard config " + err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if keepaliveChange {
|
||||||
|
wireguard.UpdateKeepAlive(file, newNode.PersistentKeepalive)
|
||||||
|
}
|
||||||
if ifaceDelta { // if a change caused an ifacedelta we need to notify the server to update the peers
|
if ifaceDelta { // if a change caused an ifacedelta we need to notify the server to update the peers
|
||||||
ncutils.Log("applying WG conf to " + file)
|
ncutils.Log("applying WG conf to " + file)
|
||||||
if ncutils.IsWindows() {
|
if ncutils.IsWindows() {
|
||||||
|
@@ -466,6 +466,30 @@ func UpdatePrivateKey(file, privateKey string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// UpdateKeepAlive - updates the persistentkeepalive of all peers
|
||||||
|
func UpdateKeepAlive(file string, keepalive int32) error {
|
||||||
|
options := ini.LoadOptions{
|
||||||
|
AllowNonUniqueSections: true,
|
||||||
|
AllowShadows: true,
|
||||||
|
}
|
||||||
|
wireguard, err := ini.LoadSources(options, file)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
peers, err := wireguard.SectionsByName(section_peers)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
newvalue := strconv.Itoa(int(keepalive))
|
||||||
|
for i := range peers {
|
||||||
|
wireguard.SectionWithIndex(section_peers, i).Key("PersistentKeepALive").SetValue(newvalue)
|
||||||
|
}
|
||||||
|
if err := wireguard.SaveTo(file); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// RemoveConfGraceful - Run remove conf and wait for it to actually be gone before proceeding
|
// RemoveConfGraceful - Run remove conf and wait for it to actually be gone before proceeding
|
||||||
func RemoveConfGraceful(ifacename string) {
|
func RemoveConfGraceful(ifacename string) {
|
||||||
// ensure you clear any existing interface first
|
// ensure you clear any existing interface first
|
||||||
|
Reference in New Issue
Block a user