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

Andrei Vagin avagin at openvz.org
Wed Dec 14 16:34:49 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.

v2: move bind() into libsoccr
v3: fix an error message
Signed-off-by: Andrei Vagin <avagin at virtuozzo.com>
---
 criu/sk-inet.c | 10 +++++-----
 soccr/soccr.c  | 10 ++++++++++
 soccr/soccr.h  |  2 +-
 3 files changed, 16 insertions(+), 6 deletions(-)

diff --git a/criu/sk-inet.c b/criu/sk-inet.c
index eb798ce..0a6487a 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,11 @@ static int open_inet_sk(struct file_desc *d)
 		goto done;
 	}
 
+	if (ie->src_port) {
+		if (inet_bind(sk, ii))
+			goto err;
+	}
+
 	/*
 	 * Listen sockets are easiest ones -- simply
 	 * bind() and listen(), and that's all.
diff --git a/soccr/soccr.c b/soccr/soccr.c
index 381cc74..afa92dc 100644
--- a/soccr/soccr.c
+++ b/soccr/soccr.c
@@ -449,6 +449,16 @@ static int libsoccr_set_sk_data_noq(struct libsoccr_sk *sk,
 	if (data->state == TCP_LISTEN)
 		return -1;
 
+	if (sk->src_addr->sa.sa_family == AF_INET)
+		addr_size = sizeof(sk->src_addr->v4);
+	else
+		addr_size = sizeof(sk->src_addr->v6);
+
+	if (bind(sk->fd, &sk->src_addr->sa, addr_size)) {
+		loge("Can't bind inet socket back\n");
+		return -1;
+	}
+
 	if (mstate & (RCVQ_FIRST_FIN | RCVQ_SECOND_FIN))
 		data->inq_seq--;
 
diff --git a/soccr/soccr.h b/soccr/soccr.h
index f46116a..a30129d 100644
--- a/soccr/soccr.h
+++ b/soccr/soccr.h
@@ -224,7 +224,7 @@ int libsoccr_set_queue_bytes(struct libsoccr_sk *sk, int queue_id, char *bytes,
 int libsoccr_set_addr(struct libsoccr_sk *sk, int self, union libsoccr_addr *, unsigned flags);
 
 /*
- * Performs restore actions on bind()-ed socket
+ * Performs restore actions on a socket
  */
 int libsoccr_restore(struct libsoccr_sk *sk, struct libsoccr_sk_data *data, unsigned data_size);
 
-- 
2.7.4



More information about the CRIU mailing list