mirror of
https://github.com/tailscale/tailscale.git
synced 2025-12-25 20:23:43 +00:00
ipn/ipnlocal: add a C2N endpoint for fetching a netmap
For debugging purposes, add a new C2N endpoint returning the current netmap. Optionally, coordination server can send a new "candidate" map response, which the client will generate a separate netmap for. Coordination server can later compare two netmaps, detecting unexpected changes to the client state. Updates tailscale/corp#32095 Signed-off-by: Anton Tolchanov <anton@tailscale.com>
This commit is contained in:
committed by
Anton Tolchanov
parent
394718a4ca
commit
4a04161828
@@ -1160,6 +1160,27 @@ func (c *Direct) sendMapRequest(ctx context.Context, isStreaming bool, nu Netmap
|
||||
return nil
|
||||
}
|
||||
|
||||
// NetmapFromMapResponseForDebug returns a NetworkMap from the given MapResponse.
|
||||
// It is intended for debugging only.
|
||||
func NetmapFromMapResponseForDebug(ctx context.Context, pr persist.PersistView, resp *tailcfg.MapResponse) (*netmap.NetworkMap, error) {
|
||||
if resp == nil {
|
||||
return nil, errors.New("nil MapResponse")
|
||||
}
|
||||
if resp.Node == nil {
|
||||
return nil, errors.New("MapResponse lacks Node")
|
||||
}
|
||||
|
||||
nu := &rememberLastNetmapUpdater{}
|
||||
sess := newMapSession(pr.PrivateNodeKey(), nu, nil)
|
||||
defer sess.Close()
|
||||
|
||||
if err := sess.HandleNonKeepAliveMapResponse(ctx, resp); err != nil {
|
||||
return nil, fmt.Errorf("HandleNonKeepAliveMapResponse: %w", err)
|
||||
}
|
||||
|
||||
return sess.netmap(), nil
|
||||
}
|
||||
|
||||
func (c *Direct) handleDebugMessage(ctx context.Context, debug *tailcfg.Debug) error {
|
||||
if code := debug.Exit; code != nil {
|
||||
c.logf("exiting process with status %v per controlplane", *code)
|
||||
|
||||
@@ -20,6 +20,7 @@ import (
|
||||
"go4.org/mem"
|
||||
"tailscale.com/control/controlknobs"
|
||||
"tailscale.com/health"
|
||||
"tailscale.com/ipn"
|
||||
"tailscale.com/tailcfg"
|
||||
"tailscale.com/tstest"
|
||||
"tailscale.com/tstime"
|
||||
@@ -27,6 +28,7 @@ import (
|
||||
"tailscale.com/types/key"
|
||||
"tailscale.com/types/logger"
|
||||
"tailscale.com/types/netmap"
|
||||
"tailscale.com/types/persist"
|
||||
"tailscale.com/types/ptr"
|
||||
"tailscale.com/util/eventbus/eventbustest"
|
||||
"tailscale.com/util/mak"
|
||||
@@ -1419,3 +1421,27 @@ func TestNetmapDisplayMessageIntegration(t *testing.T) {
|
||||
t.Errorf("unexpected message contents (-want +got):\n%s", diff)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNetmapForMapResponseForDebug(t *testing.T) {
|
||||
mr := &tailcfg.MapResponse{
|
||||
Node: &tailcfg.Node{
|
||||
ID: 1,
|
||||
Name: "foo.bar.ts.net.",
|
||||
},
|
||||
Peers: []*tailcfg.Node{
|
||||
{ID: 2, Name: "peer1.bar.ts.net.", HomeDERP: 1},
|
||||
{ID: 3, Name: "peer2.bar.ts.net.", HomeDERP: 1},
|
||||
},
|
||||
}
|
||||
ms := newTestMapSession(t, nil)
|
||||
nm1 := ms.netmapForResponse(mr)
|
||||
|
||||
prefs := &ipn.Prefs{Persist: &persist.Persist{PrivateNodeKey: ms.privateNodeKey}}
|
||||
nm2, err := NetmapFromMapResponseForDebug(t.Context(), prefs.View().Persist(), mr)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !reflect.DeepEqual(nm1, nm2) {
|
||||
t.Errorf("mismatch\nnm1: %s\nnm2: %s\n", logger.AsJSON(nm1), logger.AsJSON(nm2))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user