Netdev List
 help / color / mirror / Atom feed
From: Ralf Lici <ralf@mandelbit.com>
To: David Ahern <dsahern@kernel.org>
Cc: netdev@vger.kernel.org, Ido Schimmel <idosch@nvidia.com>,
	"David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@kernel.org>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	Simon Horman <horms@kernel.org>,
	Neal Cardwell <ncardwell@google.com>,
	Kuniyuki Iwashima <kuniyu@google.com>,
	Steffen Klassert <steffen.klassert@secunet.com>,
	Herbert Xu <herbert@gondor.apana.org.au>,
	Florian Westphal <fw@strlen.de>,
	Sabrina Dubroca <sd@queasysnail.net>,
	Antonio Quartulli <antonio@mandelbit.com>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH net-next v3 2/3] ipv6: add ip6_dst_lookup_flow_cookie
Date: Fri, 20 Nov 2026 09:16:03 +0100	[thread overview]
Message-ID: <20261120081604.71209-1-ralf@mandelbit.com> (raw)
In-Reply-To: <677402dc-c023-4c41-b437-f29083ab2a35@kernel.org>

Hi David,

On Thu, 19 Nov 2026 19:13:14 -0700, David Ahern <dsahern@kernel.org> wrote:
> On 11/17/26 2:21 AM, Ralf Lici wrote:
> > @@ -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
>
> what makes this an ipsec lookup?
>

Like ip6_dst_lookup_flow, which it wraps, it calls xfrm_lookup_route
after the route lookup, so the returned dst can be an xfrm bundle, and
the generation check also covers xfrm policy insertion, which advances
the IPv6 generation through rt_genid_bump_ipv6.

The summary line was inherited from ip6_dst_lookup_flow but I'll reword
it in v4 to say route and xfrm policy lookup.

> > + *				     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);
>
> I think this can be a standalone patch introducing a new API
>

Ok.

> > +
> >  /**
> >   *	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;
>
> unrelated change to both the new API and the ordering changes below. It
> deserves to be a separate patch with its own clear explanation of why.
>

It is the validation side of the new API for nexthop-object dsts: the
helper returns the generation sampled before the lookup as their cookie,
and ip6_dst_check currently ignores the cookie when rt->sernum is set.
Existing callers pass rt6_get_cookie, which returns rt->sernum for these
dsts, so their behavior does not change. I'll move it to its own patch
with that explanation.

> >  
> >  	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;
> >  	}
> >  
>
> And then these ordering changes need to be separate patch with an
> explanation.
>
>

Ok. v4 will be:

1. ipv6: stamp the default route node with a fresh serial on link
   failure
2. ipv6: advance the serial after rebalancing in fib6_ifup and
   fib6_ifdown
3. ipv6: validate the cookie of nexthop-object dsts in ip6_dst_check
4. ipv6: add ip6_dst_lookup_flow_cookie
5. ipv6: use lookup cookies in selected socket dst cache paths

so that the requirements are in place before the API and its users.

Thanks for the review.

-- 
Ralf Lici
Mandelbit Srl

  reply	other threads:[~2026-11-20  8:24 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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-19  9:22   ` netdev-bot+sashiko
2026-11-17  9:21 ` [PATCH net-next v3 2/3] ipv6: add ip6_dst_lookup_flow_cookie Ralf Lici
2026-11-18  8:48   ` Xia Yan
2026-11-18 14:39     ` Ralf Lici
2026-11-18 15:07       ` Xia Yan
2026-11-19  9:22   ` netdev-bot+sashiko
2026-11-19 12:31     ` Ralf Lici
2026-11-20  2:13   ` David Ahern
2026-11-20  8:16     ` Ralf Lici [this message]
2026-11-17  9:21 ` [PATCH net-next v3 3/3] ipv6: use lookup cookies in selected socket dst cache paths Ralf Lici
2026-11-19  9:22   ` netdev-bot+sashiko
2026-11-19 12:34     ` Ralf Lici

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261120081604.71209-1-ralf@mandelbit.com \
    --to=ralf@mandelbit.com \
    --cc=antonio@mandelbit.com \
    --cc=davem@davemloft.net \
    --cc=dsahern@kernel.org \
    --cc=edumazet@kernel.org \
    --cc=fw@strlen.de \
    --cc=herbert@gondor.apana.org.au \
    --cc=horms@kernel.org \
    --cc=idosch@nvidia.com \
    --cc=kuba@kernel.org \
    --cc=kuniyu@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ncardwell@google.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=sd@queasysnail.net \
    --cc=steffen.klassert@secunet.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox