Repository navigation
fix(relay): skip private relay addresses on networks this host is not on - #609
Open
Battlelamb wants to merge 1 commit into
Open
Battlelamb wants to merge 1 commit into
Battlelamb wants to merge 1 commit into
Conversation
A relay offer lists every external address of the offering host. Relay selection treated any RFC 1918 / link-local address as "lan", so a peer reached over a tailnet always picked the offering host's home-LAN address (for example 192.168.1.39) and timed out, even when the same offer carried a reachable tailnet address. selectRelay now takes the CIDRs of this host's own interfaces (localNetworkCidrs) and skips a private address outside all of them in every tier, so selection falls through to the reachable address. When localNetworks is not given, behaviour is unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
🟡 Changes recommended
The interface-CIDR guard rejects reachable off-subnet private relays, causing previously usable relays to fall back to the public hub without being attempted.
1 open issue
What changed in this PR
This PR updates relay selection to avoid choosing private addresses on networks absent from the host’s interface CIDRs, aiming to prevent unnecessary dial timeouts between machines on different networks.
Changes:
- Adds optional local-network filtering while preserving existing behavior when omitted.
- Passes host interface CIDRs into runtime relay selection.
- Adds conformance cases for off-subnet filtering and on-subnet preference.
| File | Description |
|---|---|
src/test/conformance-functions.helper.ts |
Passes optional network CIDRs into conformance calls. |
src/core/relay-selection.ts |
Collects interface CIDRs and filters off-subnet private addresses. |
src/core/relay-role.ts |
Supplies host networks during relay selection. |
conformance/manifest.json |
Updates the relay-selection case count to 12. |
conformance/function/relay-selection.json |
Adds off-subnet and on-subnet selection cases. |
Review effort: Balanced
| for (const address of offer.addresses) { | ||
| const host = relayHost(address); | ||
| if (host === undefined) continue; | ||
| if (isPrivateHost(host) && !onLocalNetwork(host, local)) continue; |
This branch has not been deployed
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.

Problem
A relay offer lists every external address of the offering host (
RelayServerbinds0.0.0.0by default).selectRelaytreats any RFC 1918 or link-local address as tierlan, whether or not the selecting host is on that network.Setup where this shows up: two machines on one tailnet, on different physical networks. Machine A is a relay and offers
ws://192.168.1.39:36937/,ws://172.18.0.1:36937/(a Docker bridge) andws://100.123.240.67:36937/(its tailnet address). Machine B is on10.34.16.0/23. B picks thelanaddress192.168.1.39, which it cannot reach, and every start logs:The tailnet address is reachable, but it is never chosen. After the failed dial,
selectUrlexcludes the whole offer and B falls back to the public hub.Change
selectRelaytakes an optionallocalNetworksinput: the CIDRs of this host's interfaces. A private or link-local address outside every one of them is skipped in all tiers, so selection falls through to the reachable address. Here that is the tailnet address, in tiertrusted.localNetworkCidrs()builds the input fromos.networkInterfaces(), andRelayRole.selectUrlpasses it.localNetworksis not given, behaviour is unchanged, so the existing 10 conformance cases still pass as they are.Tests
function/relay-selection.json: an off-subnet private address is skipped in favour of the tailnet one, and an on-subnet private address is still chosen aslan. The manifest count goes from 10 to 12.tsc --noEmitandeslint .are clean.vitest run: 2846 passed and 3 failed. The 3 failures happen onmainwithout this change too:pi-manifest-packed,web-console-routeandweb-serverneed the built package or web dist.🤖 Generated with Claude Code