From 79269472247af1341dc6adab13a1db180c37998f Mon Sep 17 00:00:00 2001 From: Per-Arne Date: Tue, 14 Apr 2020 02:26:40 +0200 Subject: [PATCH] Fixed bug where the first peer added to a new server, had colliding IP with the server --- wg_dashboard_backend/routers/v1/peer.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/wg_dashboard_backend/routers/v1/peer.py b/wg_dashboard_backend/routers/v1/peer.py index 5de21e1..1bfb02e 100644 --- a/wg_dashboard_backend/routers/v1/peer.py +++ b/wg_dashboard_backend/routers/v1/peer.py @@ -23,7 +23,16 @@ def add_peer( address_space = set(ipaddress.ip_network(server.address, strict=False).hosts()) occupied_space = set() + + # Try add server IP to list. + try: + occupied_space.add(ipaddress.ip_address(server.address.split("/")[0])) + except ValueError: + pass + for p in server.peers: + + # Try add peer ip to list. try: occupied_space.add(ipaddress.ip_address(p.address.split("/")[0])) except ValueError as e: