1705 Commits

Author SHA1 Message Date
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
Jordan Whited
70b6e8ca98
wgengine/magicsock: fix outdated heartbeat comment (#16023)
heartbeatInterval is currently 3s.

Updates #cleanup

Signed-off-by: Jordan Whited <jordan@tailscale.com>
2025-05-20 08:46:37 -07:00
Jordan Whited
3cc80cce6a
wgengine/magicsock: introduce virtualNetworkID type (#16021)
This type improves code clarity and reduces the chance of heap alloc as
we pass it as a non-pointer. VNI being a 3-byte value enables us to
track set vs unset via the reserved/unused byte.

Updates tailscale/corp#27502

Signed-off-by: Jordan Whited <jordan@tailscale.com>
2025-05-19 19:14:08 -07:00
Jordan Whited
87a4f17883
wgengine/magicsock: fix pong handling 'EndpointChange' reporting (#16018)
Updates #cleanup

Signed-off-by: Jordan Whited <jordan@tailscale.com>
2025-05-19 11:42:13 -07:00
Jordan Whited
469fabd8de
wgengine/magicsock: add missing logf arg (#15995)
Also, add the short version of the node key in parens to match existing
patterns.

Updates #cleanup

Signed-off-by: Jordan Whited <jordan@tailscale.com>
2025-05-16 16:12:59 -07:00
Jordan Whited
6de4a021bb
wgengine/magicsock: implement relayManager handshaking (#15977)
CallMeMaybeVia reception and endpoint allocation have been collapsed to
a single event channel. discoInfo caching for active relay handshakes
is now implemented.

Updates tailscale/corp#27502

Signed-off-by: Jordan Whited <jordan@tailscale.com>
2025-05-16 13:51:40 -07:00
Nick Khyl
ffb1dda245 ipn/ipnlocal,wgengine: move (*tsdial.Dialer).SetRoutes() calls from LocalBackend to userspaceEngine
This avoids reconfiguring the dialer unless the router config has changed.

Updates #12027

Signed-off-by: Nick Khyl <nickk@tailscale.com>
2025-05-12 20:51:08 -05:00
Irbe Krumina
2c16fcaa06
util/linuxfw,wgengine/router: add new netfilter rules for HA ingresses (#15896)
Add new rules to update DNAT rules for Kubernetes operator's
HA ingress where it's expected that rules will be added/removed
frequently (so we don't want to keep old rules around or rewrite
existing rules unnecessarily):
- allow deleting DNAT rules using metadata lookup
- allow inserting DNAT rules if they don't already
exist (using metadata lookup)

Updates tailscale/tailscale#15895

Signed-off-by: Irbe Krumina <irbe@tailscale.com>
Co-authored-by: chaosinthecrd <tom@tmlabs.co.uk>
2025-05-12 17:26:23 +01:00
Jordan Whited
0f4f808e70
wgengine/magicsock: re-shape relayManager to use an event loop (#15935)
The event loop removes the need for growing locking complexities and
synchronization. Now we simply use channels. The event loop only runs
while there is active work to do.

relayManager remains no-op inside magicsock for the time being.
endpoints are never 'relayCapable' and therefore endpoint & Conn will
not feed CallMeMaybeVia or allocation events into it.

A number of relayManager events remain unimplemented, e.g.
CallMeMaybeVia reception and relay handshaking.

Updates tailscale/corp#27502

Signed-off-by: Jordan Whited <jordan@tailscale.com>
2025-05-09 14:50:01 -07:00
Jordan Whited
fd63123849
wgengine/magicsock: shape relayManager and CallMeMaybeVia handling (#15864)
relayManager will eventually be responsible for handling the allocation
and handshaking of UDP relay server endpoints.

relay servers are endpoint-independent, and Conn must already maintain
handshake state for all endpoints. This justifies a new data structure
to fill these roles.

Updates tailscale/corp#27502

Signed-off-by: Jordan Whited <jordan@tailscale.com>
2025-05-02 13:08:17 -07:00
Jordan Whited
f05347a5bf
wgengine/magicsock: implement more relay handshake disco handling (#15856)
Conn.handleDiscoMessage() now makes a distinction between relay
handshake disco messages and peer disco messages.

Updates tailscale/corp#27502

Signed-off-by: Jordan Whited <jordan@tailscale.com>
2025-05-02 09:04:18 -07:00
Jordan Whited
ac04338a0d
wgengine/magicsock: fix discoInfo leak (#15845)
Conn.sendDiscoMessage() now verifies if the destination disco key is
associated with any known peer(s) in a thread-safe manner.

Updates #15844

Signed-off-by: Jordan Whited <jordan@tailscale.com>
2025-04-30 19:07:31 -07:00