All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH nf,v6 1/3] netfilter: flowtable: remove redundant ifidx field in tuple output union
@ 2026-11-20 22:52 Pablo Neira Ayuso
  2026-11-20 22:52 ` [PATCH nf,v6 2/3] netfilter: flowtable: cache destination hw address for XMIT_NEIGH type Pablo Neira Ayuso
  2026-11-20 22:52 ` [PATCH nf,v6 3/3] netfilter: flowtable: unify direct and neigh xmit path Pablo Neira Ayuso
  0 siblings, 2 replies; 8+ messages in thread
From: Pablo Neira Ayuso @ 2026-11-20 22:52 UTC (permalink / raw)
  To: netfilter-devel

The XMIT_NEIGH and XMIT_DIRECT types use an output ifidx field to
determine the destination netdevice. Remove the redundant ifidx field in
the flow_offload_tuple union that represents the output path, use the
existing struct.

No functional change, this is just a preparation patch.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
v6: no changes

 include/net/netfilter/nf_flow_table.h | 3 ---
 net/netfilter/nf_flow_table_core.c    | 2 +-
 net/netfilter/nf_flow_table_ip.c      | 4 ++--
 3 files changed, 3 insertions(+), 6 deletions(-)

diff --git a/include/net/netfilter/nf_flow_table.h b/include/net/netfilter/nf_flow_table.h
index 5b22d31cb140..61ac43b17dc9 100644
--- a/include/net/netfilter/nf_flow_table.h
+++ b/include/net/netfilter/nf_flow_table.h
@@ -160,9 +160,6 @@ struct flow_offload_tuple {
 	struct dst_entry		*dst_cache;
 
 	union {
-		struct {
-			u32		ifidx;
-		};
 		struct {
 			u32		ifidx;
 			u8		h_source[ETH_ALEN];
diff --git a/net/netfilter/nf_flow_table_core.c b/net/netfilter/nf_flow_table_core.c
index 2aa2647ed9df..a7b4fc5766a9 100644
--- a/net/netfilter/nf_flow_table_core.c
+++ b/net/netfilter/nf_flow_table_core.c
@@ -142,7 +142,7 @@ static int flow_offload_fill_route(struct flow_offload *flow,
 		break;
 	case FLOW_OFFLOAD_XMIT_XFRM:
 	case FLOW_OFFLOAD_XMIT_NEIGH:
-		flow_tuple->ifidx = route->tuple[dir].out.ifindex;
+		flow_tuple->out.ifidx = route->tuple[dir].out.ifindex;
 		flow_tuple->dst_cache = dst;
 		flow_tuple->dst_cookie = flow_offload_dst_cookie(flow_tuple);
 		break;
diff --git a/net/netfilter/nf_flow_table_ip.c b/net/netfilter/nf_flow_table_ip.c
index 19cafae748ab..115c54ad4633 100644
--- a/net/netfilter/nf_flow_table_ip.c
+++ b/net/netfilter/nf_flow_table_ip.c
@@ -867,7 +867,7 @@ static int nf_flow_queue_xmit4(struct sk_buff *skb,
 	switch (tuplehash->tuple.xmit_type) {
 	case FLOW_OFFLOAD_XMIT_NEIGH:
 		rt = dst_rtable(tuplehash->tuple.dst_cache);
-		xmit.outdev = dev_get_by_index_rcu(state->net, tuplehash->tuple.ifidx);
+		xmit.outdev = dev_get_by_index_rcu(state->net, tuplehash->tuple.out.ifidx);
 		if (!xmit.outdev) {
 			flow_offload_teardown(flow);
 			return NF_DROP;
@@ -1196,7 +1196,7 @@ static int nf_flow_queue_xmit6(struct sk_buff *skb,
 	switch (tuplehash->tuple.xmit_type) {
 	case FLOW_OFFLOAD_XMIT_NEIGH:
 		rt = dst_rt6_info(tuplehash->tuple.dst_cache);
-		xmit.outdev = dev_get_by_index_rcu(state->net, tuplehash->tuple.ifidx);
+		xmit.outdev = dev_get_by_index_rcu(state->net, tuplehash->tuple.out.ifidx);
 		if (!xmit.outdev) {
 			flow_offload_teardown(flow);
 			return NF_DROP;
-- 
2.47.3


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH nf,v6 2/3] netfilter: flowtable: cache destination hw address for XMIT_NEIGH type
  2026-11-20 22:52 [PATCH nf,v6 1/3] netfilter: flowtable: remove redundant ifidx field in tuple output union Pablo Neira Ayuso
@ 2026-11-20 22:52 ` Pablo Neira Ayuso
  2026-11-21 23:55   ` Julius Bairaktaris
  2026-11-20 22:52 ` [PATCH nf,v6 3/3] netfilter: flowtable: unify direct and neigh xmit path Pablo Neira Ayuso
  1 sibling, 1 reply; 8+ messages in thread
From: Pablo Neira Ayuso @ 2026-11-20 22:52 UTC (permalink / raw)
  To: netfilter-devel

Since commit b5964aac51e0 ("netfilter: flowtable: consolidate xmit
path"), a flow offloaded with FLOW_OFFLOAD_XMIT_NEIGH keeps being
forwarded with destination MAC 00:00:00:00:00:00 after the next hop's
neighbour entry has been removed. Nothing resolves the next hop again,
so the flow stays black-holed for as long as it keeps sending.

Cache the destination hw address in the flow entry, just like
XMIT_DIRECT does. Use the flowtable GC to validate that there is a
neighbour entry that is still valid. Otherwise, if the neighbour entry
is stale, trigger a probe.

Skip check the stale neighbour check for non-Ethernet devices such as
WireGuard or GRE by checking for all zero destination hw address,
otherwise the flow entries are incorrectly torn down.

Fixes: b5964aac51e0 ("netfilter: flowtable: consolidate xmit path")
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
v6: skip check for stale neighbout entries in case non-ethernet device
    is use in the flowtable tx path.

 net/ipv4/ipip.c                    | 18 ++++++++
 net/ipv6/ip6_tunnel.c              | 41 +++++++++++++-----
 net/netfilter/nf_flow_table_core.c | 67 ++++++++++++++++++++++++++++--
 net/netfilter/nf_flow_table_ip.c   | 41 ++++--------------
 net/netfilter/nf_flow_table_path.c | 11 ++++-
 5 files changed, 130 insertions(+), 48 deletions(-)

diff --git a/net/ipv4/ipip.c b/net/ipv4/ipip.c
index 15189e1fa068..4079aa385fea 100644
--- a/net/ipv4/ipip.c
+++ b/net/ipv4/ipip.c
@@ -358,6 +358,8 @@ static int ipip_fill_forward_path(struct net_device_path_ctx *ctx,
 {
 	struct ip_tunnel *tunnel = netdev_priv(ctx->dev);
 	const struct iphdr *tiph = &tunnel->parms.iph;
+	unsigned char ha[ETH_ALEN];
+	struct neighbour *n;
 	struct rtable *rt;
 
 	if (ctx->ether_type != cpu_to_be16(ETH_P_IP))
@@ -375,6 +377,21 @@ static int ipip_fill_forward_path(struct net_device_path_ctx *ctx,
 	if (IS_ERR(rt))
 		return PTR_ERR(rt);
 
+	n = dst_neigh_lookup(&rt->dst, &tiph->daddr);
+	if (!n) {
+		ip_rt_put(rt);
+		return -ENOENT;
+	}
+
+	if (n->dev->addr_len != ETH_ALEN ||
+	    !(READ_ONCE(n->nud_state) & NUD_VALID)) {
+		ip_rt_put(rt);
+		neigh_release(n);
+		return -EINVAL;
+	}
+	neigh_ha_snapshot(ha, n, n->dev);
+	neigh_release(n);
+
 	path->type = DEV_PATH_TUN;
 	path->tun.src_v4.s_addr = tiph->saddr;
 	path->tun.dst_v4.s_addr = tiph->daddr;
@@ -383,6 +400,7 @@ static int ipip_fill_forward_path(struct net_device_path_ctx *ctx,
 	path->tun.dst = &rt->dst;
 	path->dev = ctx->dev;
 
+	memcpy(ctx->daddr, ha, ETH_ALEN);
 	ctx->dev = rt->dst.dev;
 
 	return 0;
diff --git a/net/ipv6/ip6_tunnel.c b/net/ipv6/ip6_tunnel.c
index 64a184bca467..84d26d9454a9 100644
--- a/net/ipv6/ip6_tunnel.c
+++ b/net/ipv6/ip6_tunnel.c
@@ -1840,7 +1840,9 @@ static int ip6_tnl_fill_forward_path(struct net_device_path_ctx *ctx,
 				     struct net_device_path *path)
 {
 	struct ip6_tnl *t = netdev_priv(ctx->dev);
+	unsigned char ha[ETH_ALEN];
 	struct dst_entry *dst;
+	struct neighbour *n;
 	struct flowi6 fl6;
 	int err;
 
@@ -1863,20 +1865,37 @@ static int ip6_tnl_fill_forward_path(struct net_device_path_ctx *ctx,
 	fl6.flowi6_proto = 0;
 
 	dst = ip6_route_output(dev_net(ctx->dev), NULL, &fl6);
-	if (!dst->error) {
-		path->type = DEV_PATH_TUN;
-		path->tun.src_v6 = fl6.saddr;
-		path->tun.dst_v6 = fl6.daddr;
-		path->tun.inner_proto = IPPROTO_IPV6;
-		path->tun.encap_proto = AF_INET6;
-		path->tun.dst = dst;
-		path->dev = ctx->dev;
-		ctx->dev = dst->dev;
+	err = dst->error;
+	if (err) {
+		dst_release(dst);
+		return err;
 	}
 
-	err = dst->error;
-	if (err)
+	n = dst_neigh_lookup(dst, &fl6.daddr);
+	if (!n) {
 		dst_release(dst);
+		return -ENOENT;
+	}
+
+	if (n->dev->addr_len != ETH_ALEN ||
+	    !(READ_ONCE(n->nud_state) & NUD_VALID)) {
+		dst_release(dst);
+		neigh_release(n);
+		return -EINVAL;
+	}
+	neigh_ha_snapshot(ha, n, n->dev);
+	neigh_release(n);
+
+	path->type = DEV_PATH_TUN;
+	path->tun.src_v6 = fl6.saddr;
+	path->tun.dst_v6 = fl6.daddr;
+	path->tun.inner_proto = IPPROTO_IPV6;
+	path->tun.encap_proto = AF_INET6;
+	path->tun.dst = dst;
+	path->dev = ctx->dev;
+
+	memcpy(ctx->daddr, ha, ETH_ALEN);
+	ctx->dev = dst->dev;
 
 	return err;
 }
diff --git a/net/netfilter/nf_flow_table_core.c b/net/netfilter/nf_flow_table_core.c
index a7b4fc5766a9..80c5784140db 100644
--- a/net/netfilter/nf_flow_table_core.c
+++ b/net/netfilter/nf_flow_table_core.c
@@ -5,6 +5,7 @@
 #include <linux/netfilter.h>
 #include <linux/rhashtable.h>
 #include <linux/netdevice.h>
+#include <linux/etherdevice.h>
 #include <net/ip.h>
 #include <net/ip6_route.h>
 #include <net/netfilter/nf_tables.h>
@@ -140,8 +141,11 @@ static int flow_offload_fill_route(struct flow_offload *flow,
 		       ETH_ALEN);
 		flow_tuple->out.ifidx = route->tuple[dir].out.ifindex;
 		break;
-	case FLOW_OFFLOAD_XMIT_XFRM:
 	case FLOW_OFFLOAD_XMIT_NEIGH:
+		memcpy(flow_tuple->out.h_dest, route->tuple[dir].out.h_dest,
+		       ETH_ALEN);
+		fallthrough;
+	case FLOW_OFFLOAD_XMIT_XFRM:
 		flow_tuple->out.ifidx = route->tuple[dir].out.ifindex;
 		flow_tuple->dst_cache = dst;
 		flow_tuple->dst_cookie = flow_offload_dst_cookie(flow_tuple);
@@ -573,6 +577,63 @@ static void nf_flow_table_extend_ct_timeout(struct nf_conn *ct)
 	nf_ct_put(ct);
 }
 
+static inline bool nf_flow_dst_check_gc(struct flow_offload *flow, int dir)
+{
+	struct flow_offload_tuple *tuple = &flow->tuplehash[dir].tuple;
+	struct flow_offload_tuple *other_tuple;
+	unsigned char ha[ETH_ALEN];
+	struct neighbour *n;
+	const void *daddr;
+	u8 state;
+	bool ret;
+
+	if (!tuple->dst_cache)
+		return true;
+
+	if (!dst_check(tuple->dst_cache, tuple->dst_cookie))
+		return false;
+
+	if (tuple->xmit_type != FLOW_OFFLOAD_XMIT_NEIGH)
+		return true;
+
+	/* non-Ethernet device, skip check. */
+	if (is_zero_ether_addr(tuple->out.h_dest))
+		return true;
+
+	other_tuple = &flow->tuplehash[!dir].tuple;
+	if (other_tuple->tun_num)
+		daddr = &other_tuple->tun.src_v6;
+	else
+		daddr = &other_tuple->src_v6;
+
+	n = dst_neigh_lookup(tuple->dst_cache, daddr);
+	if (!n)
+		return false;
+
+	if (n->dev->addr_len != ETH_ALEN) {
+		neigh_release(n);
+		return false;
+	}
+	neigh_ha_snapshot(ha, n, n->dev);
+
+	state = READ_ONCE(n->nud_state);
+	if (state & NUD_VALID) {
+		if (ether_addr_equal(ha, tuple->out.h_dest))
+			ret = true;
+		else
+			ret = false;
+
+		if (state & NUD_STALE)
+			neigh_event_send(n, NULL);
+	} else {
+		ret = false;
+	}
+
+	neigh_release(n);
+
+	return ret;
+}
+
 static void nf_flow_offload_gc_step(struct nf_flowtable *flow_table,
 				    struct flow_offload *flow, void *data)
 {
@@ -585,8 +646,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_check_gc(flow, FLOW_OFFLOAD_DIR_ORIGINAL) ||
+	    !nf_flow_dst_check_gc(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_ip.c b/net/netfilter/nf_flow_table_ip.c
index 115c54ad4633..5971d2584c5c 100644
--- a/net/netfilter/nf_flow_table_ip.c
+++ b/net/netfilter/nf_flow_table_ip.c
@@ -590,8 +590,7 @@ static int nf_flow_pppoe_push(struct sk_buff *skb, u16 id,
 
 static int nf_flow_tunnel_ip_push(struct net *net, struct sk_buff *skb,
 				  struct flow_offload_tuple *tuple,
-				  struct dst_entry *dst,
-				  union nf_inet_addr **ip_addr)
+				  struct dst_entry *dst)
 {
 	__be16 frag_off = 0;
 	struct iphdr *iph;
@@ -651,15 +650,12 @@ static int nf_flow_tunnel_ip_push(struct net *net, struct sk_buff *skb,
 	__ip_select_ident(net, iph, skb_shinfo(skb)->gso_segs ?: 1);
 	ip_send_check(iph);
 
-	*ip_addr = (union nf_inet_addr *)&tuple->tun.src_v4;
-
 	return 0;
 }
 
 static int nf_flow_tunnel_ip6_push(struct net *net, struct sk_buff *skb,
 				   struct flow_offload_tuple *tuple,
-				   struct dst_entry *dst,
-				   union nf_inet_addr **ip_addr)
+				   struct dst_entry *dst)
 {
 	struct flowi6 fl6 = {
 		.daddr = tuple->tun.src_v6,
@@ -718,21 +714,18 @@ static int nf_flow_tunnel_ip6_push(struct net *net, struct sk_buff *skb,
 	ipv6_hdr(skb)->payload_len = htons(skb->len - sizeof(*ip6h));
 	IP6CB(skb)->nhoff = offsetof(struct ipv6hdr, nexthdr);
 
-	*ip_addr = (union nf_inet_addr *)&tuple->tun.src_v6;
-
 	return 0;
 }
 
 static int nf_flow_tunnel_push(struct net *net, struct sk_buff *skb,
 			       struct flow_offload_tuple *tuple,
-			       struct dst_entry *dst,
-			       union nf_inet_addr **ip_addr)
+			       struct dst_entry *dst)
 {
 	switch (tuple->tun.encap_proto) {
 	case AF_INET:
-		return nf_flow_tunnel_ip_push(net, skb, tuple, dst, ip_addr);
+		return nf_flow_tunnel_ip_push(net, skb, tuple, dst);
 	case AF_INET6:
-		return nf_flow_tunnel_ip6_push(net, skb, tuple, dst, ip_addr);
+		return nf_flow_tunnel_ip6_push(net, skb, tuple, dst);
 	default:
 		return 0;
 	}
@@ -842,9 +835,7 @@ static int nf_flow_queue_xmit4(struct sk_buff *skb,
 	struct flow_offload_tuple *other_tuple;
 	enum flow_offload_tuple_dir dir;
 	struct nf_flow_xmit xmit = {};
-	union nf_inet_addr *ip_addr;
 	struct flow_offload *flow;
-	struct neighbour *neigh;
 	struct rtable *rt;
 
 	if (unlikely(tuplehash->tuple.xmit_type == FLOW_OFFLOAD_XMIT_XFRM)) {
@@ -858,10 +849,9 @@ static int nf_flow_queue_xmit4(struct sk_buff *skb,
 	dir = tuplehash->tuple.dir;
 	flow = container_of(tuplehash, struct flow_offload, tuplehash[dir]);
 	other_tuple = &flow->tuplehash[!dir].tuple;
-	ip_addr = (union nf_inet_addr *)&other_tuple->src_v4;
 
 	if (nf_flow_tunnel_push(state->net, skb, other_tuple,
-				tuplehash->tuple.dst_cache, &ip_addr) < 0)
+				tuplehash->tuple.dst_cache) < 0)
 		return NF_DROP;
 
 	switch (tuplehash->tuple.xmit_type) {
@@ -872,12 +862,7 @@ static int nf_flow_queue_xmit4(struct sk_buff *skb,
 			flow_offload_teardown(flow);
 			return NF_DROP;
 		}
-		neigh = ip_neigh_gw4(rt->dst.dev, rt_nexthop(rt, ip_addr->ip));
-		if (IS_ERR(neigh)) {
-			flow_offload_teardown(flow);
-			return NF_DROP;
-		}
-		xmit.dest = neigh->ha;
+		xmit.dest = tuplehash->tuple.out.h_dest;
 		skb_dst_drop(skb);
 		skb_dst_set_noref(skb, &rt->dst);
 		break;
@@ -1171,9 +1156,7 @@ static int nf_flow_queue_xmit6(struct sk_buff *skb,
 	struct flow_offload_tuple *other_tuple;
 	enum flow_offload_tuple_dir dir;
 	struct nf_flow_xmit xmit = {};
-	union nf_inet_addr *ip_addr;
 	struct flow_offload *flow;
-	struct neighbour *neigh;
 	struct rt6_info *rt;
 
 	if (unlikely(tuplehash->tuple.xmit_type == FLOW_OFFLOAD_XMIT_XFRM)) {
@@ -1187,10 +1170,9 @@ static int nf_flow_queue_xmit6(struct sk_buff *skb,
 	dir = tuplehash->tuple.dir;
 	flow = container_of(tuplehash, struct flow_offload, tuplehash[dir]);
 	other_tuple = &flow->tuplehash[!dir].tuple;
-	ip_addr = (union nf_inet_addr *)&other_tuple->src_v6;
 
 	if (nf_flow_tunnel_push(state->net, skb, other_tuple,
-				tuplehash->tuple.dst_cache, &ip_addr) < 0)
+				tuplehash->tuple.dst_cache) < 0)
 		return NF_DROP;
 
 	switch (tuplehash->tuple.xmit_type) {
@@ -1201,12 +1183,7 @@ static int nf_flow_queue_xmit6(struct sk_buff *skb,
 			flow_offload_teardown(flow);
 			return NF_DROP;
 		}
-		neigh = ip_neigh_gw6(rt->dst.dev, rt6_nexthop(rt, &ip_addr->in6));
-		if (IS_ERR(neigh)) {
-			flow_offload_teardown(flow);
-			return NF_DROP;
-		}
-		xmit.dest = neigh->ha;
+		xmit.dest = tuplehash->tuple.out.h_dest;
 		skb_dst_drop(skb);
 		skb_dst_set_noref(skb, &rt->dst);
 		break;
diff --git a/net/netfilter/nf_flow_table_path.c b/net/netfilter/nf_flow_table_path.c
index 841f099434d9..5923ef9cdaef 100644
--- a/net/netfilter/nf_flow_table_path.c
+++ b/net/netfilter/nf_flow_table_path.c
@@ -57,6 +57,7 @@ static int nft_dev_fill_forward_path(const struct dst_entry *dst_cache,
 	};
 	struct neighbour *n;
 	u8 nud_state;
+	int ret;
 
 	if (!nft_is_valid_ether_device(dev)) {
 		eth_zero_addr(ha);
@@ -79,7 +80,12 @@ static int nft_dev_fill_forward_path(const struct dst_entry *dst_cache,
 out:
 	ether_addr_copy(ctx.daddr, ha);
 
-	return dev_fill_forward_path(&ctx, stack);
+	ret = dev_fill_forward_path(&ctx, stack);
+
+	if (memcmp(ctx.daddr, ha, ETH_ALEN))
+		ether_addr_copy(ha, ctx.daddr);
+
+	return ret;
 }
 
 struct nft_forward_info {
@@ -259,9 +265,10 @@ static int nft_dev_forward_path(const struct nft_pktinfo *pkt,
 	route->tuple[!dir].in.num_encaps = info.num_encaps;
 	route->tuple[!dir].in.ingress_vlans = info.ingress_vlans;
 
+	memcpy(route->tuple[dir].out.h_dest, info.h_dest, ETH_ALEN);
+
 	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].xmit_type = info.xmit_type;
 	}
 	route->tuple[dir].out.needs_gso_segment = info.needs_gso_segment;
-- 
2.47.3


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH nf,v6 3/3] netfilter: flowtable: unify direct and neigh xmit path
  2026-11-20 22:52 [PATCH nf,v6 1/3] netfilter: flowtable: remove redundant ifidx field in tuple output union Pablo Neira Ayuso
  2026-11-20 22:52 ` [PATCH nf,v6 2/3] netfilter: flowtable: cache destination hw address for XMIT_NEIGH type Pablo Neira Ayuso
@ 2026-11-20 22:52 ` Pablo Neira Ayuso
  1 sibling, 0 replies; 8+ messages in thread
From: Pablo Neira Ayuso @ 2026-11-20 22:52 UTC (permalink / raw)
  To: netfilter-devel

Since commit ("netfilter: flowtable: cache destination hw address for
XMIT_NEIGH type"), it is possible to possible to consolidate xmit path
further since the caching of the neighbour entry. To make it happen, do
not attach the cached dst to the skbuff, let's just transmit it via
dev_queue_xmit() without it.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
---
v3: no changes

 net/netfilter/nf_flow_table_ip.c | 60 ++++++++------------------------
 1 file changed, 14 insertions(+), 46 deletions(-)

diff --git a/net/netfilter/nf_flow_table_ip.c b/net/netfilter/nf_flow_table_ip.c
index 5971d2584c5c..83c24d7a3925 100644
--- a/net/netfilter/nf_flow_table_ip.c
+++ b/net/netfilter/nf_flow_table_ip.c
@@ -854,31 +854,15 @@ static int nf_flow_queue_xmit4(struct sk_buff *skb,
 				tuplehash->tuple.dst_cache) < 0)
 		return NF_DROP;
 
-	switch (tuplehash->tuple.xmit_type) {
-	case FLOW_OFFLOAD_XMIT_NEIGH:
-		rt = dst_rtable(tuplehash->tuple.dst_cache);
-		xmit.outdev = dev_get_by_index_rcu(state->net, tuplehash->tuple.out.ifidx);
-		if (!xmit.outdev) {
-			flow_offload_teardown(flow);
-			return NF_DROP;
-		}
-		xmit.dest = tuplehash->tuple.out.h_dest;
-		skb_dst_drop(skb);
-		skb_dst_set_noref(skb, &rt->dst);
-		break;
-	case FLOW_OFFLOAD_XMIT_DIRECT:
-		xmit.outdev = dev_get_by_index_rcu(state->net, tuplehash->tuple.out.ifidx);
-		if (!xmit.outdev) {
-			flow_offload_teardown(flow);
-			return NF_DROP;
-		}
-		xmit.dest = tuplehash->tuple.out.h_dest;
-		xmit.source = tuplehash->tuple.out.h_source;
-		break;
-	default:
-		WARN_ON_ONCE(1);
+	xmit.outdev = dev_get_by_index_rcu(state->net, tuplehash->tuple.out.ifidx);
+	if (!xmit.outdev) {
+		flow_offload_teardown(flow);
 		return NF_DROP;
 	}
+	xmit.dest = tuplehash->tuple.out.h_dest;
+	if (tuplehash->tuple.xmit_type == FLOW_OFFLOAD_XMIT_DIRECT)
+		xmit.source = tuplehash->tuple.out.h_source;
+
 	xmit.tuple = other_tuple;
 	xmit.needs_gso_segment = tuplehash->tuple.needs_gso_segment;
 
@@ -1175,31 +1159,15 @@ static int nf_flow_queue_xmit6(struct sk_buff *skb,
 				tuplehash->tuple.dst_cache) < 0)
 		return NF_DROP;
 
-	switch (tuplehash->tuple.xmit_type) {
-	case FLOW_OFFLOAD_XMIT_NEIGH:
-		rt = dst_rt6_info(tuplehash->tuple.dst_cache);
-		xmit.outdev = dev_get_by_index_rcu(state->net, tuplehash->tuple.out.ifidx);
-		if (!xmit.outdev) {
-			flow_offload_teardown(flow);
-			return NF_DROP;
-		}
-		xmit.dest = tuplehash->tuple.out.h_dest;
-		skb_dst_drop(skb);
-		skb_dst_set_noref(skb, &rt->dst);
-		break;
-	case FLOW_OFFLOAD_XMIT_DIRECT:
-		xmit.outdev = dev_get_by_index_rcu(state->net, tuplehash->tuple.out.ifidx);
-		if (!xmit.outdev) {
-			flow_offload_teardown(flow);
-			return NF_DROP;
-		}
-		xmit.dest = tuplehash->tuple.out.h_dest;
-		xmit.source = tuplehash->tuple.out.h_source;
-		break;
-	default:
-		WARN_ON_ONCE(1);
+	xmit.outdev = dev_get_by_index_rcu(state->net, tuplehash->tuple.out.ifidx);
+	if (!xmit.outdev) {
+		flow_offload_teardown(flow);
 		return NF_DROP;
 	}
+	xmit.dest = tuplehash->tuple.out.h_dest;
+	if (tuplehash->tuple.xmit_type == FLOW_OFFLOAD_XMIT_DIRECT)
+		xmit.source = tuplehash->tuple.out.h_source;
+
 	xmit.tuple = other_tuple;
 	xmit.needs_gso_segment = tuplehash->tuple.needs_gso_segment;
 
-- 
2.47.3


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH nf,v6 2/3] netfilter: flowtable: cache destination hw address for XMIT_NEIGH type
  2026-11-20 22:52 ` [PATCH nf,v6 2/3] netfilter: flowtable: cache destination hw address for XMIT_NEIGH type Pablo Neira Ayuso
@ 2026-11-21 23:55   ` Julius Bairaktaris
  2026-11-22  0:25     ` Pablo Neira Ayuso
  0 siblings, 1 reply; 8+ messages in thread
From: Julius Bairaktaris @ 2026-11-21 23:55 UTC (permalink / raw)
  To: pablo; +Cc: netfilter-devel

On Fri, Nov 20, 2026 at 11:52:26PM +0100, Pablo Neira Ayuso wrote:
> @@ -383,6 +400,7 @@ static int ipip_fill_forward_path(struct net_device_path_ctx *ctx,
>  	path->tun.dst = &rt->dst;
>  	path->dev = ctx->dev;
>  
> +	memcpy(ctx->daddr, ha, ETH_ALEN);
>  	ctx->dev = rt->dst.dev;

With this, an ipip or ip6tnl tunnel whose underlay device is a bridge
gets offloaded: br_fill_forward_path() finds the outer next hop's MAC
in the fdb and nft_dev_path_info() makes the tuple
FLOW_OFFLOAD_XMIT_DIRECT. On nf-next without the series such a flow is
not offloaded.

> +static inline bool nf_flow_dst_check_gc(struct flow_offload *flow, int dir)
> +{
[...]
> +	if (tuple->xmit_type != FLOW_OFFLOAD_XMIT_NEIGH)
> +		return true;

For that direct tuple the gc returns here and never compares out.h_dest
with the neighbour entry. When the next hop behind the bridge changes its
MAC and the router's neighbour entry is replaced, the flow keeps sending
to the old MAC: IPIP and IP6IP6 over a bridge stall, 3 of 3 runs each
(QEMU, nf-next 994089a3fa38 with this series). IPIP over a plain port is
neigh xmit, is torn down and offloaded again, 3 of 3. A bridged direct
flow without a tunnel stalls the same way, here (3 of 3) and on nf-next
without the series (1 run).

Julius

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH nf,v6 2/3] netfilter: flowtable: cache destination hw address for XMIT_NEIGH type
  2026-11-21 23:55   ` Julius Bairaktaris
@ 2026-11-22  0:25     ` Pablo Neira Ayuso
  2026-11-22  0:35       ` Pablo Neira Ayuso
  0 siblings, 1 reply; 8+ messages in thread
From: Pablo Neira Ayuso @ 2026-11-22  0:25 UTC (permalink / raw)
  To: Julius Bairaktaris; +Cc: netfilter-devel

On Sun, Nov 22, 2026 at 12:55:48AM +0100, Julius Bairaktaris wrote:
> On Fri, Nov 20, 2026 at 11:52:26PM +0100, Pablo Neira Ayuso wrote:
> > @@ -383,6 +400,7 @@ static int ipip_fill_forward_path(struct net_device_path_ctx *ctx,
> >  	path->tun.dst = &rt->dst;
> >  	path->dev = ctx->dev;
> >  
> > +	memcpy(ctx->daddr, ha, ETH_ALEN);
> >  	ctx->dev = rt->dst.dev;
> 
> With this, an ipip or ip6tnl tunnel whose underlay device is a bridge
> gets offloaded: br_fill_forward_path() finds the outer next hop's MAC
> in the fdb and nft_dev_path_info() makes the tuple
> FLOW_OFFLOAD_XMIT_DIRECT. On nf-next without the series such a flow is
> not offloaded.
> 
> > +static inline bool nf_flow_dst_check_gc(struct flow_offload *flow, int dir)
> > +{
> [...]
> > +	if (tuple->xmit_type != FLOW_OFFLOAD_XMIT_NEIGH)
> > +		return true;
> 
> For that direct tuple the gc returns here and never compares out.h_dest
> with the neighbour entry. When the next hop behind the bridge changes its
> MAC and the router's neighbour entry is replaced, the flow keeps sending
> to the old MAC: IPIP and IP6IP6 over a bridge stall, 3 of 3 runs each
> (QEMU, nf-next 994089a3fa38 with this series). IPIP over a plain port is
> neigh xmit, is torn down and offloaded again, 3 of 3. A bridged direct
> flow without a tunnel stalls the same way, here (3 of 3) and on nf-next
> without the series (1 run).

So you're suggesting nf_flow_dst_check_gc() should run for
FLOW_OFFLOAD_XMIT_DIRECT too?

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH nf,v6 2/3] netfilter: flowtable: cache destination hw address for XMIT_NEIGH type
  2026-11-22  0:25     ` Pablo Neira Ayuso
@ 2026-11-22  0:35       ` Pablo Neira Ayuso
  2026-11-22  0:57         ` Pablo Neira Ayuso
  0 siblings, 1 reply; 8+ messages in thread
From: Pablo Neira Ayuso @ 2026-11-22  0:35 UTC (permalink / raw)
  To: Julius Bairaktaris; +Cc: netfilter-devel

On Sun, Nov 22, 2026 at 01:25:19AM +0100, Pablo Neira Ayuso wrote:
> On Sun, Nov 22, 2026 at 12:55:48AM +0100, Julius Bairaktaris wrote:
> > On Fri, Nov 20, 2026 at 11:52:26PM +0100, Pablo Neira Ayuso wrote:
> > > @@ -383,6 +400,7 @@ static int ipip_fill_forward_path(struct net_device_path_ctx *ctx,
> > >  	path->tun.dst = &rt->dst;
> > >  	path->dev = ctx->dev;
> > >  
> > > +	memcpy(ctx->daddr, ha, ETH_ALEN);
> > >  	ctx->dev = rt->dst.dev;
> > 
> > With this, an ipip or ip6tnl tunnel whose underlay device is a bridge
> > gets offloaded: br_fill_forward_path() finds the outer next hop's MAC
> > in the fdb and nft_dev_path_info() makes the tuple
> > FLOW_OFFLOAD_XMIT_DIRECT. On nf-next without the series such a flow is
> > not offloaded.
> > 
> > > +static inline bool nf_flow_dst_check_gc(struct flow_offload *flow, int dir)
> > > +{
> > [...]
> > > +	if (tuple->xmit_type != FLOW_OFFLOAD_XMIT_NEIGH)
> > > +		return true;
> > 
> > For that direct tuple the gc returns here and never compares out.h_dest
> > with the neighbour entry. When the next hop behind the bridge changes its
> > MAC and the router's neighbour entry is replaced, the flow keeps sending
> > to the old MAC: IPIP and IP6IP6 over a bridge stall, 3 of 3 runs each
> > (QEMU, nf-next 994089a3fa38 with this series). IPIP over a plain port is
> > neigh xmit, is torn down and offloaded again, 3 of 3. A bridged direct
> > flow without a tunnel stalls the same way, here (3 of 3) and on nf-next
> > without the series (1 run).
> 
> So you're suggesting nf_flow_dst_check_gc() should run for
> FLOW_OFFLOAD_XMIT_DIRECT too?

This is what this patch does:

  [PATCH nf-next] netfilter: flowtable: teardown flow reaching bridge port on fdb updates

Until that gets merged, stall is expected.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH nf,v6 2/3] netfilter: flowtable: cache destination hw address for XMIT_NEIGH type
  2026-11-22  0:35       ` Pablo Neira Ayuso
@ 2026-11-22  0:57         ` Pablo Neira Ayuso
  0 siblings, 0 replies; 8+ messages in thread
From: Pablo Neira Ayuso @ 2026-11-22  0:57 UTC (permalink / raw)
  To: Julius Bairaktaris; +Cc: netfilter-devel

On Sun, Nov 22, 2026 at 01:35:18AM +0100, Pablo Neira Ayuso wrote:
> On Sun, Nov 22, 2026 at 01:25:19AM +0100, Pablo Neira Ayuso wrote:
> > On Sun, Nov 22, 2026 at 12:55:48AM +0100, Julius Bairaktaris wrote:
> > > On Fri, Nov 20, 2026 at 11:52:26PM +0100, Pablo Neira Ayuso wrote:
> > > > @@ -383,6 +400,7 @@ static int ipip_fill_forward_path(struct net_device_path_ctx *ctx,
> > > >  	path->tun.dst = &rt->dst;
> > > >  	path->dev = ctx->dev;
> > > >  
> > > > +	memcpy(ctx->daddr, ha, ETH_ALEN);
> > > >  	ctx->dev = rt->dst.dev;
> > > 
> > > With this, an ipip or ip6tnl tunnel whose underlay device is a bridge
> > > gets offloaded: br_fill_forward_path() finds the outer next hop's MAC
> > > in the fdb and nft_dev_path_info() makes the tuple
> > > FLOW_OFFLOAD_XMIT_DIRECT. On nf-next without the series such a flow is
> > > not offloaded.
> > > 
> > > > +static inline bool nf_flow_dst_check_gc(struct flow_offload *flow, int dir)
> > > > +{
> > > [...]
> > > > +	if (tuple->xmit_type != FLOW_OFFLOAD_XMIT_NEIGH)
> > > > +		return true;
> > > 
> > > For that direct tuple the gc returns here and never compares out.h_dest
> > > with the neighbour entry. When the next hop behind the bridge changes its
> > > MAC and the router's neighbour entry is replaced, the flow keeps sending
> > > to the old MAC: IPIP and IP6IP6 over a bridge stall, 3 of 3 runs each
> > > (QEMU, nf-next 994089a3fa38 with this series). IPIP over a plain port is
> > > neigh xmit, is torn down and offloaded again, 3 of 3. A bridged direct
> > > flow without a tunnel stalls the same way, here (3 of 3) and on nf-next
> > > without the series (1 run).
> > 
> > So you're suggesting nf_flow_dst_check_gc() should run for
> > FLOW_OFFLOAD_XMIT_DIRECT too?
> 
> This is what this patch does:
> 
>   [PATCH nf-next] netfilter: flowtable: teardown flow reaching bridge port on fdb updates
> 
> Until that gets merged, stall is expected.

Ah, I suspect you refer to the XMIT_DIRECT case when hw offload is
enabled, which indeed have dst/neigh entries.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH nf,v6 2/3] netfilter: flowtable: cache destination hw address for XMIT_NEIGH type
@ 2026-11-22 12:02 Julius Bairaktaris
  0 siblings, 0 replies; 8+ messages in thread
From: Julius Bairaktaris @ 2026-11-22 12:02 UTC (permalink / raw)
  To: Pablo Neira Ayuso; +Cc: netfilter-devel

On Sun, Nov 22, 2026 at 01:57:13AM +0100, Pablo Neira Ayuso wrote:
> > > So you're suggesting nf_flow_dst_check_gc() should run for
> > > FLOW_OFFLOAD_XMIT_DIRECT too?

For a direct tuple that has a dst_cache, yes: the h_dest comparison,
which runs only for XMIT_NEIGH now. A tuple without a dst_cache has no
neighbour to look up.

> > This is what this patch does:
> >
> > [PATCH nf-next] netfilter: flowtable: teardown flow reaching bridge port on fdb updates
> >
> > Until that gets merged, stall is expected.

The fdb check does not see a MAC change: it looks up the old h_dest,
whose entry stays on the same port or ages out, and both keep the flow.
With v11 of the roaming series on top of your v6, the bridge cases with
no tunnel, IPIP and IP6IP6 still stall, 1 run each.

> Ah, I suspect you refer to the XMIT_DIRECT case when hw offload is
> enabled, which indeed have dst/neigh entries.

No, the software flowtable: the tunnel's underlay device is a bridge,
which makes the tuple direct, and flow_offload_fill_route() keeps its
dst_cache because the reply direction has a tunnel.

Julius

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2026-11-22 12:02 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-20 22:52 [PATCH nf,v6 1/3] netfilter: flowtable: remove redundant ifidx field in tuple output union Pablo Neira Ayuso
2026-11-20 22:52 ` [PATCH nf,v6 2/3] netfilter: flowtable: cache destination hw address for XMIT_NEIGH type Pablo Neira Ayuso
2026-11-21 23:55   ` Julius Bairaktaris
2026-11-22  0:25     ` Pablo Neira Ayuso
2026-11-22  0:35       ` Pablo Neira Ayuso
2026-11-22  0:57         ` Pablo Neira Ayuso
2026-11-20 22:52 ` [PATCH nf,v6 3/3] netfilter: flowtable: unify direct and neigh xmit path Pablo Neira Ayuso
  -- strict thread matches above, loose matches on Subject: below --
2026-11-22 12:02 [PATCH nf,v6 2/3] netfilter: flowtable: cache destination hw address for XMIT_NEIGH type Julius Bairaktaris

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.