mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 21:18:19 +07:00
[PR #6780] [MERGED] fix(amneziawg): respect tunnel MTU when writing UDP replies #6452
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#6452
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/6780
Author: @mrdarkerr
Created: 10/9/2026
Status: ✅ Merged
Merged: 10/12/2026
Merged by: @MHSanaei
Base:
main← Head:fix/awg-udp-reply-mtu📝 Commits (6)
23ea0abfix(amneziawg): respect tunnel MTU when writing UDP replies7c403a1Merge branch 'main' into fix/awg-udp-reply-mtuc598e06Merge branch 'main' into fix/awg-udp-reply-mtue0a012bdocs(review): put the tally before Design and name who can store a triggerf2b24d8Merge branch 'main' into fix/awg-udp-reply-mtu5a76b0bMerge branch 'main' into fix/awg-udp-reply-mtu📊 Changes
4 files changed (+360 additions, -29 deletions)
View changed files
📝
internal/amneziawgnet/udp.go(+26 -29)➕
internal/amneziawgnet/udp_mtu_concurrent_test.go(+62 -0)➕
internal/amneziawgnet/udp_mtu_test.go(+97 -0)➕
internal/amneziawgnet/udp_mtu_v6_test.go(+175 -0)📄 Description
Summary
Make the embedded AmneziaWG UDP reply path respect the tunnel MTU by sending replies through gVisor's
FindRoute/Route.WritePacketinstead of injecting complete IP packets withWriteRawPacket.Only
internal/amneziawgnet/udp.goand three regression-test files are changed. No transport extensions, panel features, configuration fields, installer changes or dependency changes are included.Why
WriteRawPacketbypasses the normal network-endpoint path that applies the NIC MTU and fragments locally generated IP datagrams. A large UDP response can therefore be emitted into the AWG TUN as one IP packet larger than its configured MTU.On upstream main
442b7fb1637d6ecf4f2c28f76092228856e766c9, the new tests reproduce this with a 1280-byte TUN MTU and a 1452-byte UDP payload:The route-based path preserves the remote source/destination, ports and payload while letting gVisor construct and fragment the IP packets. It releases both route and packet references. UDP checksums remain valid, including encoding a zero-complement checksum as
0xffffrather than an invalid IPv6 UDP zero checksum. Address-family/zone and family-specific length checks prevent invalid datagrams and length truncation.This is a reproduced packet-sizing defect, not a claim that it explains every AWG throughput issue.
Type of change
Areas affected
How was this tested?
The regression tests consume actual channel-backed TUN output, check every emitted packet against the MTU, reassemble IPv4/IPv6 fragments, and verify addresses, UDP ports, payload and checksums. They also cover invalid lengths/addresses, the IPv6 zero-complement checksum and concurrent reply sources.
Before applying the fix, the following command exited 1 on the oversized IPv4/IPv6 cases and the IPv6 zero-checksum case:
After applying the fix, these local checks passed:
make verifyalso passed codegen freshness, golangci-lint (0 issues), frontend lint, format and typecheck before stopping atmsw-worker-check. The trackedfrontend/public/mockServiceWorker.jsis byte-identical to upstream main, but differs from the worker installed by the unchanged lockfile's MSW 3.0.2. This PR does not modify either file or the lockfile.A separate
make test-feattempt could not complete browser coverage: Playwright Chromium could not launch because this environment lackslibatk-1.0.so.0. Therefore fullmake verify/ frontend test success is not claimed. Browser dependencies, the shared worker mismatch, full-repository race, live PostgreSQL/node E2E and mobile-network performance are not verified by the local runs above.Screenshots / recordings
Not applicable; no UI changes.
Breaking changes
None. No settings, schema or client configuration changes are required.
Checklist
go build ./...and the Go test suite pass locally.make verifyand browser tests pass (limitations documented above).AI disclosure: Hermes Agent assisted with preparing this fix, regression tests and verification. All command outcomes reported above were executed locally.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.