logtopf shows the packets my FreeBSD firewall logs as a live table of flows. The name is German for “log pot”. It’s a small C program with libpcap and ncurses, and it’s now on GitHub with a prebuilt binary that also runs on pfSense and OPNsense.


Why I built it
Because pftop is just noisy. It shows every state pf is tracking, and on a busy firewall that doesn’t really show me anything useful. The questions I actually have are narrower: what’s getting blocked, by which rule, who’s using the bandwidth right now, and does my match rule catch what I think it catches?
pf can already answer all of that. Any rule with log sends its packets to the pflog0 interface, each with a header saying which rule matched, what it did and on which interface:
block in log on $wan
pass in log (all) on $lan proto tcp to port { 80 443 }
tcpdump -i pflog0 can read those, but it prints one line per packet, and that scrolls past faster than I can read. logtopf counts them instead. One row per flow, with packets, bytes, rate and how long ago it last saw a packet, sorted by whatever column I pick.
Also, I really love TUIs. A live table in a terminal is exactly how I want to watch a firewall, and nothing else like this is out there. So I wrote it.
Made for a bad connection
A firewall’s serial console is often the only way in when something’s wrong, sometimes through cu inside tmux. So logtopf is built to stay usable there. It redraws once a second, and ncurses only sends what changed, so at 9600 baud a refresh uses about 9% of the line.
Scrolling is the hard part. If you hold the arrow key on a slow line, a naive program queues up a frame per key press, and the list keeps scrolling for seconds after you let go. logtopf only draws the next scroll frame once the kernel says the last one has left the tty. A held key skips ahead instead of piling up.
Getting it ready to publish
logtopf had been “mostly done” for a while. Before putting it on GitHub, I gave it to Claude Code to review, test and clean up.
Testing a pf tool needs pf. So Claude set up a FreeBSD 14.5 VM with QEMU, and wrote a small packet generator that writes made-up frames into an epair interface through BPF. They go through real pf rules and come out on pflog0 like real traffic. logtopf runs in tmux, and each test reads the screen back with tmux capture-pane and checks the numbers.
The first failures were in the tests themselves. pf is last-match-wins, so a catch-all pass at the end of the test rules quietly overrode every log rule above it. And log (all) on a rule with no state logs every packet twice.
The first real bug: IPv6 TCP flows had no ports. logtopf only keeps the start of each packet, and 128 bytes didn’t cover the 72-byte pflog header, the 40-byte IPv6 header and the 20-byte TCP header together. It keeps 192 now.
The wrong turn
To measure the serial console, Claude first used nmdm(4), FreeBSD’s virtual null-modem cable. At 9600 baud the screen came out garbled, and it looked like an ncurses bug.
It wasn’t. Replaying the exact same bytes into tmux rendered perfectly. nmdm drops bytes when the reader on the other end is slow, and a reader pretending to be a 9600 baud terminal is slow on purpose. Claude switched to a plain pty, read at the real baud rate, and the “rendering bug” disappeared.
The benchmark that found the real bugs
I wanted the README to show how light logtopf is, since it’s meant to run on the firewall itself, and plenty of firewalls are small boxes or VMs with little to spare. So Claude benchmarked it next to pflogd, the logger FreeBSD already runs, and tcpdump, all reading the same packets, from idle up to as fast as the generator could go.
The idle numbers were great, and had been all along. Under load, three things came out.
It dropped packets it had already received. At 100,000 packets a second, logtopf threw away 884,490 of them by itself. The kernel hands packets over a whole buffer at a time, and that overflowed the 16,384-entry ring between logtopf’s capture and worker threads. The fix: when the ring is full, the capture thread now waits for the worker instead of dropping. The kernel keeps buffering in the meantime.
At full speed, it stopped reading entirely. logtopf used 0.4% CPU while the kernel dropped 19 million packets. The capture thread was pinned to core 1, “to stay off core 0 where interrupts land”. Under load, the kernel’s own packet threads filled core 1, and a thread pinned to a full core has nowhere else to go. procstat showed it as runnable but it never ran. Pinned, it stalled in 3 of 8 runs. Unpinned, in none.
It asked for far too much memory. logtopf requested a 128 MB capture buffer, which showed up as 144 MB of its own memory, and the kernel can keep two more buffers that size. Its startup warning even told people to raise the limit to 128 MB, which is bad advice on a 512 MB appliance. Stock FreeBSD caps capture buffers at 512 KiB anyway, and that turned out to be plenty: over a million packets a second with almost nothing dropped. It asks for 4 MiB now, with a -B flag for more.
There was also a fourth casualty. pflogd writes every logged packet to disk, and during the full-speed runs it wrote 3.9 GB and filled the VM.
How light it is now
| Logged packets per second | logtopf CPU | logtopf memory | pflogd CPU |
|---|---|---|---|
| none | 0.1% | 6 MiB | 0% |
| 100,000 | 1.1% | 17 MiB | 1.5% |
| 1,100,000 | 7.8% | 17 MiB | 18% |
| 1,000,000 from a scan or flood | 19% | 17 MiB | 16% |
CPU is a share of one core. “Scan or flood” means every packet comes from a new address, so logtopf has to throw out an old flow for each one. For comparison, tcpdump needed a whole core above 100,000 packets a second.
On a VM with one core and 512 MB, at 330,000 packets a second, which was all that VM could generate, logtopf used 1.9% of the core and lost nothing.
Try it
There’s a release with a binary for FreeBSD 14 and 15 on amd64. It only needs the libpcap and ncurses that come with the base system, so it runs on pfSense and OPNsense too, where there’s no compiler.
fetch https://github.com/timondurot/logtopf/releases/download/v1.0.0/logtopf-1.0.0-freebsd14-amd64.tar.gz
tar xzf logtopf-1.0.0-freebsd14-amd64.tar.gz
./logtopf-1.0.0-freebsd14-amd64/logtopf
Add log to the rules you want to watch, and press ? for the keys.
Takeaways
- Benchmark under load, not just idle. Every bug above was invisible at idle.
- Pinning a thread to a core is a bet that nothing else will ever want that core.
- When a test fails, check the test first. The last failure of the day was a
?key that the VM’s shell expanded into a filename.