Browse Source

removed localaddress

0xdcarns 2 years ago
parent
commit
368d01ff10
5 changed files with 15 additions and 26 deletions
  1. 0 4
      logic/hosts.go
  2. 1 13
      models/api_host.go
  3. 13 2
      models/api_node.go
  4. 0 1
      models/host.go
  5. 1 6
      models/node.go

+ 0 - 4
logic/hosts.go

@@ -116,10 +116,6 @@ func UpdateHost(newHost, currentHost *models.Host) {
 		newHost.Name = currentHost.Name
 	}
 
-	if newHost.LocalAddress.String() != currentHost.LocalAddress.String() {
-		newHost.LocalAddress = currentHost.LocalAddress
-	}
-
 	if newHost.LocalRange.String() != currentHost.LocalRange.String() {
 		newHost.LocalRange = currentHost.LocalRange
 	}

+ 1 - 13
models/api_host.go

@@ -13,7 +13,6 @@ type ApiHost struct {
 	Debug           bool     `json:"debug"`
 	IsStatic        bool     `json:"isstatic"`
 	ListenPort      int      `json:"listenport"`
-	LocalAddress    string   `json:"localaddress"`
 	LocalRange      string   `json:"localrange"`
 	LocalListenPort int      `json:"locallistenport"`
 	ProxyListenPort int      `json:"proxy_listen_port"`
@@ -42,10 +41,6 @@ func (h *Host) ConvertNMHostToAPI() *ApiHost {
 	}
 	a.IsStatic = h.IsStatic
 	a.ListenPort = h.ListenPort
-	a.LocalAddress = h.LocalAddress.String()
-	if isEmptyAddr(a.LocalAddress) {
-		a.LocalAddress = ""
-	}
 	a.LocalListenPort = h.LocalListenPort
 	a.LocalRange = h.LocalRange.String()
 	if isEmptyAddr(a.LocalRange) {
@@ -94,14 +89,7 @@ func (a *ApiHost) ConvertAPIHostToNMHost(currentHost *Host) *Host {
 	h.Nodes = currentHost.Nodes
 	h.TrafficKeyPublic = currentHost.TrafficKeyPublic
 	h.OS = currentHost.OS
-	if len(a.LocalAddress) > 0 {
-		_, localAddr, err := net.ParseCIDR(a.LocalAddress)
-		if err == nil {
-			h.LocalAddress = *localAddr
-		}
-	} else if !isEmptyAddr(currentHost.LocalAddress.String()) {
-		h.LocalAddress = currentHost.LocalAddress
-	}
+
 	if len(a.LocalRange) > 0 {
 		_, localRange, err := net.ParseCIDR(a.LocalRange)
 		if err == nil {

+ 13 - 2
models/api_node.go

@@ -13,6 +13,7 @@ type ApiNode struct {
 	HostID                  string   `json:"hostid,omitempty" validate:"required,min=5,id_unique"`
 	Address                 string   `json:"address" validate:"omitempty,ipv4"`
 	Address6                string   `json:"address6" validate:"omitempty,ipv6"`
+	LocalAddress            string   `json:"localaddress" validate:"omitempty,ipv4"`
 	PostUp                  string   `json:"postup"`
 	PostDown                string   `json:"postdown"`
 	AllowedIPs              []string `json:"allowedips"`
@@ -50,7 +51,6 @@ func (a *ApiNode) ConvertToServerNode(currentNode *Node) *Node {
 	convertedNode.Server = a.Server
 	convertedNode.Action = currentNode.Action
 	convertedNode.Connected = a.Connected
-	convertedNode.AllowedIPs = a.AllowedIPs
 	convertedNode.ID, _ = uuid.Parse(a.ID)
 	convertedNode.HostID, _ = uuid.Parse(a.HostID)
 	convertedNode.PostUp = a.PostUp
@@ -81,6 +81,14 @@ func (a *ApiNode) ConvertToServerNode(currentNode *Node) *Node {
 	if err == nil {
 		convertedNode.NetworkRange6 = *networkRange6
 	}
+	if len(a.LocalAddress) > 0 {
+		_, localAddr, err := net.ParseCIDR(a.LocalAddress)
+		if err == nil {
+			convertedNode.LocalAddress = *localAddr
+		}
+	} else if !isEmptyAddr(currentNode.LocalAddress.String()) {
+		convertedNode.LocalAddress = currentNode.LocalAddress
+	}
 	udpAddr, err := net.ResolveUDPAddr("udp", a.InternetGateway)
 	if err == nil {
 		convertedNode.InternetGateway = udpAddr
@@ -114,9 +122,12 @@ func (nm *Node) ConvertToAPINode() *ApiNode {
 	if isEmptyAddr(apiNode.Address6) {
 		apiNode.Address6 = ""
 	}
+	apiNode.LocalAddress = nm.LocalAddress.String()
+	if isEmptyAddr(apiNode.LocalAddress) {
+		apiNode.LocalAddress = ""
+	}
 	apiNode.PostDown = nm.PostDown
 	apiNode.PostUp = nm.PostUp
-	apiNode.AllowedIPs = nm.AllowedIPs
 	apiNode.PersistentKeepalive = int32(nm.PersistentKeepalive)
 	apiNode.LastModified = nm.LastModified.Unix()
 	apiNode.LastCheckIn = nm.LastCheckIn.Unix()

+ 0 - 1
models/host.go

@@ -24,7 +24,6 @@ type Host struct {
 	Interface        string           `json:"interface" yaml:"interface"`
 	Debug            bool             `json:"debug" yaml:"debug"`
 	ListenPort       int              `json:"listenport" yaml:"listenport"`
-	LocalAddress     net.IPNet        `json:"localaddress" yaml:"localaddress"`
 	LocalRange       net.IPNet        `json:"localrange" yaml:"localrange"`
 	LocalListenPort  int              `json:"locallistenport" yaml:"locallistenport"`
 	ProxyListenPort  int              `json:"proxy_listen_port" yaml:"proxy_listen_port"`

+ 1 - 6
models/node.go

@@ -69,6 +69,7 @@ type CommonNode struct {
 	PostUp              string               `json:"postup" yaml:"postup"`
 	PostDown            string               `json:"postdown" yaml:"postdown"`
 	Action              string               `json:"action" yaml:"action"`
+	LocalAddress        net.IPNet            `json:"localaddress" yaml:"localaddress"`
 	IsLocal             bool                 `json:"islocal" yaml:"islocal"`
 	IsEgressGateway     bool                 `json:"isegressgateway" yaml:"isegressgateway"`
 	IsIngressGateway    bool                 `json:"isingressgateway" yaml:"isingressgateway"`
@@ -85,7 +86,6 @@ type Node struct {
 	LastCheckIn             time.Time            `json:"lastcheckin" bson:"lastcheckin" yaml:"lastcheckin"`
 	LastPeerUpdate          time.Time            `json:"lastpeerupdate" bson:"lastpeerupdate" yaml:"lastpeerupdate"`
 	ExpirationDateTime      time.Time            `json:"expdatetime" bson:"expdatetime" yaml:"expdatetime"`
-	AllowedIPs              []string             `json:"allowedips" bson:"allowedips" yaml:"allowedips"`
 	EgressGatewayRanges     []string             `json:"egressgatewayranges" bson:"egressgatewayranges" yaml:"egressgatewayranges"`
 	EgressGatewayNatEnabled bool                 `json:"egressgatewaynatenabled" bson:"egressgatewaynatenabled" yaml:"egressgatewaynatenabled"`
 	EgressGatewayRequest    EgressGatewayRequest `json:"egressgatewayrequest" bson:"egressgatewayrequest" yaml:"egressgatewayrequest"`
@@ -381,9 +381,6 @@ func (newNode *Node) Fill(currentNode *Node) { // TODO add new field for nftable
 	if newNode.PostDown == "" {
 		newNode.PostDown = currentNode.PostDown
 	}
-	if newNode.AllowedIPs == nil {
-		newNode.AllowedIPs = currentNode.AllowedIPs
-	}
 	if newNode.PersistentKeepalive < 0 {
 		newNode.PersistentKeepalive = currentNode.PersistentKeepalive
 	}
@@ -503,7 +500,6 @@ func (ln *LegacyNode) ConvertToNewNode() (*Host, *Node) {
 		host.Name = ln.Name
 		host.ListenPort = int(ln.ListenPort)
 		_, cidr, _ := net.ParseCIDR(ln.LocalAddress)
-		host.LocalAddress = *cidr
 		_, cidr, _ = net.ParseCIDR(ln.LocalRange)
 		host.LocalRange = *cidr
 		host.LocalListenPort = int(ln.LocalListenPort)
@@ -552,7 +548,6 @@ func (n *Node) Legacy(h *Host, s *ServerConfig, net *Network) *LegacyNode {
 	l.HostID = h.ID.String()
 	l.Address = n.Address.String()
 	l.Address6 = n.Address6.String()
-	l.LocalAddress = h.LocalAddress.String()
 	l.Interfaces = h.Interfaces
 	l.Name = h.Name
 	l.NetworkSettings = *net