[CRIU] [PATCH 05/12] netns: create a netlink route socket out of dump_links()

Andrei Vagin avagin at openvz.org
Tue Mar 21 20:21:51 PDT 2017


From: Andrei Vagin <avagin at virtuozzo.com>

It will be used to dump netns id-s too.

Signed-off-by: Andrei Vagin <avagin at virtuozzo.com>
---
 criu/net.c | 31 ++++++++++++++++---------------
 1 file changed, 16 insertions(+), 15 deletions(-)

diff --git a/criu/net.c b/criu/net.c
index cdd1985..ad314aa 100644
--- a/criu/net.c
+++ b/criu/net.c
@@ -856,9 +856,8 @@ out:
 
 }
 
-static int dump_links(struct ns_id *ns, struct cr_imgset *fds)
+static int dump_links(int rtsk, struct ns_id *ns, struct cr_imgset *fds)
 {
-	int sk, ret;
 	struct {
 		struct nlmsghdr nlh;
 		struct rtgenmsg g;
@@ -866,12 +865,6 @@ static int dump_links(struct ns_id *ns, struct cr_imgset *fds)
 
 	pr_info("Dumping netns links\n");
 
-	ret = sk = socket(PF_NETLINK, SOCK_RAW, NETLINK_ROUTE);
-	if (sk < 0) {
-		pr_perror("Can't open rtnl sock for net dump");
-		goto out;
-	}
-
 	memset(&req, 0, sizeof(req));
 	req.nlh.nlmsg_len = sizeof(req);
 	req.nlh.nlmsg_type = RTM_GETLINK;
@@ -880,10 +873,7 @@ static int dump_links(struct ns_id *ns, struct cr_imgset *fds)
 	req.nlh.nlmsg_seq = CR_NLMSG_SEQ;
 	req.g.rtgen_family = AF_PACKET;
 
-	ret = do_rtnl_req(sk, &req, sizeof(req), dump_one_link, NULL, ns, fds);
-	close(sk);
-out:
-	return ret;
+	return do_rtnl_req(rtsk, &req, sizeof(req), dump_one_link, NULL, ns, fds);
 }
 
 static int restore_link_cb(struct nlmsghdr *hdr, struct ns_id *ns, void *arg)
@@ -1650,10 +1640,19 @@ int dump_net_ns(struct ns_id *ns)
 
 	ret = mount_ns_sysfs();
 	if (!(opts.empty_ns & CLONE_NEWNET)) {
+		int sk;
+
+		sk = socket(PF_NETLINK, SOCK_RAW, NETLINK_ROUTE);
+		if (sk < 0) {
+			pr_perror("Can't open rtnl sock for net dump");
+			ret = -1;
+		}
+
 		if (!ret)
-			ret = dump_netns_conf(ns, fds);
-		if (!ret)
-			ret = dump_links(ns, fds);
+			ret = dump_links(sk, ns, fds);
+
+		close(sk);
+
 		if (!ret)
 			ret = dump_ifaddr(fds);
 		if (!ret)
@@ -1662,6 +1661,8 @@ int dump_net_ns(struct ns_id *ns)
 			ret = dump_rule(fds);
 		if (!ret)
 			ret = dump_iptables(fds);
+		if (!ret)
+			ret = dump_netns_conf(ns, fds);
 	}
 	if (!ret)
 		ret = dump_nf_ct(fds, CR_FD_NETNF_CT);
-- 
2.7.4



More information about the CRIU mailing list