* [PATCH net-next v3 0/3] ipv6: tie the dst cookie to the lookup that returned the dst
@ 2026-11-17 9:21 Ralf Lici
2026-11-17 9:21 ` [PATCH net-next v3 1/3] ipv6: stamp the default route node with a fresh serial on link failure Ralf Lici
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Ralf Lici @ 2026-11-17 9:21 UTC (permalink / raw)
To: netdev
Cc: David Ahern, Ido Schimmel, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Simon Horman, Neal Cardwell,
Kuniyuki Iwashima, Steffen Klassert, Herbert Xu, Florian Westphal,
Sabrina Dubroca, Antonio Quartulli, linux-kernel
Hi,
This series implements a first part of the model proposed in [1] to
address the late cookie sampling race: a dst can be stored together with
a cookie read after a FIB change that its lookup did not see, and then
passes dst_check until the next change.
The case that made me post it as a series is xfrm. Adding a policy
restamps every fib6 node, so a socket whose lookup ran just before the
insertion keeps its plain dst and leaks plaintext although the policy
matches. I reproduced it for TCP connect and connected UDP, and the same
window lets a more specific blackhole route be bypassed for routes using
nexthop objects. The ovpn patch [2] hit the same pattern in
dst_cache_set_ip6.
The conversion is initially limited to tcp_v6_connect,
ip6_datagram_dst_update and ip6_sk_dst_lookup_flow. Other TCP TX cache
paths, including established-socket route refills, header rebuilds and
accepted-socket setup, still use late cookie sampling. This gives the
lookup-cookie API a small set of users and concrete fixes to review. If
the approach is accepted, I plan to follow up with a broader conversion
across the networking core and drivers.
Compared to [1], the fallback cookie is 0 instead of the pre-lookup
generation, so fib6_flush_trees is left alone, and nexthop-object dsts
are checked in ip6_dst_check instead of passing the generation down to
ip6_rt_pcpu_alloc. The other cache users (dst_cache, sctp, ipvs,
flowtable, sk_rx_dst, the xfrm bundle cookies) are not converted and
behave as before.
I tested it in a VM with lockdep, PROVE_RCU and DEBUG_ATOMIC_SLEEP,
using a debug-only delay after the lookup to hit the window: no
warnings, and the plaintext and blackhole bypass are gone in these test
cases.
I am targeting net-next to get feedback on the lookup-cookie API and its
incremental adoption before extending the conversion across the
remaining cache users. This series provides the writer-side
prerequisites and converts three socket-cache paths; it does not
complete the conversion. I am not requesting stable backports at this
stage. Backport scope and dependencies can be assessed separately once
the approach has been reviewed.
[1] https://lore.kernel.org/netdev/20260901122501.482920-1-ralf@mandelbit.com/
[2] https://lore.kernel.org/netdev/cover.1789639346.git.ralf@mandelbit.com/
Thanks,
Ralf Lici
Mandelbit Srl
---
Changes since v2 https://lore.kernel.org/all/cover.1794384146.git.ralf@mandelbit.com/
- Rebase onto current net-next, preserving the connected-only cache
lookup introduced by f778e80b3daf ("ipv6: fix cached route reuse for
control messages"). (Jakub)
- Move the serial update after rt6_multipath_rebalance in fib6_ifup and
fib6_ifdown. (Sashiko)
- Add Fixes tags and improve wording. (Sashiko)
- Clarify that this is the groundwork for fixing the race and a partial
conversion to the new API: other users will be covered in a follow-up
series.
Changes since v1 https://lore.kernel.org/netdev/cover.1793806941.git.ralf@mandelbit.com/
- Fix kdoc return statements in patch 2/3. (NIPA)
Ralf Lici (3):
ipv6: stamp the default route node with a fresh serial on link failure
ipv6: add ip6_dst_lookup_flow_cookie
ipv6: use lookup cookies in selected socket dst cache paths
include/net/ip6_route.h | 18 +++++++++----
include/net/ipv6.h | 13 ++++++++++
net/ipv6/datagram.c | 6 +++--
net/ipv6/ip6_output.c | 57 ++++++++++++++++++++++++++++++++++++++---
net/ipv6/route.c | 30 +++++++++++-----------
net/ipv6/tcp_ipv6.c | 5 ++--
6 files changed, 101 insertions(+), 28 deletions(-)
base-commit: 6ff4c5942a301675eb12e5b49d53a81e604624a1
--
2.56.0
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH net-next v3 1/3] ipv6: stamp the default route node with a fresh serial on link failure
2026-11-17 9:21 [PATCH net-next v3 0/3] ipv6: tie the dst cookie to the lookup that returned the dst Ralf Lici
@ 2026-11-17 9:21 ` Ralf Lici
2026-11-17 9:21 ` [PATCH net-next v3 2/3] ipv6: add ip6_dst_lookup_flow_cookie Ralf Lici
2026-11-17 9:21 ` [PATCH net-next v3 3/3] ipv6: use lookup cookies in selected socket dst cache paths Ralf Lici
2 siblings, 0 replies; 4+ messages in thread
From: Ralf Lici @ 2026-11-17 9:21 UTC (permalink / raw)
To: netdev
Cc: David Ahern, Ido Schimmel, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Simon Horman, Neal Cardwell,
Kuniyuki Iwashima, Steffen Klassert, Herbert Xu, Florian Westphal,
Sabrina Dubroca, Antonio Quartulli, linux-kernel
ip6_link_failure invalidates the cached dsts of an RTF_DEFAULT route by
writing -1 into the node's fn_sernum. Once the node already holds -1,
another link failure leaves the serial unchanged, so dsts cached with
that cookie can survive subsequent failures.
The assignment also leaves net->ipv6.fib6_sernum unchanged, making the
invalidation invisible to lookups watching the namespace generation.
Use fib6_update_sernum under tb6_lock to allocate and stamp a fresh
serial. This makes repeated invalidations distinguishable and allows the
lookup-cookie generation checks introduced later in this series to
detect them.
Advancing the namespace generation also invalidates unrelated dsts using
nexthop objects, which are validated against that generation.
Found while reviewing the IPv6 routing code to address the dst-cache
race.
Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Signed-off-by: Ralf Lici <ralf@mandelbit.com>
---
Changes since v2 https://lore.kernel.org/all/143461e2c94a20060ff4c7d6e5eb46c47ac46aa0.1794384146.git.ralf@mandelbit.com/
- Add a Fixes tag referencing the initial git import. (Sashiko)
- Clarify that the nexthop-object invalidation is a harmless side
effect, rather than a deficiency being fixed. (Sashiko)
No changes since v1 https://lore.kernel.org/netdev/5b039a5a24808f2678eedd283c29f8dae514ef5e.1793806941.git.ralf@mandelbit.com/
net/ipv6/route.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/net/ipv6/route.c b/net/ipv6/route.c
index 4a4c5ace63c5..cc505817399b 100644
--- a/net/ipv6/route.c
+++ b/net/ipv6/route.c
@@ -2873,13 +2873,13 @@ static void ip6_link_failure(struct sk_buff *skb)
rt6_remove_exception_rt(rt);
} else {
struct fib6_info *from;
- struct fib6_node *fn;
from = rcu_dereference(rt->from);
- if (from) {
- fn = rcu_dereference(from->fib6_node);
- if (fn && (rt->rt6i_flags & RTF_DEFAULT))
- WRITE_ONCE(fn->fn_sernum, -1);
+ if (from && from->fib6_table &&
+ (rt->rt6i_flags & RTF_DEFAULT)) {
+ spin_lock_bh(&from->fib6_table->tb6_lock);
+ fib6_update_sernum(rt6_exception_net(rt), from);
+ spin_unlock_bh(&from->fib6_table->tb6_lock);
}
}
rcu_read_unlock();
--
2.56.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH net-next v3 2/3] ipv6: add ip6_dst_lookup_flow_cookie
2026-11-17 9:21 [PATCH net-next v3 0/3] ipv6: tie the dst cookie to the lookup that returned the dst Ralf Lici
2026-11-17 9:21 ` [PATCH net-next v3 1/3] ipv6: stamp the default route node with a fresh serial on link failure Ralf Lici
@ 2026-11-17 9:21 ` Ralf Lici
2026-11-17 9:21 ` [PATCH net-next v3 3/3] ipv6: use lookup cookies in selected socket dst cache paths Ralf Lici
2 siblings, 0 replies; 4+ messages in thread
From: Ralf Lici @ 2026-11-17 9:21 UTC (permalink / raw)
To: netdev
Cc: David Ahern, Ido Schimmel, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Simon Horman, Neal Cardwell,
Kuniyuki Iwashima, Steffen Klassert, Herbert Xu, Florian Westphal,
Sabrina Dubroca, Antonio Quartulli, linux-kernel
Persistent dst caches read the validation cookie with rt6_get_cookie
after route lookup has returned. For routes without their own sernum,
this reads the current fn_sernum of the associated node. A concurrent
FIB change or xfrm policy insertion can therefore pair an old dst with a
new serial, allowing subsequent dst_check calls to accept the stale
result until another relevant change.
Add ip6_dst_lookup_flow_cookie to return the dst together with its
validation cookie. Sample the cookie between two reads of the IPv6
generation and return cookie 0 if the generation changed. This lets the
route dst serve the current packet while preventing its subsequent reuse
through cache validation. xfrm bundles retain their existing validation
through their own route and path cookies.
For nexthop-object dsts, return the pre-lookup generation and require
the supplied cookie to match rt->sernum in ip6_dst_check. This also
rejects a dst allocated with a newer serial after route selection.
Existing callers passing rt6_get_cookie retain their validation
behavior.
The generation checks require writers to publish routing changes before
advancing the serial. Move the serial updates in fib6_ifup and
fib6_ifdown after rt6_multipath_rebalance, preserving their existing
invalidation scope. Otherwise, a lookup can observe the new serial while
selecting a nexthop using the old ECMP bounds, without detecting a
generation change.
This establishes the API and writer ordering needed to address late
cookie sampling. The following patch converts selected socket cache
users while other persistent caches are left for follow-up conversions.
Signed-off-by: Ralf Lici <ralf@mandelbit.com>
---
Changes since v2 https://lore.kernel.org/all/e48cac0cdf9f3adcedecbbfff4a314a98bc22d01.1794384146.git.ralf@mandelbit.com/
- Move the serial update after rt6_multipath_rebalance in fib6_ifup and
fib6_ifdown. (Sashiko)
- Clarify that this introduces the new API while the following patch
converts *some* users to it while leaving the rest as follow-up.
Changes since v1 https://lore.kernel.org/netdev/e40f48e925a0950eac99a3f084e485e82cabe88f.1793806941.git.ralf@mandelbit.com/
- Fix kdoc return statement in ip6_dst_lookup_flow and
ip6_dst_lookup_flow_cookie. (NIPA)
include/net/ipv6.h | 13 +++++++++++
net/ipv6/ip6_output.c | 51 +++++++++++++++++++++++++++++++++++++++++--
net/ipv6/route.c | 8 +++----
3 files changed, 66 insertions(+), 6 deletions(-)
diff --git a/include/net/ipv6.h b/include/net/ipv6.h
index 579df1516d25..5a6c66504056 100644
--- a/include/net/ipv6.h
+++ b/include/net/ipv6.h
@@ -1062,6 +1062,11 @@ int ip6_dst_lookup(struct net *net, struct sock *sk, struct dst_entry **dst,
#if IS_ENABLED(CONFIG_IPV6)
struct dst_entry *ip6_dst_lookup_flow(struct net *net, const struct sock *sk, struct flowi6 *fl6,
const struct in6_addr *final_dst);
+struct dst_entry *ip6_dst_lookup_flow_cookie(struct net *net,
+ const struct sock *sk,
+ struct flowi6 *fl6,
+ const struct in6_addr *final_dst,
+ u32 *cookie);
#else
static inline struct dst_entry *ip6_dst_lookup_flow(struct net *net, const struct sock *sk,
struct flowi6 *fl6,
@@ -1069,6 +1074,14 @@ static inline struct dst_entry *ip6_dst_lookup_flow(struct net *net, const struc
{
return ERR_PTR(-EAFNOSUPPORT);
}
+
+static inline struct dst_entry *
+ip6_dst_lookup_flow_cookie(struct net *net, const struct sock *sk,
+ struct flowi6 *fl6, const struct in6_addr *final_dst,
+ u32 *cookie)
+{
+ return ERR_PTR(-EAFNOSUPPORT);
+}
#endif
struct dst_entry *ip6_sk_dst_lookup_flow(struct sock *sk, struct flowi6 *fl6,
diff --git a/net/ipv6/ip6_output.c b/net/ipv6/ip6_output.c
index 3cc911f6618e..b87ccb5586cf 100644
--- a/net/ipv6/ip6_output.c
+++ b/net/ipv6/ip6_output.c
@@ -1279,8 +1279,7 @@ EXPORT_SYMBOL_GPL(ip6_dst_lookup);
*
* This function performs a route lookup on the given flow.
*
- * It returns a valid dst pointer on success, or a pointer encoded
- * error code.
+ * Return: a valid dst pointer on success or a pointer encoded error code.
*/
struct dst_entry *ip6_dst_lookup_flow(struct net *net, const struct sock *sk, struct flowi6 *fl6,
const struct in6_addr *final_dst)
@@ -1300,6 +1299,54 @@ struct dst_entry *ip6_dst_lookup_flow(struct net *net, const struct sock *sk, st
}
EXPORT_SYMBOL_GPL(ip6_dst_lookup_flow);
+/**
+ * ip6_dst_lookup_flow_cookie - perform route lookup on flow with ipsec
+ * and return the matching dst cookie
+ * @net: Network namespace to perform lookup in
+ * @sk: socket which provides route info
+ * @fl6: flow to lookup
+ * @final_dst: final destination address for ipsec lookup
+ * @cookie: where to store the cookie for the returned dst
+ *
+ * Same as ip6_dst_lookup_flow, but also returns the cookie describing
+ * the routing state the dst was obtained from. A caller caching the dst
+ * should use this cookie when validating it with dst_check. If the
+ * IPv6 FIB changed during the lookup, a route dst no longer validates
+ * with it. An xfrm bundle is validated by xfrm and ignores the cookie.
+ *
+ * Return: a valid dst pointer on success or a pointer encoded error code.
+ */
+struct dst_entry *ip6_dst_lookup_flow_cookie(struct net *net,
+ const struct sock *sk,
+ struct flowi6 *fl6,
+ const struct in6_addr *final_dst,
+ u32 *cookie)
+{
+ const struct rt6_info *rt;
+ struct dst_entry *dst;
+ int gen0, gen1;
+
+ gen0 = rt_genid_ipv6(net);
+ /* read the generation before looking at the FIB or xfrm policies */
+ smp_rmb();
+
+ dst = ip6_dst_lookup_flow(net, sk, fl6, final_dst);
+ if (IS_ERR(dst))
+ return dst;
+
+ rt = dst_rt6_info(dst);
+ *cookie = rt->sernum ? gen0 : rt6_get_cookie(rt);
+
+ /* keep the FIB and cookie reads before the final generation read */
+ smp_rmb();
+ gen1 = rt_genid_ipv6(net);
+ if (unlikely(gen0 != gen1))
+ *cookie = 0;
+
+ return dst;
+}
+EXPORT_SYMBOL_GPL(ip6_dst_lookup_flow_cookie);
+
/**
* ip6_sk_dst_lookup_flow - perform socket cached route lookup on flow
* @sk: socket which provides the dst cache and route info
diff --git a/net/ipv6/route.c b/net/ipv6/route.c
index cc505817399b..c54844b83828 100644
--- a/net/ipv6/route.c
+++ b/net/ipv6/route.c
@@ -2817,7 +2817,7 @@ INDIRECT_CALLABLE_SCOPE struct dst_entry *ip6_dst_check(struct dst_entry *dst,
rt = dst_rt6_info(dst);
if (rt->sernum)
- return rt6_is_valid(rt) ? dst : NULL;
+ return (rt6_is_valid(rt) && cookie == rt->sernum) ? dst : NULL;
rcu_read_lock();
@@ -4911,8 +4911,8 @@ static int fib6_ifup(struct fib6_info *rt, void *p_arg)
if (rt != net->ipv6.fib6_null_entry && !rt->nh &&
rt->fib6_nh->fib_nh_dev == arg->dev) {
rt->fib6_nh->fib_nh_flags &= ~arg->nh_flags;
- fib6_update_sernum_upto_root(net, rt);
rt6_multipath_rebalance(rt);
+ fib6_update_sernum_upto_root(net, rt);
}
return 0;
@@ -5015,8 +5015,8 @@ static int fib6_ifdown(struct fib6_info *rt, void *p_arg)
}
rt6_multipath_nh_flags_set(rt, dev, RTNH_F_DEAD |
RTNH_F_LINKDOWN);
- fib6_update_sernum(net, rt);
rt6_multipath_rebalance(rt);
+ fib6_update_sernum(net, rt);
}
return -2;
case NETDEV_CHANGE:
@@ -5024,8 +5024,8 @@ static int fib6_ifdown(struct fib6_info *rt, void *p_arg)
rt->fib6_flags & (RTF_LOCAL | RTF_ANYCAST))
break;
rt->fib6_nh->fib_nh_flags |= RTNH_F_LINKDOWN;
- fib6_update_sernum(net, rt);
rt6_multipath_rebalance(rt);
+ fib6_update_sernum(net, rt);
break;
}
--
2.56.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH net-next v3 3/3] ipv6: use lookup cookies in selected socket dst cache paths
2026-11-17 9:21 [PATCH net-next v3 0/3] ipv6: tie the dst cookie to the lookup that returned the dst Ralf Lici
2026-11-17 9:21 ` [PATCH net-next v3 1/3] ipv6: stamp the default route node with a fresh serial on link failure Ralf Lici
2026-11-17 9:21 ` [PATCH net-next v3 2/3] ipv6: add ip6_dst_lookup_flow_cookie Ralf Lici
@ 2026-11-17 9:21 ` Ralf Lici
2 siblings, 0 replies; 4+ messages in thread
From: Ralf Lici @ 2026-11-17 9:21 UTC (permalink / raw)
To: netdev
Cc: David Ahern, Ido Schimmel, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Simon Horman, Neal Cardwell,
Kuniyuki Iwashima, Willem de Bruijn, Christian Brauner, Xia Yan,
Jeff Layton, Sebastian Andrzej Siewior, Qi Tang, Steffen Klassert,
Herbert Xu, Florian Westphal, Sabrina Dubroca, Antonio Quartulli,
linux-kernel
tcp_v6_connect, ip6_datagram_dst_update and ip6_sk_dst_lookup_flow
obtain a dst and sample its validation cookie afterwards. If a matching
xfrm policy is inserted between lookup and cookie sampling, the plain
route can be cached with a post-insertion serial. Subsequent packets
then pass dst validation and bypass the new policy until another
relevant FIB change.
Store the cookie returned by ip6_dst_lookup_flow_cookie in these paths
instead. Add ip6_dst_store_cookie to accept the supplied cookie,
retaining ip6_dst_store for unconverted callers.
This is a partial conversion. Established TCP route refills, header
rebuilds and accepted-socket setup still use late cookie sampling. Those
paths and other persistent caches, including SCTP and dst_cache users,
are left for follow-up conversions.
This race was found while investigating how mutable socket routing
properties affect the dst cache in ovpn's UDP TX path.
The socket-cache case was then reproduced in a VM by adding a debug-only
kernel delay after the route and policy lookup, then inserting a
matching xfrm policy before cookie sampling. TCP connect and connected
UDP sockets continued sending plaintext after the policy insertion. With
lookup cookies, the stale cached route was rejected on reuse.
Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Signed-off-by: Ralf Lici <ralf@mandelbit.com>
---
Changes since v2 https://lore.kernel.org/all/43917b9119e13e54dcde0e2941d3f4a1fe255df7.1794384146.git.ralf@mandelbit.com/
- Add a Fixes tag referencing the initial git import. (Sashiko)
- Clearly state that this is only a partial conversion to the new API.
No changes since v1 https://lore.kernel.org/netdev/832892eaa7d2371f20459c3134c72914e42970b0.1793806941.git.ralf@mandelbit.com/
include/net/ip6_route.h | 18 +++++++++++++-----
net/ipv6/datagram.c | 6 ++++--
net/ipv6/ip6_output.c | 6 ++++--
net/ipv6/route.c | 12 ++++++------
net/ipv6/tcp_ipv6.c | 5 +++--
5 files changed, 30 insertions(+), 17 deletions(-)
diff --git a/include/net/ip6_route.h b/include/net/ip6_route.h
index 95f936be32c6..2684f6069a5e 100644
--- a/include/net/ip6_route.h
+++ b/include/net/ip6_route.h
@@ -252,13 +252,13 @@ static inline const struct rt6_info *skb_rt6_info(const struct sk_buff *skb)
/*
* Store a destination cache entry in a socket
*/
-static inline void ip6_dst_store(struct sock *sk, struct dst_entry *dst,
- bool daddr_set,
- bool saddr_set)
+static inline void ip6_dst_store_cookie(struct sock *sk, struct dst_entry *dst,
+ u32 cookie, bool daddr_set,
+ bool saddr_set)
{
struct ipv6_pinfo *np = inet6_sk(sk);
- np->dst_cookie = rt6_get_cookie(dst_rt6_info(dst));
+ np->dst_cookie = cookie;
sk_setup_caps(sk, dst);
np->daddr_cache = daddr_set;
#ifdef CONFIG_IPV6_SUBTREES
@@ -266,8 +266,16 @@ static inline void ip6_dst_store(struct sock *sk, struct dst_entry *dst,
#endif
}
+static inline void ip6_dst_store(struct sock *sk, struct dst_entry *dst,
+ bool daddr_set,
+ bool saddr_set)
+{
+ ip6_dst_store_cookie(sk, dst, rt6_get_cookie(dst_rt6_info(dst)),
+ daddr_set, saddr_set);
+}
+
void ip6_sk_dst_store_flow(struct sock *sk, struct dst_entry *dst,
- const struct flowi6 *fl6);
+ const struct flowi6 *fl6, u32 cookie);
static inline bool ipv6_unicast_destination(const struct sk_buff *skb)
{
diff --git a/net/ipv6/datagram.c b/net/ipv6/datagram.c
index ff7a7ffbf983..c18609bab366 100644
--- a/net/ipv6/datagram.c
+++ b/net/ipv6/datagram.c
@@ -78,6 +78,7 @@ int ip6_datagram_dst_update(struct sock *sk, bool fix_sk_saddr)
struct in6_addr *final_p;
struct dst_entry *dst;
struct flowi6 *fl6;
+ u32 cookie;
int err = 0;
if (inet6_test_bit(SNDFLOW, sk) &&
@@ -94,7 +95,8 @@ int ip6_datagram_dst_update(struct sock *sk, bool fix_sk_saddr)
final_p = fl6_update_dst(fl6, opt, &np->final);
rcu_read_unlock();
- dst = ip6_dst_lookup_flow(sock_net(sk), sk, fl6, final_p);
+ dst = ip6_dst_lookup_flow_cookie(sock_net(sk), sk, fl6, final_p,
+ &cookie);
if (IS_ERR(dst)) {
err = PTR_ERR(dst);
goto out;
@@ -112,7 +114,7 @@ int ip6_datagram_dst_update(struct sock *sk, bool fix_sk_saddr)
}
}
- ip6_sk_dst_store_flow(sk, dst, fl6);
+ ip6_sk_dst_store_flow(sk, dst, fl6, cookie);
out:
fl6_sock_release(flowlabel);
diff --git a/net/ipv6/ip6_output.c b/net/ipv6/ip6_output.c
index b87ccb5586cf..d51986d5ea4b 100644
--- a/net/ipv6/ip6_output.c
+++ b/net/ipv6/ip6_output.c
@@ -1370,6 +1370,7 @@ struct dst_entry *ip6_sk_dst_lookup_flow(struct sock *sk, struct flowi6 *fl6,
bool connected)
{
struct dst_entry *dst;
+ u32 cookie;
if (connected) {
dst = sk_dst_check(sk, inet6_sk(sk)->dst_cookie);
@@ -1378,9 +1379,10 @@ struct dst_entry *ip6_sk_dst_lookup_flow(struct sock *sk, struct flowi6 *fl6,
return dst;
}
- dst = ip6_dst_lookup_flow(sock_net(sk), sk, fl6, final_dst);
+ dst = ip6_dst_lookup_flow_cookie(sock_net(sk), sk, fl6, final_dst,
+ &cookie);
if (connected && !IS_ERR(dst))
- ip6_sk_dst_store_flow(sk, dst_clone(dst), fl6);
+ ip6_sk_dst_store_flow(sk, dst_clone(dst), fl6, cookie);
return dst;
}
diff --git a/net/ipv6/route.c b/net/ipv6/route.c
index c54844b83828..b19bc0d0c78d 100644
--- a/net/ipv6/route.c
+++ b/net/ipv6/route.c
@@ -3048,19 +3048,19 @@ void ip6_sk_update_pmtu(struct sk_buff *skb, struct sock *sk, __be32 mtu)
}
void ip6_sk_dst_store_flow(struct sock *sk, struct dst_entry *dst,
- const struct flowi6 *fl6)
+ const struct flowi6 *fl6, u32 cookie)
{
#ifdef CONFIG_IPV6_SUBTREES
struct ipv6_pinfo *np = inet6_sk(sk);
#endif
- ip6_dst_store(sk, dst,
- ipv6_addr_equal(&fl6->daddr, &sk->sk_v6_daddr),
+ ip6_dst_store_cookie(sk, dst, cookie,
+ ipv6_addr_equal(&fl6->daddr, &sk->sk_v6_daddr),
#ifdef CONFIG_IPV6_SUBTREES
- ipv6_addr_equal(&fl6->saddr, &np->saddr) ?
- true :
+ ipv6_addr_equal(&fl6->saddr, &np->saddr) ?
+ true :
#endif
- false);
+ false);
}
static bool ip6_redirect_nh_match(const struct fib6_result *res,
diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
index 9e22ed61a6de..9dc031437b42 100644
--- a/net/ipv6/tcp_ipv6.c
+++ b/net/ipv6/tcp_ipv6.c
@@ -145,6 +145,7 @@ static int tcp_v6_connect(struct sock *sk, struct sockaddr_unsized *uaddr,
struct dst_entry *dst;
struct flowi6 *fl6;
int addr_type;
+ u32 cookie;
int err;
if (addr_len < SIN6_LEN_RFC2133)
@@ -288,7 +289,7 @@ static int tcp_v6_connect(struct sock *sk, struct sockaddr_unsized *uaddr,
*/
ip6_ecmp_set_mp_hash(net, fl6, sk->sk_txhash);
- dst = ip6_dst_lookup_flow(net, sk, fl6, final_p);
+ dst = ip6_dst_lookup_flow_cookie(net, sk, fl6, final_p, &cookie);
if (IS_ERR(dst)) {
err = PTR_ERR(dst);
goto failure;
@@ -312,7 +313,7 @@ static int tcp_v6_connect(struct sock *sk, struct sockaddr_unsized *uaddr,
inet->inet_rcv_saddr = LOOPBACK4_IPV6;
sk->sk_gso_type = SKB_GSO_TCPV6;
- ip6_dst_store(sk, dst, false, false);
+ ip6_dst_store_cookie(sk, dst, cookie, false, false);
icsk->icsk_ext_hdr_len = 0;
if (opt)
--
2.56.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-11-17 9:23 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-17 9:21 [PATCH net-next v3 0/3] ipv6: tie the dst cookie to the lookup that returned the dst Ralf Lici
2026-11-17 9:21 ` [PATCH net-next v3 1/3] ipv6: stamp the default route node with a fresh serial on link failure Ralf Lici
2026-11-17 9:21 ` [PATCH net-next v3 2/3] ipv6: add ip6_dst_lookup_flow_cookie Ralf Lici
2026-11-17 9:21 ` [PATCH net-next v3 3/3] ipv6: use lookup cookies in selected socket dst cache paths Ralf Lici
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox