|
@@ -8,7 +8,7 @@ import (
|
|
)
|
|
)
|
|
|
|
|
|
// SetPeerRoutes - sets/removes ip routes for each peer on a network
|
|
// 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
|
|
// traverse through all recieved peers
|
|
for _, peer := range newPeers {
|
|
for _, peer := range newPeers {
|
|
// if pubkey found in existing peers, check against existing peer
|
|
// 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
|
|
// traverse IPs, check to see if old peer contains each IP
|
|
for _, allowedIP := range peer.AllowedIPs { // compare new ones (if any) to old ones
|
|
for _, allowedIP := range peer.AllowedIPs { // compare new ones (if any) to old ones
|
|
if !ncutils.IPNetSliceContains(currPeerAllowedIPs, allowedIP) {
|
|
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)
|
|
ncutils.PrintLog(err.Error(), 1)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
for _, allowedIP := range currPeerAllowedIPs { // compare old ones (if any) to new ones
|
|
for _, allowedIP := range currPeerAllowedIPs { // compare old ones (if any) to new ones
|
|
if !ncutils.IPNetSliceContains(peer.AllowedIPs, allowedIP) {
|
|
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)
|
|
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
|
|
delete(oldPeers, peer.PublicKey.String()) // remove peer as it was found and processed
|
|
} else {
|
|
} else {
|
|
for _, allowedIP := range peer.AllowedIPs { // add all routes as peer doesn't exist
|
|
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)
|
|
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
|
|
// traverse through all remaining existing peers
|
|
for _, allowedIPs := range oldPeers {
|
|
for _, allowedIPs := range oldPeers {
|
|
for _, allowedIP := range allowedIPs {
|
|
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)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|