Add tsnet.Server.Underlay for DERP and magicsock sockets - #11
Open
chasylexus wants to merge 1 commit into
Open
chasylexus wants to merge 1 commit into
chasylexus wants to merge 1 commit into
Conversation
tsnet.Server.Dialer only reaches the control plane. DERP dials go through netns.NewDialerAlwaysDirect and magicsock binds its UDP sockets through netns.Listener or the process-global netns.ListenPacketFunc, so a tsnet user cannot move all of a server's own traffic onto one transport, and two servers in one process cannot use different transports. Add netmon.Underlay, carried per Monitor next to Dialer, and use it in derphttp.Client.dialContext and magicsock.Conn.listenPacket. Rebind keeps passing the current port through it, and the per-server value takes precedence over the process-global ListenPacketFunc. netcheck skips the ICMP probes when an Underlay is set, since ICMP cannot go through it. When Underlay is nil every path behaves as before.
nekohasekai
force-pushed
the
dev
branch
2 times, most recently
from
September 16, 2026 04:17
d6b37e9 to
66c96c3
Compare
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.
tsnet.Server.Dialeronly reaches the control plane. DERP dials go throughnetns.NewDialerAlwaysDirect, and magicsock binds its UDP sockets throughnetns.Listeneror the process-globalnetns.ListenPacketFunc. A tsnet user therefore cannot move all of a server's own traffic onto one transport, and two servers in one process cannot use different transports.This adds
netmon.Underlay, carried perMonitornext toDialer, and uses it inderphttp.Client.dialContext(DERP connections, including the netcheck HTTPS latency client) andmagicsock.Conn.listenPacket(peer, disco and STUN traffic).Rebindkeeps passing the current port through it, and the per-server value takes precedence over the process-globalListenPacketFunc. netcheck skips the ICMP probes when anUnderlayis set, since ICMP cannot go through it. Control plane connections keep usingDialer. WithUnderlaynil, every path behaves as before.Fallback or selection between transports is left to the caller; the hook only replaces the socket source.
Tests:
go build ./...go vet ./net/netmon/ ./derp/derphttp/ ./wgengine/magicsock/ ./net/netcheck/ ./tsnet/go test -race ./wgengine/magicsock/ ./derp/derphttp/ -run 'Underlay|DialNode|ListenPacket|Rebind'GOOS=linux,GOOS=windowsandGOOS=androidbuilds of./tsnet/,./net/netcheck/and./wgengine/magicsock/The new tests cover: sockets bound through the underlay, the current port surviving
Rebind, twoConns with independent underlays, DERPdialNodeusing the underlay, and the nil case binding and dialing directly.