mirror of
https://github.com/amnezia-vpn/amneziawg-go.git
synced 2026-10-14 05:41:54 +00:00
[PR #129] [MERGED] fix: apply S4 transport padding to keepalive packets #155
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-go#155
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-go/pull/129
Author: @wizier
Created: 3/31/2026
Status: ✅ Merged
Merged: 5/13/2026
Merged by: @ygurov
Base:
master← Head:fix/s4-keepalive-padding📝 Commits (2)
0e03177fix: apply S4 transport padding to keepalive packetsf19f048Merge branch 'master' into fix/s4-keepalive-padding📊 Changes
1 file changed (+8 additions, -9 deletions)
View changed files
📝
device/send.go(+8 -9)📄 Description
Bug
When S4 (transport padding) is non-zero, keepalive packets are sent without S4 padding, but the receiving side expects all transport packets to include it. This causes keepalives to be silently dropped, preventing the responder from ever calling
timersHandshakeComplete().Root cause
In
device/send.go:574-587,RoutineSequentialSenderonly adds S4 padding inside theif len(elem.packet) != MessageKeepaliveSizebranch:Keepalive packets (
len == MessageKeepaliveSize) skip the padding entirely.On the receive side (
device/receive.go:602-611),DeterminePacketTypeAndPaddingunconditionally expects S4 padding on all transport packets:An unpadded keepalive (32 bytes) passes the size check when S4 is small, but
packet[S4:]points into the middle of the real header — H4 validation fails and the packet is classified asMessageUnknownType→ dropped.What happens
current→ callstimersHandshakeComplete()→ sends keepalivenext(notcurrent) → waits for first transport packet to promote keypair and calltimersHandshakeComplete()DeterminePacketTypeAndPaddingfails → packet droppedlastHandshakeNanostays at 0 — keypair is never promoted fromnexttocurrentWhen S4 = 0 there is no issue — no padding expected, keepalive passes normally.
Fix
device/send.go:574-587—dataSentand padding are independent concerns:dataSentcontrolstimersDataSent(), padding is a property of all transport packets. Close thedataSentguard before the padding block so it applies to keepalives too.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.