tailscale/cmd
Andrew Dunham e58bab77db tsnet2d: build daemon on tsnet.Server instead of re-wiring it
WARNING: this is an unreviewed prototype; please do not assume this
works or is correct

The daemon's startBackendLocked reimplemented tsnet/tsnet.go's start()
nearly line-for-line — same tsd.NewSystem, netmon.New, tsdial.Dialer,
wgengine.NewUserspaceEngine, netstack.Create, netstack dial-hooks,
store.New, ipnlocal.NewLocalBackend, prefs, NeedsLogin handling, and
localapi.NewHandler. Plus the daemon kept its own GetTCPHandlerForFlow
listener registry, its own LocalAPI handler, and a hand-rolled
tailscaleIPs() reading from NetMapNoPeers.

This is a pure refactor: the daemon now constructs a tsnet.Server and
delegates to it. No tsnet code is touched.

  startBackendLocked   ->  &tsnet.Server{...}.Start()
  awaitRunning (Up)    ->  ts.Up(ctx)
  RegisterListener     ->  ts.Listen + per-listener acceptLoop goroutine
  serveDatapath dial   ->  ts.Dial
  serveLocalAPI        ->  byte-splice via ts.LocalClient().Dial into
                           tsnet's in-process memnet localapi listener;
                           Hijacker and Flusher semantics still work
                           because we're a dumb byte pipe.
  whoIs                ->  ts.LocalClient().WhoIs
  tailscaleIPs         ->  ts.TailscaleIPs
  CertDomains          ->  ts.CertDomains

