mirror of
https://github.com/tailscale/tailscale.git
synced 2025-10-03 11:31:12 +02:00
This doesn't yet fully pull it out into a feature/captiveportal package. This is the usual first step, moving the code to its own files within the same packages. Updates #17254 Change-Id: Idfaec839debf7c96f51ca6520ce36ccf2f8eec92 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
56 lines
1.3 KiB
Go
56 lines
1.3 KiB
Go
// Copyright (c) Tailscale Inc & AUTHORS
|
|
// SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
//go:build !ts_omit_captiveportal
|
|
|
|
package netcheck
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
"tailscale.com/net/captivedetection"
|
|
"tailscale.com/tailcfg"
|
|
)
|
|
|
|
func init() {
|
|
hookStartCaptivePortalDetection.Set(startCaptivePortalDetection)
|
|
}
|
|
|
|
func startCaptivePortalDetection(ctx context.Context, rs *reportState, dm *tailcfg.DERPMap, preferredDERP int) (done <-chan struct{}, stop func()) {
|
|
c := rs.c
|
|
|
|
// NOTE(andrew): we can't simply add this goroutine to the
|
|
// `NewWaitGroupChan` below, since we don't wait for that
|
|
// waitgroup to finish when exiting this function and thus get
|
|
// a data race.
|
|
ch := make(chan struct{})
|
|
|
|
tmr := time.AfterFunc(c.captivePortalDelay(), func() {
|
|
defer close(ch)
|
|
d := captivedetection.NewDetector(c.logf)
|
|
found := d.Detect(ctx, c.NetMon, dm, preferredDERP)
|
|
rs.report.CaptivePortal.Set(found)
|
|
})
|
|
|
|
stop = func() {
|
|
// Don't cancel our captive portal check if we're
|
|
// explicitly doing a verbose netcheck.
|
|
if c.Verbose {
|
|
return
|
|
}
|
|
|
|
if tmr.Stop() {
|
|
// Stopped successfully; need to close the
|
|
// signal channel ourselves.
|
|
close(ch)
|
|
return
|
|
}
|
|
|
|
// Did not stop; do nothing and it'll finish by itself
|
|
// and close the signal channel.
|
|
}
|
|
|
|
return ch, stop
|
|
}
|