netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next 0/2] Transmit time stamping on tun/tap interfaces
@ 2013-07-19 17:40 Richard Cochran
  2013-07-19 17:40 ` [PATCH net-next 1/2] Provide a generic socket error queue delivery method for Tx time stamps Richard Cochran
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Richard Cochran @ 2013-07-19 17:40 UTC (permalink / raw)
  To: netdev; +Cc: David Miller, Michael S. Tsirkin

This series adds transmit SO_TIMESTAMPING for tun and tap devices.
Having this support is useful for testing multiple instances of PTP
programs (for example, to exercise the best master clock behavior)
and for synchronizing virtual guests.

The first patch refactors the code that delivers raw error queue
packets into a common function, in order to avoid multiple, nearly
identical implementations. This can be used whenever a network layer
has an error queue for transmit time stamp reporting only.

Thanks,
Richard


Richard Cochran (2):
  Provide a generic socket error queue delivery method for Tx time
    stamps.
  tun: Support software transmit time stamping.

 drivers/net/tun.c           |   14 +++++++++++--
 include/net/sock.h          |    2 ++
 include/uapi/linux/if_tun.h |    3 +++
 net/core/sock.c             |   47 ++++++++++++++++++++++++++++++++++++++++++
 net/packet/af_packet.c      |   48 ++-----------------------------------------
 5 files changed, 66 insertions(+), 48 deletions(-)

-- 
1.7.10.4

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH net-next 1/2] Provide a generic socket error queue delivery method for Tx time stamps.
  2013-07-19 17:40 [PATCH net-next 0/2] Transmit time stamping on tun/tap interfaces Richard Cochran
@ 2013-07-19 17:40 ` Richard Cochran
  2013-07-19 17:40 ` [PATCH net-next 2/2] tun: Support software transmit time stamping Richard Cochran
  2013-07-22 21:59 ` [PATCH net-next 0/2] Transmit time stamping on tun/tap interfaces David Miller
  2 siblings, 0 replies; 4+ messages in thread
From: Richard Cochran @ 2013-07-19 17:40 UTC (permalink / raw)
  To: netdev; +Cc: David Miller, Michael S. Tsirkin

This patch moves the private error queue delivery function from the
af_packet code to the core socket method. In this way, network layers
only needing the error queue for transmit time stamping can share common
code.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
---
 include/net/sock.h     |    2 ++
 net/core/sock.c        |   47 +++++++++++++++++++++++++++++++++++++++++++++++
 net/packet/af_packet.c |   48 ++----------------------------------------------
 3 files changed, 51 insertions(+), 46 deletions(-)

diff --git a/include/net/sock.h b/include/net/sock.h
index 95a5a2c..e0473f6 100644
--- a/include/net/sock.h
+++ b/include/net/sock.h
@@ -2249,6 +2249,8 @@ static inline struct sock *skb_steal_sock(struct sk_buff *skb)
 extern void sock_enable_timestamp(struct sock *sk, int flag);
 extern int sock_get_timestamp(struct sock *, struct timeval __user *);
 extern int sock_get_timestampns(struct sock *, struct timespec __user *);
+extern int sock_recv_errqueue(struct sock *sk, struct msghdr *msg, int len,
+			      int level, int type);
 
 /*
  *	Enable debug/info messages
diff --git a/net/core/sock.c b/net/core/sock.c
index 548d716..85e8de1 100644
--- a/net/core/sock.c
+++ b/net/core/sock.c
@@ -93,6 +93,7 @@
 
 #include <linux/capability.h>
 #include <linux/errno.h>
+#include <linux/errqueue.h>
 #include <linux/types.h>
 #include <linux/socket.h>
 #include <linux/in.h>
@@ -2425,6 +2426,52 @@ void sock_enable_timestamp(struct sock *sk, int flag)
 	}
 }
 
+int sock_recv_errqueue(struct sock *sk, struct msghdr *msg, int len,
+		       int level, int type)
+{
+	struct sock_exterr_skb *serr;
+	struct sk_buff *skb, *skb2;
+	int copied, err;
+
+	err = -EAGAIN;
+	skb = skb_dequeue(&sk->sk_error_queue);
+	if (skb == NULL)
+		goto out;
+
+	copied = skb->len;
+	if (copied > len) {
+		msg->msg_flags |= MSG_TRUNC;
+		copied = len;
+	}
+	err = skb_copy_datagram_iovec(skb, 0, msg->msg_iov, copied);
+	if (err)
+		goto out_free_skb;
+
+	sock_recv_timestamp(msg, sk, skb);
+
+	serr = SKB_EXT_ERR(skb);
+	put_cmsg(msg, level, type, sizeof(serr->ee), &serr->ee);
+
+	msg->msg_flags |= MSG_ERRQUEUE;
+	err = copied;
+
+	/* Reset and regenerate socket error */
+	spin_lock_bh(&sk->sk_error_queue.lock);
+	sk->sk_err = 0;
+	if ((skb2 = skb_peek(&sk->sk_error_queue)) != NULL) {
+		sk->sk_err = SKB_EXT_ERR(skb2)->ee.ee_errno;
+		spin_unlock_bh(&sk->sk_error_queue.lock);
+		sk->sk_error_report(sk);
+	} else
+		spin_unlock_bh(&sk->sk_error_queue.lock);
+
+out_free_skb:
+	kfree_skb(skb);
+out:
+	return err;
+}
+EXPORT_SYMBOL(sock_recv_errqueue);
+
 /*
  *	Get a socket option on an socket.
  *
diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
index 4b66c75..4cb28a7 100644
--- a/net/packet/af_packet.c
+++ b/net/packet/af_packet.c
@@ -2638,51 +2638,6 @@ out:
 	return err;
 }
 
-static int packet_recv_error(struct sock *sk, struct msghdr *msg, int len)
-{
-	struct sock_exterr_skb *serr;
-	struct sk_buff *skb, *skb2;
-	int copied, err;
-
-	err = -EAGAIN;
-	skb = skb_dequeue(&sk->sk_error_queue);
-	if (skb == NULL)
-		goto out;
-
-	copied = skb->len;
-	if (copied > len) {
-		msg->msg_flags |= MSG_TRUNC;
-		copied = len;
-	}
-	err = skb_copy_datagram_iovec(skb, 0, msg->msg_iov, copied);
-	if (err)
-		goto out_free_skb;
-
-	sock_recv_timestamp(msg, sk, skb);
-
-	serr = SKB_EXT_ERR(skb);
-	put_cmsg(msg, SOL_PACKET, PACKET_TX_TIMESTAMP,
-		 sizeof(serr->ee), &serr->ee);
-
-	msg->msg_flags |= MSG_ERRQUEUE;
-	err = copied;
-
-	/* Reset and regenerate socket error */
-	spin_lock_bh(&sk->sk_error_queue.lock);
-	sk->sk_err = 0;
-	if ((skb2 = skb_peek(&sk->sk_error_queue)) != NULL) {
-		sk->sk_err = SKB_EXT_ERR(skb2)->ee.ee_errno;
-		spin_unlock_bh(&sk->sk_error_queue.lock);
-		sk->sk_error_report(sk);
-	} else
-		spin_unlock_bh(&sk->sk_error_queue.lock);
-
-out_free_skb:
-	kfree_skb(skb);
-out:
-	return err;
-}
-
 /*
  *	Pull a packet from our receive queue and hand it to the user.
  *	If necessary we block.
@@ -2708,7 +2663,8 @@ static int packet_recvmsg(struct kiocb *iocb, struct socket *sock,
 #endif
 
 	if (flags & MSG_ERRQUEUE) {
-		err = packet_recv_error(sk, msg, len);
+		err = sock_recv_errqueue(sk, msg, len,
+					 SOL_PACKET, PACKET_TX_TIMESTAMP);
 		goto out;
 	}
 
-- 
1.7.10.4

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH net-next 2/2] tun: Support software transmit time stamping.
  2013-07-19 17:40 [PATCH net-next 0/2] Transmit time stamping on tun/tap interfaces Richard Cochran
  2013-07-19 17:40 ` [PATCH net-next 1/2] Provide a generic socket error queue delivery method for Tx time stamps Richard Cochran
@ 2013-07-19 17:40 ` Richard Cochran
  2013-07-22 21:59 ` [PATCH net-next 0/2] Transmit time stamping on tun/tap interfaces David Miller
  2 siblings, 0 replies; 4+ messages in thread
From: Richard Cochran @ 2013-07-19 17:40 UTC (permalink / raw)
  To: netdev; +Cc: David Miller, Michael S. Tsirkin

This patch adds transmit time stamping to the tun/tap driver. Similar
support already exists for UDP, can, and raw packets.

Signed-off-by: Richard Cochran <richardcochran@gmail.com>
---
 drivers/net/tun.c           |   14 ++++++++++++--
 include/uapi/linux/if_tun.h |    3 +++
 2 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/drivers/net/tun.c b/drivers/net/tun.c
index db690a3..a72d141 100644
--- a/drivers/net/tun.c
+++ b/drivers/net/tun.c
@@ -739,6 +739,11 @@ static netdev_tx_t tun_net_xmit(struct sk_buff *skb, struct net_device *dev)
 			  >= dev->tx_queue_len / tun->numqueues)
 		goto drop;
 
+	if (skb->sk) {
+		sock_tx_timestamp(skb->sk, &skb_shinfo(skb)->tx_flags);
+		sw_tx_timestamp(skb);
+	}
+
 	/* Orphan the skb - required as we might hang on to it
 	 * for indefinite time. */
 	if (unlikely(skb_orphan_frags(skb, GFP_ATOMIC)))
@@ -1476,7 +1481,6 @@ static int tun_sendmsg(struct kiocb *iocb, struct socket *sock,
 	return ret;
 }
 
-
 static int tun_recvmsg(struct kiocb *iocb, struct socket *sock,
 		       struct msghdr *m, size_t total_len,
 		       int flags)
@@ -1488,10 +1492,15 @@ static int tun_recvmsg(struct kiocb *iocb, struct socket *sock,
 	if (!tun)
 		return -EBADFD;
 
-	if (flags & ~(MSG_DONTWAIT|MSG_TRUNC)) {
+	if (flags & ~(MSG_DONTWAIT|MSG_TRUNC|MSG_ERRQUEUE)) {
 		ret = -EINVAL;
 		goto out;
 	}
+	if (flags & MSG_ERRQUEUE) {
+		ret = sock_recv_errqueue(sock->sk, m, total_len,
+					 SOL_PACKET, TUN_TX_TIMESTAMP);
+		goto out;
+	}
 	ret = tun_do_read(tun, tfile, iocb, m->msg_iov, total_len,
 			  flags & MSG_DONTWAIT);
 	if (ret > total_len) {
@@ -2274,6 +2283,7 @@ static const struct ethtool_ops tun_ethtool_ops = {
 	.get_msglevel	= tun_get_msglevel,
 	.set_msglevel	= tun_set_msglevel,
 	.get_link	= ethtool_op_get_link,
+	.get_ts_info	= ethtool_op_get_ts_info,
 };
 
 
diff --git a/include/uapi/linux/if_tun.h b/include/uapi/linux/if_tun.h
index 82334f8..1870ee2 100644
--- a/include/uapi/linux/if_tun.h
+++ b/include/uapi/linux/if_tun.h
@@ -71,6 +71,9 @@
 /* read-only flag */
 #define IFF_PERSIST	0x0800
 
+/* Socket options */
+#define TUN_TX_TIMESTAMP 1
+
 /* Features for GSO (TUNSETOFFLOAD). */
 #define TUN_F_CSUM	0x01	/* You can hand me unchecksummed packets. */
 #define TUN_F_TSO4	0x02	/* I can handle TSO for IPv4 packets */
-- 
1.7.10.4

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH net-next 0/2] Transmit time stamping on tun/tap interfaces
  2013-07-19 17:40 [PATCH net-next 0/2] Transmit time stamping on tun/tap interfaces Richard Cochran
  2013-07-19 17:40 ` [PATCH net-next 1/2] Provide a generic socket error queue delivery method for Tx time stamps Richard Cochran
  2013-07-19 17:40 ` [PATCH net-next 2/2] tun: Support software transmit time stamping Richard Cochran
@ 2013-07-22 21:59 ` David Miller
  2 siblings, 0 replies; 4+ messages in thread
From: David Miller @ 2013-07-22 21:59 UTC (permalink / raw)
  To: richardcochran; +Cc: netdev, mst

From: Richard Cochran <richardcochran@gmail.com>
Date: Fri, 19 Jul 2013 19:40:08 +0200

> This series adds transmit SO_TIMESTAMPING for tun and tap devices.
> Having this support is useful for testing multiple instances of PTP
> programs (for example, to exercise the best master clock behavior)
> and for synchronizing virtual guests.
> 
> The first patch refactors the code that delivers raw error queue
> packets into a common function, in order to avoid multiple, nearly
> identical implementations. This can be used whenever a network layer
> has an error queue for transmit time stamp reporting only.

Series applied, thanks.

Next time, please use an appropriate subject prefix for patch #1.
For example, I added "net: " when I applied that patch.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2013-07-22 21:59 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-07-19 17:40 [PATCH net-next 0/2] Transmit time stamping on tun/tap interfaces Richard Cochran
2013-07-19 17:40 ` [PATCH net-next 1/2] Provide a generic socket error queue delivery method for Tx time stamps Richard Cochran
2013-07-19 17:40 ` [PATCH net-next 2/2] tun: Support software transmit time stamping Richard Cochran
2013-07-22 21:59 ` [PATCH net-next 0/2] Transmit time stamping on tun/tap interfaces David Miller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).