aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinus Nordberg <linus@nordberg.se>2019-09-30 08:44:34 +0200
committerLinus Nordberg <linus@nordberg.se>2019-10-11 10:34:35 +0200
commit042bcaf5868b5d3b814ae1877e6d56fde647994f (patch)
tree5d5300ff4a8686f3a3a940f7cb9f2ee5e16fc02b
parent[tests] Add test cases for lease handling (diff)
downloadwg-dynamic-042bcaf5868b5d3b814ae1877e6d56fde647994f.tar.xz
wg-dynamic-042bcaf5868b5d3b814ae1877e6d56fde647994f.zip
[server] Make leasetime a commandline option
-rw-r--r--common.h2
-rwxr-xr-xtests/netsh.sh2
-rw-r--r--wg-dynamic-server.c28
3 files changed, 25 insertions, 7 deletions
diff --git a/common.h b/common.h
index 426ad20..ea550d9 100644
--- a/common.h
+++ b/common.h
@@ -25,7 +25,7 @@
static const char WG_DYNAMIC_ADDR[] = "fe80::";
static const uint16_t WG_DYNAMIC_PORT = 970; /* ASCII sum of "wireguard" */
-#define WG_DYNAMIC_LEASETIME 10 /* NOTE: 10s is good for testing purposes */
+#define WG_DYNAMIC_DEFAULT_LEASETIME 3600
#define ITEMS \
E(WGKEY_UNKNOWN, "") /* must be the first entry */ \
diff --git a/tests/netsh.sh b/tests/netsh.sh
index 9f022c8..f9e9c1e 100755
--- a/tests/netsh.sh
+++ b/tests/netsh.sh
@@ -86,4 +86,4 @@ echo
echo wg-test-$$ $server_public
echo
-nn 1 ./wg-dynamic-server wg0
+nn 1 ./wg-dynamic-server --leasetime 10 wg0
diff --git a/wg-dynamic-server.c b/wg-dynamic-server.c
index 3c1fb53..cf5e860 100644
--- a/wg-dynamic-server.c
+++ b/wg-dynamic-server.c
@@ -28,11 +28,12 @@
#include "netlink.h"
static const char *progname;
-static const char *wg_interface;
+static const char *wg_interface = NULL;
static struct in6_addr well_known;
static wg_device *device = NULL;
static struct wg_dynamic_request requests[MAX_CONNECTIONS] = { 0 };
+static uint32_t leasetime = WG_DYNAMIC_DEFAULT_LEASETIME;
static int sockfd = -1;
static int epollfd = -1;
@@ -48,7 +49,7 @@ struct mnl_cb_data {
static void usage()
{
- die("usage: %s <wg-interface>\n", progname);
+ die("usage: %s [--leasetime <leasetime>] <wg-interface>\n", progname);
}
static int data_cb(const struct nlmsghdr *nlh, void *data)
@@ -269,7 +270,6 @@ static int response_request_ip(struct wg_dynamic_attr *cur, wg_key pubkey,
{
struct in_addr *ipv4 = NULL;
struct in6_addr *ipv6 = NULL;
- uint32_t leasetime = WG_DYNAMIC_LEASETIME;
while (cur) {
switch (cur->key) {
@@ -528,11 +528,29 @@ static void poll_loop()
int main(int argc, char *argv[])
{
+ char *endptr = NULL;
+
progname = argv[0];
- if (argc != 2)
+ ++argv;
+ --argc;
+
+ while (argc > 0) {
+ if (!strcmp(argv[0], "--leasetime") && argc >= 2) {
+ leasetime = (uint32_t) strtoul(argv[1], &endptr, 10);
+ if (*endptr)
+ usage();
+ argv += 2;
+ argc -= 2;
+ } else {
+ wg_interface = argv[0];
+ argv += 1;
+ argc -= 1;
+ break;
+ }
+ }
+ if (!wg_interface || argc > 0)
usage();
- wg_interface = argv[1];
setup();
poll_loop();