Documentation
¶
Overview ¶
Package tailnet detects a running Tailscale on this machine, without depending on it: no Tailscale code is linked in, and nothing here needs Tailscale to be installed.
RemoHop uses what it finds in two places:
- When both ends of a session are on the same tailnet, the peer's tailnet address is a direct path that works through any NAT (Tailscale carries it, directly or through its own relays). internal/dial prefers it over a hole-punched path and tries it before the rendezvous server's relay. It is only an additional candidate address: the RemoHop session over it is the same end-to-end encrypted, authenticated QUIC session as over any other path, and nothing Tailscale says is taken as proof of who the peer is.
- `remohop doctor` explains the network situation, Tailscale included.
Sources, in order: $REMOHOP_TAILSCALE_STATUS (a file in the format of `tailscale status --json`, for tests and odd installations), the tailscaled local API socket, the `tailscale` command, and finally the network interfaces alone (an interface named like Tailscale's with an address in 100.64.0.0/10 or fd7a:115c:a1e0::/48). REMOHOP_TAILSCALE=off turns all of it off.
Index ¶
- Constants
- Variables
- func Disabled() bool
- func InRange(a netip.Addr) bool
- func IsInterface(name string, addrs []netip.Addr) bool
- func LocalAddrs() []netip.Addr
- func Predicate(st *Status) func(netip.AddrPort) bool
- func Prefer(ctx context.Context, remote []netip.AddrPort) func(netip.AddrPort) bool
- func ResetCache()
- func Warm()
- type Node
- type Status
Constants ¶
const ( SourceDisabled = "disabled" // REMOHOP_TAILSCALE=off SourceEnv = "env" // $REMOHOP_TAILSCALE_STATUS SourceLocalAPI = "localapi" // tailscaled's local API socket SourceCLI = "cli" // `tailscale status --json` SourceInterface = "interface" // only an interface was found SourceNone = "" // nothing found )
Sources of a Status.
Variables ¶
var ( CGNAT = netip.MustParsePrefix("100.64.0.0/10") ULA = netip.MustParsePrefix("fd7a:115c:a1e0::/48") )
The address ranges Tailscale assigns from: carrier-grade NAT space for IPv4 and its own unique-local prefix for IPv6.
Functions ¶
func InRange ¶
InRange reports whether a is in one of the ranges Tailscale assigns. An address in range is not necessarily a tailnet address: carriers use 100.64.0.0/10 too.
func IsInterface ¶
IsInterface reports whether an interface looks like Tailscale's: named tailscale0 (Linux, BSD) or "Tailscale" (Windows), or a macOS utun, and holding an address in Tailscale's ranges. The name alone is not enough (any VPN may create a utun), nor is the address (a carrier may hand out 100.64.0.0/10 addresses).
func LocalAddrs ¶
LocalAddrs returns this machine's tailnet addresses as seen on its interfaces, without asking Tailscale. Cheap enough for every dial.
func Prefer ¶
Prefer returns a predicate for the candidates of a peer that are worth preferring because they are on this machine's tailnet, or nil when there are none: the peer offers no address in Tailscale's ranges, or this machine is not on a tailnet. When Tailscale itself could be asked, only addresses of machines it lists as peers qualify; with nothing but an interface to go on, any address in its ranges does.
func ResetCache ¶
func ResetCache()
ResetCache forgets the cached detection (tests, `remohop doctor`).
func Warm ¶
func Warm()
Warm starts a detection in the background when this machine has a tailnet interface, so that the Prefer of a dial in progress finds the answer cached (or being fetched) instead of starting `tailscale status` (up to 2 s on Windows and the macOS App Store build) between the introduction and the first probe, while the host's priming hold runs.
Types ¶
type Node ¶
type Node struct {
Name string `json:"name"`
DNSName string `json:"dns_name,omitempty"`
OS string `json:"os,omitempty"`
IPs []netip.Addr `json:"ips"`
Online bool `json:"online"`
// ExitNode: this node is the exit node in use; ExitNodeOption: it
// offers to be one.
ExitNode bool `json:"exit_node,omitempty"`
ExitNodeOption bool `json:"exit_node_option,omitempty"`
// CurAddr is the address Tailscale talks to it at directly, Relay the
// Tailscale relay (DERP region) it goes through otherwise.
CurAddr string `json:"cur_addr,omitempty"`
Relay string `json:"relay,omitempty"`
}
Node is a machine on the tailnet.
type Status ¶
type Status struct {
// Running: Tailscale is up and this machine is on a tailnet.
Running bool `json:"running"`
Source string `json:"source"`
// BackendState is Tailscale's own word ("Running", "Stopped",
// "NeedsLogin", ...), empty when only an interface was found.
BackendState string `json:"backend_state,omitempty"`
Version string `json:"version,omitempty"`
Tailnet string `json:"tailnet,omitempty"`
MagicDNSSuffix string `json:"magic_dns_suffix,omitempty"`
MagicDNS bool `json:"magic_dns,omitempty"`
Self Node `json:"self"`
Peers []Node `json:"peers,omitempty"`
// ExitNode names the exit node this machine sends its traffic
// through, if any.
ExitNode string `json:"exit_node,omitempty"`
// Interface is the name of the tailnet interface, if one was found.
Interface string `json:"interface,omitempty"`
// Note explains a source that failed, for `remohop doctor`.
Note string `json:"note,omitempty"`
}
Status is what was found about Tailscale on this machine.
func Detect ¶
Detect finds out whether Tailscale runs here. It never fails: what could not be found is reported in the Status. ctx bounds the local API and CLI queries.
func Parse ¶
Parse reads the output of `tailscale status --json` (or the local API's status). Fields RemoHop does not use are ignored.
func (*Status) HasPeers ¶
HasPeers reports whether the status lists the tailnet's other machines (it came from Tailscale itself, not only from an interface).