-
-
Notifications
You must be signed in to change notification settings - Fork 127
fix: set UDP source address to original destination IP for Fly.io #642
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
When using UDP on Fly.io, packets arrive at a public IP but the socket is bound to an internal private address. This commit ensures that responses are sent from the same IP that the client sent to, which is critical for correct routing. The fix: 1. Store the original destination IP (from ControlMessage.Dst) in the session 2. Set ControlMessage.Src to that IP when sending responses This ensures that when a client sends to Fly.io's public IP, the response is sent from that same IP, not from the internal private address.
📝 WalkthroughWalkthroughThreads the original destination IP (extracted from UDP control messages) through server connection management into sessions so outbound writes can source the original destination IP. Also adds lint rules, switches a test to use strings.Builder, and updates a client NewSession call site. Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant Server
participant ConnMgr as ConnManager
participant Session
participant Network
Client->>Server: UDP packet arrives (with control msg)
Server->>Server: extract cm.Dst as originalDstIP
Server->>ConnMgr: getConn(raddr, originalDstIP)
ConnMgr->>ConnMgr: getOrCreateConn(..., originalDstIP)
ConnMgr->>Session: NewSession(..., originalDstIP)
Session->>Network: WriteMessage(..., ctlMsg with Src=originalDstIP)
Network-->>Client: packet sent (source set to originalDstIP)
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
udp/server/session.go (1)
38-56: Fix compilation errors inNewSessioncalls - signature mismatch.The change to
NewSessioninudp/server/session.goadds anoriginalDstIPparameter, but the caller inudp/client.go(lines 88–95) passes parameters in the wrong order and with type mismatches:
- Expected:
ctx, doneCtx, connection, raddr, originalDstIP, maxMessageSize, mtu, closeSocket- Passed:
cfg.Ctx, context.Background(), l, addr, cfg.MaxMessageSize, cfg.MTU, cfg.CloseSocketThis causes:
maxMessageSize(uint32) passed whereoriginalDstIP(net.IP) is expected, and subsequent parameters are misaligned. The code will not compile.To preserve backward compatibility for external callers, consider the suggested approach: maintain the old signature with
originalDstIPoptional, and add a newNewSessionWithOriginalDstIPfunction for callers that need to specify it. Then update internal callers likeudp/client.goto either use the new function or passnilfororiginalDstIP.
|
Hi @denysvitali, thank you for contributing! From my side, the changes look good, but could you please also fix the build issues? |
jkralik
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pls, fix build and tests.
Add nil argument for originalDstIP parameter in NewSession call in udp/client.go that was missed in the previous commit. Also fix golangci-lint issues: use strings.Builder for loop concatenation and add exclusions for intentional stdlib-shadowing package names. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
When using UDP on Fly.io, packets arrive at a public IP but the socket is bound to an internal private address. This commit ensures that responses are sent from the same IP that the client sent to, which is critical for correct routing.
The fix:
This ensures that when a client sends to Fly.io's public IP, the response is sent from that same IP, not from the internal private address.
See this report as well by @lyubchev.
I was able to get this working after using this patch.
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.