From f7f06f00fada37e1830d84baaa638842bc575e3a Mon Sep 17 00:00:00 2001 From: Callan Bryant Date: Sun, 25 Oct 2020 22:27:33 +0000 Subject: [PATCH] check for IP networks before allocating --- add.go | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/add.go b/add.go index 09a8e21..befb6e0 100644 --- a/add.go +++ b/add.go @@ -62,9 +62,6 @@ func Add() { privateKey := GenerateJSONPrivateKey() publicKey := privateKey.PublicKey() - IP := conf.MustAllocateIP() - IP6 := conf.MustAllocateIP6() - peer := PeerConfig{ Owner: owner, Hostname: hostname, @@ -73,11 +70,21 @@ func Add() { PublicKey: publicKey, PrivateKey: privateKey, // omitted from server config JSON! PresharedKey: GenerateJSONKey(), - IP: IP, - IP6: IP6, Networks: []JSONIPNet{}, } + if len(conf.Network.IPNet.Mask) > 0 { + peer.IP = conf.MustAllocateIP() + } + + if len(conf.Network6.IPNet.Mask) > 0 { + peer.IP6 = conf.MustAllocateIP6() + } + + if len(conf.IP) == 0 && len(conf.IP6) == 0 { + ExitFail("No IPv4 or IPv6 network defined in config") + } + conf.MustAddPeer(peer) PrintPeerCfg(peer, conf) conf.MustSave()