From 4e399d82ac850ef38252f0b2ce9bc646da174ca6 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 1 Mar 2019 09:32:45 +0100 Subject: [PATCH] platform/wireguard: fix WGPEER_A_LAST_HANDSHAKE_TIME to use int64 typed timespec structure The netlink API changed for WireGuard. Adjust for that. https://git.zx2c4.com/WireGuard/commit/?id=c870c7af53f44a37814dfc76ceb8ad88e290fcd8 --- src/platform/nm-linux-platform.c | 6 ++++-- src/platform/nmp-object.h | 15 ++++++++++++++- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/platform/nm-linux-platform.c b/src/platform/nm-linux-platform.c index 4bf8555802..2f5c75b055 100644 --- a/src/platform/nm-linux-platform.c +++ b/src/platform/nm-linux-platform.c @@ -2019,8 +2019,10 @@ _wireguard_update_from_peers_nla (CList *peers, if (tb[WGPEER_A_PERSISTENT_KEEPALIVE_INTERVAL]) peer_c->data.persistent_keepalive_interval = nla_get_u16 (tb[WGPEER_A_PERSISTENT_KEEPALIVE_INTERVAL]); - if (tb[WGPEER_A_LAST_HANDSHAKE_TIME]) - nla_memcpy (&peer_c->data.last_handshake_time, tb[WGPEER_A_LAST_HANDSHAKE_TIME], sizeof (peer_c->data.last_handshake_time)); + if (tb[WGPEER_A_LAST_HANDSHAKE_TIME]) { + if (nla_len (tb[WGPEER_A_LAST_HANDSHAKE_TIME]) >= sizeof (peer_c->data.last_handshake_time)) + nla_memcpy (&peer_c->data.last_handshake_time, tb[WGPEER_A_LAST_HANDSHAKE_TIME], sizeof (peer_c->data.last_handshake_time)); + } if (tb[WGPEER_A_RX_BYTES]) peer_c->data.rx_bytes = nla_get_u64 (tb[WGPEER_A_RX_BYTES]); if (tb[WGPEER_A_TX_BYTES]) diff --git a/src/platform/nmp-object.h b/src/platform/nmp-object.h index 32775efa83..525e144001 100644 --- a/src/platform/nmp-object.h +++ b/src/platform/nmp-object.h @@ -31,6 +31,18 @@ struct udev_device; /*****************************************************************************/ +/* "struct __kernel_timespec" uses "long long", but we use gint64. In practice, + * these are the same types. */ +G_STATIC_ASSERT (sizeof (long long) == sizeof (gint64)); + +typedef struct { + /* like "struct __kernel_timespec". */ + gint64 tv_sec; + gint64 tv_nsec; +} NMPTimespec64; + +/*****************************************************************************/ + typedef union { struct sockaddr sa; struct sockaddr_in in; @@ -72,7 +84,8 @@ typedef struct { typedef struct _NMPWireGuardPeer { NMSockAddrUnion endpoint; - struct timespec last_handshake_time; + NMPTimespec64 last_handshake_time; + guint64 rx_bytes; guint64 tx_bytes;