summaryrefslogtreecommitdiffstatshomepage
path: root/src
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2019-01-22 13:38:52 +0100
committerJason A. Donenfeld <Jason@zx2c4.com>2019-01-23 14:29:44 +0100
commit49c240044ca638128a35e4fc55d86c727d3b2b1f (patch)
tree4855020bd05898c165d7aa4300a4c7bb527f432f /src
parentglobal: normalize -> clamp (diff)
downloadwireguard-linux-compat-49c240044ca638128a35e4fc55d86c727d3b2b1f.tar.xz
wireguard-linux-compat-49c240044ca638128a35e4fc55d86c727d3b2b1f.zip
netlink: use __kernel_timespec for handshake time
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'src')
-rw-r--r--src/compat/compat.h16
-rw-r--r--src/netlink.c10
-rw-r--r--src/peer.h2
-rwxr-xr-xsrc/tests/netns.sh4
-rw-r--r--src/timers.c2
-rw-r--r--src/uapi/wireguard.h2
6 files changed, 28 insertions, 8 deletions
diff --git a/src/compat/compat.h b/src/compat/compat.h
index 15cf8bb..19dd71a 100644
--- a/src/compat/compat.h
+++ b/src/compat/compat.h
@@ -748,10 +748,24 @@ static inline void crypto_xor_cpy(u8 *dst, const u8 *src1, const u8 *src2,
#define hlist_add_behind(a, b) hlist_add_after(b, a)
#endif
-#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 21, 0)
+#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 0, 0)
#define totalram_pages() totalram_pages
#endif
+#if LINUX_VERSION_CODE < KERNEL_VERSION(4, 18, 0)
+struct __kernel_timespec {
+ int64_t tv_sec, tv_nsec;
+};
+#elif LINUX_VERSION_CODE < KERNEL_VERSION(5, 1, 0)
+#include <linux/time64.h>
+#ifdef __kernel_timespec
+#undef __kernel_timespec
+struct __kernel_timespec {
+ int64_t tv_sec, tv_nsec;
+};
+#endif
+#endif
+
/* https://github.com/ClangBuiltLinux/linux/issues/7 */
#if defined( __clang__) && (!defined(CONFIG_CLANG_VERSION) || CONFIG_CLANG_VERSION < 80000)
#include <linux/bug.h>
diff --git a/src/netlink.c b/src/netlink.c
index bdd3150..3458c81 100644
--- a/src/netlink.c
+++ b/src/netlink.c
@@ -33,7 +33,7 @@ static const struct nla_policy peer_policy[WGPEER_A_MAX + 1] = {
[WGPEER_A_FLAGS] = { .type = NLA_U32 },
[WGPEER_A_ENDPOINT] = { .len = sizeof(struct sockaddr) },
[WGPEER_A_PERSISTENT_KEEPALIVE_INTERVAL] = { .type = NLA_U16 },
- [WGPEER_A_LAST_HANDSHAKE_TIME] = { .len = sizeof(struct timespec) },
+ [WGPEER_A_LAST_HANDSHAKE_TIME] = { .len = sizeof(struct __kernel_timespec) },
[WGPEER_A_RX_BYTES] = { .type = NLA_U64 },
[WGPEER_A_TX_BYTES] = { .type = NLA_U64 },
[WGPEER_A_ALLOWEDIPS] = { .type = NLA_NESTED },
@@ -107,6 +107,11 @@ static int get_peer(struct wg_peer *peer, struct allowedips_cursor *rt_cursor,
goto err;
if (!rt_cursor->seq) {
+ const struct __kernel_timespec last_handshake = {
+ .tv_sec = peer->walltime_last_handshake.tv_sec,
+ .tv_nsec = peer->walltime_last_handshake.tv_nsec
+ };
+
down_read(&peer->handshake.lock);
fail = nla_put(skb, WGPEER_A_PRESHARED_KEY,
NOISE_SYMMETRIC_KEY_LEN,
@@ -116,8 +121,7 @@ static int get_peer(struct wg_peer *peer, struct allowedips_cursor *rt_cursor,
goto err;
if (nla_put(skb, WGPEER_A_LAST_HANDSHAKE_TIME,
- sizeof(peer->walltime_last_handshake),
- &peer->walltime_last_handshake) ||
+ sizeof(last_handshake), &last_handshake) ||
nla_put_u16(skb, WGPEER_A_PERSISTENT_KEEPALIVE_INTERVAL,
peer->persistent_keepalive_interval) ||
nla_put_u64_64bit(skb, WGPEER_A_TX_BYTES, peer->tx_bytes,
diff --git a/src/peer.h b/src/peer.h
index f3cf255..2e04262 100644
--- a/src/peer.h
+++ b/src/peer.h
@@ -56,7 +56,7 @@ struct wg_peer {
u16 persistent_keepalive_interval;
bool timer_need_another_keepalive;
bool sent_lastminute_handshake;
- struct timespec walltime_last_handshake;
+ struct timespec64 walltime_last_handshake;
struct kref refcount;
struct rcu_head rcu;
struct list_head peer_list;
diff --git a/src/tests/netns.sh b/src/tests/netns.sh
index 6ef61a5..46c30e5 100755
--- a/src/tests/netns.sh
+++ b/src/tests/netns.sh
@@ -142,7 +142,7 @@ big_mtu=$(( 34816 - 1500 + $orig_mtu ))
# Test using IPv4 as outer transport
n1 wg set wg0 peer "$pub2" endpoint 127.0.0.1:2
n2 wg set wg0 peer "$pub1" endpoint 127.0.0.1:1
-# Before calling tests, we first make sure that the stats counters are working
+# Before calling tests, we first make sure that the stats counters and timestamper are working
n2 ping -c 10 -f -W 1 192.168.241.1
{ read _; read _; read _; read rx_bytes _; read _; read tx_bytes _; } < <(ip2 -stats link show dev wg0)
(( rx_bytes == 1372 && (tx_bytes == 1428 || tx_bytes == 1460) ))
@@ -152,6 +152,8 @@ read _ rx_bytes tx_bytes < <(n2 wg show wg0 transfer)
(( rx_bytes == 1372 && (tx_bytes == 1428 || tx_bytes == 1460) ))
read _ rx_bytes tx_bytes < <(n1 wg show wg0 transfer)
(( tx_bytes == 1372 && (rx_bytes == 1428 || rx_bytes == 1460) ))
+read _ timestamp < <(n1 wg show wg0 latest-handshakes)
+(( timestamp != 0 ))
tests
ip1 link set wg0 mtu $big_mtu
diff --git a/src/timers.c b/src/timers.c
index ee16c56..7614c85 100644
--- a/src/timers.c
+++ b/src/timers.c
@@ -192,7 +192,7 @@ void wg_timers_handshake_complete(struct wg_peer *peer)
del_timer(&peer->timer_retransmit_handshake);
peer->timer_handshake_attempts = 0;
peer->sent_lastminute_handshake = false;
- getnstimeofday(&peer->walltime_last_handshake);
+ ktime_get_real_ts64(&peer->walltime_last_handshake);
}
/* Should be called after an ephemeral key is created, which is before sending a
diff --git a/src/uapi/wireguard.h b/src/uapi/wireguard.h
index 3db6ff8..071ce41 100644
--- a/src/uapi/wireguard.h
+++ b/src/uapi/wireguard.h
@@ -35,7 +35,7 @@
* WGPEER_A_PRESHARED_KEY: len WG_KEY_LEN
* WGPEER_A_ENDPOINT: struct sockaddr_in or struct sockaddr_in6
* WGPEER_A_PERSISTENT_KEEPALIVE_INTERVAL: NLA_U16
- * WGPEER_A_LAST_HANDSHAKE_TIME: struct timespec
+ * WGPEER_A_LAST_HANDSHAKE_TIME: struct __kernel_timespec
* WGPEER_A_RX_BYTES: NLA_U64
* WGPEER_A_TX_BYTES: NLA_U64
* WGPEER_A_ALLOWEDIPS: NLA_NESTED