Deletes the daemon-side getTCPHandlerForFlow / getUDPHandlerForFlow,
the listenerByKey registry, lookupListener, listenAddrFor +
pickEphemeralPort (tsnet's Listen handles port allocation), cmpOr,
the single-conn http.Server listener used to host our own localapi
handler, and the direct wgengine/magicsock/netstack/ipnlocal/
controlclient/tsdial/netmon/tsd/store/ipnauth/ipn/hostinfo imports.

Daemon size: 1160 -> 925 lines (-20%).
Mental surface in the daemon shrinks much more than the line count
because the heavy subsystems are no longer reached at all.

The integration test (TestTsnet2EndToEnd) still passes in ~8s; race
detector is clean. tsnet2/ (the client shim) is unchanged and still
imports zero of wgengine / magicsock / ipnlocal / netstack / localapi
/ controlclient (verified via go list -deps), so Goal 2 of the design
(WireGuard out of the app process) is preserved.

Minor behavior change: state file is now <state-dir>/tailscaled.state
instead of <state-dir>/tsnet2.state, because tsnet.Server picks the
filename. No v1 consumer depends on this.

Deferred: forwarding tsnet.Server.UserLogf (auth URLs etc.) over the
control channel to the app's UserLogf. tsnet logs them to its own
log.Printf for now.
2026-05-25 15:49:31 -04:00
..
addlicense all: remove AUTHORS file and references to it 2026-01-23 15:49:45 -08:00
build-webclient all: remove AUTHORS file and references to it 2026-01-23 15:49:45 -08:00
checkmetrics all: remove AUTHORS file and references to it 2026-01-23 15:49:45 -08:00
cigocacher cmd/cigocacher: make --stats flag best-effort (#18761) 2026-02-19 16:06:12 +00:00
cloner cmd/cloner: preserve nil-valued entries when cloning map (#19749) 2026-05-14 10:30:59 -04:00
connector-gen all: remove AUTHORS file and references to it 2026-01-23 15:49:45 -08:00
containerboot all: migrate code off Notify.NetMap to Notify.SelfChange 2026-05-01 06:51:40 -07:00
derper derp/derpserver: use hashtriemap for peer lookup 2026-05-12 16:08:16 -07:00
derpprobe all: remove AUTHORS file and references to it 2026-01-23 15:49:45 -08:00
dist all: remove AUTHORS file and references to it 2026-01-23 15:49:45 -08:00
distsign all: remove AUTHORS file and references to it 2026-01-23 15:49:45 -08:00
featuretags all: remove AUTHORS file and references to it 2026-01-23 15:49:45 -08:00
get-authkey all: remove AUTHORS file and references to it 2026-01-23 15:49:45 -08:00
gitops-pusher tsnet: make workload identity federation opt-in 2026-05-06 18:43:45 -07:00
hello cmd/hello: split css and js into separate files (#19771) 2026-05-15 09:37:22 -07:00
jsonimports all: remove AUTHORS file and references to it 2026-01-23 15:49:45 -08:00
k8s-nameserver cmd/vet: add subtestnames analyzer; fix all existing violations 2026-04-05 15:52:51 -07:00
k8s-operator tsnet: make workload identity federation opt-in 2026-05-06 18:43:45 -07:00
k8s-proxy cmd/containerboot,cmd/k8s-proxy,kube: add authkey renewal to k8s-proxy (#19221) 2026-04-15 16:13:46 +01:00
mkmanifest all: remove AUTHORS file and references to it 2026-01-23 15:49:45 -08:00
mkpkg all: use Go 1.26 things, run most gofix modernizers 2026-03-06 13:32:03 -08:00
mkversion all: remove AUTHORS file and references to it 2026-01-23 15:49:45 -08:00
nardump tool/updateflakes, cmd/nardump: replace update-flake.sh with Go tool 2026-04-28 10:18:32 -07:00
natc all: use bart.Lite instead of bart.Table where appropriate 2026-03-24 14:45:23 +00:00
netlogfmt all: remove AUTHORS file and references to it 2026-01-23 15:49:45 -08:00
nginx-auth all: remove AUTHORS file and references to it 2026-01-23 15:49:45 -08:00
omitsize all: remove AUTHORS file and references to it 2026-01-23 15:49:45 -08:00
pgproxy cmd/pgproxy: fix client TLS handshake timeout 2026-05-11 11:12:11 -07:00
printdep cmd/printdep: add --next flag to use rc Go build hash instead 2026-01-27 14:49:56 -08:00
proxy-test-server all: remove AUTHORS file and references to it 2026-01-23 15:49:45 -08:00
proxy-to-grafana all: remove AUTHORS file and references to it 2026-01-23 15:49:45 -08:00
sniproxy all: migrate code off Notify.NetMap to Notify.SelfChange 2026-05-01 06:51:40 -07:00
speedtest all: use Go 1.26 things, run most gofix modernizers 2026-03-06 13:32:03 -08:00
ssh-auth-none-demo ssh: replace tempfork with tailscale/gliderssh 2026-04-07 11:59:38 +01:00
stunc all: remove AUTHORS file and references to it 2026-01-23 15:49:45 -08:00
stund derp,types,util: use bufio Peek+Discard for allocation-free fast reads (#19067) 2026-03-24 10:52:20 -04:00
stunstamp all: use Go 1.26 things, run most gofix modernizers 2026-03-06 13:32:03 -08:00
sync-containers all: remove AUTHORS file and references to it 2026-01-23 15:49:45 -08:00
systray client/systray: support several different color themes 2026-04-27 18:54:14 -07:00
tailscale all: update more references to Tailnet/Network Lock 2026-05-15 16:23:50 +01:00
tailscaled wgengine, cmd/tailscaled, control/controlclient: remove Engine watchdog 2026-05-15 16:49:28 -07:00
testcontrol all: remove AUTHORS file and references to it 2026-01-23 15:49:45 -08:00
testwrapper cmd/testwrapper: print unit for package duration (#19663) 2026-05-06 22:31:48 +01:00
tl-longchain all: remove AUTHORS file and references to it 2026-01-23 15:49:45 -08:00
tsconnect all: migrate code off Notify.NetMap to Notify.SelfChange 2026-05-01 06:51:40 -07:00
tsidp tsnet: make workload identity federation opt-in 2026-05-06 18:43:45 -07:00
tsnet2d tsnet2d: build daemon on tsnet.Server instead of re-wiring it 2026-05-25 15:49:31 -04:00
tsnet-proxy cmd/tsnet-proxy: add tsnet-based port proxy tool (#19468) 2026-04-22 13:34:18 -04:00
tsp control/tsp, cmd/tsp: add low-level Tailscale protocol client and tool 2026-04-16 20:00:25 -07:00
tsshd all: remove AUTHORS file and references to it 2026-01-23 15:49:45 -08:00
tta tstest/natlab/vmtest: add TestDiscoKeyChange 2026-04-29 12:58:00 -07:00
vet cmd/vet/lowerell, drive/driveimpl: forbid variables named "l" or "I" 2026-05-04 14:03:28 -07:00
viewer cmd/cloner: preserve nil-valued entries when cloning map (#19749) 2026-05-14 10:30:59 -04:00
vnet all: remove AUTHORS file and references to it 2026-01-23 15:49:45 -08:00
xdpderper all: remove AUTHORS file and references to it 2026-01-23 15:49:45 -08:00