mirror of
https://github.com/gravitl/netmaker.git
synced 2025-10-06 17:29:15 +08:00
began route consolidation
This commit is contained in:
@@ -8,7 +8,7 @@ import (
|
||||
)
|
||||
|
||||
// SetPeerRoutes - sets/removes ip routes for each peer on a network
|
||||
func SetPeerRoutes(iface string, oldPeers map[string][]net.IPNet, newPeers []wgtypes.PeerConfig) {
|
||||
func SetPeerRoutes(iface, currentNodeAddr string, oldPeers map[string][]net.IPNet, newPeers []wgtypes.PeerConfig) {
|
||||
// traverse through all recieved peers
|
||||
for _, peer := range newPeers {
|
||||
// if pubkey found in existing peers, check against existing peer
|
||||
@@ -17,14 +17,14 @@ func SetPeerRoutes(iface string, oldPeers map[string][]net.IPNet, newPeers []wgt
|
||||
// traverse IPs, check to see if old peer contains each IP
|
||||
for _, allowedIP := range peer.AllowedIPs { // compare new ones (if any) to old ones
|
||||
if !ncutils.IPNetSliceContains(currPeerAllowedIPs, allowedIP) {
|
||||
if err := setRoute(iface, &allowedIP); err != nil {
|
||||
if err := setRoute(iface, &allowedIP, allowedIP.IP.String()); err != nil {
|
||||
ncutils.PrintLog(err.Error(), 1)
|
||||
}
|
||||
}
|
||||
}
|
||||
for _, allowedIP := range currPeerAllowedIPs { // compare old ones (if any) to new ones
|
||||
if !ncutils.IPNetSliceContains(peer.AllowedIPs, allowedIP) {
|
||||
if err := deleteRoute(iface, &allowedIP); err != nil {
|
||||
if err := deleteRoute(iface, &allowedIP, allowedIP.IP.String()); err != nil {
|
||||
ncutils.PrintLog(err.Error(), 1)
|
||||
}
|
||||
}
|
||||
@@ -32,7 +32,7 @@ func SetPeerRoutes(iface string, oldPeers map[string][]net.IPNet, newPeers []wgt
|
||||
delete(oldPeers, peer.PublicKey.String()) // remove peer as it was found and processed
|
||||
} else {
|
||||
for _, allowedIP := range peer.AllowedIPs { // add all routes as peer doesn't exist
|
||||
if err := setRoute(iface, &allowedIP); err != nil {
|
||||
if err := setRoute(iface, &allowedIP, allowedIP.String()); err != nil {
|
||||
ncutils.PrintLog(err.Error(), 1)
|
||||
}
|
||||
}
|
||||
@@ -42,7 +42,16 @@ func SetPeerRoutes(iface string, oldPeers map[string][]net.IPNet, newPeers []wgt
|
||||
// traverse through all remaining existing peers
|
||||
for _, allowedIPs := range oldPeers {
|
||||
for _, allowedIP := range allowedIPs {
|
||||
deleteRoute(iface, &allowedIP)
|
||||
deleteRoute(iface, &allowedIP, allowedIP.IP.String())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// SetCurrentPeerRoutes - sets all the current peers
|
||||
func SetCurrentPeerRoutes(iface, currentAddr string, peers []wgtypes.Peer) {
|
||||
for _, peer := range peers {
|
||||
for _, allowedIP := range peer.AllowedIPs {
|
||||
setRoute(iface, &allowedIP, currentAddr)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user