summaryrefslogtreecommitdiff
path: root/fw/lib
AgeCommit message (Collapse)Author
3 dayslib: the host rule set three files were already pointing atCalvin Morrison
/lib/ndb/fw names it, fw(8) uses it in two examples, and the service file passes it as the rule file. Nothing provided it, so following any of them got you a firewall that would not start. Written for the qemu NAT segment this is developed on: the local /24 first, since the gateway and the resolver both live there, then name resolution and the web, icmp so there is something to test with that does not need a name resolved first, and one port answered on. Calvin's; committed so the tree stops referring to a file that is not in it. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
3 dayssvc: /mnt/fw/ether0 needs an mntgen of its ownCalvin Morrison
The service file said -m /mnt/fw/ether0 and nothing made that name. mntgen invents names one level deep, so the one over /mnt gives /mnt/fw and stops there: one mntgen over /mnt makes /mnt/fw yes but not /mnt/fw/ether0, which is where fw is told to mount no a second one over /mnt/fw does yes So a second mntgen over /mnt/fw, as its own service, and every fw needs it. It is a file server like the rest -- posts its name, lets the process that started it exit -- so ready=srv:mntfw, the same shape fw uses. fwstart already does this imperatively, which is why the boot path worked and the supervised path would not have. Four checks now pin the premise both rest on, ending with fw actually mounting its control files under the second mntgen. The finding and the service file are Calvin's; the checks are mine. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
3 daysfw: a dead firewall leaves the network down, and can be restarted into itCalvin Morrison
Two things can happen when a firewall dies: the traffic it was filtering carries on unfiltered, or it stops. Only the second is defensible. A machine briefly off the network is a machine somebody notices and fixes; a machine briefly on the network with no rules is the thing the firewall was installed to prevent, and nobody notices it at all. fw already does the second, in all three modes, and by mechanism rather than by care. Measured rather than assumed: before fw device: /net/ether1 addr: 10.9.9.1 route: 10.9.9.254 fw running device: pkt0 addr: 10.9.9.1 route: 10.9.9.254 fw killed device: addr: route: pktmedium is unbindonclose, so the interface and the address go when fw's fds close, and the card is left bound to nothing with nothing reading it. In a namespace it is harder still: /net answers "i/o on hungup channel" and bind -a '#I' /net answers "mount/attach disallowed", because the device mask was dropped before the program started. So todo item 1 -- "a dead fw takes the network with it", open since the first commit -- was the requirement written down as a defect. It is now design.md and a FAILURE section in fw(8), and the tests assert it, which is the point: this is exactly the property a later helpful change reverses without meaning to. putback() was that change, written and never run; deleting it removed a fail-open path, not just dead code. What was actually broken is recovery, and in a way nobody had reached: a fw that dies leaves its control filesystem mounted, and a corpse of a mount fails everything asked of it -- including the access() check fw makes before touching a card, which then refuses the restart: fw: /tmp/rdbg/ctl: clone failed; not touching /net/ether1 until it exists That check exists so fw does not take a card it cannot then serve, and it was keeping fw from ever coming back. Now the dead mount is cleared first, the same way reclaim() clears the pkt interface the same dead fw left behind: both are its own wreckage. With that and -a/-g in the service file -- so a restart does not need the address it just lost -- the whole cycle works and never passes through open: crash, network down, restart, network up and filtered. Ten checks, three of which fail against the previous fw.c. 87 pass. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
4 daysfw: make the /srv name worth watching, and say how to supervise itCalvin Morrison
todo.md said fw daemonizing meant svc could not supervise it, and that it needed a foreground mode. Both wrong. svc has had the shape from the start. ready=srv: watches the /srv name rather than the pid, and its own manual says why: "Use this for a service that posts to /srv and lets the process you started exit, which many Plan 9 file servers do on purpose. For these the /srv file is watched and the process is not, so the process exiting is normal and never causes a restart." init.c agrees -- reap() returns early for Ksrv with that comment on it. Nor is detaching unusual. 42 commands under /sys/src/cmd use postmountsrv or threadpostmountsrv; five call srv() directly, and every one of those is a stdio server (ramfs -i, ext4srv -s, skelfs, hjfs, wacom) speaking 9P on file descriptors it was handed. That is not a foreground service, it is a pipe server: no /srv, no mount, nothing to supervise. A foreground mode for fw would buy a pid to watch, and the /srv name is the better signal -- it survives the process that made it. What was true underneath the wrong diagnosis: the name was not honest. Taking the control filesystem away ends the server proc, and the relays carried on filtering: procs: 3 ... take the ctl filesystem away ... procs after: 2 still filtering? pkt interface: pkt0 A firewall nobody can reach, stop, or notice, and the /srv name gone while it runs. Srv.end now takes the whole thing down, which is the answer the relays already gave when their wire failed. Same test after: three procs become none and the interface goes with them. So: no flag, an example service file in lib/svc, and a SUPERVISION section in fw(8) that says what init should watch and what restarting will and will not fix. Restart=always brings fw back; it does not undo taking the card, so the new fw has no address to read. Supervision works, recovery does not, and that stays open as item 1. Two checks. Against the previous fw.c they fail with two orphaned procs and a pkt interface still bound -- and so do the leak checks at the end of the run, which is what they were built for. 77 pass. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
4 daysfwstart: make the directory before mounting on it, and let go of the consoleCalvin Morrison
if(! test -d /mnt/fw) mntgen /mnt/fw mount(2) needs its mount point to exist, so mntgen cannot create /mnt/fw -- and this ran it only when /mnt/fw was missing, which is exactly the case where it fails: mntgen: mount /tmp/mg/fw: file does not exist: '/tmp/mg' So on a machine that had never had a /mnt/fw, the control directories never appeared, and fw's own "not touching the card until the mountpoint exists" check then refused every card in the file. The script has never worked on a fresh machine. It has also never been run by the suite, which is the other half of why nobody noticed. Now the directory first, then mntgen only if it is not already there -- under mntgen every name exists, which is the test. Both mntgen and fw leave a server behind, and a server started from a shell keeps that shell's descriptors, so at boot they sit on the console's input and it reads as a wedged terminal. This is the trap CLAUDE.md documents; the script was walking into it. They get /dev/null. Three checks, and fwstart now gets run at all: a control directory appears, a card that is not there is reported and skipped, and nothing left running holds the descriptors we started it with. The first fails against the old script. The third does not, because the old script never started anything for want of the directory -- it guards the fix from here, not the bug that was there. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
4 daysfw: a firewall, at a card, between two networks, or in front of a namespaceCalvin Morrison
One program with three modes, sharing one rule engine and one ndb rule language. Which mode it is depends on what you point it at, and it says so at startup rather than choosing silently. fw -e /net/ether0 rules.ndb a card: every packet in or out fw rules.ndb <side> <side> two networks: everything crossing fw rules.ndb one namespace: what programs ask for The first two filter packets on a wire, using the pkt medium: the stack gives up its card and gets a synthetic one with fw on the other end, so nothing reaches it that fw did not pass. Since the stack no longer has ethernet, fw answers ARP for the address it stands in for. The third serves a filtered /net and matches connect and announce before they reach the kernel, so a refusal comes back out of dial(2) with a reason. That is only a boundary if the program also loses #I, which /dev/drivers does and cannot be undone; fw.rc does it in the right order. Rules are ndb, matched top to bottom, first match wins, no match denies. Connections are tracked, so permitting traffic one way permits the replies. A rule change drops connections the new rules forbid rather than letting them finish: a block blocks. Logging is per rule, to /sys/log/fw. Tested on the init-test VM in all three modes: a page fetched through a real card, a TCP handshake across two networks, request filtering with the escape routes closed, live rule changes killing established connections, and one rule file working unchanged at both altitudes. doc/todo.md has what is not done. Item 1 is the one that matters: a fw that dies takes the card's address with it, so the machine loses its network and fw cannot restart unaided. That also blocks svc supervision. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>