tailnet

package
v1.0.10 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2026 License: AGPL-3.0 Imports: 16 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
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

View Source
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 Disabled

func Disabled() bool

Disabled reports whether REMOHOP_TAILSCALE=off.

func InRange

func InRange(a netip.Addr) bool

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

func IsInterface(name string, addrs []netip.Addr) bool

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

func LocalAddrs() []netip.Addr

LocalAddrs returns this machine's tailnet addresses as seen on its interfaces, without asking Tailscale. Cheap enough for every dial.

func Predicate

func Predicate(st *Status) func(netip.AddrPort) bool

Predicate is Prefer's decision for a given status.

func Prefer

func Prefer(ctx context.Context, remote []netip.AddrPort) func(netip.AddrPort) bool

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

func Detect(ctx context.Context) *Status

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

func Parse(b []byte) (*Status, error)

Parse reads the output of `tailscale status --json` (or the local API's status). Fields RemoHop does not use are ignored.

func (*Status) HasPeers

func (s *Status) HasPeers() bool

HasPeers reports whether the status lists the tailnet's other machines (it came from Tailscale itself, not only from an interface).

func (*Status) IsSelf

func (s *Status) IsSelf(a netip.Addr) bool

IsSelf reports whether a is one of this machine's tailnet addresses.

func (*Status) Peer

func (s *Status) Peer(a netip.Addr) (*Node, bool)

Peer returns the tailnet peer that holds a, if the status lists it.

Jump to

Keyboard shortcuts

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