Commit a973e6fc authored by Andrew Vagin's avatar Andrew Vagin Committed by Pavel Emelyanov

net: dump ipv6 routes

"ip route dump" dumps only ipv4 routes.
Reported-by: 's avatarRoss Boucher <boucher@gmail.com>
Signed-off-by: 's avatarAndrew Vagin <avagin@openvz.org>
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent 3ffad59e
...@@ -73,6 +73,7 @@ struct cr_fd_desc_tmpl imgset_template[CR_FD_MAX] = { ...@@ -73,6 +73,7 @@ struct cr_fd_desc_tmpl imgset_template[CR_FD_MAX] = {
FD_ENTRY(NETNS, "netns-%d"), FD_ENTRY(NETNS, "netns-%d"),
FD_ENTRY_F(IFADDR, "ifaddr-%d", O_NOBUF), FD_ENTRY_F(IFADDR, "ifaddr-%d", O_NOBUF),
FD_ENTRY_F(ROUTE, "route-%d", O_NOBUF), FD_ENTRY_F(ROUTE, "route-%d", O_NOBUF),
FD_ENTRY_F(ROUTE6, "route6-%d", O_NOBUF),
FD_ENTRY_F(IPTABLES, "iptables-%d", O_NOBUF), FD_ENTRY_F(IPTABLES, "iptables-%d", O_NOBUF),
FD_ENTRY_F(TMPFS_IMG, "tmpfs-%d.tar.gz", O_NOBUF), FD_ENTRY_F(TMPFS_IMG, "tmpfs-%d.tar.gz", O_NOBUF),
FD_ENTRY_F(TMPFS_DEV, "tmpfs-dev-%d.tar.gz", O_NOBUF), FD_ENTRY_F(TMPFS_DEV, "tmpfs-dev-%d.tar.gz", O_NOBUF),
......
...@@ -39,6 +39,7 @@ enum { ...@@ -39,6 +39,7 @@ enum {
CR_FD_NETDEV, CR_FD_NETDEV,
CR_FD_IFADDR, CR_FD_IFADDR,
CR_FD_ROUTE, CR_FD_ROUTE,
CR_FD_ROUTE6,
CR_FD_IPTABLES, CR_FD_IPTABLES,
CR_FD_NETNS, CR_FD_NETNS,
_CR_FD_NETNS_TO, _CR_FD_NETNS_TO,
......
...@@ -92,6 +92,7 @@ ...@@ -92,6 +92,7 @@
#define IFADDR_MAGIC RAW_IMAGE_MAGIC #define IFADDR_MAGIC RAW_IMAGE_MAGIC
#define ROUTE_MAGIC RAW_IMAGE_MAGIC #define ROUTE_MAGIC RAW_IMAGE_MAGIC
#define ROUTE6_MAGIC RAW_IMAGE_MAGIC
#define TMPFS_IMG_MAGIC RAW_IMAGE_MAGIC #define TMPFS_IMG_MAGIC RAW_IMAGE_MAGIC
#define TMPFS_DEV_MAGIC RAW_IMAGE_MAGIC #define TMPFS_DEV_MAGIC RAW_IMAGE_MAGIC
#define IPTABLES_MAGIC RAW_IMAGE_MAGIC #define IPTABLES_MAGIC RAW_IMAGE_MAGIC
......
...@@ -518,7 +518,7 @@ exit: ...@@ -518,7 +518,7 @@ exit:
return ret; return ret;
} }
static int run_ip_tool(char *arg1, char *arg2, int fdin, int fdout) static int run_ip_tool(char *arg1, char *arg2, char *arg3, int fdin, int fdout)
{ {
char *ip_tool_cmd; char *ip_tool_cmd;
int ret; int ret;
...@@ -530,7 +530,7 @@ static int run_ip_tool(char *arg1, char *arg2, int fdin, int fdout) ...@@ -530,7 +530,7 @@ static int run_ip_tool(char *arg1, char *arg2, int fdin, int fdout)
ip_tool_cmd = "ip"; ip_tool_cmd = "ip";
ret = cr_system(fdin, fdout, -1, ip_tool_cmd, ret = cr_system(fdin, fdout, -1, ip_tool_cmd,
(char *[]) { "ip", arg1, arg2, NULL }); (char *[]) { "ip", arg1, arg2, arg3, NULL });
if (ret) { if (ret) {
pr_err("IP tool failed on %s %s\n", arg1, arg2); pr_err("IP tool failed on %s %s\n", arg1, arg2);
return -1; return -1;
...@@ -558,13 +558,28 @@ static int run_iptables_tool(char *def_cmd, int fdin, int fdout) ...@@ -558,13 +558,28 @@ static int run_iptables_tool(char *def_cmd, int fdin, int fdout)
static inline int dump_ifaddr(struct cr_imgset *fds) static inline int dump_ifaddr(struct cr_imgset *fds)
{ {
struct cr_img *img = img_from_set(fds, CR_FD_IFADDR); struct cr_img *img = img_from_set(fds, CR_FD_IFADDR);
return run_ip_tool("addr", "save", -1, img_raw_fd(img)); return run_ip_tool("addr", "save", NULL, -1, img_raw_fd(img));
} }
static inline int dump_route(struct cr_imgset *fds) static inline int dump_route(struct cr_imgset *fds)
{ {
struct cr_img *img = img_from_set(fds, CR_FD_ROUTE); struct cr_img *img;
return run_ip_tool("route", "save", -1, img_raw_fd(img));
img = img_from_set(fds, CR_FD_ROUTE);
if (run_ip_tool("route", "save", NULL, -1, img_raw_fd(img)))
return -1;
/* If ipv6 is disabled, "ip -6 route dump" dumps all routes */
if (access("/proc/sys/net/ipv6/", F_OK)) {
pr_debug("ipv6 is disabled\n");
return 0;
}
img = img_from_set(fds, CR_FD_ROUTE6);
if (run_ip_tool("-6", "route", "save", -1, img_raw_fd(img)))
return -1;
return 0;
} }
static inline int dump_iptables(struct cr_imgset *fds) static inline int dump_iptables(struct cr_imgset *fds)
...@@ -610,8 +625,10 @@ static int restore_ip_dump(int type, int pid, char *cmd) ...@@ -610,8 +625,10 @@ static int restore_ip_dump(int type, int pid, char *cmd)
struct cr_img *img; struct cr_img *img;
img = open_image(type, O_RSTR, pid); img = open_image(type, O_RSTR, pid);
if (empty_image(img))
return 0;
if (img) { if (img) {
ret = run_ip_tool(cmd, "restore", img_raw_fd(img), -1); ret = run_ip_tool(cmd, "restore", NULL, img_raw_fd(img), -1);
close_image(img); close_image(img);
} }
...@@ -625,7 +642,13 @@ static inline int restore_ifaddr(int pid) ...@@ -625,7 +642,13 @@ static inline int restore_ifaddr(int pid)
static inline int restore_route(int pid) static inline int restore_route(int pid)
{ {
return restore_ip_dump(CR_FD_ROUTE, pid, "route"); if (restore_ip_dump(CR_FD_ROUTE, pid, "route"))
return -1;
if (restore_ip_dump(CR_FD_ROUTE6, pid, "route"))
return -1;
return 0;
} }
static inline int restore_iptables(int pid) static inline int restore_iptables(int pid)
......
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