[CRIU] [PATCH] tcp: bind tcp sockets after enabling the repair mode

Andrei Vagin avagin at openvz.org
Tue Dec 13 19:55:37 PST 2016


From: Andrei Vagin <avagin at virtuozzo.com>

Only sockets in the repair mode can be bound to the same
port a few time, what is required to restore tcp connects.

Signed-off-by: Andrei Vagin <avagin at virtuozzo.com>
---
 criu/sk-inet.c | 9 ++++-----
 criu/sk-tcp.c  | 7 +++++++
 2 files changed, 11 insertions(+), 5 deletions(-)

diff --git a/criu/sk-inet.c b/criu/sk-inet.c
index eb798ce..670d66d 100644
--- a/criu/sk-inet.c
+++ b/criu/sk-inet.c
@@ -628,11 +628,6 @@ static int open_inet_sk(struct file_desc *d)
 	if (restore_opt(sk, SOL_SOCKET, SO_REUSEADDR, &yes))
 		goto err;
 
-	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");
@@ -649,6 +644,10 @@ static int open_inet_sk(struct file_desc *d)
 		goto done;
 	}
 
+	if (ie->src_port && inet_bind(sk, ii))
+		goto err;
+
+
 	/*
 	 * Listen sockets are easiest ones -- simply
 	 * bind() and listen(), and that's all.
diff --git a/criu/sk-tcp.c b/criu/sk-tcp.c
index 8179a35..b5cab96 100644
--- a/criu/sk-tcp.c
+++ b/criu/sk-tcp.c
@@ -428,6 +428,13 @@ int restore_one_tcp(int fd, struct inet_sk_info *ii)
 	if (!sk)
 		return -1;
 
+	/*
+	 * The repair mode has to be enabled to be able
+	 * to connect to the same address twice.
+	 */
+	if (ii->ie->src_port && inet_bind(fd, ii))
+		return -1;
+
 	if (restore_tcp_conn_state(fd, sk, ii))
 		return -1;
 
-- 
2.7.4



More information about the CRIU mailing list