Start of netcheck package & including network state in Hostinfo.
* adds new packet "netcheck" to do the checking of UDP, IPv6, and nearest DERP server, and the Report type for all that (and more in the future, probably pulling in danderson's natprobe) * new tailcfg.NetInfo type * cmd/tailscale netcheck subcommand (tentative name, likely to change/move) to print out the netcheck.Report. Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:
committed by
Brad Fitzpatrick
parent
a07af762e4
commit
14559340ee
@@ -0,0 +1,42 @@
|
||||
// Copyright (c) 2020 Tailscale Inc & AUTHORS All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
package main // import "tailscale.com/cmd/tailscale"
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"log"
|
||||
"sort"
|
||||
"time"
|
||||
|
||||
"github.com/pborman/getopt/v2"
|
||||
"tailscale.com/netcheck"
|
||||
)
|
||||
|
||||
func isSubcommand(cmd string) bool {
|
||||
return len(getopt.Args()) == 1 && getopt.Args()[0] == cmd
|
||||
}
|
||||
|
||||
func netcheckCmd() {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||||
defer cancel()
|
||||
report, err := netcheck.GetReport(ctx, log.Printf)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
fmt.Printf("\nReport:\n")
|
||||
fmt.Printf("\t* UDP: %v\n", report.UDP)
|
||||
fmt.Printf("\t* IPv6: %v\n", report.IPv6)
|
||||
fmt.Printf("\t* MappingVariesByDestIP: %v\n", report.MappingVariesByDestIP)
|
||||
fmt.Printf("\t* DERP latency:\n")
|
||||
var ss []string
|
||||
for s := range report.DERPLatency {
|
||||
ss = append(ss, s)
|
||||
}
|
||||
sort.Strings(ss)
|
||||
for _, s := range ss {
|
||||
fmt.Printf("\t\t- %s = %v\n", s, report.DERPLatency[s])
|
||||
}
|
||||
}
|
||||
@@ -59,6 +59,11 @@ func main() {
|
||||
nopf := getopt.BoolLong("no-packet-filter", 'F', "disable packet filter")
|
||||
advroutes := getopt.ListLong("routes", 'r', "routes to advertise to other nodes (comma-separated, e.g. 10.0.0.0/8,192.168.1.0/24)")
|
||||
getopt.Parse()
|
||||
// TODO(bradfitz): move this into a proper subcommand system when we have that.
|
||||
if isSubcommand("netcheck") {
|
||||
netcheckCmd()
|
||||
return
|
||||
}
|
||||
pol := logpolicy.New("tailnode.log.tailscale.io")
|
||||
if len(getopt.Args()) > 0 {
|
||||
log.Fatalf("too many non-flag arguments: %#v", getopt.Args()[0])
|
||||
|
||||
Reference in New Issue
Block a user