mirror of
https://github.com/gravitl/netmaker.git
synced 2024-09-20 23:36:18 +08:00
static configs
This commit is contained in:
parent
f8df4b571b
commit
aae89cbaca
|
@ -59,7 +59,7 @@ func GetPeersList(networkName string) ([]models.Node, error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
functions.PrintUserLog(models.NODE_SERVER_NAME, "sending peer "+peer.MacAddress+" "+peer.Endpoint, 2)
|
functions.PrintUserLog(models.NODE_SERVER_NAME, "adding to peer list: "+peer.MacAddress+" "+peer.Endpoint, 3)
|
||||||
peers = append(peers, peer)
|
peers = append(peers, peer)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -193,7 +193,6 @@ func CreateNode(node models.Node, networkName string) (models.Node, error) {
|
||||||
node.Password = string(hash)
|
node.Password = string(hash)
|
||||||
|
|
||||||
node.Network = networkName
|
node.Network = networkName
|
||||||
|
|
||||||
if node.Name == models.NODE_SERVER_NAME {
|
if node.Name == models.NODE_SERVER_NAME {
|
||||||
if node.CheckIsServer() {
|
if node.CheckIsServer() {
|
||||||
node.IsServer = "yes"
|
node.IsServer = "yes"
|
||||||
|
|
|
@ -252,7 +252,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.StaticPubKey == "yes" {
|
if action == models.NODE_UPDATE_KEY && node.IsStatic == "yes" {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if node.Network == networkName {
|
if node.Network == networkName {
|
||||||
|
|
|
@ -57,8 +57,7 @@ type Node struct {
|
||||||
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"`
|
||||||
IngressGatewayRange string `json:"ingressgatewayrange" bson:"ingressgatewayrange" yaml:"ingressgatewayrange"`
|
IngressGatewayRange string `json:"ingressgatewayrange" bson:"ingressgatewayrange" yaml:"ingressgatewayrange"`
|
||||||
StaticPubKey string `json:"staticpubkey" bson:"staticpubkey" yaml:"staticpubkey" validate:"checkyesorno"`
|
IsStatic string `json:"isstatic" bson:"isstatic" yaml:"isstatic" validate:"checkyesorno"`
|
||||||
StaticIP string `json:"staticip" bson:"staticip" yaml:"staticip" validate:"checkyesorno"`
|
|
||||||
UDPHolePunch string `json:"udpholepunch" bson:"udpholepunch" yaml:"udpholepunch" validate:"checkyesorno"`
|
UDPHolePunch string `json:"udpholepunch" bson:"udpholepunch" yaml:"udpholepunch" validate:"checkyesorno"`
|
||||||
PullChanges string `json:"pullchanges" bson:"pullchanges" yaml:"pullchanges" validate:"checkyesorno"`
|
PullChanges string `json:"pullchanges" bson:"pullchanges" yaml:"pullchanges" validate:"checkyesorno"`
|
||||||
DNSOn string `json:"dnson" bson:"dnson" yaml:"dnson" validate:"checkyesorno"`
|
DNSOn string `json:"dnson" bson:"dnson" yaml:"dnson" validate:"checkyesorno"`
|
||||||
|
@ -204,11 +203,8 @@ func (node *Node) SetDefaults() {
|
||||||
postup := parentNetwork.DefaultPostUp
|
postup := parentNetwork.DefaultPostUp
|
||||||
node.PostUp = postup
|
node.PostUp = postup
|
||||||
}
|
}
|
||||||
if node.StaticIP == "" {
|
if node.IsStatic == "" {
|
||||||
node.StaticIP = "no"
|
node.IsStatic = "no"
|
||||||
}
|
|
||||||
if node.StaticPubKey == "" {
|
|
||||||
node.StaticPubKey = "no"
|
|
||||||
}
|
}
|
||||||
if node.UDPHolePunch == "" {
|
if node.UDPHolePunch == "" {
|
||||||
node.UDPHolePunch = parentNetwork.DefaultUDPHolePunch
|
node.UDPHolePunch = parentNetwork.DefaultUDPHolePunch
|
||||||
|
@ -237,10 +233,10 @@ func (newNode *Node) Fill(currentNode *Node) {
|
||||||
if newNode.ID == "" {
|
if newNode.ID == "" {
|
||||||
newNode.ID = currentNode.ID
|
newNode.ID = currentNode.ID
|
||||||
}
|
}
|
||||||
if newNode.Address == "" {
|
if newNode.Address == "" && newNode.IsStatic != "yes"{
|
||||||
newNode.Address = currentNode.Address
|
newNode.Address = currentNode.Address
|
||||||
}
|
}
|
||||||
if newNode.Address6 == "" {
|
if newNode.Address6 == "" && newNode.IsStatic != "yes"{
|
||||||
newNode.Address6 = currentNode.Address6
|
newNode.Address6 = currentNode.Address6
|
||||||
}
|
}
|
||||||
if newNode.LocalAddress == "" {
|
if newNode.LocalAddress == "" {
|
||||||
|
@ -249,15 +245,15 @@ func (newNode *Node) Fill(currentNode *Node) {
|
||||||
if newNode.Name == "" {
|
if newNode.Name == "" {
|
||||||
newNode.Name = currentNode.Name
|
newNode.Name = currentNode.Name
|
||||||
}
|
}
|
||||||
if newNode.ListenPort == 0 {
|
if newNode.ListenPort == 0 && newNode.IsStatic != "yes"{
|
||||||
newNode.ListenPort = currentNode.ListenPort
|
newNode.ListenPort = currentNode.ListenPort
|
||||||
}
|
}
|
||||||
if newNode.PublicKey == "" {
|
if newNode.PublicKey == "" && newNode.IsStatic != "yes" {
|
||||||
newNode.PublicKey = currentNode.PublicKey
|
newNode.PublicKey = currentNode.PublicKey
|
||||||
} else {
|
} else {
|
||||||
newNode.KeyUpdateTimeStamp = time.Now().Unix()
|
newNode.KeyUpdateTimeStamp = time.Now().Unix()
|
||||||
}
|
}
|
||||||
if newNode.Endpoint == "" {
|
if newNode.Endpoint == "" && newNode.IsStatic != "yes"{
|
||||||
newNode.Endpoint = currentNode.Endpoint
|
newNode.Endpoint = currentNode.Endpoint
|
||||||
}
|
}
|
||||||
if newNode.PostUp == "" {
|
if newNode.PostUp == "" {
|
||||||
|
@ -331,14 +327,8 @@ func (newNode *Node) Fill(currentNode *Node) {
|
||||||
if newNode.IngressGatewayRange == "" {
|
if newNode.IngressGatewayRange == "" {
|
||||||
newNode.IngressGatewayRange = currentNode.IngressGatewayRange
|
newNode.IngressGatewayRange = currentNode.IngressGatewayRange
|
||||||
}
|
}
|
||||||
if newNode.StaticIP == "" {
|
if newNode.IsStatic == "" {
|
||||||
newNode.StaticIP = currentNode.StaticIP
|
newNode.IsStatic = currentNode.IsStatic
|
||||||
}
|
|
||||||
if newNode.StaticIP == "" {
|
|
||||||
newNode.StaticIP = currentNode.StaticIP
|
|
||||||
}
|
|
||||||
if newNode.StaticPubKey == "" {
|
|
||||||
newNode.StaticPubKey = currentNode.StaticPubKey
|
|
||||||
}
|
}
|
||||||
if newNode.UDPHolePunch == "" {
|
if newNode.UDPHolePunch == "" {
|
||||||
newNode.UDPHolePunch = currentNode.SaveConfig
|
newNode.UDPHolePunch = currentNode.SaveConfig
|
||||||
|
@ -364,6 +354,7 @@ func (newNode *Node) Fill(currentNode *Node) {
|
||||||
if newNode.Action == "" {
|
if newNode.Action == "" {
|
||||||
newNode.Action = currentNode.Action
|
newNode.Action = currentNode.Action
|
||||||
}
|
}
|
||||||
|
newNode.IsServer = currentNode.IsServer
|
||||||
}
|
}
|
||||||
|
|
||||||
func (currentNode *Node) Update(newNode *Node) error {
|
func (currentNode *Node) Update(newNode *Node) error {
|
||||||
|
|
|
@ -22,7 +22,7 @@ import (
|
||||||
func checkIP(node *models.Node, servercfg config.ServerConfig, cliconf config.ClientConfig, network string) bool {
|
func checkIP(node *models.Node, servercfg config.ServerConfig, cliconf config.ClientConfig, network string) bool {
|
||||||
ipchange := false
|
ipchange := false
|
||||||
var err error
|
var err error
|
||||||
if node.Roaming == "yes" {
|
if node.Roaming == "yes" && node.IsStatic != "yes" {
|
||||||
if node.IsLocal == "no" {
|
if node.IsLocal == "no" {
|
||||||
log.Println("Checking to see if public addresses have changed")
|
log.Println("Checking to see if public addresses have changed")
|
||||||
extIP, err := getPublicIP()
|
extIP, err := getPublicIP()
|
||||||
|
@ -88,12 +88,9 @@ func setDNS(node *models.Node, servercfg config.ServerConfig, nodecfg *models.No
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
func checkNodeActions(node *models.Node, network string, servercfg config.ServerConfig, localNode *models.Node) string {
|
func checkNodeActions(node *models.Node, network string, servercfg config.ServerConfig, localNode *models.Node) string {
|
||||||
if node.Action == models.NODE_UPDATE_KEY || localNode.Action == models.NODE_UPDATE_KEY {
|
if (node.Action == models.NODE_UPDATE_KEY || localNode.Action == models.NODE_UPDATE_KEY) &&
|
||||||
|
node.IsStatic != "yes" {
|
||||||
err := wireguard.SetWGKeyConfig(network, servercfg.GRPCAddress)
|
err := wireguard.SetWGKeyConfig(network, servercfg.GRPCAddress)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("Unable to process reset keys request:", err)
|
log.Println("Unable to process reset keys request:", err)
|
||||||
|
|
|
@ -82,7 +82,8 @@ func InitWireguard(node *models.Node, privkey string, peers []wgtypes.PeerConfig
|
||||||
conf := wgtypes.Config{}
|
conf := wgtypes.Config{}
|
||||||
if nodecfg.UDPHolePunch == "yes" &&
|
if nodecfg.UDPHolePunch == "yes" &&
|
||||||
nodecfg.IsServer == "no" &&
|
nodecfg.IsServer == "no" &&
|
||||||
nodecfg.IsIngressGateway == "no" {
|
nodecfg.IsIngressGateway == "no" &&
|
||||||
|
nodecfg.IsStatic != "yes" {
|
||||||
conf = wgtypes.Config{
|
conf = wgtypes.Config{
|
||||||
PrivateKey: &key,
|
PrivateKey: &key,
|
||||||
ReplacePeers: true,
|
ReplacePeers: true,
|
||||||
|
|
Loading…
Reference in a new issue