]> git.ipfire.org Git - thirdparty/iproute2.git/commitdiff
ip: extend route get to return matching fib route
authorRoopa Prabhu <roopa@cumulusnetworks.com>
Fri, 2 Jun 2017 04:53:28 +0000 (21:53 -0700)
committerStephen Hemminger <stephen@networkplumber.org>
Mon, 5 Jun 2017 19:33:50 +0000 (12:33 -0700)
Uses newly introduced RTM_GETROUTE flag RTM_F_FIB_MATCH
to return a matching fib route. Introduces 'fibmatch'
keyword to ip route get.

ipv4:
----
$ip route show
default via 192.168.0.2 dev eth0
10.0.14.0/24
        nexthop via 172.16.0.3  dev dummy0 weight 1
        nexthop via 172.16.1.3  dev dummy1 weight 1

$ip route get 10.0.14.2
10.0.14.2 via 172.16.1.3 dev dummy1  src 172.16.1.1
    cache

$ip route get fibmatch 10.0.14.2
10.0.14.0/24
        nexthop via 172.16.0.3  dev dummy0 weight 1
        nexthop via 172.16.1.3  dev dummy1 weight 1

ipv6:
----
$ip -6 route show
2001:db9:100::/120  metric 1024
        nexthop via 2001:db8:2::2  dev dummy0 weight 1
        nexthop via 2001:db8:12::2  dev dummy1 weight 1

$ip -6 route get 2001:db9:100::1
2001:db9:100::1 from :: via 2001:db8:12::2 dev dummy1  \
                src 2001:db8:12::1  metric 1024  pref medium

$ip -6 route get fibmatch 2001:db9:100::1
2001:db9:100::/120  metric 1024
        nexthop via 2001:db8:12::2  dev dummy1 weight 1
        nexthop via 2001:db8:2::2  dev dummy0 weight 1

Signed-off-by: Roopa Prabhu <roopa@cumulusnetworks.com>
Acked-by: David Ahern <dsahern@gmail.com>
ip/iproute.c
man/man8/ip-route.8.in

index b4ca2911a5dfb66759c7e1aba84c345a60ba9d2a..1b9c90356730c5153db178eefbceef60ffaf2a48 100644 (file)
@@ -65,7 +65,8 @@ static void usage(void)
        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, "       ip route get [ ROUTE_GET_FLAGS ] ADDRESS\n");
+       fprintf(stderr, "                            [ from ADDRESS iif STRING ]\n");
        fprintf(stderr, "                            [ oif STRING ] [ tos TOS ]\n");
        fprintf(stderr, "                            [ mark NUMBER ] [ vrf NAME ]\n");
        fprintf(stderr, "                            [ uid NUMBER ]\n");
@@ -103,6 +104,7 @@ static void usage(void)
        fprintf(stderr, "ENCAPHDR := [ MPLSLABEL | SEG6HDR ]\n");
        fprintf(stderr, "SEG6HDR := [ mode SEGMODE ] segs ADDR1,ADDRi,ADDRn [hmac HMACKEYID] [cleanup]\n");
        fprintf(stderr, "SEGMODE := [ encap | inline ]\n");
+       fprintf(stderr, "ROUTE_GET_FLAGS := [ fibmatch ]\n");
        exit(-1);
 }
 
@@ -1674,6 +1676,7 @@ static int iproute_get(int argc, char **argv)
        char  *idev = NULL;
        char  *odev = NULL;
        int connected = 0;
+       int fib_match = 0;
        int from_ok = 0;
        unsigned int mark = 0;
 
@@ -1728,6 +1731,8 @@ static int iproute_get(int argc, char **argv)
                        if (get_unsigned(&uid, *argv, 0))
                                invarg("invalid UID\n", *argv);
                        addattr32(&req.n, sizeof(req), RTA_UID, uid);
+               } else if (matches(*argv, "fibmatch") == 0) {
+                       fib_match = 1;
                } else {
                        inet_prefix addr;
 
@@ -1776,6 +1781,8 @@ static int iproute_get(int argc, char **argv)
                req.r.rtm_family = AF_INET;
 
        req.r.rtm_flags |= RTM_F_LOOKUP_TABLE;
+       if (fib_match)
+               req.r.rtm_flags |= RTM_F_FIB_MATCH;
 
        if (rtnl_talk(&rth, &req.n, &req.n, sizeof(req)) < 0)
                return -2;
index c8eb38a758523e2a6c0ee052cc542caf8505e033..de8d360a628551867a531cc4ab3d8eb32da8e5ed 100644 (file)
@@ -28,6 +28,7 @@ ip-route \- routing table management
 
 .ti -8
 .B  ip route get
+.I ROUTE_GET_FLAGS
 .IR ADDRESS " [ "
 .BI from " ADDRESS " iif " STRING"
 .RB " ] [ " oif
@@ -219,6 +220,12 @@ throw " | " unreachable " | " prohibit " | " blackhole " | " nat " ]"
 .B hmac
 .IR KEYID " ]"
 
+.ti -8
+.IR ROUTE_GET_FLAGS " := "
+.BR " [ "
+.BR fibmatch
+.BR " ] "
+
 .SH DESCRIPTION
 .B ip route
 is used to manipulate entries in the kernel routing tables.
@@ -929,6 +936,11 @@ get a single route
 this command gets a single route to a destination and prints its
 contents exactly as the kernel sees it.
 
+.TP
+.BI fibmatch
+Return full fib lookup matched route. Default is to return the resolved
+dst entry
+
 .TP
 .BI to " ADDRESS " (default)
 the destination address.