mirror of
https://github.com/tailscale/tailscale.git
synced 2025-04-20 21:51:42 +00:00
cmd/tailscale/cli: add debug --ipn mode
To watch the IPN message bus. Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:
parent
e67f1b5da0
commit
0301ccd275
@ -6,12 +6,15 @@ package cli
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"flag"
|
"flag"
|
||||||
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/peterbourgon/ff/v2/ffcli"
|
"github.com/peterbourgon/ff/v2/ffcli"
|
||||||
"tailscale.com/client/tailscale"
|
"tailscale.com/client/tailscale"
|
||||||
|
"tailscale.com/ipn"
|
||||||
)
|
)
|
||||||
|
|
||||||
var debugCmd = &ffcli.Command{
|
var debugCmd = &ffcli.Command{
|
||||||
@ -20,12 +23,16 @@ var debugCmd = &ffcli.Command{
|
|||||||
FlagSet: (func() *flag.FlagSet {
|
FlagSet: (func() *flag.FlagSet {
|
||||||
fs := flag.NewFlagSet("debug", flag.ExitOnError)
|
fs := flag.NewFlagSet("debug", flag.ExitOnError)
|
||||||
fs.BoolVar(&debugArgs.goroutines, "daemon-goroutines", false, "If true, dump the tailscaled daemon's goroutines")
|
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
|
return fs
|
||||||
})(),
|
})(),
|
||||||
}
|
}
|
||||||
|
|
||||||
var debugArgs struct {
|
var debugArgs struct {
|
||||||
goroutines bool
|
goroutines bool
|
||||||
|
ipn bool
|
||||||
|
netMap bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func runDebug(ctx context.Context, args []string) error {
|
func runDebug(ctx context.Context, args []string) error {
|
||||||
@ -38,6 +45,22 @@ func runDebug(ctx context.Context, args []string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
os.Stdout.Write(goroutines)
|
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
|
return nil
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user