netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] iproute: Add route showdump command
@ 2012-07-26  8:53 Pavel Emelyanov
  2012-07-26 16:03 ` Stephen Hemminger
  0 siblings, 1 reply; 3+ messages in thread
From: Pavel Emelyanov @ 2012-07-26  8:53 UTC (permalink / raw)
  To: Stephen Hemminger; +Cc: Dan Smith, Linux Netdev List

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. How about adding a command that reads
the rtnl stream from stdin and prints the data in a way the usual
"ip route list" does?

Signed-off-by: Pavel Emelyanov <xemul@parallels.com>

---

diff --git a/ip/iproute.c b/ip/iproute.c
index 5cd313e..585a7d8 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");
@@ -1526,6 +1527,17 @@ 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)
+{
+	exit(rtnl_from_file(stdin, &show_handler, NULL));
+}
+
 void iproute_reset_filter()
 {
 	memset(&filter, 0, sizeof(filter));
@@ -1570,6 +1582,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);

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] iproute: Add route showdump command
  2012-07-26  8:53 [PATCH] iproute: Add route showdump command Pavel Emelyanov
@ 2012-07-26 16:03 ` Stephen Hemminger
  2012-07-27  4:14   ` Pavel Emelyanov
  0 siblings, 1 reply; 3+ messages in thread
From: Stephen Hemminger @ 2012-07-26 16:03 UTC (permalink / raw)
  To: Pavel Emelyanov; +Cc: Dan Smith, Linux Netdev List

On Thu, 26 Jul 2012 12:53:39 +0400
Pavel Emelyanov <xemul@parallels.com> wrote:

> 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. How about adding a command that reads
> the rtnl stream from stdin and prints the data in a way the usual
> "ip route list" does?
> 
> Signed-off-by: Pavel Emelyanov <xemul@parallels.com>

Being able to decode a dump is great idea.
Are the user's smart enough not to try it out at the command prompt
and get totally lost? Maybe another isatty() check is needed.

Another solution would be to put a small header on the save file with
a magic number that could be checked. This would mean changing save/restore/showdump
and ideally updating the magic file in distributions.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] iproute: Add route showdump command
  2012-07-26 16:03 ` Stephen Hemminger
@ 2012-07-27  4:14   ` Pavel Emelyanov
  0 siblings, 0 replies; 3+ messages in thread
From: Pavel Emelyanov @ 2012-07-27  4:14 UTC (permalink / raw)
  To: Stephen Hemminger; +Cc: Dan Smith, Linux Netdev List

On 07/26/2012 08:03 PM, Stephen Hemminger wrote:
> On Thu, 26 Jul 2012 12:53:39 +0400
> Pavel Emelyanov <xemul@parallels.com> wrote:
> 
>> 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. How about adding a command that reads
>> the rtnl stream from stdin and prints the data in a way the usual
>> "ip route list" does?
>>
>> Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
> 
> Being able to decode a dump is great idea.
> Are the user's smart enough not to try it out at the command prompt
> and get totally lost? Maybe another isatty() check is needed.
> 
> Another solution would be to put a small header on the save file with
> a magic number that could be checked. This would mean changing save/restore/showdump
> and ideally updating the magic file in distributions.
> .

Hm... The idea with magic looks reasonable.
I will look at what can be done here, thanks!

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2012-07-27  4:14 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-07-26  8:53 [PATCH] iproute: Add route showdump command Pavel Emelyanov
2012-07-26 16:03 ` Stephen Hemminger
2012-07-27  4:14   ` Pavel Emelyanov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).