aboutsummaryrefslogtreecommitdiffstats
path: root/lease.h
diff options
context:
space:
mode:
authorLinus Nordberg <linus@nordberg.se>2019-09-29 22:16:52 +0200
committerLinus Nordberg <linus@nordberg.se>2019-09-29 22:36:19 +0200
commit415a43be2ae31372a33e910913d6ae0ba401e167 (patch)
treebdb5e6fec4c4bd3fa1f61f491daad6e7f816bf58 /lease.h
parentRemove allowed-ips from peers as leases expire (diff)
downloadwg-dynamic-415a43be2ae31372a33e910913d6ae0ba401e167.tar.xz
wg-dynamic-415a43be2ae31372a33e910913d6ae0ba401e167.zip
Server side lease handling
Extend when requested, release when being replaced. Separate address families so that one can be granted even when the pool for the other is empty.
Diffstat (limited to 'lease.h')
-rw-r--r--lease.h23
1 files changed, 17 insertions, 6 deletions
diff --git a/lease.h b/lease.h
index 23852e6..8e83135 100644
--- a/lease.h
+++ b/lease.h
@@ -37,10 +37,12 @@ void leases_free();
/*
* Creates a new lease and returns a pointer to it, or NULL if either we ran out
- * of assignable IPs or the requested IP is already taken.
+ * of assignable IPs or if requested IP(s) are already taken.
*/
struct wg_dynamic_lease *new_lease(wg_key pubkey, uint32_t leasetime,
- struct in_addr *ipv4, struct in6_addr *ipv6);
+ const struct in_addr *ipv4,
+ const struct in6_addr *ipv6,
+ struct wg_dynamic_lease *current);
/*
* Returns all leases belonging to pubkey, or NULL if there are none.
@@ -48,12 +50,12 @@ struct wg_dynamic_lease *new_lease(wg_key pubkey, uint32_t leasetime,
struct wg_dynamic_lease *get_leases(wg_key pubkey);
/*
- * Extend the lease to be leasetime seconds long again. Returns true on error,
- * or false otherwise.
+ * Release the lease and free allocated memory.
*/
-bool extend_lease(struct wg_dynamic_lease *lease, uint32_t leasetime);
+bool release_lease(struct wg_dynamic_lease *lease, wg_key pubkey);
-/* Refreshes all leases, meaning expired ones will be removed. Returns the
+/*
+ * Refreshes all leases, meaning expired ones will be removed. Returns the
* amount of seconds until the next lease will expire, or at most INT_MAX/1000.
*/
int leases_refresh(void (*update_cb)(wg_key *, int));
@@ -63,4 +65,13 @@ int leases_refresh(void (*update_cb)(wg_key *, int));
*/
void leases_update_pools(struct mnl_socket *nlsock);
+/*
+ * Return true if lease is !NULL and has not expired.
+ */
+bool lease_is_valid(const struct wg_dynamic_lease *lease);
+
+#ifdef DEBUG
+char *lease_to_str(const struct wg_dynamic_lease *l);
+#endif
+
#endif