Skip to contentSkip to conversation

Checkpoint and Restart of INET routing information

PATCH In review Dan Smith 6 participants 12 messages Apr 23, 2010 – Apr 28, 2010 2 messages not in the archive

Subsystems (3)
lore
Share & tools
lore

Dan Smith

author
#0 lore raw

This set extends the existing network socket, device, and namespace support in the checkpoint tree to cover routing information. It does so by making heavy use of RTNETLINK to dump and insert routes much like userspace would. Because the task doing the checkpointing or restarting needs to examine or setup resources for tasks in network namespaces other than its own, an additional kernel socket setup call is added. It provides us the ability to talk to RTNETLINK in a foreign netns.

The support added in this set allows me to configure various inet4 and inet6 routes in a container and have them saved and restored successfully during a checkpoint/restart process.

A message that is not in the archive (sent off-list or not yet received): 1272034539-19899-1-git-send-email-danms-r/[email protected]

author
#2 lore raw

PATCH 1/4 Fix acquiring socket lock before reading RTNETLINK response

---
 net/checkpoint_dev.c |    7 ++++---
 1 files changed, 4 insertions(+), 3 deletions(-)
net/checkpoint_dev.c +4 -3
index 7ccb899..2787892 100644
@@ -136,11 +136,12 @@ static struct nlmsghdr *rtnl_get_response(struct socket *rtnl,
 
 	*skb = NULL;
 
+	lock_sock(rtnl->sk);
 	ret = sk_wait_data(rtnl->sk, &timeo);
-	if (!ret)
-		return ERR_PTR(-EPIPE);
+	if (ret)
+		*skb = skb_dequeue(&rtnl->sk->sk_receive_queue);
+	release_sock(rtnl->sk);
 
-	*skb = skb_dequeue(&rtnl->sk->sk_receive_queue);
 	if (!*skb)
 		return ERR_PTR(-EPIPE);
 
Signature · 1 line
1.6.2.5

A message that is not in the archive (sent off-list or not yet received): 1272034539-19899-2-git-send-email-danms-r/[email protected]

author
#4 lore raw

Re: [PATCH 1/4] Fix acquiring socket lock before reading RTNETLINK response

DS> Signed-off-by: Dan Smith <danms-r/[email protected]>

I went too deep with my send-email command line. This patch isn't related to the others, so please disregard.

Signature · 3 lines
Dan Smith
IBM Linux Technology Center
email: danms-r/[email protected]
author
#5 lore raw

RFC PATCH 2/4 Add sock_create_kern_net()

In reply to a message not in the archive

This helper allows kernel routines to create a socket in a given netns, instead of forcing it to the initial or current one.

I know this seems like it's violating the netns boundary. The intended use (as in the following patches) is specifically when talking to RTNETLINK in another netns for the purposes of creating or examining resources there. It is expected that this will be used for that sort of transient socket creation only. In other words:

  s = sock_create_kern_net(AF_NETLINK, ..., other_netns, ...);
  rtnl_talk(s);
  close(s);

If this is acceptable, I will actually be able to clean up and simplify other bits of the net checkpoint code to make better use of RTNL for examining and restoring resources.

Perhaps we should assert that family == AF_NETLINK (or maybe just printk(KERN_WARN) if it is not) to prevent abuse of this call?

---
 include/linux/net.h |    2 ++
 net/socket.c        |    6 ++++++
 2 files changed, 8 insertions(+), 0 deletions(-)
include/linux/net.h +2 -0
index 9548e45..9cfc899 100644
@@ -235,6 +235,8 @@ extern int	     sock_create(int family, int type, int proto,
 				 struct socket **res);
 extern int	     sock_create_kern(int family, int type, int proto,
 				      struct socket **res);
+extern int	     sock_create_kern_net(int family, int type, int protocol,
+				      struct net *net, struct socket **res);
 extern int	     sock_create_lite(int family, int type, int proto,
 				      struct socket **res); 
 extern void	     sock_release(struct socket *sock);
net/socket.c +6 -0
index 3253c04..95c94a7 100644
@@ -1294,6 +1294,12 @@ int sock_create_kern(int family, int type, int protocol, struct socket **res)
 	return __sock_create(&init_net, family, type, protocol, res, 1);
 }
 
