[CRIU] [PATCH v1 06/12] gc: implement locked tcp connections show

Eugene Batalov eabatalov89 at gmail.com
Wed Jul 27 22:14:42 PDT 2016


Signed-off-by: Eugene Batalov <eabatalov89 at gmail.com>
---
 criu/cr-gc.c           |  4 ++++
 criu/include/sk-inet.h |  1 +
 criu/sk-tcp.c          | 38 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 43 insertions(+)

diff --git a/criu/cr-gc.c b/criu/cr-gc.c
index 4c8bea9..b43b066 100644
--- a/criu/cr-gc.c
+++ b/criu/cr-gc.c
@@ -12,6 +12,7 @@
 #include "util.h"
 #include "sockets.h"
 #include "net.h"
+#include "sk-inet.h"
 
 static int gc_validate_opts(void)
 {
@@ -74,6 +75,9 @@ static int gc_show(void)
 {
 	show_link_remaps();
 
+	if (gc_show_locked_tcp_conns() < 0)
+		return -1;
+
 	return 0;
 }
 
diff --git a/criu/include/sk-inet.h b/criu/include/sk-inet.h
index c82ffd4..a6f54dd 100644
--- a/criu/include/sk-inet.h
+++ b/criu/include/sk-inet.h
@@ -67,6 +67,7 @@ static inline void tcp_repair_off(int fd)
 extern void tcp_locked_conn_add(struct inet_sk_info *);
 extern int rst_unlock_tcp_connections(void);
 extern void cpt_unlock_tcp_connections(void);
+extern int gc_show_locked_tcp_conns(void);
 
 extern int dump_one_tcp(int sk, struct inet_sk_desc *sd);
 extern int restore_one_tcp(int sk, struct inet_sk_info *si);
diff --git a/criu/sk-tcp.c b/criu/sk-tcp.c
index c4aa58f..97f2c31 100644
--- a/criu/sk-tcp.c
+++ b/criu/sk-tcp.c
@@ -7,6 +7,7 @@
 #include <string.h>
 #include <sched.h>
 #include <netinet/in.h>
+#include <arpa/inet.h>
 
 #include "cr_options.h"
 #include "util.h"
@@ -728,6 +729,43 @@ int rst_unlock_tcp_connections(void)
 	return 0;
 }
 
+static int show_tcp_conn(struct inet_sk_info *si)
+{
+	char sip[INET_ADDR_LEN], dip[INET_ADDR_LEN];
+	int family = si->ie->family;
+
+	if (!inet_ntop(family, (void *)si->ie->src_addr, sip, INET_ADDR_LEN) ||
+			!inet_ntop(family, (void *)si->ie->dst_addr, dip, INET_ADDR_LEN)) {
+		pr_perror("nf: Can't translate ip addr");
+		return -1;
+	}
+
+	pr_msg("Locked tcp connection: %s:%d -> %s:%d\n",
+			sip, (int)si->ie->src_port, dip, (int)si->ie->dst_port);
+
+	return 0;
+}
+
+int gc_show_locked_tcp_conns(void)
+{
+	struct inet_sk_info *ii;
+
+	/*
+	 * Unshared ps tree net ns is destroyed after successful
+	 * dump. No host net ns netfilter rules are locking
+	 * TCP connections in this case.
+	 */
+	if (root_ns_mask & CLONE_NEWNET)
+		return 0;
+
+	list_for_each_entry(ii, &rst_tcp_repair_sockets, rlist) {
+		if (show_tcp_conn(ii))
+			return -1;
+	}
+
+	return 0;
+}
+
 int check_tcp(void)
 {
 	socklen_t optlen;
-- 
1.9.1



More information about the CRIU mailing list