summaryrefslogtreecommitdiffstatshomepage
path: root/src/tools
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2017-11-22 16:49:56 +0100
committerJason A. Donenfeld <Jason@zx2c4.com>2017-11-22 18:32:48 +0100
commit314c17259e09d18af9fcafa9d7e8b59c5cf1e1ca (patch)
tree92c96f7aca12855ba83431de6d766568664f1e97 /src/tools
parentpoly1305: import MIPS64 primitive from OpenSSL (diff)
downloadwireguard-monolithic-historical-314c17259e09d18af9fcafa9d7e8b59c5cf1e1ca.tar.xz
wireguard-monolithic-historical-314c17259e09d18af9fcafa9d7e8b59c5cf1e1ca.zip
global: switch from timeval to timespec
This gets us nanoseconds instead of microseconds, which is better, and we can do this pretty much without freaking out existing userspace, which doesn't actually make use of the nano/micro seconds field: zx2c4@thinkpad ~ $ cat a.c void main() { puts(sizeof(struct timeval) == sizeof(struct timespec) ? "success" : "failure"); } zx2c4@thinkpad ~ $ gcc a.c -m64 && ./a.out success zx2c4@thinkpad ~ $ gcc a.c -m32 && ./a.out success This doesn't solve y2038 problem, but timespec64 isn't yet a thing in userspace.
Diffstat (limited to 'src/tools')
-rw-r--r--src/tools/containers.h4
-rw-r--r--src/tools/ipc.c2
-rw-r--r--src/tools/show.c8
3 files changed, 7 insertions, 7 deletions
diff --git a/src/tools/containers.h b/src/tools/containers.h
index 58d0657..31eabea 100644
--- a/src/tools/containers.h
+++ b/src/tools/containers.h
@@ -6,9 +6,9 @@
#include <stdint.h>
#include <stdlib.h>
+#include <time.h>
#include <net/if.h>
#include <netinet/in.h>
-#include <sys/time.h>
#include <sys/socket.h>
#include "../uapi/wireguard.h"
@@ -43,7 +43,7 @@ struct wgpeer {
struct sockaddr_in6 addr6;
} endpoint;
- struct timeval last_handshake_time;
+ struct timespec last_handshake_time;
uint64_t rx_bytes, tx_bytes;
uint16_t persistent_keepalive_interval;
diff --git a/src/tools/ipc.c b/src/tools/ipc.c
index 2d24287..a88672f 100644
--- a/src/tools/ipc.c
+++ b/src/tools/ipc.c
@@ -427,7 +427,7 @@ static int userspace_get_device(struct wgdevice **out, const char *interface)
} else if (peer && !strcmp(key, "last_handshake_time_sec"))
peer->last_handshake_time.tv_sec = NUM(0xffffffffffffffffULL);
else if (peer && !strcmp(key, "last_handshake_time_nsec"))
- peer->last_handshake_time.tv_usec = NUM(0xffffffffffffffffULL) / 1000;
+ peer->last_handshake_time.tv_nsec = NUM(0xffffffffffffffffULL);
else if (peer && !strcmp(key, "rx_bytes"))
peer->rx_bytes = NUM(0xffffffffffffffffULL);
else if (peer && !strcmp(key, "tx_bytes"))
diff --git a/src/tools/show.c b/src/tools/show.c
index 6ae5830..ebfdf5b 100644
--- a/src/tools/show.c
+++ b/src/tools/show.c
@@ -24,13 +24,13 @@ static int peer_cmp(const void *first, const void *second)
time_t diff;
const struct wgpeer *a = *(const void **)first, *b = *(const void **)second;
- if (!a->last_handshake_time.tv_sec && !a->last_handshake_time.tv_usec && (b->last_handshake_time.tv_sec || b->last_handshake_time.tv_usec))
+ if (!a->last_handshake_time.tv_sec && !a->last_handshake_time.tv_nsec && (b->last_handshake_time.tv_sec || b->last_handshake_time.tv_nsec))
return 1;
- if (!b->last_handshake_time.tv_sec && !b->last_handshake_time.tv_usec && (a->last_handshake_time.tv_sec || a->last_handshake_time.tv_usec))
+ if (!b->last_handshake_time.tv_sec && !b->last_handshake_time.tv_nsec && (a->last_handshake_time.tv_sec || a->last_handshake_time.tv_nsec))
return -1;
diff = a->last_handshake_time.tv_sec - b->last_handshake_time.tv_sec;
if (!diff)
- diff = a->last_handshake_time.tv_usec - b->last_handshake_time.tv_usec;
+ diff = a->last_handshake_time.tv_nsec - b->last_handshake_time.tv_nsec;
if (diff < 0)
return 1;
if (diff > 0)
@@ -149,7 +149,7 @@ static size_t pretty_time(char *buf, const size_t len, unsigned long long left)
return offset;
}
-static char *ago(const struct timeval *t)
+static char *ago(const struct timespec *t)
{
static char buf[1024];
size_t offset;