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) {
|
func PrintPeerCfg(peer PeerConfig, conf *DsnetConfig) {
|
||||||
allowedIPs := make([]JSONIPNet, len(conf.Networks)+2)
|
allowedIPs := make([]JSONIPNet, 0, len(conf.Networks)+2)
|
||||||
allowedIPs[0] = conf.Network
|
|
||||||
allowedIPs[1] = conf.Network6
|
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...)
|
allowedIPs = append(allowedIPs, conf.Networks...)
|
||||||
|
|
||||||
var peerConf string
|
var peerConf string
|
||||||
|
@ -232,14 +232,26 @@ func (conf DsnetConfig) GetWgPeerConfigs() []wgtypes.PeerConfig {
|
|||||||
presharedKey := peer.PresharedKey.Key
|
presharedKey := peer.PresharedKey.Key
|
||||||
|
|
||||||
// AllowedIPs = private IP + defined networks
|
// AllowedIPs = private IP + defined networks
|
||||||
allowedIPs := make([]net.IPNet, len(peer.Networks)+2)
|
allowedIPs := make([]net.IPNet, 0, len(peer.Networks)+2)
|
||||||
allowedIPs[0] = net.IPNet{
|
|
||||||
|
if len(peer.IP) > 0 {
|
||||||
|
allowedIPs = append(
|
||||||
|
allowedIPs,
|
||||||
|
net.IPNet{
|
||||||
IP: peer.IP,
|
IP: peer.IP,
|
||||||
Mask: net.IPMask{255, 255, 255, 255},
|
Mask: net.IPMask{255, 255, 255, 255},
|
||||||
|
},
|
||||||
|
)
|
||||||
}
|
}
|
||||||
allowedIPs[1] = net.IPNet{
|
|
||||||
|
if len(peer.IP6) > 0 {
|
||||||
|
allowedIPs = append(
|
||||||
|
allowedIPs,
|
||||||
|
net.IPNet{
|
||||||
IP: peer.IP6,
|
IP: peer.IP6,
|
||||||
Mask: net.IPMask{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff},
|
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 {
|
for i, net := range peer.Networks {
|
||||||
|
Loading…
Reference in New Issue
Block a user