mirror of
https://github.com/checkpoint-restore/criu.git
synced 2026-07-25 19:14:04 +00:00
netns: Ifaddrs dump and restore
Just run the ip addr save and ip addr restore respectively. Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
This commit is contained in:
parent
0b9b1bd91a
commit
fc1eb96783
5 changed files with 39 additions and 1 deletions
1
image.c
1
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)
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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 *);
|
||||
|
|
|
|||
35
net.c
35
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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue