Skip to contentSkip to conversation

netfilter: flowtable: remove hw flows before unbinding the flow block

PATCH New Arnau Valls 1 participant 1 message Nov 3

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 netfilter: flowtable: remove hw flows before unbinding the flow block

Since commit 13210fc63f35 ("netfilter: nf_tables: imbalance in flowtable binding"), deleting a flowtable unbinds the driver callbacks at commit time, before nf_flow_table_free() queues FLOW_CLS_DESTROY for the remaining flows. The destroy requests find an empty cb_list and the flows stay in hardware.

Conntrack then times the entries out while the hardware keeps forwarding them. Once one direction ages out of the hardware table, its packets hit the stack without a conntrack entry and get rejected. This breaks long-lived UDP flows such as WireGuard whenever the flowtable is recreated, for example on every firewall reload in OpenWrt.

Remove the device's flows on FLOW_BLOCK_UNBIND while the driver is still bound, as nf_flow_table_indr_cleanup() does for indirect blocks. The gc skips flows with pending offload work, so run one more pass and flush.

Tested on MT7981 (mtk_eth_soc PPE) with v7.4-rc1 and 6.12.74. Found and fixed with help from an AI assistant (Claude).

Fixes 13210fc63f35 ("netfilter: nf_tables: imbalance in flowtable binding")

---

Notes:
Reproducer: hw-offloaded UDP flow through NAT, then delete and recreate the flowtable in one transaction (fw4 reload). Without the patch the conntrack entry gets a timeout and the PPE entries stay bound. With it the PPE entries are removed and the flow is offloaded again within a second, no packet loss over six reloads.

Not tested: lockdep, other drivers, the indirect block path.

 net/netfilter/nf_flow_table_offload.c | 9 +++++++++
 1 file changed, 9 insertions(+)
net/netfilter/nf_flow_table_offload.c +9 -0
index 4365859220e6..68654d243bae 100644
@@ -1279,6 +1279,15 @@ int nf_flow_table_offload_setup(struct nf_flowtable *flowtable,
 	if (!nf_flowtable_hw_offload(flowtable))
 		return nf_flow_offload_xdp_setup(flowtable, dev, cmd);
 
+	/* Flush this device's hw flows while the driver is still bound. The
+	 * second gc pass catches flows skipped due to pending offload work.
+	 */
+	if (cmd == FLOW_BLOCK_UNBIND) {
+		nf_flow_table_gc_cleanup(flowtable, dev);
+		nf_flow_table_gc_run(flowtable);
+		nf_flow_table_offload_flush(flowtable);
+	}
+
 	if (dev->netdev_ops->ndo_setup_tc)
 		err = nf_flow_table_offload_cmd(&bo, flowtable, dev, cmd,
 						&extack);

base-commit: 05441d697f7f9a927264f4058cbbc6a03dfcac9d

Signature · 1 line
2.54.0