Skip to contentSkip to conversation

c/r: Add support for connected AF_INET sockets

RFC PATCH In review Dan Smith 6 participants 13 messages Oct 20, 2009 – Oct 23, 2009 6 messages not in the archive

Subsystems (4)
lore
Share & tools
lore

Dan Smith

author
#0 lore raw

This updated patch set fixes some issues idenitifed in the second patch, as well as adds some additional features and documentation. It also brings a third patch that handles TCP timestamp adjustment and a fourth that adds some information about sockets to the checkpoint/readme.txt in Documentation/.

#1 lore raw

RFC PATCH 2/4 Add c/r support for connected INET sockets

This patch adds basic support for C/R of open INET sockets. I think that all the important bits of the TCP and ICSK socket structures is saved, but I think there is still some additional IPv6 stuff that needs to be handled.

With this patch applied, the following script can be used to demonstrate the functionality:

https://lists.linux-foundation.org/pipermail/containers/2009-October/021239.html

It shows that this enables migration of a sendmail process with open connections from one machine to another without dropping.

We still need comments from the netdev people about what sort of sanity checking we need to do on the values in the ckpt_hdr_socket_inet structure on restart.

Note that this still doesn't address lingering sockets yet.

Changes in v2:
- Restore saddr, rcv_saddr, daddr, sport, and dport from the sockaddr structure instead of saving them separately
- Fix 'sock' naming in sock_cptrst()
- Don't take the queue lock before skb_queue_tail() since it is done for us
- Allow "listen only" restore behavior if RESTART_SOCK_LISTENONLY flag is specified on sys_restart()
- Pull the implementation of the list of listening sockets back into this patch
- Fix dangling printk
- Add some comments around the parent/child restore logic

---
 checkpoint/sys.c                 |    4 +
 include/linux/checkpoint.h       |    5 +-
 include/linux/checkpoint_hdr.h   |   97 ++++++++++++++
 include/linux/checkpoint_types.h |    2 +
 net/checkpoint.c                 |   23 ++--
 net/ipv4/checkpoint.c            |  263 +++++++++++++++++++++++++++++++++++++-
 6 files changed, 379 insertions(+), 15 deletions(-)
checkpoint/sys.c +4 -0
index 260a1ee..df00973 100644
@@ -221,6 +221,8 @@ static void ckpt_ctx_free(struct ckpt_ctx *ctx)
 
 	kfree(ctx->pids_arr);
 
+	sock_listening_list_free(&ctx->listen_sockets);
+
 	kfree(ctx);
 }
 
