Says the verb and its answer, the two new files (uplink-names, its applied record) and fallback.json, the guard's round over the default- route link, the sudo -n install / mv -f commands, and that uplink-names only sets how resolved answers those names over a link, never the link itself. Builds: design 08 sign-in-page §10
9.6 KiB
systemd-resolved
A machine's own resolver (novox/hq ADR 0247): systemd-resolved, holding the node seat node-resolver and
providing split-dns at the machine's reach. It is assigned only where something on the machine requires
split-dns — today a VPN client whose company domains must go to the VPN's own servers while every other
name still goes to the mesh's two resolvers. Every other machine has none, and lists the mesh's resolvers
in its resolver file as ADR 0223 says.
It knows nothing about any VPN. It routes a set of domains to a set of servers over one link, lists
what is routed, and takes a route away. A module wrapping a VPN client that writes /etc/resolv.conf
itself carries its own adapter, which calls these verbs. A VPN that tells systemd-resolved its link's DNS
itself (NetworkManager's VPNs, WireGuard set up by networkd, Tailscale) needs none.
What it writes
| file | what |
|---|---|
/etc/resolv.conf |
this machine's own private address alone, with ADR 0223's options. The uplink's holder steps back from this file where this module is assigned (the controller's rule, ADR 0247), so it has one writer |
/etc/node-resolver/resolv.conf |
the same file, kept beside it for the guard to compare with and put back |
/etc/node-resolver/suffix |
the mesh's own domain, which a route may never take |
/etc/systemd/resolved.conf.d/50-mesh.conf |
every mesh resolver as the default route for names (DNS=, Domains=~.), no public fallback, the stub on loopback and on the private address, no cache, no LLMNR or mDNS |
/etc/node-resolver/answer-within |
the config value answer-within: how long the guard gives each of the mesh's resolvers to answer before it takes them for silent (issue 1981) |
/etc/node-resolver/private-interface |
the private network's own interface name, so the guard never gives the uplink's names to it (design 08 sign-in-page §7, DQ-1) |
/var/lib/node-resolver/uplink-names |
the host names uplink-names gave, one a line, root's, written through sudo -n install then sudo -n mv -f (§6); stays until an empty list or a person's cleanup, even once the module leaves |
/var/lib/node-resolver/uplink-names.applied |
the guard's own record of what it last gave the link carrying the default route: the names, the link, when, and resolved's refusal or empty (§8); read at the guard's start, so a restart takes the names off the link it names, never inferring which |
/run/node-resolver/fallback.json |
whether the mesh's resolvers are silent now, by ADR 0688's guard, and since when; routes' mesh_resolvers field reads it; gone at the next boot, and the guard's first round writes it again |
On the private address, so containers reach it. A container copies its machine's resolver file and
cannot reach the machine's loopback, so the file names the address the machine has on the private
network, where resolved also listens (DNSStubListenerExtra). The packet filter admits a machine's own
guests and nobody else, so no other machine can ask it. The port is declared from: machine and fixed:
a fixed port is a claim on the machine, given to one module, and the mesh's own resolver (dnsmasq, on
the anchor and the home server) claims the same one. The two are not meant to share a machine.
No cache. Nothing on the machine keeps a copy of a mesh name or of a "no such name". Each question is asked again, as it was before this resolver.
Its package is systemd's. resolved ships with systemd, whose package belongs to the systemd module
holding node-service-manager (ADR 0207). This module declares the service, running and enabled,
restarted when its drop-in changes, and nothing to install.
The guard
One long-running process, as root: resolver-tools guard.
- It keeps the resolver file the module's own. Twice a second it compares
/etc/resolv.confwith the kept copy. Another program's write is displaced: the guard keeps what it wrote in/run/node-resolver/displaced/, readable by root alone and gone at the next boot, and names its writer from the file's own header. - A write a module takes is put back at once. A module on the machine that reads the write and routes what it needed says it took it, and the module's own file stands again within a second.
- A write nobody takes stands for 90 seconds, then is put back. 90 seconds is longer than the
node-engine needs to see the rewrite twice, so ADR 0241's
machine.<m>.systemd-resolved.rewrittenis still raised, naming the writer, for a write nothing on the machine declared to handle. - Only the mesh's resolvers answer every name. Every five seconds, a link that a network manager gave servers of its own is told it is not a default route for names. Its own domains stay its own.
- While the mesh's resolvers are silent, a network's own servers answer. Behind a network's sign-in
page (a guest or hotel network) the private network is out of reach until the person signs in, so no
name, the page's included, would resolve. Every five seconds the guard first asks each of the mesh's
resolvers a name under the mesh's domain, straight over the network, each within the config value
answer-within(seconds, default 1); while none answers, every link a network manager gave servers is a default route again, read from resolved each round (so it holds after the guard restarts), and a network joined meanwhile keeps its default route. A linkrouterouted (a VPN's) never is. Once one answers, they lose it within five seconds. The guard says both turns on its journal, and the node's network check still says the mesh's names do not resolve. - What it says elsewhere — the
routesverb'soutside_writes, from/run/node-resolver/history.json— is when, the writer's name and what became of each write. It never includes a server or a domain. - It gives the uplink's holder's check names to the link carrying the default route. Every round it
reads
/var/lib/node-resolver/uplink-namesand finds the link that carries the default route: among the kernel's IPv4 default routes, or the IPv6 ones when there is none, the one with the lowest metric whose link is neither onerouterouted (a VPN's) nor the private network's own interface (its own fact,/etc/node-resolver/private-interface); none when there is no such link. It gives that link its own domains plus one routing-only domain~<name>per name, keeping every search domain and routing domain it already has, and takes the names off the link they were on before, when that differs: never a link's servers, its default route for names (that stays the fallback's alone), its addresses or its routes. It never counts its own names when it judges whether a link isrouterouted, so a link holding only them still has its default route given back by the fallback while the mesh's resolvers are silent. What it gave is kept in/var/lib/node-resolver/uplink-names.applied, read at the guard's own start, so a restart never infers which link to take them off; a refusal by resolved is journalled once per change, never every round.uplink-namesonly sets how resolved answers those names over a link — never the link itself, which the network manager chooses.
Its verbs
On the mesh, through the node's runtime as the operator account (writes escalate with sudo -n):
| verb | does |
|---|---|
<node>/node-resolver.routes (r) |
the mesh's resolvers, each link given servers of its own with its routed domains and whether it is a default route, and the resolver file's outside writes. Also uplink_names {names, link, refused} (the applied list's names resolved holds on that link now, never the file's) and mesh_resolvers {silent, since} (ADR 0688's fallback). The machine's own socket answers the same |
<node>/node-resolver.route (a) |
{link, domains, servers}: these domains, and every name under them, to these servers over this link, and only them. The mesh's own domain and the root are refused |
<node>/node-resolver.unroute (a) |
{link}: that link's domains go to the mesh's resolvers again |
<node>/node-resolver.uplink-names (a) |
{names}: at most 8 host names (letters, digits, hyphens and dots, lower-cased); an empty list takes them away. Writes /var/lib/node-resolver/uplink-names whole, through sudo -n install -m 0644 -o root -g root /dev/stdin uplink-names.new then sudo -n mv -f uplink-names.new uplink-names. Answers {names, link, set_at}: the names now given, the link they are answered over now (empty when no link carries a default route), and when. Refused, naming the name and why: not a host name (a wildcard, a trailing dot, a label over 63 bytes), the root, the mesh's own domain or under it, or more than 8 names |
On the machine, to its own root processes, over /run/node-resolver/verbs.sock (mode 0600). The path
is the seat's, so a caller does not need to know which holder answers. The protocol is one JSON line
{"verb": …, "args": {…}} and one JSON line back, {"result": …} or {"error": "…"}. The verbs are
routes, route and unroute (uplink-names is the bus's alone, never the machine's: its caller is
always on the bus), plus:
displaced: the write standing now, with what it held, or null;routewithtakes(the write'sid) andby(the module's name): route, then take that write, so the module's file is put back.
A VPN's servers and domains are handed over on this socket, never over the bus. They cross the bus only
as the answer to routes when the operator asks it, and nothing keeps that answer.
resolved holds the routes itself, per link, and forgets a link's route when the link goes. Nothing here keeps a table of its own that could disagree with it.