mirror of
https://github.com/amnezia-vpn/amneziawg-linux-kernel-module.git
synced 2026-10-13 21:34:34 +00:00
[PR #170] fix: per-peer S3-S4 junk offset detection for backward compatibility #216
Labels
No labels
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
amnezia-vpn/amneziawg-linux-kernel-module#216
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/amnezia-vpn/amneziawg-linux-kernel-module/pull/170
Author: @otternetwork
Created: 4/30/2026
Status: 🔄 Open
Base:
master← Head:fix/per-peer-junk-offsets📝 Commits (4)
27c4269fix: restore per-peer legacy WireGuard client support7eb04a3fix: detect AWG 1.0 vs 2.0 peers for header generation419d1a8fix: per-peer S3-S4 junk offset detection for backward compatibilityf78f526feat: export per-peer last data receive timestamp via netlink📊 Changes
9 files changed (+251 additions, -56 deletions)
View changed files
📝
src/magic_header.h(+9 -0)📝
src/netlink.c(+48 -2)📝
src/netlink.h(+2 -1)📝
src/noise.c(+16 -1)📝
src/peer.c(+7 -0)📝
src/peer.h(+3 -0)📝
src/receive.c(+71 -16)📝
src/send.c(+79 -36)📝
src/uapi/wireguard.h(+16 -0)📄 Description
Summary
When an AWG 2.0 server has S3-S4 junk offsets configured (S3>0, S4>0), it prepends S3/S4 junk to cookie and transport packets for all AWG peers unconditionally. This breaks AWG clients that don't use S3-S4 offsets — they can't find the header at the expected offset and drop the packet.
This PR adds per-peer detection of S3-S4 junk offset support, following the established pattern of
advanced_security(#164) andranged_headers(#165):junk_offsetsfield tostruct wg_peerprepare_awg_message(), add fallback parsing: try AWG headers at standard offsets (without S3/S4 prefix) when the S3/S4-prefixed match failswg_packet_consume_data(), which updatespeer->junk_offsetsafter peer identification viakey_idxwg_packet_encrypt_workeronpeer->advanced_security && peer->junk_offsetsjunk_offsetsfrom true to false on real data packets (skb->len > MESSAGE_MINIMUM_LENGTH), not keepalives — some client implementations (notably wireguard-go based) omit S4 junk from keepalive packets while correctly adding it to data packetsTransient packet loss while switching to legacy mode
Because the handshake carries no information about whether the client supports S3/S4, the server cannot know the peer's capability until it observes actual transport packets. New peers optimistically inherit junk_offsets = true from the device configuration. When a client without S3/S4 connects, this creates a brief detection window:
During the step 2, server-to-client packets are dropped.
There is no workaround for this within the current design — S3/S4 junk is a transport-layer feature invisible at handshake time. However, this is a very minor issue in practice for several reasons:
UAPI extension
Expose the new flag to userspace via
WGPEER_A_JUNK_OFFSETSnetlink attribute (backward compatible — old userspace ignores unknown attributes). Combined with the existing flags, userspace can now fully distinguish peer capabilities:advanced_securityranged_headersjunk_offsetsDepends on #165 — must be merged first.
Test plan
WGPEER_A_JUNK_OFFSETSattribute for connected peersCloses #168
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.