summaryrefslogtreecommitdiffhomepage
path: root/talpid-wireguard/src/wireguard_kernel
diff options
context:
space:
mode:
authorDavid Lönnhager <david.l@mullvad.net>2025-09-01 12:22:17 +0200
committerDavid Lönnhager <david.l@mullvad.net>2025-09-03 14:17:52 +0200
commit89c12d3d3a01c03ecc4c4e85df18b4bd09795112 (patch)
tree5d7f179b29f8e067e93ddc82ab047dfaaa5ba49c /talpid-wireguard/src/wireguard_kernel
parent1bf0ced17d8ce825108c1439ddb6ea9cb6344ed8 (diff)
downloadmullvadvpn-89c12d3d3a01c03ecc4c4e85df18b4bd09795112.tar.xz
mullvadvpn-89c12d3d3a01c03ecc4c4e85df18b4bd09795112.zip
Add last WG handshake to stats
Diffstat (limited to 'talpid-wireguard/src/wireguard_kernel')
-rw-r--r--talpid-wireguard/src/wireguard_kernel/stats.rs25
1 files changed, 24 insertions, 1 deletions
diff --git a/talpid-wireguard/src/wireguard_kernel/stats.rs b/talpid-wireguard/src/wireguard_kernel/stats.rs
index 8604e8243f..a055a35d10 100644
--- a/talpid-wireguard/src/wireguard_kernel/stats.rs
+++ b/talpid-wireguard/src/wireguard_kernel/stats.rs
@@ -1,3 +1,5 @@
+use std::time::{Duration, SystemTime, UNIX_EPOCH};
+
use super::wg_message::{DeviceMessage, DeviceNla, PeerNla};
use crate::stats::{Stats, StatsMap};
@@ -10,18 +12,39 @@ impl Stats {
for msg in peers {
let mut tx_bytes = 0;
let mut rx_bytes = 0;
+ let mut last_handshake_time = None;
let mut pub_key = None;
for nla in &msg.0 {
match nla {
PeerNla::TxBytes(bytes) => tx_bytes = *bytes,
PeerNla::RxBytes(bytes) => rx_bytes = *bytes,
+ PeerNla::LastHandshakeTime(time) => {
+ last_handshake_time = || -> Option<SystemTime> {
+ // handshake_{sec,nsec} are relative to UNIX_EPOCH
+ // https://www.wireguard.com/xplatform/
+ Some(
+ UNIX_EPOCH
+ + Duration::new(
+ time.tv_sec().try_into().ok()?,
+ time.tv_nsec().try_into().ok()?,
+ ),
+ )
+ }();
+ }
PeerNla::PublicKey(key) => pub_key = Some(*key),
_ => continue,
}
}
if let Some(key) = pub_key {
- map.insert(key, Stats { tx_bytes, rx_bytes });
+ map.insert(
+ key,
+ Stats {
+ tx_bytes,
+ rx_bytes,
+ last_handshake_time,
+ },
+ );
}
}
}