Documentation
¶
Overview ¶
Package captivedetection provides a way to detect if the system is connected to a network that has a captive portal. It does this by making HTTP requests to known captive portal detection endpoints and checking if the HTTP responses indicate that a captive portal might be present.
Index ¶
Constants ¶
const Timeout = 3 * time.Second
Timeout is the timeout for captive portal detection requests. Because the captive portal intercepting our requests is usually located on the LAN, this is a relatively short timeout.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Detector ¶
type Detector struct {
// contains filtered or unexported fields
}
Detector checks whether the system is behind a captive portal.
func NewDetector ¶
NewDetector creates a new Detector instance for captive portal detection.
func (*Detector) Detect ¶
func (d *Detector) Detect(ctx context.Context, netMon *netmon.Monitor, derpMap *tailcfg.DERPMap, preferredDERPRegionID int) (found bool)
Detect is the entry point to the API. It attempts to detect if the system is behind a captive portal by making HTTP requests to known captive portal detection Endpoints. If any of the requests return a response code or body that looks like a captive portal, Detect returns true. It returns false in all other cases, including when any error occurs during a detection attempt.
This function might take a while to return, as it will attempt to detect a captive portal on all available interfaces by performing multiple HTTP requests. It should be called in a separate goroutine if you want to avoid blocking.
type Endpoint ¶
type Endpoint struct { // URL is the URL that we make an HTTP request to as part of the captive portal detection process. URL *url.URL // StatusCode is the expected HTTP status code that we expect to see in the response. StatusCode int // ExpectedContent is a string that we expect to see contained in the response body. If this is non-empty, // we will check that the response body contains this string. If it is empty, we will not check the response body // and only check the status code. ExpectedContent string // SupportsTailscaleChallenge is true if the endpoint will return the sent value of the X-Tailscale-Challenge // HTTP header in its HTTP response. SupportsTailscaleChallenge bool // Provider is the source of the endpoint. This is used to prioritize certain endpoints over others // (for example, a DERP node in the preferred region should always be used first). Provider EndpointProvider }
Endpoint represents a URL that can be used to detect a captive portal, along with the expected result of the HTTP request.
type EndpointProvider ¶
type EndpointProvider int
EndpointProvider is an enum that represents the source of an Endpoint.
const ( // DERPMapPreferred is used for an endpoint that is a DERP node contained in the current preferred DERP region, // as provided by the DERPMap. DERPMapPreferred EndpointProvider = iota // DERPMapOther is used for an endpoint that is a DERP node, but not contained in the current preferred DERP region. DERPMapOther // Tailscale is used for endpoints that are the Tailscale coordination server or admin console. Tailscale )
func (EndpointProvider) String ¶
func (p EndpointProvider) String() string