198 points · by zdw · 3y ago · 63 comments
This allows for very fast dropping of DOS flood attacks. I've tested this using ipfw up to screening and dropping several 10s of millions of packets on 2014 era Xeons with minimal impact to traffic serving. I wrote a paper about this for a conf. that was cancelled due to COVID. I really need to re-submit it someplace.
This works for Mellanox, Chelsio, and NICs that use iflib (ix, ixl, igb, bnxt, and more that I'm forgetting).
OpenBSD has something very close to that w/ bpf(4) BIOCGFILDROP filter "drop".
https://man.openbsd.org/bpf#BIOCGFILDROP
In 2014 I was working on a hardware appliance for a company that has something to do with packet capture, and I found an intel driver that implemented a ring buffer on a 1 gigabit Ethernet adapter that allowed me to capture line rate without dropping a single packet over the course of hours; prior to this the adapter was barely able to capture 90% of the packets. I remember marveling at the design that must have gone into it, and here too to your description of this performance improvement.
I miss that stuff. Thanks for sharing,
I never quite 'got it' - this helps. Are you aware of similar tweaks in Linux land, by chance?
I consider myself reasonably well-experienced as a systems administrator... but can't quite recall stumbling across anything quite like this.
Check out https://blog.cloudflare.com/l4drop-xdp-ebpf-based-ddos-mitig...
and:
Makes sense why I haven't seen it, came out around the time I joined $CurrentEmployer, and we're stuck a couple decades behind.
But FreeBSD also has jails/vnet, which makes root -> kernel escalation a lot more spicy. Eventually the bug gets found, some years later, although not really the result of negligence.
As someone not deeply into the BSDs and who has never tried pf, I would love to see this claim illustrated with a few examples.
Are there any “definitive” or authoritative beginner guides for those merely curious, but without a production system to test on?
I actually find ipfw(8) [0] syntax more human-friendly.
[0] https://man.freebsd.org/cgi/man.cgi?query=ipfw&sektion=8&for...
https://docs.freebsd.org/en/books/handbook/firewalls/#firewa...
https://chat.openai.com/share/e1e2a207-5fb4-4f12-9f3c-7850ff...
https://docs.oracle.com/cd/E37838_01/html/E60993/pfovw-compa...
If they pulled in a more recent pf from either OpenBSD or more current FreeBSD would be welcome. (And you know, a recent tcp stack would be nice too; although they've added in things like MPTCP that they'd need to port forward by 20+ years)
>HISTORY
> The pfctl program and the packet filter mechanism first appeared in OpenBSD 3.0.
> July 1, 2007
Although I'm running Monterey, so maybe it's updated in more recent versions of MacOS.
They look an old version of OpenBSD PF and updated it to be multithreaded.
I could be mistaken, but I believe both FreeBSD PF & OpenBSD PF are still single threaded.
FWIW the threading in the network stack is one of the original major divergences between Open/FreeBSD PF. The way FreeBSD's PF works is within the context of FreeBSD's threaded network stack. FreeBSD PF is not "single threaded" in the way it used to mean.
I would really like to have the modern PF syntax/structure from OpenBSD in FreeBSD though. The unified rdr/nat/pass/block mechanism in OpenBSD is so much cleaner and nicer to work with.
To elaborate for people who don't know the history: Disagreement about how multithreading should work are why Matt got booted from the FreeBSD project and started DragonFly.
Conflicting personalities makes resolving technical disagreements so much harder.
[1] https://man.freebsd.org/cgi/man.cgi?query=pf&apropos=0&sekti...
I'm not an OpenBSD user but it sounds like this changed recently in OpenBSD-land as well, because the "Will multiple processors help?" FAQ entry disappeared some time between January and March 2023: https://web.archive.org/web/20230112170731/https://www.openb...
The number of queues will vary according to the specific NIC chip.
Multiqueue NICs do great work on networking loads when you have 1 core per NIC queue; and you can eliminate or at least reduce cross-core communication for most of the work.
It's not complex firewalling, but I did some HAProxy stuff in tcp mode, and the throughput available when running without queue alignment was miniscule compared to the throughput available when properly aligned. Firewalling has the benefit that queue alignment should happen automagically, because of where it runs. If you're doing a lot of processing in userspace, it makes a lot less of a difference, but on a very lightweight application, there was no point in using more cores than nic queues, because cross-core communication was too slow.
Check the /etc/examples stuff for the best docs on `npf`. Most of what I found online was outdated or just plain wrong.