Movatterモバイル変換


[0]ホーム

URL:


netcheck

package
v1.92.2Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 10, 2025 License:BSD-3-ClauseImports:41Imported by:20

Details

Repository

github.com/tailscale/tailscale

Links

Documentation

Overview

Package netcheck checks the network conditions from the current host.

Index

Constants

View Source
const (// PreferredDERPFrameTime is the time which, if a DERP frame has been// received within that period, we treat that region as being present// even without receiving a STUN response.// Note: must remain higher than the derp package frameReceiveRecordRatePreferredDERPFrameTime = 8 *time.Second// PreferredDERPKeepAliveTimeout is 2x the DERP Keep Alive timeout. If there// is no latency data to make judgements from, but we have heard from our// current DERP region inside of 2x the KeepAlive window, don't switch DERP// regions yet, keep the current region. This prevents region flapping /// home DERP removal during short periods of packet loss where the DERP TCP// connection may itself naturally recover.// TODO(raggi): expose shared time bounds from the DERP package rather than// duplicating them here.PreferredDERPKeepAliveTimeout = 2 *derp.KeepAlive)
View Source
const (// ReportTimeout is the maximum amount of time netcheck will// spend gathering a single report.ReportTimeout = 5 *time.Second)

The various default timeouts for things.

Variables

This section is empty.

Functions

This section is empty.

Types

typeClient

type Client struct {// NetMon is the netmon.Monitor to use to get the current// (cached) network interface.// It must be non-nil.NetMon *netmon.Monitor// Verbose enables verbose logging.Verbosebool// Logf optionally specifies where to log to.// If nil, log.Printf is used.Logflogger.Logf// TimeNow, if non-nil, is used instead of time.Now.TimeNow func()time.Time// SendPacket is required to send a packet to the specified address. For// convenience it shares a signature with WriteToUDPAddrPort.SendPacket func([]byte,netip.AddrPort) (int,error)// SkipExternalNetwork controls whether the client should not try// to reach things other than localhost. This is set to true// in tests to avoid probing the local LAN's router, etc.SkipExternalNetworkbool// PortMapper, if non-nil, is used for portmap queries.// If nil, portmap discovery is not done.PortMapperportmappertype.Client// UseDNSCache controls whether this client should use a// *dnscache.Resolver to resolve DERP hostnames, when no IP address is// provided in the DERP map. Note that Tailscale-provided DERP servers// all specify explicit IPv4 and IPv6 addresses, so this is mostly// helpful for users with custom DERP servers.//// If false, the default net.Resolver will be used, with no caching.UseDNSCachebool// if non-zero, force this DERP region to be preferred in all reports where// the DERP is found to be reachable.ForcePreferredDERPint// contains filtered or unexported fields}

Client generates Reports describing the result of both passive and activenetwork configuration probing. It provides two different modes of report, afull report (see MakeNextReportFull) and a more lightweight incrementalreport. The client must be provided with SendPacket in order to performactive probes, and must receive STUN packet replies via ReceiveSTUNPacket.Client can be used in a standalone fashion via the Standalone method.

func (*Client)GetReport

func (c *Client) GetReport(ctxcontext.Context, dm *tailcfg.DERPMap, opts *GetReportOpts) (_ *Report, reterrerror)

GetReport gets a report. The 'opts' argument is optional and can be nil.Callers are discouraged from passing a ctx with an arbitrary deadline as thismay cause GetReport to return prematurely before all reporting methods haveexecuted. ReportTimeout is the maximum amount of time GetReport will spendgathering a report.

It may not be called concurrently with itself.

func (*Client)MakeNextReportFull

func (c *Client) MakeNextReportFull()

MakeNextReportFull forces the next GetReport call to be a full(non-incremental) probe of all DERP regions.

func (*Client)ReceiveSTUNPacket

func (c *Client) ReceiveSTUNPacket(pkt []byte, srcnetip.AddrPort)

ReceiveSTUNPacket must be called when a STUN packet is received as a reply topacket the client sent using SendPacket. In Standalone this is performed bythe loop started by Standalone, in normal operation in tailscaled incomingSTUN replies are routed to this method.

func (*Client)SetForcePreferredDERPadded inv1.78.0

func (c *Client) SetForcePreferredDERP(regionint)

func (*Client)Standaloneadded inv1.48.0

func (c *Client) Standalone(ctxcontext.Context, bindAddrstring)error

Standalone creates the necessary UDP sockets on the given bindAddr and startsan IO loop so that the Client can perform active probes with no further needfor external driving of IO (no need to set/implement SendPacket, or callReceiveSTUNPacket). It must be called prior to starting any reports and isshut down by cancellation of the provided context. If both IPv4 and IPv6 failto bind, errors will be returned, if one or both protocols can bind no erroris returned.

typeGetReportOptsadded inv1.58.0

type GetReportOpts struct {// GetLastDERPActivity is a callback that, if provided, should return// the absolute time that the calling code last communicated with a// given DERP region. This is used to assist in avoiding PreferredDERP// ("home DERP") flaps.//// If no communication with that region has occurred, or it occurred// too far in the past, this function should return the zero time.GetLastDERPActivity func(int)time.Time// OnlyTCP443 constrains netcheck reporting to measurements over TCP port// 443.OnlyTCP443bool// OnlySTUN constrains netcheck reporting to STUN measurements over UDP.OnlySTUNbool}

GetReportOpts contains options that can be passed to GetReport. Unlessspecified, all fields are optional and can be left as their zero value.At most one of OnlyTCP443 or OnlySTUN may be set.

typeReport

type Report struct {Nowtime.Time// the time the report was runUDPbool// a UDP STUN round trip completedIPv6bool// an IPv6 STUN round trip completedIPv4bool// an IPv4 STUN round trip completedIPv6CanSendbool// an IPv6 packet was able to be sentIPv4CanSendbool// an IPv4 packet was able to be sentOSHasIPv6bool// could bind a socket to ::1ICMPv4bool// an ICMPv4 round trip completed// MappingVariesByDestIP is whether STUN results depend which// STUN server you're talking to (on IPv4).MappingVariesByDestIPopt.Bool// UPnP is whether UPnP appears present on the LAN.// Empty means not checked.UPnPopt.Bool// PMP is whether NAT-PMP appears present on the LAN.// Empty means not checked.PMPopt.Bool// PCP is whether PCP appears present on the LAN.// Empty means not checked.PCPopt.BoolPreferredDERPint// or 0 for unknownRegionLatency   map[int]time.Duration// keyed by DERP Region IDRegionV4Latency map[int]time.Duration// keyed by DERP Region IDRegionV6Latency map[int]time.Duration// keyed by DERP Region IDGlobalV4Counters map[netip.AddrPort]int// number of times the endpoint was observedGlobalV6Counters map[netip.AddrPort]int// number of times the endpoint was observedGlobalV4netip.AddrPortGlobalV6netip.AddrPort// CaptivePortal is set when we think there's a captive portal that is// intercepting HTTP traffic.CaptivePortalopt.Bool}

Report contains the result of a single netcheck.

func (*Report)AnyPortMappingCheckedadded inv1.0.0

func (r *Report) AnyPortMappingChecked()bool

AnyPortMappingChecked reports whether any of UPnP, PMP, or PCP are non-empty.

func (*Report)Clone

func (r *Report) Clone() *Report

func (*Report)GetGlobalAddrsadded inv1.68.0

func (r *Report) GetGlobalAddrs() (v4, v6 []netip.AddrPort)

GetGlobalAddrs returns the v4 and v6 global addresses observed during thenetcheck, which includes the best latency endpoint first, followed by anyother endpoints that were observed repeatedly. It excludes singular endpointsthat are likely only the result of a hard NAT.

Source Files

View all Source files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f orF : Jump to
y orY : Canonical URL
go.dev uses cookies from Google to deliver and enhance the quality of its services and to analyze traffic.Learn more.

[8]ページ先頭

©2009-2025 Movatter.jp