C/R: inet4 and inet6 unicast routes (v2)
Subsystems (2)
RFC PATCH 1/1 C/R: inet4 and inet6 unicast routes (v2)
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.
Changes in v2:
This version of the patch actually moves the current task into the desired network namespace temporarily, for the purposes of examining and restoring the route information. This is a instead of creating a cross- namespace socket to do the job, as was done in v1.
This is just an RFC to see if this is an acceptable method. For a final version, adding a helper to nsproxy.c would allow us to create a new nsproxy with the desired netns instead of creating one with copy_namespaces() just to kill it off and use the target one.
I still think the previous method is cleaner, but this way may violate fewer namespace boundaries (I'm still undecided :)
--- include/linux/checkpoint_hdr.h | 31 +++ net/checkpoint_dev.c | 463 +++++++++++++++++++++++++++++++++++++++- 2 files changed, 493 insertions(+), 1 deletions(-)
include/linux/checkpoint_hdr.h +31 -0
@@ -20,6 +20,7 @@#ifndef CONFIG_CHECKPOINT #warn linux/checkpoint_hdr.h included directly (without CONFIG_CHECKPOINT)#endif +#include <linux/if.h> #else /* __KERNEL__ */
@@ -782,6 +783,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 {
@@ -826,6 +828,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 +462 -1
526 lines not on this page · raw message
Signature · 1 line
1.6.2.5
net/checkpoint_dev.c int checkpoint_netdev(struct ckpt_ctx *ctx, void *ptr) · line 452
Quoted 8 lines · Dan Smith
net/checkpoint_dev.c +8
-0+static int temp_netns_enter (struct net *net) +{ +int ret; +struct net *tmp_netns; + + ret =copy_namespaces (CLONE_NEWNET , current); +if (ret) +return ret;
Actually there is one problem here - copy_namespaces() is specifically used only by clone() and it expects tsk to not yet be live. So it just does
tsk->nsproxy = new_ns
Since you're doing this on current which is live, it would have to use rcu_assign_pointer() to be safe.
So I'm afraid you're going to have to do a slightly uglier thing where you unshare_nsproxy_namespaces() and then switch_task_namespaces() to the new nsproxy.
net/checkpoint_dev.c int checkpoint_netdev(struct ckpt_ctx *ctx, void *ptr) · line 460
Quoted 8 lines
net/checkpoint_dev.c +8
-0+ + tmp_netns = current->nsproxy->net_ns; +get_net (net); + current->nsproxy->net_ns = net; +put_net (tmp_netns); + +return 0 ; +}
Otherwise it looks good to me. My only other comment would be to soothe readers' anxieties by putting a comment right here explaining that switch_task_namespaces() will drop your ref to current->nsproxy->net_ns, and that you had never dropped the ref to prev so it will be safe.
net/checkpoint_dev.c int checkpoint_netdev(struct ckpt_ctx *ctx, void *ptr) · line 465
Quoted 4 lines
net/checkpoint_dev.c +4
-0+static void temp_netns_exit (struct nsproxy *prev) +{ +switch_task_namespaces (current, prev); +}
thanks,
-serge
SH> So I'm afraid you're going to have to do a slightly uglier thing SH> where you unshare_nsproxy_namespaces() and then
SH> switch_task_namespaces() to the new nsproxy.
Well, I think that would be hidden in the nicer helper function I think I'll need, which I eluded to in the patch header. This is just an RFC proof that it can be done in this manner, but I think a separate helper in nsproxy.c is in order to make it nice (and avoid the extra alloc/free of the netns that copy_namespaces() will create). Agreed?
Thanks!
Signature · 3 lines
Dan Smith IBM Linux Technology Center email: [email protected]
Quoted 10 lines · Dan Smith
SH> So I'm afraid you're going to have to do a slightly uglier thing SH> where you
unshare_nsproxy_namespaces()and then
SH>switch_task_namespaces()to the new nsproxy.Well, I think that would be hidden in the nicer helper function I think I'll need, which I eluded to in the patch header. This is just an RFC proof that it can be done in this manner, but I think a separate helper in
nsproxy.cis in order to make it nice (and avoid the extra alloc/free of the netns thatcopy_namespaces()will create). Agreed?
Yup - thanks!
-serge
Quoted 18 lines · Dan Smith
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.Changes in v2:
This version of the patch actually moves the current task into the desired network namespace temporarily, for the purposes of examining and restoring the route information. This is a instead of creating a cross- namespace socket to do the job, as was done in v1.
This is just an RFC to see if this is an acceptable method. For a final version, adding a helper to
nsproxy.cwould allow us to create a new nsproxy with the desired netns instead of creating one withcopy_namespaces()just to kill it off and use the target one.
Quoted 8 lines
I still think the previous method is cleaner, but this way may violate fewer namespace boundaries (I'm still undecided :)
Signed-off-by Dan Smith <[email protected]>Cc David Miller <[email protected]>Cc Vlad Yasevich <[email protected]>Cc jamal <[email protected]>---
Hi Dan,
Eric did a patchset (as Jamal mentioned it) where you can have a process to enter a specific namespace from userspace.
Is it possible to enter the namespace and dump / restore the routes with NETLINK_ROUTE from userspace ? Or is it something not possible ?
Thanks
-- Daniel
DL> Is it possible to enter the namespace and dump / restore the DL> routes with NETLINK_ROUTE from userspace ? Or is it something not DL> possible ?
I'm sure it would be doable. However, checkpointing the routes that way would:
(a) Be inconsistent with how we checkpoint all the other resources, including the other network resources we handle from the kernel with rtnl
(b) Require merging of the data from the resources saved in userspace with those saved in kernelspace
(c) Eliminate the ability for an application to easily checkpoint itself by making a single syscall
(d) Require this same sort of jumping back and forth between namespaces by the userspace task doing the checkpoint/restart
Signature · 3 lines
Dan Smith IBM Linux Technology Center email: [email protected]
A message that is not in the archive (sent off-list or not yet received): 87bpd0zl9l.fsf-FLMGYpZoEPULwtHQx/[email protected]
Quoted 7 lines · Dan Smith
I'm sure it would be doable. However, checkpointing the routes that way would:
(a) Be inconsistent with how we checkpoint all the other resources, including the other network resources we handle from the kernel with rtnl
My 2c:
The problem as i see it (with all net structures not just routes - i was equally pessimistic when i saw those other net structure checkpoint/restore changes) is you are faced with a herculean high-maintainance effort...
You have a separate piece of code which populates structures that _you_ maintain for attributes that are defined elsewhere by other people. Nobody adding a new attribute that is very important to route restoration for example is likely to change your code. Unless you tie the two together (so changing one forces the coder to change the other). And once people deploy kernels it is hard to change. Historically (for pragmatic reasons) such rich interfaces sit in user space - much easier to update user space.
cheers,
jamal
j> The problem as i see it (with all net structures not just routes - j> i was equally pessimistic when i saw those other net structure j> checkpoint/restore changes) is you are faced with a herculean j> high-maintainance effort... You have a separate piece of code j> which populates structures that _you_ maintain for attributes that j> are defined elsewhere by other people. Nobody adding a new j> attribute that is very important to route restoration for example j> is likely to change your code. Unless you tie the two together (so j> changing one forces the coder to change the other). And once j> people deploy kernels it is hard to change. Historically (for j> pragmatic reasons) such rich interfaces sit in user space - much j> easier to update user space.
The benefits of doing what we can in userspace are well-understood and arguing for doing so where it makes sense is, of course, a good idea.
However, it seems to me that the rtnl interface provides us a reasonable layer of isolation between us and such changes. Am I wrong? The rtnl messages appear to be rather generic and timeless, and in most cases have a significant amount of flexibility with respect to allowing advanced attributes to be ignored (which implies taking the default).
In many other areas of C/R we're not so lucky and don't have a well-defined interface for dumping that information out of the kernel...
Signature · 3 lines
Dan Smith IBM Linux Technology Center email: [email protected]
Quoted 6 lines · Dan Smith
The benefits of doing what we can in userspace are well-understood and arguing for doing so where it makes sense is, of course, a good idea.
However, it seems to me that the rtnl interface provides us a reasonable layer of isolation between us and such changes. Am I wrong?
I may not have made my point earlier:
Let me give you an example by looking at your migration attributes..
-----
+ __be32 inet4_len; /* mask length (bits)*/ + __u32 inet4_met; /* metric */ + __be32 inet4_dst; /* route address */ + __be32 inet4_gwy; /* gateway address */
-----
At some point i had a discussion with some folks on netdev where it seemed valueable to add a fwmark to the route. If such is made, I dont see what the motivation for whoever is codifying to add it to your attributes so you can migrate the fwmark. One good motivation is to make sure the main route code fails to compile if your attributes dont get modified - this could happen if you re-use the same data structures as the kernel etc.
Quoted 4 lines
The rtnl messages appear to be rather generic and timeless, and in most cases have a significant amount of flexibility with respect to allowing advanced attributes to be ignored (which implies taking the default).
True - but you still need to worry about compat issues etc i.e when you migrate to a remote kernel they better have the same features and kernel config.. I am assuming this is not hard to impose on an admin. Doing things in user space allows for doing more interesting things like negotiating on capabilities etc
Quoted 3 lines
In many other areas of C/R we're not so lucky and don't have a well-defined interface for dumping that information out of the kernel...
Maybe the answer is to start by formalizing that, not sure.
cheers,
jamal
Quoted 4 lines · Dan Smith
DL> Is it possible to enter the namespace and dump / restore the DL> routes with
NETLINK_ROUTEfrom userspace ? Or is it something not DL> possible ?
Quoted 8 lines
I'm sure it would be doable. However, checkpointing the routes that way would:
(a) Be inconsistent with how we checkpoint all the other resources, including the other network resources we handle from the kernel with rtnl
(b) Require merging of the data from the resources saved in userspace with those saved in kernelspace
See below suggestion for userspace.
Quoted 2 lines
(c) Eliminate the ability for an application to easily checkpoint itself by making a single syscall
I can't think of a use-case of a networked application that takes a checkpoint of itself (including live network).
Anyway, it's can still be useful to at least do the restore from userspace (while checkpoint is done in kernel - like with pids). We may reduce the complexity of restore (in kernel) greatly.
(BTW, instead of syscall one could have a library call that will take care of the userspace "work").
Quoted 3 lines
(d) Require this same sort of jumping back and forth between namespaces by the userspace task doing the checkpoint/restart
I wonder: if we could relatively simply recreate the network ns, the interfaces in them, and then restore the routing information all from userspace before calling sys_restart, it may be useful in simplifying the kernel code, and allowing more flexibility for userspace alterations.
I definitely should have asked the question much earlier when you started the work on restoring network ns and interfaces ... (oh, I reckon it's better late than never).
Just tossing out the idea, see what kind of thoughts it evokes. Most likely I'll get a "that won't work because ...", but I'm hoping for a "hmm.. maybe.. let me see.." :)
Oren.
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 29 lines · Daniel Lezcano
Quoted 18 lines · Dan Smith
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.Changes in v2:
This version of the patch actually moves the current task into the desired network namespace temporarily, for the purposes of examining and restoring the route information. This is a instead of creating a cross- namespace socket to do the job, as was done in v1.
This is just an RFC to see if this is an acceptable method. For a final version, adding a helper to
nsproxy.cwould allow us to create a new nsproxy with the desired netns instead of creating one withcopy_namespaces()just to kill it off and use the target one.Quoted 8 lines
I still think the previous method is cleaner, but this way may violate fewer namespace boundaries (I'm still undecided :)
Signed-off-by Dan Smith <danms-r/[email protected]>Cc David Miller <davem-fT/PcQaiUtIeIZ0/[email protected]>Cc Vlad Yasevich <[email protected]>Cc jamal <hadi-fAAogVwAN2Kw5LPnMra/[email protected]>---
Hi Dan,
Quoted 8 lines
Eric did a patchset (as Jamal mentioned it) where you can have a process to enter a specific namespace from userspace.
Is it possible to enter the namespace and dump / restore the routes with
NETLINK_ROUTEfrom userspace ? Or is it something not possible ?
I also think that restoring routes from userspace, if feasible, will be advantageous.
Besides, that will simplify cases in which userspace would like to restore something different (in terms of routes) than what was saved in the checkpoint.
So the question is, what would it take ?
Oren.