Transmit time stamping on tun/tap interfaces
Subsystems (5)
cover Transmit time stamping on tun/tap interfaces
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(-)
Signature · 1 line
1.7.10.4
PATCH 1/2 Provide a generic socket error queue delivery method for Tx time stamps.
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.
--- include/net/sock.h | 2 ++ net/core/sock.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ net/packet/af_packet.c | 48 ++---------------------------------------------- 3 files changed, 51 insertions(+), 46 deletions(-)
include/net/sock.h +2 -0
@@ -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
net/core/sock.c +47 -0
59 lines not on this page · raw message
net/packet/af_packet.c +2 -46
60 lines not on this page · raw message
Signature · 1 line
1.7.10.4
PATCH 2/2 tun: Support software transmit time stamping.
In reply to Richard CochranThis patch adds transmit time stamping to the tun/tap driver. Similar support already exists for UDP, can, and raw packets.
--- drivers/net/tun.c | 14 ++++++++++++-- include/uapi/linux/if_tun.h | 3 +++ 2 files changed, 15 insertions(+), 2 deletions(-)
drivers/net/tun.c +12 -2
@@ -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, };
include/uapi/linux/if_tun.h +3 -0
@@ -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 */
Signature · 1 line
1.7.10.4
David Miller
maintainerFrom: Richard Cochran <[email protected]>
Date: Fri, 19 Jul 2013 19:40:08 +0200
Quoted 9 lines
This series adds transmit
SO_TIMESTAMPINGfor 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.