Thanks for the comments. On Wed, Apr 26, 2017 at 07:34:49PM -0400, Willem de Bruijn wrote: > > +struct net_device *dev_get_by_napi_id(unsigned int napi_id) > > +{ > > + struct net_device *dev = NULL; > > + struct napi_struct *napi; > > + > > + rcu_read_lock(); > > + > > + napi = napi_by_id(napi_id); > > + if (napi) > > + dev = napi->dev; > > + > > + rcu_read_unlock(); > > + > > + return dev; > > +} > > +EXPORT_SYMBOL(dev_get_by_napi_id); > > Returning dev without holding a reference is not safe. You'll probably > have to call this with rcu_read_lock held instead.
How about changing the function to simply return the index instead of the device (e.g. dev_get_ifindex_by_napi_id())? Would that be too specific? > > /* > > * called from sock_recv_timestamp() if sock_flag(sk, SOCK_RCVTSTAMP) > > */ > > @@ -699,8 +719,12 @@ void __sock_recv_timestamp(struct msghdr *msg, struct > > sock *sk, > > empty = 0; > > if (shhwtstamps && > > (sk->sk_tsflags & SOF_TIMESTAMPING_RAW_HARDWARE) && > > This information is also informative with software timestamps. But is it useful and worth the cost? If I have two interfaces and only one has HW timestamping, or just one interface which can timestamp incoming packets at a limited rate, I would prefer to not waste CPU cycles preparing and processing useless data. > And getting the real iif is definitely useful outside timestamps. Do you have an example? We have asked that in the original thread, but no one suggested anything. For AF_PACKET there is PACKET_ORIGDEV. When I was searching the Internet on how to get the index with INET sockets, it looked like I was the only one who had this problem :). > An > alternative approach is to add versioning to IP_PKTINFO with a new > setsockopt IP_PKTINFO_VERSION plus a new struct in_pktinfo_v2 > that extends in_pktinfo. Just a thought. The struct would contain both the original and last interface index, and the length as well? And similarly with in6_pktinfo? If there is an agreement that the information would useful also for other things than timestamping, I can try that. If not, I think it would be better to keep it tied to HW timestamping. -- Miroslav Lichvar