Documentation ¶
Overview ¶
Package interfaces contains helpers for looking up system network interfaces.
Index ¶
- Variables
- func DefaultRouteInterface() (string, error)
- func ForeachInterface(fn func(Interface, []netip.Prefix)) error
- func ForeachInterfaceAddress(fn func(Interface, netip.Prefix)) error
- func HTTPOfListener(ln net.Listener) string
- func HasCGNATInterface() (bool, error)
- func LikelyHomeRouterIP() (gateway, myIP netip.Addr, ok bool)
- func LocalAddresses() (regular, loopback []netip.Addr, err error)
- func RegisterInterfaceGetter(getInterfaces func() ([]Interface, error))
- func Tailscale() ([]netip.Addr, *net.Interface, error)
- func UseAllIPs(ips netip.Addr) bool
- func UseAllInterfaces(i Interface, ips []netip.Prefix) bool
- func UseInterestingIPs(ip netip.Addr) bool
- func UseInterestingInterfaces(i Interface, ips []netip.Prefix) bool
- type DefaultRouteDetails
- type IPFilter
- type Interface
- type InterfaceFilter
- type List
- type State
Constants ¶
This section is empty.
Variables ¶
var LoginEndpointForProxyDetermination = "https://controlplane.tailscale.com/"
LoginEndpointForProxyDetermination is the URL used for testing which HTTP proxy the system should use.
Functions ¶
func DefaultRouteInterface ¶ added in v1.2.0
DefaultRouteInterface is like DefaultRoute but only returns the interface name.
func ForeachInterface ¶ added in v1.6.0
ForeachInterface is a wrapper for GetList, then List.ForeachInterface.
func ForeachInterfaceAddress ¶
ForeachInterfaceAddress is a wrapper for GetList, then List.ForeachInterfaceAddress.
func HTTPOfListener ¶ added in v0.98.0
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 HasCGNATInterface ¶ added in v1.28.0
HasCGNATInterface reports whether there are any non-Tailscale interfaces that use a CGNAT IP range.
func LikelyHomeRouterIP ¶ added in v1.0.0
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 ¶
LocalAddresses returns the machine's IP addresses, separated by whether they're loopback addresses. If there are no regular addresses it will return any IPv4 linklocal or IPv6 unique local addresses because we know of environments where these are used with NAT to provide connectivity.
func RegisterInterfaceGetter ¶ added in v1.16.0
RegisterInterfaceGetter sets the function that's used to query the system network interfaces.
func Tailscale ¶
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.
func UseAllInterfaces ¶ added in v1.20.0
UseAllInterfaces is an InterfaceFilter that includes all interfaces.
func UseInterestingIPs ¶ added in v1.20.0
UseInterestingIPs is an IPFilter that reports whether ip is an interesting IP address. An IP address is interesting if it is neither a loopback nor a link local unicast IP address.
func UseInterestingInterfaces ¶ added in v1.20.0
UseInterestingInterfaces is an InterfaceFilter that reports whether i is an interesting interface. An interesting interface if it is (a) not owned by Tailscale and (b) routes interesting IP addresses. See UseInterestingIPs for the definition of an interesting IP address.
Types ¶
type DefaultRouteDetails ¶ added in v1.20.0
type DefaultRouteDetails struct { // InterfaceName is the interface name. It must always be populated. // It's like "eth0" (Linux), "Ethernet 2" (Windows), "en0" (macOS). InterfaceName string // InterfaceDesc is populated on Windows at least. It's a // longer description, like "Red Hat VirtIO Ethernet Adapter". InterfaceDesc string // InterfaceIndex is like net.Interface.Index. // Zero means not populated. InterfaceIndex int }
DefaultRouteDetails are the details about a default route returned by DefaultRoute.
func DefaultRoute ¶ added in v1.20.0
func DefaultRoute() (DefaultRouteDetails, error)
DefaultRoute returns details of the network interface that owns the default route, not including any tailscale interfaces.
type IPFilter ¶ added in v1.20.0
An IPFilter indicates whether EqualFiltered should use ip when deciding whether two States are equal. ip is an ip address associated with some interface under consideration.
type Interface ¶
type Interface struct { *net.Interface AltAddrs []net.Addr // if non-nil, returned by Addrs Desc string // extra description (used on Windows) }
Interface is a wrapper around Go's net.Interface with some extra methods.
func (Interface) IsLoopback ¶
type InterfaceFilter ¶ added in v1.20.0
An InterfaceFilter indicates whether EqualFiltered should use i when deciding whether two States are equal. ips are all the IPPrefixes associated with i.
type List ¶ added in v1.16.1
type List []Interface
List is a list of interfaces on the machine.
func (List) ForeachInterface ¶ added in v1.16.1
ForeachInterface calls fn for each interface in ifaces, with all its addresses. The IPPrefix's IP is the IP address assigned to the interface, and Bits are the subnet mask.
func (List) ForeachInterfaceAddress ¶ added in v1.16.1
ForeachInterfaceAddress calls fn for each interface in ifaces, with all its addresses. The IPPrefix's IP is the IP address assigned to the interface, and Bits are the subnet mask.
type State ¶
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.Prefix Interface 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. HaveV6 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. // // When non-empty, its value is the map key into Interface and // InterfaceIPs. DefaultRouteInterface string // HTTPProxy is the HTTP proxy to use, if any. 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 ¶
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
AnyInterfaceUp reports whether any interface seems like it has Internet access.
func (*State) EqualFiltered ¶ added in v1.8.0
func (s *State) EqualFiltered(s2 *State, useInterface InterfaceFilter, useIP IPFilter) bool
EqualFiltered reports whether s and s2 are equal, considering only interfaces in s for which filter returns true, and considering only IPs for those interfaces for which filterIP returns true.