netmaker/logic/wireguard.go

45 lines
1.3 KiB
Go
Raw Normal View History

package logic
import (
"github.com/gravitl/netmaker/models"
)
2022-02-15 00:01:33 +08:00
// IfaceDelta - checks if the new node causes an interface change
func IfaceDelta(currentNode *models.Node, newNode *models.Node) bool {
2022-02-15 00:01:33 +08:00
// single comparison statements
if newNode.Address.String() != currentNode.Address.String() ||
newNode.Address6.String() != currentNode.Address6.String() ||
2022-02-15 00:01:33 +08:00
newNode.IsEgressGateway != currentNode.IsEgressGateway ||
newNode.IsIngressGateway != currentNode.IsIngressGateway ||
newNode.IsRelay != currentNode.IsRelay ||
newNode.PersistentKeepalive != currentNode.PersistentKeepalive ||
newNode.DNSOn != currentNode.DNSOn ||
2022-12-24 03:07:16 +08:00
newNode.Connected != currentNode.Connected {
2022-02-15 00:01:33 +08:00
return true
}
// multi-comparison statements
if newNode.IsEgressGateway {
2022-02-15 00:01:33 +08:00
if len(currentNode.EgressGatewayRanges) != len(newNode.EgressGatewayRanges) {
return true
}
for _, address := range newNode.EgressGatewayRanges {
if !StringSliceContains(currentNode.EgressGatewayRanges, address) {
return true
}
}
}
if newNode.IsRelay {
2022-02-15 00:01:33 +08:00
if len(currentNode.RelayAddrs) != len(newNode.RelayAddrs) {
return true
}
for _, address := range newNode.RelayAddrs {
if !StringSliceContains(currentNode.RelayAddrs, address) {
return true
}
}
}
return false
}
2022-01-18 06:44:12 +08:00
// == Private Functions ==