+int sock_create_kern_net(int family, int type, int protocol,
+			 struct net *net, struct socket **res)
+{
+	return __sock_create(net, family, type, protocol, res, 1);
+}
+
 SYSCALL_DEFINE3(socket, int, family, int, type, int, protocol)
 {
 	int retval;
Signature · 1 line
1.6.2.5
maintainer
#6 lore raw

Re: [PATCH 2/4] [RFC] Add sock_create_kern_net()

From: Dan Smith <[email protected]>
Date: Fri, 23 Apr 2010 07:55:37 -0700

Quoted 8 lines

This helper allows kernel routines to create a socket in a given netns, instead of forcing it to the initial or current one.

I know this seems like it's violating the netns boundary. The intended use (as in the following patches) is specifically when talking to RTNETLINK in another netns for the purposes of creating or examining resources there. It is expected that this will be used for that sort of transient socket creation only. In other words:

If you can create netlink sockets in a remote NS you can also make changes there, and the whole point is to disallow changes.

So maybe you won't be making changes, but others will think about using this and doing so.

At a high level, I think this is a really bad idea, so I won't be applying this, sorry.

#7 lore raw

Re: [PATCH 2/4] [RFC] Add sock_create_kern_net()

Quoted 12 lines · David Miller

From: Dan Smith <[email protected]>
Date: Fri, 23 Apr 2010 07:55:37 -0700

Quoted 8 lines

This helper allows kernel routines to create a socket in a given netns, instead of forcing it to the initial or current one.

I know this seems like it's violating the netns boundary. The intended use (as in the following patches) is specifically when talking to RTNETLINK in another netns for the purposes of creating or examining resources there. It is expected that this will be used for that sort of transient socket creation only. In other words:

Quoted 8 lines

If you can create netlink sockets in a remote NS you can also make changes there, and the whole point is to disallow changes.

So maybe you won't be making changes, but others will think about using this and doing so.

At a high level, I think this is a really bad idea, so I won't be applying this, sorry.

What this is changed to be a socket option or ioctl or some other mechanism that allows one to move an existing unbound, unconnected socket to another namespace?

This way, we do not modify the namespace directly, but still have ability to move sockets into it for required communication.

In my mind moving a socket is someone similar to moving an interface to a namespace. You just moving a required resource.

Thanks
-vlad

Quoted 5 lines

--
To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#8 lore raw

Re: [PATCH 2/4] [RFC] Add sock_create_kern_net()

In reply to David Miller

Hi,

DM> If you can create netlink sockets in a remote NS you can also make DM> changes there, and the whole point is to disallow changes.

DM> So maybe you won't be making changes, but others will think about DM> using this and doing so.

I would be making changes on restart, because I insert routes. As has been pointed out, Eric's setns() patches allow this sort of violation from userspace even :)

Following that example, I could have the checkpointing task stash the current nsproxy and temporarily jump to the destination netns to do the checkpoint. I'll cook up something to look at...

Thanks Dave!

Signature · 3 lines
Dan Smith
IBM Linux Technology Center
email: [email protected]
#9 lore raw

Re: [PATCH 2/4] [RFC] Add sock_create_kern_net()

In reply to Dan Smith
Quoted 9 lines · Dan Smith

This helper allows kernel routines to create a socket in a given netns, instead of forcing it to the initial or current one.

I know this seems like it's violating the netns boundary. The intended use (as in the following patches) is specifically when talking to RTNETLINK in another netns for the purposes of creating or examining resources there. It is expected that this will be used for that sort of transient socket creation only. In other words:

Quoted 4 lines
  s = sock_create_kern_net(AF_NETLINK, ..., other_netns, ...);
  rtnl_talk(s);
  close(s);

CCing Eric B. and Daniel with whom i have had this discussion before.

So ... how does user space know what "other_netns" is?

Also note Eric's recent patches introduced another way of opening a socket in a different namespace - are you using those in the abstraction to find what netns is?

cheers,
jamal

#10 lore raw

Re: [PATCH 2/4] [RFC] Add sock_create_kern_net()

j> So ... how does user space know what "other_netns" is?

That's the point, userspace doesn't know about and can't use this interface. This is a way for the kernel to open a socket in another netns to talk to that netns' RTNETLINK. I realize in its current form it could be used for something more nefarious, but it would be kernel code doing it.

j> Also note Eric's recent patches introduced another way of opening a j> socket in a different namespace - are you using those in the j> abstraction to find what netns is?

No. The process doing the checkpoint already has pointers to the tasks and thus their netns pointers. Eric's interface is an abstraction to allow userspace to do something similar, I think that using it from the kernel would be rather messy.

Signature · 3 lines
Dan Smith
IBM Linux Technology Center
email: [email protected]
author
#11 lore raw

PATCH 3/4 C/R: Make rtnl_open() and rtnl_do() take and pass a netns pointer

In reply to a message not in the archive

(also make rtnl_do() return negative or 0, not the message length)

---
 net/checkpoint_dev.c |   16 +++++++++-------
 1 files changed, 9 insertions(+), 7 deletions(-)
net/checkpoint_dev.c +9 -7
index 2787892..df8b16a 100644
@@ -107,12 +107,13 @@ static int __kern_dev_ioctl(struct net *net, unsigned int cmd, void *arg)
 	return ret;
 }
 