@@ -249,6 +251,8 @@ static struct ckpt_ctx *ckpt_ctx_alloc(int fd, unsigned long uflags,
 	spin_lock_init(&ctx->lock);
 #endif
 
+	INIT_LIST_HEAD(&ctx->listen_sockets);
+
 	err = -EBADF;
 	ctx->file = fget(fd);
 	if (!ctx->file)
include/linux/checkpoint.h +4 -1
index 1da0b04..73d1677 100644
@@ -19,6 +19,7 @@
 #define RESTART_TASKSELF	0x1
 #define RESTART_FROZEN		0x2
 #define RESTART_GHOST		0x4
+#define RESTART_SOCK_LISTENONLY 0x8
 
 #ifdef __KERNEL__
 #ifdef CONFIG_CHECKPOINT
@@ -48,7 +49,8 @@
 #define RESTART_USER_FLAGS  \
 	(RESTART_TASKSELF | \
 	 RESTART_FROZEN | \
-	 RESTART_GHOST)
+	 RESTART_GHOST | \
+	 RESTART_SOCK_LISTENONLY)
 
 extern int walk_task_subtree(struct task_struct *task,
 			     int (*func)(struct task_struct *, void *),
@@ -102,6 +104,7 @@ extern int ckpt_sock_getnames(struct ckpt_ctx *ctx,
 			      struct sockaddr *rem, unsigned *rem_len);
 void sock_restore_header_info(struct sk_buff *skb,
 			      struct ckpt_hdr_socket_buffer *h);
+void sock_listening_list_free(struct list_head *head);
 
 /* ckpt kflags */
 #define ckpt_set_ctx_kflag(__ctx, __kflag)  \
include/linux/checkpoint_hdr.h +97 -0

109 lines not on this page · raw message

include/linux/checkpoint_types.h +2 -0
index fa57cdc..91c141b 100644
@@ -65,6 +65,8 @@ struct ckpt_ctx {
 	struct list_head pgarr_list;	/* page array to dump VMA contents */
 	struct list_head pgarr_pool;	/* pool of empty page arrays chain */
 
+	struct list_head listen_sockets;/* listening parent sockets */
+
 	/* [multi-process checkpoint] */
 	struct task_struct **tasks_arr; /* array of all tasks [checkpoint] */
 	int nr_tasks;                   /* size of tasks array */
net/checkpoint.c +11 -12
index 5ed2724..3e7574d 100644
@@ -122,6 +122,7 @@ void sock_restore_header_info(struct sk_buff *skb,
 
 static int __sock_write_buffers(struct ckpt_ctx *ctx,
 				struct sk_buff_head *queue,
+				uint16_t family,
 				int dst_objref)
 {
 	struct sk_buff *skb;
@@ -130,11 +131,7 @@ static int __sock_write_buffers(struct ckpt_ctx *ctx,
 		struct ckpt_hdr_socket_buffer *h;
 		int ret = 0;
 
-		/* FIXME: This could be a false positive for non-unix
-		 *        buffers, so add a type check here in the
-		 *        future
-		 */
-		if (UNIXCB(skb).fp) {
+		if ((family == AF_UNIX) && UNIXCB(skb).fp) {
 			ckpt_write_err(ctx, "TE", "af_unix: pass fd", -EBUSY);
 			return -EBUSY;
 		}
@@ -174,6 +171,7 @@ static int __sock_write_buffers(struct ckpt_ctx *ctx,
 
 static int sock_write_buffers(struct ckpt_ctx *ctx,
 			      struct sk_buff_head *queue,
+			      uint16_t family,
 			      int dst_objref)
 {
 	struct ckpt_hdr_socket_queue *h;
@@ -193,7 +191,7 @@ static int sock_write_buffers(struct ckpt_ctx *ctx,
 	h->skb_count = ret;
 	ret = ckpt_write_obj(ctx, (struct ckpt_hdr *) h);
 	if (!ret)
-		ret = __sock_write_buffers(ctx, &tmpq, dst_objref);
+		ret = __sock_write_buffers(ctx, &tmpq, family, dst_objref);
 
  out:
 	ckpt_hdr_put(ctx, h);
@@ -215,12 +213,14 @@ int sock_deferred_write_buffers(void *data)
 		return dst_objref;
 	}
 
-	ret = sock_write_buffers(ctx, &dq->sk->sk_receive_queue, dst_objref);
+	ret = sock_write_buffers(ctx, &dq->sk->sk_receive_queue,
+				 dq->sk->sk_family, dst_objref);
 	ckpt_debug("write recv buffers: %i\n", ret);
 	if (ret < 0)
 		return ret;
 
-	ret = sock_write_buffers(ctx, &dq->sk->sk_write_queue, dst_objref);
+	ret = sock_write_buffers(ctx, &dq->sk->sk_write_queue,
+				 dq->sk->sk_family, dst_objref);
 	ckpt_debug("write send buffers: %i\n", ret);
 
 	return ret;
@@ -745,10 +745,9 @@ struct sock *do_sock_restore(struct ckpt_ctx *ctx)
 		goto err;
 
 	if ((h->sock_common.family == AF_INET) &&
-	    (h->sock.state != TCP_LISTEN)) {
-		/* Temporary hack to enable restore of TCP_LISTEN sockets
-		 * while forcing anything else to a closed state
-		 */
+	    (h->sock.state != TCP_LISTEN) &&
+	    (ctx->uflags & RESTART_SOCK_LISTENONLY)) {
+		ckpt_debug("Forcing open socket closed\n");
 		sock->sk->sk_state = TCP_CLOSE;
 		sock->state = SS_UNCONNECTED;
 	}
net/ipv4/checkpoint.c +261 -2

296 lines not on this page · raw message

Signature · 1 line
1.6.2.5
Acked-by on v1 2/4
#2 lore raw

Re: [PATCH 2/4] [RFC] Add c/r support for connected INET sockets

Quoted 32 lines · Dan Smith

This patch adds basic support for C/R of open INET sockets. I think that all the important bits of the TCP and ICSK socket structures is saved, but I think there is still some additional IPv6 stuff that needs to be handled.

With this patch applied, the following script can be used to demonstrate the functionality:

https://lists.linux-foundation.org/pipermail/containers/2009-October/021239.html

It shows that this enables migration of a sendmail process with open connections from one machine to another without dropping.

We still need comments from the netdev people about what sort of sanity checking we need to do on the values in the ckpt_hdr_socket_inet structure on restart.

Note that this still doesn't address lingering sockets yet.

Changes in v2:
- Restore saddr, rcv_saddr, daddr, sport, and dport from the sockaddr structure instead of saving them separately
- Fix 'sock' naming in sock_cptrst()
- Don't take the queue lock before skb_queue_tail() since it is done for us
- Allow "listen only" restore behavior if RESTART_SOCK_LISTENONLY flag is specified on sys_restart()
- Pull the implementation of the list of listening sockets back into this patch
- Fix dangling printk
- Add some comments around the parent/child restore logic

Quoted 4 lines

fwiw,

except

net/ipv4/checkpoint.c struct dq_buffers { · line 192

Quoted 9 lines
net/ipv4/checkpoint.c +9 -0
+static int sock_inet_restore_addrs(struct inet_sock *inet,
+				   struct ckpt_hdr_socket_inet *hh)
+{
+	inet->daddr = hh->raddr.sin_addr.s_addr;
+	inet->saddr = hh->laddr.sin_addr.s_addr;
+	inet->rcv_saddr = inet->saddr;
+
+	inet->dport = hh->raddr.sin_port;
+	inet->sport = hh->laddr.sin_port;

Sorry, I think we've discussed this before but can't recall - does setting sport here allow an unpriv user to bypass CAP_NET_BIND_SERVICE?

-serge

#3 lore raw

Re: [PATCH 2/4] [RFC] Add c/r support for connected INET sockets

SH> Sorry, I think we've discussed this before but can't recall - does SH> setting sport here allow an unpriv user to bypass
SH> CAP_NET_BIND_SERVICE?

Yes, it does. I was kinda considering that part of the input sanity checking that I officially punted on. However, as far as I know, we'll just need to check that capability before we bind() in the listen/closed case and hash in the connected case.

Signature · 3 lines
Dan Smith
IBM Linux Technology Center
email: [email protected]
Acked-by on v1 2/4
#4 lore raw

Re: [PATCH 2/4] [RFC] Add c/r support for connected INET sockets

In reply to Dan Smith
Quoted 19 lines · Dan Smith

This patch adds basic support for C/R of open INET sockets. I think that all the important bits of the TCP and ICSK socket structures is saved, but I think there is still some additional IPv6 stuff that needs to be handled.

With this patch applied, the following script can be used to demonstrate the functionality:

https://lists.linux-foundation.org/pipermail/containers/2009-October/021239.html

It shows that this enables migration of a sendmail process with open connections from one machine to another without dropping.

We still need comments from the netdev people about what sort of sanity checking we need to do on the values in the ckpt_hdr_socket_inet structure on restart.

Note that this still doesn't address lingering sockets yet.

[...]

include/linux/checkpoint_types.h struct ckpt_ctx { · line 69

Quoted 10 lines
include/linux/checkpoint_types.h +2 -0
index fa57cdc..91c141b 100644
@@ -65,6 +65,8 @@ struct ckpt_ctx {
 	struct list_head pgarr_list;	/* page array to dump VMA contents */
 	struct list_head pgarr_pool;	/* pool of empty page arrays chain */
 
+	struct list_head listen_sockets;/* listening parent sockets */
+

Nit: maybe move under the comment "multi-process restart" ?

[...]

Otherwise (and pending comments from netdev people on sanity checks):

A message that is not in the archive (sent off-list or not yet received): 1256072803-3518-1-git-send-email-danms-r/[email protected]

author
#6 lore raw

PATCH 1/4 Record and restore skb header marks

Save this information when we checkpoint an skb and provide a mechanism to restore that information on restart. This will be used in the subsequent INET patch.

---
 include/linux/checkpoint.h     |    2 ++
 include/linux/checkpoint_hdr.h |    7 +++++++
 net/checkpoint.c               |   33 +++++++++++++++++++++++++++++++++
 3 files changed, 42 insertions(+), 0 deletions(-)
include/linux/checkpoint.h +2 -0
index 4b61378..1da0b04 100644
@@ -100,6 +100,8 @@ extern int ckpt_sock_getnames(struct ckpt_ctx *ctx,
 			      struct socket *socket,
 			      struct sockaddr *loc, unsigned *loc_len,
 			      struct sockaddr *rem, unsigned *rem_len);
+void sock_restore_header_info(struct sk_buff *skb,
+			      struct ckpt_hdr_socket_buffer *h);
 
 /* ckpt kflags */
 #define ckpt_set_ctx_kflag(__ctx, __kflag)  \
include/linux/checkpoint_hdr.h +7 -0
index ca2500d..3e6cab1 100644
@@ -542,8 +542,15 @@ struct ckpt_hdr_socket_queue {
 
 struct ckpt_hdr_socket_buffer {
 	struct ckpt_hdr h;
+	__u64 mac_len;
+	__u64 hdr_len;
+	__u64 transport_header;
+	__u64 network_header;
+	__u64 mac_header;
 	__s32 sk_objref;
 	__s32 pr_objref;
+	__u16 protocol;
+	__u8 cb[48];
 };
 
 #define CKPT_UNIX_LINKED 1
net/checkpoint.c +33 -0
index dd23efd..5ed2724 100644
@@ -88,6 +88,38 @@ static int sock_copy_buffers(struct sk_buff_head *from,
 	return -EAGAIN;
 }
 
+static void sock_record_header_info(struct sk_buff *skb,
+				    struct ckpt_hdr_socket_buffer *h)
+{
+
+	h->mac_len = skb->mac_len;
+	h->hdr_len = skb->hdr_len;
+
+#ifdef NET_SKBUFF_DATA_USES_OFFSET
+	h->transport_header = skb->transport_hdr;
+	h->network_header = skb->network_header;
+	h->mac_header = skb->mac_header;
+#else
+	h->transport_header = skb->transport_header - skb->head;
+	h->network_header = skb->network_header - skb->head;
+	h->mac_header = skb->mac_header - skb->head;
+#endif
+
+	memcpy(h->cb, skb->cb, sizeof(skb->cb));
+}
+
+void sock_restore_header_info(struct sk_buff *skb,
+			      struct ckpt_hdr_socket_buffer *h)
+{
+	skb->mac_len = h->mac_len;
+	skb->hdr_len = h->hdr_len;
+	skb_set_transport_header(skb, h->transport_header);
+	skb_set_network_header(skb, h->network_header);
+	skb_set_mac_header(skb, h->mac_header);
+
+	memcpy(skb->cb, h->cb, sizeof(skb->cb));
+}
+
 static int __sock_write_buffers(struct ckpt_ctx *ctx,
 				struct sk_buff_head *queue,
 				int dst_objref)
@@ -123,6 +155,7 @@ static int __sock_write_buffers(struct ckpt_ctx *ctx,
 			goto end;
 		h->sk_objref = ret;
 		h->pr_objref = dst_objref;
+		sock_record_header_info(skb, h);
 
 		ret = ckpt_write_obj(ctx, (struct ckpt_hdr *) h);
 		if (ret < 0)
Signature · 1 line
1.6.2.5

A message that is not in the archive (sent off-list or not yet received): 1256072803-3518-2-git-send-email-danms-r/[email protected]

#8 lore raw

Re: [PATCH 1/4] Record and restore skb header marks

Quoted 70 lines · Dan Smith

Save this information when we checkpoint an skb and provide a mechanism to restore that information on restart. This will be used in the subsequent INET patch.

---
 include/linux/checkpoint.h     |    2 ++
 include/linux/checkpoint_hdr.h |    7 +++++++
 net/checkpoint.c               |   33 +++++++++++++++++++++++++++++++++
 3 files changed, 42 insertions(+), 0 deletions(-)
include/linux/checkpoint.h +2 -0
index 4b61378..1da0b04 100644
@@ -100,6 +100,8 @@ extern int ckpt_sock_getnames(struct ckpt_ctx *ctx,
 			      struct socket *socket,
 			      struct sockaddr *loc, unsigned *loc_len,
 			      struct sockaddr *rem, unsigned *rem_len);
+void sock_restore_header_info(struct sk_buff *skb,
+			      struct ckpt_hdr_socket_buffer *h);
 
 /* ckpt kflags */
 #define ckpt_set_ctx_kflag(__ctx, __kflag)  \
include/linux/checkpoint_hdr.h +7 -0
index ca2500d..3e6cab1 100644
@@ -542,8 +542,15 @@ struct ckpt_hdr_socket_queue {
 
 struct ckpt_hdr_socket_buffer {
 	struct ckpt_hdr h;
+	__u64 mac_len;
+	__u64 hdr_len;
+	__u64 transport_header;
+	__u64 network_header;
+	__u64 mac_header;
 	__s32 sk_objref;
 	__s32 pr_objref;
+	__u16 protocol;
+	__u8 cb[48];
 };
 
 #define CKPT_UNIX_LINKED 1
net/checkpoint.c +18 -0
index dd23efd..5ed2724 100644
@@ -88,6 +88,38 @@ static int sock_copy_buffers(struct sk_buff_head *from,
 	return -EAGAIN;
 }
 
+static void sock_record_header_info(struct sk_buff *skb,
+				    struct ckpt_hdr_socket_buffer *h)
+{
+
+	h->mac_len = skb->mac_len;
+	h->hdr_len = skb->hdr_len;
+
+#ifdef NET_SKBUFF_DATA_USES_OFFSET
+	h->transport_header = skb->transport_hdr;
+	h->network_header = skb->network_header;
+	h->mac_header = skb->mac_header;
+#else
+	h->transport_header = skb->transport_header - skb->head;
+	h->network_header = skb->network_header - skb->head;
+	h->mac_header = skb->mac_header - skb->head;
+#endif
+
+	memcpy(h->cb, skb->cb, sizeof(skb->cb));

net/checkpoint.c static int sock_copy_buffers(struct sk_buff_head *from, · line 118

Quoted 10 lines
net/checkpoint.c +10 -0
+}
+
+void sock_restore_header_info(struct sk_buff *skb,
+			      struct ckpt_hdr_socket_buffer *h)
+{
+	skb->mac_len = h->mac_len;
+	skb->hdr_len = h->hdr_len;
+	skb_set_transport_header(skb, h->transport_header);
+	skb_set_network_header(skb, h->network_header);
+	skb_set_mac_header(skb, h->mac_header);

Should you verify that each of these new headers is located inside the skb?

net/checkpoint.c static int sock_copy_buffers(struct sk_buff_head *from, · line 120

Quoted 2 lines
net/checkpoint.c +2 -0
+
+	memcpy(skb->cb, h->cb, sizeof(skb->cb));

verify that (h->h.len - (h->cb - h->h)) > sizeof(skb->cb)) ?

Quoted 20 lines
net/checkpoint.c +3 -0
+}
+
 static int __sock_write_buffers(struct ckpt_ctx *ctx,
 				struct sk_buff_head *queue,
 				int dst_objref)
@@ -123,6 +155,7 @@ static int __sock_write_buffers(struct ckpt_ctx *ctx,
 			goto end;
 		h->sk_objref = ret;
 		h->pr_objref = dst_objref;
+		sock_record_header_info(skb, h);
 
 		ret = ckpt_write_obj(ctx, (struct ckpt_hdr *) h);
 		if (ret < 0)
Signature · 6 lines
1.6.2.5

_______________________________________________
Containers mailing list
Containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org
https://lists.linux-foundation.org/mailman/listinfo/containers

A message that is not in the archive (sent off-list or not yet received): 20091021155201.GA15402-r/[email protected]

author
#10 lore raw

Re: [PATCH 1/4] Record and restore skb header marks

SH> Should you verify that each of these new headers is located SH> inside the skb?

<Ahem> Um. Yes.... :)

Signature · 3 lines
Dan Smith
IBM Linux Technology Center
email: danms-r/[email protected]
author
#11 lore raw

PATCH 3/4 Adjust TCP timestamp values by a scalar value

In reply to a message not in the archive

Adjust the sent and received TCP timestamp value by a scalar value in the tcp_sock structure. This will be zero most of the time, except when the socket has been migrated with c/r. If a socket is re-migrated, we take the new adjusted value as the saved value so that on restart it can be re-adjusted. Also, copy this into the timewait sock so that timestamps can continue to be adjusted in timewait state in the minisocks code.

Note that TCP timestamps are just a jiffies stamp, which means they have no relation to wall-clock time and thus a simple correction factor should be enough to ensure correctness.

---
 include/linux/checkpoint_hdr.h |    2 ++
 include/linux/tcp.h            |    3 +++
 include/net/tcp.h              |    3 ++-
 net/ipv4/checkpoint.c          |    8 ++++++++
 net/ipv4/syncookies.c          |    2 +-
 net/ipv4/tcp_input.c           |   14 +++++++-------
 net/ipv4/tcp_ipv4.c            |    2 +-
 net/ipv4/tcp_minisocks.c       |    8 ++++++--
 net/ipv4/tcp_output.c          |   20 ++++++++++----------
 net/ipv6/syncookies.c          |    2 +-
 net/ipv6/tcp_ipv6.c            |    2 +-
 11 files changed, 42 insertions(+), 24 deletions(-)
include/linux/checkpoint_hdr.h +2 -0
index 0c10657..9c2f13d 100644
@@ -649,6 +649,8 @@ struct ckpt_hdr_socket_inet {
 		__u32 keepalive_time;
 		__u32 keepalive_intvl;
 
+		__s32 tcp_ts;
+
 		__u16 urg_data;
 		__u16 advmss;
 		__u8 frto_counter;
include/linux/tcp.h +3 -0
index 8afac76..b845e21 100644
@@ -399,6 +399,8 @@ struct tcp_sock {
 		u32		  probe_seq_end;
 	} mtu_probe;
 
+	s32	ts_adjust;	/* tcp_time_stamp adjustment factor */
+
 #ifdef CONFIG_TCP_MD5SIG
 /* TCP AF-Specific parts; only used by MD5 Signature support so far */
 	struct tcp_sock_af_ops	*af_specific;
@@ -420,6 +422,7 @@ struct tcp_timewait_sock {
 	u32			  tw_rcv_wnd;
 	u32			  tw_ts_recent;
 	long			  tw_ts_recent_stamp;
+	s32			  tw_ts_adjust;
 #ifdef CONFIG_TCP_MD5SIG
 	u16			  tw_md5_keylen;
 	u8			  tw_md5_key[TCP_MD5SIG_MAXKEYLEN];
include/net/tcp.h +2 -1
index 88af843..96b4b27 100644
@@ -409,7 +409,8 @@ extern int			tcp_recvmsg(struct kiocb *iocb, struct sock *sk,
 
 extern void			tcp_parse_options(struct sk_buff *skb,
 						  struct tcp_options_received *opt_rx,
-						  int estab);
+						  int estab,
+						  s32 ts_adjust);
 
 extern u8			*tcp_parse_md5sig_option(struct tcphdr *th);
 
net/ipv4/checkpoint.c +8 -0
index 5913652..f858dbc 100644
@@ -178,6 +178,14 @@ static int sock_inet_tcp_cptrst(struct ckpt_ctx *ctx,
 	CKPT_COPY(op, hh->tcp.keepalive_time, sk->keepalive_time);
 	CKPT_COPY(op, hh->tcp.keepalive_intvl, sk->keepalive_intvl);
 
+	if (op == CKPT_CPT)
+		hh->tcp.tcp_ts = tcp_time_stamp + sk->ts_adjust;
+	else
+		sk->ts_adjust = hh->tcp.tcp_ts - tcp_time_stamp;
+
+	ckpt_debug("TCP tcp_ts %i ts_adjust %i\n",
+		   hh->tcp.tcp_ts, sk->ts_adjust);
+
 	return 0;
 }
 
net/ipv4/syncookies.c +1 -1
index cd2b97f..31eafef 100644
@@ -277,7 +277,7 @@ struct sock *cookie_v4_check(struct sock *sk, struct sk_buff *skb,
 
 	/* check for timestamp cookie support */
 	memset(&tcp_opt, 0, sizeof(tcp_opt));
-	tcp_parse_options(skb, &tcp_opt, 0);
+	tcp_parse_options(skb, &tcp_opt, 0, tp->ts_adjust);
 
 	if (tcp_opt.saw_tstamp)
 		cookie_check_timestamp(&tcp_opt);
net/ipv4/tcp_input.c +7 -7
index 2bdb0da..63cac78 100644
@@ -3699,7 +3699,7 @@ old_ack:
  * the fast version below fails.
  */
 void tcp_parse_options(struct sk_buff *skb, struct tcp_options_received *opt_rx,
-		       int estab)
+		       int estab, s32 ts_adjust)
 {
 	unsigned char *ptr;
 	struct tcphdr *th = tcp_hdr(skb);
@@ -3756,8 +3756,8 @@ void tcp_parse_options(struct sk_buff *skb, struct tcp_options_received *opt_rx,
 				    ((estab && opt_rx->tstamp_ok) ||
 				     (!estab && sysctl_tcp_timestamps))) {
 					opt_rx->saw_tstamp = 1;
-					opt_rx->rcv_tsval = get_unaligned_be32(ptr);
-					opt_rx->rcv_tsecr = get_unaligned_be32(ptr + 4);
+					opt_rx->rcv_tsval = get_unaligned_be32(ptr) + ts_adjust;
+					opt_rx->rcv_tsecr = get_unaligned_be32(ptr + 4) + ts_adjust;
 				}
 				break;
 			case TCPOPT_SACK_PERM:
@@ -3799,9 +3799,9 @@ static int tcp_parse_aligned_timestamp(struct tcp_sock *tp, struct tcphdr *th)
 			  | (TCPOPT_TIMESTAMP << 8) | TCPOLEN_TIMESTAMP)) {
 		tp->rx_opt.saw_tstamp = 1;
 		++ptr;
-		tp->rx_opt.rcv_tsval = ntohl(*ptr);
+		tp->rx_opt.rcv_tsval = ntohl(*ptr) + tp->ts_adjust;
 		++ptr;
-		tp->rx_opt.rcv_tsecr = ntohl(*ptr);
+		tp->rx_opt.rcv_tsecr = ntohl(*ptr) + tp->ts_adjust;
 		return 1;
 	}
 	return 0;
@@ -3821,7 +3821,7 @@ static int tcp_fast_parse_options(struct sk_buff *skb, struct tcphdr *th,
 		if (tcp_parse_aligned_timestamp(tp, th))
 			return 1;
 	}
-	tcp_parse_options(skb, &tp->rx_opt, 1);
+	tcp_parse_options(skb, &tp->rx_opt, 1, tp->ts_adjust);
 	return 1;
 }
 
@@ -5366,7 +5366,7 @@ static int tcp_rcv_synsent_state_process(struct sock *sk, struct sk_buff *skb,
 	struct inet_connection_sock *icsk = inet_csk(sk);
 	int saved_clamp = tp->rx_opt.mss_clamp;
 
-	tcp_parse_options(skb, &tp->rx_opt, 0);
+	tcp_parse_options(skb, &tp->rx_opt, 0, tp->ts_adjust);
 
 	if (th->ack) {
 		/* rfc793:
net/ipv4/tcp_ipv4.c +1 -1
index 6d88219..e8efe7f 100644
@@ -1222,7 +1222,7 @@ int tcp_v4_conn_request(struct sock *sk, struct sk_buff *skb)
 	tmp_opt.mss_clamp = 536;
 	tmp_opt.user_mss  = tcp_sk(sk)->rx_opt.user_mss;
 
-	tcp_parse_options(skb, &tmp_opt, 0);
+	tcp_parse_options(skb, &tmp_opt, 0, 0);
 
 	if (want_cookie && !tmp_opt.saw_tstamp)
 		tcp_clear_options(&tmp_opt);
net/ipv4/tcp_minisocks.c +6 -2
index f8d67cc..4c72954 100644
@@ -102,7 +102,7 @@ tcp_timewait_state_process(struct inet_timewait_sock *tw, struct sk_buff *skb,
 
 	tmp_opt.saw_tstamp = 0;
 	if (th->doff > (sizeof(*th) >> 2) && tcptw->tw_ts_recent_stamp) {
-		tcp_parse_options(skb, &tmp_opt, 0);
+		tcp_parse_options(skb, &tmp_opt, 0, tcptw->tw_ts_adjust);
 
 		if (tmp_opt.saw_tstamp) {
 			tmp_opt.ts_recent	= tcptw->tw_ts_recent;
@@ -292,6 +292,7 @@ void tcp_time_wait(struct sock *sk, int state, int timeo)
 		tcptw->tw_snd_nxt	= tp->snd_nxt;
 		tcptw->tw_rcv_wnd	= tcp_receive_window(tp);
 		tcptw->tw_ts_recent	= tp->rx_opt.ts_recent;
+		tcptw->tw_ts_adjust	= tp->ts_adjust;
 		tcptw->tw_ts_recent_stamp = tp->rx_opt.ts_recent_stamp;
 
 #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
@@ -503,7 +504,10 @@ struct sock *tcp_check_req(struct sock *sk, struct sk_buff *skb,
 
 	tmp_opt.saw_tstamp = 0;
 	if (th->doff > (sizeof(struct tcphdr)>>2)) {
-		tcp_parse_options(skb, &tmp_opt, 0);
+		/* C/R doesn't support request sockets yet, so we
+		 * don't need to worry about passing a ts_adjust here
+		 */
+		tcp_parse_options(skb, &tmp_opt, 0, 0);
 
 		if (tmp_opt.saw_tstamp) {
 			tmp_opt.ts_recent = req->ts_recent;
net/ipv4/tcp_output.c +10 -10
index bd62712..38c165e 100644
@@ -1487,7 +1487,7 @@ static int tcp_mtu_probe(struct sock *sk)
 
 	/* We're ready to send.  If this fails, the probe will
 	 * be resegmented into mss-sized pieces by tcp_write_xmit(). */
-	TCP_SKB_CB(nskb)->when = tcp_time_stamp;
+	TCP_SKB_CB(nskb)->when = tcp_time_stamp + tp->ts_adjust;
 	if (!tcp_transmit_skb(sk, nskb, 1, GFP_ATOMIC)) {
 		/* Decrement cwnd here because we are sending
 		 * effectively two packets. */
@@ -1568,7 +1568,7 @@ static int tcp_write_xmit(struct sock *sk, unsigned int mss_now, int nonagle,
 		    unlikely(tso_fragment(sk, skb, limit, mss_now)))
 			break;
 
-		TCP_SKB_CB(skb)->when = tcp_time_stamp;
+		TCP_SKB_CB(skb)->when = tcp_time_stamp + tp->ts_adjust;
 
 		if (unlikely(tcp_transmit_skb(sk, skb, 1, gfp)))
 			break;
@@ -1922,7 +1922,7 @@ int tcp_retransmit_skb(struct sock *sk, struct sk_buff *skb)
 	/* Make a copy, if the first transmission SKB clone we made
 	 * is still in somebody's hands, else make a clone.
 	 */
-	TCP_SKB_CB(skb)->when = tcp_time_stamp;
+	TCP_SKB_CB(skb)->when = tcp_time_stamp + tp->ts_adjust;
 
 	err = tcp_transmit_skb(sk, skb, 1, GFP_ATOMIC);
 
@@ -2138,7 +2138,7 @@ void tcp_send_active_reset(struct sock *sk, gfp_t priority)
 	tcp_init_nondata_skb(skb, tcp_acceptable_seq(sk),
 			     TCPCB_FLAG_ACK | TCPCB_FLAG_RST);
 	/* Send it off. */
-	TCP_SKB_CB(skb)->when = tcp_time_stamp;
+	TCP_SKB_CB(skb)->when = tcp_time_stamp + tcp_sk(sk)->ts_adjust;
 	if (tcp_transmit_skb(sk, skb, 0, priority))
 		NET_INC_STATS(sock_net(sk), LINUX_MIB_TCPABORTFAILED);
 
@@ -2176,7 +2176,7 @@ int tcp_send_synack(struct sock *sk)
 		TCP_SKB_CB(skb)->flags |= TCPCB_FLAG_ACK;
 		TCP_ECN_send_synack(tcp_sk(sk), skb);
 	}
-	TCP_SKB_CB(skb)->when = tcp_time_stamp;
+	TCP_SKB_CB(skb)->when = tcp_time_stamp + tcp_sk(sk)->ts_adjust;
 	return tcp_transmit_skb(sk, skb, 1, GFP_ATOMIC);
 }
 
@@ -2229,7 +2229,7 @@ struct sk_buff *tcp_make_synack(struct sock *sk, struct dst_entry *dst,
 		TCP_SKB_CB(skb)->when = cookie_init_timestamp(req);
 	else
 #endif
-	TCP_SKB_CB(skb)->when = tcp_time_stamp;
+	TCP_SKB_CB(skb)->when = tcp_time_stamp + tp->ts_adjust;
 	tcp_header_size = tcp_synack_options(sk, req, mss,
 					     skb, &opts, &md5) +
 			  sizeof(struct tcphdr);
@@ -2352,7 +2352,7 @@ int tcp_connect(struct sock *sk)
 	TCP_ECN_send_syn(sk, buff);
 
 	/* Send it off. */
-	TCP_SKB_CB(buff)->when = tcp_time_stamp;
+	TCP_SKB_CB(buff)->when = tcp_time_stamp + tp->ts_adjust;
 	tp->retrans_stamp = TCP_SKB_CB(buff)->when;
 	skb_header_release(buff);
 	__tcp_add_write_queue_tail(sk, buff);
@@ -2457,7 +2457,7 @@ void tcp_send_ack(struct sock *sk)
 	tcp_init_nondata_skb(buff, tcp_acceptable_seq(sk), TCPCB_FLAG_ACK);
 
 	/* Send it off, this clears delayed acks for us. */
-	TCP_SKB_CB(buff)->when = tcp_time_stamp;
+	TCP_SKB_CB(buff)->when = tcp_time_stamp + tcp_sk(sk)->ts_adjust;
 	tcp_transmit_skb(sk, buff, 0, GFP_ATOMIC);
 }
 
@@ -2489,7 +2489,7 @@ static int tcp_xmit_probe_skb(struct sock *sk, int urgent)
 	 * send it.
 	 */
 	tcp_init_nondata_skb(skb, tp->snd_una - !urgent, TCPCB_FLAG_ACK);
-	TCP_SKB_CB(skb)->when = tcp_time_stamp;
+	TCP_SKB_CB(skb)->when = tcp_time_stamp + tp->ts_adjust;
 	return tcp_transmit_skb(sk, skb, 0, GFP_ATOMIC);
 }
 
@@ -2524,7 +2524,7 @@ int tcp_write_wakeup(struct sock *sk)
 			tcp_set_skb_tso_segs(sk, skb, mss);
 
 		TCP_SKB_CB(skb)->flags |= TCPCB_FLAG_PSH;
-		TCP_SKB_CB(skb)->when = tcp_time_stamp;
+		TCP_SKB_CB(skb)->when = tcp_time_stamp + tp->ts_adjust;
 		err = tcp_transmit_skb(sk, skb, 1, GFP_ATOMIC);
 		if (!err)
 			tcp_event_new_data_sent(sk, skb);
net/ipv6/syncookies.c +1 -1
index 8c25139..9337ec6 100644
@@ -185,7 +185,7 @@ struct sock *cookie_v6_check(struct sock *sk, struct sk_buff *skb)
 
 	/* check for timestamp cookie support */
 	memset(&tcp_opt, 0, sizeof(tcp_opt));
-	tcp_parse_options(skb, &tcp_opt, 0);
+	tcp_parse_options(skb, &tcp_opt, 0, tp->ts_adjust);
 
 	if (tcp_opt.saw_tstamp)
 		cookie_check_timestamp(&tcp_opt);
net/ipv6/tcp_ipv6.c +1 -1
index d849dd5..3a83570 100644
@@ -1202,7 +1202,7 @@ static int tcp_v6_conn_request(struct sock *sk, struct sk_buff *skb)
 	tmp_opt.mss_clamp = IPV6_MIN_MTU - sizeof(struct tcphdr) - sizeof(struct ipv6hdr);
 	tmp_opt.user_mss = tp->rx_opt.user_mss;
 
-	tcp_parse_options(skb, &tmp_opt, 0);
+	tcp_parse_options(skb, &tmp_opt, 0, 0);
 
 	if (want_cookie && !tmp_opt.saw_tstamp)
 		tcp_clear_options(&tmp_opt);
Signature · 1 line
1.6.2.5

A message that is not in the archive (sent off-list or not yet received): 1256072803-3518-4-git-send-email-danms-r/[email protected]

#13 lore raw

Re: [PATCH 3/4] Adjust TCP timestamp values by a scalar value

Quoted 13 lines · Dan Smith

Adjust the sent and received TCP timestamp value by a scalar value in the tcp_sock structure. This will be zero most of the time, except when the socket has been migrated with c/r. If a socket is re-migrated, we take the new adjusted value as the saved value so that on restart it can be re-adjusted. Also, copy this into the timewait sock so that timestamps can continue to be adjusted in timewait state in the minisocks code.

Note that TCP timestamps are just a jiffies stamp, which means they have no relation to wall-clock time and thus a simple correction factor should be enough to ensure correctness.

...

Quoted 14 lines
include/linux/tcp.h +2 -0
index 8afac76..b845e21 100644
@@ -399,6 +399,8 @@ struct tcp_sock {
 		u32		  probe_seq_end;
 	} mtu_probe;
 
+	s32	ts_adjust;	/* tcp_time_stamp adjustment factor */
+
 #ifdef CONFIG_TCP_MD5SIG
 /* TCP AF-Specific parts; only used by MD5 Signature support so far */
 	struct tcp_sock_af_ops	*af_specific;

include/linux/tcp.h struct tcp_timewait_sock { · line 428

Quoted 7 lines
include/linux/tcp.h +1 -0
@@ -420,6 +422,7 @@ struct tcp_timewait_sock {
 	u32			  tw_rcv_wnd;
 	u32			  tw_ts_recent;
 	long			  tw_ts_recent_stamp;
+	s32			  tw_ts_adjust;
 #ifdef CONFIG_TCP_MD5SIG
 	u16			  tw_md5_keylen;
 	u8			  tw_md5_key[TCP_MD5SIG_MAXKEYLEN];

I think this definately needs to go by netdev to see if they object to the extra fields, and the (negligable?) extra processing in frequent paths like tcp_send_ack.

-serge

A message that is not in the archive (sent off-list or not yet received): 20091021180638.GA24465-r/[email protected]

author
#15 lore raw

Re: [PATCH 3/4] Adjust TCP timestamp values by a scalar value

SH> I think this definately needs to go by netdev to see if they SH> object to the extra fields, and the (negligable?) extra processing SH> in frequent paths like tcp_send_ack.

Indeed, I thought I had that Cc header in there to send it their way. Oops.

Signature · 3 lines
Dan Smith
IBM Linux Technology Center
email: danms-r/[email protected]
author
#16 lore raw

PATCH 4/4 Add some content to the readme.txt for socket c/r

In reply to a message not in the archive
---
 Documentation/checkpoint/readme.txt |   21 +++++++++++++++++++++
 1 files changed, 21 insertions(+), 0 deletions(-)
Documentation/checkpoint/readme.txt +21 -0
index 571c469..e6c173d 100644
@@ -334,6 +334,27 @@ we will be forced to more carefully review each of those features.
 However, this can be controlled with a sysctl-variable.
 
 
+Sockets
+=======
+
+For AF_UNIX sockets, both endpoints must be within the checkpointed
+task set to maintain a connected state after restart.  UNIX sockets
+that are in the process of passing a descriptor will cause the
+checkpoint to fail with -EBUSY indicating a transient state that
+cannot be checkpointed.  Listening sockets with an unaccepted peer
+will also cause an -EBUSY result.
+
+AF_INET sockets with endpoints outside the checkpointed task set may
+remain open if care is taken to avoid TCP timeouts and resets.
+Careful use of a virtual IP address can help avoid emission of an RST
+to the non-checkpointed endpoint.  If desired, the
+RESTART_SOCK_LISTENONLY flag may be passed to the restart syscall
+which will cause all connected AF_INET sockets to be closed during the
+restore process.  Listening sockets will still be restored to their
+original state, which makes this mode a candidate for something like
+an HTTP server.
+
+
 Kernel interfaces
 =================
 
Signature · 1 line
1.6.2.5

A message that is not in the archive (sent off-list or not yet received): 1256072803-3518-5-git-send-email-danms-r/[email protected]

#18 lore raw

Re: [PATCH 4/4] Add some content to the readme.txt for socket c/r

Quoted 1 line · Dan Smith

Nicely put !

Quoted 36 lines
---
 Documentation/checkpoint/readme.txt |   21 +++++++++++++++++++++
 1 files changed, 21 insertions(+), 0 deletions(-)
Documentation/checkpoint/readme.txt +21 -0
index 571c469..e6c173d 100644
@@ -334,6 +334,27 @@ we will be forced to more carefully review each of those features.
 However, this can be controlled with a sysctl-variable.
 
 
+Sockets
+=======
+
+For AF_UNIX sockets, both endpoints must be within the checkpointed
+task set to maintain a connected state after restart.  UNIX sockets
+that are in the process of passing a descriptor will cause the
+checkpoint to fail with -EBUSY indicating a transient state that
+cannot be checkpointed.  Listening sockets with an unaccepted peer
+will also cause an -EBUSY result.
+
+AF_INET sockets with endpoints outside the checkpointed task set may
+remain open if care is taken to avoid TCP timeouts and resets.
+Careful use of a virtual IP address can help avoid emission of an RST
+to the non-checkpointed endpoint.  If desired, the
+RESTART_SOCK_LISTENONLY flag may be passed to the restart syscall
+which will cause all connected AF_INET sockets to be closed during the
+restore process.  Listening sockets will still be restored to their
+original state, which makes this mode a candidate for something like
+an HTTP server.
+
+
 Kernel interfaces
 =================