net: dummy: add phony ndo_setup_tc stub
Subsystems (3)
Florian Westphal
maintainerPATCH 1/1 net: dummy: add phony ndo_setup_tc stub
Allow to use dummy driver to test offload control plane code.
Unlike netdevsim, dummy is a data sink so no capabilities (e.g. u32-style matcher, vport device redirects, PPPoE header push/pop etc). have to be implemented.
Tag the offload callback to permit error injection to test rollback/abort code in nf_tables.
At this time, nf_tables has an upfront check for offload capabilities to avoid exposure of offload code paths on machines that lack capable hardware. With this patch, dummy can always "offload" which exposes this functionality. Given real hardware will normally live in the initial namespace, restrict the offload to initial user ns instead.
--- drivers/net/dummy.c | 10 ++++++++++ net/netfilter/nf_tables_offload.c | 3 +++ 2 files changed, 13 insertions(+)
drivers/net/dummy.c +10 -0
@@ -85,6 +85,15 @@ static int dummy_change_carrier(struct net_device *dev, bool new_carrier)return 0 ; } +static int dummy_setup_tc (struct net_device *dev,enum tc_setup_type type,void *type_data) +{ +if (dev_net (dev)->user_ns != &init_user_ns) +return -EOPNOTSUPP ; + +return 0 ; +} +ALLOW_ERROR_INJECTION (dummy_setup_tc,ERRNO ); +static const struct net_device_ops dummy_netdev_ops = { .ndo_init = dummy_dev_init, .ndo_start_xmit = dummy_xmit,
@@ -93,6 +102,7 @@ static const struct net_device_ops dummy_netdev_ops = { .ndo_set_mac_address = eth_mac_addr, .ndo_get_stats64 = dummy_get_stats64, .ndo_change_carrier = dummy_change_carrier, + .ndo_setup_tc = dummy_setup_tc, };static const struct ethtool_ops dummy_ethtool_ops = {
net/netfilter/nf_tables_offload.c +3 -0
@@ -234,6 +234,9 @@ bool nft_chain_offload_support(const struct nft_base_chain *basechain)return false; dev = ops->dev; +if (dev_net (dev)->user_ns != &init_user_ns) +return false; +if (!dev->netdev_ops->ndo_setup_tc && !flow_indr_dev_exists ())return false;
Signature · 1 line
2.53.0
Jakub Kicinski
maintainerQuoted 3 lines · On Tue, 9 Jun 2026 16:28:09 +0200 Florian Westphal wrote:
Unlike netdevsim, dummy is a data sink so no capabilities (e.g. u32-style matcher, vport device redirects, PPPoE header push/pop etc). have to be implemented.
If no "peer" is configured netdevsim is also a data sink.
We added netdevsim because dummy and veth started accumulating "features" which were clearly just for test harnesses. Would be great if we could stay the course and put whatever changes you need in netdevsim, even if it requires some hacks.
Is there anything fundamentally blocking the use of netdevsim? Or is it just convenience (since netdevsim is a bit of a PITA to create and establish the name of)?
Florian Westphal
maintainerQuoted 6 lines · Jakub Kicinski
Quoted 3 lines · On Tue, 9 Jun 2026 16:28:09 +0200 Florian Westphal wrote:
Unlike netdevsim, dummy is a data sink so no capabilities (e.g. u32-style matcher, vport device redirects, PPPoE header push/pop etc). have to be implemented.
If no "peer" is configured netdevsim is also a data sink.
Yes, but you can configure peers. And then this fake offload stub is a liar.
I would expect that offloads for netdevsim actually work, i.e. that a shaper shapes, that ets offload does delay packets and in case of flowtable that it will move skbs from one vport to another (if that was requested).
Quoted 4 lines
We added netdevsim because dummy and veth started accumulating "features" which were clearly just for test harnesses. Would be great if we could stay the course and put whatever changes you need in netdevsim, even if it requires some hacks.
Is a lot more work. I don't have time ATM to implement a u32-style packet matcher or a fake software flowtable.
Quoted 3 lines
Is there anything fundamentally blocking the use of netdevsim? Or is it just convenience (since netdevsim is a bit of a PITA to create and establish the name of)?
I played with netdevsim, aside from the above (i.e., I don't expect netdevsim to say 'offloaded' and then ignore all the offloaded commands...) the worst part is the naming and the behaviour when creating new devices while in a network namespace. Test is spawned via 'unshare -n' -- I did not find a way to really extract the new device name reliably except via 'ip link'.
I think thats solveable, so yes, I could make netdevsim lie instead.
But I don't think its the right thing to do.
If you disagree and think that this is fine I can retarget this to netdevsim, no problem.
Jakub Kicinski
maintainerQuoted 16 lines · On Wed, 10 Jun 2026 00:25:30 +0200 Florian Westphal wrote:
Quoted 6 lines · Jakub Kicinski
Quoted 3 lines · On Tue, 9 Jun 2026 16:28:09 +0200 Florian Westphal wrote:
Unlike netdevsim, dummy is a data sink so no capabilities (e.g. u32-style matcher, vport device redirects, PPPoE header push/pop etc). have to be implemented.
If no "peer" is configured netdevsim is also a data sink.
Yes, but you can configure peers. And then this fake offload stub is a liar.
I would expect that offloads for netdevsim actually work, i.e. that a shaper shapes, that ets offload does delay packets and in case of flowtable that it will move skbs from one vport to another (if that was requested).
Quoted 7 lines
Quoted 4 lines
We added netdevsim because dummy and veth started accumulating "features" which were clearly just for test harnesses. Would be great if we could stay the course and put whatever changes you need in netdevsim, even if it requires some hacks.
Is a lot more work. I don't have time ATM to implement a u32-style packet matcher or a fake software flowtable.
There are no real requirements on how netdevsim behaves. The only requirement is that there's an in-tree test that uses whatever functionality is being added. So you can implement the features to whatever depth you need for your current testing.
Quoted 10 lines
Quoted 3 lines
Is there anything fundamentally blocking the use of netdevsim? Or is it just convenience (since netdevsim is a bit of a PITA to create and establish the name of)?
I played with netdevsim, aside from the above (i.e., I don't expect netdevsim to say 'offloaded' and then ignore all the offloaded commands...) the worst part is the naming and the behaviour when creating new devices while in a network namespace. Test is spawned via 'unshare -n' -- I did not find a way to really extract the new device name reliably except via 'ip link'.
Yes :( we have some helpers in tools/testing/selftests/drivers/net/netdevsim/ethtool-common.sh among other places but libraries are a PITA in ksft as well.
Quoted 6 lines
I think thats solveable, so yes, I could make netdevsim lie instead.
But I don't think its the right thing to do.
If you disagree and think that this is fine I can retarget this to netdevsim, no problem.
Yes, I'd prefer netdevsim. If nothing else it lets us discard "security reports" by saying that nobody should have netdevsim loaded on a production system.
Pablo Neira Ayuso
maintainernet/netfilter/nf_tables_offload.c bool nft_chain_offload_support(const struct nft_base_chain *basechain) · line 238
Quoted 10 lines · Florian Westphal
net/netfilter/nf_tables_offload.c +2
-0@@ -234,6 +234,9 @@ bool nft_chain_offload_support(const struct nft_base_chain *basechain)return false; dev = ops->dev; +if (dev_net (dev)->user_ns != &init_user_ns) +return false;
I have no idea how hardware offload can be used away from init_net_ns (not even init_user_ns). For most drivers, this exposes the same hardware offload capabilities for all netns, so they can interfer each?
@Jakub: Did you mention any driver that already support netns? Otherwise, maybe it is worth to restrict driver which do not explicit opt-in to netns support?
Thanks.
Quoted 8 lines
net/netfilter/nf_tables_offload.c +1
-0+if (!dev->netdev_ops->ndo_setup_tc && !flow_indr_dev_exists ())return false;Signature · 1 line
2.53.0
Jakub Kicinski
maintainerQuoted 17 lines · On Wed, 10 Jun 2026 00:56:24 +0200 Pablo Neira Ayuso wrote:
net/netfilter/nf_tables_offload.c bool nft_chain_offload_support(const struct nft_base_chain *basechain) · line 238
Quoted 10 lines · Florian Westphal
net/netfilter/nf_tables_offload.c +2
-0@@ -234,6 +234,9 @@ bool nft_chain_offload_support(const struct nft_base_chain *basechain)return false; dev = ops->dev; +if (dev_net (dev)->user_ns != &init_user_ns) +return false;I have no idea how hardware offload can be used away from
init_net_ns(not eveninit_user_ns). For most drivers, this exposes the same hardware offload capabilities for all netns, so they can interfer each?
Quoted 3 lines
@Jakub: Did you mention any driver that already support netns? Otherwise, maybe it is worth to restrict driver which do not explicit opt-in to netns support?
IDK if any SW driver can do it, I guess that's the risk here.
For HW drivers it doesn't matter which netns they are in, offload should just work. But of course malicious users can't conjure up HW devices, admin has to explicitly move the device into a netns. Which is an explicit "permission grant".
The offload itself should be inherently netns aware since it should not cross netns boundaries?