netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFC] net : add tx timestamp to packet mmap.
@ 2012-12-12 15:29 Paul Chavent
  2012-12-12 19:23 ` David Miller
  2012-12-13 13:29 ` Richard Cochran
  0 siblings, 2 replies; 41+ messages in thread
From: Paul Chavent @ 2012-12-12 15:29 UTC (permalink / raw)
  To: davem, edumazet, daniel.borkmann, xemul, ebiederm, netdev; +Cc: Paul Chavent

This patch allow to generate tx timestamps of packets sent by the packet mmap interface.

Actually, you can't get tx timestamps with the sample code below.

I wonder if my current implementation is good. And if not, how should i get the timestamps ?

Wouldn't be a good idea to put timestamps in the ring buffer frame before give it back to the user ?

Thanks for your comments.

/* BEGIN OF SAMPLE CODE */
struct timespec ts = {0,0};
struct sockaddr from_addr;
static uint8_t tmp_data[256];
struct iovec msg_iov = {tmp_data, sizeof(tmp_data)};
static uint8_t cmsg_buff[256];
struct msghdr msghdr = {&from_addr, sizeof(from_addr),
                        &msg_iov, 1,
                        cmsg_buff, sizeof(cmsg_buff),
                        0};

ssize_t err = recvmsg(itf->sock_fd, &msghdr, MSG_ERRQUEUE);
if(err < 0)
  {
    perror("recvmsg failed");
    return -1;
  }

struct cmsghdr *cmsg;
for(cmsg = CMSG_FIRSTHDR(&msghdr); cmsg != NULL; cmsg = CMSG_NXTHDR(&msghdr, cmsg))
{
  if(cmsg->cmsg_level == SOL_SOCKET && cmsg->cmsg_type == SCM_TIMESTAMPING)
    {
      ts = *(struct timespec *)CMSG_DATA(cmsg);
      fprintf(stderr, "SCM_TIMESTAMPING available\n");
    }
  else if (cmsg->cmsg_level == SOL_PACKET && cmsg->cmsg_type == PACKET_TX_TIMESTAMP)
      {
        ts = *(struct timespec *)CMSG_DATA(cmsg);
        fprintf(stderr, "PACKET_TX_TIMESTAMP available\n");
      }
} 
/* END OF SAMPLE CODE */

Signed-off-by: Paul Chavent <paul.chavent@onera.fr>
---
 net/packet/af_packet.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
index e639645..948748b 100644
--- a/net/packet/af_packet.c
+++ b/net/packet/af_packet.c
@@ -1857,6 +1857,10 @@ static int tpacket_fill_skb(struct packet_sock *po, struct sk_buff *skb,
 	void *data;
 	int err;
 
+	err = sock_tx_timestamp(&po->sk, &skb_shinfo(skb)->tx_flags);
+	if (err < 0)
+		return err;
+
 	ph.raw = frame;
 
 	skb->protocol = proto;
-- 
1.7.12.1

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

end of thread, other threads:[~2013-04-22 14:23 UTC | newest]

Thread overview: 41+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-12-12 15:29 [RFC] net : add tx timestamp to packet mmap Paul Chavent
2012-12-12 19:23 ` David Miller
2012-12-13  7:13   ` Paul Chavent
2012-12-13 13:29 ` Richard Cochran
2012-12-13 16:13   ` Paul Chavent
2012-12-13 18:17     ` Richard Cochran
2012-12-14  7:57       ` Paul Chavent
2013-04-09 10:42       ` Paul Chavent
2013-04-09 13:15         ` Richard Cochran
2013-04-13 18:33     ` Willem de Bruijn
2013-04-13 18:56       ` [PATCH] net-packet: tx timestamping on tpacket ring Willem de Bruijn
2013-04-13 22:18         ` Daniel Borkmann
2013-04-13 22:47           ` David Miller
2013-04-14  0:04             ` Willem de Bruijn
2013-04-14  0:16               ` Willem de Bruijn
2013-04-14  0:49                 ` Willem de Bruijn
2013-04-14  5:16                   ` Daniel Borkmann
2013-04-14  0:00           ` Willem de Bruijn
2013-04-14 10:52             ` Daniel Borkmann
2013-04-14 13:07               ` Richard Cochran
2013-04-15  7:37                 ` Paul Chavent
2013-04-15 16:56                   ` Richard Cochran
2013-04-15 16:59                   ` Willem de Bruijn
2013-04-17 10:22                     ` Richard Cochran
2013-04-19 21:51                     ` [PATCH net-next v2] packet: " Willem de Bruijn
2013-04-20 12:33                       ` Daniel Borkmann
2013-04-21  2:30                         ` Willem de Bruijn
2013-04-21 10:10                           ` Daniel Borkmann
2013-04-21 16:42                             ` Willem de Bruijn
2013-04-21 18:14                               ` Daniel Borkmann
2013-04-22  8:19                               ` Paul Chavent
2013-04-22 10:25                                 ` Daniel Borkmann
2013-04-22 14:23                                 ` Willem de Bruijn
2013-04-20 16:43                       ` Richard Cochran
2013-04-21  2:34                         ` Willem de Bruijn
2013-04-15 15:41               ` [PATCH] net-packet: " Paul Chavent
2013-04-15  9:45           ` David Laight
2013-04-15 17:08             ` Willem de Bruijn
2013-04-15 17:31             ` David Miller
2013-04-15  7:31         ` Paul Chavent
2013-04-15 16:37           ` Willem de Bruijn

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).