From a6439860cdd165eaafac7eb83079c9ea89b7fd6b Mon Sep 17 00:00:00 2001 From: Pavel Emelyanov Date: Thu, 2 Aug 2012 08:31:46 +0400 Subject: [PATCH] net: Routes dump and restore Same here -- run ip tool and that's it. Signed-off-by: Pavel Emelyanov --- image.c | 1 + include/crtools.h | 1 + include/image.h | 1 + include/net.h | 1 + net.c | 18 ++++++++++++++++++ 5 files changed, 22 insertions(+) diff --git a/image.c b/image.c index f278828cf..bcca98c95 100644 --- a/image.c +++ b/image.c @@ -120,6 +120,7 @@ struct cr_fd_desc_tmpl fdset_template[CR_FD_MAX] = { FD_ENTRY(MOUNTPOINTS, "mountpoints-%d", show_mountpoints), FD_ENTRY(NETDEV, "netdev-%d", show_netdevices), FD_ENTRY(IFADDR, "ifaddr-%d", show_ifaddrs), + FD_ENTRY(ROUTE, "route-%d", show_routes), }; static struct cr_fdset *alloc_cr_fdset(int nr) diff --git a/include/crtools.h b/include/crtools.h index e2a6ab6a5..6fda2cdd7 100644 --- a/include/crtools.h +++ b/include/crtools.h @@ -48,6 +48,7 @@ enum { CR_FD_MOUNTPOINTS, CR_FD_NETDEV, CR_FD_IFADDR, + CR_FD_ROUTE, _CR_FD_NS_TO, CR_FD_PSTREE, diff --git a/include/image.h b/include/image.h index a0424fe04..e8a5c6e37 100644 --- a/include/image.h +++ b/include/image.h @@ -59,6 +59,7 @@ #define NETDEV_MAGIC 0x57373951 /* Yaroslavl */ #define IFADDR_MAGIC RAW_IMAGE_MAGIC +#define ROUTE_MAGIC RAW_IMAGE_MAGIC #define PAGE_IMAGE_SIZE 4096 #define PAGE_RSS 1 diff --git a/include/net.h b/include/net.h index 559f3dd6e..e207a610f 100644 --- a/include/net.h +++ b/include/net.h @@ -3,6 +3,7 @@ struct cr_options; void show_netdevices(int fd, struct cr_options *); void show_ifaddrs(int fd, struct cr_options *); +void show_routes(int fd, struct cr_options *); struct cr_fdset; int dump_net_ns(int pid, struct cr_fdset *); diff --git a/net.c b/net.c index 0e9ca9905..5d55d487f 100644 --- a/net.c +++ b/net.c @@ -232,6 +232,11 @@ static inline int dump_ifaddr(struct cr_fdset *fds) return run_ip_tool("addr", "save", -1, fdset_fd(fds, CR_FD_IFADDR)); } +static inline int dump_route(struct cr_fdset *fds) +{ + return run_ip_tool("route", "save", -1, fdset_fd(fds, CR_FD_ROUTE)); +} + static int restore_ip_dump(int type, int pid, char *cmd) { int fd, ret; @@ -250,11 +255,20 @@ static inline int restore_ifaddr(int pid) return restore_ip_dump(CR_FD_IFADDR, pid, "addr"); } +static inline int restore_route(int pid) +{ + return restore_ip_dump(CR_FD_ROUTE, pid, "route"); +} + void show_ifaddrs(int fd, struct cr_options *o) { BUG_ON(1); } +void show_routes(int fd, struct cr_options *o) +{ + BUG_ON(1); +} int dump_net_ns(int pid, struct cr_fdset *fds) { @@ -265,6 +279,8 @@ int dump_net_ns(int pid, struct cr_fdset *fds) ret = dump_links(fds); if (!ret) ret = dump_ifaddr(fds); + if (!ret) + ret = dump_route(fds); return ret; } @@ -276,6 +292,8 @@ int prepare_net_ns(int pid) ret = restore_links(pid); if (!ret) ret = restore_ifaddr(pid); + if (!ret) + ret = restore_route(pid); return ret; }