[CRIU] [PATCH 08/21] soccr: move connect from criu to soccr

Andrei Vagin avagin at openvz.org
Mon Nov 28 11:27:43 PST 2016


From: Andrei Vagin <avagin at virtuozzo.com>

We will need to disable the repair mode before connect()
to restore syn-sent sockets. And even now connect() looks
like a part of internal logic of libsoccr.

Signed-off-by: Andrei Vagin <avagin at virtuozzo.com>
---
 criu/sk-inet.c | 20 ++++++++++----------
 criu/sk-tcp.c  |  9 ---------
 soccr/soccr.c  | 30 ++++++++++++++++--------------
 3 files changed, 26 insertions(+), 33 deletions(-)

diff --git a/criu/sk-inet.c b/criu/sk-inet.c
index 30e7fa6..987217d 100644
--- a/criu/sk-inet.c
+++ b/criu/sk-inet.c
@@ -592,6 +592,16 @@ static int open_inet_sk(struct file_desc *d)
 	if (restore_opt(sk, SOL_SOCKET, SO_REUSEADDR, &yes))
 		goto err;
 
+	/*
+	 * Listen sockets are easiest ones -- simply
+	 * bind() and listen(), and that's all.
+	 */
+
+	if (ie->src_port) {
+		if (inet_bind(sk, ii))
+			goto err;
+	}
+
 	if (tcp_connection(ie)) {
 		if (!opts.tcp_established_ok) {
 			pr_err("Connected TCP socket in image\n");
@@ -608,16 +618,6 @@ static int open_inet_sk(struct file_desc *d)
 		goto done;
 	}
 
-	/*
-	 * Listen sockets are easiest ones -- simply
-	 * bind() and listen(), and that's all.
-	 */
-
-	if (ie->src_port) {
-		if (inet_bind(sk, ii))
-			goto err;
-	}
-
 	if (ie->state == TCP_LISTEN) {
 		if (ie->proto != IPPROTO_TCP) {
 			pr_err("Wrong socket in listen state %d\n", ie->proto);
diff --git a/criu/sk-tcp.c b/criu/sk-tcp.c
index d08a4c0..bfe26c1 100644
--- a/criu/sk-tcp.c
+++ b/criu/sk-tcp.c
@@ -349,15 +349,6 @@ static int restore_tcp_conn_state(int sk, struct libsoccr_sk *socr, struct inet_
 
 	(void)data;
 
-	if (libsoccr_set_sk_data_unbound(socr, &data, sizeof(data)))
-		goto err_c;
-
-	if (inet_bind(sk, ii))
-		goto err_c;
-
-	if (inet_connect(sk, ii))
-		goto err_c;
-
 	if (libsoccr_set_sk_data_noq(socr, &data, sizeof(data)))
 		goto err_c;
 
diff --git a/soccr/soccr.c b/soccr/soccr.c
index 019eeea..31cb870 100644
--- a/soccr/soccr.c
+++ b/soccr/soccr.c
@@ -323,9 +323,17 @@ static int set_queue_seq(struct libsoccr_sk *sk, int queue, __u32 seq)
 	return 0;
 }
 
-int libsoccr_set_sk_data_unbound(struct libsoccr_sk *sk,
+#ifndef TCPOPT_SACK_PERM
+#define TCPOPT_SACK_PERM TCPOPT_SACK_PERMITTED
+#endif
+
+int libsoccr_set_sk_data_noq(struct libsoccr_sk *sk,
 		struct libsoccr_sk_data *data, unsigned data_size)
 {
+	struct tcp_repair_opt opts[4];
+	int addr_size;
+	int onr = 0;
+
 	if (!data || data_size < SOCR_DATA_MIN_SIZE)
 		return -1;
 
@@ -339,21 +347,15 @@ int libsoccr_set_sk_data_unbound(struct libsoccr_sk *sk,
 				data->outq_seq - data->outq_len))
 		return -3;
 
-	return 0;
-}
-
-#ifndef TCPOPT_SACK_PERM
-#define TCPOPT_SACK_PERM TCPOPT_SACK_PERMITTED
-#endif
+	if (data->dst_addr.sa.sa_family == AF_INET)
+		addr_size = sizeof(data->dst_addr.sin);
+	else
+		addr_size = sizeof(data->dst_addr.sin6);
 
-int libsoccr_set_sk_data_noq(struct libsoccr_sk *sk,
-		struct libsoccr_sk_data *data, unsigned data_size)
-{
-	struct tcp_repair_opt opts[4];
-	int onr = 0;
-
-	if (!data || data_size < SOCR_DATA_MIN_SIZE)
+	if (connect(sk->fd, &data->dst_addr.sa, addr_size) == -1) {
+		loge("Can't connect inet socket back\n");
 		return -1;
+	}
 
 	logd("\tRestoring TCP options\n");
 
-- 
2.7.4



More information about the CRIU mailing list