Re: [PATCH iproute2 net-next] iproute: ip route get support for sport, dport and ipproto match

2018-06-01 Thread David Ahern
On 5/30/18 11:06 AM, Roopa Prabhu wrote:
> From: Roopa Prabhu 
> 
> Signed-off-by: Roopa Prabhu 
> ---
>  ip/iproute.c   | 26 +-
>  man/man8/ip-route.8.in | 20 +++-
>  2 files changed, 44 insertions(+), 2 deletions(-)

applied to iproute2-next. Thanks


[PATCH iproute2 net-next] iproute: ip route get support for sport, dport and ipproto match

2018-05-30 Thread Roopa Prabhu
From: Roopa Prabhu 

Signed-off-by: Roopa Prabhu 
---
 ip/iproute.c   | 26 +-
 man/man8/ip-route.8.in | 20 +++-
 2 files changed, 44 insertions(+), 2 deletions(-)

diff --git a/ip/iproute.c b/ip/iproute.c
index 56dd9f2..ef04d27 100644
--- a/ip/iproute.c
+++ b/ip/iproute.c
@@ -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"
@@ -1994,6 +1995,29 @@ static int iproute_get(int argc, char **argv)
req.r.rtm_family = addr.family;
addattr_l(, sizeof(req), RTA_NEWDST,
  , addr.bytelen);
+   } else if (matches(*argv, "sport") == 0) {
+   __be16 sport;
+
+   NEXT_ARG();
+   if (get_be16(, *argv, 0))
+   invarg("invalid sport\n", *argv);
+   addattr16(, sizeof(req), RTA_SPORT, sport);
+   } else if (matches(*argv, "dport") == 0) {
+   __be16 dport;
+
+   NEXT_ARG();
+   if (get_be16(, *argv, 0))
+   invarg("invalid dport\n", *argv);
+   addattr16(, 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(, sizeof(req), RTA_IP_PROTO, ipproto);
} else {
inet_prefix addr;
 
diff --git a/man/man8/ip-route.8.in b/man/man8/ip-route.8.in
index b28f3d2..b21a847 100644
--- a/man/man8/ip-route.8.in
+++ b/man/man8/ip-route.8.in
@@ -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 " | "\
@@ -1045,6 +1051,18 @@ the firewall mark
 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
 .RB "(option " from ")"
-- 
2.1.4