From fc1eb96783399b526c1954fdaa5a1122b6cd0f1a Mon Sep 17 00:00:00 2001 From: Pavel Emelyanov Date: Thu, 2 Aug 2012 08:26:43 +0400 Subject: [PATCH] netns: Ifaddrs dump and restore Just run the ip addr save and ip addr restore respectively. Signed-off-by: Pavel Emelyanov --- image.c | 1 + include/crtools.h | 1 + include/image.h | 2 ++ include/net.h | 1 + net.c | 35 ++++++++++++++++++++++++++++++++++- 5 files changed, 39 insertions(+), 1 deletion(-) diff --git a/image.c b/image.c index 62a647832..f278828cf 100644 --- a/image.c +++ b/image.c @@ -119,6 +119,7 @@ struct cr_fd_desc_tmpl fdset_template[CR_FD_MAX] = { FD_ENTRY(TCP_STREAM, "tcp-stream-%x", show_tcp_stream), FD_ENTRY(MOUNTPOINTS, "mountpoints-%d", show_mountpoints), FD_ENTRY(NETDEV, "netdev-%d", show_netdevices), + FD_ENTRY(IFADDR, "ifaddr-%d", show_ifaddrs), }; static struct cr_fdset *alloc_cr_fdset(int nr) diff --git a/include/crtools.h b/include/crtools.h index d25ebb6b4..e2a6ab6a5 100644 --- a/include/crtools.h +++ b/include/crtools.h @@ -47,6 +47,7 @@ enum { CR_FD_IPCNS_SEM, CR_FD_MOUNTPOINTS, CR_FD_NETDEV, + CR_FD_IFADDR, _CR_FD_NS_TO, CR_FD_PSTREE, diff --git a/include/image.h b/include/image.h index df4c8ba61..a0424fe04 100644 --- a/include/image.h +++ b/include/image.h @@ -58,6 +58,8 @@ #define MOUNTPOINTS_MAGIC 0x55563928 /* Petushki */ #define NETDEV_MAGIC 0x57373951 /* Yaroslavl */ +#define IFADDR_MAGIC RAW_IMAGE_MAGIC + #define PAGE_IMAGE_SIZE 4096 #define PAGE_RSS 1 #define PAGE_ANON 2 diff --git a/include/net.h b/include/net.h index 50218d79e..559f3dd6e 100644 --- a/include/net.h +++ b/include/net.h @@ -2,6 +2,7 @@ #define __CR_NET_H__ struct cr_options; void show_netdevices(int fd, struct cr_options *); +void show_ifaddrs(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 4962365fb..0e9ca9905 100644 --- a/net.c +++ b/net.c @@ -170,7 +170,7 @@ static int restore_links(int pid) return ret; } -int run_ip_tool(char *arg1, char *arg2, int fdin, int fdout) +static int run_ip_tool(char *arg1, char *arg2, int fdin, int fdout) { int pid, ret, status; @@ -227,6 +227,35 @@ int run_ip_tool(char *arg1, char *arg2, int fdin, int fdout) return 0; } +static inline int dump_ifaddr(struct cr_fdset *fds) +{ + return run_ip_tool("addr", "save", -1, fdset_fd(fds, CR_FD_IFADDR)); +} + +static int restore_ip_dump(int type, int pid, char *cmd) +{ + int fd, ret; + + ret = fd = open_image_ro(type, pid); + if (fd > 0) { + ret = run_ip_tool(cmd, "restore", fd, -1); + close(fd); + } + + return ret; +} + +static inline int restore_ifaddr(int pid) +{ + return restore_ip_dump(CR_FD_IFADDR, pid, "addr"); +} + +void show_ifaddrs(int fd, struct cr_options *o) +{ + BUG_ON(1); +} + + int dump_net_ns(int pid, struct cr_fdset *fds) { int ret; @@ -234,6 +263,8 @@ int dump_net_ns(int pid, struct cr_fdset *fds) ret = switch_ns(pid, CLONE_NEWNET, "net", NULL); if (!ret) ret = dump_links(fds); + if (!ret) + ret = dump_ifaddr(fds); return ret; } @@ -243,6 +274,8 @@ int prepare_net_ns(int pid) int ret; ret = restore_links(pid); + if (!ret) + ret = restore_ifaddr(pid); return ret; }