mirror of
				https://github.com/gravitl/netmaker.git
				synced 2025-10-31 12:16:29 +08:00 
			
		
		
		
	fixing localport issues
This commit is contained in:
		| @@ -37,7 +37,7 @@ type Node struct { | |||||||
| 	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"` | ||||||
| 	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"` | 	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"` | ||||||
| @@ -272,9 +272,6 @@ func (newNode *Node) Fill(currentNode *Node) { | |||||||
| 	if newNode.LocalListenPort == 0 && newNode.IsStatic != "yes" { | 	if newNode.LocalListenPort == 0 && newNode.IsStatic != "yes" { | ||||||
| 		newNode.LocalListenPort = currentNode.LocalListenPort | 		newNode.LocalListenPort = currentNode.LocalListenPort | ||||||
| 	} | 	} | ||||||
| 	if newNode.LocalListenPort == 0 { |  | ||||||
| 		newNode.LocalListenPort = currentNode.ListenPort |  | ||||||
| 	} |  | ||||||
| 	if newNode.PublicKey == "" && newNode.IsStatic != "yes" { | 	if newNode.PublicKey == "" && newNode.IsStatic != "yes" { | ||||||
| 		newNode.PublicKey = currentNode.PublicKey | 		newNode.PublicKey = currentNode.PublicKey | ||||||
| 	} | 	} | ||||||
|   | |||||||
| @@ -241,7 +241,6 @@ func GetCLIConfig(c *cli.Context) (ClientConfig, string, error) { | |||||||
| 	cfg.Node.PostUp = c.String("postup") | 	cfg.Node.PostUp = c.String("postup") | ||||||
| 	cfg.Node.PostDown = c.String("postdown") | 	cfg.Node.PostDown = c.String("postdown") | ||||||
| 	cfg.Node.ListenPort = int32(c.Int("port")) | 	cfg.Node.ListenPort = int32(c.Int("port")) | ||||||
| 	cfg.Node.LocalListenPort = int32(c.Int("localport")) |  | ||||||
| 	cfg.Node.PersistentKeepalive = int32(c.Int("keepalive")) | 	cfg.Node.PersistentKeepalive = int32(c.Int("keepalive")) | ||||||
| 	cfg.Node.PublicKey = c.String("publickey") | 	cfg.Node.PublicKey = c.String("publickey") | ||||||
| 	privateKey := c.String("privatekey") | 	privateKey := c.String("privatekey") | ||||||
|   | |||||||
| @@ -6,6 +6,7 @@ import ( | |||||||
| 	"errors" | 	"errors" | ||||||
| 	"fmt" | 	"fmt" | ||||||
| 	"os" | 	"os" | ||||||
|  | 	"strconv" | ||||||
| 	"sync" | 	"sync" | ||||||
| 	"time" | 	"time" | ||||||
|  |  | ||||||
| @@ -68,12 +69,11 @@ func Checkin(ctx context.Context, wg *sync.WaitGroup) { | |||||||
| 							deviceiface = nodeCfg.Node.Interface | 							deviceiface = nodeCfg.Node.Interface | ||||||
| 						} | 						} | ||||||
| 					} | 					} | ||||||
| 					localPort, err := local.GetLocalListenPort(deviceiface) | 					localPort, errN := local.GetLocalListenPort(deviceiface) | ||||||
| 					if err != nil { | 					if errN != nil { | ||||||
| 						logger.Log(1, "error encountered checking private ip addresses: ", err.Error()) | 						logger.Log(1, "error encountered checking local listen port: ", err.Error()) | ||||||
| 					} | 					} else if nodeCfg.Node.LocalListenPort != localPort && localPort != 0 { | ||||||
| 					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))) | ||||||
| 						logger.Log(1, "local port has changed from ", string(nodeCfg.Node.LocalListenPort), " to ", string(localPort)) |  | ||||||
| 						nodeCfg.Node.LocalListenPort = localPort | 						nodeCfg.Node.LocalListenPort = localPort | ||||||
| 						if err := PublishNodeUpdate(&nodeCfg); err != nil { | 						if err := PublishNodeUpdate(&nodeCfg); err != nil { | ||||||
| 							logger.Log(0, "could not publish local port change") | 							logger.Log(0, "could not publish local port change") | ||||||
|   | |||||||
| @@ -129,6 +129,7 @@ func GetLocalListenPort(ifacename string) (int32, error) { | |||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return 0, err | 		return 0, err | ||||||
| 	} | 	} | ||||||
|  | 	portstring = strings.TrimSuffix(portstring, "\n") | ||||||
| 	i, err := strconv.ParseInt(portstring, 10, 32) | 	i, err := strconv.ParseInt(portstring, 10, 32) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return 0, err | 		return 0, err | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 afeiszli
					afeiszli