Re: [PATCHv3 net] ipv6: do not match device when remove source route

Ido Schimmel
2023-07-25T08:06:15Z

On Mon, Jul 24, 2023 at 05:42:34PM +0800, Hangbin Liu wrote:
> On Sun, Jul 23, 2023 at 11:13:36AM +0300, Ido Schimmel wrote:
> > > BTW, to fix it, how about check if the IPv6 addr still exist. e.g.
> > >
> > > --- a/net/ipv6/route.c
> > > +++ b/net/ipv6/route.c
> > > @@ -4590,10 +4590,11 @@ static int fib6_remove_prefsrc(struct fib6_info *rt, void *arg)
> > > struct net_device *dev = ((struct arg_dev_net_ip *)arg)->dev;
> > > struct net *net = ((struct arg_dev_net_ip *)arg)->net;
> > > struct in6_addr *addr = ((struct arg_dev_net_ip *)arg)->addr;
> > > + u32 tb6_id = l3mdev_fib_table(dev) ? : RT_TABLE_MAIN;
> > >
> > > - if (!rt->nh &&
> > > - ((void *)rt->fib6_nh->fib_nh_dev == dev || !dev) &&
> > > - rt != net->ipv6.fib6_null_entry &&
> > > + if (rt != net->ipv6.fib6_null_entry &&
> > > + rt->fib6_table->tb6_id == tb6_id &&
> > > + !ipv6_chk_addr_and_flags(net, addr, NULL, true, 0, IFA_F_TENTATIVE) &&
> > > ipv6_addr_equal(addr, &rt->fib6_prefsrc.addr)) {
> >
> > ipv6_chk_addr_and_flags() is more expensive than ipv6_addr_equal() so
> > better to first check that route indeed uses the address as the
> > preferred source address and only then check if it exists.
>
> OK.
> >
> > Maybe you can even do it in rt6_remove_prefsrc(). That would be similar
> > to what IPv4 is doing.
>
> Do you mean call ipv6_chk_addr_and_flags() in rt6_remove_prefsrc()?

Yes.