netdevsim: add fake FT/CLS_FLOWER offload
Subsystems (5)
Florian Westphal
maintainercover netdevsim: add fake FT/CLS_FLOWER offload
1) Enable nf_tables offload control plane testing in netdevsim. Tag existing offload fn to allow error injection for testing rollback and abort logic.
2) Add nft_offload selftest to exercise the control plane and error unwind via fault injection.
Florian Westphal (2):
netdevsim: tc: allow to test nf_tables offload control plane code
selftests: netfilter: add phony nft_offload test
drivers/net/netdevsim/tc.c | 18 ++- .../testing/selftests/net/netfilter/Makefile | 1 + tools/testing/selftests/net/netfilter/config | 6 + .../selftests/net/netfilter/nft_offload.sh | 132 ++++++++++++++++++ 4 files changed, 156 insertions(+), 1 deletion(-) create mode 100755 tools/testing/selftests/net/netfilter/nft_offload.sh
Signature · 1 line
2.53.0
Florian Westphal
maintainerPATCH 2/2 selftests: netfilter: add phony nft_offload test
... "phony", because its not testing offloads, it tests the control plane code. Also test error unwind via fault injection framework.
For a proper test, real hardware would be required given we'd have check if 'previously handed off to hardware' offload commands are properly removed again on failure or rule flush.
--- .../testing/selftests/net/netfilter/Makefile | 1 + tools/testing/selftests/net/netfilter/config | 6 + .../selftests/net/netfilter/nft_offload.sh | 132 ++++++++++++++++++ 3 files changed, 139 insertions(+) create mode 100755 tools/testing/selftests/net/netfilter/nft_offload.sh
tools/testing/selftests/net/netfilter/Makefile +1 -0
@@ -32,6 +32,7 @@ TEST_PROGS := \ nft_meta.sh \ nft_nat.sh \ nft_nat_zones.sh \ + nft_offload.sh \ nft_queue.sh \ nft_synproxy.sh \ nft_tproxy_tcp.sh \
tools/testing/selftests/net/netfilter/config +6 -0
@@ -11,6 +11,7 @@ CONFIG_BRIDGE_NF_EBTABLES_LEGACY=m CONFIG_BRIDGE_VLAN_FILTERING=y CONFIG_CGROUP_BPF=y CONFIG_CRYPTO_SHA1=m +CONFIG_DEBUG_FS=y CONFIG_DUMMY=m CONFIG_INET_DIAG=m CONFIG_INET_ESP=m
@@ -33,9 +34,14 @@ CONFIG_IPV6_TUNNEL=m CONFIG_IP_VS=m CONFIG_IP_VS_PROTO_TCP=y CONFIG_IP_VS_RR=m +CONFIG_FAIL_FUNCTION=y +CONFIG_FAULT_INJECTION=y +CONFIG_FAULT_INJECTION_DEBUG_FS=y +CONFIG_FUNCTION_ERROR_INJECTION=y CONFIG_MACVLAN=m CONFIG_NAMESPACES=y CONFIG_NET_CLS_U32=m +CONFIG_NETDEVSIM=m CONFIG_NETFILTER=y CONFIG_NETFILTER_ADVANCED=y CONFIG_NETFILTER_NETLINK=m
tools/testing/selftests/net/netfilter/nft_offload.sh new file +132 -0
132 lines not on this page · raw message
Signature · 1 line
2.53.0
Florian Westphal
maintainerPATCH 1/2 netdevsim: tc: allow to test nf_tables offload control plane code
In reply to Florian WestphalThe actual 'offload' is phony, all commands are ignored: this is only useful to test control plane code.
Tag the existing callback to permit error injection to test rollback/abort code in nf_tables.
--- drivers/net/netdevsim/tc.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-)
drivers/net/netdevsim/tc.c +17 -1
@@ -9,7 +9,20 @@static int nsim_setup_tc_block_cb (enum tc_setup_type type,void *type_data,void *cb_priv) { -return nsim_bpf_setup_tc_block_cb (type, type_data, cb_priv); +int err =0 ; + +switch (type) { +case TC_SETUP_CLSBPF : + err =nsim_bpf_setup_tc_block_cb (type, type_data, cb_priv); +break ; +case TC_SETUP_CLSFLOWER : +break ; +default : + err = -EOPNOTSUPP ; +break ; + } + +return err; }static void nsim_taprio_stats (struct tc_taprio_qopt_stats *stats)
@@ -73,7 +86,10 @@ nsim_setup_tc(struct net_device *dev, enum tc_setup_type type, void *type_data) &nsim_block_cb_list, nsim_setup_tc_block_cb, ns, ns, true); +case TC_SETUP_FT : +return 0 ;default :return -EOPNOTSUPP ; } } +ALLOW_ERROR_INJECTION (nsim_setup_tc,ERRNO );
Signature · 1 line
2.53.0
Jakub Kicinski
maintainerRe: [PATCH net-next 2/2] selftests: netfilter: add phony nft_offload test
In reply to Florian WestphalQuoted 8 lines · On Wed, 10 Jun 2026 19:58:44 +0200 Florian Westphal wrote:
... "phony", because its not testing offloads, it tests the control plane code. Also test error unwind via fault injection framework.
For a proper test, real hardware would be required given we'd have check if 'previously handed off to hardware' offload commands are properly removed again on failure or rule flush.
Signed-off-by Florian Westphal <[email protected]>
Validation errors in tools/testing/selftests/net/netfilter/config:
Lines 36-37 invalid order, CONFIG_FAIL_FUNCTION=y should be before CONFIG_IP_VS_RR=m
Shellcheck also has some comments FWIW
Jakub Kicinski
maintainerRe: [PATCH net-next 1/2] netdevsim: tc: allow to test nf_tables offload control plane code
In reply to Florian Westphaldrivers/net/netdevsim/tc.c nsim_setup_tc(struct net_device *dev, enum tc_setup_type type, void *type_data) · line 95
Quoted 11 lines · On Wed, 10 Jun 2026 19:58:43 +0200 Florian Westphal wrote:
drivers/net/netdevsim/tc.c +3
-0@@ -73,7 +86,10 @@ nsim_setup_tc(struct net_device *dev, enum tc_setup_type type, void *type_data) &nsim_block_cb_list, nsim_setup_tc_block_cb, ns, ns, true); +case TC_SETUP_FT : +return 0 ;default :return -EOPNOTSUPP ; } } +ALLOW_ERROR_INJECTION (nsim_setup_tc,ERRNO );
As you probably seen other netdevsim offloads use explicit debugfs files to "fail operation X". Slightly easier to deal with, and netdevsim is a test harness anyway. But entirely up to you.
Florian Westphal
maintainerRe: [PATCH net-next 1/2] netdevsim: tc: allow to test nf_tables offload control plane code
Quoted 16 lines · Jakub Kicinski
drivers/net/netdevsim/tc.c nsim_setup_tc(struct net_device *dev, enum tc_setup_type type, void *type_data) · line 95
Quoted 11 lines · On Wed, 10 Jun 2026 19:58:43 +0200 Florian Westphal wrote:
drivers/net/netdevsim/tc.c +3
-0@@ -73,7 +86,10 @@ nsim_setup_tc(struct net_device *dev, enum tc_setup_type type, void *type_data) &nsim_block_cb_list, nsim_setup_tc_block_cb, ns, ns, true); +case TC_SETUP_FT : +return 0 ;default :return -EOPNOTSUPP ; } } +ALLOW_ERROR_INJECTION (nsim_setup_tc,ERRNO );As you probably seen other netdevsim offloads use explicit debugfs files to "fail operation X". Slightly easier to deal with, and netdevsim is a test harness anyway. But entirely up to you.
I'd rather not reimplement the '30% failure rate' and the 'make-it-fail' logic (allows to have restrict the error injection to selected processed), so I would prefer to give fuzzers more rope.
I'll fix up the sashiko hints in v2.