tailnet

package
v0.12.1 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2026 License: MIT Imports: 12 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 reads this machine's Tailscale state and manages Tailscale Serve entries through the tailscale CLI, which works the same with every Tailscale variant (macOS app, Homebrew, Linux packages).

Index

Constants

View Source
const (
	Missing   = "missing"   // the tailscale command was not found
	Stopped   = "stopped"   // installed, but not connected or its service is not running
	SignedOut = "signedOut" // waiting for a sign-in or the device's approval
)

Why Tailscale is unavailable, so the dashboard can say what to do.

Variables

View Source
var ErrUnavailable = errors.New("Tailscale is not available") //nolint:staticcheck // ST1005: starts with a product name

ErrUnavailable means the tailscale CLI is missing or Tailscale is not connected.

Functions

func Problem added in v0.2.0

func Problem(err error) string

Problem is the reason for an ErrUnavailable (Missing, Stopped or SignedOut), or "" for any other error.

func Serve

func Serve(ctx context.Context, port int, target string) error

Serve makes Tailscale Serve proxy HTTPS on port of the tailnet to target, with this machine's certificate for its tailnet name, so clients can tell it apart from anything else answering on that address. --yes skips confirmation prompts; a CLI without that flag runs without it.

func Unserve

func Unserve(ctx context.Context, port int, https bool) error

Unserve removes the entry for port.

Types

type Cache

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

Cache keeps the last status for a short while: identity checks run on every peer connection and must not spawn the CLI each time.

func NewCache

func NewCache(ttl time.Duration) *Cache

NewCache returns a cache whose entries live for ttl.

func Preloaded

func Preloaded(st *Status) *Cache

Preloaded returns a cache that always answers st, for callers (and tests) that already hold a status.

func (*Cache) Fresh

func (c *Cache) Fresh(ctx context.Context) (*Status, error)

Fresh returns a status read now, unless one was read in the last second.

func (*Cache) Get

func (c *Cache) Get(ctx context.Context) (*Status, error)

Get returns a status no older than the cache's ttl.

func (*Cache) SelfAddrs added in v0.4.2

func (c *Cache) SelfAddrs() []netip.Addr

SelfAddrs returns this machine's Tailscale addresses from the cached status (read again at most once per ttl), or none when Tailscale is unavailable or does not answer within a few seconds.

type Node

type Node struct {
	// Name is the device's host name, e.g. "devbox".
	Name string `json:"name"`
	// DNSName is the MagicDNS name without the trailing dot.
	DNSName string `json:"dnsName"`
	// Label is the first DNS label: a host name safe for URLs.
	Label  string   `json:"label"`
	OS     string   `json:"os"`
	IPs    []string `json:"-"`
	Online bool     `json:"-"`
	Tagged bool     `json:"-"`
	UserID int64    `json:"-"`
}

Node is one device of the tailnet.

type ServeEntry

type ServeEntry struct {
	Served bool
	// Target is the backend URL when the whole port goes to one backend;
	// empty for anything else (TCP forwarding, several paths).
	Target string
	HTTPS  bool
}

ServeEntry is how Tailscale Serve uses one port of this machine.

func ServeTarget

func ServeTarget(ctx context.Context, dnsName string, port int) (ServeEntry, error)

ServeTarget reads how Tailscale Serve uses port on this machine.

type Status

type Status struct {
	Self Node
	// Owner is the login name of the user that owns this machine's node.
	Owner string
	Peers []Node
}

Status is a snapshot of this machine's view of the tailnet.

func Fetch

func Fetch(ctx context.Context) (*Status, error)

Fetch reads the current status.

func (*Status) ByIP

func (st *Status) ByIP(ip string) (Node, bool)

ByIP returns the node, this machine included, that has address ip.

func (*Status) Owned

func (st *Status) Owned(n Node) bool

Owned reports whether n belongs to the same user as this machine and is not a tagged device. Only such devices may connect in either direction.

Jump to

Keyboard shortcuts

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