Skip to content

Commit ceaa1fe

Browse files
avagindavem330
authored andcommitted
tcp: adding a per-socket timestamp offset
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>
1 parent d0023f8 commit ceaa1fe

File tree

3 files changed

+7
-0
lines changed

3 files changed

+7
-0
lines changed

include/linux/tcp.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,8 @@ struct tcp_sock {
162162
u32 rcv_tstamp; /* timestamp of last received ACK (for keepalives) */
163163
u32 lsndtime; /* timestamp of last sent data packet (for restart window) */
164164

165+
u32 tsoffset; /* timestamp offset */
166+
165167
struct list_head tsq_node; /* anchor in tsq_tasklet.head list */
166168
unsigned long tsq_flags;
167169

@@ -353,6 +355,7 @@ struct tcp_timewait_sock {
353355
u32 tw_rcv_nxt;
354356
u32 tw_snd_nxt;
355357
u32 tw_rcv_wnd;
358+
u32 tw_ts_offset;
356359
u32 tw_ts_recent;
357360
long tw_ts_recent_stamp;
358361
#ifdef CONFIG_TCP_MD5SIG

net/ipv4/tcp.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,8 @@ void tcp_init_sock(struct sock *sk)
400400
tcp_enable_early_retrans(tp);
401401
icsk->icsk_ca_ops = &tcp_init_congestion_ops;
402402

403+
tp->tsoffset = 0;
404+
403405
sk->sk_state = TCP_CLOSE;
404406

405407
sk->sk_write_space = sk_stream_write_space;

net/ipv4/tcp_minisocks.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,7 @@ void tcp_time_wait(struct sock *sk, int state, int timeo)
288288
tcptw->tw_rcv_wnd = tcp_receive_window(tp);
289289
tcptw->tw_ts_recent = tp->rx_opt.ts_recent;
290290
tcptw->tw_ts_recent_stamp = tp->rx_opt.ts_recent_stamp;
291+
tcptw->tw_ts_offset = tp->tsoffset;
291292

292293
#if IS_ENABLED(CONFIG_IPV6)
293294
if (tw->tw_family == PF_INET6) {
@@ -499,6 +500,7 @@ struct sock *tcp_create_openreq_child(struct sock *sk, struct request_sock *req,
499500
newtp->rx_opt.ts_recent_stamp = 0;
500501
newtp->tcp_header_len = sizeof(struct tcphdr);
501502
}
503+
newtp->tsoffset = 0;
502504
#ifdef CONFIG_TCP_MD5SIG
503505
newtp->md5sig_info = NULL; /*XXX*/
504506
if (newtp->af_specific->md5_lookup(sk, newsk))

0 commit comments

Comments
 (0)