1716 Commits

Author SHA1 Message Date
Jordan Whited
50a476fbc4
wgengine/magicsock: fix magicsock deadlock around Conn.NoteRecvActivity (#16687) (#16696)
Updates #16651
Updates tailscale/corp#30836


(cherry picked from commit a9f3fd1c67ca427aceee708f319a0a12df6a5de8)

Signed-off-by: Jordan Whited <jordan@tailscale.com>
2025-07-28 19:28:27 -07:00
Jordan Whited
179745b83e
wgengine/magicsock: update discoInfo docs (#16638)
discoInfo is also used for holding peer relay server disco keys.

Updates #cleanup

Signed-off-by: Jordan Whited <jordan@tailscale.com>
2025-07-23 12:30:04 -07:00
Jordan Whited
1677fb1905
wgengine/magicsock,all: allocate peer relay over disco instead of PeerAPI (#16603)
Updates tailscale/corp#30583
Updates tailscale/corp#30534
Updates tailscale/corp#30557

Signed-off-by: Dylan Bargatze <dylan@tailscale.com>
Signed-off-by: Jordan Whited <jordan@tailscale.com>
Co-authored-by: Dylan Bargatze <dylan@tailscale.com>
2025-07-21 10:02:37 -07:00
Jordan Whited
36aeacb297
wgengine/magicsock: add peer relay metrics (#16582)
Updates tailscale/corp#30040

Signed-off-by: Jordan Whited <jordan@tailscale.com>
2025-07-16 14:34:05 -07:00
Jordan Whited
3c6d17e6f1
cmd/tailscale/cli,ipn/ipnlocal,wgengine/magicsock: implement tailscale debug peer-relay-servers (#16577)
Updates tailscale/corp#30036

Signed-off-by: Jordan Whited <jordan@tailscale.com>
2025-07-16 10:03:05 -07:00
Jordan Whited
d65c0fd2d0
tailcfg,wgengine/magicsock: set peer relay CapVer (#16531)
Updates tailscale/corp#27502
Updates tailscale/corp#30051

Signed-off-by: Jordan Whited <jordan@tailscale.com>
2025-07-15 12:29:07 -07:00
Jordan Whited
b63f8a457d
wgengine/magicsock: prioritize trusted peer relay paths over untrusted (#16559)
A trusted peer relay path is always better than an untrusted direct or
peer relay path.

Updates tailscale/corp#30412

Signed-off-by: Jordan Whited <jordan@tailscale.com>
2025-07-14 15:09:31 -07:00
Jordan Whited
fc5050048e
wgengine/magicsock: don't acquire Conn.mu in udpRelayEndpointReady (#16557)
udpRelayEndpointReady used to write into the peerMap, which required
holding Conn.mu, but this changed in f9e7131.

Updates #cleanup

Signed-off-by: Jordan Whited <jordan@tailscale.com>
2025-07-14 10:42:56 -07:00
Jordan Whited
bd29a1c8c1
feature/relayserver,wgengine/magicsock: remove WIP gating of peer relay (#16533)
Updates tailscale/corp#30051

Signed-off-by: Jordan Whited <jordan@tailscale.com>
2025-07-10 18:52:01 -07:00
Dylan Bargatze
fed72e2aa9
cmd/tailscale, ipn/ipnstate, wgengine/magicsock: update ping output for peer relay (#16515)
Updates the output for "tailscale ping" to indicate if a peer relay was traversed, just like the output for DERP or direct connections.

Fixes tailscale/corp#30034

Signed-off-by: Dylan Bargatze <dylan@tailscale.com>
2025-07-10 18:22:25 -04:00
Jordan Whited
f9bfd8118a
wgengine/magicsock: resolve epAddr collisions across peer relay conns (#16526)
Updates tailscale/corp#30042
Updates tailscale/corp#29422

Signed-off-by: Jordan Whited <jordan@tailscale.com>
2025-07-10 12:41:14 -07:00
Jordan Whited
6a0fad1e10
wgengine/magicsock: don't peer relay if NodeAttrOnlyTCP443 is set (#16517)
Updates tailscale/corp#30138

Signed-off-by: Jordan Whited <jordan@tailscale.com>
2025-07-09 20:02:00 -07:00
Jordan Whited
ae8641735d
cmd/tailscale/cli,ipn/ipnstate,wgengine/magicsock: label peer-relay (#16510)
Updates tailscale/corp#30033

Signed-off-by: Jordan Whited <jordan@tailscale.com>
2025-07-09 15:17:51 -07:00
Dylan Bargatze
d40b25326c
tailcfg, wgengine/magicsock: disable all UDP relay usage if disable-relay-client is set (#16492)
If the NodeAttrDisableRelayClient node attribute is set, ensures that a node cannot allocate endpoints on a UDP relay server itself, and cannot use newly-discovered paths (via disco/CallMeMaybeVia) that traverse a UDP relay server.

Fixes tailscale/corp#30180

Signed-off-by: Dylan Bargatze <dylan@tailscale.com>
2025-07-09 18:06:58 -04:00
Jordan Whited
008a238acd
wgengine/magicsock: support self as candidate peer relay (#16499)
Updates tailscale/corp#30247

Signed-off-by: Jordan Whited <jordan@tailscale.com>
2025-07-09 09:16:29 -07:00
Jordan Whited
a60e0caf6a
wgengine/magicsock: remove conn.InitiationAwareEndpoint TODO (#16498)
It was implemented in 5b0074729d38f8cc301803da06086033f53b1b93.

Updates #cleanup

Signed-off-by: Jordan Whited <jordan@tailscale.com>
2025-07-08 19:37:09 -07:00
Jordan Whited
5b0074729d
go.mod,wgengine/magicsock: implement conn.InitiationAwareEndpoint (#16486)
Since a [*lazyEndpoint] makes wireguard-go responsible for peer ID, but
wireguard-go may not yet be configured for said peer, we need a JIT hook
around initiation message reception to call what is usually called from
an [*endpoint].

Updates tailscale/corp#30042

Signed-off-by: Jordan Whited <jordan@tailscale.com>
2025-07-08 09:45:18 -07:00
Naman Sood
04d24cdbd4
wgengine/netstack: correctly proxy half-closed TCP connections
TCP connections are two unidirectional data streams, and if one of these
streams closes, we should not assume the other half is closed as well.
For example, if an HTTP client closes its write half of the connection
early, it may still be expecting to receive data on its read half, so we
should keep the server -> client half of the connection open, while
terminating the client -> server half.

Fixes tailscale/corp#29837.

Signed-off-by: Naman Sood <mail@nsood.in>
2025-07-07 15:36:16 -04:00
Jordan Whited
a84d58015c
wgengine/magicsock: fix lazyEndpoint DstIP() vs SrcIP() (#16453)
These were flipped. DstIP() and DstIPBytes() are used internally by
wireguard-go as part of a handshake DoS mitigation strategy.

Updates tailscale/corp#20732
Updates tailscale/corp#30042

Signed-off-by: Jordan Whited <jordan@tailscale.com>
2025-07-07 10:06:38 -07:00
Jordan Whited
3b32cc7586
wgengine/magicsock: simplify Geneve-encapsulated disco.Ping handling (#16448)
Just make [relayManager] always handle it, there's no benefit to
checking bestAddr's.

Also, remove passing of disco.Pong to [relayManager] in
endpoint.handlePongConnLocked(), which is redundant with the callsite in
Conn.handleDiscoMessage(). Conn.handleDiscoMessage() already passes to
[relayManager] if the txID us not known to any [*endpoint].

Updates tailscale/corp#27502

Signed-off-by: Jordan Whited <jordan@tailscale.com>
2025-07-07 09:38:10 -07:00
Jordan Whited
540eb05638
wgengine/magicsock: make Conn.Send() lazyEndpoint aware (#16465)
A lazyEndpoint may end up on this TX codepath when wireguard-go is
deemed "under load" and ends up transmitting a cookie reply using the
received conn.Endpoint.

Updates tailscale/corp#20732
Updates tailscale/corp#30042

Signed-off-by: Jordan Whited <jordan@tailscale.com>
2025-07-07 08:45:13 -07:00
Dylan Bargatze
92a114c66d
tailcfg, feature/relayserver, wgengine/magicsock: invert UDP relay server nodeAttrs (#16444)
Inverts the nodeAttrs related to UDP relay client/server enablement to disablement, and fixes up the corresponding logic that uses them. Also updates the doc comments on both nodeAttrs.

Fixes tailscale/corp#30024

Signed-off-by: Dylan Bargatze <dylan@tailscale.com>
2025-07-04 12:48:38 -04:00
Jordan Whited
f9e7131772
wgengine/magicsock: make lazyEndpoint load bearing for UDP relay (#16435)
Cryptokey Routing identification is now required to set an [epAddr] into
the peerMap for Geneve-encapsulated [epAddr]s.

Updates tailscale/corp#27502
Updates tailscale/corp#29422
Updates tailscale/corp#30042

Signed-off-by: Jordan Whited <jordan@tailscale.com>
2025-07-02 13:27:30 -07:00
Jordan Whited
d2edf7133a
wgengine/magicsock: remove references to rucPtr (#16441)
It used to be a **RebindingUDPConn, now it's just a *RebindingUDPConn.

Updates #cleanup

Signed-off-by: Jordan Whited <jordan@tailscale.com>
2025-07-02 09:23:54 -07:00
Jordan Whited
47e77565c6
wgengine/magicsock: avoid handshaking relay endpoints that are trusted (#16412)
Changes to our src/address family can trigger blackholes.

This commit also adds a missing set of trustBestAddrUntil when setting
a UDP relay path as bestAddr.

Updates tailscale/corp#27502

Signed-off-by: Jordan Whited <jordan@tailscale.com>
2025-06-30 12:12:57 -07:00
Jordan Whited
3dc694b4f1
wgengine/magicsock: clear UDP relay bestAddr's on disco ping timeout (#16410)
Otherwise we can end up mirroring packets to them forever. We may
eventually want to relax this to direct paths as well, but start with
UDP relay paths, which have a higher chance of becoming untrusted and
never working again, to be conservative.

Updates tailscale/corp#27502

Signed-off-by: Jordan Whited <jordan@tailscale.com>
2025-06-27 19:11:59 -07:00
Jordan Whited
0a64e86a0d
wgengine/magicsock: move UDP relay path discovery to heartbeat() (#16407)
This was previously hooked around direct UDP path discovery /
CallMeMaybe transmission, and related conditions. Now it is subject to
relay-specific considerations.

Updates tailscale/corp#27502

Signed-off-by: Jordan Whited <jordan@tailscale.com>
2025-06-27 13:56:55 -07:00
Jordan Whited
b32a01b2dc
disco,net/udprelay,wgengine/magicsock: support relay re-binding (#16388)
Relay handshakes may now occur multiple times over the lifetime of a
relay server endpoint. Handshake messages now include a handshake
generation, which is client specified, as a means to trigger safe
challenge reset server-side.

Relay servers continue to enforce challenge values as single use. They
will only send a given value once, in reply to the first arriving bind
message for a handshake generation.

VNI has been added to the handshake messages, and we expect the outer
Geneve header value to match the sealed value upon reception.

Remote peer disco pub key is now also included in handshake messages,
and it must match the receiver's expectation for the remote,
participating party.

Updates tailscale/corp#27502

Signed-off-by: Jordan Whited <jordan@tailscale.com>
2025-06-26 19:30:14 -07:00
Jordan Whited
b2bf7e988e
wgengine/magicsock: add envknob to toggle UDP relay feature (#16396)
Updates tailscale/corp#27502

Signed-off-by: Jordan Whited <jordan@tailscale.com>
2025-06-26 18:39:47 -07:00
Jordan Whited
51d00e135b
wgengine/magicsock: fix relayManager alloc work cleanup (#16387)
Premature cancellation was preventing the work from ever being cleaned
up in runLoop().

Updates tailscale/corp#27502

Signed-off-by: Jordan Whited <jordan@tailscale.com>
2025-06-25 19:13:02 -07:00
Nick Khyl
9e28bfc69c ipn/ipnlocal,wgengine/magicsock: wait for magicsock to process pending events on authReconfig
Updates #16369

Signed-off-by: Nick Khyl <nickk@tailscale.com>
2025-06-24 16:39:08 -05:00
Jordan Whited
31eebdb0f8
wgengine/magicsock: send CallMeMaybeVia for relay endpoints (#16360)
If we acted as the allocator we are responsible for signaling it to the
remote peer in a CallMeMaybeVia message over DERP.

Updates tailscale/corp#27502

Signed-off-by: Jordan Whited <jordan@tailscale.com>
2025-06-23 16:13:58 -07:00
Jordan Whited
a589863d61
feature/relayserver,net/udprelay,wgengine/magicsock: implement retry (#16347)
udprelay.Server is lazily initialized when the first request is received
over peerAPI. These early requests have a high chance of failure until
the first address discovery cycle has completed.

Return an ErrServerNotReady error until the first address discovery
cycle has completed, and plumb retry handling for this error all the
way back to the client in relayManager.

relayManager can now retry after a few seconds instead of waiting for
the next path discovery cycle, which could take another minute or
longer.

Updates tailscale/corp#27502

Signed-off-by: Jordan Whited <jordan@tailscale.com>
2025-06-23 15:50:43 -07:00
Jordan Whited
9288efe592
wgengine/magicsock: remove premature return in handshakeServerEndpoint (#16351)
Any return underneath this select case must belong to a type switch case.

Updates tailscale/corp#27502

Signed-off-by: Jordan Whited <jordan@tailscale.com>
2025-06-23 08:53:29 -07:00
Jordan Whited
0905936c45
wgengine/magicsock: set Geneve header protocol for WireGuard (#16350)
Otherwise receives interpret as naked WireGuard.

Updates tailscale/corp#27502

Signed-off-by: Jordan Whited <jordan@tailscale.com>
2025-06-21 21:14:42 -07:00
Jordan Whited
61958f531c
wgengine/magicsock: set conn field in relayHandshakeDiscoMsgEvent (#16348)
Updates tailscale/corp#27502

Signed-off-by: Jordan Whited <jordan@tailscale.com>
2025-06-21 19:09:36 -07:00
Jordan Whited
e935a28a19
wgengine/magicsock: set rxDiscoMsgCh field in relayHandshakeWork (#16349)
Updates tailscale/corp#27502

Signed-off-by: Jordan Whited <jordan@tailscale.com>
2025-06-21 19:09:19 -07:00
Jordan Whited
cd9b9a8cad
wgengine/magicsock: fix relay endpoint allocation URL (#16344)
Updates tailscale/corp#27502

Signed-off-by: Jordan Whited <jordan@tailscale.com>
2025-06-20 19:23:52 -07:00
Jordan Whited
d3bb34c628
wgengine/magicsock: generate relay server set from tailnet policy (#16331)
Updates tailscale/corp#27502

Signed-off-by: Jordan Whited <jordan@tailscale.com>
2025-06-20 15:00:28 -07:00
Jordan Whited
583f740c0b
Revert "types/netmap,wgengine/magicsock: propagate CapVer to magicsock.endpoint (#16244)" (#16322)
This reverts commit 6a93b17c8cafc1d8e1c52e133511e52ed9086355.

The reverted commit added more complexity than it was worth at the
current stage. Handling delta CapVer changes requires extensive changes
to relayManager datastructures in order to also support delta updates of
relay servers.

Updates tailscale/corp#27502

Signed-off-by: Jordan Whited <jordan@tailscale.com>
2025-06-19 09:47:06 -07:00
Jordan Whited
fcab50b276
ipn/ipnlocal,wgengine{/magicsock}: replace SetNetworkMap with eventbus (#16299)
Same with UpdateNetmapDelta.

Updates tailscale/corp#27502
Updates #15160

Signed-off-by: Jordan Whited <jordan@tailscale.com>
2025-06-18 10:31:00 -07:00
Jordan Whited
8e6f63cf11
ipn/ipnlocal,wgengine/magicsock: use eventbus for node & filter updates (#16271)
nodeBackend now publishes filter and node changes to eventbus topics
that are consumed by magicsock.Conn

Updates tailscale/corp#27502
Updates tailscale/corp#29543

Signed-off-by: Jordan Whited <jordan@tailscale.com>
2025-06-16 08:42:09 -07:00
Jordan Whited
6a93b17c8c
types/netmap,wgengine/magicsock: propagate CapVer to magicsock.endpoint (#16244)
This enables us to mark nodes as relay capable or not. We don't actually
do that yet, as we haven't established a relay CapVer.

Updates tailscale/corp#27502

Signed-off-by: Jordan Whited <jordan@tailscale.com>
2025-06-10 17:31:14 -07:00
Jordan Whited
9501f66985
wgengine/magicsock: don't cancel in-progress relayManager work (#16233)
It might complete, interrupting it reduces the chances of establishing a
relay path.

Updates tailscale/corp#27502

Signed-off-by: Jordan Whited <jordan@tailscale.com>
2025-06-09 15:37:58 -07:00
Jordan Whited
c343bffa72
wgengine/relaymanager: don't start runLoop() on init() (#16231)
This is simply for consistency with relayManagerInputEvent(), which
should be the sole launcher of runLoop().

Updates tailscale/corp#27502

Signed-off-by: Jordan Whited <jordan@tailscale.com>
2025-06-09 14:49:00 -07:00
Jordan Whited
67b1693c13
wgengine/magicsock: enable setting relay epAddr's as bestAddr (#16229)
relayManager can now hand endpoint a relay epAddr for it to consider
as bestAddr.

endpoint and Conn disco ping/pong handling are now VNI-aware.

Updates tailscale/corp#27502
Updates tailscale/corp#29422

Signed-off-by: Jordan Whited <jordan@tailscale.com>
2025-06-09 13:17:14 -07:00
Jordan Whited
66ae8737f4
wgengine/magicsock: make endpoint.bestAddr Geneve-aware (#16195)
This commit adds a new type to magicsock, epAddr, which largely ends up
replacing netip.AddrPort in packet I/O paths throughout, enabling
Geneve encapsulation over UDP awareness.

The conn.ReceiveFunc for UDP has been revamped to fix and more clearly
distinguish the different classes of packets we expect to receive: naked
STUN binding messages, naked disco, naked WireGuard, Geneve-encapsulated
disco, and Geneve-encapsulated WireGuard.

Prior to this commit, STUN matching logic in the RX path could swallow
a naked WireGuard packet if the keypair index, which is randomly
generated, happened to overlap with a subset of the STUN magic cookie.

Updates tailscale/corp#27502
Updates tailscale/corp#29326

Signed-off-by: Jordan Whited <jordan@tailscale.com>
2025-06-06 09:46:29 -07:00
Claus Lensbøl
3f7a9f82e3
wgengine/magicsock: fix bpf fragmentation jump offsets (#16204)
Fragmented datagrams would be processed instead of being dumped right
away. In reality, thse datagrams would be dropped anyway later so there
should functionally not be any change. Additionally, the feature is off
by default.

Closes #16203

Signed-off-by: Claus Lensbøl <claus@tailscale.com>
2025-06-06 11:42:33 -04:00
Jordan Whited
5f35143d83
go.mod,wgengine/magicsock: update wireguard-go (#16148)
Our conn.Bind implementation is updated to make Send() offset-aware for
future VXLAN/Geneve encapsulation support.

Updates tailscale/corp#27502

Signed-off-by: Jordan Whited <jordan@tailscale.com>
2025-06-02 13:22:28 -07:00
Jordan Whited
ffc8ec289b
wgengine/magicsock: implement relayManager endpoint probing (#16029)
relayManager is responsible for disco ping/pong probing of relay
endpoints once a handshake is complete.

Future work will enable relayManager to set a relay endpoint as the best
UDP path on an endpoint if appropriate.

Updates tailscale/corp#27502

Signed-off-by: Jordan Whited <jordan@tailscale.com>
2025-05-28 10:45:59 -07:00