I’ve returned to the topic of eBPF after 4 years, but this article won’t be about Cilium.
Well, I recently came across the bpfilter project and started wondering whether it could be useful for something very practical: maintaining a dynamic blocklist on a Linux server.
The idea was not to build yet another complete firewall. Linux already has excellent tools for that. I was more interested in a narrower problem: can a small service accept block decisions from Fail2ban, CrowdSec, an operator, or a threat feed and apply them directly in the kernel?
When a Linux server is under attack, the first question is usually simple:
Which addresses should be blocked?
The second question is more complicated:
Where should those blocks be enforced?
The usual Linux answer is familiar: Fail2ban makes a decision, and nftables or iptables applies it.
This line of thinking led to bfban: dynamic IP and CIDR blocklists managed by a small daemon and applied through bpfilter and eBPF.
I did not want to present it as a replacement for nftables. The goal was much more specific:
Can a Linux service maintain a changing blocklist and apply it inside the kernel, with expiration times (TTLs), CIDR support, and state recovery after a restart?
The answer is yes — at least for the functionality tested so far.
The problem with mixing the roles
Several tools are often mentioned together even though they do different jobs:
- Fail2ban reads logs and decides when an address should be banned.
- CrowdSec can make similar decisions using its own detection and reputation mechanisms.
- nftables and iptables enforce firewall rules.
- bpfilter is another packet-filtering engine that can load chains and sets as eBPF programs.
-
bfbandmanages dynamic bans, expiration times, and persistent state. - XDP and Netfilter are kernel attachment points where filtering can happen.
A simple workflow looks like this:
Fail2ban / CrowdSec / threat feed / operator
|
v
bfband Unix-socket daemon
|
v
bpfilter chain and dynamic sets
|
v
packet accepted or dropped
The important distinction is that bfban is not a log detector.
It does not decide that an SSH login is suspicious. It receives a decision from Fail2ban, CrowdSec, an operator, or another security system and applies that decision.
Where eBPF is involved
The daemon is not in the packet path.
When an administrator adds an address:
sudo /usr/sbin/bfbandctl add 203.0.113.10 60
bfband updates a bpfilter set. bpfilter then loads the filtering chain into the kernel as an eBPF program with associated maps.
After that, packets are checked in the kernel. A packet does not start a new process, call the daemon, or pass through a shell command for every lookup.
This separation is important:
Control plane:
bfbandctl -> Unix socket -> bfband -> bpfilter set
Packet path:
incoming packet -> kernel hook -> eBPF rule -> ACCEPT or DROP
The daemon manages the data. The kernel makes the packet decision.
Is bfban a replacement for nftables?
No — not as a complete firewall.
Use nftables when the server needs:
- stateful firewall rules;
- NAT;
- routing and forwarding policy;
- service and port policy;
- connection tracking;
- complex combinations of firewall conditions;
- a mature general-purpose firewall configuration.
bfban has a narrower purpose: maintaining a dynamic list of IP addresses and networks that should be blocked.
A useful way to think about it is this:
| Task | Suitable component |
|---|---|
| Detect brute-force login attempts | Fail2ban |
| Maintain a general firewall policy | nftables |
| Maintain a dynamic blocklist from several sources | bfban |
| Apply a packet decision inside the kernel | bpfilter/eBPF |
| Drop packets at the earliest supported ingress point | XDP |
If a direct Fail2ban-to-nftables setup already solves the problem, there may be no reason to add bfban.
The point of the project is not to replace every firewall. The point is to provide a focused blocklist-management layer with a different enforcement backend.
What does the proof of concept demonstrate?
The proof of concept demonstrates several concrete properties:
- IPv4 and IPv6 address handling;
- CIDR prefix handling;
- dynamic updates to kernel-backed sets;
- temporary bans with an expiration time (TTL);
- automatic removal after expiration;
- preservation of the original expiration time after a daemon restart;
- real packet drops, not only changes in a user-space list;
- integration with a bpfilter chain attached to
NF_LOCAL_IN.
That last point matters.
It is easy to show that a command accepted an IP address. It is more useful to show that traffic from that address actually stops, and that traffic starts working again after the TTL expires.
A real integration test
The test environment was:
- Rocky Linux 10;
- Linux kernel 6.12;
- bpfilter 0.8.0.
First, the daemon and the empty kernel sets were checked:
sudo /usr/sbin/bfbandctl ping
sudo /usr/sbin/bfbandctl list
sudo bfcli ruleset get
Then a documentation address was blocked for 60 seconds:
sudo /usr/sbin/bfbandctl add 203.0.113.10 60
sudo /usr/sbin/bfbandctl list
sudo bfcli ruleset get
The address appeared in both places:
- the daemon's list;
- the kernel-side
banlist4set.
After the TTL expired, the address disappeared from both lists.
The next test used a second machine on the network. Its IP address was blocked for 70 seconds. ICMP packets stopped arriving. After approximately 70 seconds, ping started working again without manual removal.
That verified the complete cycle:
ADD -> DROP -> TTL expiration -> REMOVE -> ACCEPT
The restart test was more important.
The test address was blocked for 180 seconds. After approximately 30 seconds, the daemon was restarted:
sudo systemctl restart bfband
sudo /usr/sbin/bfbandctl list
sudo bfcli ruleset get
The block remained active after the restart. It disappeared roughly 180 seconds after the original ADD, not 180 seconds after the restart.
That means the daemon restored the existing state without extending the ban.
Why use a daemon instead of direct firewall commands?
A shell command can add an address to a firewall set. That may be enough for a small setup.
A daemon becomes useful when several systems need to submit decisions:
- Fail2ban;
- CrowdSec;
- an operator;
- an abuse-response script;
- a threat-intelligence feed;
- an internal security service.
Instead of every producer implementing its own firewall update logic, they can use one Unix-socket API.
The daemon can also centralize:
- TTL handling;
- state persistence;
- restart recovery;
- duplicate handling;
- CIDR validation;
- bounded batch updates;
- reconciliation between user-space state and kernel state.
This is the main value of bfban: not the existence of another add IP command, but the lifecycle around a changing blocklist.
What is a threat feed?
A threat feed is not a database containing every malicious bot on the Internet.
It is usually a curated list of indicators associated with a specific threat or abuse pattern:
- IP addresses;
- CIDR networks;
- malicious hosting ranges;
- command-and-control infrastructure;
- addresses observed in phishing, malware, or scanning activity.
An IOC means “indicator of compromise”. In this context, an IOC may simply be an IP address or CIDR network that another system has already identified as suspicious.
bfban can apply such a list. It does not discover or verify the indicators itself.
What is XDP?
XDP stands for eXpress Data Path.
It is an early Linux hook for incoming packets. On a supported interface, an
XDP program can make a decision before the packet enters most of the normal
network stack.
bpfilter documents XDP as an early receive hook, before the regular Linux network stack processes the packet. See the bpfilter hook documentation.
bfban can attach its filtering chain to XDP:
sudo env BFBAN_HOOK='BF_HOOK_XDP{ifindex=2}' \
/usr/sbin/bfban init
However, XDP is not automatically the right choice for every server.
It only handles incoming traffic on the selected interface. It does not filter outgoing traffic from the host. It also does not solve a saturated provider link: if the uplink is already full, the packets have reached the provider and the local machine is too late.
The default bfban configuration uses NF_LOCAL_IN, which is usually easier to understand and suitable for protecting services running on the local host.
Native XDP and generic XDP
There are two important XDP execution modes.
Native XDP
Native XDP runs in the network driver's receive path, before the packet becomes a Linux socket-buffer structure (skb).
This is the earliest software path and usually has the lowest host overhead. It depends on support from the Linux driver.
Generic XDP
Generic XDP runs later, after the packet has entered the regular Linux receive path and has been turned into an skb.
It is compatible with more interfaces, so it is useful for testing and for environments where native support is unavailable. However, it has already paid some of the normal packet-processing cost.
bfban supports both native and generic XDP attachment. The actual mode depends on the kernel, driver, and attachment path.
It is important to verify the mode instead of assuming that a successful XDP attachment means native XDP is active:
sudo bpftool net show dev eno1
sudo ip -details link show dev eno1
ethtool -i eno1
The same filtering rule can therefore run at different points in the receive path.
Native and generic XDP should not be treated as equivalent performance modes. Generic XDP is still real XDP, but it does not provide the same early-ingress advantage.
What bfban does not do
bfban does not:
- classify botnets automatically;
- replace a stateful firewall;
- perform NAT;
- restore a saturated Internet connection;
- guarantee that every packet of a distributed attack is visible;
- decide whether a log entry represents an attack;
- turn an untrusted threat feed into a verified source of truth.
It is a component in a layered security design.
A practical deployment might include these layers:
provider filtering / DDoS protection
|
v
Linux host
/ \
v v
nftables bfban
^
|
Fail2ban / CrowdSec
The provider protects the uplink, the host firewall handles general policy, and bfban handles a changing blocklist. Fail2ban and CrowdSec remain decision makers; they feed bans into bfban.
The practical conclusion
bfban is useful when a Linux host needs a small, focused, kernel-backed blocklist service with:
- one API for multiple producers;
- IP and CIDR support;
- TTL-based bans;
- persistent state;
- restart recovery;
- bpfilter/eBPF enforcement;
- optional XDP placement.
It is not a universal firewall and does not need to become one.
The proof of concept is valuable precisely because it tests a narrow claim in the real datapath: a user-space daemon can maintain a dynamic blocklist, bpfilter can represent that list as kernel-side sets and rules, and traffic from a blocked source can actually stop and later recover when the TTL expires.
That is a useful building block — as long as it is used for the job it was designed to do.
Sources and further reading
- bfban GitHub repository
- bpfilter hook placement
- bpfilter rules and verdicts
- bpfilter
libbpfilterdocumentation - bpfilter source-build instructions
- bpfilter GitHub repository
- eBPF XDP documentation and driver support
- Linux BPF/JIT documentation
- Linux LPM-trie maps
- Linux BPF hash maps
- Linux XDP live-frame documentation
- XDP research paper
- nftables sets
- Feodo Tracker blocklist
- Spamhaus DROP
Top comments (0)