tcp: set and get per-socket timestamp
authorAndrey Vagin <[email protected]>
Mon, 11 Feb 2013 05:50:18 +0000 (05:50 +0000)
committerDavid S. Miller <[email protected]>
Wed, 13 Feb 2013 18:22:15 +0000 (13:22 -0500)
A timestamp can be set, only if a socket is in the repair mode.

This patch adds a new socket option TCP_TIMESTAMP, which allows to
get and set current tcp times stamp.

Cc: "David S. Miller" <[email protected]>
Cc: Alexey Kuznetsov <[email protected]>
Cc: James Morris <[email protected]>
Cc: Hideaki YOSHIFUJI <[email protected]>
Cc: Patrick McHardy <[email protected]>
Cc: Eric Dumazet <[email protected]>
Cc: Pavel Emelyanov <[email protected]>
Signed-off-by: Andrey Vagin <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
include/uapi/linux/tcp.h
net/ipv4/tcp.c

index e962faa5ab0dcf9d58909b0256a78f51029e290b..6b1ead0b0c9d54a041bda86d5cf9b927e9aa3a56 100644 (file)
@@ -111,6 +111,7 @@ enum {
 #define TCP_QUEUE_SEQ          21
 #define TCP_REPAIR_OPTIONS     22
 #define TCP_FASTOPEN           23      /* Enable FastOpen on listeners */
+#define TCP_TIMESTAMP          24
 
 struct tcp_repair_opt {
        __u32   opt_code;
index 8a90bda960381ee0f577062e55560470fcc27684..801b07b796f01a78b8bc0beeaae71eb1bca0d26c 100644 (file)
@@ -2714,6 +2714,12 @@ static int do_tcp_setsockopt(struct sock *sk, int level,
                else
                        err = -EINVAL;
                break;
+       case TCP_TIMESTAMP:
+               if (!tp->repair)
+                       err = -EPERM;
+               else
+                       tp->tsoffset = val - tcp_time_stamp;
+               break;
        default:
                err = -ENOPROTOOPT;
                break;
@@ -2962,6 +2968,9 @@ static int do_tcp_getsockopt(struct sock *sk, int level,
        case TCP_USER_TIMEOUT:
                val = jiffies_to_msecs(icsk->icsk_user_timeout);
                break;
+       case TCP_TIMESTAMP:
+               val = tcp_time_stamp + tp->tsoffset;
+               break;
        default:
                return -ENOPROTOOPT;
        }