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

Submitted by Andrei Vagin on March 22, 2017, 12:28 a.m.

Details

Message ID 1490142533-20654-6-git-send-email-avagin@openvz.org
State New
Series "Dump and restore internal veth devices"
Headers show

Commit Message

Andrei Vagin March 22, 2017, 12:28 a.m.
From: Andrei Vagin <avagin@virtuozzo.com>

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

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

Patch hide | download patch | download mbox

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);