Skip to content

Commit

Permalink
mover failOver func to pro pkg
Browse files Browse the repository at this point in the history
  • Loading branch information
abhishek9686 committed Jan 23, 2024
1 parent a446c50 commit c690eb1
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 25 deletions.
29 changes: 4 additions & 25 deletions logic/peers.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ var (
ResetFailedOverPeer = func(failedOverNode *models.Node) error {
return nil
}
// GetFailOverPeerIps - gets failover peerips
GetFailOverPeerIps = func(peer, node *models.Node) []net.IPNet {
return []net.IPNet{}
}
)

// GetPeerUpdateForHost - gets the consolidated peer update for the host from all networks
Expand Down Expand Up @@ -362,31 +366,6 @@ func GetAllowedIPs(node, peer *models.Node, metrics *models.Metrics) []net.IPNet
return allowedips
}

func GetFailOverPeerIps(peer, node *models.Node) []net.IPNet {
allowedips := []net.IPNet{}
for failOverpeerID := range node.FailOverPeers {
failOverpeer, err := GetNodeByID(failOverpeerID)
if err == nil && failOverpeer.FailedOverBy == peer.ID {
if failOverpeer.Address.IP != nil {
allowed := net.IPNet{
IP: failOverpeer.Address.IP,
Mask: net.CIDRMask(32, 32),
}
allowedips = append(allowedips, allowed)
}
if failOverpeer.Address6.IP != nil {
allowed := net.IPNet{
IP: failOverpeer.Address6.IP,
Mask: net.CIDRMask(128, 128),
}
allowedips = append(allowedips, allowed)
}

}
}
return allowedips
}

func GetEgressIPs(peer *models.Node) []net.IPNet {

peerHost, err := GetHost(peer.HostID.String())
Expand Down
1 change: 1 addition & 0 deletions pro/initialize.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ func InitPro() {
})
logic.ResetFailOver = proLogic.ResetFailOver
logic.ResetFailedOverPeer = proLogic.ResetFailedOverPeer
logic.GetFailOverPeerIps = proLogic.GetFailOverPeerIps
logic.DenyClientNodeAccess = proLogic.DenyClientNode
logic.IsClientNodeAllowed = proLogic.IsClientNodeAllowed
logic.AllowClientNodeAccess = proLogic.RemoveDeniedNodeFromClient
Expand Down
27 changes: 27 additions & 0 deletions pro/logic/failover.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package logic

import (
"errors"
"net"

"github.com/google/uuid"
"github.com/gravitl/netmaker/logic"
Expand Down Expand Up @@ -96,3 +97,29 @@ func ResetFailOver(failOverNode *models.Node) error {
}
return nil
}

// GetFailOverPeerIps - adds the failedOvered peerIps by the peer
func GetFailOverPeerIps(peer, node *models.Node) []net.IPNet {
allowedips := []net.IPNet{}
for failOverpeerID := range node.FailOverPeers {
failOverpeer, err := logic.GetNodeByID(failOverpeerID)
if err == nil && failOverpeer.FailedOverBy == peer.ID {
if failOverpeer.Address.IP != nil {
allowed := net.IPNet{
IP: failOverpeer.Address.IP,
Mask: net.CIDRMask(32, 32),
}
allowedips = append(allowedips, allowed)
}
if failOverpeer.Address6.IP != nil {
allowed := net.IPNet{
IP: failOverpeer.Address6.IP,
Mask: net.CIDRMask(128, 128),
}
allowedips = append(allowedips, allowed)
}

}
}
return allowedips
}

0 comments on commit c690eb1

Please sign in to comment.