netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] ip route: Print table id for 'ip route get'
@ 2015-09-02 17:30 David Ahern
  0 siblings, 0 replies; only message in thread
From: David Ahern @ 2015-09-02 17:30 UTC (permalink / raw)
  To: netdev; +Cc: David Ahern

Table id is not dumped for 'ip route get' requests because the RTM_F_CLONED
flag is set in rt_fill_info. Move it out from the check and show user the
table id any time it is not MAIN.

Example:
    $ ip ru ls
    0:		from all lookup local
    32765:	from all to 10.2.1.0/24 lookup 10
    32766:	from all lookup main
    32767:	from all lookup default

    $ ip route ls
    default via 10.0.0.254 dev eth0
    10.0.0.0/24 dev eth0  proto kernel  scope link  src 10.0.0.2
    10.2.2.0/24 dev eth2  proto kernel  scope link  src 10.2.2.2
    10.2.3.0/24 dev eth3  proto kernel  scope link  src 10.2.3.2
    10.2.4.0/24 dev eth4  proto kernel  scope link  src 10.2.4.2

    $ ip route ls table 10
    10.2.1.0/24 dev eth1  scope link

    Currently:
    $ ip route get 10.2.1.240
    10.2.1.240 dev eth1  src 10.2.1.2
        cache

    With this patch:
    $ ip route get 10.2.1.240
    10.2.1.240 dev eth1  table 10  src 10.2.1.2
        cache

Signed-off-by: David Ahern <dsa@cumulusnetworks.com>
---
 ip/iproute.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/ip/iproute.c b/ip/iproute.c
index 8f49e6289003..9e6148d68e6c 100644
--- a/ip/iproute.c
+++ b/ip/iproute.c
@@ -421,9 +421,10 @@ int print_route(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg)
 	if (tb[RTA_OIF] && filter.oifmask != -1)
 		fprintf(fp, "dev %s ", ll_index_to_name(*(int*)RTA_DATA(tb[RTA_OIF])));
 
+	if ((table != RT_TABLE_MAIN || show_details > 0) && !filter.tb)
+		fprintf(fp, " table %s ", rtnl_rttable_n2a(table, b1, sizeof(b1)));
+
 	if (!(r->rtm_flags&RTM_F_CLONED)) {
-		if ((table != RT_TABLE_MAIN || show_details > 0) && !filter.tb)
-			fprintf(fp, " table %s ", rtnl_rttable_n2a(table, b1, sizeof(b1)));
 		if ((r->rtm_protocol != RTPROT_BOOT || show_details > 0) && filter.protocolmask != -1)
 			fprintf(fp, " proto %s ", rtnl_rtprot_n2a(r->rtm_protocol, b1, sizeof(b1)));
 		if ((r->rtm_scope != RT_SCOPE_UNIVERSE || show_details > 0) && filter.scopemask != -1)
-- 
1.9.1

^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2015-09-02 17:30 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-09-02 17:30 [PATCH] ip route: Print table id for 'ip route get' David Ahern

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).