]> git.ipfire.org Git - thirdparty/iproute2.git/commitdiff
iproute: Add route showdump command (v2)
authorPavel Emelyanov <xemul@parallels.com>
Fri, 27 Jul 2012 04:57:20 +0000 (08:57 +0400)
committerStephen Hemminger <shemminger@vyatta.com>
Fri, 7 Sep 2012 16:13:32 +0000 (09:13 -0700)
Some time ago the save+restore commands were added to ip route (git
id f4ff11e3, Add ip route save/restore). These two save the raw rtnl
stream into a file and restore one (reading it from stdin).

The problem is that there's no way to get the contents of the dump
file in a human readable form. The proposal is to add a command that
reads the rtnl stream from stdin and prints the data in a way the
usual "ip route list" does?

changes since v1:

* Take the magic at the beginning of the dump file into account
* Check for stdin (the dump is taken from) is not a tty

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
ip/iproute.c

index 1cf341799f52709cb23d60f4184959619a5dc381..3e5f8d09b5cc7d882d7014a8fc790f9d4acd6871 100644 (file)
@@ -60,6 +60,7 @@ static void usage(void)
        fprintf(stderr, "Usage: ip route { list | flush } SELECTOR\n");
        fprintf(stderr, "       ip route save SELECTOR\n");
        fprintf(stderr, "       ip route restore\n");
+       fprintf(stderr, "       ip route showdump\n");
        fprintf(stderr, "       ip route get ADDRESS [ from ADDRESS iif STRING ]\n");
        fprintf(stderr, "                            [ oif STRING ]  [ tos TOS ]\n");
        fprintf(stderr, "                            [ mark NUMBER ]\n");
@@ -1565,6 +1566,20 @@ int iproute_restore(void)
        exit(rtnl_from_file(stdin, &restore_handler, NULL));
 }
 
+static int show_handler(const struct sockaddr_nl *nl, struct nlmsghdr *n, void *arg)
+{
+       print_route(nl, n, stdout);
+       return 0;
+}
+
+static int iproute_showdump(void)
+{
+       if (route_dump_check_magic())
+               exit(-1);
+
+       exit(rtnl_from_file(stdin, &show_handler, NULL));
+}
+
 void iproute_reset_filter()
 {
        memset(&filter, 0, sizeof(filter));
@@ -1609,6 +1624,8 @@ int do_iproute(int argc, char **argv)
                return iproute_list_flush_or_save(argc-1, argv+1, IPROUTE_SAVE);
        if (matches(*argv, "restore") == 0)
                return iproute_restore();
+       if (matches(*argv, "showdump") == 0)
+               return iproute_showdump();
        if (matches(*argv, "help") == 0)
                usage();
        fprintf(stderr, "Command \"%s\" is unknown, try \"ip route help\".\n", *argv);