Where I come from
I started using FreeBSD in the mid-90s, when NLINK was born. We started as NETLINK, but we had to change the name because of a trademark conflict. Some people here in Recife still call us by our first name.
Our first ISP had three main pieces: a Cisco router, a mail server running FreeBSD, and a Slackware Linux box as the dial-in server, with RocketPort serial cards sharing IRQs.
I started with security using Cisco ACLs. As the business grew, I had to build a firewall on the mail server too, and I used ipfw, which I learned by reading its man page. In 1996 I ordered a book from Book Pool, Internet Firewalls and Network Security, and that was the start of the security background I have used in every project since, from a system on a chip (SoC) installed in an office building to a router at the edge of a big datacenter.
Early on I built what I called horizontal security: logging in through the VPN did not open the whole network. Each user could reach only the servers they were authorized for, and every server had its own firewall. Today people call this controlling lateral movement, or micro-segmentation.
ipfw was my firewall for all of those jobs. Today, for small and medium offices, I use pf through OPNsense. In the datacenter I still use ipfw, because its stateless rules are fast with heavy traffic. That choice also influenced a development team I work with: they built a new VPC platform on FreeBSD jails with ipfw nat.
The call
One day I was called to solve a strange problem on that platform: very low traffic and very high CPU. A single network thread in the kernel was at 100% while the server handled only a few hundred packets per second.
How do you solve that in production, on a system you didn’t build, without knowing how it works inside? We couldn’t find the cause at the time. The first workaround was to move from ipfw to pf. Later the service moved off FreeBSD completely, to Debian and Proxmox.
That stayed with me for two years.
Two years later: a lab
Two years later, things were different. I had more continuous time for deep study, and I had already overcome some barriers, like working with Phabricator and Arcanist. I also got the application’s source code, thanks to Pedro Correia, and with it I could see exactly how each tenant’s NAT was configured. The key line was a 1:1 NAT used in the reverse direction of classic NAT: instead of hiding private clients behind one public address, it publishes a private server on a public address.
ipfw nat 1 config ip <public> unreg_only same_ports redirect_addr <private> <public>With that, I built a lab on one FreeBSD 16.0-CURRENT machine: three VNET jails (client, router, server) connected by epair interfaces, the same NAT configuration as production, and a small C program that sends TCP SYNs at a fixed rate to the published server. Finding where the bug was hidden took six months of research.
Then I used DTrace to measure two things: how long each packet spends inside libalias, the library behind ipfw nat, and which kernel function burns the CPU.
The result was clear. With 150,000 to 170,000 connections to port 443, every inbound packet took 1 to 2 milliseconds inside libalias, the network thread was at 99%, and 99% of the CPU samples were in one function: _FindLinkIn() .
A control experiment confirmed it. Same packet rate, but spread over many destination ports instead of only 443: even with more connections in total, each packet took 2 to 4 microseconds. The problem was not the number of connections. It was how many of them shared the same public port.
The bug
libalias keeps one record (a “link”) per connection. For an inbound packet it does two lookups:
Find the group for the public address, public port and protocol. This part uses a tree, so it is fast.
Inside that group, find the link for the remote client (address and port).
Step 2 was a linked list, walked one entry at a time.
For outbound traffic, the usual NAT case, each connection gets its own public port, so every group is small and the list is short. But with a published server, every client connects to the same public port: 443. All of them land in the same group, and every packet walks the whole list. TCP links that never see a clean close can live up to 24 hours, so the list grows to hundreds of thousands of entries.
Hosting providers hit this. Home and office routers don’t, and that is probably why it survived so long.
How old is it?
The grouping goes back to the first libalias, which Charles Mott started in August 1996 (version history). Version 2.1, from May 1997, added PacketAliasRedirectAddr() and PacketAliasRedirectPort(), the ancestors of redirect_addr and redirect_port. That is the version Brian Somers imported into FreeBSD on May 23, 1997 (3b160b8b6e5e), and from that moment all clients of a published address landed in one group. Gleb Smirnoff later brought libalias into the kernel for ng_nat in May 2005 (c4c9b52b8720), released in FreeBSD 6.0, and Paolo Pisati added in-kernel NAT to ipfw for FreeBSD 7.0, moving it into its own ipfw_nat module in February 2008 (531c890b8aec). The search inside the group stayed a list the whole time.
So the bug is about 29 years old.
In 1997, libalias ran in userland, inside ppp and natd, on single-CPU machines behind dial-up links. A redirect to a busy server would have hit the same list walk, but a few dozen connections never made it visible. The bug was there from the start; it only needed datacenter-scale traffic to wake up.
The fix
The change keeps the links of each group in a red-black tree ordered by the remote address and port, instead of a list. A lookup now takes about 18 comparisons instead of walking up to 170,000 entries.
All 22 libalias regression tests pass, and in userland a new connection in a group of 100,000 links went from about 1.25 ms to about 600 ns.
Upstream
I sent the patch to FreeBSD’s Phabricator as [D60083]. Adrian Chadd accepted it first and asked for more networking reviewers, so I also wrote to the freebsd-net mailing list. Gleb Smirnoff reviewed it line by line and asked good questions that made the patch better. Then he committed it to FreeBSD main with my name and my commit message: [16bc669facc5].
What I learned
A problem you can’t explain in production can often be explained in a lab. The lab is the tool that turns a guess into a measurement.
DTrace answered in minutes what we couldn’t answer in two years: where the time goes.
A control experiment is as important as the experiment itself.
If you run FreeBSD hard in production, you will find things nobody else sees. Report them, and if you can, fix them.
This bug once pushed a platform away from ipfw. Now ipfw handles that kind of traffic, for everyone.
How I make this
The investigation, lab, measurements and kernel patch in this post are my own work, and the patch was reviewed and committed by FreeBSD developers. English is my second language, so I use AI to help edit and polish my writing.



Great content and if it helps: https://systemsandbusiness.substack.com/
I worked on the IIS development team at Microsoft from 1997 to 2004. In IIS 4, we supported more than one website, using the Host header in the then-new HTTP/1.1 standard. In IIS 5, which released with Windows Server 2000, our goal was to go from supporting ~20 websites well to running 5,000 sites with decent performance. We found that we had a lot of linked lists that cost nothing to traverse when there were only 20 sites on one server, but were significant overhead when there were 5,000 sites. We developed a scalable hash table with fine-grained locking that was used for many different collections that needed fast lookup.