[2/2] net: handle a case when --empty net is set only for criu dump

Submitted by Andrei Vagin on Oct. 5, 2017, 5:58 p.m.

Details

Message ID 20171005175847.2432-2-avagin@openvz.org
State Accepted
Series "Series without cover letter"
Commit 1b4f35d4031807ae67bf166b039e42bac1df00f3
Headers show

Commit Message

Andrei Vagin Oct. 5, 2017, 5:58 p.m.
From: Andrei Vagin <avagin@virtuozzo.com>

The origin idea was to set --empty net for criu dump and criu restore,
but before cde33dcb0639 ("empty-ns: Don't C/R iptables too (v2)"),
criu restore worked without --empty net and we didn't notice that
docker doesn't set this option on restore.

After a small brainstorm, we decided that it is better to remove
this requirement. Docker has to set this option, but with this changes,
the docker issue will be less urgent.

https://github.com/checkpoint-restore/criu/issues/393
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
---
 criu/net.c | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

Patch hide | download patch | download mbox

diff --git a/criu/net.c b/criu/net.c
index 1e7c74e1e..8a2b60b67 100644
--- a/criu/net.c
+++ b/criu/net.c
@@ -1972,13 +1972,18 @@  static inline int restore_iptables(int pid)
 	struct cr_img *img;
 
 	img = open_image(CR_FD_IPTABLES, O_RSTR, pid);
-	if (img) {
-		ret = run_iptables_tool("iptables-restore -w", img_raw_fd(img), -1);
-		close_image(img);
+	if (img == NULL)
+		return -1;
+	if (empty_image(img)) {
+		ret = 0;
+		goto ipt6;
 	}
+
+	ret = run_iptables_tool("iptables-restore -w", img_raw_fd(img), -1);
+	close_image(img);
 	if (ret)
 		return ret;
-
+ipt6:
 	img = open_image(CR_FD_IP6TABLES, O_RSTR, pid);
 	if (img == NULL)
 		return -1;
@@ -2188,6 +2193,9 @@  static int restore_netns_ids(struct ns_id *ns)
 {
 	int i, sk, exit_code = -1;
 
+	if (!ns->net.netns)
+		return 0;
+
 	sk = socket(PF_NETLINK, SOCK_RAW, NETLINK_ROUTE);
 	if (sk < 0) {
 		pr_perror("Can't open rtnl sock for net dump");