mirror of
https://github.com/amnezia-vpn/amneziawg-go.git
synced 2026-10-13 21:34:25 +00:00
[PR #170] fix: send the first packet with the configured transport padding #184
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#184
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/170
Author: @anton-vinogradov
Created: 8/3/2026
Status: 🔄 Open
Base:
master← Head:fix/transport-padding-first-packet📝 Commits (1)
e449d12fix: send the first packet with the configured transport padding📊 Changes
2 files changed (+29 additions, -0 deletions)
View changed files
📝
device/device_test.go(+13 -0)📝
device/send.go(+16 -0)📄 Description
The problem
With
S4set, the tunnel loses its first data packet.device.TestAWGDevicePingshows it on currentmaster, no changes needed:The same test passes on
v0.2.19. Running one parameter at a time showss4is the only one that breaks it -jc,jmin,jmax,s1,s2,s3andh1-h4are all fine. Sending three pings in a row shows only the first is lost:Why
RoutineReadFromTUNreads the padding once and then blocks inReadwith an offset computed from it:The routine is started by
NewDevice, so it enters that firstReadbeforeIpcSethas appliedS4. The packet lands at offset 16, while the peer - configured by then - looks for the message type at offset16+S4.Logging the receiving side confirms it.
S4is 25, and the type is at offset 0 instead of 25:Only the first packet is affected, because the next pass of the loop reads the padding again.
This is a change from
0.2.x: there the padding was applied inRoutineSequentialSender, at send time, so it was always current. The 3.0 refactor moved it to read time and put it before the blocking call.The cost in practice is one TCP retransmit on the first connection after the device comes up, which is easy to miss but is still a lost packet on every start.
The change
Re-read the padding after
Readreturns, and move the packets if it changed. This covers a liveS4change over UAPI as well, not only start-up. The copy only runs when the value actually changed, so the normal path is one atomic load.Verification
device.TestAWGDevicePinganddevice.TestTwoDevicePingpass with the changego test ./...is green, andgo test -race ./device/is greenFound while adding AmneziaWG 3.0 support to a userspace client, where the first
connection through a fresh tunnel was reliably a second slower than the rest.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.