1687 Commits

Author SHA1 Message Date
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
Jordan Whited
080387558c
wgengine/magicsock: start to make disco reception Geneve aware (#15832)
Updates tailscale/corp#27502

Signed-off-by: Jordan Whited <jordan@tailscale.com>
2025-04-30 13:31:35 -07:00
Jordan Whited
61635f8670
wgengine/magicsock: support Geneve-encap'd Disco transmission (#15811)
Updates tailscale/corp#27502

Signed-off-by: Jordan Whited <jordan@tailscale.com>
2025-04-28 15:55:49 -07:00
M. J. Fromberger
dda2c0d2c2 wgengine/magicsock: subscribe to portmapper updates
When an event bus is plumbed in, use it to subscribe and react to port mapping
updates instead of using the client's callback mechanism. For now, the callback
remains available as a fallback when an event bus is not provided.

Updates #15160

Change-Id: I026adca44bf6187692ee87ae8ec02641c12f7774
Signed-off-by: M. J. Fromberger <fromberger@tailscale.com>
2025-04-16 10:10:45 -07:00
David Anderson
5399fa159a net/netmon: publish events to event bus
Updates #15160

Signed-off-by: David Anderson <dave@tailscale.com>
2025-04-16 10:10:45 -07:00
M. J. Fromberger
deb0b255ff all: update the tsd.System constructor name (#15372)
Replace NewSystemWithEventBus with plain NewSystem, and update all usage.
See https://github.com/tailscale/tailscale/pull/15355#discussion_r2003910766

Updates #15160

Change-Id: I64d337f09576b41d9ad78eba301a74b9a9d6ebf4
Signed-off-by: M. J. Fromberger <fromberger@tailscale.com>
2025-04-16 10:10:45 -07:00
M. J. Fromberger
baead61e44 {wgengine,util/portmapper}: add and plumb an event bus (#15359)
Updates #15160

Change-Id: I2510fb4a8905fb0abe8a8e0c5b81adb15d50a6f8
Signed-off-by: M. J. Fromberger <fromberger@tailscale.com>
2025-04-16 10:10:45 -07:00
M. J. Fromberger
418e19fb5e portmapper: update NewClient to use a Config argument
In preparation for adding more parameters (and later, moving some away), rework
the portmapper constructor to accept its arguments on a Config struct rather
than positionally.

This is a breaking change to the function signature, but one that is very easy
to update, and a search of GitHub reveals only six instances of usage outside
clones and forks of Tailscale itself, that are not direct copies of the code
fixed up here.

While we could stub in another constructor, I think it is safe to let those
folks do the update in-place, since their usage is already affected by other
changes we can't test for anyway.

Updates #15160

Change-Id: I9f8a5e12b38885074c98894b7376039261b43f43
Signed-off-by: M. J. Fromberger <fromberger@tailscale.com>
2025-04-16 10:10:45 -07:00
M. J. Fromberger
2ac6e1edfd wgengine: plumb an event bus into the userspace engine
Updates #15160

Change-Id: Ia695ccdddd09cd950de22abd000d4c531d6bf3c8
Signed-off-by: M. J. Fromberger <fromberger@tailscale.com>
2025-04-16 10:10:45 -07:00
M. J. Fromberger
ffb22ee353 all: construct new System values with an event bus pre-populated
Although, at the moment, we do not yet require an event bus to be present, as
we start to add more pieces we will want to ensure it is always available.  Add
a new constructor and replace existing uses of new(tsd.System) throughout.
Update generated files for import changes.

Updates #15160

Change-Id: Ie5460985571ade87b8eac8b416948c7f49f0f64b
Signed-off-by: M. J. Fromberger <fromberger@tailscale.com>
2025-04-16 10:10:45 -07:00
Jordan Whited
62182fc37d
wgengine/netstack: revert cubic cc to reno cc (#15677)
Updates google/gvisor#11632
Updates tailscale/corp#27717

Signed-off-by: Jordan Whited <jordan@tailscale.com>
2025-04-14 10:09:56 -07:00
Brad Fitzpatrick
6c914409cd Revert "ipn/ipnstate: add home DERP to tailscale status JSON"
This reverts commit 476a4c6ff174d46ce3b125c018c07c43713e1c10.

Reason: redundant with `tailscale status --json | jq '.Self.Relay'`
which we all forgot about. Whoops.

Updates #15625
2025-04-10 11:34:48 -07:00
Brad Fitzpatrick
476a4c6ff1 ipn/ipnstate: add home DERP to tailscale status JSON
Fixes #15625

Change-Id: Ic20dad2dab4ac52c666057845bdc3cf5c0ffcd8f
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2025-04-10 10:09:32 -07:00
Brad Fitzpatrick
fb96137d79 net/{netx,memnet},all: add netx.DialFunc, move memnet Network impl
This adds netx.DialFunc, unifying a type we have a bazillion other
places, giving it now a nice short name that's clickable in
editors, etc.

That highlighted that my earlier move (03b47a55c7956) of stuff from
nettest into netx moved too much: it also dragged along the memnet
impl, meaning all users of netx.DialFunc who just wanted netx for the
type definition were instead also pulling in all of memnet.

So move the memnet implementation netx.Network into memnet, a package
we already had.

Then use netx.DialFunc in a bunch of places. I'm sure I missed some.
And plenty remain in other repos, to be updated later.

Updates tailscale/corp#27636

Change-Id: I7296cd4591218e8624e214f8c70dab05fb884e95
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2025-04-08 10:07:47 -07:00
David Anderson
66664b3167 wgengine/router: default to a fake router on android
The regular android app constructs its own wgengine with
additional FFI shims, so this default codepath only affects
other handcrafted buids like tsnet, which do not let the
caller customize the innards of wgengine.

Android >=14 forbids the use of netlink sockets, which makes
the standard linux router fail to initialize.

Fixes #9836

Signed-off-by: David Anderson <dave@tailscale.com>
2025-04-03 14:37:14 -07:00
Brad Fitzpatrick
65c7a37bc6 all: use network less when running in v86 emulator
Updates #5794

Change-Id: I1d8b005a1696835c9062545f87b7bab643cfc44d
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2025-04-02 07:36:04 -07:00
Brad Fitzpatrick
bbdd3c3bde wgengine/router: add Plan 9 implementation
Updates #5794

Change-Id: Ib78a3ea971a2374d405b024ab88658ec34be59a6
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2025-04-02 07:36:04 -07:00
Brad Fitzpatrick
e3282c1632 wgengine/magicsock: avoid some log spam on Plan 9
Updates #5794

Change-Id: I12e8417ebd553f9951690c388fbe42228f8c9097
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2025-04-02 07:36:04 -07:00
Brad Fitzpatrick
60847128df net/tstun: add Plan 9 'tun' support
Updates #5794

Change-Id: I8c466cae25ae79be1097450a63e8c25c7b519331
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
2025-04-02 07:36:04 -07:00