diagd: allow disabling ipv6 connectivity check in health.json

This makes rtr7-safe-update work in environments without IPv6.
This commit is contained in:
Michael Stapelberg 2023-08-12 16:14:13 +02:00
parent 681ccd815c
commit 05a7b11ba6

View File

@ -80,38 +80,49 @@ func firstError(re *diag.EvalResult) string {
return "" return ""
} }
func graph(uplink string, ipv6 bool) *diag.Monitor {
const ip6allrouters = "ff02::2" // no /etc/hosts on gokrazy
graph := diag.Link(uplink).
Then(diag.DHCPv4().
Then(diag.Ping4Gateway().
Then(diag.TCP4("www.google.ch:80"))))
if ipv6 {
graph = graph.
Then(diag.DHCPv6().
Then(diag.TCP6("lan0", "www.google.ch:80"))).
Then(diag.RouterAdvertisments(uplink).
Then(diag.Ping6Gateway().
Then(diag.TCP6(uplink, "www.google.ch:80")))).
Then(diag.Ping6("", ip6allrouters+"%"+uplink))
}
return diag.NewMonitor(graph)
}
func logic() error { func logic() error {
var ( var (
ifname = flag.String("interface", ifname = flag.String("interface",
"uplink0", "uplink0",
"interface name to query") "interface name to query")
) ipv6 = flag.Bool("ipv6",
const ( true,
ip6allrouters = "ff02::2" // no /etc/hosts on gokrazy "whether to expect IPv6 connectivity in health.json")
) )
flag.Parse() flag.Parse()
uplink := *ifname uplink := *ifname
m := diag.NewMonitor(diag.Link(uplink). mHumanReadable := graph(uplink, true) // for display only
Then(diag.DHCPv4(). mJSON := graph(uplink, *ipv6) // for updates
Then(diag.Ping4Gateway().
Then(diag.TCP4("www.google.ch:80")))).
Then(diag.DHCPv6().
Then(diag.TCP6("lan0", "www.google.ch:80"))).
Then(diag.RouterAdvertisments(uplink).
Then(diag.Ping6Gateway().
Then(diag.TCP6(uplink, "www.google.ch:80")))).
Then(diag.Ping6("", ip6allrouters+"%"+uplink)))
var mu sync.Mutex var mu sync.Mutex
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
mu.Lock() mu.Lock()
re := m.Evaluate() re := mHumanReadable.Evaluate()
mu.Unlock() mu.Unlock()
fmt.Fprintf(w, `<!DOCTYPE html><style type="text/css">ul { list-style-type: none; }</style><ul>`) fmt.Fprintf(w, `<!DOCTYPE html><style type="text/css">ul { list-style-type: none; }</style><ul>`)
dump(0, w, re) dump(0, w, re)
}) })
http.HandleFunc("/health.json", func(w http.ResponseWriter, r *http.Request) { http.HandleFunc("/health.json", func(w http.ResponseWriter, r *http.Request) {
mu.Lock() mu.Lock()
re := m.Evaluate() re := mJSON.Evaluate()
mu.Unlock() mu.Unlock()
reply := struct { reply := struct {
FirstError string `json:"first_error"` FirstError string `json:"first_error"`