Support nftables and iptables, preferring nftables #92
No reviewers
Labels
No labels
Bug
BuildIssue
Claude-fixed
Enhancement
In Progress
Low priority
On Hold
Rejected
Security
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
keyop-go/nfq_forwarder!92
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "issue15_nftables_support"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Closes #15.
Abstracts the packet-interception/NAT mechanism behind a
firewallBackendinterface (internal/nfq_forwarder/firewall.go) with two implementations:iptablesBackend(firewall_iptables.go) - a near-mechanical move of the existing, already battle-hardened iptables logic (unchanged in substance).nftablesBackend(firewall_nftables.go) - shells out tonft(8)and parses its structured-jJSON output, owning a dedicatedinet nfq_forwardertable with two chains pinned to nftables' named prioritiesmangle/dstnat(confirmed empirically to resolve to -150/-100, preserving the same interception-before-DNAT ordering guarantee GitLab issue #4 depends on).Configuration.FirewallBackend(firewall_backend: auto|iptables|nftables, defaultauto) drivesselectFirewallBackend, called once at startup: auto-detection prefers nftables when actually usable (not just present on PATH - confirmed empirically that an unprivileged process can findnftbut still fail a barenft list tables), falling back to iptables otherwise. An explicit override skips detection and fails loudly if that backend doesn't work.Packaging now bundles both
iptablesandnftprivate, capability-enabled copies (.goreleaser.yaml,scripts/nfpm-postinstall.sh,Makefile'sinstalltarget, CI's defensive package-install block) - verified via a realmake packagerun that both binaries build, get packaged into the.deb, and the postinstall script'ssetcapstep covers both.Real-host verification (this sandbox has genuine root): the nftables backend was verified end-to-end - rule creation, correct priorities/comments, counter reads, and full cleanup - against a real
nftinstance. The iptables backend's regression check hit an unrelated, pre-existing environment defect in this sandbox (the localiptablesbinary crashes with a glibcfree(): invalid sizeon any invocation at all, confirmed via a raw shell call outside Go) - not caused by this refactor, since the exact rule-construction code is unchanged. SeeCLAUDE.md's Known Issues for the full verification status and what's still open (a clean-host iptables regression check, and real SSH traffic through the nftables backend).Test plan
make lintcleanmake testclean (all packages)go build ./...nftinstance (root)make packagebuild confirming bothiptablesandnftare bundled and setcap'd🤖 Generated with Claude Code
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.