netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* sock_get_timestamp() ktime_to_timeval returns -2?
@ 2008-04-04 18:38 Andrew Brampton
  2008-04-05 12:38 ` Eric Dumazet
  0 siblings, 1 reply; 4+ messages in thread
From: Andrew Brampton @ 2008-04-04 18:38 UTC (permalink / raw)
  To: netdev

Hi,
I'm using the following piece of code to record the received time of my 
packets.

struct timeval tv = {0,0};
if ( ioctl(s, SIOCGSTAMP, &tv) )
   return 0;

When I use UDP this is all great, but when I use TCP this stops working. I 
have since found out that I can't use this for TCP packets[1], but the 
reason I'm writing this email is because ioctl returns zero when using TCP 
and tv has a odd value in it. tv.tv_sec = -2, and tv.tv_usec = 999999.

Now I assume -2 is some kind of error code, so I dug into the linux code to 
try and figure out what it means. The ioctl eventually calls 
sock_get_timestamp() which in turn calls ktime_to_timeval. I can see in 
sock_get_timestamp() that tv_sec is compared to -1 and ioctl returns an 
error, however I can not find where tv_sec is set to -2. If -2 is another 
error code then it should be checked inside sock_get_timestamp().

So I'm wondering if this is a bug in the kernel somewhere, or should I just 
expect ioctl to fail yet return 0? I have not included a test app, but if 
you want I'll be happy to code a short app to show this problem, but the 
critital lines are the ioctl call and that a TCP socket is used. This occurs 
on both the 2.6.22-3-amd64 kernel as well as on 2.6.24.

Thanks
Andrew

[1] http://www.ussg.iu.edu/hypermail/linux/kernel/0301.2/1248.html 


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

* Re: sock_get_timestamp() ktime_to_timeval returns -2?
  2008-04-04 18:38 sock_get_timestamp() ktime_to_timeval returns -2? Andrew Brampton
@ 2008-04-05 12:38 ` Eric Dumazet
  2008-04-07 21:57   ` Andrew Brampton
  2008-04-14  4:39   ` David Miller
  0 siblings, 2 replies; 4+ messages in thread
From: Eric Dumazet @ 2008-04-05 12:38 UTC (permalink / raw)
  To: Andrew Brampton, David S. Miller; +Cc: netdev

[-- Attachment #1: Type: text/plain, Size: 1675 bytes --]

Andrew Brampton a écrit :
> Hi,
> I'm using the following piece of code to record the received time of my 
> packets.
> 
> struct timeval tv = {0,0};
> if ( ioctl(s, SIOCGSTAMP, &tv) )
>   return 0;
> 
> When I use UDP this is all great, but when I use TCP this stops working. 
> I have since found out that I can't use this for TCP packets[1], but the 
> reason I'm writing this email is because ioctl returns zero when using 
> TCP and tv has a odd value in it. tv.tv_sec = -2, and tv.tv_usec = 999999.
> 
> Now I assume -2 is some kind of error code, so I dug into the linux code 
> to try and figure out what it means. The ioctl eventually calls 
> sock_get_timestamp() which in turn calls ktime_to_timeval. I can see in 
> sock_get_timestamp() that tv_sec is compared to -1 and ioctl returns an 
> error, however I can not find where tv_sec is set to -2. If -2 is 
> another error code then it should be checked inside sock_get_timestamp().
> 
> So I'm wondering if this is a bug in the kernel somewhere, or should I 
> just expect ioctl to fail yet return 0? I have not included a test app, 
> but if you want I'll be happy to code a short app to show this problem, 
> but the critital lines are the ioctl call and that a TCP socket is used. 
> This occurs on both the 2.6.22-3-amd64 kernel as well as on 2.6.24.



I believe the following patch should make sure ENOENT is delivered to the 
application. And yes, SIOCGSTAMP has a meaning only for UDP or other packet 
protocols.

Thank you Andrew for spotting this bug.

[SOCK] sk_stamp: should be initialized to ktime_set(-1L, 0)

Problem spotted by Andrew Brampton

Signed-off-by: Eric Dumazet <dada1@cosmosbay.com>


[-- Attachment #2: sk_stamp.patch --]
[-- Type: text/plain, Size: 430 bytes --]

diff --git a/net/core/sock.c b/net/core/sock.c
index 2654c14..7a0567b 100644
--- a/net/core/sock.c
+++ b/net/core/sock.c
@@ -1725,7 +1725,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
 	sk->sk_rcvtimeo		=	MAX_SCHEDULE_TIMEOUT;
 	sk->sk_sndtimeo		=	MAX_SCHEDULE_TIMEOUT;
 
-	sk->sk_stamp = ktime_set(-1L, -1L);
+	sk->sk_stamp = ktime_set(-1L, 0);
 
 	atomic_set(&sk->sk_refcnt, 1);
 	atomic_set(&sk->sk_drops, 0);

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

* Re: sock_get_timestamp() ktime_to_timeval returns -2?
  2008-04-05 12:38 ` Eric Dumazet
@ 2008-04-07 21:57   ` Andrew Brampton
  2008-04-14  4:39   ` David Miller
  1 sibling, 0 replies; 4+ messages in thread
From: Andrew Brampton @ 2008-04-07 21:57 UTC (permalink / raw)
  To: netdev, Eric Dumazet

From: "Eric Dumazet"
>
> I believe the following patch should make sure ENOENT is delivered to the
> application. And yes, SIOCGSTAMP has a meaning only for UDP or other 
> packet
> protocols.
>

Thanks Eric, I didn't expect someone to identify and fix this bug so 
quickly!. I have tested your patch and my problems have gone away.

thanks
Andrew 


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

* Re: sock_get_timestamp() ktime_to_timeval returns -2?
  2008-04-05 12:38 ` Eric Dumazet
  2008-04-07 21:57   ` Andrew Brampton
@ 2008-04-14  4:39   ` David Miller
  1 sibling, 0 replies; 4+ messages in thread
From: David Miller @ 2008-04-14  4:39 UTC (permalink / raw)
  To: dada1; +Cc: andrew, netdev

From: Eric Dumazet <dada1@cosmosbay.com>
Date: Sat, 05 Apr 2008 14:38:31 +0200

> [SOCK] sk_stamp: should be initialized to ktime_set(-1L, 0)
> 
> Problem spotted by Andrew Brampton
> 
> Signed-off-by: Eric Dumazet <dada1@cosmosbay.com>

Applied, thanks Eric.

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

end of thread, other threads:[~2008-04-14  4:39 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-04-04 18:38 sock_get_timestamp() ktime_to_timeval returns -2? Andrew Brampton
2008-04-05 12:38 ` Eric Dumazet
2008-04-07 21:57   ` Andrew Brampton
2008-04-14  4:39   ` 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).