Skip to content

Commit e053b16

Browse files
committed
blog: nftables flowtable
1 parent 8311397 commit e053b16

File tree

3 files changed

+119
-0
lines changed

3 files changed

+119
-0
lines changed

_layouts/post.html

+8
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,11 @@ <h1 >{{ page.title }}</h1>
2727
</article>
2828

2929
</div>
30+
31+
<!-- For rendering mermaid diagrams. -->
32+
<script src="https://cdn.jsdelivr.net/npm/mermaid/dist/mermaid.min.js"></script>
33+
<script>
34+
mermaid.initialize({ startOnLoad: true,
35+
theme: 'base'});
36+
window.mermaid.init(undefined, document.querySelectorAll('.language-mermaid'));
37+
</script>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
---
2+
layout: post
3+
title: "Software fastpath with nftables flowtable"
4+
section: Blog
5+
date: 2023-05-25T12:00:00
6+
author: Eric Garver
7+
category: feature
8+
---
9+
10+
## Introduction
11+
12+
Firewalld gained support for [nftables
13+
flowtable](https://github.com/firewalld/firewalld/pull/1116). This is a
14+
software fastpath that may significantly improve forwarding performance.
15+
16+
[Nftables
17+
flowtable](https://wiki.nftables.org/wiki-nftables/index.php/Flowtables)
18+
makes use of the kernel's connection tracking to bypass much of the
19+
network stack. This accelerates data packets of established
20+
connections.
21+
22+
## What It Looks Like
23+
24+
This feature can be enabled by setting `NftablesFlowtable` in
25+
`/etc/firewalld/firewalld.conf`. This setting defaults to `off`. To
26+
enable flowtable support set this value to your list of interfaces for
27+
which you want flowtable to be enabled, e.g. `NftablesFlowtable=eth0
28+
eth1`.
29+
30+
This can be done manually or with a sed expression.
31+
32+
Example to enable `eth0` and `eth1`:
33+
34+
```
35+
# sed -i 's/^NftablesFlowtable=.*/NftablesFlowtable=eth0 eth1/' /etc/firewalld/firewalld.conf
36+
# firewall-cmd --reload
37+
```
38+
39+
When this feature is enabled firewalld adds the below additional nftables
40+
rules. It's one additional rule and one flowtable object.
41+
42+
```
43+
table inet firewalld {
44+
flowtable fastpath {
45+
hook ingress priority filter + 10
46+
devices = { eth0, eth1 }
47+
}
48+
[..]
49+
chain filter_FORWARD {
50+
type filter hook forward priority filter + 10; policy accept;
51+
ct state { established, related } meta l4proto { tcp, udp } flow add @fastpath <--- new rule
52+
ct state { established, related } accept
53+
[..]
54+
```
55+
56+
## Performance Tests
57+
58+
This is the test topology used for gather performance test results.
59+
60+
```mermaid
61+
flowchart TB
62+
iperf3_client-->eth0
63+
eth1-->iperf3_server
64+
subgraph DUT
65+
eth0-->firewalld
66+
firewalld-->eth1
67+
subgraph firewalld
68+
end
69+
end
70+
subgraph traffgen
71+
subgraph net_namespace
72+
subgraph iperf3_server
73+
end
74+
end
75+
subgraph iperf3_client
76+
end
77+
end
78+
```
79+
80+
The device under test was artificially limited to two CPU cores. This
81+
was done specifically to stress the forward path.
82+
83+
For [traffic
84+
generation](https://gist.github.com/erig0/aaef1ca59f285323dcacf66255244c60)
85+
uses 16 iperf3 instances are run in parallel with 128 parallel streams
86+
for 60 seconds. This simulates 2048 concurrent connections. The
87+
benchmark is run 10 times to normalize the results.
88+
89+
Below is a graph of the results of `NftablesFlowtable` enabled vs
90+
disabled. The absolute numbers are less important. The important
91+
takeaway is the relative performance improvement.
92+
93+
![performance graph](/images/nftables-flowtable-perf.png)
94+
95+
## Caveats
96+
97+
Nftables flowtable can accelerate TCP and UDP flows. Control packets
98+
will still take the traditional network path, i.e. they will take the
99+
slow path.
100+
101+
Firewalld supports source based zones with `--add-source`. These can
102+
also be accelerated, but keep in mind that flowtable is enabled on the
103+
interface. So you must make sure that traffic from that source is
104+
received on the interface that was added to `NftablesFlowtable`. If in
105+
doubt, always use `--add-interface`.
106+
107+
## Summary
108+
109+
Nftables flowtable brings a significant performance improvement for
110+
forwarded traffic. This is applies to use cases like: network firewall,
111+
home router, and even container/VM traffic.

images/nftables-flowtable-perf.png

13 KB
Loading

0 commit comments

Comments
 (0)