From ec017ba795a721a74e85793d72589cc6218987f4 Mon Sep 17 00:00:00 2001 From: Saim Shafique Date: Sat, 14 Nov 2026 09:29:57 +0000 Subject: [PATCH] fix: don't advertise Tailscale addresses as direct endpoints Magicsock reports every local interface address, including the addresses of a tailscaled tunnel interface, and onEngineStatus advertised them all to the peer. A peer on the same LAN could then pick our Tailscale address as the direct path, running WireGuard inside Tailscale's WireGuard through a 1280-byte-MTU tun. On Linux the batched (GSO) sends on that path mostly never arrive, so throughput from Linux collapsed to tens of KB/s (#168). Skip endpoints whose address is a Tailscale address (tsaddr.IsTailscaleIP) when advertising; the plain LAN address is used instead, and DERP remains the fallback where no direct path exists. --- CHANGELOG.md | 10 ++++++++++ tailcat.go | 12 +++++++++++ tailcat_test.go | 53 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 75 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b87d718e3..12e1bac4d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,6 +29,16 @@ shared DERP relay mostly measures its rate limit; `--via-derp` allows relayed tests through your own relay, never through Tailscale's shared ones. +- Direct paths no longer go through a peer's Tailscale address: + tailcat used to offer its Tailscale addresses (100.64.0.0/10 or + fd7a:115c:a1e0::/48) as direct UDP endpoints, so two machines on the + same LAN that both run Tailscale could end up sending WireGuard + inside Tailscale's WireGuard, through a 1280-byte-MTU tunnel. On + Linux the batched (GSO) sends on that path mostly never arrived and + throughput from Linux collapsed to tens of KB/s. Those addresses + are no longer advertised; the plain LAN address is used instead, + and DERP remains the fallback where no direct path exists. + ([#168](https://github.com/tailscale/tailcat/issues/168)) ## v0.7.0 (2026-09-19) diff --git a/tailcat.go b/tailcat.go index 7585d3ace..c17b4fb5d 100644 --- a/tailcat.go +++ b/tailcat.go @@ -1547,12 +1547,24 @@ func (b *locoBackend) peerForIP(ip netip.Addr) (_ wgengine.PeerForIP, ok bool) { // has no control plane distributing endpoints, and magicsock never // attempts a direct path to a peer with no known endpoints, so these // advertisements are what make direct connections possible at all. +// +// Endpoints on a Tailscale address (100.64.0.0/10 or +// fd7a:115c:a1e0::/48) are left out: advertising one invites the peer +// to run our WireGuard inside Tailscale's WireGuard, through a tun +// device with a 1280-byte MTU, and on Linux the batched (GSO) sends +// on that path mostly never arrive, so throughput from Linux collapses +// to tens of KB/s (#168). A peer on the same LAN always has a plain +// LAN address to use instead, and where no direct path exists at all +// DERP remains the fallback. func (b *locoBackend) onEngineStatus(st *wgengine.Status, err error) { if err != nil || st == nil { return } var eps []netip.AddrPort for _, ep := range st.LocalAddrs { + if tsaddr.IsTailscaleIP(ep.Addr.Addr()) { + continue + } eps = append(eps, ep.Addr) } slices.SortFunc(eps, func(a, b netip.AddrPort) int { return a.Compare(b) }) diff --git a/tailcat_test.go b/tailcat_test.go index 6b7e7b285..a09818148 100644 --- a/tailcat_test.go +++ b/tailcat_test.go @@ -16,6 +16,7 @@ import ( "net/http/httptest" "net/netip" "os" + "slices" "strings" "sync" "sync/atomic" @@ -40,6 +41,7 @@ import ( "tailscale.com/tstest/integration" "tailscale.com/types/key" "tailscale.com/types/logger" + "tailscale.com/wgengine" "tailscale.com/wgengine/filter" ) @@ -1682,3 +1684,54 @@ func TestPeerKey(t *testing.T) { } } } + +func TestOnEngineStatusFiltersTailscaleEndpoints(t *testing.T) { + // Magicsock reports every local interface address as a UDP + // endpoint, including the addresses of a tailscaled tunnel + // interface when the machine also runs Tailscale. Advertising + // one of those invites the peer to run our WireGuard inside + // Tailscale's WireGuard, through a 1280-byte-MTU tun, and on + // Linux the batched (GSO) sends on that path mostly never + // arrive (#168). Only the non-Tailscale endpoints may be + // advertised. + b := &locoBackend{} + b.onEngineStatus(&wgengine.Status{LocalAddrs: []tailcfg.Endpoint{ + {Addr: netip.MustParseAddrPort("192.168.1.2:1234"), Type: tailcfg.EndpointLocal}, + {Addr: netip.MustParseAddrPort("100.64.1.2:1234"), Type: tailcfg.EndpointLocal}, + {Addr: netip.MustParseAddrPort("[fd7a:115c:a1e0::1]:1234"), Type: tailcfg.EndpointLocal}, + {Addr: netip.MustParseAddrPort("203.0.113.5:1234"), Type: tailcfg.EndpointSTUN}, + {Addr: netip.MustParseAddrPort("[2001:db8::1]:1234"), Type: tailcfg.EndpointLocal}, + {Addr: netip.MustParseAddrPort("100.127.255.255:1234"), Type: tailcfg.EndpointLocal}, + {Addr: netip.MustParseAddrPort("100.128.0.1:1234"), Type: tailcfg.EndpointLocal}, + {Addr: netip.MustParseAddrPort("[fd7a:115c:a1e1::1]:1234"), Type: tailcfg.EndpointLocal}, + }}, nil) + b.mu.Lock() + got := append([]netip.AddrPort(nil), b.eps...) + b.mu.Unlock() + want := []netip.AddrPort{ + netip.MustParseAddrPort("100.128.0.1:1234"), + netip.MustParseAddrPort("192.168.1.2:1234"), + netip.MustParseAddrPort("203.0.113.5:1234"), + netip.MustParseAddrPort("[2001:db8::1]:1234"), + // Just outside the Tailscale ULA range (fd7a:115c:a1e0::/48 + // covers a1e0, not a1e1), so it stays advertised. + netip.MustParseAddrPort("[fd7a:115c:a1e1::1]:1234"), + } + if !slices.Equal(got, want) { + t.Fatalf("advertised endpoints = %v; want %v", got, want) + } + + // If every endpoint is a Tailscale address, nothing is + // advertised and no direct path is attempted; DERP remains. + b = &locoBackend{} + b.onEngineStatus(&wgengine.Status{LocalAddrs: []tailcfg.Endpoint{ + {Addr: netip.MustParseAddrPort("100.64.1.2:1234"), Type: tailcfg.EndpointLocal}, + {Addr: netip.MustParseAddrPort("[fd7a:115c:a1e0::1]:1234"), Type: tailcfg.EndpointLocal}, + }}, nil) + b.mu.Lock() + got = append([]netip.AddrPort(nil), b.eps...) + b.mu.Unlock() + if len(got) != 0 { + t.Fatalf("advertised endpoints = %v; want none", got) + } +}