Browse Source

ingress gateway functional

root 4 years ago
parent
commit
884037e228

+ 1 - 1
compose/docker-compose.localserver.yml

@@ -21,6 +21,6 @@ services:
     ports:
       - "80:80"
     environment:
-      BACKEND_URL: "http://HOST_IP:8081"
+      BACKEND_URL: "http://34.228.52.243:8081"
 volumes:
   mongovol: {}

+ 1 - 1
controllers/controller.go

@@ -32,7 +32,7 @@ func HandleRESTRequests(wg *sync.WaitGroup) {
     fileHandlers(r)
     serverHandlers(r)
     extClientHandlers(r)
-
+    intClientHandlers(r)
 
 		port := servercfg.GetAPIPort()
 

+ 6 - 0
controllers/extClientHttpController.go

@@ -294,6 +294,12 @@ func CreateExtClient(extclient models.ExtClient) error {
 	// insert our network into the network table
 	_, err := collection.InsertOne(ctx, extclient)
 	defer cancel()
+	if err != nil {
+		return err
+	}
+
+	err = SetNetworkNodesLastModified(extclient.Network)
+
 	return err
 }
 

+ 35 - 88
controllers/serverClient.go → controllers/intClientHttpController.go

@@ -1,122 +1,67 @@
 package controller
 
 import (
+//	"fmt"
+	"errors"
 	"context"
 	"encoding/json"
-	"fmt"
-
-	// "fmt"
 	"net/http"
 	"time"
-	"strconv"
 	"github.com/gorilla/mux"
 	"github.com/gravitl/netmaker/functions"
 	"github.com/gravitl/netmaker/serverctl"
 	"github.com/gravitl/netmaker/servercfg"
 	"github.com/gravitl/netmaker/models"
 	"github.com/gravitl/netmaker/mongoconn"
-	"go.mongodb.org/mongo-driver/bson"
-	"go.mongodb.org/mongo-driver/mongo/options"
 	"golang.zx2c4.com/wireguard/wgctrl/wgtypes"
-	"github.com/skip2/go-qrcode"
 )
 
-func serverClientHandlers(r *mux.Router) {
+func intClientHandlers(r *mux.Router) {
 
-	r.HandleFunc("/api/wgconf/{macaddress}", securityCheck(http.HandlerFunc(getWGClientConf))).Methods("GET")
-	r.HandleFunc("/api/register", securityCheck(http.HandlerFunc(registerClient))).Methods("POST")
+	r.HandleFunc("/api/intclient/{clientid}", securityCheck(http.HandlerFunc(getIntClient))).Methods("GET")
+	r.HandleFunc("/api/intclients", securityCheck(http.HandlerFunc(getAllIntClients))).Methods("GET")
+        r.HandleFunc("/api/intclients/deleteall", securityCheck(http.HandlerFunc(deleteAllIntClients))).Methods("POST")
+	r.HandleFunc("/api/intclient/register", http.HandlerFunc(registerIntClient)).Methods("POST")
 }
 
-//Get an individual extclient. Nothin fancy here folks.
-func getWGClientConf(w http.ResponseWriter, r *http.Request) {
-        // set header.
+func getAllIntClients(w http.ResponseWriter, r *http.Request) {
         w.Header().Set("Content-Type", "application/json")
-
-        var params = mux.Vars(r)
-
-        var extclient models.ExtClient
-
-        collection := mongoconn.Client.Database("netmaker").Collection("extclients")
-
-        ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
-
-        filter := bson.M{"network": "grpc", "clientid": params["clientid"]}
-        err := collection.FindOne(ctx, filter, options.FindOne().SetProjection(bson.M{"_id": 0})).Decode(&extclient)
+        clients, err := functions.GetAllIntClients()
         if err != nil {
                 returnErrorResponse(w, r, formatError(err, "internal"))
                 return
         }
+        //Return all the extclients in JSON format
+        w.WriteHeader(http.StatusOK)
+        json.NewEncoder(w).Encode(clients)
+}
 
-        gwnode, err := functions.GetNodeByMacAddress(extclient.Network, extclient.IngressGatewayID)
+func deleteAllIntClients(w http.ResponseWriter, r *http.Request) {
+        w.Header().Set("Content-Type", "application/json")
+        err := functions.DeleteAllIntClients()
         if err != nil {
-		fmt.Println("Could not retrieve Ingress Gateway Node " + extclient.IngressGatewayID)
-		returnErrorResponse(w, r, formatError(err, "internal"))
+                returnErrorResponse(w, r, formatError(err, "internal"))
                 return
         }
+        //Return all the extclients in JSON format
+        w.WriteHeader(http.StatusOK)
+}
 
-	network, err := functions.GetParentNetwork(extclient.Network)
+func getIntClient(w http.ResponseWriter, r *http.Request) {
+        w.Header().Set("Content-Type", "application/json")
+        clients, err := functions.GetAllIntClients()
         if err != nil {
-                fmt.Println("Could not retrieve Ingress Gateway Network " + extclient.Network)
                 returnErrorResponse(w, r, formatError(err, "internal"))
                 return
         }
-	keepalive := ""
-	if network.DefaultKeepalive != 0 {
-		keepalive = "PersistentKeepalive = " + strconv.Itoa(int(network.DefaultKeepalive))
-	}
-	gwendpoint := gwnode.Endpoint + ":" + strconv.Itoa(int(gwnode.ListenPort))
-	config := fmt.Sprintf(`[Interface]
-Address = %s
-PrivateKey = %s
-
-[Peer]
-PublicKey = %s
-AllowedIPs = %s
-Endpoint = %s
-%s
-
-`, extclient.Address + "/32",
-   extclient.PrivateKey,
-   gwnode.PublicKey,
-   network.AddressRange,
-   gwendpoint,
-   keepalive)
-
-	if params["type"] == "qr" {
-		bytes, err := qrcode.Encode(config, qrcode.Medium, 220)
-		if err != nil {
-			returnErrorResponse(w, r, formatError(err, "internal"))
-			return
-		}
-		w.Header().Set("Content-Type", "image/png")
-		w.WriteHeader(http.StatusOK)
-		_, err = w.Write(bytes)
-		if err != nil {
-			returnErrorResponse(w, r, formatError(err, "internal"))
-			return
-		}
-		return
-	}
-
-	if params["type"] == "file" {
-		name := extclient.ClientID + ".conf"
-                w.Header().Set("Content-Type", "application/config")
-		w.Header().Set("Content-Disposition", "attachment; filename=\"" + name + "\"")
-		w.WriteHeader(http.StatusOK)
-		_, err := fmt.Fprint(w, config)
-		if err != nil {
-                        returnErrorResponse(w, r, formatError(err, "internal"))
-		}
-		return
-	}
-
-        defer cancel()
-
+        //Return all the extclients in JSON format
         w.WriteHeader(http.StatusOK)
-        json.NewEncoder(w).Encode(extclient)
+        json.NewEncoder(w).Encode(clients)
 }
 
-func RegisterClient(client models.ServerClient) (models.ServerClient, error) {
+
+
+func RegisterIntClient(client models.IntClient) (models.IntClient, error) {
 	if client.PrivateKey == "" {
 		privateKey, err := wgtypes.GeneratePrivateKey()
 		if err != nil {
@@ -132,6 +77,9 @@ func RegisterClient(client models.ServerClient) (models.ServerClient, error) {
 		if err != nil {
 			return client, err
 		}
+		if newAddress == "" {
+			return client, errors.New("Could not find an address.")
+		}
 		client.Address6 = newAddress
 	}
         if client.Network == "" { client.Network = "comms" }
@@ -144,8 +92,7 @@ func RegisterClient(client models.ServerClient) (models.ServerClient, error) {
 	client.ServerPort = server.ServerPort
 	client.ServerKey = server.ServerKey
 
-
-	collection := mongoconn.Client.Database("netmaker").Collection("serverclients")
+	collection := mongoconn.Client.Database("netmaker").Collection("intclients")
 	ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
 	// insert our network into the network table
 	_, err = collection.InsertOne(ctx, client)
@@ -159,14 +106,14 @@ func RegisterClient(client models.ServerClient) (models.ServerClient, error) {
 
 	return client, err
 }
-func registerClient(w http.ResponseWriter, r *http.Request) {
+func registerIntClient(w http.ResponseWriter, r *http.Request) {
         w.Header().Set("Content-Type", "application/json")
 
         var errorResponse = models.ErrorResponse{
                 Code: http.StatusInternalServerError, Message: "W1R3: It's not you it's me.",
         }
 
-        var clientreq models.ServerClient
+        var clientreq models.IntClient
 
         //get node from body of request
         err := json.NewDecoder(r.Body).Decode(&clientreq)
@@ -184,7 +131,7 @@ func registerClient(w http.ResponseWriter, r *http.Request) {
                                 return
                 }
         }
-        client, err := RegisterClient(clientreq)
+        client, err := RegisterIntClient(clientreq)
 
         if err != nil {
                 returnErrorResponse(w, r, formatError(err, "internal"))

+ 3 - 2
controllers/nodeGrpcController.go

@@ -62,6 +62,7 @@ func (s *NodeServiceServer) ReadNode(ctx context.Context, req *nodepb.ReadNodeRe
 			Dnsoff:          !servercfg.IsDNSMode(),
 			Ispending:       node.IsPending,
 			Isingressgateway:       node.IsIngressGateway,
+			Ingressgatewayrange:       node.IngressGatewayRange,
 			Publickey:       node.PublicKey,
 			Listenport:      node.ListenPort,
 			Keepalive:       node.PersistentKeepalive,
@@ -77,7 +78,7 @@ func (s *NodeServiceServer) GetConn(ctx context.Context, data *nodepb.Client) (*
         // Get the protobuf node type from the protobuf request type
         // Essentially doing req.Node to access the struct with a nil check
         // Now we have to convert this into a NodeItem type to convert into BSON
-        clientreq := models.ServerClient{
+        clientreq := models.IntClient{
                 // ID:       primitive.NilObjectID,
                 Address:             data.GetAddress(),
                 Address6:            data.GetAddress6(),
@@ -100,7 +101,7 @@ func (s *NodeServiceServer) GetConn(ctx context.Context, data *nodepb.Client) (*
                         )
 		}
 	}
-	client, err := RegisterClient(clientreq)
+	client, err := RegisterIntClient(clientreq)
 
         if err != nil {
                 // return internal gRPC error to be handled later

+ 64 - 39
controllers/nodeHttpController.go

@@ -8,7 +8,7 @@ import (
 	"net/http"
 	"strings"
 	"time"
-
+	"log"
 	"github.com/gorilla/mux"
 	"github.com/gravitl/netmaker/functions"
 	"github.com/gravitl/netmaker/models"
@@ -244,7 +244,7 @@ func getNetworkNodes(w http.ResponseWriter, r *http.Request) {
 
 	w.Header().Set("Content-Type", "application/json")
 
-	var nodes []models.ReturnNode
+	var nodes []models.Node
 	var params = mux.Vars(r)
 	nodes, err := GetNetworkNodes(params["network"])
 	if err != nil {
@@ -257,34 +257,34 @@ func getNetworkNodes(w http.ResponseWriter, r *http.Request) {
 	json.NewEncoder(w).Encode(nodes)
 }
 
-func GetNetworkNodes(network string) ([]models.ReturnNode, error) {
-	var nodes []models.ReturnNode
+func GetNetworkNodes(network string) ([]models.Node, error) {
+	var nodes []models.Node
 	collection := mongoconn.Client.Database("netmaker").Collection("nodes")
 	ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
 	filter := bson.M{"network": network}
 	//Filtering out the ID field cuz Dillon doesn't like it. May want to filter out other fields in the future
 	cur, err := collection.Find(ctx, filter, options.Find().SetProjection(bson.M{"_id": 0}))
 	if err != nil {
-		return []models.ReturnNode{}, err
+		return []models.Node{}, err
 	}
 	defer cancel()
 	for cur.Next(context.TODO()) {
-		//Using a different model for the ReturnNode (other than regular node).
+		//Using a different model for the Node (other than regular node).
 		//Either we should do this for ALL structs (so Networks and Keys)
 		//OR we should just use the original struct
 		//My preference is to make some new return structs
 		//TODO: Think about this. Not an immediate concern. Just need to get some consistency eventually
-		var node models.ReturnNode
+		var node models.Node
 		err := cur.Decode(&node)
 		if err != nil {
-			return []models.ReturnNode{}, err
+			return []models.Node{}, err
 		}
 		// add item our array of nodes
 		nodes = append(nodes, node)
 	}
 	//TODO: Another fatal error we should take care of.
 	if err := cur.Err(); err != nil {
-		return []models.ReturnNode{}, err
+		return []models.Node{}, err
 	}
 	return nodes, nil
 }
@@ -581,7 +581,7 @@ func CreateEgressGateway(gateway models.EgressGatewayRequest) (models.Node, erro
 			{"postup", nodechange.PostUp},
 			{"postdown", nodechange.PostDown},
 			{"isegressgateway", nodechange.IsEgressGateway},
-			{"gatewayrange", nodechange.EgressGatewayRange},
+			{"egressgatewayrange", nodechange.EgressGatewayRange},
 			{"lastmodified", nodechange.LastModified},
 		}},
 	}
@@ -687,35 +687,60 @@ func createIngressGateway(w http.ResponseWriter, r *http.Request) {
 	json.NewEncoder(w).Encode(node)
 }
 
-func CreateIngressGateway(network string, macaddress string) (models.Node, error) {
-	node, err := functions.GetNodeByMacAddress(network, macaddress)
-	if err != nil {
-		return models.Node{}, err
-	}
-
-	collection := mongoconn.Client.Database("netmaker").Collection("nodes")
-	ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
-	// Create filter
-	filter := bson.M{"macaddress": macaddress, "network": network}
-	// prepare update model.
-	update := bson.D{
-		{"$set", bson.D{
-			{"isingressgateway", true},
-			{"lastmodified", time.Now().Unix()},
-		}},
-	}
-	var nodeupdate models.Node
-	err = collection.FindOneAndUpdate(ctx, filter, update).Decode(&nodeupdate)
-	defer cancel()
-	if err != nil {
-		return models.Node{}, err
-	}
-	//Get updated values to return
-	node, err = functions.GetNodeByMacAddress(network, macaddress)
-	if err != nil {
-		return models.Node{}, err
-	}
-	return node, nil
+func CreateIngressGateway(netid string, macaddress string) (models.Node, error) {
+
+	node, err := functions.GetNodeByMacAddress(netid, macaddress)
+        if err != nil {
+                return models.Node{}, err
+        }
+
+        network, err := functions.GetParentNetwork(netid)
+        if err != nil {
+		log.Println("Could not find network.")
+                return models.Node{}, err
+        }
+
+	if node.IsEgressGateway {
+		errors.New("Node cannot be both Ingress and Egress Gateway in same network.")
+                return models.Node{}, err
+	}
+
+	node.IngressGatewayRange = network.AddressRange
+        node.PostUp = "iptables -A FORWARD -i " + node.Interface + " -j ACCEPT; iptables -t nat -A POSTROUTING -o " + node.Interface + " -j MASQUERADE"
+        node.PostDown = "iptables -D FORWARD -i " + node.Interface + " -j ACCEPT; iptables -t nat -D POSTROUTING -o " + node.Interface + " -j MASQUERADE"
+        collection := mongoconn.Client.Database("netmaker").Collection("nodes")
+        ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
+        // Create filter
+        filter := bson.M{"macaddress": macaddress, "network": netid}
+        node.SetLastModified()
+        // prepare update model.
+        update := bson.D{
+                {"$set", bson.D{
+                        {"postup", node.PostUp},
+                        {"postdown", node.PostDown},
+                        {"isingressgateway", true},
+                        {"ingressgatewayrange", node.IngressGatewayRange},
+                        {"lastmodified", node.LastModified},
+                }},
+        }
+        var nodeupdate models.Node
+        err = collection.FindOneAndUpdate(ctx, filter, update).Decode(&nodeupdate)
+        defer cancel()
+        if err != nil {
+		log.Println("error updating node to gateway")
+                return models.Node{}, err
+        }
+        err = SetNetworkNodesLastModified(netid)
+        if err != nil {
+                return node, err
+        }
+        //Get updated values to return
+        node, err = functions.GetNodeByMacAddress(netid, macaddress)
+        if err != nil {
+		log.Println("error finding node after update")
+                return node, err
+        }
+        return node, nil
 }
 
 func deleteIngressGateway(w http.ResponseWriter, r *http.Request) {

+ 145 - 12
functions/helpers.go

@@ -123,6 +123,47 @@ func GetPeersList(networkName string) ([]models.PeersResponse, error) {
         return peers, err
 }
 
+func GetIntPeersList() ([]models.PeersResponse, error) {
+
+        var peers []models.PeersResponse
+
+        collection := mongoconn.Client.Database("netmaker").Collection("intclients")
+
+        ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
+
+        filter := bson.M{"isserver": ""}
+
+        cur, err := collection.Find(ctx, filter)
+
+        if err != nil {
+                return peers, err
+        }
+
+        // Close the cursor once finished and cancel if it takes too long
+        defer cancel()
+
+        for cur.Next(context.TODO()) {
+
+                var peer models.PeersResponse
+                err := cur.Decode(&peer)
+                if err != nil {
+                        log.Fatal(err)
+                }
+
+                // add the node to our node array
+                //maybe better to just return this? But then that's just GetNodes...
+                peers = append(peers, peer)
+        }
+
+        //Uh oh, fatal error! This needs some better error handling
+        //TODO: needs appropriate error handling so the server doesnt shut down.
+        if err := cur.Err(); err != nil {
+                log.Fatal(err)
+        }
+
+        return peers, err
+}
+
 func IsFieldUnique(network string, field string, value string) bool {
 
 	var node models.Node
@@ -148,6 +189,27 @@ func IsFieldUnique(network string, field string, value string) bool {
 	return isunique
 }
 
+func ServerIntClientExists() (bool, error) {
+
+        collection := mongoconn.Client.Database("netmaker").Collection("intclients")
+
+        ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
+
+        filter := bson.M{"isserver": "yes"}
+
+        var result bson.M
+        err := collection.FindOne(ctx, filter).Decode(&result)
+
+        defer cancel()
+
+        if err != nil {
+                if err == mongo.ErrNoDocuments {
+                        return false, nil
+                }
+        }
+        return true, err
+}
+
 func NetworkExists(name string) (bool, error) {
 
 	collection := mongoconn.Client.Database("netmaker").Collection("networks")
@@ -548,6 +610,45 @@ func GetNodeByMacAddress(network string, macaddress string) (models.Node, error)
 	return node, nil
 }
 
+func DeleteAllIntClients() error {
+        collection := mongoconn.Client.Database("netmaker").Collection("intclients")
+        ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
+        // Filter out them ID's again
+        err := collection.Drop(ctx)
+        if err != nil {
+                return err
+        }
+        defer cancel()
+        return nil
+}
+
+func GetAllIntClients() ([]models.IntClient, error) {
+        var client models.IntClient
+        var clients []models.IntClient
+        collection := mongoconn.Client.Database("netmaker").Collection("intclients")
+        ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
+        // Filter out them ID's again
+        cur, err := collection.Find(ctx, bson.M{}, options.Find().SetProjection(bson.M{"_id": 0}))
+        if err != nil {
+                return []models.IntClient{}, err
+        }
+        defer cancel()
+        for cur.Next(context.TODO()) {
+                err := cur.Decode(&client)
+                if err != nil {
+                        return []models.IntClient{}, err
+                }
+                // add node to our array
+                clients = append(clients, client)
+        }
+
+        //TODO: Fatal error
+        if err := cur.Err(); err != nil {
+                return []models.IntClient{}, err
+        }
+        return clients, nil
+}
+
 func GetAllExtClients() ([]models.ExtClient, error) {
         var extclient models.ExtClient
         var extclients []models.ExtClient
@@ -619,7 +720,9 @@ func UniqueAddress6(networkName string) (string, error) {
 		return "", err
 	}
 	if network.IsDualStack == nil || *network.IsDualStack == false {
-		return "", nil
+		if networkName != "comms" {
+			return "", nil
+		}
 	}
 
 	offset := true
@@ -633,8 +736,14 @@ func UniqueAddress6(networkName string) (string, error) {
 			offset = false
 			continue
 		}
-		if IsIP6Unique(networkName, ip.String()) {
-			return ip.String(), err
+		if networkName == "comms" {
+	                if IsIP6UniqueClients(networkName, ip.String()) {
+	                        return ip.String(), err
+	                }
+		} else {
+			if IsIP6Unique(networkName, ip.String()) {
+				return ip.String(), err
+			}
 		}
 	}
 	//TODO
@@ -693,7 +802,6 @@ func IsIPUniqueExtClients(network string, ip string) bool {
         defer cancel()
 
         if err != nil {
-                fmt.Println(err)
                 return isunique
         }
 
@@ -722,7 +830,6 @@ func IsIPUnique(network string, ip string) bool {
 	defer cancel()
 
 	if err != nil {
-		fmt.Println(err)
 		return isunique
 	}
 
@@ -750,7 +857,6 @@ func IsIP6Unique(network string, ip string) bool {
 	defer cancel()
 
 	if err != nil {
-		fmt.Println(err)
 		return isunique
 	}
 
@@ -760,6 +866,33 @@ func IsIP6Unique(network string, ip string) bool {
 	return isunique
 }
 
+//checks if IP is unique in the address range
+//used by UniqueAddress
+func IsIP6UniqueClients(network string, ip string) bool {
+
+        var client models.IntClient
+
+        isunique := true
+
+        collection := mongoconn.Client.Database("netmaker").Collection("intclients")
+        ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
+
+        filter := bson.M{"address6": ip, "network": network}
+
+        err := collection.FindOne(ctx, filter).Decode(&client)
+
+        defer cancel()
+
+        if err != nil {
+                return isunique
+        }
+
+        if client.Address6 == ip {
+                isunique = false
+        }
+        return isunique
+}
+
 //called once key has been used by createNode
 //reduces value by one and deletes if necessary
 func DecrimentKey(networkName string, keyvalue string) {
@@ -844,21 +977,21 @@ func Inc(ip net.IP) {
 	}
 }
 
-func GetAllNodes() ([]models.ReturnNode, error) {
-	var node models.ReturnNode
-	var nodes []models.ReturnNode
+func GetAllNodes() ([]models.Node, error) {
+	var node models.Node
+	var nodes []models.Node
 	collection := mongoconn.Client.Database("netmaker").Collection("nodes")
 	ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
 	// Filter out them ID's again
 	cur, err := collection.Find(ctx, bson.M{}, options.Find().SetProjection(bson.M{"_id": 0}))
 	if err != nil {
-		return []models.ReturnNode{}, err
+		return []models.Node{}, err
 	}
 	defer cancel()
 	for cur.Next(context.TODO()) {
 		err := cur.Decode(&node)
 		if err != nil {
-			return []models.ReturnNode{}, err
+			return []models.Node{}, err
 		}
 		// add node to our array
 		nodes = append(nodes, node)
@@ -866,7 +999,7 @@ func GetAllNodes() ([]models.ReturnNode, error) {
 
 	//TODO: Fatal error
 	if err := cur.Err(); err != nil {
-		return []models.ReturnNode{}, err
+		return []models.Node{}, err
 	}
 	return nodes, nil
 }

+ 3 - 2
go.mod

@@ -6,7 +6,7 @@ require (
 	github.com/davecgh/go-spew v1.1.1 // indirect
 	github.com/dgrijalva/jwt-go v3.2.0+incompatible
 	github.com/go-playground/validator/v10 v10.5.0
-	github.com/golang/protobuf v1.4.3 // indirect
+	github.com/golang/protobuf v1.5.2 // indirect
 	github.com/gorilla/handlers v1.5.1
 	github.com/gorilla/mux v1.8.0
 	github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e // indirect
@@ -25,6 +25,7 @@ require (
 	golang.zx2c4.com/wireguard/wgctrl v0.0.0-20200609130330-bd2cb7843e1b
 	google.golang.org/genproto v0.0.0-20210201151548-94839c025ad4 // indirect
 	google.golang.org/grpc v1.35.0
-	google.golang.org/protobuf v1.25.0
+	google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.1.0 // indirect
+	google.golang.org/protobuf v1.26.0
 	gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c
 )

+ 9 - 0
go.sum

@@ -73,6 +73,9 @@ github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QD
 github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
 github.com/golang/protobuf v1.4.3 h1:JjCZWpVbqXDqFVmTfYWEVTMIYrL/NPdPSCHPJ0T/raM=
 github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
+github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
+github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw=
+github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
 github.com/golang/snappy v0.0.1 h1:Qgr9rKW7uDUkrbSmQeiDsGa8SjGyCOGtuasMWwvp2P4=
 github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
 github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
@@ -82,6 +85,7 @@ github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/
 github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
 github.com/google/go-cmp v0.5.2 h1:X2ev0eStA3AbceY54o37/0PQ/UWqKEiiO2dKL5OPaFM=
 github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
+github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
 github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
 github.com/gorilla/handlers v1.5.1 h1:9lRY6j8DEeeBT10CvO9hGW0gmky0BprnvDI5vfhUHH4=
 github.com/gorilla/handlers v1.5.1/go.mod h1:t8XrUpc4KVXb7HGyJ4/cEnwQiaxrX/hz1Zv/4g96P1Q=
@@ -269,6 +273,8 @@ google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQ
 google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk=
 google.golang.org/grpc v1.35.0 h1:TwIQcH3es+MojMVojxxfQ3l3OF2KzlRxML2xZq0kRo8=
 google.golang.org/grpc v1.35.0/go.mod h1:qjiiYl8FncCW8feJPdyg3v6XW24KsRHe+dy9BAGRRjU=
+google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.1.0 h1:M1YKkFIboKNieVO5DLUEVzQfGwJD30Nv2jfUgzb5UcE=
+google.golang.org/grpc/cmd/protoc-gen-go-grpc v1.1.0/go.mod h1:6Kw0yEErY5E/yWrBtf03jp27GLLJujG4z/JK95pnjjw=
 google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
 google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=
 google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM=
@@ -280,6 +286,9 @@ google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpAD
 google.golang.org/protobuf v1.24.0/go.mod h1:r/3tXBNzIEhYS9I1OUVjXDlt8tc493IdKGjtUeSXeh4=
 google.golang.org/protobuf v1.25.0 h1:Ejskq+SyPohKW+1uil0JJMtmHCgJPJ/qWTxr8qp+R4c=
 google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c=
+google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
+google.golang.org/protobuf v1.26.0 h1:bxAC2xTBsZGibn2RTntX0oH50xLsqy1OxA9tTL3p/lk=
+google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
 gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
 gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
 gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=

+ 87 - 70
grpc/node.pb.go

@@ -140,6 +140,7 @@ type Node struct {
 	Allowedips           string   `protobuf:"bytes,22,opt,name=allowedips,proto3" json:"allowedips,omitempty"`
 	Islocal              bool     `protobuf:"varint,23,opt,name=islocal,proto3" json:"islocal,omitempty"`
 	Isingressgateway     bool     `protobuf:"varint,28,opt,name=isingressgateway,proto3" json:"isingressgateway,omitempty"`
+	Ingressgatewayrange  string   `protobuf:"bytes,29,opt,name=ingressgatewayrange,proto3" json:"ingressgatewayrange,omitempty"`
 	Isdualstack          bool     `protobuf:"varint,27,opt,name=isdualstack,proto3" json:"isdualstack,omitempty"`
 	Dnsoff               bool     `protobuf:"varint,24,opt,name=dnsoff,proto3" json:"dnsoff,omitempty"`
 	Localrange           string   `protobuf:"bytes,25,opt,name=localrange,proto3" json:"localrange,omitempty"`
@@ -348,6 +349,13 @@ func (m *Node) GetIsingressgateway() bool {
 	return false
 }
 
+func (m *Node) GetIngressgatewayrange() string {
+	if m != nil {
+		return m.Ingressgatewayrange
+	}
+	return ""
+}
+
 func (m *Node) GetIsdualstack() bool {
 	if m != nil {
 		return m.Isdualstack
@@ -459,6 +467,7 @@ func (m *CheckInResponse) GetNeeddelete() bool {
 type PeersResponse struct {
 	Isegressgateway      bool     `protobuf:"varint,1,opt,name=isegressgateway,proto3" json:"isegressgateway,omitempty"`
 	Egressgatewayrange   string   `protobuf:"bytes,2,opt,name=egressgatewayrange,proto3" json:"egressgatewayrange,omitempty"`
+	Ingressgatewayrange  string   `protobuf:"bytes,9,opt,name=ingressgatewayrange,proto3" json:"ingressgatewayrange,omitempty"`
 	Publickey            string   `protobuf:"bytes,5,opt,name=publickey,proto3" json:"publickey,omitempty"`
 	Endpoint             string   `protobuf:"bytes,6,opt,name=endpoint,proto3" json:"endpoint,omitempty"`
 	Address              string   `protobuf:"bytes,3,opt,name=address,proto3" json:"address,omitempty"`
@@ -510,6 +519,13 @@ func (m *PeersResponse) GetEgressgatewayrange() string {
 	return ""
 }
 
+func (m *PeersResponse) GetIngressgatewayrange() string {
+	if m != nil {
+		return m.Ingressgatewayrange
+	}
+	return ""
+}
+
 func (m *PeersResponse) GetPublickey() string {
 	if m != nil {
 		return m.Publickey
@@ -1346,74 +1362,75 @@ func init() {
 func init() { proto.RegisterFile("grpc/node.proto", fileDescriptor_d13bd996b67da4ef) }
 
 var fileDescriptor_d13bd996b67da4ef = []byte{
-	// 1093 bytes of a gzipped FileDescriptorProto
-	0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff,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x7e, 0x0d, 0x00, 0x00,
+	// 1112 bytes of a gzipped FileDescriptorProto
+	0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xdc, 0x57, 0x4f, 0x6f, 0x23, 0x35,
+	0x14, 0x57, 0xd2, 0xa6, 0x49, 0x5f, 0x9a, 0xb6, 0xeb, 0xee, 0x16, 0x13, 0x96, 0x55, 0x15, 0xa1,
+	0x55, 0x17, 0xd1, 0xa6, 0x14, 0x69, 0x85, 0xc4, 0x01, 0x89, 0x2e, 0xaa, 0x40, 0xb0, 0x82, 0x41,
+	0x5c, 0xb8, 0xb9, 0x33, 0x2f, 0xb3, 0x56, 0xa6, 0xf6, 0x74, 0xec, 0x24, 0xdb, 0x1b, 0x17, 0x6e,
+	0x7c, 0x21, 0xbe, 0x0f, 0x57, 0xbe, 0x03, 0xf2, 0x9f, 0xc9, 0x78, 0xa6, 0xe9, 0x9f, 0x65, 0x6f,
+	0xdc, 0xc6, 0x3f, 0xbf, 0xbf, 0xbf, 0xe7, 0xf7, 0xec, 0x81, 0x9d, 0xb4, 0xc8, 0xe3, 0xb1, 0x90,
+	0x09, 0x1e, 0xe7, 0x85, 0xd4, 0x92, 0xac, 0x9b, 0xef, 0x51, 0x02, 0x5b, 0x3f, 0xc8, 0x94, 0x8b,
+	0x08, 0xaf, 0x66, 0xa8, 0x34, 0x79, 0x06, 0x70, 0xc9, 0x62, 0x96, 0x24, 0x05, 0x2a, 0x45, 0x5b,
+	0x07, 0xad, 0xc3, 0xcd, 0x28, 0x40, 0xc8, 0x10, 0x7a, 0x39, 0x53, 0x6a, 0x21, 0x8b, 0x84, 0xb6,
+	0xed, 0xee, 0x72, 0x4d, 0x28, 0x74, 0x05, 0xea, 0x85, 0x2c, 0xa6, 0x74, 0xcd, 0x6e, 0x95, 0xcb,
+	0xd1, 0xe7, 0x30, 0xf0, 0x5e, 0x54, 0x2e, 0x85, 0x42, 0x72, 0x00, 0x7d, 0x16, 0xc7, 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3a, 0xb6, 0xbf, 0x6c, 0x17, 0xb3, 0xc9, 0x58, 0x5f, 0xe7, 0xa8, 0xc6, 0x53, 0x21, 0x17,
+	0xc2, 0xfe, 0xcc, 0xe5, 0x17, 0x17, 0x1b, 0x76, 0xf3, 0x8b, 0x7f, 0x03, 0x00, 0x00, 0xff, 0xff,
+	0xf3, 0x46, 0x2a, 0x24, 0xe2, 0x0d, 0x00, 0x00,
 }

+ 2 - 0
grpc/node.proto

@@ -47,6 +47,7 @@ message Node {
     string allowedips = 22;
     bool islocal = 23;
     bool isingressgateway = 28;
+    string ingressgatewayrange = 29;
     bool isdualstack = 27;
     bool dnsoff = 24;
     string localrange = 25;
@@ -65,6 +66,7 @@ message CheckInResponse {
 message PeersResponse {
     bool isegressgateway = 1;
     string egressgatewayrange = 2;
+    string ingressgatewayrange = 9;
     string publickey = 5;
     string endpoint = 6;
     string address = 3;

+ 12 - 8
main.go

@@ -9,6 +9,7 @@ import (
     "github.com/gravitl/netmaker/servercfg"
     "github.com/gravitl/netmaker/serverctl"
     "github.com/gravitl/netmaker/mongoconn"
+    "github.com/gravitl/netmaker/functions"
     "fmt"
     "os"
     "os/exec"
@@ -60,14 +61,17 @@ func main() {
 	}
 
 	if servercfg.IsGRPCWireGuard() {
-		err = serverctl.InitServerWireGuard()
-                if err != nil {
-                        log.Fatal(err)
-                }
-		err = serverctl.ReconfigureServerWireGuard()
-                if err != nil {
-                        log.Fatal(err)
-                }
+		exists, err := functions.ServerIntClientExists()
+		if err == nil && !exists {
+			err = serverctl.InitServerWireGuard()
+	                if err != nil {
+	                        log.Fatal(err)
+	                }
+			err = serverctl.ReconfigureServerWireGuard()
+	                if err != nil {
+	                        log.Fatal(err)
+	                }
+		}
 	}
 	//NOTE: Removed Check and Logic for DNS Mode
 	//Reasoning. DNS Logic is very small on server. Can run with little/no impact. Just sets a tiny config file.

+ 2 - 2
models/serverclient.go → models/intclient.go

@@ -2,10 +2,10 @@ package models
 
 import (
 )
-type ServerClient struct {
+type IntClient struct {
 	PrivateKey     string             `json:"privatekey" bson:"privatekey"`
 	PublicKey      string             `json:"publickey" bson:"publickey"`
-	AccessKey      string             `json:"publickey" bson:"accesskey"`
+	AccessKey      string             `json:"accesskey" bson:"accesskey"`
 	Address        string             `json:"address" bson:"address"`
 	Address6        string             `json:"address6" bson:"address6"`
 	Network        string             `json:"network" bson:"network"`

+ 2 - 1
models/node.go

@@ -45,7 +45,8 @@ type Node struct {
 	IsPending           bool               `json:"ispending" bson:"ispending"`
 	IsEgressGateway           bool               `json:"isegressgateway" bson:"isegressgateway"`
 	IsIngressGateway           bool               `json:"isingressgateway" bson:"isingressgateway"`
-	EgressGatewayRange        string             `json:"gatewayrange" bson:"gatewayrange"`
+	EgressGatewayRange        string             `json:"egressgatewayrange" bson:"egressgatewayrange"`
+	IngressGatewayRange        string             `json:"ingressgatewayrange" bson:"ingressgatewayrange"`
 	PostChanges         string             `json:"postchanges" bson:"postchanges"`
 }
 

+ 0 - 27
models/returnNode.go

@@ -1,27 +0,0 @@
-//TODO:  Either add a returnNetwork and returnKey, or delete this
-package models
-
-type ReturnNode struct {
-	Address	string `json:"address" bson:"address"`
-	Address6 string `json:"address6" bson:"address6"`
-	Name	string `json:"name" bson:"name"`
-	MacAddress string `json:"macaddress" bson:"macaddress"`
-	LastCheckIn int64 `json:"lastcheckin" bson:"lastcheckin"`
-	LastModified int64 `json:"lastmodified" bson:"lastmodified"`
-	LastPeerUpdate int64 `json:"lastpeerupdate" bson:"lastpeerupdate"`
-	ListenPort	int32 `json:"listenport" bson:"listenport"`
-	PublicKey	string `json:"publickey" bson:"publickey" validate:"base64"`
-	Endpoint	string `json:"endpoint" bson:"endpoint" validate:"required,ipv4"`
-	PostUp	string `json:"postup" bson:"postup"`
-	PostDown	string `json:"postdown" bson:"postdown"`
-	PersistentKeepalive int32 `json:"persistentkeepalive" bson:"persistentkeepalive"`
-	SaveConfig	*bool `json:"saveconfig" bson:"saveconfig"`
-	Interface	string `json:"interface" bson:"interface"`
-	Network	string `json:"network" bson:"network"`
-	IsPending	bool `json:"ispending" bson:"ispending"`
-	IsEgressGateway	bool `json:"isegressgateway" bson:"isegressgateway"`
-	IsIngressGateway	bool `json:"isingressgateway" bson:"isingressgateway"`
-	EgressGatewayRange	string `json:"egressgatewayrange" bson:"egressgatewayrange"`
-        LocalAddress    string `json:"localaddress" bson:"localaddress" validate:"localaddress_check"`
-        ExpirationDateTime      int64 `json:"expdatetime" bson:"expdatetime"`
-}

+ 2 - 2
models/structs.go

@@ -95,8 +95,8 @@ type PeersResponse struct {
 	Address      string `json:"address" bson:"address"`
 	Address6     string `json:"address6" bson:"address6"`
 	LocalAddress string `json:"localaddress" bson:"localaddress"`
-	IsEgressGateway    bool   `json:"isgateway" bson:"isgateway"`
-	EgressGatewayRange string `json:"gatewayrange" bson:"gatewayrange"`
+	IsEgressGateway    bool   `json:"isegressgateway" bson:"isegressgateway"`
+	EgressGatewayRange string `json:"egressgatewayrange" bson:"egressgatewayrange"`
 	ListenPort   int32  `json:"listenport" bson:"listenport"`
 	KeepAlive    int32  `json:"persistentkeepalive" bson:"persistentkeepalive"`
 }

+ 2 - 2
netclient/config/config.go

@@ -14,7 +14,7 @@ import (
 	"github.com/gravitl/netmaker/models"
 )
 type GlobalConfig struct {
-	Client models.ServerClient
+	Client models.IntClient
 }
 
 type ClientConfig struct {
@@ -222,7 +222,7 @@ func(config *ClientConfig) ReadConfig() {
 		}
 	}
 }
-func ModGlobalConfig(cfg models.ServerClient) error{
+func ModGlobalConfig(cfg models.IntClient) error{
         var modconfig GlobalConfig
         var err error
         if FileExists("/etc/netclient/netconfig-global-001") {

+ 2 - 2
netclient/functions/register.go

@@ -13,7 +13,7 @@ import (
 
 func Register(cfg config.GlobalConfig) error {
 
-        postclient := &models.ServerClient{
+        postclient := &models.IntClient{
                 AccessKey: cfg.Client.AccessKey,
                 PublicKey: cfg.Client.PublicKey,
                 PrivateKey: cfg.Client.PublicKey,
@@ -38,7 +38,7 @@ func Register(cfg config.GlobalConfig) error {
 	if err != nil {
 		return err
 	}
-	var wgclient models.ServerClient
+	var wgclient models.IntClient
 	json.Unmarshal(bodyBytes, &wgclient)
         err = config.ModGlobalConfig(wgclient)
         if err != nil {

+ 1 - 1
netclient/wireguard/kernel.go

@@ -23,7 +23,7 @@ import (
 	"golang.zx2c4.com/wireguard/wgctrl/wgtypes"
 	//homedir "github.com/mitchellh/go-homedir"
 )
-func InitGRPCWireguard(client models.ServerClient) error {
+func InitGRPCWireguard(client models.IntClient) error {
         key, err := wgtypes.ParseKey(client.PrivateKey)
         if err !=  nil {
                 return err

+ 10 - 0
servercfg/serverconf.go

@@ -70,6 +70,11 @@ func GetAPIHost() string {
 		serverhost = config.Config.Server.APIHost
         } else if os.Getenv("SERVER_HOST") != ""  {
                 serverhost = os.Getenv("SERVER_HOST")
+        } else {
+                remoteip, _ := GetPublicIP()
+                if remoteip != "" {
+                        serverhost = remoteip
+                }
         }
 	return serverhost
 }
@@ -91,6 +96,11 @@ func GetGRPCHost() string {
 	       serverhost = config.Config.Server.GRPCHost
 	} else if os.Getenv("SERVER_HOST") != ""  {
 	       serverhost = os.Getenv("SERVER_HOST")
+	} else {
+	        remoteip, _ := GetPublicIP()
+		if remoteip != "" {
+			serverhost = remoteip
+		}
 	}
         return serverhost
 }

+ 1 - 1
servercfg/wireguardconf.go

@@ -40,7 +40,7 @@ func GetGRPCWGInterface() string {
        return iface
 }
 func GetGRPCWGAddress() string {
-        address := "fd73:0093:84f3:a13d:0000:0000:0000:0001"
+        address := "10.101.0.1"
       if os.Getenv("SERVER_GRPC_WG_ADDRESS") != ""  {
               address = os.Getenv("SERVER_GRPC_WG_ADDRESS")
       } else if config.Config.WG.GRPCWGAddress != "" {

+ 3 - 3
serverctl/serverctl.go

@@ -61,9 +61,9 @@ func CreateDefaultNetwork() (bool, error) {
 
 }
 
-func GetServerWGConf() (models.ServerClient, error) {
-        var server models.ServerClient
-        collection := mongoconn.Client.Database("netmaker").Collection("serverclients")
+func GetServerWGConf() (models.IntClient, error) {
+        var server models.IntClient
+        collection := mongoconn.Client.Database("netmaker").Collection("intclients")
         ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
 	filter := bson.M{"network": "comms", "isserver": "yes"}
         err := collection.FindOne(ctx, filter, options.FindOne().SetProjection(bson.M{"_id": 0})).Decode(&server)

+ 17 - 16
serverctl/wireguard.go

@@ -44,7 +44,7 @@ func InitServerWireGuard() error {
 			return err
 		}
 	}
-	address, err := netlink.ParseAddr(wgconfig.GRPCWGAddress + "/32")
+	address, err := netlink.ParseAddr(wgconfig.GRPCWGAddress + "/24")
 	if err != nil {
 		return err
 	}
@@ -63,18 +63,20 @@ func InitServerWireGuard() error {
 		log.Println("could not bring up wireguard interface")
 		return err
 	}
-	var client models.ServerClient
-	client.PrivateKey = servercfg.GetGRPCWGPrivKey()
-	client.PublicKey = servercfg.GetGRPCWGPubKey()
-	client.ServerEndpoint = servercfg.GetGRPCHost()
-	client.Address6 = servercfg.GetGRPCWGAddress()
+	var client models.IntClient
+	client.PrivateKey = wgconfig.GRPCWGPrivKey
+	client.PublicKey = wgconfig.GRPCWGPubKey
+	client.ServerEndpoint = wgconfig.GRPCWGEndpoint
+	client.ServerAddress = wgconfig.GRPCWGAddress
+	client.ServerPort = wgconfig.GRPCWGPort
+	client.Address = wgconfig.GRPCWGAddress
 	client.IsServer = "yes"
 	client.Network = "comms"
 	err = RegisterServer(client)
         return err
 }
 
-func RegisterServer(client models.ServerClient) error {
+func RegisterServer(client models.IntClient) error {
         if client.PrivateKey == "" {
                 privateKey, err := wgtypes.GeneratePrivateKey()
                 if err != nil {
@@ -86,16 +88,19 @@ func RegisterServer(client models.ServerClient) error {
         }
 
         if client.Address == "" {
-                newAddress, err := functions.UniqueAddress6(client.Network)
+                newAddress, err := functions.UniqueAddress(client.Network)
                 if err != nil {
                         return err
                 }
-                client.Address6 = newAddress
+		if newAddress == "" {
+			return errors.New("Could not retrieve address")
+		}
+                client.Address = newAddress
         }
 	if client.Network == "" { client.Network = "comms" }
         client.ServerKey = client.PublicKey
 
-        collection := mongoconn.Client.Database("netmaker").Collection("serverclients")
+        collection := mongoconn.Client.Database("netmaker").Collection("intclients")
         ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
         // insert our network into the network table
         _, err := collection.InsertOne(ctx, client)
@@ -120,7 +125,7 @@ func ReconfigureServerWireGuard() error {
                 return err
         }
 
-	peers, err := functions.GetPeersList("comms")
+	peers, err := functions.GetIntPeersList()
         if err != nil {
                 return err
         }
@@ -141,7 +146,7 @@ func ReconfigureServerWireGuard() error {
                 if peer.Address != "" {
 			var peeraddr = net.IPNet{
 	                        IP: net.ParseIP(peer.Address),
-	                        Mask: net.CIDRMask(32, 32),
+	                        Mask: net.CIDRMask(128, 128),
 	                }
 	                allowedips = append(allowedips, peeraddr)
 		}
@@ -154,10 +159,6 @@ func ReconfigureServerWireGuard() error {
                 }
 		peercfg = wgtypes.PeerConfig{
                         PublicKey: pubkey,
-                        Endpoint: &net.UDPAddr{
-                                IP:   net.ParseIP(peer.Endpoint),
-                                Port: int(peer.ListenPort),
-                        },
                         ReplaceAllowedIPs: true,
                         AllowedIPs: allowedips,
                 }