From e68d4d5805e1ba4a680681fccfbd85dad58557d5 Mon Sep 17 00:00:00 2001 From: julianknodt Date: Mon, 28 Jun 2021 17:51:10 -0700 Subject: [PATCH] cmd/tailscale: add debug flag to dump derp map This adds a flag in tailscale debug for dumping the derp map to stdout. Fixes #2249. Signed-off-by: julianknodt --- cmd/tailscale/cli/debug.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/cmd/tailscale/cli/debug.go b/cmd/tailscale/cli/debug.go index 851bb97de..a25cd41e4 100644 --- a/cmd/tailscale/cli/debug.go +++ b/cmd/tailscale/cli/debug.go @@ -31,6 +31,7 @@ var debugCmd = &ffcli.Command{ 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.prefs, "prefs", false, "If true, dump active prefs") + fs.BoolVar(&debugArgs.derpMap, "derp", false, "If true, dump DERP map") fs.BoolVar(&debugArgs.pretty, "pretty", false, "If true, pretty-print output (for --prefs)") fs.BoolVar(&debugArgs.netMap, "netmap", true, "whether to include netmap in --ipn mode") fs.BoolVar(&debugArgs.localCreds, "local-creds", false, "print how to connect to local tailscaled") @@ -44,6 +45,7 @@ var debugArgs struct { goroutines bool ipn bool netMap bool + derpMap bool file string prefs bool pretty bool @@ -87,6 +89,18 @@ func runDebug(ctx context.Context, args []string) error { os.Stdout.Write(goroutines) return nil } + if debugArgs.derpMap { + dm, err := tailscale.CurrentDERPMap(ctx) + if err != nil { + return fmt.Errorf( + "failed to get local derp map, instead `curl %s/derpmap/default`: %w", ipn.DefaultControlURL, err, + ) + } + enc := json.NewEncoder(os.Stdout) + enc.SetIndent("", "\t") + enc.Encode(dm) + return nil + } if debugArgs.ipn { c, bc, ctx, cancel := connect(ctx) defer cancel()