RediWM is a Wayland compositor written in Zig (OpenGL ES) that includes everything in one process
Firewall (firewall/, firewall_helper/, firewall_main.zig)
Plan and decisions: docs/plans/firewall.md. Settings side:
control_center/sections/firewall*.zig (notes in src/control_center/AGENTS.md).
firewall/is the shared module (std only): the model Settings draws, the request protocol, validation, and pure parsers/renderers per manager (ufw.zig,firewalld.zig,own.zigfor our nftables table and pf anchor,inventory.zig,sockets.zig,blocks.zig). Test them withzig build test-firewall; nothing here runs a tool.rediwm-firewall-helperruns as root under pkexec and is the only code that runs tools or writes system files.read(status, recent blocks) andmanage(everything) are separate polkit actions, chosen by argv1 (data/org.rediwm.firewall.policy); the helper refuses a change inreadmode.syncre-applies our saved rules (boot unit, NetworkManager dispatcher). Requests are untrusted: every field passesvalidate.zigbefore a renderer or argv sees it, which is why renderers never escape. Removals usevalidate.removal(port lists, a manager's ownrawtext, matched against its listing).- Tools come from system directories only (
run.tool), run with a fixed C-locale environment (run.environment), never a shell. Failures reach the page as fixed words (failureinfirewall_main.zig), never tool output. - One manager at a time. nftables base chains stack, so our table cannot
open what ufw or RediOS drops.
linux.zigdetects our table, firewalld, ufw and RediOS; edits go through whichever manages, and nothing is editable while two are active. Our own table (inet rediwm) and pf anchor (rediwm) are written only by us; other tables, pf.conf rules and ipfw are read-only. pf.conf is changed only to add the anchor (backup kept) or, when missing, written fromown.pf_conf. - Trust is a connection's NetworkManager zone (
networks.zig): firewalld follows it natively; our table'shome_ifacesset is filled bysync(dispatcher). Without NetworkManager (FreeBSD) trust is per interface in our state. - Revert: a change with
revert_afterforks a detached watchdog (state.arm) that applies the computed undo unlessconfirmstops it. It closes stdio so Settings' pipe ends now. Lockdown is a separateinet rediwm_lockdowntable (priority -200), runtime only. - State files are root-only:
${sysconfdir}/rediwm/firewall.json(ours; re-validated on load), renderedfirewall.nft/pf.rediwm.conf, run state under${rundir}/rediwm-firewall. Useinstall_paths, never literals; the systemd unit and dispatcher paths are third-party locations and literal. - Tests never touch the host firewall:
tests/firewall_helper.pyruns the real helper as namespace root inunshare -rmnwith config/run dirs on tmpfs and nmcli/systemctl/ufw/firewall-cmd hidden;tests/firewall_settings.pydrives Settings with a fake pkexec (tests/fixtures/firewall_pkexec.sh) and fake helper. pf is checked on the FreeBSD VM (pfctl -nf).