[CRIU] [rfc 1/3] plugin: Add tcp close-wait helper

Cyrill Gorcunov gorcunov at openvz.org
Fri Mar 7 06:43:45 PST 2014


Build plugin with make -C plugins.
Then run criu with "-L plugins" option.

Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
---
 plugins/Makefile      |  5 +++++
 plugins/plugin-inet.c | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 62 insertions(+)
 create mode 100644 plugins/Makefile
 create mode 100644 plugins/plugin-inet.c

diff --git a/plugins/Makefile b/plugins/Makefile
new file mode 100644
index 000000000000..a1dd70e00d2f
--- /dev/null
+++ b/plugins/Makefile
@@ -0,0 +1,5 @@
+plugin-inet.so: plugin-inet.c
+	gcc -O2 -Werror -Wall -shared -nostartfiles $^ -o $@ -iquote ../include -fPIC
+
+all: plugin-inet.so
+	@true
diff --git a/plugins/plugin-inet.c b/plugins/plugin-inet.c
new file mode 100644
index 000000000000..33633713ef72
--- /dev/null
+++ b/plugins/plugin-inet.c
@@ -0,0 +1,57 @@
+#include <string.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <errno.h>
+
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <sys/mman.h>
+
+#include <linux/netlink.h>
+#include <linux/rtnetlink.h>
+
+#include <netinet/tcp.h>
+#include <arpa/inet.h>
+
+#include "criu-plugin.h"
+#include "criu-log.h"
+
+/*
+ * This is trivial plugin to simply zap tcp/ipv4 sockets which are
+ * in CLOSE_WAIT states.
+ */
+
+static int match_family_proto(int family, int type, int proto)
+{
+	return family == PF_INET && type == SOCK_STREAM && proto == IPPROTO_TCP;
+}
+
+int cr_plugin_dump_inet_sk(int fd, int id, int family, int type, int proto)
+{
+	struct tcp_info info;
+	socklen_t aux;
+	int ret = -1;
+
+	if (!match_family_proto(family, type, proto))
+		return -ENOTSUP;
+
+	aux = sizeof(info);
+	ret = getsockopt(fd, SOL_TCP, TCP_INFO, &info, &aux);
+	if (ret) {
+		pr_perror("Failed to obtain TCP_INFO");
+		return -1;
+	}
+
+	if (info.tcpi_state != TCP_CLOSE_WAIT)
+		return -ENOTSUP;
+
+	return 0;
+}
+
+int cr_plugin_restore_inet_sk(int id, int family, int type, int proto)
+{
+	if (!match_family_proto(family, type, proto))
+		return -ENOTSUP;
+
+	return socket(family, type, proto);
+}
-- 
1.8.3.1



More information about the CRIU mailing list