fix: isolate tunnel UDP sessions by listener - #3087
Open
fzlzjerry wants to merge 2 commits into
Open
Conversation
There was a problem hiding this comment.
Pull request overview
This PR fixes a UDP tunnel NAT/session collision where packets from the same client source IP:port were incorrectly sharing the same SNAT association across different tunnel listeners. It does so by incorporating the listener’s local address into the session key while preserving the real client address for metadata and write-back behavior.
Changes:
- Generate a listener-scoped session key for tunnel UDP packets (listener local addr + client addr).
- Extend the tunnel UDP packet implementation to carry a dedicated key address used for SNAT keying.
- Add a regression test covering one source socket sending via multiple tunnel listeners.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| listener/tunnel/udp.go | Builds a listener-scoped session key and stores it as a custom key address for SNAT key generation. |
| listener/tunnel/packet.go | Adds keyAddr and makes LocalAddr() return the keying address used by PacketAdapter.Key(). |
| listener/tunnel/udp_test.go | Adds a regression test validating key separation across listeners and preserving source metadata/write-back. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Signed-off-by: Morax <james20081204@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Root cause
UDP packet adapters used only the client source address as their NAT table key. As a result, tunnel listeners receiving packets from the same source IP and port shared one
PacketSender, even when their listening ports and forwarding targets were different.The tunnel packet now exposes a listener-scoped custom address for key generation while retaining the real source address as its raw address and write-back destination. Packets from the same source still reuse an association within one listener, but different listeners create independent associations.
User impact
A single UDP socket can send to multiple tunnel listener ports and each flow is forwarded to its configured target independently. Source metadata, inbound-port metadata, and reply routing remain unchanged.
Validation
go test ./listener/tunnel -count=1SKIP_INTEROP_TEST=1 CGO_ENABLED=0 go test ./... -count=1SKIP_INTEROP_TEST=1 CGO_ENABLED=0 go test ./... -count=1 -tags with_gvisorCloses #3052