[PR #271] BFD-like session-layer path-liveness probes #270

Open
opened 2026-10-25 04:17:49 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/amnezia-vpn/amneziawg-linux-kernel-module/pull/271
Author: @mvkvl
Created: 10/14/2026
Status: 🔄 Open

Base: master ← Head: pr2-bfd


📝 Commits (6)

  • 054f3d3 fix: record handshake completion when sending handshake response
  • 65e41a5 bfd: add probe marker format and peer stats fields
  • 811ae6b bfd: send reply and probe via staged packet path
  • f3418bf bfd: intercept probe and reply in receive path
  • fe6d455 bfd: add WGPEER_A_SEND_PROBE netlink attribute and probe stats
  • 55423cc compat: use linux/unaligned.h on kernel 6.12+

📊 Changes

9 files changed (+202 additions, -1 deletions)

View changed files

➕ src/bfd.h (+71 -0)
📝 src/compat/compat.h (+2 -0)
📝 src/netlink.c (+25 -1)
📝 src/peer.c (+1 -0)
📝 src/peer.h (+7 -0)
📝 src/queueing.h (+5 -0)
📝 src/receive.c (+27 -0)
📝 src/send.c (+53 -0)
📝 src/uapi/wireguard.h (+11 -0)

📄 Description

Title

bfd: add session-layer path-liveness probes (marker intercept, reply, netlink stats)

Body

Summary

Adds an optional session-layer BFD-style probe mechanism for path-specific
link liveness. A 30-byte marker is embedded in the decrypted data payload;
the peer intercepts it, replies via the already-updated endpoint, and drops
the probe so it never reaches the TUN interface. RTT and last-success
timestamps are exposed via netlink dump for userspace supervision.

Motivation

Kernel WireGuard supervision relies on last_handshake, Rx counters and
optional ICMP probes. All three have failure modes:

  • last_handshake freezes for idle or userspace peers (see PR #1 for the
    responder-side half of the fix).
  • Rx counters require actual traffic to grow.
  • ICMP probes through a relay are not path-specific: a live relay can mask
    a dead direct path.

A session-layer probe answers from the source endpoint of the decrypted
packet, making the check path-specific and relay-immune.

Design

  • Marker format (bfd.h): fixed 30-byte big-endian prefix of the
    decrypted data payload. First byte is 0x57 ('W'), so a valid IPv4/IPv6
    header (0x45/0x46/0x6x) can never match. Magic is 0x57534246 ("WSBF").
  • Receive intercept (receive.c): in wg_packet_consume_data_done,
    after the keepalive check and before data delivery, recognise the marker.
    PROBE → reply and drop; REPLY → record RTT and success timestamp.
    Non-marker packets continue unchanged.
  • Send path (send.c): wg_packet_send_bfd_reply() and
    wg_packet_send_bfd_probe() build the skb following the keepalive recipe
    (reserved head room, is_keepalive=false, skb_reset_network_header for
    ECN) and stage it. Encryption, endpoint xmit and the rest of the data
    path stay untouched. Without a valid keypair the staged packet triggers a
    handshake like any other data.
  • Netlink (netlink.c, uapi/wireguard.h):
    • WGPEER_A_SEND_PROBE (flag) — SET_DEVICE raises a per-peer request
      flag and schedules bfd_work on handshake_send_wq. No inline send
      while holding device_update_lock.
    • WGPEER_A_BFD_LAST_RTT_NS, WGPEER_A_BFD_LAST_OK_TS,
      WGPEER_A_BFD_LOSS, WGPEER_A_BFD_SEQ — GET_DEVICE dump reports
      per-peer statistics from lock-free atomics.
    • All new attributes are appended to the end of
      enum wgpeer_attribute, so existing wireguard-tools ABI values stay
      untouched.
  • Per-peer state (peer.h): lock-free atomics for last RTT, last
    success timestamp, unanswered-probe counter and last sequence number;
    plus a netlink request flag and work item.

Includes handshake fix

This branch also contains the one-line handshake-timestamp fix from PR #1
(wg_timers_handshake_complete in wg_packet_send_handshake_response),
which is a prerequisite for meaningful supervision on responder-only
sessions.

Compatibility

  • Non-marker packets (magic or version mismatch) continue through the
    normal data path unchanged.
  • Peers that do not send probes are unaffected.
  • The mechanism is opt-in: probes are only sent when userspace sets
    WGPEER_A_SEND_PROBE.
  • Built and tested against upstream master (4569c4c) on Debian 13
    (kernel 6.12.x) and Ubuntu 22.04 (kernel 5.15).

Testing

  • 3-node WireGuard lab (hub + 2 spokes, userspace and kernel dataplanes):
    • Probe/reply exchange verified via netlink dump (RTT < 1 ms on LAN).
    • Dropping the UDP port between hub and spoke: probes stop, supervision
      detects death in ~3 s (probe interval 1 s x loss threshold 3).
    • Relay path does not answer probes from the wrong endpoint
      (path-specificity confirmed).
  • Unit-level: marker encoding/decoding, non-marker passthrough, keepalive
    does not collide with marker (first byte 0x57 vs 0x00).
  • CPU overhead: < 1 % and < 1 kbit/s per peer at a 1 s probe interval
    (50-byte packets).

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/amnezia-vpn/amneziawg-linux-kernel-module/pull/271 **Author:** [@mvkvl](https://github.com/mvkvl) **Created:** 10/14/2026 **Status:** 🔄 Open **Base:** `master` ← **Head:** `pr2-bfd` --- ### 📝 Commits (6) - [`054f3d3`](https://github.com/amnezia-vpn/amneziawg-linux-kernel-module/commit/054f3d3b3b4d1f75238d927f1e30c36851afd5ad) fix: record handshake completion when sending handshake response - [`65e41a5`](https://github.com/amnezia-vpn/amneziawg-linux-kernel-module/commit/65e41a584d7ef8be8d7b5d0d0c9d5f57f7c8ccec) bfd: add probe marker format and peer stats fields - [`811ae6b`](https://github.com/amnezia-vpn/amneziawg-linux-kernel-module/commit/811ae6b86f22956bef2057da36da2cc2a436b778) bfd: send reply and probe via staged packet path - [`f3418bf`](https://github.com/amnezia-vpn/amneziawg-linux-kernel-module/commit/f3418bf0917c8e69257da2ae0f6cd470d5153191) bfd: intercept probe and reply in receive path - [`fe6d455`](https://github.com/amnezia-vpn/amneziawg-linux-kernel-module/commit/fe6d45573fa27fe6c3c323486617b5a5085ddea9) bfd: add WGPEER_A_SEND_PROBE netlink attribute and probe stats - [`55423cc`](https://github.com/amnezia-vpn/amneziawg-linux-kernel-module/commit/55423cc5159dfd9776c5bb0a2960672711b4b6b4) compat: use linux/unaligned.h on kernel 6.12+ ### 📊 Changes **9 files changed** (+202 additions, -1 deletions) <details> <summary>View changed files</summary> ➕ `src/bfd.h` (+71 -0) 📝 `src/compat/compat.h` (+2 -0) 📝 `src/netlink.c` (+25 -1) 📝 `src/peer.c` (+1 -0) 📝 `src/peer.h` (+7 -0) 📝 `src/queueing.h` (+5 -0) 📝 `src/receive.c` (+27 -0) 📝 `src/send.c` (+53 -0) 📝 `src/uapi/wireguard.h` (+11 -0) </details> ### 📄 Description ## Title bfd: add session-layer path-liveness probes (marker intercept, reply, netlink stats) ## Body ### Summary Adds an optional session-layer BFD-style probe mechanism for path-specific link liveness. A 30-byte marker is embedded in the decrypted data payload; the peer intercepts it, replies via the already-updated endpoint, and drops the probe so it never reaches the TUN interface. RTT and last-success timestamps are exposed via netlink dump for userspace supervision. ### Motivation Kernel WireGuard supervision relies on `last_handshake`, Rx counters and optional ICMP probes. All three have failure modes: - `last_handshake` freezes for idle or userspace peers (see PR #1 for the responder-side half of the fix). - Rx counters require actual traffic to grow. - ICMP probes through a relay are not path-specific: a live relay can mask a dead direct path. A session-layer probe answers from the source endpoint of the decrypted packet, making the check path-specific and relay-immune. ### Design - **Marker format** (`bfd.h`): fixed 30-byte big-endian prefix of the decrypted data payload. First byte is `0x57` ('W'), so a valid IPv4/IPv6 header (0x45/0x46/0x6x) can never match. Magic is `0x57534246` ("WSBF"). - **Receive intercept** (`receive.c`): in `wg_packet_consume_data_done`, after the keepalive check and before data delivery, recognise the marker. PROBE → reply and drop; REPLY → record RTT and success timestamp. Non-marker packets continue unchanged. - **Send path** (`send.c`): `wg_packet_send_bfd_reply()` and `wg_packet_send_bfd_probe()` build the skb following the keepalive recipe (reserved head room, `is_keepalive=false`, `skb_reset_network_header` for ECN) and stage it. Encryption, endpoint xmit and the rest of the data path stay untouched. Without a valid keypair the staged packet triggers a handshake like any other data. - **Netlink** (`netlink.c`, `uapi/wireguard.h`): - `WGPEER_A_SEND_PROBE` (flag) — SET_DEVICE raises a per-peer request flag and schedules `bfd_work` on `handshake_send_wq`. No inline send while holding `device_update_lock`. - `WGPEER_A_BFD_LAST_RTT_NS`, `WGPEER_A_BFD_LAST_OK_TS`, `WGPEER_A_BFD_LOSS`, `WGPEER_A_BFD_SEQ` — GET_DEVICE dump reports per-peer statistics from lock-free atomics. - All new attributes are appended to the **end** of `enum wgpeer_attribute`, so existing wireguard-tools ABI values stay untouched. - **Per-peer state** (`peer.h`): lock-free atomics for last RTT, last success timestamp, unanswered-probe counter and last sequence number; plus a netlink request flag and work item. ### Includes handshake fix This branch also contains the one-line handshake-timestamp fix from PR #1 (`wg_timers_handshake_complete` in `wg_packet_send_handshake_response`), which is a prerequisite for meaningful supervision on responder-only sessions. ### Compatibility - Non-marker packets (magic or version mismatch) continue through the normal data path unchanged. - Peers that do not send probes are unaffected. - The mechanism is opt-in: probes are only sent when userspace sets `WGPEER_A_SEND_PROBE`. - Built and tested against upstream `master` (4569c4c) on Debian 13 (kernel 6.12.x) and Ubuntu 22.04 (kernel 5.15). ### Testing - 3-node WireGuard lab (hub + 2 spokes, userspace and kernel dataplanes): - Probe/reply exchange verified via netlink dump (RTT < 1 ms on LAN). - Dropping the UDP port between hub and spoke: probes stop, supervision detects death in ~3 s (probe interval 1 s x loss threshold 3). - Relay path does not answer probes from the wrong endpoint (path-specificity confirmed). - Unit-level: marker encoding/decoding, non-marker passthrough, keepalive does not collide with marker (first byte 0x57 vs 0x00). - CPU overhead: < 1 % and < 1 kbit/s per peer at a 1 s probe interval (50-byte packets). --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No labels
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
amnezia-vpn/amneziawg-linux-kernel-module#270
No description provided.