From ba50c4c71ac116e6a6dca95306790b24d5865f29 Mon Sep 17 00:00:00 2001 From: contra Date: Wed, 6 May 2026 11:22:18 +0300 Subject: [PATCH] fix: detect WireGuard handshake when nanosecond component is zero The condition required both hsSec > 0 AND hsNano > 0, but a valid handshake can have nsec=0 (when it happens at an exact second boundary). Changed to OR so any non-zero timestamp is recognized as a successful handshake. --- services/wireguard/endpoint/userspace/device_parser.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/services/wireguard/endpoint/userspace/device_parser.go b/services/wireguard/endpoint/userspace/device_parser.go index 47583dadc1..e2cda970f9 100644 --- a/services/wireguard/endpoint/userspace/device_parser.go +++ b/services/wireguard/endpoint/userspace/device_parser.go @@ -191,10 +191,10 @@ func (dp *deviceParser) peerParse(key, value string) { dp.hsNano = dp.parseInt(value) // Assume that we've seen both seconds and nanoseconds and populate this - // field now. However, if both fields were set to 0, assume we have never - // had a successful handshake with this peer, and return a zero-value - // time.Time to our callers. - if dp.hsSec > 0 && dp.hsNano > 0 { + // field now. Only skip if BOTH are 0 (no handshake ever occurred). + // Note: either field alone can be 0 for a valid handshake (e.g. nsec=0 + // when the handshake happened at an exact second boundary). + if dp.hsSec > 0 || dp.hsNano > 0 { p.LastHandshakeTime = time.Unix(int64(dp.hsSec), int64(dp.hsNano)) } case "tx_bytes":