Documentation
¶
Index ¶
Constants ¶
const ( SettingNet = "net" SettingExit = "net-exit" SettingRoutes = "net-routes" SettingUseExit = "net-use-exit" SettingAcceptRoutes = "net-accept-routes" SettingDNS = "net-dns" )
Config keys.
const ( DNSAuto = "auto" // per-interface split DNS for .remohop where the system has it (systemd-resolved) DNSHosts = "hosts" // a marked block in the hosts file DNSOff = "off" // only the responder on the mesh address )
DNS modes (net-dns).
const Domain = "remohop"
Domain is the DNS suffix of mesh names: laptop.remohop.
const PolicyFile = "net-policy.json"
PolicyFile holds the adopted signed policy in the config directory.
const Service = "net"
Service is the host service the mesh runs on.
const StatusFile = "net-status.json"
StatusFile is where the host's mesh reports its state, for `remohop net status` and `remohop net peers`.
Variables ¶
var DefaultPrefix4 = netip.MustParsePrefix("10.78.0.0/16")
DefaultPrefix4 is the IPv4 network mesh addresses come from unless the account's policy names another. It is next to the point-to-point VPN's 10.77.0.0/16 and well away from Tailscale's 100.64.0.0/10, so both can run on the same machine.
Functions ¶
func Label ¶
Label turns a device name into a DNS label: lower case letters, digits and dashes, at most 63 characters, never empty.
func ParsePrefix4 ¶
ParsePrefix4 validates an IPv4 mesh network: private (RFC 1918), between /8 and /24. Carrier-grade NAT space is refused: Tailscale lives there.
Types ¶
type Assignment ¶
type Assignment struct {
Key ed25519.PublicKey
Label string // DNS label, unique in the mesh
Addr4 netip.Addr
Addr6 netip.Addr
// Gen is the step of the key's candidate sequence the addresses came
// from: 0 unless an earlier member already held the first choice.
Gen int
}
Assignment is what a member gets: its addresses and its name.
func Assign ¶
func Assign(prefix4, prefix6 netip.Prefix, members []Member) []Assignment
Assign gives every member its addresses and name. members must be in the order the account's log added them, every device that was ever added included (removed ones too): a later member never takes an address an earlier one holds, and nobody's address changes when someone joins or leaves. Every device computes the same assignment from the same log.
func (Assignment) FQDN ¶
func (a Assignment) FQDN() string
FQDN is the member's full mesh name, without the trailing dot.
type Member ¶
type Member struct {
Key ed25519.PublicKey
// Name is the name the device had when it joined (from the signed
// account log), turned into a DNS label by Assign.
Name string
}
Member is a device in the mesh, as allocation sees it.
type Node ¶
type Node struct {
// contains filtered or unexported fields
}
Node is this device's part of the mesh: its tunnel interface, its links to the other devices and its DNS responder. It runs inside the host process (see service.go).
type PeerStatus ¶
type PeerStatus struct {
Name string `json:"name"`
FQDN string `json:"fqdn"`
Identity string `json:"identity"`
ID string `json:"id,omitempty"`
Addr4 string `json:"addr4"`
Addr6 string `json:"addr6,omitempty"`
Online bool `json:"online"`
// Link is "up", "connecting" or empty (none: links come up when
// traffic needs them).
Link string `json:"link,omitempty"`
Path string `json:"path,omitempty"`
Remote string `json:"remote,omitempty"`
Since time.Time `json:"since,omitzero"`
OpenedHere bool `json:"opened_here,omitempty"`
Tx int64 `json:"tx_packets,omitempty"`
Rx int64 `json:"rx_packets,omitempty"`
Dropped int64 `json:"dropped,omitempty"`
Exit bool `json:"exit_node,omitempty"`
Routes []string `json:"routes,omitempty"`
LastError string `json:"last_error,omitempty"`
}
PeerStatus is another device of the mesh.
type Policy ¶
type Policy struct {
Version int64 `json:"version"`
// Prefix4 overrides DefaultPrefix4 for the whole account.
Prefix4 string `json:"prefix4,omitempty"`
Rules []Rule `json:"rules"`
}
A policy says which devices may reach which ports of which others. It is enforced by the receiving device on every packet that arrives over the mesh: what a device lets in is decided where it is, not where the traffic comes from.
{
"version": 3,
"rules": [
{"from": ["laptop", "phone"], "to": ["nas"], "ports": ["22/tcp", "445/tcp", "icmp"]},
{"from": ["*"], "to": ["printer"], "ports": ["631/tcp"]},
{"from": ["laptop"], "to": ["192.168.1.0/24"]}
]
}
A selector is "*", a device's mesh name (as `remohop net peers` shows it, without ".remohop"), or a device's identity fingerprint. In "to", a CIDR selects destinations behind a subnet router or exit node; those match nothing else (and "*" matches them too). Ports: "*" or absent for all, "22", "22/tcp", "8000-8100/udp", "icmp" (ping). Replies to connections a device opened itself always pass, as do ICMP errors.
Without a policy every device of the mesh may reach every port of every other, as on a LAN. A policy with an empty rule list lets nothing in.
The policy is shared by the account's devices: it is signed by the device that set it (`remohop net policy set`), which must be a member of the account, and devices pass it on to each other when they connect. A device adopts a policy with a higher version than its own. A device outside every account keeps a policy signed by itself.
func ParsePolicy ¶
ParsePolicy reads and checks a policy document.
type Rule ¶
type Rule struct {
From []string `json:"from"`
To []string `json:"to"`
Ports []string `json:"ports,omitempty"`
}
Rule lets the devices in From reach Ports on the destinations in To.
type SignedPolicy ¶
type SignedPolicy struct {
// Policy is the document exactly as signed (base64 in JSON, so that
// no reformatting can change the signed bytes).
Policy []byte `json:"policy"`
// Account is the account ID it belongs to; empty for a device outside
// every account.
Account []byte `json:"account,omitempty"`
Signer []byte `json:"signer"`
Sig []byte `json:"sig"`
}
SignedPolicy is a policy as it is stored and passed between devices.
func SignPolicy ¶
SignPolicy signs a policy for account with id.
func (*SignedPolicy) Verify ¶
func (sp *SignedPolicy) Verify(account []byte, member func(ed25519.PublicKey) bool) (*Policy, error)
Verify checks the signature and that the signer may set the policy (member reports whether a key is a member of the account; for a device outside every account, whether it is that device itself), and returns the policy.
type Status ¶
type Status struct {
PID int `json:"pid"`
Up bool `json:"up"`
Error string `json:"error,omitempty"`
Updated time.Time `json:"updated"`
Device string `json:"device,omitempty"`
Name string `json:"name,omitempty"`
FQDN string `json:"fqdn,omitempty"`
Identity string `json:"identity,omitempty"`
Addr4 string `json:"addr4,omitempty"`
Addr6 string `json:"addr6,omitempty"`
Prefix4 string `json:"prefix4,omitempty"`
Prefix6 string `json:"prefix6,omitempty"`
DNS string `json:"dns,omitempty"`
Exit bool `json:"exit,omitempty"`
Routes []string `json:"routes,omitempty"`
UseExit string `json:"use_exit,omitempty"`
ExitActive bool `json:"exit_active,omitempty"`
AcceptRoutes bool `json:"accept_routes,omitempty"`
Learned []string `json:"learned_routes,omitempty"`
// PolicyVersion is 0 and PolicyRules -1 without a policy (everything
// allowed).
PolicyVersion int64 `json:"policy_version"`
PolicyRules int `json:"policy_rules"`
PolicySigner string `json:"policy_signer,omitempty"`
Notes []string `json:"notes,omitempty"`
Peers []PeerStatus `json:"peers,omitempty"`
}
Status is the mesh on this device.
func ReadStatus ¶
ReadStatus returns the mesh status the host process last wrote, or nil when the mesh is not running (no file, or its process is gone).