aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinus Nordberg <linus@nordberg.se>2019-09-30 09:17:16 +0200
committerLinus Nordberg <linus@nordberg.se>2019-10-01 16:39:41 +0200
commit8a3be328fad5d7b256da6b77ecea6002297f353d (patch)
tree9c10e103ff33a0468c8a1469b683e3172f64bbc8
parent[server] Make leasetime an optional command line argument (diff)
downloadwg-dynamic-8a3be328fad5d7b256da6b77ecea6002297f353d.tar.xz
wg-dynamic-8a3be328fad5d7b256da6b77ecea6002297f353d.zip
WIP
[server] Restore leases from allowedips at startup
-rw-r--r--lease.h1
-rw-r--r--wg-dynamic-server.c30
2 files changed, 30 insertions, 1 deletions
diff --git a/lease.h b/lease.h
index 8e83135..b67e598 100644
--- a/lease.h
+++ b/lease.h
@@ -44,6 +44,7 @@ struct wg_dynamic_lease *new_lease(wg_key pubkey, uint32_t leasetime,
const struct in6_addr *ipv6,
struct wg_dynamic_lease *current);
+
/*
* Returns all leases belonging to pubkey, or NULL if there are none.
*/
diff --git a/wg-dynamic-server.c b/wg-dynamic-server.c
index 87f3037..72063a9 100644
--- a/wg-dynamic-server.c
+++ b/wg-dynamic-server.c
@@ -517,6 +517,33 @@ static void cleanup()
}
}
+static void init_leaess_from_peers()
+{
+ wg_peer *peer;
+
+ wg_for_each_peer(device, peer) {
+ wg_allowedip *allowedip;
+ struct in6_addr *lladdr = NULL;
+ struct in_addr *ipv4 = NULL;
+ struct in6_addr *ipv6 = NULL;
+ wg_for_each_allowedip(peer, allowedip) {
+ if (allowedip->family == AF_INET6 &&
+ IN6_IS_ADDR_LINKLOCAL(&allowedip->ip6))
+ lladdr = &allowedip->ip6;
+ if (allowedip->family == AF_INET && !ipv4)
+ ipv4 = &allowedip->ip4;
+ else if (allowedip->family == AF_INET6 && !ipv6)
+ ipv6 = &allowedip->ip6;
+ }
+
+ if (!ipv4 && !ipv6)
+ continue;
+
+ set_lease(wg_interface, peer->public_key, leasetime, lladdr, ipv4, ipv6);
+ }
+}
+
+
static void setup()
{
if (inet_pton(AF_INET6, WG_DYNAMIC_ADDR, &well_known) != 1)
@@ -542,7 +569,8 @@ static void setup()
wg_interface);
setup_sockets();
- leases_init("leases_file", nlsock);
+ leases_init(NULL, nlsock);
+ init_leaess_from_peers();
}
static int get_avail_request()