Movatterモバイル変換


[0]ホーム

URL:


netmon

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:36Imported by:67

Details

Repository

github.com/tailscale/tailscale

Links

Documentation

Overview

Package monitor provides facilities for monitoring networkinterface and route changes. It primarily exists to know whenportable devices move between different networks.

Index

Constants

This section is empty.

Variables

View Source
var LoginEndpointForProxyDetermination = "https://controlplane.tailscale.com/"

LoginEndpointForProxyDetermination is the URL used for testingwhich HTTP proxy the system should use.

Functions

funcDefaultRouteInterfaceadded inv1.66.0

func DefaultRouteInterface() (string,error)

DefaultRouteInterface is like DefaultRoute but only returns theinterface name.

funcForeachInterfaceadded inv1.66.0

func ForeachInterface(fn func(Interface, []netip.Prefix))error

ForeachInterface is a wrapper for GetList, thenList.ForeachInterface.

funcForeachInterfaceAddressadded inv1.66.0

func ForeachInterfaceAddress(fn func(Interface,netip.Prefix))error

ForeachInterfaceAddress is a wrapper for GetList, thenList.ForeachInterfaceAddress.

funcHTTPOfListeneradded inv1.66.0

func HTTPOfListener(lnnet.Listener)string

HTTPOfListener returns the HTTP address to ln.If the listener is listening on the unspecified address, itit tries to find a reasonable interface address on the machine to use.

funcInterfaceDebugExtrasadded inv1.66.0

func InterfaceDebugExtras(ifIndexint) (string,error)

InterfaceDebugExtras returns extra debugging information about an interfaceif any (an empty string will be returned if there are no additional details).Formatting is platform-dependent and should not be parsed.

funcLikelyHomeRouterIPadded inv1.66.0

func LikelyHomeRouterIP() (gateway, myIPnetip.Addr, okbool)

LikelyHomeRouterIP returns the likely IP of the residential router,which will always be an IPv4 private address, if found.In addition, it returns the IP address of the current machine onthe LAN using that gateway.This is used as the destination for UPnP, NAT-PMP, PCP, etc queries.

funcLinkChangeLogLimiteradded inv1.82.0

func LinkChangeLogLimiter(ctxcontext.Context, logflogger.Logf, nm *Monitor)logger.Logf

LinkChangeLogLimiter returns a newlogger.Logf that logs each uniqueformat string to the underlying logger only once per major LinkChange event.

The logger stops tracking seen format strings when the provided context isdone.

funcLocalAddressesadded inv1.66.0

func LocalAddresses() (regular, loopback []netip.Addr, errerror)

LocalAddresses returns the machine's IP addresses, separated bywhether they're loopback addresses. If there are no regular addressesit will return any IPv4 linklocal or IPv6 unique local addresses because weknow of environments where these are used with NAT to provide connectivity.

funcRegisterInterfaceGetteradded inv1.66.0

func RegisterInterfaceGetter(getInterfaces func() ([]Interface,error))

RegisterInterfaceGetter sets the function that's used to querythe system network interfaces.

Types

typeChangeDeltaadded inv1.50.0

