interfaces

package
v1.2.2 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2020 License: BSD-3-Clause Imports: 20 Imported by: 0

Documentation

Overview

Package interfaces contains helpers for looking up system network interfaces.

Index

Constants

This section is empty.

Variables

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

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

Functions

func DefaultRouteInterface added in v1.2.0

func DefaultRouteInterface() (string, error)

DefaultRouteInterface returns the name of the network interface that owns the default route, not including any tailscale interfaces.

func ForeachInterfaceAddress

func ForeachInterfaceAddress(fn func(Interface, netaddr.IP)) error

ForeachInterfaceAddress calls fn for each interface's address on the machine.

func HTTPOfListener added in v0.98.0

func HTTPOfListener(ln net.Listener) string

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

func IsTailscaleIP

func IsTailscaleIP(ip net.IP) bool

IsTailscaleIP reports whether ip is an IP in a range used by Tailscale virtual network interfaces.

func LikelyHomeRouterIP added in v1.0.0

func LikelyHomeRouterIP() (gateway, myIP netaddr.IP, ok bool)

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 on the LAN using that gateway. This is used as the destination for UPnP, NAT-PMP, PCP, etc queries.

func LocalAddresses

func LocalAddresses() (regular, loopback []string, err error)

LocalAddresses returns the machine's IP addresses, separated by whether they're loopback addresses.

func Tailscale

func Tailscale() (net.IP, *net.Interface, error)

Tailscale returns the current machine's Tailscale interface, if any. If none is found, all zero values are returned. A non-nil error is only returned on a problem listing the system interfaces.

Types

type Interface

type Interface struct {
	*net.Interface
}

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

func (Interface) IsLoopback

func (i Interface) IsLoopback() bool

func (Interface) IsUp

func (i Interface) IsUp() bool

type State

type State struct {
	InterfaceIPs map[string][]netaddr.IP
	InterfaceUp  map[string]bool

	// HaveV6Global is whether this machine has an IPv6 global address
	// on some non-Tailscale interface that's up.
	HaveV6Global bool

	// HaveV4 is whether the machine has some non-localhost,
	// non-link-local IPv4 address on a non-Tailscale interface that's up.
	HaveV4 bool

	// 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.
	IsExpensive bool

	// DefaultRouteInterface is the interface name for the machine's default route.
	// It is not yet populated on all OSes.
	// Its exact value should not be assumed to be a map key for
	// the Interface maps above; it's only used for debugging.
	DefaultRouteInterface string

	// HTTPProxy is the HTTP proxy to use.
	HTTPProxy string

	// PAC is the URL to the Proxy Autoconfig URL, if applicable.
	PAC string
}

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 GetState

func GetState() (*State, error)

GetState returns the state of all the current machine's network interfaces.

It does not set the returned State.IsExpensive. The caller can populate that.

func (*State) AnyInterfaceUp added in v1.2.0

func (s *State) AnyInterfaceUp() bool

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

func (*State) Equal

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

func (*State) HasPAC added in v1.2.0

func (s *State) HasPAC() bool

func (*State) RemoveTailscaleInterfaces

func (s *State) RemoveTailscaleInterfaces()

RemoveTailscaleInterfaces modifes s to remove any interfaces that are owned by this process. (TODO: make this true; currently it makes the Linux-only assumption that the interface is named /^tailscale/)

func (*State) String added in v1.2.0

func (s *State) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL