Patchwork tcp: update the netstamp_needed counter when cloning sockets

login
register
mail settings
Submitter Octavian Purdila
Date Jan. 5, 2010, 11:06 p.m.
Message ID <1262732790-16053-1-git-send-email-opurdila@ixiacom.com>
Download mbox | patch
Permalink /patch/42222/
State Accepted
Delegated to: David Miller
Headers show

Comments

Octavian Purdila - Jan. 5, 2010, 11:06 p.m.
This fixes a netstamp_needed accounting issue when the listen socket
has SO_TIMESTAMP set:

    s = socket(AF_INET, SOCK_STREAM, 0);
    setsockopt(s, SOL_SOCKET, SO_TIMESTAMP, 1); -> netstamp_needed = 1
    bind(s, ...);
    listen(s, ...);
    s2 = accept(s, ...); -> netstamp_needed = 1
    close(s2); -> netstamp_needed = 0
    close(s); -> netstamp_needed = -1

Signed-off-by: Octavian Purdila <opurdila@ixiacom.com>
---
 net/core/sock.c |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)
David Miller - Jan. 8, 2010, 8 a.m.
From: Octavian Purdila <opurdila@ixiacom.com>
Date: Wed,  6 Jan 2010 01:06:30 +0200

> This fixes a netstamp_needed accounting issue when the listen socket
> has SO_TIMESTAMP set:
> 
>     s = socket(AF_INET, SOCK_STREAM, 0);
>     setsockopt(s, SOL_SOCKET, SO_TIMESTAMP, 1); -> netstamp_needed = 1
>     bind(s, ...);
>     listen(s, ...);
>     s2 = accept(s, ...); -> netstamp_needed = 1
>     close(s2); -> netstamp_needed = 0
>     close(s); -> netstamp_needed = -1
> 
> Signed-off-by: Octavian Purdila <opurdila@ixiacom.com>

Applied and queued up for -stable, thanks for fixing this!
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Patch

diff --git a/net/core/sock.c b/net/core/sock.c
index 76ff58d..e1f6f22 100644
--- a/net/core/sock.c
+++ b/net/core/sock.c
@@ -1205,6 +1205,10 @@  struct sock *sk_clone(const struct sock *sk, const gfp_t priority)
 
 		if (newsk->sk_prot->sockets_allocated)
 			percpu_counter_inc(newsk->sk_prot->sockets_allocated);
+
+		if (sock_flag(newsk, SOCK_TIMESTAMP) ||
+		    sock_flag(newsk, SOCK_TIMESTAMPING_RX_SOFTWARE))
+			net_enable_timestamp();
 	}
 out:
 	return newsk;