type ChangeDelta struct {// Old is the old interface state, if known.// It's nil if the old state is unknown.// Do not mutate it.Old *State// New is the new network state.// It is always non-nil.// Do not mutate it.New *State// Major is our legacy boolean of whether the network changed in some major// way.//// Deprecated: do not remove. As of 2023-08-23 we're in a renewed effort to// remove it and ask specific qustions of ChangeDelta instead. Look at Old// and New (or add methods to ChangeDelta) instead of using Major.Majorbool// TimeJumped is whether there was a big jump in wall time since the last// time we checked. This is a hint that a mobile sleeping device might have// come out of sleep.TimeJumpedbool}

ChangeDelta describes the difference between two network states.

typeChangeFunc

type ChangeFunc func(*ChangeDelta)

ChangeFunc is a callback function registered with Monitor that's called when thenetwork changed.

typeDefaultRouteDetailsadded inv1.66.0

type DefaultRouteDetails struct {// InterfaceName is the interface name. It must always be populated.// It's like "eth0" (Linux), "Ethernet 2" (Windows), "en0" (macOS).InterfaceNamestring// InterfaceDesc is populated on Windows at least. It's a// longer description, like "Red Hat VirtIO Ethernet Adapter".InterfaceDescstring// InterfaceIndex is like net.Interface.Index.// Zero means not populated.InterfaceIndexint}

DefaultRouteDetails are the details about a default route returnedby DefaultRoute.

funcDefaultRouteadded inv1.66.0

func DefaultRoute() (DefaultRouteDetails,error)

DefaultRoute returns details of the network interface that ownsthe default route, not including any tailscale interfaces.

typeInterfaceadded inv1.66.0

type Interface struct {*net.InterfaceAltAddrs []net.Addr// if non-nil, returned by AddrsDescstring// extra description (used on Windows)}

Interface is a wrapper around Go's net.Interface with some extra methods.

func (Interface)Addrsadded inv1.66.0

func (iInterface) Addrs() ([]net.Addr,error)

func (Interface)Equaladded inv1.66.0

func (aInterface) Equal(bInterface)bool

func (Interface)IsLoopbackadded inv1.66.0

func (iInterface) IsLoopback()bool

func (Interface)IsUpadded inv1.66.0

func (iInterface) IsUp()bool

typeInterfaceListadded inv1.66.0

type InterfaceList []Interface

InterfaceList is a list of interfaces on the machine.

funcGetInterfaceListadded inv1.66.0

func GetInterfaceList() (InterfaceList,error)

GetInterfaceList returns the list of interfaces on the machine.

func (InterfaceList)ForeachInterfaceadded inv1.66.0

func (ifacesInterfaceList) ForeachInterface(fn func(Interface, []netip.Prefix))error

ForeachInterface calls fn for each interface in ifaces, withall its addresses. The IPPrefix's IP is the IP address assigned tothe interface, and Bits are the subnet mask.

func (InterfaceList)ForeachInterfaceAddressadded inv1.66.0

func (ifacesInterfaceList) ForeachInterfaceAddress(fn func(Interface,netip.Prefix))error

ForeachInterfaceAddress calls fn for each interface in ifaces, withall its addresses. The IPPrefix's IP is the IP address assigned tothe interface, and Bits are the subnet mask.

typeMonitor

type Monitor struct {// contains filtered or unexported fields}

Monitor represents a monitoring instance.

funcNew

func New(bus *eventbus.Bus, logflogger.Logf) (*Monitor,error)

New instantiates and starts a monitoring instance.The returned monitor is inactive until it's started by the Start method.Use RegisterChangeCallback to get notified of network changes.

funcNewStaticadded inv1.66.0

func NewStatic() *Monitor

NewStatic returns a Monitor that's a one-time snapshot of the network statebut doesn't actually monitor for changes. It should only be used in testsand situations like cleanups or short-lived CLI programs.

func (*Monitor)Close

func (m *Monitor) Close()error

Close closes the monitor.

func (*Monitor)GatewayAndSelfIP

func (m *Monitor) GatewayAndSelfIP() (gw, myIPnetip.Addr, okbool)

GatewayAndSelfIP returns the current network's default gateway, andthe machine's default IP for that gateway.

It's the same as interfaces.LikelyHomeRouterIP, but it caches theresult until the monitor detects a network change.

func (*Monitor)HasCGNATInterfaceadded inv1.82.0

func (m *Monitor) HasCGNATInterface() (bool,error)

HasCGNATInterface reports whether there are any non-Tailscale interfaces thatuse a CGNAT IP range.

func (*Monitor)InjectEvent

func (m *Monitor) InjectEvent()

InjectEvent forces the monitor to pretend there was a networkchange and re-check the state of the network. Any registeredChangeFunc callbacks will be called within the event coalescingperiod (under a fraction of a second).

func (*Monitor)InterfaceState

func (m *Monitor) InterfaceState() *State

InterfaceState returns the latest snapshot of the machine's networkinterfaces.

The returned value is owned by Mon; it must not be modified.

func (*Monitor)IsMajorChangeFromadded inv1.50.0

func (m *Monitor) IsMajorChangeFrom(s1, s2 *State)bool

IsMajorChangeFrom reports whether the transition from s1 to s2 isa "major" change, where major roughly means it's worth tearing downa bunch of connections and rebinding.

TODO(bradiftz): tigten this definition.

func (*Monitor)Polladded inv1.50.0

func (m *Monitor) Poll()

Poll forces the monitor to pretend there was a networkchange and re-check the state of the network.

This is like InjectEvent but only fires ChangeFunc callbacksif the network state differed at all.

func (*Monitor)RegisterChangeCallback

func (m *Monitor) RegisterChangeCallback(callbackChangeFunc) (unregister func())

RegisterChangeCallback adds callback to the set of parties to benotified (in their own goroutine) when the network state changes.To remove this callback, call unregister (or close the monitor).

func (*Monitor)SetTailscaleInterfaceNameadded inv1.50.0

func (m *Monitor) SetTailscaleInterfaceName(ifNamestring)

SetTailscaleInterfaceName sets the name of the Tailscale interface. Forexample, "tailscale0", "tun0", "utun3", etc.

This must be called only early in tailscaled startup before the monitor isused.

func (*Monitor)Start

func (m *Monitor) Start()

Start starts the monitor.A monitor can only be started & closed once.

typeRuleDeletedadded inv1.84.0

type RuleDeleted struct {// Table is the table number that the deleted rule referenced.Tableuint8// Priority is the lookup priority of the deleted rule.Priorityuint32}

RuleDeleted reports that one of Tailscale's policy routing ruleswas deleted.

typeStateadded inv1.66.0

type State struct {// InterfaceIPs maps from an interface name to the IP addresses// configured on that interface. Each address is represented as an// IPPrefix, where the IP is the interface IP address and Bits is// the subnet mask.InterfaceIPs map[string][]netip.PrefixInterface    map[string]Interface// HaveV6 is whether this machine has an IPv6 Global or Unique Local Address// which might provide connectivity on a non-Tailscale interface that's up.HaveV6bool// HaveV4 is whether the machine has some non-localhost,// non-link-local IPv4 address on a non-Tailscale interface that's up.HaveV4bool// IsExpensive is whether the current network interface is// considered "expensive", which currently means LTE/etc// instead of Wifi. This field is not populated by GetState.IsExpensivebool// DefaultRouteInterface is the interface name for the// machine's default route.//// It is not yet populated on all OSes.//// When non-empty, its value is the map key into Interface and// InterfaceIPs.DefaultRouteInterfacestring// HTTPProxy is the HTTP proxy to use, if any.HTTPProxystring// PAC is the URL to the Proxy Autoconfig URL, if applicable.PACstring}

State is intended to store the state of the machine's network interfaces,routing table, and other network configuration.For now it's pretty basic.

func (*State)AnyInterfaceUpadded inv1.66.0

func (s *State) AnyInterfaceUp()bool

AnyInterfaceUp reports whether any interface seems like it has Internet access.

func (*State)Equaladded inv1.66.0

func (s *State) Equal(s2 *State)bool

Equal reports whether s and s2 are exactly equal.

func (*State)HasIPadded inv1.66.0

func (s *State) HasIP(ipnetip.Addr)bool

HasIP reports whether any interface has the provided IP address.

func (*State)HasPACadded inv1.66.0

func (s *State) HasPAC()bool

func (*State)Stringadded inv1.66.0

func (s *State) String()string

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