summaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authorDavid S. Miller <davem@davemloft.net>2017-05-21 13:37:35 -0400
committerDavid S. Miller <davem@davemloft.net>2017-05-21 13:37:35 -0400
commitdae37055f475a369f7433360e246afbdccd22ff6 (patch)
tree558123f0c9eebd3587869de6b568221847c674c3 /net
parent2061ec3f1370d5491e801a693618af2b933781fe (diff)
parent74abc9b18f446d1a9e0602a71a22e5ffe8a2cd23 (diff)
downloadop-kernel-dev-dae37055f475a369f7433360e246afbdccd22ff6.zip
op-kernel-dev-dae37055f475a369f7433360e246afbdccd22ff6.tar.gz
Merge branch 'net-extend-socket-timestamping-API'
Miroslav Lichvar says: ==================== Extend socket timestamping API Changes v5->v6: - fixed skb_is_swtx_tstamp() when OPT_TX_SWHW is disabled and improved its description - improved OPT_PKTINFO documentation - improved scm_timestamping documentation Changes v4->v5: - fixed initialization of reserved fields in struct scm_ts_pktinfo Changes v3->v4: - added reserved fields to struct scm_ts_pktinfo - replaced patch fixing false SW timestamps with a documentation fix - updated OPT_TX_SWHW patch to handle false SW timestamps Changes v2->v3: - modified struct scm_ts_pktinfo to use fixed-width integer types - added WARN_ON_ONCE for missing RCU lock in dev_get_by_napi_id() - modified dev_get_by_napi_id() to not return dev in unexpected branch - modified recv to return SCM_TIMESTAMPING_PKTINFO even if the interface index is unknown Changes v1->v2: - added separate patch for new NAPI functions - split code from __sock_recv_timestamp() for better readability - fixed RCU locking - fixed compiler warning (missing case in switch in first patch) - inline sw_tx_timestamp() in its only user Changes RFC->v1: - reworked SOF_TIMESTAMPING_OPT_PKTINFO patch to not add new fields to skb shared info (net device is now looked up by napi_id), not require any changes in drivers, and restrict the cmsg to incoming packets - renamed SOF_TIMESTAMPING_OPT_MULTIMSG to SOF_TIMESTAMPING_OPT_TX_SWHW and fixed its description - moved struct scm_ts_pktinfo from errqueue.h to net_tstamp.h as it can't be received from the error queue anymore - improved commit descriptions and removed incorrect comment This patchset adds new options to the timestamping API that will be useful for NTP implementations and possibly other applications. The first patch specifies a timestamp filter for NTP packets. The second patch updates drivers that can timestamp all packets, or need to list the filter as unsupported. There is no attempt to add the support to the phyter driver. The third patch adds two helper functions working with NAPI ID, which is needed by the next patch. The fourth patch adds a new option to get a new control message with the L2 length and interface index for incoming packets with hardware timestamps. The fifth patch fixes documentation on number of non-zero fields in scm_timestamping and warns about false software timestamps when SO_TIMESTAMP(NS) is combined with SCM_TIMESTAMPING. The sixth patch adds a new option to request both software and hardware timestamps for outgoing packets. The seventh patch updates drivers that assumed software timestamping cannot be used together with hardware timestamping. The patches have been tested on x86_64 machines with igb and e1000e drivers. ==================== Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net')
-rw-r--r--net/core/dev.c26
-rw-r--r--net/core/dev_ioctl.c1
-rw-r--r--net/core/skbuff.c4
-rw-r--r--net/socket.c47
4 files changed, 75 insertions, 3 deletions
diff --git a/net/core/dev.c b/net/core/dev.c
index bb136f7..3d98fbf 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -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
@@ -867,6 +868,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
* @name: a pointer to the buffer where the name will be stored.
diff --git a/net/core/dev_ioctl.c b/net/core/dev_ioctl.c
index b94b1d2..77f04e7 100644
--- a/net/core/dev_ioctl.c
+++ b/net/core/dev_ioctl.c
@@ -225,6 +225,7 @@ static int net_hwtstamp_validate(struct ifreq *ifr)
case HWTSTAMP_FILTER_PTP_V2_EVENT:
case HWTSTAMP_FILTER_PTP_V2_SYNC:
case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ:
+ case HWTSTAMP_FILTER_NTP_ALL:
rx_filter_valid = 1;
break;
}
diff --git a/net/core/skbuff.c b/net/core/skbuff.c
index d5c9811..780b7c1 100644
--- a/net/core/skbuff.c
+++ b/net/core/skbuff.c
@@ -3901,6 +3901,10 @@ void __skb_tstamp_tx(struct sk_buff *orig_skb,
if (!sk)
return;
+ if (!hwtstamps && !(sk->sk_tsflags & SOF_TIMESTAMPING_OPT_TX_SWHW) &&
+ skb_shinfo(orig_skb)->tx_flags & SKBTX_IN_PROGRESS)
+ return;
+
tsonly = sk->sk_tsflags & SOF_TIMESTAMPING_OPT_TSONLY;
if (!skb_may_tx_timestamp(sk, tsonly))
return;
diff --git a/net/socket.c b/net/socket.c
index c2564eb..cb355a7 100644
--- a/net/socket.c
+++ b/net/socket.c
@@ -662,6 +662,40 @@ static bool skb_is_err_queue(const struct sk_buff *skb)
return skb->pkt_type == PACKET_OUTGOING;
}
+/* On transmit, software and hardware timestamps are returned independently.
+ * As the two skb clones share the hardware timestamp, which may be updated
+ * before the software timestamp is received, a hardware TX timestamp may be
+ * returned only if there is no software TX timestamp. Ignore false software
+ * timestamps, which may be made in the __sock_recv_timestamp() call when the
+ * option SO_TIMESTAMP(NS) is enabled on the socket, even when the skb has a
+ * hardware timestamp.
+ */
+static bool skb_is_swtx_tstamp(const struct sk_buff *skb, int false_tstamp)
+{
+ return skb->tstamp && !false_tstamp && skb_is_err_queue(skb);
+}
+
+static void put_ts_pktinfo(struct msghdr *msg, struct sk_buff *skb)
+{
+ struct scm_ts_pktinfo ts_pktinfo;
+ struct net_device *orig_dev;
+
+ if (!skb_mac_header_was_set(skb))
+ return;
+
+ memset(&ts_pktinfo, 0, sizeof(ts_pktinfo));
+
+ rcu_read_lock();
+ orig_dev = dev_get_by_napi_id(skb_napi_id(skb));
+ if (orig_dev)
+ ts_pktinfo.if_index = orig_dev->ifindex;
+ rcu_read_unlock();
+
+ ts_pktinfo.pkt_length = skb->len - skb_mac_offset(skb);
+ put_cmsg(msg, SOL_SOCKET, SCM_TIMESTAMPING_PKTINFO,
+ sizeof(ts_pktinfo), &ts_pktinfo);
+}
+
/*
* called from sock_recv_timestamp() if sock_flag(sk, SOCK_RCVTSTAMP)
*/
@@ -670,14 +704,16 @@ void __sock_recv_timestamp(struct msghdr *msg, struct sock *sk,
{
int need_software_tstamp = sock_flag(sk, SOCK_RCVTSTAMP);
struct scm_timestamping tss;
- int empty = 1;
+ int empty = 1, false_tstamp = 0;
struct skb_shared_hwtstamps *shhwtstamps =
skb_hwtstamps(skb);
/* Race occurred between timestamp enabling and packet
receiving. Fill in the current time for now. */
- if (need_software_tstamp && skb->tstamp == 0)
+ if (need_software_tstamp && skb->tstamp == 0) {
__net_timestamp(skb);
+ false_tstamp = 1;
+ }
if (need_software_tstamp) {
if (!sock_flag(sk, SOCK_RCVTSTAMPNS)) {
@@ -699,8 +735,13 @@ void __sock_recv_timestamp(struct msghdr *msg, struct sock *sk,
empty = 0;
if (shhwtstamps &&
(sk->sk_tsflags & SOF_TIMESTAMPING_RAW_HARDWARE) &&
- ktime_to_timespec_cond(shhwtstamps->hwtstamp, tss.ts + 2))
+ !skb_is_swtx_tstamp(skb, false_tstamp) &&
+ ktime_to_timespec_cond(shhwtstamps->hwtstamp, tss.ts + 2)) {
empty = 0;
+ if ((sk->sk_tsflags & SOF_TIMESTAMPING_OPT_PKTINFO) &&
+ !skb_is_err_queue(skb))
+ put_ts_pktinfo(msg, skb);
+ }
if (!empty) {
put_cmsg(msg, SOL_SOCKET,
SCM_TIMESTAMPING, sizeof(tss), &tss);
OpenPOWER on IntegriCloud