support peer networks in allowedIPs

This commit is contained in:
Callan Bryant 2020-03-12 20:02:57 +00:00
parent 050749fbb6
commit ea5ffaa4e2
No known key found for this signature in database
GPG Key ID: C31FA9DF3ACBFFAA
2 changed files with 14 additions and 7 deletions

View File

@ -1,8 +1,9 @@
package main
import (
"os"
"fmt"
"os"
"github.com/naggie/dsnet"
)

View File

@ -185,6 +185,17 @@ func (conf DsnetConfig) GetWgPeerConfigs() []wgtypes.PeerConfig {
// pointer to each peer (d'oh)
presharedKey := peer.PresharedKey.Key
// AllowedIPs = private IP + defined networks
allowedIPs := make([]net.IPNet, len(peer.Networks)+1)
allowedIPs[0] = net.IPNet{
IP: peer.IP,
Mask: net.IPMask{255, 255, 255, 255},
}
for i, net := range peer.Networks {
allowedIPs[i+1] = net.IPNet
}
wgPeers = append(wgPeers, wgtypes.PeerConfig{
PublicKey: peer.PublicKey.Key,
Remove: false,
@ -192,12 +203,7 @@ func (conf DsnetConfig) GetWgPeerConfigs() []wgtypes.PeerConfig {
PresharedKey: &presharedKey,
Endpoint: nil,
ReplaceAllowedIPs: true,
AllowedIPs: []net.IPNet{
net.IPNet{
IP: peer.IP,
Mask: net.IPMask{255, 255, 255, 255},
},
},
AllowedIPs: allowedIPs,
})
}