Parcourir la source

add extrallowedIps on other extclients

Abhishek Kondur il y a 1 an
Parent
commit
2b42c8b546
2 fichiers modifiés avec 10 ajouts et 23 suppressions
  1. 2 22
      controllers/ext_client.go
  2. 8 1
      logic/extpeers.go

+ 2 - 22
controllers/ext_client.go

@@ -7,6 +7,7 @@ import (
 	"net"
 	"net/http"
 	"strconv"
+	"strings"
 
 	"github.com/gorilla/mux"
 	"github.com/gravitl/netmaker/database"
@@ -216,27 +217,6 @@ func getExtClientConf(w http.ResponseWriter, r *http.Request) {
 	} else {
 		gwendpoint = fmt.Sprintf("%s:%d", host.EndpointIP.String(), host.ListenPort)
 	}
-	var newAllowedIPs string
-	if logic.IsInternetGw(gwnode) {
-		egressrange := "0.0.0.0/0"
-		if gwnode.Address6.IP != nil && client.Address6 != "" {
-			egressrange += "," + "::/0"
-		}
-		newAllowedIPs = egressrange
-	} else {
-		newAllowedIPs = network.AddressRange
-		if newAllowedIPs != "" && network.AddressRange6 != "" {
-			newAllowedIPs += ","
-		}
-		if network.AddressRange6 != "" {
-			newAllowedIPs += network.AddressRange6
-		}
-		if egressGatewayRanges, err := logic.GetEgressRangesOnNetwork(&client); err == nil {
-			for _, egressGatewayRange := range egressGatewayRanges {
-				newAllowedIPs += "," + egressGatewayRange
-			}
-		}
-	}
 
 	defaultDNS := ""
 	if client.DNS != "" {
@@ -266,7 +246,7 @@ Endpoint = %s
 		defaultMTU,
 		defaultDNS,
 		host.PublicKey,
-		newAllowedIPs,
+		strings.Join(logic.GetExtclientAllowedIPs(client), ","),
 		gwendpoint,
 		keepalive)
 

+ 8 - 1
logic/extpeers.go

@@ -460,13 +460,20 @@ func GetExtclientAllowedIPs(client models.ExtClient) (allowedIPs []string) {
 		allowedIPs = []string{egressrange}
 	} else {
 		allowedIPs = []string{network.AddressRange}
-
 		if network.AddressRange6 != "" {
 			allowedIPs = append(allowedIPs, network.AddressRange6)
 		}
 		if egressGatewayRanges, err := GetEgressRangesOnNetwork(&client); err == nil {
 			allowedIPs = append(allowedIPs, egressGatewayRanges...)
 		}
+		if extclients, err := GetAllExtClients(); err == nil {
+			for _, extclient := range extclients {
+				if extclient.ClientID == client.ClientID {
+					continue
+				}
+				allowedIPs = append(allowedIPs, extclient.ExtraAllowedIPs...)
+			}
+		}
 	}
 	return
 }