From 0301ccd27535ccb9f1898b0b0e45e76bfd32e14a Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Tue, 30 Mar 2021 10:42:35 -0700 Subject: [PATCH] cmd/tailscale/cli: add debug --ipn mode To watch the IPN message bus. Signed-off-by: Brad Fitzpatrick --- cmd/tailscale/cli/debug.go | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/cmd/tailscale/cli/debug.go b/cmd/tailscale/cli/debug.go index 50e9b9c23..b7a9e28bd 100644 --- a/cmd/tailscale/cli/debug.go +++ b/cmd/tailscale/cli/debug.go @@ -6,12 +6,15 @@ package cli import ( "context" + "encoding/json" "errors" "flag" + "fmt" "os" "github.com/peterbourgon/ff/v2/ffcli" "tailscale.com/client/tailscale" + "tailscale.com/ipn" ) var debugCmd = &ffcli.Command{ @@ -20,12 +23,16 @@ var debugCmd = &ffcli.Command{ FlagSet: (func() *flag.FlagSet { fs := flag.NewFlagSet("debug", flag.ExitOnError) fs.BoolVar(&debugArgs.goroutines, "daemon-goroutines", false, "If true, dump the tailscaled daemon's goroutines") + fs.BoolVar(&debugArgs.ipn, "ipn", false, "If true, subscribe to IPN notifications") + fs.BoolVar(&debugArgs.netMap, "netmap", true, "whether to include netmap in --ipn mode") return fs })(), } var debugArgs struct { goroutines bool + ipn bool + netMap bool } func runDebug(ctx context.Context, args []string) error { @@ -38,6 +45,22 @@ func runDebug(ctx context.Context, args []string) error { return err } os.Stdout.Write(goroutines) + return nil + } + if debugArgs.ipn { + c, bc, ctx, cancel := connect(ctx) + defer cancel() + + bc.SetNotifyCallback(func(n ipn.Notify) { + if !debugArgs.netMap { + n.NetMap = nil + } + j, _ := json.MarshalIndent(n, "", "\t") + fmt.Printf("%s\n", j) + }) + bc.RequestEngineStatus() + pump(ctx, bc, c) + return errors.New("exit") } return nil }