mirror of
https://github.com/gravitl/netmaker.git
synced 2025-10-05 16:57:51 +08:00
isStatic now only represents whether the Endpoint var is static
This commit is contained in:
@@ -680,7 +680,7 @@ func networkNodesUpdateAction(networkName string, action string) error {
|
|||||||
fmt.Println("error in node address assignment!")
|
fmt.Println("error in node address assignment!")
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if action == models.NODE_UPDATE_KEY && node.IsStatic == "yes" {
|
if action == models.NODE_UPDATE_KEY {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if node.Network == networkName {
|
if node.Network == networkName {
|
||||||
|
@@ -80,7 +80,9 @@ func GetNodePeers(network *models.Network, nodeid string, excludeRelayed bool, i
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// if udp hole punching is on, but port is still set to default (e.g. 51821), use the LocalListenPort
|
// if udp hole punching is on, but port is still set to default (e.g. 51821), use the LocalListenPort
|
||||||
if node.UDPHolePunch == "yes" && node.IsStatic != "yes" && peer.ListenPort == node.ListenPort {
|
// removing IsStatic check. IsStatic will now ONLY refer to endpoint.
|
||||||
|
//if node.UDPHolePunch == "yes" && node.IsStatic != "yes" && peer.ListenPort == node.ListenPort {
|
||||||
|
if node.UDPHolePunch == "yes" && peer.ListenPort == node.ListenPort {
|
||||||
peer.ListenPort = node.LocalListenPort
|
peer.ListenPort = node.LocalListenPort
|
||||||
}
|
}
|
||||||
if node.IsRelay == "yes" { // TODO, check if addressrange6 needs to be appended
|
if node.IsRelay == "yes" { // TODO, check if addressrange6 needs to be appended
|
||||||
|
@@ -406,8 +406,7 @@ func isDeleteError(err error) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func checkNodeActions(node *models.Node) string {
|
func checkNodeActions(node *models.Node) string {
|
||||||
if (node.Action == models.NODE_UPDATE_KEY) &&
|
if node.Action == models.NODE_UPDATE_KEY {
|
||||||
node.IsStatic != "yes" {
|
|
||||||
err := setWGKeyConfig(node)
|
err := setWGKeyConfig(node)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logger.Log(1, "unable to process reset keys request:", err.Error())
|
logger.Log(1, "unable to process reset keys request:", err.Error())
|
||||||
|
107
models/node.go
107
models/node.go
@@ -35,53 +35,54 @@ var seededRand *rand.Rand = rand.New(
|
|||||||
|
|
||||||
// Node - struct for node model
|
// Node - struct for node model
|
||||||
type Node struct {
|
type Node struct {
|
||||||
ID string `json:"id,omitempty" bson:"id,omitempty" yaml:"id,omitempty" validate:"required,min=5"`
|
ID string `json:"id,omitempty" bson:"id,omitempty" yaml:"id,omitempty" validate:"required,min=5"`
|
||||||
Address string `json:"address" bson:"address" yaml:"address" validate:"omitempty,ipv4"`
|
Address string `json:"address" bson:"address" yaml:"address" validate:"omitempty,ipv4"`
|
||||||
Address6 string `json:"address6" bson:"address6" yaml:"address6" validate:"omitempty,ipv6"`
|
Address6 string `json:"address6" bson:"address6" yaml:"address6" validate:"omitempty,ipv6"`
|
||||||
LocalAddress string `json:"localaddress" bson:"localaddress" yaml:"localaddress" validate:"omitempty,ip"`
|
LocalAddress string `json:"localaddress" bson:"localaddress" yaml:"localaddress" validate:"omitempty,ip"`
|
||||||
Name string `json:"name" bson:"name" yaml:"name" validate:"omitempty,max=62,in_charset"`
|
Name string `json:"name" bson:"name" yaml:"name" validate:"omitempty,max=62,in_charset"`
|
||||||
NetworkSettings Network `json:"networksettings" bson:"networksettings" yaml:"networksettings" validate:"-"`
|
NetworkSettings Network `json:"networksettings" bson:"networksettings" yaml:"networksettings" validate:"-"`
|
||||||
ListenPort int32 `json:"listenport" bson:"listenport" yaml:"listenport" validate:"omitempty,numeric,min=1024,max=65535"`
|
ListenPort int32 `json:"listenport" bson:"listenport" yaml:"listenport" validate:"omitempty,numeric,min=1024,max=65535"`
|
||||||
LocalListenPort int32 `json:"locallistenport" bson:"locallistenport" yaml:"locallistenport" validate:"numeric,min=0,max=65535"`
|
LocalListenPort int32 `json:"locallistenport" bson:"locallistenport" yaml:"locallistenport" validate:"numeric,min=0,max=65535"`
|
||||||
PublicKey string `json:"publickey" bson:"publickey" yaml:"publickey" validate:"required,base64"`
|
PublicKey string `json:"publickey" bson:"publickey" yaml:"publickey" validate:"required,base64"`
|
||||||
Endpoint string `json:"endpoint" bson:"endpoint" yaml:"endpoint" validate:"required,ip"`
|
Endpoint string `json:"endpoint" bson:"endpoint" yaml:"endpoint" validate:"required,ip"`
|
||||||
PostUp string `json:"postup" bson:"postup" yaml:"postup"`
|
PostUp string `json:"postup" bson:"postup" yaml:"postup"`
|
||||||
PostDown string `json:"postdown" bson:"postdown" yaml:"postdown"`
|
PostDown string `json:"postdown" bson:"postdown" yaml:"postdown"`
|
||||||
AllowedIPs []string `json:"allowedips" bson:"allowedips" yaml:"allowedips"`
|
AllowedIPs []string `json:"allowedips" bson:"allowedips" yaml:"allowedips"`
|
||||||
PersistentKeepalive int32 `json:"persistentkeepalive" bson:"persistentkeepalive" yaml:"persistentkeepalive" validate:"omitempty,numeric,max=1000"`
|
PersistentKeepalive int32 `json:"persistentkeepalive" bson:"persistentkeepalive" yaml:"persistentkeepalive" validate:"omitempty,numeric,max=1000"`
|
||||||
IsHub string `json:"ishub" bson:"ishub" yaml:"ishub" validate:"checkyesorno"`
|
IsHub string `json:"ishub" bson:"ishub" yaml:"ishub" validate:"checkyesorno"`
|
||||||
AccessKey string `json:"accesskey" bson:"accesskey" yaml:"accesskey"`
|
AccessKey string `json:"accesskey" bson:"accesskey" yaml:"accesskey"`
|
||||||
Interface string `json:"interface" bson:"interface" yaml:"interface"`
|
Interface string `json:"interface" bson:"interface" yaml:"interface"`
|
||||||
LastModified int64 `json:"lastmodified" bson:"lastmodified" yaml:"lastmodified"`
|
LastModified int64 `json:"lastmodified" bson:"lastmodified" yaml:"lastmodified"`
|
||||||
ExpirationDateTime int64 `json:"expdatetime" bson:"expdatetime" yaml:"expdatetime"`
|
ExpirationDateTime int64 `json:"expdatetime" bson:"expdatetime" yaml:"expdatetime"`
|
||||||
LastPeerUpdate int64 `json:"lastpeerupdate" bson:"lastpeerupdate" yaml:"lastpeerupdate"`
|
LastPeerUpdate int64 `json:"lastpeerupdate" bson:"lastpeerupdate" yaml:"lastpeerupdate"`
|
||||||
LastCheckIn int64 `json:"lastcheckin" bson:"lastcheckin" yaml:"lastcheckin"`
|
LastCheckIn int64 `json:"lastcheckin" bson:"lastcheckin" yaml:"lastcheckin"`
|
||||||
MacAddress string `json:"macaddress" bson:"macaddress" yaml:"macaddress" validate:"macaddress_unique"`
|
MacAddress string `json:"macaddress" bson:"macaddress" yaml:"macaddress" validate:"macaddress_unique"`
|
||||||
Password string `json:"password" bson:"password" yaml:"password" validate:"required,min=6"`
|
Password string `json:"password" bson:"password" yaml:"password" validate:"required,min=6"`
|
||||||
Network string `json:"network" bson:"network" yaml:"network" validate:"network_exists"`
|
Network string `json:"network" bson:"network" yaml:"network" validate:"network_exists"`
|
||||||
IsRelayed string `json:"isrelayed" bson:"isrelayed" yaml:"isrelayed"`
|
IsRelayed string `json:"isrelayed" bson:"isrelayed" yaml:"isrelayed"`
|
||||||
IsPending string `json:"ispending" bson:"ispending" yaml:"ispending"`
|
IsPending string `json:"ispending" bson:"ispending" yaml:"ispending"`
|
||||||
IsRelay string `json:"isrelay" bson:"isrelay" yaml:"isrelay" validate:"checkyesorno"`
|
IsRelay string `json:"isrelay" bson:"isrelay" yaml:"isrelay" validate:"checkyesorno"`
|
||||||
IsDocker string `json:"isdocker" bson:"isdocker" yaml:"isdocker" validate:"checkyesorno"`
|
IsDocker string `json:"isdocker" bson:"isdocker" yaml:"isdocker" validate:"checkyesorno"`
|
||||||
IsK8S string `json:"isk8s" bson:"isk8s" yaml:"isk8s" validate:"checkyesorno"`
|
IsK8S string `json:"isk8s" bson:"isk8s" yaml:"isk8s" validate:"checkyesorno"`
|
||||||
IsEgressGateway string `json:"isegressgateway" bson:"isegressgateway" yaml:"isegressgateway"`
|
IsEgressGateway string `json:"isegressgateway" bson:"isegressgateway" yaml:"isegressgateway"`
|
||||||
IsIngressGateway string `json:"isingressgateway" bson:"isingressgateway" yaml:"isingressgateway"`
|
IsIngressGateway string `json:"isingressgateway" bson:"isingressgateway" yaml:"isingressgateway"`
|
||||||
EgressGatewayRanges []string `json:"egressgatewayranges" bson:"egressgatewayranges" yaml:"egressgatewayranges"`
|
EgressGatewayRanges []string `json:"egressgatewayranges" bson:"egressgatewayranges" yaml:"egressgatewayranges"`
|
||||||
RelayAddrs []string `json:"relayaddrs" bson:"relayaddrs" yaml:"relayaddrs"`
|
RelayAddrs []string `json:"relayaddrs" bson:"relayaddrs" yaml:"relayaddrs"`
|
||||||
IngressGatewayRange string `json:"ingressgatewayrange" bson:"ingressgatewayrange" yaml:"ingressgatewayrange"`
|
IngressGatewayRange string `json:"ingressgatewayrange" bson:"ingressgatewayrange" yaml:"ingressgatewayrange"`
|
||||||
IsStatic string `json:"isstatic" bson:"isstatic" yaml:"isstatic" validate:"checkyesorno"`
|
// IsStatic - refers to if the Endpoint is set manually or dynamically
|
||||||
UDPHolePunch string `json:"udpholepunch" bson:"udpholepunch" yaml:"udpholepunch" validate:"checkyesorno"`
|
IsStatic string `json:"isstatic" bson:"isstatic" yaml:"isstatic" validate:"checkyesorno"`
|
||||||
DNSOn string `json:"dnson" bson:"dnson" yaml:"dnson" validate:"checkyesorno"`
|
UDPHolePunch string `json:"udpholepunch" bson:"udpholepunch" yaml:"udpholepunch" validate:"checkyesorno"`
|
||||||
IsServer string `json:"isserver" bson:"isserver" yaml:"isserver" validate:"checkyesorno"`
|
DNSOn string `json:"dnson" bson:"dnson" yaml:"dnson" validate:"checkyesorno"`
|
||||||
Action string `json:"action" bson:"action" yaml:"action"`
|
IsServer string `json:"isserver" bson:"isserver" yaml:"isserver" validate:"checkyesorno"`
|
||||||
IsLocal string `json:"islocal" bson:"islocal" yaml:"islocal" validate:"checkyesorno"`
|
Action string `json:"action" bson:"action" yaml:"action"`
|
||||||
LocalRange string `json:"localrange" bson:"localrange" yaml:"localrange"`
|
IsLocal string `json:"islocal" bson:"islocal" yaml:"islocal" validate:"checkyesorno"`
|
||||||
IPForwarding string `json:"ipforwarding" bson:"ipforwarding" yaml:"ipforwarding" validate:"checkyesorno"`
|
LocalRange string `json:"localrange" bson:"localrange" yaml:"localrange"`
|
||||||
OS string `json:"os" bson:"os" yaml:"os"`
|
IPForwarding string `json:"ipforwarding" bson:"ipforwarding" yaml:"ipforwarding" validate:"checkyesorno"`
|
||||||
MTU int32 `json:"mtu" bson:"mtu" yaml:"mtu"`
|
OS string `json:"os" bson:"os" yaml:"os"`
|
||||||
Version string `json:"version" bson:"version" yaml:"version"`
|
MTU int32 `json:"mtu" bson:"mtu" yaml:"mtu"`
|
||||||
Server string `json:"server" bson:"server" yaml:"server"`
|
Version string `json:"version" bson:"version" yaml:"version"`
|
||||||
TrafficKeys TrafficKeys `json:"traffickeys" bson:"traffickeys" yaml:"traffickeys"`
|
Server string `json:"server" bson:"server" yaml:"server"`
|
||||||
|
TrafficKeys TrafficKeys `json:"traffickeys" bson:"traffickeys" yaml:"traffickeys"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// NodesArray - used for node sorting
|
// NodesArray - used for node sorting
|
||||||
@@ -255,10 +256,10 @@ func (node *Node) SetDefaultName() {
|
|||||||
func (newNode *Node) Fill(currentNode *Node) {
|
func (newNode *Node) Fill(currentNode *Node) {
|
||||||
newNode.ID = currentNode.ID
|
newNode.ID = currentNode.ID
|
||||||
|
|
||||||
if newNode.Address == "" && newNode.IsStatic != "yes" {
|
if newNode.Address == "" {
|
||||||
newNode.Address = currentNode.Address
|
newNode.Address = currentNode.Address
|
||||||
}
|
}
|
||||||
if newNode.Address6 == "" && newNode.IsStatic != "yes" {
|
if newNode.Address6 == "" {
|
||||||
newNode.Address6 = currentNode.Address6
|
newNode.Address6 = currentNode.Address6
|
||||||
}
|
}
|
||||||
if newNode.LocalAddress == "" {
|
if newNode.LocalAddress == "" {
|
||||||
@@ -267,16 +268,16 @@ func (newNode *Node) Fill(currentNode *Node) {
|
|||||||
if newNode.Name == "" {
|
if newNode.Name == "" {
|
||||||
newNode.Name = currentNode.Name
|
newNode.Name = currentNode.Name
|
||||||
}
|
}
|
||||||
if newNode.ListenPort == 0 && newNode.IsStatic != "yes" {
|
if newNode.ListenPort == 0 {
|
||||||
newNode.ListenPort = currentNode.ListenPort
|
newNode.ListenPort = currentNode.ListenPort
|
||||||
}
|
}
|
||||||
if newNode.LocalListenPort == 0 && newNode.IsStatic != "yes" {
|
if newNode.LocalListenPort == 0 {
|
||||||
newNode.LocalListenPort = currentNode.LocalListenPort
|
newNode.LocalListenPort = currentNode.LocalListenPort
|
||||||
}
|
}
|
||||||
if newNode.PublicKey == "" && newNode.IsStatic != "yes" {
|
if newNode.PublicKey == "" {
|
||||||
newNode.PublicKey = currentNode.PublicKey
|
newNode.PublicKey = currentNode.PublicKey
|
||||||
}
|
}
|
||||||
if newNode.Endpoint == "" && newNode.IsStatic != "yes" {
|
if newNode.Endpoint == "" {
|
||||||
newNode.Endpoint = currentNode.Endpoint
|
newNode.Endpoint = currentNode.Endpoint
|
||||||
}
|
}
|
||||||
if newNode.PostUp == "" {
|
if newNode.PostUp == "" {
|
||||||
|
@@ -40,8 +40,7 @@ func ApplyWithoutWGQuick(node *models.Node, ifacename string, confPath string) e
|
|||||||
nodeport := int(node.ListenPort)
|
nodeport := int(node.ListenPort)
|
||||||
if node.UDPHolePunch == "yes" &&
|
if node.UDPHolePunch == "yes" &&
|
||||||
node.IsServer == "no" &&
|
node.IsServer == "no" &&
|
||||||
node.IsIngressGateway != "yes" &&
|
node.IsIngressGateway != "yes" {
|
||||||
node.IsStatic != "yes" {
|
|
||||||
conf = wgtypes.Config{
|
conf = wgtypes.Config{
|
||||||
PrivateKey: &key,
|
PrivateKey: &key,
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user