netfilter: flowtable: teardown flow reaching bridge port on fdb updates
Subsystems (3)
Pablo Neira Ayuso
maintainerPATCH 1/1 netfilter: flowtable: teardown flow reaching bridge port on fdb updates
The flowtable GC already checks if dst_entries are still valid, but such check is lacking for fdb entries when the bypass reaches a bridge port. This is an issue in roaming scenarios when the bridge is used.
Eric Woudstra describes the problem:
"When the host moves to another port of the same bridge, for example a station roaming to another access point, the bridge updates its fdb entry and the flow keeps sending to the old port. Packets from the other end keep hitting the flow and refresh it, so it does not expire while the sender retransmits. A hardware offloaded flow behaves the same, and none of its packets reaches the software path."
One possibility to address this issue is to subscribe to SWITCHDEV_FDB_DEL_TO_DEVICE event notifications, however, this requires iterating over the whole flowtable whenever a fdb entry is removed.
This patch adds the infrastructure to check if the fdb entry is stale, so the flowtable GC can collect tear it down to set up the flowtable bypass again with a fresh fdb entry.
---
+Cc'ing bridge maintainer, since this adds a new file to net/bridge.
This is an alternative to:
[PATCH nf-next v5 2/3] netfilter: flowtable: teardown direct xmit flows when the fdb entry moves
include/linux/netfilter.h | 9 +++++ include/net/netfilter/nf_flow_table.h | 4 +- net/bridge/Makefile | 2 +- net/bridge/br.c | 4 ++ net/bridge/br_nf_utils.c | 55 +++++++++++++++++++++++++++ net/bridge/br_private.h | 3 ++ net/netfilter/core.c | 3 ++ net/netfilter/nf_flow_table_core.c | 51 ++++++++++++++++++++++++- net/netfilter/nf_flow_table_path.c | 5 ++- 9 files changed, 131 insertions(+), 5 deletions(-) create mode 100644 net/bridge/br_nf_utils.c
include/linux/netfilter.h +9 -0
@@ -67,6 +67,15 @@ static inline void nf_inet_addr_mask(const union nf_inet_addr *a1,#endif } +struct net_bridge ; + +struct nf_br_utils { +bool (*fdb_valid_dst)(struct net *net,int ifindex, +const unsigned char *addr,__u16 vid); +}; + +extern struct nf_br_utils __rcu *nf_br_utils_hook; +int netfilter_init (void );struct sk_buff ;
include/net/netfilter/nf_flow_table.h +3 -1
@@ -152,6 +152,7 @@ struct flow_offload_tuple { xmit_type:3, encap_num:2, needs_gso_segment:1, + bridge_path:1, tun_num:2, in_vlan_ingress:2;u16 mtu;
@@ -234,7 +235,8 @@ struct nf_flow_route {u32 hw_ifindex;u8 h_source[ETH_ALEN ];u8 h_dest[ETH_ALEN ]; - u8 needs_gso_segment:1; + u8 needs_gso_segment:1, + bridge_path:1; } out;enum flow_offload_xmit_type xmit_type; } tuple[FLOW_OFFLOAD_DIR_MAX ];
net/bridge/Makefile +1 -1
@@ -8,7 +8,7 @@ obj-$(CONFIG_BRIDGE) += bridge.o bridge-y := br.o br_device.o br_fdb.o br_forward.o br_if.o br_input.o \ br_ioctl.o br_stp.o br_stp_bpdu.o \ br_stp_if.o br_stp_timer.o br_netlink.o \ - br_netlink_tunnel.o br_arp_nd_proxy.o + br_netlink_tunnel.o br_arp_nd_proxy.o br_nf_utils.o bridge-$(CONFIG_SYSFS) += br_sysfs_if.o br_sysfs_br.o
net/bridge/br.c +4 -0
@@ -446,6 +446,8 @@ static int __init br_init(void)if (err) goto err_out2; +br_nf_utils_init (); + err =register_netdevice_notifier (&br_device_notifier);if (err) goto err_out3;
@@ -479,6 +481,7 @@ static int __init br_init(void) err_out4:unregister_netdevice_notifier (&br_device_notifier); err_out3: +br_nf_utils_fini ();br_nf_core_fini (); err_out2:unregister_pernet_subsys (&br_net_ops);
@@ -501,6 +504,7 @@ static void __exit br_deinit(void)rcu_barrier ();/* Wait for completion of call_rcu()'s */ +br_nf_utils_fini ();br_nf_core_fini ();br_fdb_fini (); }
net/bridge/br_nf_utils.c new file +55 -0
55 lines not on this page · raw message
net/bridge/br_private.h +3 -0
@@ -2013,6 +2013,9 @@ struct nf_br_ops { };extern const struct nf_br_ops __rcu *nf_br_ops; +void br_nf_utils_init (void ); +void br_nf_utils_fini (void ); +/* br_netfilter.c */ #if IS_ENABLED (CONFIG_BRIDGE_NETFILTER )int br_nf_core_init (void );
net/netfilter/core.c +3 -0
@@ -798,6 +798,9 @@ static struct pernet_operations netfilter_net_ops = { .exit = netfilter_net_exit, }; +struct nf_br_utils __rcu *nf_br_utils_hook; +EXPORT_SYMBOL_GPL (nf_br_utils_hook); +int __init netfilter_init (void ) {int ret;
net/netfilter/nf_flow_table_core.c +49 -2
69 lines not on this page · raw message
net/netfilter/nf_flow_table_path.c +4 -1
@@ -95,7 +95,8 @@ struct nft_forward_info {u8 ingress_vlans;u8 h_source[ETH_ALEN ];u8 h_dest[ETH_ALEN ]; -bool needs_gso_segment; + u8 needs_gso_segment:1, + bridge_path:1;enum flow_offload_xmit_type xmit_type; };
@@ -183,6 +184,7 @@ static int nft_dev_path_info(struct net_device_path_stack *stack,case DEV_PATH_BR_VLAN_KEEP :break ; } + info->bridge_path =1 ; info->xmit_type =FLOW_OFFLOAD_XMIT_DIRECT ;break ;default :
@@ -260,6 +262,7 @@ static int nft_dev_forward_path(const struct nft_pktinfo *pkt,if (info.xmit_type ==FLOW_OFFLOAD_XMIT_DIRECT ) {memcpy (route->tuple[dir].out.h_source, info.h_source,ETH_ALEN );memcpy (route->tuple[dir].out.h_dest, info.h_dest,ETH_ALEN ); + route->tuple[dir].out.bridge_path = info.bridge_path; route->tuple[dir].xmit_type = info.xmit_type; } route->tuple[dir].out.needs_gso_segment = info.needs_gso_segment;
Signature · 1 line
2.47.3
Hi Pablo,
First of all, thank you so much for taking on this issue.
Quoted 2 lines · Pablo Neira Ayuso
This is an alternative to:
[PATCH nf-next v5 2/3] netfilter: flowtable: teardown direct xmit flows when the fdb entry moves
There is a v6 of that series. It dropped the switchdev notifier and, like your patch, checks the fdb from the gc:
https://lore.kernel.org/netfilter-devel/[email protected]/
I ran its selftest on your patch, a few issues:
Quoted 3 lines
+ f =
br_fdb_find_rcu(br, addr, vid);
+ if (!f)
+ goto out;
Offloaded packets do not refresh the fdb entry, so the flow is torn down every time the entry ages out. The "age" case in the v6 selftest fails with this.
Quoted 1 line
+ valid = br_utils->fdb_valid_dst(net,
this_tuple->out.ifidx,
out.ifidx is the lower device when the bridge port is a vlan device, so this is never valid. And the vid from encap[0] is 0 on a vlan_filtering bridge with untagged ports. Both cases tear the flow down on every gc run, 9 times in 10 seconds here.
Quoted 1 line
+ dst =
READ_ONCE(f->dst);
This does not build on nf-next after a39c339fd6c5, f->dst is a struct net_bridge_dst now. br_nf_utils.o also fails to link with CONFIG_NETFILTER=n.
Your version is smaller in the tuple and cheaper in the gc, though. I can send a v7 that takes the fdb lookup from yours and keeps the fixes above, if that works for you.
Julius
Am Mi., 14. Okt. 2026 um 21:03 Uhr schrieb Pablo Neira Ayuso <[email protected]>:
Quoted 325 lines
The flowtable GC already checks if
dst_entriesare still valid, but such check is lacking for fdb entries when the bypass reaches a bridge port. This is an issue in roaming scenarios when the bridge is used.Eric Woudstra describes the problem:
"When the host moves to another port of the same bridge, for example a station roaming to another access point, the bridge updates its fdb entry and the flow keeps sending to the old port. Packets from the other end keep hitting the flow and refresh it, so it does not expire while the sender retransmits. A hardware offloaded flow behaves the same, and none of its packets reaches the software path."
One possibility to address this issue is to subscribe to
SWITCHDEV_FDB_DEL_TO_DEVICEevent notifications, however, this requires iterating over the whole flowtable whenever a fdb entry is removed.This patch adds the infrastructure to check if the fdb entry is stale, so the flowtable GC can collect tear it down to set up the flowtable bypass again with a fresh fdb entry.
Reported-by Eric Woudstra <[email protected]>Reported-by Julius Bairaktaris <[email protected]>Signed-off-by Pablo Neira Ayuso <[email protected]>---
+Cc'ing bridge maintainer, since this adds a new file to net/bridge.This is an alternative to:
[PATCH nf-next v5 2/3] netfilter: flowtable: teardown direct xmit flows when the fdb entry movesinclude/linux/netfilter.h | 9 +++++ include/net/netfilter/nf_flow_table.h | 4 +- net/bridge/Makefile | 2 +- net/bridge/br.c | 4 ++ net/bridge/br_nf_utils.c | 55 +++++++++++++++++++++++++++ net/bridge/br_private.h | 3 ++ net/netfilter/core.c | 3 ++ net/netfilter/nf_flow_table_core.c | 51 ++++++++++++++++++++++++- net/netfilter/nf_flow_table_path.c | 5 ++- 9 files changed, 131 insertions(+), 5 deletions(-) create mode 100644 net/bridge/br_nf_utils.cinclude/linux/netfilter.h +9
-0@@ -67,6 +67,15 @@ static inline void nf_inet_addr_mask(const union nf_inet_addr *a1,#endif } +struct net_bridge ; + +struct nf_br_utils { +bool (*fdb_valid_dst)(struct net *net,int ifindex, +const unsigned char *addr,__u16 vid); +}; + +extern struct nf_br_utils __rcu *nf_br_utils_hook; +int netfilter_init (void );struct sk_buff ;include/net/netfilter/nf_flow_table.h +3
-1@@ -152,6 +152,7 @@ struct flow_offload_tuple { xmit_type:3, encap_num:2, needs_gso_segment:1, + bridge_path:1, tun_num:2, in_vlan_ingress:2;u16 mtu;@@ -234,7 +235,8 @@ struct nf_flow_route {u32 hw_ifindex;u8 h_source[ETH_ALEN ];u8 h_dest[ETH_ALEN ]; - u8 needs_gso_segment:1; + u8 needs_gso_segment:1, + bridge_path:1; } out;enum flow_offload_xmit_type xmit_type; } tuple[FLOW_OFFLOAD_DIR_MAX ];net/bridge/Makefile +1
-1@@ -8,7 +8,7 @@ obj-$(CONFIG_BRIDGE) += bridge.o bridge-y := br.o br_device.o br_fdb.o br_forward.o br_if.o br_input.o \ br_ioctl.o br_stp.o br_stp_bpdu.o \ br_stp_if.o br_stp_timer.o br_netlink.o \ - br_netlink_tunnel.o br_arp_nd_proxy.o + br_netlink_tunnel.o br_arp_nd_proxy.o br_nf_utils.o bridge-$(CONFIG_SYSFS) += br_sysfs_if.o br_sysfs_br.onet/bridge/br.c +4
-0@@ -446,6 +446,8 @@ static int __init br_init(void)if (err) goto err_out2; +br_nf_utils_init (); + err =register_netdevice_notifier (&br_device_notifier);if (err) goto err_out3;@@ -479,6 +481,7 @@ static int __init br_init(void) err_out4:unregister_netdevice_notifier (&br_device_notifier); err_out3: +br_nf_utils_fini ();br_nf_core_fini (); err_out2:unregister_pernet_subsys (&br_net_ops);@@ -501,6 +504,7 @@ static void __exit br_deinit(void)rcu_barrier ();/* Wait for completion of call_rcu()'s */ +br_nf_utils_fini ();br_nf_core_fini ();br_fdb_fini (); }net/bridge/br_nf_utils.c new file +55
-0@@ -0,0 +1,55 @@ +// SPDX-License-Identifier: GPL-2.0-only +#include <linux/module.h> +#include <linux/kernel.h> +#include <linux/netdevice.h> +#include <linux/netfilter.h> + +#include "br_private.h" + +static bool nf_br_fdb_valid_dst (struct net *net,int ifindex, +const unsigned char *addr,__u16 vid) +{ +const struct net_bridge_port *dst; +struct net_device *dev, *upper; +struct net_bridge_fdb_entry *f; +struct net_bridge *br; + +rcu_read_lock (); + dev =dev_get_by_index_rcu (net, ifindex); +if (!dev || !netif_is_bridge_port (dev)) + goto out; + + upper =netdev_master_upper_dev_get_rcu (dev); +if (!upper) + goto out; + + br =netdev_priv (upper); + + f =br_fdb_find_rcu (br, addr, vid); +if (!f) + goto out; + + dst =READ_ONCE (f->dst); +if (dst && dst->dev->ifindex == ifindex) { +rcu_read_unlock (); +return true; + } +out: +rcu_read_unlock (); + +return false; +} + +static struct nf_br_utils nf_br_utils = { + .fdb_valid_dst = nf_br_fdb_valid_dst, +}; + +void __init br_nf_utils_init (void ) +{ +RCU_INIT_POINTER (nf_br_utils_hook, &nf_br_utils); +} + +void br_nf_utils_fini (void ) +{ +rcu_assign_pointer (nf_br_utils_hook,NULL ); +}net/bridge/br_private.h +3
-0@@ -2013,6 +2013,9 @@ struct nf_br_ops { };extern const struct nf_br_ops __rcu *nf_br_ops; +void br_nf_utils_init (void ); +void br_nf_utils_fini (void ); +/* br_netfilter.c */ #if IS_ENABLED (CONFIG_BRIDGE_NETFILTER )int br_nf_core_init (void );net/netfilter/core.c +3
-0@@ -798,6 +798,9 @@ static struct pernet_operations netfilter_net_ops = { .exit = netfilter_net_exit, }; +struct nf_br_utils __rcu *nf_br_utils_hook; +EXPORT_SYMBOL_GPL (nf_br_utils_hook); +int __init netfilter_init (void ) {int ret;net/netfilter/nf_flow_table_core.c +49
-2@@ -127,6 +127,8 @@ static int flow_offload_fill_route(struct flow_offload *flow,switch (route->tuple[dir].xmit_type) {case FLOW_OFFLOAD_XMIT_DIRECT : + flow_tuple->bridge_path = route->tuple[dir].out.bridge_path; +if (route->tuple[!dir].in.num_tuns) { flow_tuple->dst_cache = dst; flow_tuple->dst_cookie =@@ -572,6 +574,51 @@ static void nf_flow_table_extend_ct_timeout(struct nf_conn *ct)nf_ct_put (ct); } +static bool nf_flow_dst_valid (struct nf_flowtable *flow_table, +struct flow_offload *flow,int dir) +{ +struct flow_offload_tuple *this_tuple = &flow->tuplehash[dir].tuple; +struct net *net =read_pnet (&flow_table->net); +struct flow_offload_tuple *other_tuple; +struct nf_br_utils *br_utils; +__u16 vid =0 ; +bool valid; + +switch (this_tuple->xmit_type) { +case FLOW_OFFLOAD_XMIT_NEIGH : + valid =nf_flow_dst_check (this_tuple); +break ; +case FLOW_OFFLOAD_XMIT_DIRECT : +if (!this_tuple->bridge_path) { + valid = true; +break ; + } + other_tuple = &flow->tuplehash[!dir].tuple; + +rcu_read_lock (); + br_utils =rcu_dereference (nf_br_utils_hook); +if (!br_utils) { +rcu_read_unlock (); + valid = true; +break ; + } + +if (other_tuple->encap[0 ].proto ==htons (ETH_P_8021Q ) || + other_tuple->encap[0 ].proto ==htons (ETH_P_8021AD )) + vid = other_tuple->encap[0 ].id; + + valid = br_utils->fdb_valid_dst (net, this_tuple->out.ifidx, + this_tuple->out.h_dest, vid); +rcu_read_unlock (); +break ; +default : + valid = true; +break ; + } + +return valid; +} +static void nf_flow_offload_gc_step (struct nf_flowtable *flow_table,struct flow_offload *flow,void *data) {@@ -584,8 +631,8 @@ static void nf_flow_offload_gc_step(struct nf_flowtable *flow_table,if (nf_flow_has_expired (flow) ||nf_ct_is_dying (flow->ct) || - !nf_flow_dst_check (&flow->tuplehash[FLOW_OFFLOAD_DIR_ORIGINAL ].tuple) || - !nf_flow_dst_check (&flow->tuplehash[FLOW_OFFLOAD_DIR_REPLY ].tuple) || + !nf_flow_dst_valid (flow_table, flow,FLOW_OFFLOAD_DIR_ORIGINAL ) || + !nf_flow_dst_valid (flow_table, flow,FLOW_OFFLOAD_DIR_REPLY ) ||nf_flow_custom_gc (flow_table, flow)) {flow_offload_teardown (flow); teardown = true;net/netfilter/nf_flow_table_path.c +4
-2@@ -95,7 +95,8 @@ struct nft_forward_info {u8 ingress_vlans;u8 h_source[ETH_ALEN ];u8 h_dest[ETH_ALEN ]; -bool needs_gso_segment; + u8 needs_gso_segment:1, + bridge_path:1;enum flow_offload_xmit_type xmit_type; };@@ -183,6 +184,7 @@ static int nft_dev_path_info(struct net_device_path_stack *stack,case DEV_PATH_BR_VLAN_KEEP :break ; } + info->bridge_path =1 ; info->xmit_type =FLOW_OFFLOAD_XMIT_DIRECT ;break ;default :@@ -260,6 +262,7 @@ static int nft_dev_forward_path(const struct nft_pktinfo *pkt,if (info.xmit_type ==FLOW_OFFLOAD_XMIT_DIRECT ) {memcpy (route->tuple[dir].out.h_source, info.h_source,ETH_ALEN );memcpy (route->tuple[dir].out.h_dest, info.h_dest,ETH_ALEN ); + route->tuple[dir].out.bridge_path = info.bridge_path; route->tuple[dir].xmit_type = info.xmit_type; } route->tuple[dir].out.needs_gso_segment = info.needs_gso_segment; --2.47.3
Pablo Neira Ayuso
maintainerOn Wed, Oct 14, 2026 at 10:00:47PM +0000, Julius Bairaktaris wrote:
[...]
Quoted 3 lines
Your version is smaller in the tuple and cheaper in the gc, though. I can send a v7 that takes the fdb lookup from yours and keeps the fixes above, if that works for you.
Please, go ahead, let's see how v7 looks like.
kernel test robot
build botkernel test robot noticed the following build errors:
Hi Pablo,
kernel test robot noticed the following build errors:
[auto build test ERROR on nf-next/main]
url: https://github.com/intel-lab-lkp/linux/commits/Pablo-Neira-Ayuso/netfilter-flowtable-teardown-flow-reaching-bridge-port-on-fdb-updates/20261014-230256 base: https://git.kernel.org/pub/scm/linux/kernel/git/netfilter/nf-next.git main patch link: https://lore.kernel.org/r/20261014210256.1573072-1-pablo%40netfilter.org patch subject: [PATCH nf-next] netfilter: flowtable: teardown flow reaching bridge port on fdb updates config: nios2-randconfig-1000-20261015 (https://download.01.org/0day-ci/archive/20261015/[email protected]/config) compiler: nios2-linux-gcc (GCC) 11.5.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20261015/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All errors (new ones prefixed by >>):
In file included from ./arch/nios2/include/generated/asm/rwonce.h:1,
from include/linux/compiler.h:369,
from include/linux/build_bug.h:5,
from include/linux/container_of.h:5, from include/linux/list.h:5,
from include/linux/module.h:12,
from net/bridge/br_nf_utils.c:2:
net/bridge/br_nf_utils.c: In function 'nf_br_fdb_valid_dst':
>> include/asm-generic/rwonce.h:48:1: error: incompatible types when assigning to type 'const struct net_bridge_port *' from type 'struct net_bridge_dst'
48 | ({ \
| ^
net/bridge/br_nf_utils.c:32:15: note: in expansion of macro 'READ_ONCE'
32 | dst = READ_ONCE(f->dst);
| ^~~~~~~~~vim +48 include/asm-generic/rwonce.h
e506ea451254ab Will Deacon 2019-10-15 46
e506ea451254ab Will Deacon 2019-10-15 47 #define READ_ONCE(x) \
e506ea451254ab Will Deacon 2019-10-15 @48 ({ \
e506ea451254ab Will Deacon 2019-10-15 49 compiletime_assert_rwonce_type(x); \
3c9184109e78ea Will Deacon 2019-10-30 50 __READ_ONCE(x); \
e506ea451254ab Will Deacon 2019-10-15 51 })e506ea451254ab Will Deacon 2019-10-15 52
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
kernel test robot
build botkernel test robot noticed the following build errors:
Hi Pablo,
kernel test robot noticed the following build errors:
[auto build test ERROR on nf-next/main]
url: https://github.com/intel-lab-lkp/linux/commits/Pablo-Neira-Ayuso/netfilter-flowtable-teardown-flow-reaching-bridge-port-on-fdb-updates/20261014-230256 base: https://git.kernel.org/pub/scm/linux/kernel/git/netfilter/nf-next.git main patch link: https://lore.kernel.org/r/20261014210256.1573072-1-pablo%40netfilter.org patch subject: [PATCH nf-next] netfilter: flowtable: teardown flow reaching bridge port on fdb updates config: hexagon-randconfig-1000-20261015 (https://download.01.org/0day-ci/archive/20261015/[email protected]/config) compiler: clang version 24.0.0git (https://github.com/llvm/llvm-project 6719b9e31d6a93099612c474eec76d9f41d0275a) reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20261015/[email protected]/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All errors (new ones prefixed by >>):
>> net/bridge/br_nf_utils.c:32:6: error: assigning to 'const struct net_bridge_port *' from incompatible type 'typeof_unqual (f->dst)' (aka 'struct net_bridge_dst')
32 | dst = READ_ONCE(f->dst);
| ^ ~~~~~~~~~~~~~~~~~1 error generated.
vim +32 net/bridge/br_nf_utils.c
8
9 static bool nf_br_fdb_valid_dst(struct net *net, int ifindex,
10 const unsigned char *addr, __u16 vid)
11 {
12 const struct net_bridge_port *dst;
13 struct net_device *dev, *upper;
14 struct net_bridge_fdb_entry *f;
15 struct net_bridge *br;
16
17 rcu_read_lock();
18 dev = dev_get_by_index_rcu(net, ifindex);
19 if (!dev || !netif_is_bridge_port(dev))
20 goto out;
21
22 upper = netdev_master_upper_dev_get_rcu(dev);
23 if (!upper)
24 goto out;
25
26 br = netdev_priv(upper);
27
28 f = br_fdb_find_rcu(br, addr, vid);
29 if (!f)
30 goto out;
31
> 32 dst = READ_ONCE(f->dst);
33 if (dst && dst->dev->ifindex == ifindex) {
34 rcu_read_unlock();
35 return true;
36 }
37 out:
38 rcu_read_unlock();
39
40 return false;
41 }
42 --
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki