]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
net: add function to retrieve original skb device using NAPI ID
authorMiroslav Lichvar <mlichvar@redhat.com>
Fri, 19 May 2017 15:52:37 +0000 (17:52 +0200)
committerDavid S. Miller <davem@davemloft.net>
Sun, 21 May 2017 17:37:32 +0000 (13:37 -0400)
Since commit b68581778cd0 ("net: Make skb->skb_iif always track
skb->dev") skbs don't have the original index of the interface which
received the packet. This information is now needed for a new control
message related to hardware timestamping.

Instead of adding a new field to skb, we can find the device by the NAPI
ID if it is available, i.e. CONFIG_NET_RX_BUSY_POLL is enabled and the
driver is using NAPI. Add dev_get_by_napi_id() and also skb_napi_id() to
hide the CONFIG_NET_RX_BUSY_POLL ifdef.

CC: Richard Cochran <richardcochran@gmail.com>
Suggested-by: Willem de Bruijn <willemb@google.com>
Acked-by: Willem de Bruijn <willemb@google.com>
Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
include/linux/netdevice.h
include/linux/skbuff.h
net/core/dev.c

index f8f7cd52a0a0946b44dbbc9fb74de1f6c4db9ac0..c50c9218e31e06a98ef606967c973cdd10511460 100644 (file)
@@ -2456,6 +2456,7 @@ static inline int dev_recursion_level(void)
 struct net_device *dev_get_by_index(struct net *net, int ifindex);
 struct net_device *__dev_get_by_index(struct net *net, int ifindex);
 struct net_device *dev_get_by_index_rcu(struct net *net, int ifindex);
+struct net_device *dev_get_by_napi_id(unsigned int napi_id);
 int netdev_get_name(struct net *net, char *name, int ifindex);
 int dev_restart(struct net_device *dev);
 int skb_gro_receive(struct sk_buff **head, struct sk_buff *skb);
index 1713e4b7ea9f1c5f47e5da6dc398a94fa8a4eadb..8acce7143f6a0f5d5833171f5efb7e95e2fa20c1 100644 (file)
@@ -858,6 +858,15 @@ static inline bool skb_pkt_type_ok(u32 ptype)
        return ptype <= PACKET_OTHERHOST;
 }
 
+static inline unsigned int skb_napi_id(const struct sk_buff *skb)
+{
+#ifdef CONFIG_NET_RX_BUSY_POLL
+       return skb->napi_id;
+#else
+       return 0;
+#endif
+}
+
 void kfree_skb(struct sk_buff *skb);
 void kfree_skb_list(struct sk_buff *segs);
 void skb_tx_error(struct sk_buff *skb);
index bb136f726890331d02e69236dd5730eb09a1873c..3d98fbf4cbb0edaddaa6626c5bd7199402b3a566 100644 (file)
@@ -163,6 +163,7 @@ static int netif_rx_internal(struct sk_buff *skb);
 static int call_netdevice_notifiers_info(unsigned long val,
                                         struct net_device *dev,
                                         struct netdev_notifier_info *info);
+static struct napi_struct *napi_by_id(unsigned int napi_id);
 
 /*
  * The @dev_base_head list is protected by @dev_base_lock and the rtnl
@@ -866,6 +867,31 @@ struct net_device *dev_get_by_index(struct net *net, int ifindex)
 }
 EXPORT_SYMBOL(dev_get_by_index);
 
+/**
+ *     dev_get_by_napi_id - find a device by napi_id
+ *     @napi_id: ID of the NAPI struct
+ *
+ *     Search for an interface by NAPI ID. Returns %NULL if the device
+ *     is not found or a pointer to the device. The device has not had
+ *     its reference counter increased so the caller must be careful
+ *     about locking. The caller must hold RCU lock.
+ */
+
+struct net_device *dev_get_by_napi_id(unsigned int napi_id)
+{
+       struct napi_struct *napi;
+
+       WARN_ON_ONCE(!rcu_read_lock_held());
+
+       if (napi_id < MIN_NAPI_ID)
+               return NULL;
+
+       napi = napi_by_id(napi_id);
+
+       return napi ? napi->dev : NULL;
+}
+EXPORT_SYMBOL(dev_get_by_napi_id);
+
 /**
  *     netdev_get_name - get a netdevice name, knowing its ifindex.
  *     @net: network namespace