]> git.proxmox.com Git - mirror_iproute2.git/commitdiff
iproute: ip route get support for sport, dport and ipproto match
authorRoopa Prabhu <roopa@cumulusnetworks.com>
Wed, 30 May 2018 17:06:18 +0000 (10:06 -0700)
committerDavid Ahern <dsahern@gmail.com>
Fri, 1 Jun 2018 15:19:30 +0000 (08:19 -0700)
Signed-off-by: Roopa Prabhu <roopa@cumulusnetworks.com>
Signed-off-by: David Ahern <dsahern@gmail.com>
ip/iproute.c
man/man8/ip-route.8.in

index 78c8085b473a6fd34415248f7f6a8bfa625aeca7..30833414a3f7f4a6597c9edd32d2d1090ae1219b 100644 (file)
@@ -69,7 +69,8 @@ static void usage(void)
                "                            [ from ADDRESS iif STRING ]\n"
                "                            [ oif STRING ] [ tos TOS ]\n"
                "                            [ mark NUMBER ] [ vrf NAME ]\n"
-               "                            [ uid NUMBER ]\n"
+               "                            [ uid NUMBER ] [ ipproto PROTOCOL ]\n"
+               "                            [ sport NUMBER ] [ dport NUMBER ]\n"
                "       ip route { add | del | change | append | replace } ROUTE\n"
                "SELECTOR := [ root PREFIX ] [ match PREFIX ] [ exact PREFIX ]\n"
                "            [ table TABLE_ID ] [ vrf NAME ] [ proto RTPROTO ]\n"
@@ -1991,6 +1992,29 @@ static int iproute_get(int argc, char **argv)
                                req.r.rtm_family = addr.family;
                        addattr_l(&req.n, sizeof(req), RTA_NEWDST,
                                  &addr.data, addr.bytelen);
+               } else if (matches(*argv, "sport") == 0) {
+                       __be16 sport;
+
+                       NEXT_ARG();
+                       if (get_be16(&sport, *argv, 0))
+                               invarg("invalid sport\n", *argv);
+                       addattr16(&req.n, sizeof(req), RTA_SPORT, sport);
+               } else if (matches(*argv, "dport") == 0) {
+                       __be16 dport;
+
+                       NEXT_ARG();
+                       if (get_be16(&dport, *argv, 0))
+                               invarg("invalid dport\n", *argv);
+                       addattr16(&req.n, sizeof(req), RTA_DPORT, dport);
+               } else if (matches(*argv, "ipproto") == 0) {
+                       int ipproto;
+
+                       NEXT_ARG();
+                       ipproto = inet_proto_a2n(*argv);
+                       if (ipproto < 0)
+                               invarg("Invalid \"ipproto\" value\n",
+                                      *argv);
+                       addattr8(&req.n, sizeof(req), RTA_IP_PROTO, ipproto);
                } else {
                        inet_prefix addr;
 
index b28f3d2c7d117bf77414800a274c208f3561595b..b21a8472414273f1f6b84bcdb378009645538794 100644 (file)
@@ -38,7 +38,13 @@ ip-route \- routing table management
 .B  tos
 .IR TOS " ] [ "
 .B  vrf
-.IR NAME " ] "
+.IR NAME " ] [ "
+.B  ipproto
+.IR PROTOCOL " ] [ "
+.B  sport
+.IR NUMBER " ] [ "
+.B  dport
+.IR NUMBER " ] "
 
 .ti -8
 .BR "ip route" " { " add " | " del " | " change " | " append " | "\
@@ -1044,6 +1050,18 @@ the firewall mark
 .BI vrf " NAME"
 force the vrf device on which this packet will be routed.
 
+.TP
+.BI ipproto " PROTOCOL"
+ip protocol as seen by the route lookup
+
+.TP
+.BI sport " NUMBER"
+source port as seen by the route lookup
+
+.TP
+.BI dport " NUMBER"
+destination port as seen by the route lookup
+
 .TP
 .B connected
 if no source address