tcp: adding a per-socket timestamp offset
authorAndrey Vagin <avagin@openvz.org>
Mon, 11 Feb 2013 05:50:17 +0000 (05:50 +0000)
committerDavid S. Miller <davem@davemloft.net>
Wed, 13 Feb 2013 18:22:15 +0000 (13:22 -0500)
This functionality is used for restoring tcp sockets. A tcp timestamp
depends on how long a system has been running, so it's differ for each
host. The solution is to set a per-socket offset.

A per-socket offset for a TIME_WAIT socket is inherited from a proper
tcp socket.

tcp_request_sock doesn't have a timestamp offset, because the repair
mode for them are not implemented.

Cc: "David S. Miller" <davem@davemloft.net>
Cc: Alexey Kuznetsov <kuznet@ms2.inr.ac.ru>
Cc: James Morris <jmorris@namei.org>
Cc: Hideaki YOSHIFUJI <yoshfuji@linux-ipv6.org>
Cc: Patrick McHardy <kaber@trash.net>
Cc: Eric Dumazet <edumazet@google.com>
Cc: Pavel Emelyanov <xemul@parallels.com>
Signed-off-by: Andrey Vagin <avagin@openvz.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
include/linux/tcp.h
net/ipv4/tcp.c
net/ipv4/tcp_minisocks.c

index 6d0d461..f28408c 100644 (file)
@@ -162,6 +162,8 @@ struct tcp_sock {
        u32     rcv_tstamp;     /* timestamp of last received ACK (for keepalives) */
        u32     lsndtime;       /* timestamp of last sent data packet (for restart window) */
 
+       u32     tsoffset;       /* timestamp offset */
+
        struct list_head tsq_node; /* anchor in tsq_tasklet.head list */
        unsigned long   tsq_flags;
 
@@ -353,6 +355,7 @@ struct tcp_timewait_sock {
        u32                       tw_rcv_nxt;
        u32                       tw_snd_nxt;
        u32                       tw_rcv_wnd;
+       u32                       tw_ts_offset;
        u32                       tw_ts_recent;
        long                      tw_ts_recent_stamp;
 #ifdef CONFIG_TCP_MD5SIG
index 2c7e596..8a90bda 100644 (file)
@@ -400,6 +400,8 @@ void tcp_init_sock(struct sock *sk)
        tcp_enable_early_retrans(tp);
        icsk->icsk_ca_ops = &tcp_init_congestion_ops;
 
+       tp->tsoffset = 0;
+
        sk->sk_state = TCP_CLOSE;
 
        sk->sk_write_space = sk_stream_write_space;
index f040928..4dfc99f 100644 (file)
@@ -288,6 +288,7 @@ void tcp_time_wait(struct sock *sk, int state, int timeo)
                tcptw->tw_rcv_wnd       = tcp_receive_window(tp);
                tcptw->tw_ts_recent     = tp->rx_opt.ts_recent;
                tcptw->tw_ts_recent_stamp = tp->rx_opt.ts_recent_stamp;
+               tcptw->tw_ts_offset     = tp->tsoffset;
 
 #if IS_ENABLED(CONFIG_IPV6)
                if (tw->tw_family == PF_INET6) {
@@ -499,6 +500,7 @@ struct sock *tcp_create_openreq_child(struct sock *sk, struct request_sock *req,
                        newtp->rx_opt.ts_recent_stamp = 0;
                        newtp->tcp_header_len = sizeof(struct tcphdr);
                }
+               newtp->tsoffset = 0;
 #ifdef CONFIG_TCP_MD5SIG
                newtp->md5sig_info = NULL;      /*XXX*/
                if (newtp->af_specific->md5_lookup(sk, newsk))