From 04fabcd359df9f4a5da738ac47c232729f54a5b1 Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Sun, 24 Sep 2023 08:08:28 -0700 Subject: [PATCH] ipn/{ipnlocal,localapi}, cli: add debug force-netmap-update For loading testing & profiling the cost of full netmap updates. Updates #1909 Change-Id: I0afdf5de9967f8d95c7f81d5b531ed1c92c3208f Signed-off-by: Brad Fitzpatrick --- cmd/tailscale/cli/debug.go | 5 +++++ ipn/ipnlocal/local.go | 17 +++++++++++++++++ ipn/localapi/localapi.go | 2 ++ 3 files changed, 24 insertions(+) diff --git a/cmd/tailscale/cli/debug.go b/cmd/tailscale/cli/debug.go index 1fe3bf00b..c8c0f75c0 100644 --- a/cmd/tailscale/cli/debug.go +++ b/cmd/tailscale/cli/debug.go @@ -138,6 +138,11 @@ var debugCmd = &ffcli.Command{ Exec: localAPIAction("break-derp-conns"), ShortHelp: "break any open DERP connections from the daemon", }, + { + Name: "force-netmap-update", + Exec: localAPIAction("force-netmap-update"), + ShortHelp: "force a full no-op netmap update (for load testing)", + }, { Name: "control-knobs", Exec: debugControlKnobs, diff --git a/ipn/ipnlocal/local.go b/ipn/ipnlocal/local.go index 94e995aaa..97440bc81 100644 --- a/ipn/ipnlocal/local.go +++ b/ipn/ipnlocal/local.go @@ -2133,6 +2133,23 @@ func (b *LocalBackend) DebugNotify(n ipn.Notify) { b.send(n) } +// DebugForceNetmapUpdate forces a full no-op netmap update of the current +// netmap in all the various subsystems (wireguard, magicsock, LocalBackend). +// +// It exists for load testing reasons (for issue 1909), doing what would happen +// if a new MapResponse came in from the control server that couldn't be handled +// incrementally. +func (b *LocalBackend) DebugForceNetmapUpdate() { + b.mu.Lock() + defer b.mu.Unlock() + nm := b.netMap + b.e.SetNetworkMap(nm) + if nm != nil { + b.magicConn().SetDERPMap(nm.DERPMap) + } + b.setNetMapLocked(nm) +} + // send delivers n to the connected frontend and any API watchers from // LocalBackend.WatchNotifications (via the LocalAPI). // diff --git a/ipn/localapi/localapi.go b/ipn/localapi/localapi.go index c5fec6091..ec5b1cd79 100644 --- a/ipn/localapi/localapi.go +++ b/ipn/localapi/localapi.go @@ -557,6 +557,8 @@ func (h *Handler) serveDebug(w http.ResponseWriter, r *http.Request) { err = h.b.DebugBreakTCPConns() case "break-derp-conns": err = h.b.DebugBreakDERPConns() + case "force-netmap-update": + h.b.DebugForceNetmapUpdate() case "control-knobs": k := h.b.ControlKnobs() w.Header().Set("Content-Type", "application/json")