[Devel,criu-ovz] tcp: bind tcp sockets after enabling the repair mode

Submitted by Andrei Vagin on Dec. 15, 2016, 6:46 p.m.

Details

Message ID 1481827563-16832-1-git-send-email-avagin@openvz.org
State New
Series "tcp: bind tcp sockets after enabling the repair mode"
Headers show

Commit Message

Andrei Vagin Dec. 15, 2016, 6:46 p.m.
From: Andrei Vagin <avagin@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@virtuozzo.com>
---
 criu/sk-inet.c | 10 +++++-----
 soccr/soccr.c  | 10 ++++++++++
 2 files changed, 15 insertions(+), 5 deletions(-)

Patch hide | download patch | download mbox

diff --git a/criu/sk-inet.c b/criu/sk-inet.c
index b056e31..cc5a4d6 100644
--- a/criu/sk-inet.c
+++ b/criu/sk-inet.c
@@ -656,11 +656,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");
@@ -677,6 +672,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 6be8f7d..2c85ddc 100644
--- a/soccr/soccr.c
+++ b/soccr/soccr.c
@@ -412,6 +412,16 @@  int libsoccr_set_sk_data_noq(struct libsoccr_sk *sk,
 	if (data->state == TCP_LISTEN)
 		return -1;
 
+	if (data->src_addr.sa.sa_family == AF_INET)
+		addr_size = sizeof(data->src_addr.v4);
+	else
+		addr_size = sizeof(data->src_addr.v6);
+
+	if (bind(sk->fd, &data->src_addr.sa, addr_size) == -1) {
+		loge("Can't bind inet socket back\n");
+		return -1;
+	}
+
 	if (mstate & (RCVQ_FIRST_FIN | RCVQ_SECOND_FIN))
 		data->inq_seq--;