On Fri, 2016-03-25 at 17:08 -0700, Tom Herbert wrote:
> On Fri, Mar 25, 2016 at 3:29 PM, Eric Dumazet <eduma...@google.com> wrote:

> > +/* Must be called under rcu_read_lock().
> 
> 
> It might be just as easy to do the rcu_read_lock() within the
> function. That way we don't need to require callers to do it now.
> 
> > + * Does increment socket refcount.
> > + */
> > +#if IS_ENABLED(CONFIG_NETFILTER_XT_MATCH_SOCKET) || \
> > +    IS_ENABLED(CONFIG_NETFILTER_XT_TARGET_TPROXY)
> >  struct sock *udp4_lib_lookup(struct net *net, __be32 saddr, __be16 sport,
> >                              __be32 daddr, __be16 dport, int dif)
> >  {
> > -       return __udp4_lib_lookup(net, saddr, sport, daddr, dport, dif,
> > -                                &udp_table, NULL);
> > +       struct sock *sk;
> > +
> > +       sk = __udp4_lib_lookup(net, saddr, sport, daddr, dport,
> > +                              dif, &udp_table, NULL);
> > +       if (sk && !atomic_inc_not_zero(&sk->sk_refcnt))
> > +               sk = NULL;
> > +       return sk;
> >  }
> >  EXPORT_SYMBOL_GPL(udp4_lib_lookup);
> > +#endif


Well, these callers already run with rcu_read_lock(), I simply added a
comment to remind this assumption.

As I said, we might later avoid the refcounting if callers are modified
to not call sock_put(). This is why I prefer to maintain the reuirement
of rcu_read_lock() being held by callers anyway.




Reply via email to