Development and tests
New to the code? Start with the code tour. What each test layer proves, and the results observed, are in Testing.
Go 1.27.4. Dependencies are pinned in go.mod and go.sum:
github.com/google/nftables (netlink), modernc.org/sqlite (pure-Go SQLite),
github.com/BurntSushi/toml, github.com/mdlayher/netlink and
golang.org/x/sys. The nftables library describes itself as early-stage, so
review and rerun the kernel tests before changing its version.
Build
Shell commands
scripts/build.sh # static linux/amd64 and linux/arm64 in dist/
VERSION=0.1.0 SOURCE_DATE_EPOCH=1790000000 scripts/build.shThe script also writes SHA256SUMS and THIRD_PARTY_LICENSES.txt. The same
source, Go version and variables produce identical binaries.
Tests
Shell commands
gofmt -l .
go vet ./...
GOOS=linux go vet ./...
go test ./...Portable packages (parsers, policy, storage, firewall model, CLI) run on any OS.
Files ending _linux_test.go run only on Linux.
On Linux, as root, with iproute2, nft and ping:
Shell commands
sudo env IPFENCE_INTEGRATION=1 "PATH=$PATH" go test -count=1 ./...This enables the kernel tests. They create network namespaces, change nftables only inside them, and delete them. Without the variable or privileges they are reported as skipped, with the reason; a skip is not a pass.
Shell commands
CGO_ENABLED=1 go test -race ./... # needs a C compiler
go test ./internal/detect -run '^$' -fuzz FuzzParsers -fuzztime 2mEnd-to-end, in a disposable virtual machine only
These scripts install the service, edit sshd and web server configuration, run
nft flush rulesetand switch the iptables variant. They refuse to run unless/etc/ipfence-disposable-test-machineexists. Never create that file on a machine you care about.
Needs systemd, openssh server and client, nftables, iproute2, curl, python3,
nginx, caddy, logrotate and strace. Run from an SSH session so init can be
checked.
Shell commands
sudo touch /etc/ipfence-disposable-test-machine
# copy the binary, systemd/ipfence.service and test/e2e/*.sh into one directory
sudo bash ./e2e.sh main ./ipfence-linux-amd64 ./ipfence.service
sudo cp e2e.sh lib.sh /var/tmp/ && sudo reboot
sudo bash /var/tmp/e2e.sh after-reboote2e.sh assumes the test machine is reached from 10.0.2.2, the host address
under QEMU user networking; change that check for other setups.
Shell commands
sudo bash ./matrix.sh docker ./ipfence-linux-amd64 ./ipfence.service
sudo bash ./matrix.sh ufw ./ipfence-linux-amd64 ./ipfence.service
sudo bash ./matrix.sh firewalld ./ipfence-linux-amd64 ./ipfence.servicematrix.sh docker tests whichever engine and firewall backend is configured and
needs a static busybox (busybox-static).
Changing things
- A new parser needs fixtures from real output, hostile input cases and a fuzz seed. It must not use anything a client controls to choose the address.
- A new probe needs a false-positive case in
TestProbesDoNotMatchOrdinaryTraffic. - A firewall change needs a model test and a kernel test, including "does not touch other tables".
- Never edit a released database migration; add one.
- Names that a rename would change live in
internal/product; also change the module path ingo.mod, the unit, the scripts and the docs.