diff options
author | Linus Nordberg <linus@nordberg.se> | 2019-03-22 10:23:50 +0100 |
---|---|---|
committer | Linus Nordberg <linus@nordberg.se> | 2019-03-22 10:23:50 +0100 |
commit | fed4f79b5ea8843edf8763b9e7e811f7ffaee6e7 (patch) | |
tree | f89ce919f447dbf113d55c034fbda35eaaa8cdba | |
parent | add starttime to struct wg_dynamic_lease (diff) | |
download | wg-dynamic-fed4f79b5ea8843edf8763b9e7e811f7ffaee6e7.tar.xz wg-dynamic-fed4f79b5ea8843edf8763b9e7e811f7ffaee6e7.zip |
add now()
-rw-r--r-- | common.c | 9 | ||||
-rw-r--r-- | common.h | 1 | ||||
-rw-r--r-- | wg-dynamic-server.c | 5 |
3 files changed, 11 insertions, 4 deletions
@@ -324,3 +324,12 @@ size_t printf_to_buf(char *buf, size_t bufsize, size_t offset, char *fmt, ...) fatal("Outbuffer too small"); return n; } + +uint32_t now() +{ + struct timespec tp; + if (clock_gettime(CLOCK_REALTIME, &tp)) + fatal("clock_gettime(CLOCK_REALTIME)"); + return tp.tv_sec; +} + @@ -84,4 +84,5 @@ bool handle_request(int fd, struct wg_dynamic_request *req, bool (*error)(int, int)); size_t send_message(int fd, unsigned char *buf, size_t *len); size_t printf_to_buf(char *buf, size_t bufsize, size_t len, char *fmt, ...); +uint32_t now(); #endif diff --git a/wg-dynamic-server.c b/wg-dynamic-server.c index c477411..8660ba2 100644 --- a/wg-dynamic-server.c +++ b/wg-dynamic-server.c @@ -308,7 +308,6 @@ static void close_connection(int *fd, struct wg_dynamic_request *req) static int allocate_from_pool(struct wg_dynamic_request *const req, struct wg_dynamic_lease *lease) { - struct timespec tp; struct wg_dynamic_attr *attr; /* NOTE: "allocating" whatever client asks for */ @@ -318,9 +317,7 @@ static int allocate_from_pool(struct wg_dynamic_request *const req, * to the wg interface, and kept up to date as the routing * table changes */ - if (clock_gettime(CLOCK_REALTIME, &tp)) - fatal("clock_gettime(CLOCK_REALTIME)"); - lease->starttime = tp.tv_sec; + lease->starttime = now(); lease->leasetime = WG_DYNAMIC_LEASETIME; attr = req->first; |