* [RFC PATCH v1 net-next 0/3] flow offload teardown when layer 2 roaming
@ 2025-02-04 19:50 Eric Woudstra
2025-02-04 19:50 ` [RFC PATCH v1 net-next 1/3] netfilter: flow: Add bridge_vid member Eric Woudstra
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Eric Woudstra @ 2025-02-04 19:50 UTC (permalink / raw)
To: Pablo Neira Ayuso, Jozsef Kadlecsik, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, Simon Horman,
Vladimir Oltean, Nikolay Aleksandrov, Frank Wunderlich,
Daniel Golle
Cc: netfilter-devel, coreteam, netdev, linux-kernel, Eric Woudstra
In case of a bridge in the forward-fastpath or bridge-fastpath the fdb is
used to create the tuple. In case of roaming at layer 2 level, for example
802.11r, the destination device is changed in the fdb. The destination
device of a direct transmitting tuple is no longer valid and traffic is
send to the wrong destination. Also the hardware offloaded fastpath is not
valid anymore.
This flowentry needs to be torn down asap. Also make sure that the flow
entry is not being used, when marked for teardown.
This patch-set depends on patch-set: "PATCH v5 bridge-fastpath and related
improvements" only for applying the patch correctly, but it is not a
functional requirement.
Eric Woudstra (3):
netfilter: flow: Add bridge_vid member
netfilter: nf_flow_table_core: teardown direct xmit when destination
changed
netfilter: nf_flow_table_ip: don't follow fastpath when marked
teardown
include/net/netfilter/nf_flow_table.h | 2 +
net/netfilter/nf_flow_table_core.c | 66 +++++++++++++++++++++++++++
net/netfilter/nf_flow_table_ip.c | 6 +++
net/netfilter/nft_flow_offload.c | 4 ++
4 files changed, 78 insertions(+)
--
2.47.1
^ permalink raw reply [flat|nested] 4+ messages in thread
* [RFC PATCH v1 net-next 1/3] netfilter: flow: Add bridge_vid member
2025-02-04 19:50 [RFC PATCH v1 net-next 0/3] flow offload teardown when layer 2 roaming Eric Woudstra
@ 2025-02-04 19:50 ` Eric Woudstra
2025-02-04 19:50 ` [RFC PATCH v1 net-next 2/3] netfilter: nf_flow_table_core: teardown direct xmit when destination changed Eric Woudstra
2025-02-04 19:50 ` [RFC PATCH v1 net-next 3/3] netfilter: nf_flow_table_ip: don't follow fastpath when marked teardown Eric Woudstra
2 siblings, 0 replies; 4+ messages in thread
From: Eric Woudstra @ 2025-02-04 19:50 UTC (permalink / raw)
To: Pablo Neira Ayuso, Jozsef Kadlecsik, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, Simon Horman,
Vladimir Oltean, Nikolay Aleksandrov, Frank Wunderlich,
Daniel Golle
Cc: netfilter-devel, coreteam, netdev, linux-kernel, Eric Woudstra
Store the vid used on the bridge in the flow_offload_tuple, so it can be
used later to identify fdb entries that relate to the tuple.
The bridge_vid member is added to the structures nft_forward_info,
nf_flow_route and flow_offload_tuple. It can now be passed from
net_device_path->bridge.vlan_id to flow_offload_tuple->out.bridge_vid.
Signed-off-by: Eric Woudstra <ericwouds@gmail.com>
---
include/net/netfilter/nf_flow_table.h | 2 ++
net/netfilter/nf_flow_table_core.c | 1 +
net/netfilter/nft_flow_offload.c | 4 ++++
3 files changed, 7 insertions(+)
diff --git a/include/net/netfilter/nf_flow_table.h b/include/net/netfilter/nf_flow_table.h
index a7f5d6166088..77d6098badd4 100644
--- a/include/net/netfilter/nf_flow_table.h
+++ b/include/net/netfilter/nf_flow_table.h
@@ -145,6 +145,7 @@ struct flow_offload_tuple {
};
struct {
u32 ifidx;
+ u16 bridge_vid;
u8 h_source[ETH_ALEN];
u8 h_dest[ETH_ALEN];
} out;
@@ -210,6 +211,7 @@ struct nf_flow_route {
} in;
struct {
u32 ifindex;
+ u16 bridge_vid;
u8 h_source[ETH_ALEN];
u8 h_dest[ETH_ALEN];
} out;
diff --git a/net/netfilter/nf_flow_table_core.c b/net/netfilter/nf_flow_table_core.c
index 1e5d3735c028..bcf9435638e2 100644
--- a/net/netfilter/nf_flow_table_core.c
+++ b/net/netfilter/nf_flow_table_core.c
@@ -127,6 +127,7 @@ 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->out.bridge_vid = route->tuple[dir].out.bridge_vid;
dst_release(dst);
break;
case FLOW_OFFLOAD_XMIT_XFRM:
diff --git a/net/netfilter/nft_flow_offload.c b/net/netfilter/nft_flow_offload.c
index 03a0b5f7e8d2..95cc58cf068e 100644
--- a/net/netfilter/nft_flow_offload.c
+++ b/net/netfilter/nft_flow_offload.c
@@ -84,6 +84,7 @@ struct nft_forward_info {
__u16 id;
__be16 proto;
} encap[NF_FLOW_TABLE_ENCAP_MAX];
+ u16 bridge_vid;
u8 num_encaps;
u8 ingress_vlans;
u8 h_source[ETH_ALEN];
@@ -162,6 +163,7 @@ static void nft_dev_path_info(const struct net_device_path_stack *stack,
case DEV_PATH_BR_VLAN_KEEP:
break;
}
+ info->bridge_vid = path->bridge.vlan_id;
info->xmit_type = FLOW_OFFLOAD_XMIT_DIRECT;
break;
default:
@@ -252,6 +254,7 @@ static int nft_dev_fill_bridge_path(struct flow_offload *flow,
ether_addr_copy(th[dir].tuple.out.h_source, src_ha);
ether_addr_copy(th[dir].tuple.out.h_dest, dst_ha);
th[dir].tuple.out.ifidx = info.outdev->ifindex;
+ th[dir].tuple.out.bridge_vid = info.bridge_vid;
th[dir].tuple.xmit_type = FLOW_OFFLOAD_XMIT_DIRECT;
return 0;
@@ -344,6 +347,7 @@ static void nft_dev_forward_path(struct nf_flow_route *route,
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.ifindex = info.outdev->ifindex;
+ route->tuple[dir].out.bridge_vid = info.bridge_vid;
route->tuple[dir].xmit_type = info.xmit_type;
}
}
--
2.47.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [RFC PATCH v1 net-next 2/3] netfilter: nf_flow_table_core: teardown direct xmit when destination changed
2025-02-04 19:50 [RFC PATCH v1 net-next 0/3] flow offload teardown when layer 2 roaming Eric Woudstra
2025-02-04 19:50 ` [RFC PATCH v1 net-next 1/3] netfilter: flow: Add bridge_vid member Eric Woudstra
@ 2025-02-04 19:50 ` Eric Woudstra
2025-02-04 19:50 ` [RFC PATCH v1 net-next 3/3] netfilter: nf_flow_table_ip: don't follow fastpath when marked teardown Eric Woudstra
2 siblings, 0 replies; 4+ messages in thread
From: Eric Woudstra @ 2025-02-04 19:50 UTC (permalink / raw)
To: Pablo Neira Ayuso, Jozsef Kadlecsik, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, Simon Horman,
Vladimir Oltean, Nikolay Aleksandrov, Frank Wunderlich,
Daniel Golle
Cc: netfilter-devel, coreteam, netdev, linux-kernel, Eric Woudstra
In case of a bridge in the forward-fastpath or bridge-fastpath the fdb is
used to create the tuple. In case of roaming at layer 2 level, for example
802.11r, the destination device is changed in the fdb. The destination
device of a direct transmitting tuple is no longer valid and traffic is
send to the wrong destination. Also the hardware offloaded fastpath is not
valid anymore.
In case of roaming, a switchdev notification is send to delete the old fdb
entry. Upon receiving this notification, mark all direct transmitting flows
with the same ifindex, vid and hardware address as the fdb entry to be
teared down. The hardware offloaded fastpath is still in effect, so
minimize the delay of the work queue by setting the delay to zero.
Signed-off-by: Eric Woudstra <ericwouds@gmail.com>
---
net/netfilter/nf_flow_table_core.c | 65 ++++++++++++++++++++++++++++++
1 file changed, 65 insertions(+)
diff --git a/net/netfilter/nf_flow_table_core.c b/net/netfilter/nf_flow_table_core.c
index bcf9435638e2..f7a364492dab 100644
--- a/net/netfilter/nf_flow_table_core.c
+++ b/net/netfilter/nf_flow_table_core.c
@@ -13,6 +13,7 @@
#include <net/netfilter/nf_conntrack_core.h>
#include <net/netfilter/nf_conntrack_l4proto.h>
#include <net/netfilter/nf_conntrack_tuple.h>
+#include <net/switchdev.h>
static DEFINE_MUTEX(flowtable_lock);
static LIST_HEAD(flowtables);
@@ -742,6 +743,63 @@ void nf_flow_table_cleanup(struct net_device *dev)
}
EXPORT_SYMBOL_GPL(nf_flow_table_cleanup);
+struct flow_cleanup_data {
+ const unsigned char *addr;
+ int ifindex;
+ u16 vid;
+ bool found;
+};
+
+static void nf_flow_table_do_cleanup_addr(struct nf_flowtable *flow_table,
+ struct flow_offload *flow, void *data)
+{
+ struct flow_cleanup_data *cud = data;
+
+ if ((flow->tuplehash[0].tuple.xmit_type == FLOW_OFFLOAD_XMIT_DIRECT &&
+ flow->tuplehash[0].tuple.out.ifidx == cud->ifindex &&
+ flow->tuplehash[0].tuple.out.bridge_vid == cud->vid &&
+ ether_addr_equal(flow->tuplehash[0].tuple.out.h_dest, cud->addr)) ||
+ (flow->tuplehash[1].tuple.xmit_type == FLOW_OFFLOAD_XMIT_DIRECT &&
+ flow->tuplehash[1].tuple.out.ifidx == cud->ifindex &&
+ flow->tuplehash[1].tuple.out.bridge_vid == cud->vid &&
+ ether_addr_equal(flow->tuplehash[1].tuple.out.h_dest, cud->addr))) {
+ flow_offload_teardown(flow);
+ cud->found = true;
+ }
+}
+
+static int nf_flow_table_switchdev_event(struct notifier_block *unused,
+ unsigned long event, void *ptr)
+{
+ struct switchdev_notifier_fdb_info *fdb_info;
+ struct nf_flowtable *flowtable;
+ struct flow_cleanup_data cud;
+
+ if (event != SWITCHDEV_FDB_DEL_TO_DEVICE)
+ return NOTIFY_DONE;
+
+ fdb_info = ptr;
+ cud.addr = fdb_info->addr;
+ cud.vid = fdb_info->vid;
+ cud.ifindex = fdb_info->info.dev->ifindex;
+
+ mutex_lock(&flowtable_lock);
+ list_for_each_entry(flowtable, &flowtables, list) {
+ cud.found = false;
+ nf_flow_table_iterate(flowtable, nf_flow_table_do_cleanup_addr, &cud);
+ if (cud.found)
+ mod_delayed_work(system_power_efficient_wq,
+ &flowtable->gc_work, 0);
+ }
+ mutex_unlock(&flowtable_lock);
+
+ return NOTIFY_DONE;
+}
+
+struct notifier_block nf_flow_table_switchdev_nb __read_mostly = {
+ .notifier_call = nf_flow_table_switchdev_event,
+};
+
void nf_flow_table_free(struct nf_flowtable *flow_table)
{
mutex_lock(&flowtable_lock);
@@ -815,6 +873,10 @@ static int __init nf_flow_table_module_init(void)
if (ret)
goto out_offload;
+ ret = register_switchdev_notifier(&nf_flow_table_switchdev_nb);
+ if (ret < 0)
+ goto out_sw_noti;
+
ret = nf_flow_register_bpf();
if (ret)
goto out_bpf;
@@ -822,6 +884,8 @@ static int __init nf_flow_table_module_init(void)
return 0;
out_bpf:
+ unregister_switchdev_notifier(&nf_flow_table_switchdev_nb);
+out_sw_noti:
nf_flow_table_offload_exit();
out_offload:
unregister_pernet_subsys(&nf_flow_table_net_ops);
@@ -830,6 +894,7 @@ static int __init nf_flow_table_module_init(void)
static void __exit nf_flow_table_module_exit(void)
{
+ unregister_switchdev_notifier(&nf_flow_table_switchdev_nb);
nf_flow_table_offload_exit();
unregister_pernet_subsys(&nf_flow_table_net_ops);
}
--
2.47.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [RFC PATCH v1 net-next 3/3] netfilter: nf_flow_table_ip: don't follow fastpath when marked teardown
2025-02-04 19:50 [RFC PATCH v1 net-next 0/3] flow offload teardown when layer 2 roaming Eric Woudstra
2025-02-04 19:50 ` [RFC PATCH v1 net-next 1/3] netfilter: flow: Add bridge_vid member Eric Woudstra
2025-02-04 19:50 ` [RFC PATCH v1 net-next 2/3] netfilter: nf_flow_table_core: teardown direct xmit when destination changed Eric Woudstra
@ 2025-02-04 19:50 ` Eric Woudstra
2 siblings, 0 replies; 4+ messages in thread
From: Eric Woudstra @ 2025-02-04 19:50 UTC (permalink / raw)
To: Pablo Neira Ayuso, Jozsef Kadlecsik, David S. Miller,
Eric Dumazet, Jakub Kicinski, Paolo Abeni, Simon Horman,
Vladimir Oltean, Nikolay Aleksandrov, Frank Wunderlich,
Daniel Golle
Cc: netfilter-devel, coreteam, netdev, linux-kernel, Eric Woudstra
When a flow is marked for teardown, because the destination is not valid
any more, the software fastpath may still be in effect and traffic is
still send to the wrong destination. Change the ip/ipv6 hooks to not use
the software fastpath for a flow that is marked to be teared down and let
the packet continue along the normal path.
Signed-off-by: Eric Woudstra <ericwouds@gmail.com>
---
net/netfilter/nf_flow_table_ip.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/net/netfilter/nf_flow_table_ip.c b/net/netfilter/nf_flow_table_ip.c
index b9292eb40907..84a8fe7b7b5d 100644
--- a/net/netfilter/nf_flow_table_ip.c
+++ b/net/netfilter/nf_flow_table_ip.c
@@ -543,6 +543,9 @@ nf_flow_offload_ip_hook(void *priv, struct sk_buff *skb,
dir = tuplehash->tuple.dir;
flow = container_of(tuplehash, struct flow_offload, tuplehash[dir]);
+ if (test_bit(NF_FLOW_TEARDOWN, &flow->flags))
+ return NF_ACCEPT;
+
switch (tuplehash->tuple.xmit_type) {
case FLOW_OFFLOAD_XMIT_NEIGH:
rt = dst_rtable(tuplehash->tuple.dst_cache);
@@ -841,6 +844,9 @@ nf_flow_offload_ipv6_hook(void *priv, struct sk_buff *skb,
dir = tuplehash->tuple.dir;
flow = container_of(tuplehash, struct flow_offload, tuplehash[dir]);
+ if (test_bit(NF_FLOW_TEARDOWN, &flow->flags))
+ return NF_ACCEPT;
+
switch (tuplehash->tuple.xmit_type) {
case FLOW_OFFLOAD_XMIT_NEIGH:
rt = dst_rt6_info(tuplehash->tuple.dst_cache);
--
2.47.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
end of thread, other threads:[~2025-02-04 19:51 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-02-04 19:50 [RFC PATCH v1 net-next 0/3] flow offload teardown when layer 2 roaming Eric Woudstra
2025-02-04 19:50 ` [RFC PATCH v1 net-next 1/3] netfilter: flow: Add bridge_vid member Eric Woudstra
2025-02-04 19:50 ` [RFC PATCH v1 net-next 2/3] netfilter: nf_flow_table_core: teardown direct xmit when destination changed Eric Woudstra
2025-02-04 19:50 ` [RFC PATCH v1 net-next 3/3] netfilter: nf_flow_table_ip: don't follow fastpath when marked teardown Eric Woudstra
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).