-static struct socket *rtnl_open(void)
+static struct socket *rtnl_open(struct net *net)
 {
 	struct socket *sock;
 	int ret;
 
-	ret = sock_create(AF_NETLINK, SOCK_DGRAM, NETLINK_ROUTE, &sock);
+	ret = sock_create_kern_net(AF_NETLINK, SOCK_DGRAM, NETLINK_ROUTE,
+				   net, &sock);
 	if (ret < 0)
 		return ERR_PTR(ret);
 
@@ -538,7 +539,7 @@ static struct sk_buff *del_link_msg(char *name)
 	return skb;
 }
 
-static int rtnl_do(struct sk_buff *skb)
+static int rtnl_do(struct net *net, struct sk_buff *skb)
 {
 	int ret = -ENOMEM;
 	struct socket *rtnl = NULL;
@@ -551,7 +552,7 @@ static int rtnl_do(struct sk_buff *skb)
 	kvec.iov_len = skb->len;
 	kvec.iov_base = skb->head;
 
-	rtnl = rtnl_open();
+	rtnl = rtnl_open(net);
 	if (IS_ERR(rtnl)) {
 		ret = PTR_ERR(rtnl);
 		ckpt_debug("Unable to open rtnetlink socket: %i\n", ret);
@@ -570,7 +571,8 @@ static int rtnl_do(struct sk_buff *skb)
 	if (IS_ERR(nlh)) {
 		ret = PTR_ERR(nlh);
 		ckpt_debug("RTNETLINK said: %i\n", ret);
-	}
+	} else
+		ret = 0;
  out:
 	rtnl_close(rtnl);
 	kfree_skb(rskb);
@@ -590,7 +592,7 @@ static struct net_device *rtnl_newlink(new_link_fn fn, void *data, char *name)
 		return ERR_PTR(PTR_ERR(skb));
 	}
 
-	ret = rtnl_do(skb);
+	ret = rtnl_do(current->nsproxy->net_ns, skb);
 	kfree_skb(skb);
 	if (ret < 0)
 		return ERR_PTR(ret);
