diff options
| author | Brad Fitzpatrick <bradfitz@tailscale.com> | 2021-01-10 12:03:01 -0800 |
|---|---|---|
| committer | Brad Fitzpatrick <bradfitz@tailscale.com> | 2021-01-10 12:11:22 -0800 |
| commit | 5efb0a8bcad2ad7ba2f587fc5dbd74fc16eba17a (patch) | |
| tree | dac67f6f2da4a3b78623937c2446e1a4a5bbdb44 /cmd | |
| parent | c09d5a9e2844d255dccc6787bdec6c765f56a0e8 (diff) | |
| download | tailscale-5efb0a8bcad2ad7ba2f587fc5dbd74fc16eba17a.tar.xz tailscale-5efb0a8bcad2ad7ba2f587fc5dbd74fc16eba17a.zip | |
cmd/tailscale: change formatting of "tailscale status"
* show DNS name over hostname, removing domain's common MagicDNS suffix.
only show hostname if there's no DNS name.
but still show shared devices' MagicDNS FQDN.
* remove nerdy low-level details by default: endpoints, DERP relay,
public key. They're available in JSON mode still for those who need
them.
* only show endpoint or DERP relay when it's active with the goal of
making debugging easier. (so it's easier for users to understand
what's happening) The asterisks are gone.
* remove Tx/Rx numbers by default for idle peers; only show them when
there's traffic.
* include peers' owner login names
* add CLI option to not show peers (matching --self=true, --peers= also
defaults to true)
* sort by DNS/host name, not public key
* reorder columns
Diffstat (limited to 'cmd')
| -rw-r--r-- | cmd/tailscale/cli/status.go | 100 | ||||
| -rw-r--r-- | cmd/tailscale/depaware.txt | 1 | ||||
| -rw-r--r-- | cmd/tailscaled/depaware.txt | 1 |
3 files changed, 75 insertions, 27 deletions
diff --git a/cmd/tailscale/cli/status.go b/cmd/tailscale/cli/status.go index 782c4d8ef..52e30478e 100644 --- a/cmd/tailscale/cli/status.go +++ b/cmd/tailscale/cli/status.go @@ -14,6 +14,8 @@ import ( "net" "net/http" "os" + "sort" + "strings" "time" "github.com/peterbourgon/ff/v2/ffcli" @@ -21,6 +23,7 @@ import ( "tailscale.com/ipn" "tailscale.com/ipn/ipnstate" "tailscale.com/net/interfaces" + "tailscale.com/util/dnsname" ) var statusCmd = &ffcli.Command{ @@ -34,6 +37,7 @@ var statusCmd = &ffcli.Command{ fs.BoolVar(&statusArgs.web, "web", false, "run webserver with HTML showing status") fs.BoolVar(&statusArgs.active, "active", false, "filter output to only peers with active sessions (not applicable to web mode)") fs.BoolVar(&statusArgs.self, "self", true, "show status of local machine") + fs.BoolVar(&statusArgs.peers, "peers", true, "show status of peers") fs.StringVar(&statusArgs.listen, "listen", "127.0.0.1:8384", "listen address; use port 0 for automatic") fs.BoolVar(&statusArgs.browser, "browser", true, "Open a browser in web mode") return fs @@ -47,6 +51,7 @@ var statusArgs struct { browser bool // in web mode, whether to open browser active bool // in CLI mode, filter output to only peers with active sessions self bool // in CLI mode, show status of local machine + peers bool // in CLI mode, show status of peer machines } func runStatus(ctx context.Context, args []string) error { @@ -136,47 +141,54 @@ func runStatus(ctx context.Context, args []string) error { f := func(format string, a ...interface{}) { fmt.Fprintf(&buf, format, a...) } printPS := func(ps *ipnstate.PeerStatus) { active := peerActive(ps) - f("%s %-7s %-15s %-18s tx=%8d rx=%8d ", - ps.PublicKey.ShortString(), - ps.OS, + f("%-15s %-20s %-12s %-7s ", ps.TailAddr, - ps.SimpleHostName(), - ps.TxBytes, - ps.RxBytes, + dnsOrQuoteHostname(st, ps), + ownerLogin(st, ps), + ps.OS, ) relay := ps.Relay - if active && relay != "" && ps.CurAddr == "" { - relay = "*" + relay + "*" - } else { - relay = " " + relay - } - f("%-6s", relay) - for i, addr := range ps.Addrs { - if i != 0 { - f(", ") - } - if addr == ps.CurAddr { - f("*%s*", addr) + anyTraffic := ps.TxBytes != 0 || ps.RxBytes != 0 + if !active { + if anyTraffic { + f("idle") } else { - f("%s", addr) + f("-") + } + } else { + f("active; ") + if relay != "" && ps.CurAddr == "" { + f("relay %q", relay) + } else if ps.CurAddr != "" { + f("direct %s", ps.CurAddr) } } + if anyTraffic { + f(", tx %d rx %d", ps.TxBytes, ps.RxBytes) + } f("\n") } if statusArgs.self && st.Self != nil { printPS(st.Self) } - for _, peer := range st.Peers() { - ps := st.Peer[peer] - if ps.ShareeNode { - continue + if statusArgs.peers { + var peers []*ipnstate.PeerStatus + for _, peer := range st.Peers() { + ps := st.Peer[peer] + if ps.ShareeNode { + continue + } + peers = append(peers, ps) } - active := peerActive(ps) - if statusArgs.active && !active { - continue + sort.Slice(peers, func(i, j int) bool { return sortKey(peers[i]) < sortKey(peers[j]) }) + for _, ps := range peers { + active := peerActive(ps) + if statusArgs.active && !active { + continue + } + printPS(ps) } - printPS(ps) } os.Stdout.Write(buf.Bytes()) return nil @@ -188,3 +200,37 @@ func runStatus(ctx context.Context, args []string) error { func peerActive(ps *ipnstate.PeerStatus) bool { return !ps.LastWrite.IsZero() && time.Since(ps.LastWrite) < 2*time.Minute } + +func dnsOrQuoteHostname(st *ipnstate.Status, ps *ipnstate.PeerStatus) string { + if i := strings.Index(ps.DNSName, "."); i != -1 && dnsname.HasSuffix(ps.DNSName, st.MagicDNSSuffix) { + return ps.DNSName[:i] + } + if ps.DNSName != "" { + return ps.DNSName + } + return fmt.Sprintf("- (%q)", ps.SimpleHostName()) +} + +func sortKey(ps *ipnstate.PeerStatus) string { + if ps.DNSName != "" { + return ps.DNSName + } + if ps.HostName != "" { + return ps.HostName + } + return ps.TailAddr +} + +func ownerLogin(st *ipnstate.Status, ps *ipnstate.PeerStatus) string { + if ps.UserID.IsZero() { + return "-" + } + u, ok := st.User[ps.UserID] + if !ok { + return fmt.Sprint(ps.UserID) + } + if i := strings.Index(u.LoginName, "@"); i != -1 { + return u.LoginName[:i+1] + } + return u.LoginName +} diff --git a/cmd/tailscale/depaware.txt b/cmd/tailscale/depaware.txt index 620838b17..4edd14a02 100644 --- a/cmd/tailscale/depaware.txt +++ b/cmd/tailscale/depaware.txt @@ -74,6 +74,7 @@ tailscale.com/cmd/tailscale dependencies: (generated by github.com/tailscale/dep tailscale.com/types/strbuilder from tailscale.com/net/packet tailscale.com/types/structs from tailscale.com/control/controlclient+ tailscale.com/types/wgkey from tailscale.com/control/controlclient+ + tailscale.com/util/dnsname from tailscale.com/cmd/tailscale/cli+ LW tailscale.com/util/endian from tailscale.com/net/netns+ tailscale.com/util/lineread from tailscale.com/control/controlclient+ tailscale.com/util/systemd from tailscale.com/control/controlclient+ diff --git a/cmd/tailscaled/depaware.txt b/cmd/tailscaled/depaware.txt index 1e2c8612b..b0f26cf51 100644 --- a/cmd/tailscaled/depaware.txt +++ b/cmd/tailscaled/depaware.txt @@ -82,6 +82,7 @@ tailscale.com/cmd/tailscaled dependencies: (generated by github.com/tailscale/de tailscale.com/types/strbuilder from tailscale.com/net/packet tailscale.com/types/structs from tailscale.com/control/controlclient+ tailscale.com/types/wgkey from tailscale.com/control/controlclient+ + tailscale.com/util/dnsname from tailscale.com/control/controlclient+ LW tailscale.com/util/endian from tailscale.com/net/netns+ tailscale.com/util/lineread from tailscale.com/control/controlclient+ tailscale.com/util/pidowner from tailscale.com/ipn/ipnserver |
