mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 21:18:19 +07:00
[PR #6376] [MERGED] fix(amneziawg): account for S4 junk in the default tunnel MTU #6239
Labels
No labels
backlog
bug
clarification needed
documentation
duplicate
enhancement
github_actions
good first issue
invalid
javascript
New Feature
PR welcomed
pull-request
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
MHSanaei/3x-ui#6239
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/MHSanaei/3x-ui/pull/6376
Author: @YoungReckless4
Created: 8/31/2026
Status: ✅ Merged
Merged: 9/8/2026
Merged by: @MHSanaei
Base:
main← Head:fix/amneziawg-mtu-s4📝 Commits (3)
f54e6eefix(amneziawg): account for S4 junk in the default tunnel MTU09d255bfix(amneziawg): rebuild the device when S4 changes the derived MTU0a430abMerge remote-tracking branch 'origin/main' into pr/6376📊 Changes
12 files changed (+263 additions, -26 deletions)
View changed files
📝
frontend/src/lib/xray/amneziawg-obfuscation.ts(+15 -0)📝
frontend/src/lib/xray/inbound-link.ts(+2 -3)📝
frontend/src/pages/clients/amneziawgConfig.ts(+2 -1)📝
frontend/src/test/amneziawg-conf-parity.test.ts(+76 -0)📝
internal/amneziawg/params.go(+13 -0)📝
internal/amneziawg/params_test.go(+36 -0)📝
internal/amneziawgnet/device.go(+2 -10)📝
internal/amneziawgnet/manager.go(+9 -8)📝
internal/amneziawgnet/manager_test.go(+63 -0)📝
internal/sub/service.go(+3 -3)📝
internal/sub/service_amneziawg_test.go(+40 -0)📝
internal/web/runtime/local.go(+2 -1)📄 Description
The bug
amneziawgprepends S4 random bytes to every transport packet(
device.NewOutboundElementsetselem.padding = device.paddings.transport) and,unlike
ContentPaddingAdditionandRandomTrailers, never clamps them against thetunnel MTU.
randomPaddingAdditionandcalculatePaddingSizeboth cap atmtu, sothey contribute 0 on a full-size packet;
randomTrailerreturns 0 for anything aboveDefaultUdpWindow. S4 is the one that always applies.A full-size packet therefore reaches the wire at:
With
defaultMTU = 1420that crosses 1500 as soon as S4 exceeds 20, andGenerateObfuscation31drawsS4 = randInt(12, 27)with both bounds inclusive —so roughly 44% of newly created inbounds (S4 in 21..27) fragment every full-size
packet they send, silently.
Measured, not derived
Two AmneziaWG interfaces in separate network namespaces joined by a veth pair,
measuring the outer UDP datagram:
The formula matches byte for byte at every point, and the threshold is exactly the
predicted S4 ≥ 21.
The fix
One new exported symbol,
EffectiveMTU(configuredMTU, s4)ininternal/amneziawg: an explicit MTUis returned untouched, otherwise
1420 - S4. The 1280 floor is defensive — validation caps S4 at32, so it cannot be reached through the panel.
Client configs now carry the same number. They previously omitted the
MTUlinewhenever the server had no explicit value, which left the client on its own 1420
default — so fixing only the server side would have left the client-to-server
direction fragmenting, silently and in one direction only.
All three emitters agree now. The two that matter most in practice are the
TypeScript ones —
buildAmneziaWGClientConfig(download/QR) andgenAmneziaWGConfig(thevpn://share link), since the AmneziaVPN client importsa config rather than polling a subscription — and
amneziaWGConfigTexton the Goside emits the same text for the subscription endpoint. That three-way agreement is
what
amneziawg-conf-parity.test.tsexists to protect, and the new cases therecover MTU specifically.
Tests
TestDefaultMTUForS4KeepsFullSizePacketsUnfragmented— sweeps S4 0..32 and assertsthe wire size never exceeds 1500. Fails on the old default from S4 = 21 up.
TestEffectiveMTUPrefersTheAdminsValue— an explicit MTU is never overridden.TestAmneziaWGClientConfigAlwaysCarriesTheServerMTU— the emitted client configalways contains the server's effective MTU.
gofmt,go vet ./...,go testoninternal/amneziawg,internal/amneziawgnet,internal/sub, plustsc --noEmitand the two affected frontend test files (61 tests)all pass.
Compatibility
Existing inbounds with an explicit MTU are unaffected. Inbounds relying on the default
get a smaller MTU on the next reconcile; clients must re-import their config (or refetch
the subscription) for the client side to match, which is the same requirement any MTU
change has always had.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.