mirror of
https://github.com/gravitl/netmaker.git
synced 2025-09-26 21:01:32 +08:00
NM-15: sync device interfaces on checkin (#3548)
* sync devices interface on checkin * deep compare ifaces on checkin
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"reflect"
|
||||
"sort"
|
||||
"sync"
|
||||
|
||||
@@ -307,6 +308,10 @@ func UpdateHostFromClient(newHost, currHost *models.Host) (sendPeerUpdate bool)
|
||||
sendPeerUpdate = true
|
||||
isEndpointChanged = true
|
||||
}
|
||||
if !reflect.DeepEqual(currHost.Interfaces, newHost.Interfaces) {
|
||||
currHost.Interfaces = newHost.Interfaces
|
||||
sendPeerUpdate = true
|
||||
}
|
||||
|
||||
if isEndpointChanged {
|
||||
for _, nodeID := range currHost.Nodes {
|
||||
|
@@ -20,6 +20,7 @@ import (
|
||||
"github.com/c-robinson/iplib"
|
||||
"github.com/gravitl/netmaker/database"
|
||||
"github.com/gravitl/netmaker/logger"
|
||||
"github.com/gravitl/netmaker/models"
|
||||
)
|
||||
|
||||
// IsBase64 - checks if a string is in base64 format
|
||||
@@ -253,3 +254,22 @@ func GetClientIP(r *http.Request) string {
|
||||
}
|
||||
return ip
|
||||
}
|
||||
|
||||
// CompareIfaceSlices compares two slices of Iface for deep equality (order-sensitive)
|
||||
func CompareIfaceSlices(a, b []models.Iface) bool {
|
||||
if len(a) != len(b) {
|
||||
return false
|
||||
}
|
||||
for i := range a {
|
||||
if !compareIface(a[i], b[i]) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
func compareIface(a, b models.Iface) bool {
|
||||
return a.Name == b.Name &&
|
||||
a.Address.IP.Equal(b.Address.IP) &&
|
||||
a.Address.Mask.String() == b.Address.Mask.String() &&
|
||||
a.AddressString == b.AddressString
|
||||
}
|
||||
|
@@ -274,7 +274,7 @@ func HandleHostCheckin(h, currentHost *models.Host) bool {
|
||||
return false
|
||||
}
|
||||
}
|
||||
ifaceDelta := len(h.Interfaces) != len(currentHost.Interfaces) ||
|
||||
ifaceDelta := len(h.Interfaces) != len(currentHost.Interfaces) || !logic.CompareIfaceSlices(h.Interfaces, currentHost.Interfaces) ||
|
||||
!h.EndpointIP.Equal(currentHost.EndpointIP) ||
|
||||
(len(h.NatType) > 0 && h.NatType != currentHost.NatType) ||
|
||||
h.DefaultInterface != currentHost.DefaultInterface ||
|
||||
|
Reference in New Issue
Block a user