aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinus Nordberg <linus@nordberg.se>2019-09-30 08:44:34 +0200
committerLinus Nordberg <linus@nordberg.se>2019-09-30 08:44:34 +0200
commit29ed5cd5d57dc7a30ca08d45877a0fb2fcfce289 (patch)
tree9210b856ae150ce38bc5b0deb5c42fa961224386
parent[tests] Add test cases for lease handling (diff)
downloadwg-dynamic-29ed5cd5d57dc7a30ca08d45877a0fb2fcfce289.tar.xz
wg-dynamic-29ed5cd5d57dc7a30ca08d45877a0fb2fcfce289.zip
[server] Make leasetime an optional command line argument
-rw-r--r--common.h2
-rwxr-xr-xtests/netsh.sh2
-rw-r--r--wg-dynamic-server.c13
3 files changed, 12 insertions, 5 deletions
diff --git a/common.h b/common.h
index fcb0f0e..5ac2f09 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..6737d29 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 wg0 10
diff --git a/wg-dynamic-server.c b/wg-dynamic-server.c
index 2b073f1..87f3037 100644
--- a/wg-dynamic-server.c
+++ b/wg-dynamic-server.c
@@ -34,6 +34,7 @@ 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;
@@ -49,7 +50,7 @@ struct mnl_cb_data {
static void usage()
{
- die("usage: %s <wg-interface>\n", progname);
+ die("usage: %s <wg-interface> [<leasetime>]\n", progname);
}
static int data_cb(const struct nlmsghdr *nlh, void *data)
@@ -377,7 +378,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;
struct wg_dynamic_lease *current = NULL;
while (cur) {
@@ -647,10 +647,17 @@ static void poll_loop()
int main(int argc, char *argv[])
{
progname = argv[0];
- if (argc != 2)
+ if (argc < 2 || argc > 3)
usage();
wg_interface = argv[1];
+ if (argc == 3) {
+ char *endptr;
+ leasetime = (uint32_t) strtoul(argv[2], &endptr, 10);
+ if (*endptr)
+ usage();
+ }
+
setup();
poll_loop();