Repository navigation
Transport: Pass UDP destination to dialer controllers - #7201
Conversation
UDP sockets use ListenPacket, whose Control callback supplies the local bind address. Passing that address to dialer controllers prevents the native TUN controller from recognizing loopback destinations, unlike TCP. With autoOutboundsInterface enabled, local UDP DNS and SOCKS relays can then be bound to the physical interface and fail to send on Windows. Supply the resolved remote endpoint to the controllers and document their address contract. Keep socket creation, explicit source binding and listener callbacks unchanged. Add IPv4/IPv6 regression cases for wildcard and explicit source addresses, including a check that the selected local source remains intact.
|
This is the last issue I encountered for now... Maybe you have a better way to address it. I use a dnscrypt server on localhost, and it is inaccessible when TUN is used. |
|
Question for the future: should I tell Codex to exclude tests from PRs? |
|
AI written tests always have the possibility of using impossible upstream calls to trigger bugs, and can lead to infinite expansion of test cases |
Noted... I perfectly understand what you mean. I periodically have to do cleanup passes to remove trivial tests or tests for situations that can never happen in reality. It is very annoying, but I often skip over them, especially when I vibe-code in parallel with my main job... What a time... |
|
In the old days, the network was slow, commits took forever, and a week was only enough for one PR. |
|
这报错 #7160 (comment) 会不会有关 |
This PR fixes it only for loopback connections because it skips binding entirely. |
|
@eliotcougar 想想咋修比较好 |
|
Hi @RPRX — I’m an AI coding agent based on Codex GPT6.1-Sol, assisting @eliotcougar with this investigation. I reproduced the remaining failure using the actual Windows TUN binding helper and default dialer: an IPv4 UDP destination gets a dual-stack socket ( I’m working on a separate, focused family-aware binding fix. The required interface binding must still fail closed; simply ignoring socket-option errors would reintroduce the loop/leak problem. I’ll also check dual-stack UDP and multi-destination usage before proposing the change, and submit a draft with native before/after evidence. |
|
@eliotcougar 没绷住,你还是换个astra来吧显得尊重些 |
I would love to, but Astra drains my weekly budget in a day... 😄 |
… TUN inbound's `autoOutboundsInterface` (#7214) And #7214 (comment) #7201 (comment) Fixes #7160 (comment) --------- Co-authored-by: patterniha <[email protected]>
Native TUN's
autoOutboundsInterfacecan break UDP connections to local DNS servers and local SOCKS relays. TCP to the same services continues working. The TUN controller explicitly exempts loopback destinations, but it is given the wrong address for UDP.DefaultSystemDialeropens UDP sockets withListenPacket, whoseControladdress is the local bind endpoint, often0.0.0.0:0. Forwarding that argument to dialer controllers makes TUN miss its loopback exemption and bind the socket to the physical interface. TCP controllers already receive the remote endpoint. On Windows the resulting UDP send fails with:Pass the resolved
destAddr.String()to UDP dialer controllers, consistent with the TCP path and the existing outbound socket-options call. Document that callback contract. Socket creation, explicit source binding, controller error handling and listener-controller arguments are unchanged; no configuration fields are added.Native reproduction
Tested on Windows 10/amd64 in Hyper-V, using Go 1.27.2 builds from unmodified v26.10.17 (
92ccc939) and from that source with only this destination-address correction. The test core processes contain no application-specific patches.A native TUN with an isolated
198.18.247.1/30gateway andautoOutboundsInterface: "Ethernet"installs the controller without taking over default routes or system DNS. After waiting for TUN to report ready, loopback UDP echo/DNS fixtures were exercised through both SOCKS and the native TUN data path. A second unmodified core supplied the local SOCKS-chain hop.Both stock TUN runs failed the same cases: UDP to
127.0.0.1,127.0.0.2and::1; local DNS forwarding; the built-in DNS client using a local resolver; and a local SOCKS UDP hop. Failed fixtures received zero requests. Direct UDP outside the test core, TCP by literal IP, and TCP through the SOCKS chain remained healthy. Hostname-based TCP also failed when its local DNS lookup failed, explaining how this can appear to break TCP connectivity too.This affects other inbounds in the same core because TUN registers a process-wide controller. It is not limited to packets entering the TUN adapter. A fresh build of the final PR source separately passed all 17 native probes, with graceful core shutdown and the original guest runtime, adapters and routes preserved. These are controlled functional tests, not throughput measurements or an estimate of failure frequency.
Regression coverage and validation
go test -mod=readonly ./transport/internet -count=100 -shuffle=on -timeout=90spassed; the SOCKS and DNS-outbound packages passed too. Freedom compiles and has no test files.go vet ./transport/internet, upstreamvformat, andgit diff --checkpassed.app/dnssuite stops at the existingTestTCPLocalNameServerWithIPv6Override, which receives an empty AAAA answer from its public resolver here. The same failure was reproduced on the unmodified base.