@@ -610,7 +612,7 @@ static int rtnl_dellink(char *name)
 		return PTR_ERR(skb);
 	}
 
-	ret = rtnl_do(skb);
+	ret = rtnl_do(current->nsproxy->net_ns, skb);
 	kfree_skb(skb);
 
 	return ret;
Signature · 1 line
1.6.2.5
author
#12 lore raw

PATCH 4/4 C/R: inet4 and inet6 unicast routes

In reply to a message not in the archive

This patch adds support for checkpointing and restoring route information. It keeps enough information to restore basic routes at the level of detail of /proc/net/route. It uses RTNETLINK to extract the information during checkpoint and also to insert it back during restore. This gives us a nice layer of isolation between us and the various "fib" implementations.

---
 include/linux/checkpoint_hdr.h |   31 +++
 net/checkpoint_dev.c           |  412 +++++++++++++++++++++++++++++++++++++++-
 2 files changed, 442 insertions(+), 1 deletions(-)
include/linux/checkpoint_hdr.h +31 -0
index 633c9b0..187d706 100644
@@ -23,6 +23,7 @@
 #include <sys/un.h>
 #include <netinet/in.h>
 #endif
+#include <linux/if.h>
 
 /*
  * /usr/include/linux/security.h is not exported to userspace, so
@@ -783,6 +784,7 @@ struct ckpt_hdr_file_socket {
 struct ckpt_hdr_netns {
 	struct ckpt_hdr h;
 	__s32 this_ref;
+	__u32 routes;
 } __attribute__((aligned(8)));
 
 enum ckpt_netdev_types {
@@ -837,6 +839,35 @@ struct ckpt_netdev_addr {
 	} __attribute__((aligned(8)));
 } __attribute__((aligned(8)));
 
+enum ckpt_route_types {
+	CKPT_ROUTE_IPV4,
+	CKPT_ROUTE_IPV6,
+	CKPT_ROUTE_MAX
+};
+
+#define CKPT_ROUTE_FLAG_GW 1
+
+struct ckpt_route {
+	__u16 type;
+	__u16 flags;
+
+	union {
+		struct {
+			__be32 inet4_len;          /* mask length (bits) */
+			__u32  inet4_met;          /* metric             */
+			__be32 inet4_dst;          /* route address      */
+			__be32 inet4_gwy;          /* gateway address    */
+		};
+		struct {
+			__u32 inet6_len;           /* mask length (bits) */
+			__u32 inet6_met;           /* metric             */
+			struct in6_addr inet6_dst; /* route address      */
+			struct in6_addr inet6_gwy; /* gateway address    */
+		};
+	} __attribute__((aligned(8)));
+	char dev[IFNAMSIZ+1];
+} __attribute__((aligned(8)));
+
 struct ckpt_hdr_eventpoll_items {
 	struct ckpt_hdr h;
 	__s32  epfile_objref;
net/checkpoint_dev.c +411 -1

475 lines not on this page · raw message

Signature · 1 line
1.6.2.5
#13 lore raw
In reply to Dan Smith
Quoted 8 lines · Dan Smith

This set extends the existing network socket, device, and namespace support in the checkpoint tree to cover routing information. It does so by making heavy use of RTNETLINK to dump and insert routes much like userspace would. Because the task doing the checkpointing or restarting needs to examine or setup resources for tasks in network namespaces other than its own, an additional kernel socket setup call is added. It provides us the ability to talk to RTNETLINK in a foreign netns.

Quoted 4 lines

The support added in this set allows me to configure various inet4 and inet6 routes in a container and have them saved and restored successfully during a checkpoint/restart process.

Why do you need to do that from the kernel ? Same remark for ipv4/6 addresses. What prevents you to do 'ip route show' and use these informations to restore the routes later ? Will we end up by moving all the network userspace tools in the kernel ? :)

If you use the Eric's setns patchset, you will be able to do that easily from userspace, no ?