Running Loading on an interface
Loading on an interface attach, swap and remove programs safely.
These commands need Linux and root. Run sudo moat doctor --iface eth0
first: it says whether the machine and the interface's driver are ready.
See Install.
$ moat load rules.moat --iface eth0 [--mode native|generic] [--audit] [--dry-run]
$ moat reload rules.moat --iface eth0 [--dry-run]
$ moat unload --iface eth0 [--keep-sets]
$ moat status [--iface eth0] [--json]
$ moat audit on|off --iface eth0
$ moat enable rules.moat --iface eth0
$ moat disable --iface eth0
loadcompiles the rules, attaches them through a pinned XDP link and fills sets that come from files.--dry-runonly runs the kernel verifier.--auditstarts in audit mode.reloadswaps the program in place: there is no moment without a program. Sets whose definition is unchanged keep their contents, and sets loaded from a file are made equal to the file again. Counters start again from zero.- After the interface was removed and came back, which is what the unit
moat enableinstalls runs into,loadandreloadattach afresh and keep the sets: "the previous program had come off eth0 (the interface was removed); attached afresh, keeping sets". unloaddetaches the program and removes its state. With--keep-setsthe sets stay for the nextload.audit onmakes rules that drop count the packet and let it pass;statsthen shows them as "would drop".enablecopies the rules and their set files to/etc/moat/IFACE/and enablesmoat@IFACE.service, which loads them whenever the interface appears, at boot or later.statusnames any pinned map that has gone missing, for example "pinned map moat_counters in /sys/fs/bpf/moat/eth0 is missing; run moat unload to clean up, then moat load".
stats, status, var list, set list and set show wait, up to 10
seconds, while a load, a reload or a set change runs, so they never mix
one program's rule names with another program's counters.
Another XDP program on the interface
An interface runs one XDP program at a time. When another tool already
attached one, moat load stops and says so:
$ sudo moat load rules.moat --iface eth0
eth0 already runs an XDP program that moat did not attach; remove it with the tool that attached it, or with ip link set dev eth0 xdp off (moat doctor --iface eth0 shows it)
moat doctor --iface eth0 shows the same before loading, with the
program's name and id.
Where state lives
Pinned link and maps are in /sys/fs/bpf/moat/IFACE/, the manifest in
/var/lib/moat/IFACE/manifest.json. MOAT_BPFFS, MOAT_STATE,
MOAT_ETC and MOAT_SYSTEMD move these directories.
In another network namespace, enter it with nsenter --net=... rather than ip netns exec, which hides the BPF filesystem behind a fresh /sys.
Exit codes: 0 success, 1 errors in the rules, 2 wrong usage or state, 3 the kernel verifier or clang refused the program. The verifier is the usual cause of 3.