Browse Source

add static node ips in the ingress update

abhishek9686 10 months ago
parent
commit
1c9b986f0e
3 changed files with 23 additions and 6 deletions
  1. 15 0
      logic/extpeers.go
  2. 4 3
      logic/peers.go
  3. 4 3
      models/mqtt.go

+ 15 - 0
logic/extpeers.go

@@ -402,6 +402,19 @@ func ToggleExtClientConnectivity(client *models.ExtClient, enable bool) (models.
 	return newClient, nil
 	return newClient, nil
 }
 }
 
 
+func GetStaticNodeIps(node models.Node) (ips []net.IP) {
+	extclients := GetStaticNodesByNetwork(models.NetworkID(node.Network), false)
+	for _, extclient := range extclients {
+		if extclient.StaticNode.Address != "" {
+			ips = append(ips, extclient.StaticNode.AddressIPNet4().IP)
+		}
+		if extclient.StaticNode.Address6 != "" {
+			ips = append(ips, extclient.StaticNode.AddressIPNet6().IP)
+		}
+	}
+	return
+}
+
 func GetFwRulesOnIngressGateway(node models.Node) (rules []models.FwRule) {
 func GetFwRulesOnIngressGateway(node models.Node) (rules []models.FwRule) {
 	// fetch user access to static clients via policies
 	// fetch user access to static clients via policies
 	extclients := GetStaticNodesByNetwork(models.NetworkID(node.Network), true)
 	extclients := GetStaticNodesByNetwork(models.NetworkID(node.Network), true)
@@ -413,12 +426,14 @@ func GetFwRulesOnIngressGateway(node models.Node) (rules []models.FwRule) {
 					rules = append(rules, models.FwRule{
 					rules = append(rules, models.FwRule{
 						SrcIp: userNodeI.StaticNode.AddressIPNet4().IP,
 						SrcIp: userNodeI.StaticNode.AddressIPNet4().IP,
 						DstIP: extclient.StaticNode.AddressIPNet4().IP,
 						DstIP: extclient.StaticNode.AddressIPNet4().IP,
+						Allow: true,
 					})
 					})
 				}
 				}
 				if userNodeI.StaticNode.Address6 != "" {
 				if userNodeI.StaticNode.Address6 != "" {
 					rules = append(rules, models.FwRule{
 					rules = append(rules, models.FwRule{
 						SrcIp: userNodeI.StaticNode.AddressIPNet6().IP,
 						SrcIp: userNodeI.StaticNode.AddressIPNet6().IP,
 						DstIP: extclient.StaticNode.AddressIPNet6().IP,
 						DstIP: extclient.StaticNode.AddressIPNet6().IP,
+						Allow: true,
 					})
 					})
 				}
 				}
 			}
 			}

+ 4 - 3
logic/peers.go

@@ -294,9 +294,10 @@ func GetPeerUpdateForHost(network string, host *models.Host, allNodes []models.N
 			extPeers, extPeerIDAndAddrs, egressRoutes, extUserIps, err = GetExtPeers(&node, &node)
 			extPeers, extPeerIDAndAddrs, egressRoutes, extUserIps, err = GetExtPeers(&node, &node)
 			if err == nil {
 			if err == nil {
 				hostPeerUpdate.FwUpdate.IngressInfo[node.ID.String()] = models.IngressInfo{
 				hostPeerUpdate.FwUpdate.IngressInfo[node.ID.String()] = models.IngressInfo{
-					IngressID: node.ID.String(),
-					UserIps:   extUserIps,
-					Rules:     GetFwRulesOnIngressGateway(node),
+					IngressID:     node.ID.String(),
+					UserIps:       extUserIps,
+					Rules:         GetFwRulesOnIngressGateway(node),
+					StaticNodeIps: GetStaticNodeIps(node),
 				}
 				}
 				hostPeerUpdate.EgressRoutes = append(hostPeerUpdate.EgressRoutes, egressRoutes...)
 				hostPeerUpdate.EgressRoutes = append(hostPeerUpdate.EgressRoutes, egressRoutes...)
 				hostPeerUpdate.Peers = append(hostPeerUpdate.Peers, extPeers...)
 				hostPeerUpdate.Peers = append(hostPeerUpdate.Peers, extPeers...)

+ 4 - 3
models/mqtt.go

@@ -34,9 +34,10 @@ type FwRule struct {
 
 
 // IngressInfo - struct for ingress info
 // IngressInfo - struct for ingress info
 type IngressInfo struct {
 type IngressInfo struct {
-	IngressID string   `json:"ingress_id"`
-	UserIps   []net.IP `json:"user_ips"`
-	Rules     []FwRule `json:"rules"`
+	IngressID     string   `json:"ingress_id"`
+	UserIps       []net.IP `json:"user_ips"`
+	StaticNodeIps []net.IP `json:"static_node_ips"`
+	Rules         []FwRule `json:"rules"`
 }
 }
 
 
 // EgressInfo - struct for egress info
 // EgressInfo - struct for egress info