4
4
Netfilter's flowtable infrastructure
5
5
====================================
6
6
7
- This documentation describes the software flowtable infrastructure available in
8
- Netfilter since Linux kernel 4.16.
7
+ This documentation describes the Netfilter flowtable infrastructure which allows
8
+ you to define a fastpath through the flowtable datapath. This infrastructure
9
+ also provides hardware offload support. The flowtable supports for the layer 3
10
+ IPv4 and IPv6 and the layer 4 TCP and UDP protocols.
9
11
10
12
Overview
11
13
--------
12
14
13
- Initial packets follow the classic forwarding path, once the flow enters the
14
- established state according to the conntrack semantics (ie. we have seen traffic
15
- in both directions), then you can decide to offload the flow to the flowtable
16
- from the forward chain via the 'flow offload' action available in nftables .
15
+ Once the first packet of the flow successfully goes through the IP forwarding
16
+ path, from the second packet on, you might decide to offload the flow to the
17
+ flowtable through your ruleset. The flowtable infrastructure provides a rule
18
+ action that allows you to specify when to add a flow to the flowtable .
17
19
18
- Packets that find an entry in the flowtable (ie. flowtable hit) are sent to the
19
- output netdevice via neigh_xmit(), hence, they bypass the classic forwarding
20
- path (the visible effect is that you do not see these packets from any of the
21
- netfilter hooks coming after the ingress). In case of flowtable miss, the packet
22
- follows the classic forward path.
20
+ A packet that finds a matching entry in the flowtable (ie. flowtable hit) is
21
+ transmitted to the output netdevice via neigh_xmit(), hence, packets bypass the
22
+ classic IP forwarding path (the visible effect is that you do not see these
23
+ packets from any of the Netfilter hooks coming after ingress). In case that
24
+ there is no matching entry in the flowtable (ie. flowtable miss), the packet
25
+ follows the classic IP forwarding path.
23
26
24
- The flowtable uses a resizable hashtable, lookups are based on the following
25
- 7 -tuple selectors: source, destination, layer 3 and layer 4 protocols, source
26
- and destination ports and the input interface (useful in case there are several
27
- conntrack zones in place).
27
+ The flowtable uses a resizable hashtable. Lookups are based on the following
28
+ n -tuple selectors: layer 2 protocol encapsulation (VLAN and PPPoE), layer 3
29
+ source and destination, layer 4 source and destination ports and the input
30
+ interface (useful in case there are several conntrack zones in place).
28
31
29
- Flowtables are populated via the 'flow offload' nftables action, so the user can
30
- selectively specify what flows are placed into the flow table . Hence, packets
31
- follow the classic forwarding path unless the user explicitly instruct packets
32
- to use this new alternative forwarding path via nftables policy.
32
+ The 'flow add' action allows you to populate the flowtable, the user selectively
33
+ specifies what flows are placed into the flowtable . Hence, packets follow the
34
+ classic IP forwarding path unless the user explicitly instruct flows to use this
35
+ new alternative forwarding path via policy.
33
36
34
- This is represented in Fig.1, which describes the classic forwarding path
35
- including the Netfilter hooks and the flowtable fastpath bypass.
37
+ The flowtable datapath is represented in Fig.1, which describes the classic IP
38
+ forwarding path including the Netfilter hooks and the flowtable fastpath bypass.
36
39
37
40
::
38
41
@@ -67,11 +70,13 @@ including the Netfilter hooks and the flowtable fastpath bypass.
67
70
Fig.1 Netfilter hooks and flowtable interactions
68
71
69
72
The flowtable entry also stores the NAT configuration, so all packets are
70
- mangled according to the NAT policy that matches the initial packets that went
71
- through the classic forwarding path. The TTL is decremented before calling
72
- neigh_xmit(). Fragmented traffic is passed up to follow the classic forwarding
73
- path given that the transport selectors are missing, therefore flowtable lookup
74
- is not possible.
73
+ mangled according to the NAT policy that is specified from the classic IP
74
+ forwarding path. The TTL is decremented before calling neigh_xmit(). Fragmented
75
+ traffic is passed up to follow the classic IP forwarding path given that the
76
+ transport header is missing, in this case, flowtable lookups are not possible.
77
+ TCP RST and FIN packets are also passed up to the classic IP forwarding path to
78
+ release the flow gracefully. Packets that exceed the MTU are also passed up to
79
+ the classic forwarding path to report packet-too-big ICMP errors to the sender.
75
80
76
81
Example configuration
77
82
---------------------
@@ -85,7 +90,7 @@ flowtable and add one rule to your forward chain::
85
90
}
86
91
chain y {
87
92
type filter hook forward priority 0; policy accept;
88
- ip protocol tcp flow offload @f
93
+ ip protocol tcp flow add @f
89
94
counter packets 0 bytes 0
90
95
}
91
96
}
@@ -103,6 +108,117 @@ flow is offloaded, you will observe that the counter rule in the example above
103
108
does not get updated for the packets that are being forwarded through the
104
109
forwarding bypass.
105
110
111
+ You can identify offloaded flows through the [OFFLOAD] tag when listing your
112
+ connection tracking table.
113
+
114
+ ::
115
+ # conntrack -L
116
+ tcp 6 src=10.141.10.2 dst=192.168.10.2 sport=52728 dport=5201 src=192.168.10.2 dst=192.168.10.1 sport=5201 dport=52728 [OFFLOAD] mark=0 use=2
117
+
118
+
119
+ Layer 2 encapsulation
120
+ ---------------------
121
+
122
+ Since Linux kernel 5.13, the flowtable infrastructure discovers the real
123
+ netdevice behind VLAN and PPPoE netdevices. The flowtable software datapath
124
+ parses the VLAN and PPPoE layer 2 headers to extract the ethertype and the
125
+ VLAN ID / PPPoE session ID which are used for the flowtable lookups. The
126
+ flowtable datapath also deals with layer 2 decapsulation.
127
+
128
+ You do not need to add the PPPoE and the VLAN devices to your flowtable,
129
+ instead the real device is sufficient for the flowtable to track your flows.
130
+
131
+ Bridge and IP forwarding
132
+ ------------------------
133
+
134
+ Since Linux kernel 5.13, you can add bridge ports to the flowtable. The
135
+ flowtable infrastructure discovers the topology behind the bridge device. This
136
+ allows the flowtable to define a fastpath bypass between the bridge ports
137
+ (represented as eth1 and eth2 in the example figure below) and the gateway
138
+ device (represented as eth0) in your switch/router.
139
+
140
+ ::
141
+ fastpath bypass
142
+ .-------------------------.
143
+ / \
144
+ | IP forwarding |
145
+ | / \ \/
146
+ | br0 eth0 ..... eth0
147
+ . / \ *host B*
148
+ -> eth1 eth2
149
+ . *switch/router*
150
+ .
151
+ .
152
+ eth0
153
+ *host A*
154
+
155
+ The flowtable infrastructure also supports for bridge VLAN filtering actions
156
+ such as PVID and untagged. You can also stack a classic VLAN device on top of
157
+ your bridge port.
158
+
159
+ If you would like that your flowtable defines a fastpath between your bridge
160
+ ports and your IP forwarding path, you have to add your bridge ports (as
161
+ represented by the real netdevice) to your flowtable definition.
162
+
163
+ Counters
164
+ --------
165
+
166
+ The flowtable can synchronize packet and byte counters with the existing
167
+ connection tracking entry by specifying the counter statement in your flowtable
168
+ definition, e.g.
169
+
170
+ ::
171
+ table inet x {
172
+ flowtable f {
173
+ hook ingress priority 0; devices = { eth0, eth1 };
174
+ counter
175
+ }
176
+ ...
177
+ }
178
+
179
+ Counter support is available since Linux kernel 5.7.
180
+
181
+ Hardware offload
182
+ ----------------
183
+
184
+ If your network device provides hardware offload support, you can turn it on by
185
+ means of the 'offload' flag in your flowtable definition, e.g.
186
+
187
+ ::
188
+ table inet x {
189
+ flowtable f {
190
+ hook ingress priority 0; devices = { eth0, eth1 };
191
+ flags offload;
192
+ }
193
+ ...
194
+ }
195
+
196
+ There is a workqueue that adds the flows to the hardware. Note that a few
197
+ packets might still run over the flowtable software path until the workqueue has
198
+ a chance to offload the flow to the network device.
199
+
200
+ You can identify hardware offloaded flows through the [HW_OFFLOAD] tag when
201
+ listing your connection tracking table. Please, note that the [OFFLOAD] tag
202
+ refers to the software offload mode, so there is a distinction between [OFFLOAD]
203
+ which refers to the software flowtable fastpath and [HW_OFFLOAD] which refers
204
+ to the hardware offload datapath being used by the flow.
205
+
206
+ The flowtable hardware offload infrastructure also supports for the DSA
207
+ (Distributed Switch Architecture).
208
+
209
+ Limitations
210
+ -----------
211
+
212
+ The flowtable behaves like a cache. The flowtable entries might get stale if
213
+ either the destination MAC address or the egress netdevice that is used for
214
+ transmission changes.
215
+
216
+ This might be a problem if:
217
+
218
+ - You run the flowtable in software mode and you combine bridge and IP
219
+ forwarding in your setup.
220
+ - Hardware offload is enabled.
221
+
106
222
More reading
107
223
------------
108
224
0 commit comments