| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 | package ncutilsimport (	"net"	"github.com/gravitl/netmaker/models")// IfaceDelta - checks if the new node causes an interface changefunc IfaceDelta(currentNode *models.Node, newNode *models.Node) bool {	// single comparison statements	if newNode.Endpoint != currentNode.Endpoint ||		newNode.PublicKey != currentNode.PublicKey ||		newNode.Address != currentNode.Address ||		newNode.Address6 != currentNode.Address6 ||		newNode.IsEgressGateway != currentNode.IsEgressGateway ||		newNode.IsIngressGateway != currentNode.IsIngressGateway ||		newNode.IsRelay != currentNode.IsRelay ||		newNode.ListenPort != currentNode.ListenPort ||		newNode.UDPHolePunch != currentNode.UDPHolePunch ||		newNode.MTU != currentNode.MTU ||		newNode.IsPending != currentNode.IsPending ||		newNode.PersistentKeepalive != currentNode.PersistentKeepalive ||		newNode.DNSOn != currentNode.DNSOn ||		len(newNode.AllowedIPs) != len(currentNode.AllowedIPs) {		return true	}	// multi-comparison statements	if newNode.IsEgressGateway == "yes" {		if len(currentNode.EgressGatewayRanges) != len(newNode.EgressGatewayRanges) {			return true		}		for _, address := range newNode.EgressGatewayRanges {			if !StringSliceContains(currentNode.EgressGatewayRanges, address) {				return true			}		}	}	if newNode.IsRelay == "yes" {		if len(currentNode.RelayAddrs) != len(newNode.RelayAddrs) {			return true		}		for _, address := range newNode.RelayAddrs {			if !StringSliceContains(currentNode.RelayAddrs, address) {				return true			}		}	}	for _, address := range newNode.AllowedIPs {		if !StringSliceContains(currentNode.AllowedIPs, address) {			return true		}	}	return false}// StringSliceContains - sees if a string slice contains a string elementfunc StringSliceContains(slice []string, item string) bool {	for _, s := range slice {		if s == item {			return true		}	}	return false}// IPNetSliceContains - sees if a string slice contains a string elementfunc IPNetSliceContains(slice []net.IPNet, item net.IPNet) bool {	for _, s := range slice {		if s.String() == item.String() {			return true		}	}	return false}// IfaceExists - return true if you can find the ifacefunc IfaceExists(ifacename string) bool {	localnets, err := net.Interfaces()	if err != nil {		return false	}	for _, localnet := range localnets {		if ifacename == localnet.Name {			return true		}	}	return false}
 |