add allowedIPs conditionally

This commit is contained in:
Callan Bryant 2020-10-27 21:57:44 +00:00
parent a6bacff44d
commit 0481996116
No known key found for this signature in database
GPG Key ID: C31FA9DF3ACBFFAA
2 changed files with 29 additions and 10 deletions

13
add.go
View File

@ -125,9 +125,16 @@ func Add() {
}
func PrintPeerCfg(peer PeerConfig, conf *DsnetConfig) {
allowedIPs := make([]JSONIPNet, len(conf.Networks)+2)
allowedIPs[0] = conf.Network
allowedIPs[1] = conf.Network6
allowedIPs := make([]JSONIPNet, 0, len(conf.Networks)+2)
if len(conf.Network.IPNet.Mask) > 0 {
allowedIPs = append(allowedIPs, conf.Network)
}
if len(conf.Network6.IPNet.Mask) > 0 {
allowedIPs = append(allowedIPs, conf.Network6)
}
allowedIPs = append(allowedIPs, conf.Networks...)
var peerConf string

View File

@ -232,14 +232,26 @@ func (conf DsnetConfig) GetWgPeerConfigs() []wgtypes.PeerConfig {
presharedKey := peer.PresharedKey.Key
// AllowedIPs = private IP + defined networks
allowedIPs := make([]net.IPNet, len(peer.Networks)+2)
allowedIPs[0] = net.IPNet{
IP: peer.IP,
Mask: net.IPMask{255, 255, 255, 255},
allowedIPs := make([]net.IPNet, 0, len(peer.Networks)+2)
if len(peer.IP) > 0 {
allowedIPs = append(
allowedIPs,
net.IPNet{
IP: peer.IP,
Mask: net.IPMask{255, 255, 255, 255},
},
)
}
allowedIPs[1] = net.IPNet{
IP: peer.IP6,
Mask: net.IPMask{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff},
if len(peer.IP6) > 0 {
allowedIPs = append(
allowedIPs,
net.IPNet{
IP: peer.IP6,
Mask: net.IPMask{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff},
},
)
}
for i, net := range peer.Networks {