cmd/tailscale/cli: add debug function to print the netmap

It's possible to do this with a combination of watch-ipn and jq, but looking
at the netmap while debugging is quite common, so it's nice to have a one-shot
command to get it.

Updates #cleanup

Signed-off-by: David Anderson <danderson@tailscale.com>
pull/10324/head
David Anderson 1 year ago committed by Dave Anderson
parent fd22145b52
commit f867392970

@ -193,6 +193,16 @@ var debugCmd = &ffcli.Command{
return fs return fs
})(), })(),
}, },
{
Name: "netmap",
Exec: runNetmap,
ShortHelp: "print the current network map",
FlagSet: (func() *flag.FlagSet {
fs := newFlagSet("netmap")
fs.BoolVar(&netmapArgs.showPrivateKey, "show-private-key", false, "include node private key in printed netmap")
return fs
})(),
},
{ {
Name: "via", Name: "via",
Exec: runVia, Exec: runVia,
@ -448,6 +458,33 @@ func runWatchIPN(ctx context.Context, args []string) error {
return nil return nil
} }
var netmapArgs struct {
showPrivateKey bool
}
func runNetmap(ctx context.Context, args []string) error {
ctx, cancel := context.WithTimeout(ctx, 5*time.Second)
defer cancel()
var mask ipn.NotifyWatchOpt = ipn.NotifyInitialNetMap
if !netmapArgs.showPrivateKey {
mask |= ipn.NotifyNoPrivateKeys
}
watcher, err := localClient.WatchIPNBus(ctx, mask)
if err != nil {
return err
}
defer watcher.Close()
n, err := watcher.Next()
if err != nil {
return err
}
j, _ := json.MarshalIndent(n.NetMap, "", "\t")
fmt.Printf("%s\n", j)
return nil
}
func runDERPMap(ctx context.Context, args []string) error { func runDERPMap(ctx context.Context, args []string) error {
dm, err := localClient.CurrentDERPMap(ctx) dm, err := localClient.CurrentDERPMap(ctx)
if err != nil { if err != nil {

Loading…
Cancel
Save