diff options
author | Linus Nordberg <linus@nordberg.se> | 2019-09-30 08:44:34 +0200 |
---|---|---|
committer | Linus Nordberg <linus@nordberg.se> | 2019-09-30 08:44:34 +0200 |
commit | 29ed5cd5d57dc7a30ca08d45877a0fb2fcfce289 (patch) | |
tree | 9210b856ae150ce38bc5b0deb5c42fa961224386 /wg-dynamic-server.c | |
parent | [tests] Add test cases for lease handling (diff) | |
download | wg-dynamic-29ed5cd5d57dc7a30ca08d45877a0fb2fcfce289.tar.xz wg-dynamic-29ed5cd5d57dc7a30ca08d45877a0fb2fcfce289.zip |
[server] Make leasetime an optional command line argument
Diffstat (limited to 'wg-dynamic-server.c')
-rw-r--r-- | wg-dynamic-server.c | 13 |
1 files changed, 10 insertions, 3 deletions
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(); |