mirror of
https://github.com/gravitl/netmaker.git
synced 2025-02-25 00:24:37 +08:00
fixing localport issues
This commit is contained in:
parent
ccc0ed851d
commit
5f303cb50a
4 changed files with 8 additions and 11 deletions
|
@ -37,7 +37,7 @@ type Node struct {
|
|||
Address string `json:"address" bson:"address" yaml:"address" validate:"omitempty,ipv4"`
|
||||
Address6 string `json:"address6" bson:"address6" yaml:"address6" validate:"omitempty,ipv6"`
|
||||
LocalAddress string `json:"localaddress" bson:"localaddress" yaml:"localaddress" validate:"omitempty,ip"`
|
||||
LocalListenPort int32 `json:"locallistenport" bson:"locallistenport" yaml:"locallistenport" validate:"numeric,min=1024,max=65535"`
|
||||
LocalListenPort int32 `json:"locallistenport" bson:"locallistenport" yaml:"locallistenport" validate:"numeric,min=0,max=65535"`
|
||||
Name string `json:"name" bson:"name" yaml:"name" validate:"omitempty,max=62,in_charset"`
|
||||
NetworkSettings Network `json:"networksettings" bson:"networksettings" yaml:"networksettings" validate:"-"`
|
||||
ListenPort int32 `json:"listenport" bson:"listenport" yaml:"listenport" validate:"omitempty,numeric,min=1024,max=65535"`
|
||||
|
@ -272,9 +272,6 @@ func (newNode *Node) Fill(currentNode *Node) {
|
|||
if newNode.LocalListenPort == 0 && newNode.IsStatic != "yes" {
|
||||
newNode.LocalListenPort = currentNode.LocalListenPort
|
||||
}
|
||||
if newNode.LocalListenPort == 0 {
|
||||
newNode.LocalListenPort = currentNode.ListenPort
|
||||
}
|
||||
if newNode.PublicKey == "" && newNode.IsStatic != "yes" {
|
||||
newNode.PublicKey = currentNode.PublicKey
|
||||
}
|
||||
|
|
|
@ -241,7 +241,6 @@ func GetCLIConfig(c *cli.Context) (ClientConfig, string, error) {
|
|||
cfg.Node.PostUp = c.String("postup")
|
||||
cfg.Node.PostDown = c.String("postdown")
|
||||
cfg.Node.ListenPort = int32(c.Int("port"))
|
||||
cfg.Node.LocalListenPort = int32(c.Int("localport"))
|
||||
cfg.Node.PersistentKeepalive = int32(c.Int("keepalive"))
|
||||
cfg.Node.PublicKey = c.String("publickey")
|
||||
privateKey := c.String("privatekey")
|
||||
|
|
|
@ -6,6 +6,7 @@ import (
|
|||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"strconv"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
|
@ -68,12 +69,11 @@ func Checkin(ctx context.Context, wg *sync.WaitGroup) {
|
|||
deviceiface = nodeCfg.Node.Interface
|
||||
}
|
||||
}
|
||||
localPort, err := local.GetLocalListenPort(deviceiface)
|
||||
if err != nil {
|
||||
logger.Log(1, "error encountered checking private ip addresses: ", err.Error())
|
||||
}
|
||||
if nodeCfg.Node.LocalListenPort != localPort && localPort != 0 {
|
||||
logger.Log(1, "local port has changed from ", string(nodeCfg.Node.LocalListenPort), " to ", string(localPort))
|
||||
localPort, errN := local.GetLocalListenPort(deviceiface)
|
||||
if errN != nil {
|
||||
logger.Log(1, "error encountered checking local listen port: ", err.Error())
|
||||
} else if nodeCfg.Node.LocalListenPort != localPort && localPort != 0 {
|
||||
logger.Log(1, "local port has changed from ", strconv.Itoa(int(nodeCfg.Node.LocalListenPort)), " to ", strconv.Itoa(int(localPort)))
|
||||
nodeCfg.Node.LocalListenPort = localPort
|
||||
if err := PublishNodeUpdate(&nodeCfg); err != nil {
|
||||
logger.Log(0, "could not publish local port change")
|
||||
|
|
|
@ -129,6 +129,7 @@ func GetLocalListenPort(ifacename string) (int32, error) {
|
|||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
portstring = strings.TrimSuffix(portstring, "\n")
|
||||
i, err := strconv.ParseInt(portstring, 10, 32)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
|
|
Loading…
Reference in a new issue