From patchwork Thu Jul 26 08:53:39 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pavel Emelyanov X-Patchwork-Id: 173372 X-Patchwork-Delegate: shemminger@vyatta.com Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 25E7D2C008A for ; Thu, 26 Jul 2012 18:53:54 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751053Ab2GZIxt (ORCPT ); Thu, 26 Jul 2012 04:53:49 -0400 Received: from mailhub.sw.ru ([195.214.232.25]:46959 "EHLO relay.sw.ru" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750741Ab2GZIxs (ORCPT ); Thu, 26 Jul 2012 04:53:48 -0400 Received: from [10.30.22.37] ([10.30.22.37]) (authenticated bits=0) by relay.sw.ru (8.13.4/8.13.4) with ESMTP id q6Q8reIb003060 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Thu, 26 Jul 2012 12:53:42 +0400 (MSK) Message-ID: <50110593.1070502@parallels.com> Date: Thu, 26 Jul 2012 12:53:39 +0400 From: Pavel Emelyanov User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:10.0.1) Gecko/20120209 Thunderbird/10.0.1 MIME-Version: 1.0 To: Stephen Hemminger CC: Dan Smith , Linux Netdev List Subject: [PATCH] iproute: Add route showdump command Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org 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 --- -- To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html 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);