* [PATCH nf-next v11 1/3] net: bridge: fill a forward path only to a port that forwards
2026-11-21 20:55 [PATCH nf-next v11 0/3] netfilter: flowtable: tear down bridged flows on layer 2 roaming Julius Bairaktaris
@ 2026-11-21 20:55 ` Julius Bairaktaris
2026-11-21 20:55 ` [PATCH nf-next v11 2/3] netfilter: flowtable: tear down direct xmit flows when the fdb entry moves Julius Bairaktaris
2026-11-21 20:55 ` [PATCH nf-next v11 3/3] selftests: netfilter: nft_flowtable.sh: roam a host between two bridge ports Julius Bairaktaris
2 siblings, 0 replies; 5+ messages in thread
From: Julius Bairaktaris @ 2026-11-21 20:55 UTC (permalink / raw)
To: netfilter-devel
Cc: Pablo Neira Ayuso, Florian Westphal, Phil Sutter,
Nikolay Aleksandrov, Ido Schimmel, David S . Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Simon Horman, Shuah Khan,
Eric Woudstra, netdev, bridge, coreteam, linux-kselftest
br_fill_forward_path() resolves the destination port from the fdb and
checks only that the vlan exists on it. A port in STP blocking, learning
or disabled state, or an MST vlan that is not forwarding on it, still
gets a path, so the flowtable transmits straight to a port the bridge
itself does not deliver to (should_deliver()).
Add br_port_forwards(), the port and vlan part of should_deliver(), and
fill a path only to a port it accepts.
Signed-off-by: Julius Bairaktaris <julius@bairaktaris.de>
---
v11: no changes
v10: https://lore.kernel.org/netfilter-devel/20261115005555.645727-2-julius@bairaktaris.de/
net/bridge/br_device.c | 2 +-
net/bridge/br_forward.c | 19 +++++++++++++++++++
net/bridge/br_private.h | 1 +
3 files changed, 21 insertions(+), 1 deletion(-)
diff --git a/net/bridge/br_device.c b/net/bridge/br_device.c
index 0a1ce9e59a4d..f5860e88dbe9 100644
--- a/net/bridge/br_device.c
+++ b/net/bridge/br_device.c
@@ -402,7 +402,7 @@ static int br_fill_forward_path(struct net_device_path_ctx *ctx,
return -1;
dst = br_fdb_dst_port(f);
- if (!dst)
+ if (!dst || !br_port_forwards(dst, path->bridge.vlan_id))
return -1;
if (br_vlan_fill_forward_path_mode(br, dst, path))
diff --git a/net/bridge/br_forward.c b/net/bridge/br_forward.c
index 54365c6104b5..9dbe9c949558 100644
--- a/net/bridge/br_forward.c
+++ b/net/bridge/br_forward.c
@@ -31,6 +31,25 @@ static bool should_deliver_vlan(const struct br_fwd_dst *fwd,
return br_allowed_egress(nbp_vlan_group_rcu(fwd->port), skb);
}
+/* Called under RCU. Whether @p forwards a frame in @vid, 0 without vlan
+ * filtering, as should_deliver() decides for a frame filtered at input.
+ */
+bool br_port_forwards(const struct net_bridge_port *p, u16 vid)
+{
+ struct net_bridge_vlan *v;
+
+ if (!br_mst_is_enabled(p) && p->state != BR_STATE_FORWARDING)
+ return false;
+
+ if (!br_opt_get(p->br, BROPT_VLAN_ENABLED))
+ return !vid;
+
+ v = br_vlan_find(nbp_vlan_group_rcu(p), vid);
+
+ return v && br_vlan_should_use(v) &&
+ br_vlan_state_allowed(br_vlan_get_state(v), false);
+}
+
/* Don't forward packets to originating port or forwarding disabled */
static __always_inline bool should_deliver(const struct br_fwd_dst *fwd,
const struct sk_buff *skb)
diff --git a/net/bridge/br_private.h b/net/bridge/br_private.h
index 014d0b8db8c7..2c73d2549eae 100644
--- a/net/bridge/br_private.h
+++ b/net/bridge/br_private.h
@@ -1048,6 +1048,7 @@ int br_dev_queue_push_xmit(struct net *net, struct sock *sk, struct sk_buff *skb
void br_forward(struct net_bridge_dst dst, struct sk_buff *skb,
bool local_rcv, bool local_orig);
int br_forward_finish(struct net *net, struct sock *sk, struct sk_buff *skb);
+bool br_port_forwards(const struct net_bridge_port *p, u16 vid);
void br_flood(struct net_bridge *br, struct net_bridge_vlan *v,
struct sk_buff *skb, enum br_pkt_type pkt_type,
bool local_rcv, bool local_orig);
--
2.53.0
^ permalink raw reply related [flat|nested] 5+ messages in thread* [PATCH nf-next v11 2/3] netfilter: flowtable: tear down direct xmit flows when the fdb entry moves
2026-11-21 20:55 [PATCH nf-next v11 0/3] netfilter: flowtable: tear down bridged flows on layer 2 roaming Julius Bairaktaris
2026-11-21 20:55 ` [PATCH nf-next v11 1/3] net: bridge: fill a forward path only to a port that forwards Julius Bairaktaris
@ 2026-11-21 20:55 ` Julius Bairaktaris
2026-11-21 21:10 ` Pablo Neira Ayuso
2026-11-21 20:55 ` [PATCH nf-next v11 3/3] selftests: netfilter: nft_flowtable.sh: roam a host between two bridge ports Julius Bairaktaris
2 siblings, 1 reply; 5+ messages in thread
From: Julius Bairaktaris @ 2026-11-21 20:55 UTC (permalink / raw)
To: netfilter-devel
Cc: Pablo Neira Ayuso, Florian Westphal, Phil Sutter,
Nikolay Aleksandrov, Ido Schimmel, David S . Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Simon Horman, Shuah Khan,
Eric Woudstra, netdev, bridge, coreteam, linux-kselftest
From: Pablo Neira Ayuso <pablo@netfilter.org>
A direct xmit flow that reaches a bridge port keeps sending to that port
when the host moves to another port of the bridge, and packets from the
other side keep the flow from timing out.
The gc now checks the fdb entry after nf_flow_dst_check_gc(), through
nf_br_utils_hook, and tears the flow down when the entry points to
another port. An entry that aged out does not tear it down, because
offloaded packets do not refresh it.
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.
The bridge port is found from out.ifidx through the vlan devices that
the forward path has below the port. The flow keeps the vid the forward
path looked the fdb entry up in: a vlan that leaves the port untagged
is in neither encap stack. struct flow_offload grows from 296 to 312
bytes on x86_64; its slab cache is cacheline aligned, so an object takes
320 bytes either way.
The flow is also torn down when the port no longer forwards in that
vid, where the bridge would no longer deliver either: the port left the
forwarding state, the vlan left the port, or vlan filtering was turned
on or off. With two bridges on the path, at most two fit in a forward
path, the gc goes up from the inner bridge through the vlan devices
between them to the port of the outer one and checks its entry as well.
Neigh xmit flows need no fdb check: a forward path that crosses a bridge
always makes the flow direct xmit, and a failed walk is not offloaded.
Reported-by: Eric Woudstra <ericwouds@gmail.com>
Link: https://lore.kernel.org/netfilter-devel/20250925182623.114045-1-ericwouds@gmail.com/
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
[julius@bairaktaris.de: find the bridge port below the vlan devices of the
path, keep the vid of the fdb lookup, keep a flow whose entry aged out,
check that the port forwards the vid, check both bridges of a stacked
path, follow struct net_bridge_dst, build br_nf_utils.o only with the
flowtable]
Link: https://lore.kernel.org/netfilter-devel/20261014210256.1573072-1-pablo@netfilter.org/
Signed-off-by: Julius Bairaktaris <julius@bairaktaris.de>
---
v11: rebased onto Pablo's xmit series: the gc checks the fdb entry
after his nf_flow_dst_check_gc(), which replaces nf_flow_dst_check()
there, and his patch now sets out.h_dest for every xmit type
v10: https://lore.kernel.org/netfilter-devel/20261115005555.645727-3-julius@bairaktaris.de/
include/linux/netfilter.h | 7 +++
include/net/netfilter/nf_flow_table.h | 22 ++++++++-
net/bridge/Makefile | 2 +
net/bridge/br.c | 2 +
net/bridge/br_nf_utils.c | 35 ++++++++++++++
net/bridge/br_private.h | 13 +++++
net/netfilter/core.c | 3 ++
net/netfilter/nf_flow_table_core.c | 68 ++++++++++++++++++++++++++-
net/netfilter/nf_flow_table_path.c | 29 +++++++++++-
9 files changed, 176 insertions(+), 5 deletions(-)
create mode 100644 net/bridge/br_nf_utils.c
diff --git a/include/linux/netfilter.h b/include/linux/netfilter.h
index e99afc1414cd..be85d8f68b45 100644
--- a/include/linux/netfilter.h
+++ b/include/linux/netfilter.h
@@ -67,6 +67,13 @@ static inline void nf_inet_addr_mask(const union nf_inet_addr *a1,
#endif
}
+struct nf_br_utils {
+ bool (*fdb_valid_dst)(const struct net_device *dev,
+ const unsigned char *addr, u16 vid);
+};
+
+extern const struct nf_br_utils __rcu *nf_br_utils_hook;
+
int netfilter_init(void);
struct sk_buff;
diff --git a/include/net/netfilter/nf_flow_table.h b/include/net/netfilter/nf_flow_table.h
index 143bcfce3678..206296483fe1 100644
--- a/include/net/netfilter/nf_flow_table.h
+++ b/include/net/netfilter/nf_flow_table.h
@@ -121,6 +121,18 @@ struct flow_offload_tunnel {
u8 encap_proto;
};
+/* The outer of two bridges on the path: its vid, and how to reach its port
+ * from the inner bridge.
+ */
+struct flow_offload_br_outer {
+ u16 vid;
+ u8 present:1,
+ link_vlans:2,
+ link_untag:1,
+ link_8021ad:1,
+ inner_tag:1;
+};
+
struct flow_offload_tuple {
union {
struct in_addr src_v4;
@@ -153,6 +165,8 @@ struct flow_offload_tuple {
xmit_type:3,
encap_num:2,
needs_gso_segment:1,
+ bridge_path:1,
+ port_vlans:2,
tun_num:2,
in_vlan_ingress:2;
u16 mtu;
@@ -164,6 +178,8 @@ struct flow_offload_tuple {
u32 ifidx;
u8 h_source[ETH_ALEN];
u8 h_dest[ETH_ALEN];
+ u16 bridge_vid;
+ struct flow_offload_br_outer br_outer;
} out;
struct {
u32 iifidx;
@@ -232,7 +248,11 @@ struct nf_flow_route {
u32 hw_ifindex;
u8 h_source[ETH_ALEN];
u8 h_dest[ETH_ALEN];
- u8 needs_gso_segment:1;
+ u16 bridge_vid;
+ struct flow_offload_br_outer br_outer;
+ u8 needs_gso_segment:1,
+ bridge_path:1,
+ port_vlans:2;
} out;
enum flow_offload_xmit_type xmit_type;
} tuple[FLOW_OFFLOAD_DIR_MAX];
diff --git a/net/bridge/Makefile b/net/bridge/Makefile
index 1203dc19e15c..fc53c332246d 100644
--- a/net/bridge/Makefile
+++ b/net/bridge/Makefile
@@ -14,6 +14,8 @@ bridge-$(CONFIG_SYSFS) += br_sysfs_if.o br_sysfs_br.o
bridge-$(subst m,y,$(CONFIG_BRIDGE_NETFILTER)) += br_nf_core.o
+bridge-$(subst m,y,$(CONFIG_NF_FLOW_TABLE)) += br_nf_utils.o
+
br_netfilter-y := br_netfilter_hooks.o
br_netfilter-$(subst m,y,$(CONFIG_IPV6)) += br_netfilter_ipv6.o
obj-$(CONFIG_BRIDGE_NETFILTER) += br_netfilter.o
diff --git a/net/bridge/br.c b/net/bridge/br.c
index d9a39ff98868..c0618ef6dac5 100644
--- a/net/bridge/br.c
+++ b/net/bridge/br.c
@@ -458,6 +458,7 @@ static int __init br_init(void)
goto err_out6;
brioctl_set(br_ioctl_stub);
+ br_nf_utils_init();
#if IS_MODULE(CONFIG_BRIDGE_NETFILTER)
pr_info("bridge: filtering via arp/ip/ip6tables is no longer available "
@@ -486,6 +487,7 @@ static int __init br_init(void)
static void __exit br_deinit(void)
{
+ br_nf_utils_fini();
stp_proto_unregister(&br_stp_proto);
br_netlink_fini();
unregister_switchdev_blocking_notifier(&br_switchdev_blocking_notifier);
diff --git a/net/bridge/br_nf_utils.c b/net/bridge/br_nf_utils.c
new file mode 100644
index 000000000000..c9a7c94d301c
--- /dev/null
+++ b/net/bridge/br_nf_utils.c
@@ -0,0 +1,35 @@
+// SPDX-License-Identifier: GPL-2.0-only
+#include <linux/netdevice.h>
+#include <linux/netfilter.h>
+
+#include "br_private.h"
+
+static bool nf_br_fdb_valid_dst(const struct net_device *dev,
+ const unsigned char *addr, u16 vid)
+{
+ const struct net_bridge_fdb_entry *f;
+ const struct net_bridge_port *p;
+
+ p = br_port_get_check_rcu(dev);
+ if (!p || !br_port_forwards(p, vid))
+ return false;
+
+ /* Offloaded packets do not refresh the entry, it can age out. */
+ f = br_fdb_find_rcu(p->br, addr, vid);
+
+ return !f || br_fdb_dst_port(f) == p;
+}
+
+static const struct nf_br_utils nf_br_utils = {
+ .fdb_valid_dst = nf_br_fdb_valid_dst,
+};
+
+void br_nf_utils_init(void)
+{
+ rcu_assign_pointer(nf_br_utils_hook, &nf_br_utils);
+}
+
+void br_nf_utils_fini(void)
+{
+ RCU_INIT_POINTER(nf_br_utils_hook, NULL);
+}
diff --git a/net/bridge/br_private.h b/net/bridge/br_private.h
index 2c73d2549eae..6a6685e93b49 100644
--- a/net/bridge/br_private.h
+++ b/net/bridge/br_private.h
@@ -2166,6 +2166,19 @@ struct nf_br_ops {
};
extern const struct nf_br_ops __rcu *nf_br_ops;
+#if IS_ENABLED(CONFIG_NF_FLOW_TABLE)
+void br_nf_utils_init(void);
+void br_nf_utils_fini(void);
+#else
+static inline void br_nf_utils_init(void)
+{
+}
+
+static inline void br_nf_utils_fini(void)
+{
+}
+#endif
+
/* br_netfilter.c */
#if IS_ENABLED(CONFIG_BRIDGE_NETFILTER)
int br_nf_core_init(void);
diff --git a/net/netfilter/core.c b/net/netfilter/core.c
index 44c856c1e621..92e9852c80c0 100644
--- a/net/netfilter/core.c
+++ b/net/netfilter/core.c
@@ -814,6 +814,9 @@ static struct pernet_operations netfilter_net_ops = {
.exit = netfilter_net_exit,
};
+const struct nf_br_utils __rcu *nf_br_utils_hook;
+EXPORT_SYMBOL_GPL(nf_br_utils_hook);
+
int __init netfilter_init(void)
{
int ret;
diff --git a/net/netfilter/nf_flow_table_core.c b/net/netfilter/nf_flow_table_core.c
index 283a6fc215e5..64d0b3a916dd 100644
--- a/net/netfilter/nf_flow_table_core.c
+++ b/net/netfilter/nf_flow_table_core.c
@@ -6,6 +6,7 @@
#include <linux/rhashtable.h>
#include <linux/netdevice.h>
#include <linux/etherdevice.h>
+#include <linux/if_vlan.h>
#include <net/ip.h>
#include <net/ip6_route.h>
#include <net/netfilter/nf_tables.h>
@@ -140,6 +141,10 @@ static int flow_offload_fill_route(struct flow_offload *flow,
memcpy(flow_tuple->out.h_source, route->tuple[dir].out.h_source,
ETH_ALEN);
flow_tuple->out.ifidx = route->tuple[dir].out.ifindex;
+ flow_tuple->bridge_path = route->tuple[dir].out.bridge_path;
+ flow_tuple->out.bridge_vid = route->tuple[dir].out.bridge_vid;
+ flow_tuple->out.br_outer = route->tuple[dir].out.br_outer;
+ flow_tuple->port_vlans = route->tuple[dir].out.port_vlans;
break;
case FLOW_OFFLOAD_XMIT_NEIGH:
memcpy(flow_tuple->out.h_dest, route->tuple[dir].out.h_dest,
@@ -636,6 +641,65 @@ static inline bool nf_flow_dst_check_gc(struct flow_offload *flow, int dir)
return ret;
}
+static bool nf_flow_dst_valid(struct nf_flowtable *flow_table,
+ struct flow_offload *flow, int dir)
+{
+ struct flow_offload_tuple *other = &flow->tuplehash[!dir].tuple;
+ struct flow_offload_tuple *tuple = &flow->tuplehash[dir].tuple;
+ struct net *net = read_pnet(&flow_table->net);
+ const struct flow_offload_br_outer *outer = &tuple->out.br_outer;
+ const struct nf_br_utils *br_utils;
+ struct net_device *dev;
+ bool valid = true;
+ __be16 proto;
+ int i, n;
+
+ if (!nf_flow_dst_check_gc(flow, dir))
+ return false;
+
+ if (!tuple->bridge_path)
+ return true;
+
+ rcu_read_lock();
+ br_utils = rcu_dereference(nf_br_utils_hook);
+ if (!br_utils)
+ goto out;
+
+ dev = dev_get_by_index_rcu(net, tuple->out.ifidx);
+ for (i = 0; dev && i < tuple->port_vlans; i++)
+ dev = __vlan_find_dev_deep_rcu(dev, other->encap[i].proto,
+ other->encap[i].id);
+
+ valid = dev && br_utils->fdb_valid_dst(dev, tuple->out.h_dest,
+ tuple->out.bridge_vid);
+ if (!valid || !outer->present)
+ goto out;
+
+ /* Up from the inner bridge through the vlan devices to the port of
+ * the outer one. A link vlan the inner bridge untags is not in the
+ * encap stack, its vid is the inner bridge vid.
+ */
+ dev = netdev_master_upper_dev_get_rcu(dev);
+ if (dev && outer->link_untag) {
+ proto = outer->link_8021ad ? htons(ETH_P_8021AD) :
+ htons(ETH_P_8021Q);
+ dev = __vlan_find_dev_deep_rcu(dev, proto,
+ tuple->out.bridge_vid);
+ }
+ i += outer->inner_tag;
+ n = i + outer->link_vlans - outer->link_untag;
+ for (; dev && i < n; i++)
+ dev = __vlan_find_dev_deep_rcu(dev, other->encap[i].proto,
+ other->encap[i].id);
+
+ valid = dev && br_utils->fdb_valid_dst(dev, tuple->out.h_dest,
+ outer->vid);
+out:
+ rcu_read_unlock();
+
+ return valid;
+}
+
static void nf_flow_offload_gc_step(struct nf_flowtable *flow_table,
struct flow_offload *flow, void *data)
{
@@ -648,8 +712,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_gc(flow, FLOW_OFFLOAD_DIR_ORIGINAL) ||
- !nf_flow_dst_check_gc(flow, FLOW_OFFLOAD_DIR_REPLY) ||
+ !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;
diff --git a/net/netfilter/nf_flow_table_path.c b/net/netfilter/nf_flow_table_path.c
index 8db396ddbd00..a18fce90b3b2 100644
--- a/net/netfilter/nf_flow_table_path.c
+++ b/net/netfilter/nf_flow_table_path.c
@@ -101,7 +101,11 @@ struct nft_forward_info {
u8 ingress_vlans;
u8 h_source[ETH_ALEN];
u8 h_dest[ETH_ALEN];
- bool needs_gso_segment;
+ u16 bridge_vid;
+ struct flow_offload_br_outer br_outer;
+ u8 needs_gso_segment:1,
+ bridge_path:1,
+ port_vlans:2;
enum flow_offload_xmit_type xmit_type;
};
@@ -112,8 +116,9 @@ static int nft_dev_path_info(struct net_device_path_stack *stack,
struct nft_forward_info *info,
unsigned char *ha, struct nft_flowtable *ft)
{
+ struct flow_offload_br_outer *o = &info->br_outer;
const struct net_device_path *path;
- int i;
+ int i, n;
memcpy(info->h_dest, ha, ETH_ALEN);
@@ -160,6 +165,8 @@ static int nft_dev_path_info(struct net_device_path_stack *stack,
info->encap[info->num_encaps].proto =
path->encap.proto;
info->num_encaps++;
+ if (info->bridge_path)
+ info->port_vlans++;
}
if (path->type == DEV_PATH_PPPOE) {
memcpy(info->h_dest, path->encap.h_dest, ETH_ALEN);
@@ -171,6 +178,7 @@ static int nft_dev_path_info(struct net_device_path_stack *stack,
if (is_zero_ether_addr(info->h_source))
memcpy(info->h_source, path->dev->dev_addr, ETH_ALEN);
+ n = info->num_encaps;
switch (path->bridge.vlan_mode) {
case DEV_PATH_BR_VLAN_UNTAG_HW:
if (info->num_encaps == 0)
@@ -195,6 +203,19 @@ static int nft_dev_path_info(struct net_device_path_stack *stack,
case DEV_PATH_BR_VLAN_KEEP:
break;
}
+ if (info->bridge_path) {
+ o->present = 1;
+ o->vid = info->bridge_vid;
+ o->link_vlans = info->port_vlans;
+ o->link_untag = path->bridge.vlan_mode ==
+ DEV_PATH_BR_VLAN_UNTAG;
+ o->link_8021ad = path->bridge.vlan_proto ==
+ htons(ETH_P_8021AD);
+ o->inner_tag = info->num_encaps > n;
+ }
+ info->bridge_path = 1;
+ info->bridge_vid = path->bridge.vlan_id;
+ info->port_vlans = 0;
info->xmit_type = FLOW_OFFLOAD_XMIT_DIRECT;
break;
default:
@@ -274,6 +295,10 @@ 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);
+ route->tuple[dir].out.bridge_path = info.bridge_path;
+ route->tuple[dir].out.bridge_vid = info.bridge_vid;
+ route->tuple[dir].out.br_outer = info.br_outer;
+ route->tuple[dir].out.port_vlans = info.port_vlans;
route->tuple[dir].xmit_type = info.xmit_type;
}
route->tuple[dir].out.needs_gso_segment = info.needs_gso_segment;
--
2.53.0
^ permalink raw reply related [flat|nested] 5+ messages in thread* [PATCH nf-next v11 3/3] selftests: netfilter: nft_flowtable.sh: roam a host between two bridge ports
2026-11-21 20:55 [PATCH nf-next v11 0/3] netfilter: flowtable: tear down bridged flows on layer 2 roaming Julius Bairaktaris
2026-11-21 20:55 ` [PATCH nf-next v11 1/3] net: bridge: fill a forward path only to a port that forwards Julius Bairaktaris
2026-11-21 20:55 ` [PATCH nf-next v11 2/3] netfilter: flowtable: tear down direct xmit flows when the fdb entry moves Julius Bairaktaris
@ 2026-11-21 20:55 ` Julius Bairaktaris
2 siblings, 0 replies; 5+ messages in thread
From: Julius Bairaktaris @ 2026-11-21 20:55 UTC (permalink / raw)
To: netfilter-devel
Cc: Pablo Neira Ayuso, Florian Westphal, Phil Sutter,
Nikolay Aleksandrov, Ido Schimmel, David S . Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Simon Horman, Shuah Khan,
Eric Woudstra, netdev, bridge, coreteam, linux-kselftest
Move a host to another port of a bridge on the router while its flow is
offloaded, and check that the transfer continues and is offloaded again.
The cases are plain and vlan bridge ports, vlan ports whose real devices
are ports of another bridge, "bridge fdb replace", a pinned and then
deleted fdb entry, an aged out entry (the flow must stay), the plain
case over IPv6, and a vlan_filtering bridge with untagged ports, with
tagged plain and vlan ports, and with the router address on a vlan
device on the bridge. Two cases give the ports vid 10 untagged while
their pvid stays 1, with a host that tags what it sends: the router
address on a vlan device on the bridge, and on the bridge with pvid 10.
With "stack" the bridge port is a vlan device of another bridge, and
with "stackout" the host moves from behind that bridge to a port of the
outer one. Three cases check that the flow follows what the bridge
delivers: the host's port is disabled and its vlan leaves the port
(the flow must stop in both), and vlan_filtering is turned off before
the host roams. In two cases the host is the remote end of an IPIP and
an IP6IP6 tunnel on the router, whose flow transmits to the bridge port
below the tunnel.
Without the gc check the transfer stalls when the host moves.
Signed-off-by: Julius Bairaktaris <julius@bairaktaris.de>
---
v11: the host roams below an IPIP and an IP6IP6 tunnel on the router,
which Pablo's series offloads as direct xmit to the bridge port
v10: https://lore.kernel.org/netfilter-devel/20261115005555.645727-4-julius@bairaktaris.de/
.../selftests/net/netfilter/nft_flowtable.sh | 390 ++++++++++++++++++
1 file changed, 390 insertions(+)
diff --git a/tools/testing/selftests/net/netfilter/nft_flowtable.sh b/tools/testing/selftests/net/netfilter/nft_flowtable.sh
index 449c518bd947..6ae84472790f 100755
--- a/tools/testing/selftests/net/netfilter/nft_flowtable.sh
+++ b/tools/testing/selftests/net/netfilter/nft_flowtable.sh
@@ -851,6 +851,396 @@ test_ipip
test_bridge
+# set by setup_ns, which reuses a name it already holds
+rns1="" rnsr="" rns2=""
+
+# Roam a host between two ports of a bridge on the router while its flow is
+# offloaded, as a station moving between two access points attached to ports
+# of one bridge. The host keeps its address and mac on a bridge of its own and
+# roams by moving that bridge's port, so only the fdb changes. With a vid the
+# bridge ports are vlan devices, whose ifindex differs from the device the
+# flow transmits on. With "replace" the router's fdb entry is sticky and the
+# move is a "bridge fdb replace". With "del" the host stays, its entry is
+# pinned to the other port and then deleted, and a ping relearns it. With
+# "age" the host stays and its entry ages out, which must not tear the flow
+# down. A flow that stays on the fast path leaves no more than a few packets
+# in the forward chain, the counter tells offloaded from slow path. The plain
+# roam also runs over IPv6, and on a vlan_filtering bridge: with untagged
+# ports ("vf"), whose fdb entries are keyed by the pvid of the port, with
+# tagged ports ("tag"), and with untagged ports and the router address on a
+# vlan device on the bridge ("upper"). "asym" and "asymkeep" give the ports
+# vid 10 untagged while their pvid stays 1 and the host tags what it sends,
+# with the router address on a vlan device on the bridge or on the bridge with
+# pvid 10. With "stack" the port of br0 is a vlan device on br1, whose ports
+# the host moves between; with "stackout" the host moves from behind br1 to a
+# port of br0. With "block" the host's port is set to the disabled state,
+# which must stop the flow. With "vdel" the host's vlan leaves its port, which
+# must stop the flow, and with "toggle" vlan_filtering is turned off before
+# the host roams. With "ipip" and "ip6tnl" the host is the remote end of a
+# tunnel on the router, and the flow through the tunnel transmits to the
+# bridge port below it.
+test_bridge_roam()
+{
+ local vid=$1 how=$2 fam=${3:-4} vf=$4 trunk=$5 tun=$6
+ local p0=sr0 p1=sr1 r0=rr0 r1=rr1 rbr=br0
+ local mac=02:00:00:09:01:99
+ local what="roaming on bridge${vf:+ with vlan_filtering}"
+ [ "$vf" = tag ] && what="$what and tagged ports"
+ [ "$vf" = upper ] && what="$what and a vlan device on the bridge"
+ [ "$vf" = asym ] && what="$what, a vlan device on the bridge"
+ [ "$vf" = asymkeep ] && what="$what and the bridge pvid"
+ [ "${vf#asym}" != "$vf" ] && what="$what untagged on ports of pvid 1"
+ what="$what${vid:+ with vlan ports}"
+ case "$how" in
+ block) what="$what, the host's port disabled" ;;
+ vdel) what="$what, the vlan leaving the port" ;;
+ toggle) what="$what, vlan_filtering turned off" ;;
+ ?*) what="$what by fdb $how" ;;
+ esac
+ [ "$trunk" = trunk ] &&
+ what="$what whose real devices are ports of another bridge"
+ [ "$trunk" = stack ] && what="$what on a vlan device of another bridge"
+ [ "$trunk" = stackout ] &&
+ what="$what from a vlan device of another bridge to a port"
+ local ftdevs="rr0, rr1, rw0"
+ local hn=10.9.1 wn=10.9.2 dot=. len=24 nodad="" ip6="" srv=10.9.2.99
+ local min=10000000
+ local dev old new slow fdb lpid cpid win=2
+
+ if [ "$fam" = 6 ]; then
+ hn=dead:9:1 wn=dead:9:2 dot=:: len=64 nodad=nodad ip6=-6
+ srv="[dead:9:2::99]"
+ what="$what over IPv6"
+ fi
+ [ "$tun" = ipip ] && what="$what below an IPIP tunnel"
+ [ "$tun" = ip6tnl ] && what="$what below an IP6IP6 tunnel"
+
+ setup_ns rns1 rnsr rns2
+ # router solicitations of the host would pass the bridge and refresh
+ # its fdb entry
+ if [ "$fam" = 4 ]; then
+ ip netns exec "$rns1" sysctl -q \
+ net.ipv6.conf.all.disable_ipv6=1 \
+ net.ipv6.conf.default.disable_ipv6=1
+ fi
+
+ if ! ip -net "$rnsr" link add br0 type bridge \
+ ${vf:+vlan_filtering 1} 2>/dev/null; then
+ echo "SKIP: could not add bridge for $what"
+ [ "$ret" -eq 0 ] && ret=$ksft_skip
+ return
+ fi
+
+ ip link add sr0 netns "$rns1" type veth peer name rr0 netns "$rnsr"
+ ip link add sr1 netns "$rns1" type veth peer name rr1 netns "$rnsr"
+ ip link add rw0 netns "$rnsr" type veth peer name w0 netns "$rns2"
+ if [ "$trunk" = stackout ]; then
+ ip link add sr2 netns "$rns1" type veth peer name rr2 \
+ netns "$rnsr"
+ ip -net "$rns1" link set sr2 up
+ ip -net "$rnsr" link set rr2 up
+ ftdevs="$ftdevs, rr2"
+ fi
+ for dev in sr0 sr1; do
+ ip -net "$rns1" link set "$dev" up
+ done
+ for dev in rr0 rr1; do
+ ip -net "$rnsr" link set "$dev" up
+ done
+
+ if [ -n "$vid" ]; then
+ for dev in sr0 sr1; do
+ ip -net "$rns1" link add link "$dev" name "$dev.$vid" \
+ type vlan id "$vid"
+ ip -net "$rns1" link set "$dev.$vid" up
+ done
+ p0=sr0.$vid; p1=sr1.$vid
+ fi
+ if [ -n "$vid" ] && [ "${trunk#stack}" = "$trunk" ]; then
+ for dev in rr0 rr1; do
+ ip -net "$rnsr" link add link "$dev" name "$dev.$vid" \
+ type vlan id "$vid"
+ ip -net "$rnsr" link set "$dev.$vid" up
+ done
+ r0=rr0.$vid; r1=rr1.$vid
+ fi
+ if [ -n "$trunk" ]; then
+ ip -net "$rnsr" link add br1 type bridge
+ ip -net "$rnsr" link set rr0 master br1
+ ip -net "$rnsr" link set rr1 master br1
+ ip -net "$rnsr" link set br1 up
+ fi
+ if [ "${trunk#stack}" != "$trunk" ]; then
+ ip -net "$rnsr" link add link br1 name br1.$vid \
+ type vlan id "$vid"
+ ip -net "$rnsr" link set br1.$vid up
+ r0=br1.$vid; r1=br1.$vid
+ fi
+ # the host moves from behind br1 to a port of br0
+ [ "$trunk" = stackout ] && { r1=rr2; p1=sr2; }
+
+ ip -net "$rnsr" link set "$r0" master br0
+ [ "$r1" != "$r0" ] && ip -net "$rnsr" link set "$r1" master br0
+ ip -net "$rnsr" link set br0 up
+ if [ "$vf" = tag ]; then
+ for dev in "$r0" "$r1"; do
+ bridge -n "$rnsr" vlan add vid 10 dev "$dev"
+ done
+ bridge -n "$rnsr" vlan add vid 10 dev br0 self pvid untagged
+ for dev in "$p0" "$p1"; do
+ ip -net "$rns1" link add link "$dev" name "$dev.10" \
+ type vlan id 10
+ ip -net "$rns1" link set "$dev.10" up
+ done
+ p0=$p0.10; p1=$p1.10
+ elif [ "$vf" = upper ]; then
+ for dev in "$r0" "$r1"; do
+ bridge -n "$rnsr" vlan add vid 10 dev "$dev" \
+ pvid untagged
+ done
+ bridge -n "$rnsr" vlan add vid 10 dev br0 self
+ ip -net "$rnsr" link add link br0 name br0.10 type vlan id 10
+ ip -net "$rnsr" link set br0.10 up
+ rbr=br0.10
+ elif [ "$vf" = asym ] || [ "$vf" = asymkeep ]; then
+ # vid 10 leaves the ports untagged but is not their pvid; the
+ # host tags what it sends, so the entry is learned in vid 10.
+ for dev in "$r0" "$r1"; do
+ bridge -n "$rnsr" vlan add vid 10 dev "$dev" untagged
+ done
+ if [ "$vf" = asym ]; then
+ bridge -n "$rnsr" vlan add vid 10 dev br0 self
+ ip -net "$rnsr" link add link br0 name br0.10 \
+ type vlan id 10
+ ip -net "$rnsr" link set br0.10 up
+ rbr=br0.10
+ else
+ bridge -n "$rnsr" vlan add vid 10 dev br0 self \
+ pvid untagged
+ fi
+ fi
+ ip -net "$rnsr" addr add $hn${dot}1/$len dev $rbr $nodad
+ ip -net "$rnsr" addr add $wn${dot}1/$len dev rw0 $nodad
+ ip -net "$rnsr" link set rw0 up
+ ip netns exec "$rnsr" sysctl -q net.ipv4.ip_forward=1
+ ip netns exec "$rnsr" sysctl -q net.ipv6.conf.all.forwarding=1
+
+ # the host takes untagged frames into vid 10 and sends it tagged
+ host_port() {
+ ip -net "$rns1" link set "$1" master stbr
+ if [ "$vf" = asym ] || [ "$vf" = asymkeep ]; then
+ bridge -n "$rns1" vlan add vid 10 dev "$1" pvid
+ bridge -n "$rns1" vlan del vid 1 dev "$1"
+ fi
+ }
+ ip -net "$rns1" link add stbr type bridge
+ if [ "$vf" = asym ] || [ "$vf" = asymkeep ]; then
+ ip -net "$rns1" link set stbr type bridge vlan_filtering 1
+ bridge -n "$rns1" vlan add vid 10 dev stbr self pvid untagged
+ bridge -n "$rns1" vlan del vid 1 dev stbr self
+ fi
+ ip -net "$rns1" link set stbr address $mac
+ host_port "$p0"
+ ip -net "$rns1" link set stbr up
+ ip -net "$rns1" addr add $hn${dot}99/$len dev stbr $nodad
+ ip $ip6 -net "$rns1" route add default via $hn${dot}1
+
+ ip -net "$rns2" addr add $wn${dot}99/$len dev w0 $nodad
+ ip -net "$rns2" link set w0 up
+ ip $ip6 -net "$rns2" route add default via $wn${dot}1
+
+ if [ -n "$tun" ]; then
+ local tn=10.9.3 wnet=$wn.0
+ [ "$fam" = 6 ] && tn=dead:9:3 wnet=$wn::
+ if ! ip -net "$rnsr" link add rtun type "$tun" \
+ local $hn${dot}1 remote $hn${dot}99 \
+ ${ip6:+encaplimit none}; then
+ echo "SKIP: could not add tunnel for $what"
+ [ "$ret" -eq 0 ] && ret=$ksft_skip
+ return
+ fi
+ ip -net "$rns1" link add stun type "$tun" \
+ local $hn${dot}99 remote $hn${dot}1 \
+ ${ip6:+encaplimit none}
+ ip -net "$rnsr" link set rtun up
+ ip -net "$rns1" link set stun up
+ ip -net "$rnsr" addr add $tn${dot}1/$len dev rtun $nodad
+ ip -net "$rns1" addr add $tn${dot}99/$len dev stun $nodad
+ ip $ip6 -net "$rns1" route add $wnet/$len dev stun
+ fi
+
+ # no neighbour probes, so the host only sends when it receives
+ ip -net "$rnsr" neigh replace $hn${dot}99 lladdr $mac nud permanent \
+ dev $rbr
+ ip -net "$rns1" neigh replace $hn${dot}1 nud permanent dev stbr \
+ lladdr "$(ip -net "$rnsr" -br link show br0 | awk '{print $3}')"
+
+ if ! ip netns exec "$rnsr" nft -f - <<EOF
+table inet filter {
+ counter roam_repl { }
+ flowtable f1 { hook ingress priority 0; devices = { $ftdevs }; }
+ chain forward {
+ type filter hook forward priority 0; policy accept;
+ meta oif "rw0" tcp dport 12345 flow add @f1
+ meta iif "rw0" tcp sport 12345 counter name roam_repl flow add @f1
+ }
+}
+EOF
+ then
+ echo "SKIP: could not load ruleset for $what"
+ [ "$ret" -eq 0 ] && ret=$ksft_skip
+ return
+ fi
+
+ # the host discards what it receives, its socket byte counter is read
+ rx_bytes() { ip netns exec "$rns1" ss -tin "dst $srv" 2>/dev/null |
+ grep -o 'bytes_received:[0-9]*' | head -1 | cut -d: -f2; }
+ rx_started() { local n; n=$(rx_bytes); [ "${n:-0}" -gt 0 ]; }
+ # forward chain packets of the reply direction since the last call
+ slow_pkts() { ip netns exec "$rnsr" \
+ nft reset counter inet filter roam_repl |
+ grep -o 'packets [0-9]*' | cut -d' ' -f2; }
+ roam_listener_ready() {
+ ss -N "$rns2" -lnt -o "sport = :12345" | grep -q 12345
+ }
+
+ roam_stop() {
+ kill "$cpid" "$lpid" 2>/dev/null
+ wait "$cpid" "$lpid" 2>/dev/null
+ }
+
+ timeout $((SOCAT_TIMEOUT * 5)) ip netns exec "$rns2" socat -u \
+ OPEN:/dev/zero TCP$fam-LISTEN:12345,reuseaddr &
+ lpid=$!
+ if ! busywait "$BUSYWAIT_TIMEOUT" roam_listener_ready; then
+ echo "FAIL: $what: listener did not start" 1>&2
+ ret=1
+ kill "$lpid" 2>/dev/null; wait "$lpid" 2>/dev/null
+ return
+ fi
+ timeout $((SOCAT_TIMEOUT * 5)) ip netns exec "$rns1" socat -u \
+ TCP$fam:$srv:12345 OPEN:/dev/null &
+ cpid=$!
+
+ if ! busywait "$BUSYWAIT_TIMEOUT" rx_started; then
+ echo "FAIL: $what: transfer did not start" 1>&2
+ ret=1
+ roam_stop
+ return
+ fi
+ sleep 2
+ slow_pkts > /dev/null
+ old=$(rx_bytes)
+ sleep 2
+ new=$(rx_bytes)
+ slow=$(slow_pkts)
+ if [ -z "$slow" ] || [ $((${new:-0} - ${old:-0})) -lt $min ] ||
+ [ "$slow" -gt 100 ]; then
+ echo "FAIL: $what: not offloaded before the roam:" \
+ "$((${new:-0} - ${old:-0})) bytes," \
+ "${slow:-no} forward chain packets" 1>&2
+ ret=1
+ roam_stop
+ return
+ fi
+
+ if [ "$how" = age ]; then
+ # ageing_time is in centiseconds
+ ip -net "$rnsr" link set br0 type bridge ageing_time 200
+ win=10
+ elif [ "$how" = del ]; then
+ bridge -n "$rnsr" fdb replace $mac dev "$r1" \
+ master static sticky
+ sleep 2
+ bridge -n "$rnsr" fdb del $mac dev "$r1" master static
+ ip netns exec "$rns1" ping $ip6 -c 2 -W 1 -q $hn${dot}1 \
+ >/dev/null 2>&1
+ elif [ "$how" = block ]; then
+ # the bridge no longer delivers there, nor may the flow; the
+ # disabled state sticks without STP and keeps the fdb
+ bridge -n "$rnsr" link set dev "$r0" state 0
+ elif [ "$how" = vdel ]; then
+ # the bridge no longer delivers to the host, nor may the flow
+ bridge -n "$rnsr" vlan del vid 1 dev "$r0"
+ else
+ # roam: move the host bridge to the other port and send on it
+ if [ "$how" = toggle ]; then
+ ip -net "$rnsr" link set br0 type bridge \
+ vlan_filtering 0
+ sleep 2
+ fi
+ if [ "$how" = replace ]; then
+ bridge -n "$rnsr" fdb replace $mac dev "$r0" \
+ master static sticky
+ fi
+ ip -net "$rns1" link set "$p0" nomaster
+ host_port "$p1"
+ ip netns exec "$rns1" ping $ip6 -c 2 -W 1 -q $hn${dot}1 \
+ >/dev/null 2>&1
+ if [ "$how" = replace ]; then
+ bridge -n "$rnsr" fdb replace $mac dev "$r1" \
+ master static sticky
+ fi
+ fi
+
+ # the bytes in flight at the roam drain within the first seconds; a
+ # stale flow delivers nothing after that, a torn down one resumes and
+ # is offloaded again.
+ sleep 4
+ old=$(rx_bytes)
+ sleep 4
+ new=$(rx_bytes)
+ slow_pkts > /dev/null
+ sleep $win
+ slow=$(slow_pkts)
+ # before the host's FIN passes the bridge and relearns the entry
+ fdb=$(bridge -n "$rnsr" fdb show br br0 | grep "$mac.*master")
+ roam_stop
+
+ if [ "$how" = vdel ] || [ "$how" = block ]; then
+ if [ $((${new:-0} - ${old:-0})) -gt 0 ]; then
+ echo "FAIL: $what: $((${new:-0} - ${old:-0})) bytes" \
+ "delivered to a port that does not forward" 1>&2
+ ret=1
+ else
+ echo "PASS: flow offload for $what"
+ fi
+ elif [ "$how" = age ] && [ -n "$fdb" ]; then
+ echo "FAIL: $what: the host's fdb entry did not age out" 1>&2
+ ret=1
+ elif [ $((${new:-0} - ${old:-0})) -lt $min ]; then
+ echo "FAIL: $what: transfer stalled after the roam" 1>&2
+ ret=1
+ elif [ "$slow" != 0 ]; then
+ echo "FAIL: $what: $slow forward chain packets after the roam" \
+ 1>&2
+ ret=1
+ else
+ echo "PASS: flow offload for $what"
+ fi
+}
+
+test_bridge_roam ""
+test_bridge_roam 100
+test_bridge_roam "" replace
+test_bridge_roam "" del
+test_bridge_roam "" age
+test_bridge_roam "" "" 6
+test_bridge_roam "" "" 4 vf
+test_bridge_roam "" "" 4 tag
+test_bridge_roam 100 "" 4 tag
+test_bridge_roam 100 "" 4 "" trunk
+test_bridge_roam 100 "" 4 "" stack
+test_bridge_roam 100 "" 4 "" stackout
+test_bridge_roam "" block
+test_bridge_roam "" vdel 4 vf
+test_bridge_roam "" toggle 4 vf
+test_bridge_roam "" "" 4 upper
+test_bridge_roam "" "" 4 asym
+test_bridge_roam "" "" 4 asymkeep
+test_bridge_roam "" "" 4 "" "" ipip
+test_bridge_roam "" "" 6 "" "" ip6tnl
+
KEY_SHA="0x"$(ps -af | sha1sum | cut -d " " -f 1)
KEY_AES="0x"$(ps -af | md5sum | cut -d " " -f 1)
SPI1=$RANDOM
--
2.53.0
^ permalink raw reply related [flat|nested] 5+ messages in thread