add allowedIPs conditionally
This commit is contained in:
parent
a6bacff44d
commit
0481996116
13
add.go
13
add.go
@ -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
|
||||
|
@ -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{
|
||||
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{
|
||||
|
||||
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 {
|
||||
|
Loading…
Reference in New Issue
Block a user