From: Pavel Emelyanov <xemul@parallels.com>
To: Stephen Hemminger <shemminger@linux-foundation.org>,
Linux Netdev List <netdev@vger.kernel.org>
Subject: [PATCH 2/2] iproute: Add route showdump command (v2)
Date: Fri, 27 Jul 2012 08:57:20 +0400 [thread overview]
Message-ID: <50121FB0.6060200@parallels.com> (raw)
In-Reply-To: <50121F4D.8090606@parallels.com>
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 | 17 +++++++++++++++++
1 files changed, 17 insertions(+), 0 deletions(-)
diff --git a/ip/iproute.c b/ip/iproute.c
index bbb3923..572e2e8 100644
--- a/ip/iproute.c
+++ b/ip/iproute.c
@@ -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");
@@ -1566,6 +1567,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));
@@ -1610,6 +1625,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);
--
1.5.5.6
next prev parent reply other threads:[~2012-07-27 4:57 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-07-27 4:55 [PATCH 1/2] iproute: Add magic cookie to route dump file Pavel Emelyanov
2012-07-27 4:57 ` Pavel Emelyanov [this message]
2012-07-27 5:03 ` [PATCH 2/2] iproute: Add route showdump command (v2) Pavel Emelyanov
2012-07-27 6:06 ` Pavel Emelyanov
2012-07-27 17:05 ` Stephen Hemminger
2012-09-11 15:47 ` [PATCH] iproute: Add ability to save, restore and show the interfaces' addresses (resend) Pavel Emelyanov
2012-09-11 16:18 ` Stephen Hemminger
2012-09-07 16:14 ` [PATCH 2/2] iproute: Add route showdump command (v2) Stephen Hemminger
2012-07-27 10:46 ` [PATCH 1/2] iproute: Add magic cookie to route dump file David Laight
2012-07-27 13:35 ` Pavel Emelyanov
2012-07-27 16:59 ` Stephen Hemminger
2012-08-17 20:49 ` Stephen Hemminger
2012-08-20 8:05 ` Pavel Emelyanov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=50121FB0.6060200@parallels.com \
--to=xemul@parallels.com \
--cc=netdev@vger.kernel.org \
--cc=shemminger@linux-foundation.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.