Commit fc1eb967 authored by Pavel Emelyanov's avatar Pavel Emelyanov

netns: Ifaddrs dump and restore

Just run the ip addr save and ip addr restore respectively.
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent 0b9b1bd9
...@@ -119,6 +119,7 @@ struct cr_fd_desc_tmpl fdset_template[CR_FD_MAX] = { ...@@ -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(TCP_STREAM, "tcp-stream-%x", show_tcp_stream),
FD_ENTRY(MOUNTPOINTS, "mountpoints-%d", show_mountpoints), FD_ENTRY(MOUNTPOINTS, "mountpoints-%d", show_mountpoints),
FD_ENTRY(NETDEV, "netdev-%d", show_netdevices), FD_ENTRY(NETDEV, "netdev-%d", show_netdevices),
FD_ENTRY(IFADDR, "ifaddr-%d", show_ifaddrs),
}; };
static struct cr_fdset *alloc_cr_fdset(int nr) static struct cr_fdset *alloc_cr_fdset(int nr)
......
...@@ -47,6 +47,7 @@ enum { ...@@ -47,6 +47,7 @@ enum {
CR_FD_IPCNS_SEM, CR_FD_IPCNS_SEM,
CR_FD_MOUNTPOINTS, CR_FD_MOUNTPOINTS,
CR_FD_NETDEV, CR_FD_NETDEV,
CR_FD_IFADDR,
_CR_FD_NS_TO, _CR_FD_NS_TO,
CR_FD_PSTREE, CR_FD_PSTREE,
......
...@@ -58,6 +58,8 @@ ...@@ -58,6 +58,8 @@
#define MOUNTPOINTS_MAGIC 0x55563928 /* Petushki */ #define MOUNTPOINTS_MAGIC 0x55563928 /* Petushki */
#define NETDEV_MAGIC 0x57373951 /* Yaroslavl */ #define NETDEV_MAGIC 0x57373951 /* Yaroslavl */
#define IFADDR_MAGIC RAW_IMAGE_MAGIC
#define PAGE_IMAGE_SIZE 4096 #define PAGE_IMAGE_SIZE 4096
#define PAGE_RSS 1 #define PAGE_RSS 1
#define PAGE_ANON 2 #define PAGE_ANON 2
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
#define __CR_NET_H__ #define __CR_NET_H__
struct cr_options; struct cr_options;
void show_netdevices(int fd, struct cr_options *); void show_netdevices(int fd, struct cr_options *);
void show_ifaddrs(int fd, struct cr_options *);
struct cr_fdset; struct cr_fdset;
int dump_net_ns(int pid, struct cr_fdset *); int dump_net_ns(int pid, struct cr_fdset *);
......
...@@ -170,7 +170,7 @@ static int restore_links(int pid) ...@@ -170,7 +170,7 @@ static int restore_links(int pid)
return ret; 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; int pid, ret, status;
...@@ -227,6 +227,35 @@ int run_ip_tool(char *arg1, char *arg2, int fdin, int fdout) ...@@ -227,6 +227,35 @@ int run_ip_tool(char *arg1, char *arg2, int fdin, int fdout)
return 0; 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 dump_net_ns(int pid, struct cr_fdset *fds)
{ {
int ret; int ret;
...@@ -234,6 +263,8 @@ int dump_net_ns(int pid, struct cr_fdset *fds) ...@@ -234,6 +263,8 @@ int dump_net_ns(int pid, struct cr_fdset *fds)
ret = switch_ns(pid, CLONE_NEWNET, "net", NULL); ret = switch_ns(pid, CLONE_NEWNET, "net", NULL);
if (!ret) if (!ret)
ret = dump_links(fds); ret = dump_links(fds);
if (!ret)
ret = dump_ifaddr(fds);
return ret; return ret;
} }
...@@ -243,6 +274,8 @@ int prepare_net_ns(int pid) ...@@ -243,6 +274,8 @@ int prepare_net_ns(int pid)
int ret; int ret;
ret = restore_links(pid); ret = restore_links(pid);
if (!ret)
ret = restore_ifaddr(pid);
return ret; return ret;
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment