[CRIU] [PATCH 1/2] tcp: Move window checking code into cr-check.c

Pavel Emelyanov xemul at virtuozzo.com
Thu Dec 29 04:14:24 PST 2016


Signed-off-by: Pavel Emelyanov <xemul at virtuozzo.com>
---
 criu/cr-check.c        | 44 +++++++++++++++++++++++++++++++++++++++++++-
 criu/include/kerndat.h |  2 --
 criu/kerndat.c         |  4 ----
 criu/sk-tcp.c          | 38 --------------------------------------
 4 files changed, 43 insertions(+), 45 deletions(-)

diff --git a/criu/cr-check.c b/criu/cr-check.c
index 60279e1..ce75ac5 100644
--- a/criu/cr-check.c
+++ b/criu/cr-check.c
@@ -24,6 +24,8 @@
 #include <linux/aio_abi.h>
 #include <sys/mount.h>
 
+#include "../soccr/soccr.h"
+
 #include "types.h"
 #include "fdinfo.h"
 #include "sockets.h"
@@ -938,6 +940,46 @@ static int check_tcp_halt_closed(void)
 	return 0;
 }
 
+static int kerndat_tcp_repair_window(void)
+{
+	struct tcp_repair_window opt;
+	socklen_t optlen = sizeof(opt);
+	int sk, val = 1;
+
+	sk = socket(AF_INET, SOCK_STREAM, 0);
+	if (sk < 0) {
+		pr_perror("Unable to create inet socket");
+		goto errn;
+	}
+
+	if (setsockopt(sk, SOL_TCP, TCP_REPAIR, &val, sizeof(val))) {
+		if (errno == EPERM) {
+			pr_warn("TCP_REPAIR isn't available to unprivileged users\n");
+			goto now;
+		}
+		pr_perror("Unable to set TCP_REPAIR");
+		goto err;
+	}
+
+	if (getsockopt(sk, SOL_TCP, TCP_REPAIR_WINDOW, &opt, &optlen)) {
+		if (errno != ENOPROTOOPT) {
+			pr_perror("Unable to set TCP_REPAIR_WINDOW");
+			goto err;
+		}
+now:
+		val = 0;
+	} else
+		val = 1;
+
+	close(sk);
+	return val;
+
+err:
+	close(sk);
+errn:
+	return -1;
+}
+
 static int check_tcp_window(void)
 {
 	int ret;
@@ -946,7 +988,7 @@ static int check_tcp_window(void)
 	if (ret < 0)
 		return -1;
 
-	if (!kdat.has_tcp_window) {
+	if (ret == 0) {
 		pr_err("The TCP_REPAIR_WINDOW option isn't supported.\n");
 		return -1;
 	}
diff --git a/criu/include/kerndat.h b/criu/include/kerndat.h
index ab6ef3f..1d472bf 100644
--- a/criu/include/kerndat.h
+++ b/criu/include/kerndat.h
@@ -31,7 +31,6 @@ struct kerndat_s {
 	bool has_dirty_track;
 	bool has_memfd;
 	bool has_fdinfo_lock;
-	bool has_tcp_window;
 	unsigned long task_size;
 	bool ipv6;
 	bool has_loginuid;
@@ -60,7 +59,6 @@ enum {
  */
 extern int kerndat_fs_virtualized(unsigned int which, u32 kdev);
 
-extern int kerndat_tcp_repair_window();
 extern int kerndat_tcp_repair();
 extern int kerndat_uffd(bool need_uffd);
 
diff --git a/criu/kerndat.c b/criu/kerndat.c
index 1cc0a1d..349b85e 100644
--- a/criu/kerndat.c
+++ b/criu/kerndat.c
@@ -596,8 +596,6 @@ int kerndat_init(void)
 	if (!ret)
 		ret = kerndat_iptables_has_xtlocks();
 	if (!ret)
-		ret = kerndat_tcp_repair_window();
-	if (!ret)
 		ret = kerndat_compat_restore();
 	if (!ret)
 		ret = kerndat_tcp_repair();
@@ -631,8 +629,6 @@ int kerndat_init_rst(void)
 	if (!ret)
 		ret = kerndat_iptables_has_xtlocks();
 	if (!ret)
-		ret = kerndat_tcp_repair_window();
-	if (!ret)
 		ret = kerndat_compat_restore();
 	if (!ret)
 		ret = kerndat_tcp_repair();
diff --git a/criu/sk-tcp.c b/criu/sk-tcp.c
index 6f04bdb..057c035 100644
--- a/criu/sk-tcp.c
+++ b/criu/sk-tcp.c
@@ -474,41 +474,3 @@ out:
 	return ret;
 }
 
-int kerndat_tcp_repair_window()
-{
-	struct tcp_repair_window opt;
-	socklen_t optlen = sizeof(opt);
-	int sk, val = 1;
-
-	sk = socket(AF_INET, SOCK_STREAM, 0);
-	if (sk < 0) {
-		pr_perror("Unable to create inet socket");
-		return -1;
-	}
-
-	if (setsockopt(sk, SOL_TCP, TCP_REPAIR, &val, sizeof(val))) {
-		if (errno == EPERM) {
-			kdat.has_tcp_window = false;
-			pr_warn("TCP_REPAIR isn't available to unprivileged users\n");
-			close(sk);
-			return 0;
-		}
-		pr_perror("Unable to set TCP_REPAIR");
-		close(sk);
-		return -1;
-	}
-
-	if (getsockopt(sk, SOL_TCP, TCP_REPAIR_WINDOW, &opt, &optlen)) {
-		if (errno != ENOPROTOOPT) {
-			pr_perror("Unable to set TCP_REPAIR_WINDOW");
-			close(sk);
-			return -1;
-		}
-		kdat.has_tcp_window = false;
-	} else
-		kdat.has_tcp_window = true;
-	close(sk);
-
-	return 0;
-}
-
-- 
2.5.0


More information about the CRIU mailing list