[prev in list] [next in list] [prev in thread] [next in thread] 

List:       busybox
Subject:    [PATCH] iproute: support for filtering by and printing of scope
From:       André Draszik <git () andred ! net>
Date:       2017-05-31 11:36:35
Message-ID: 20170531113635.32739-1-git () andred ! net
[Download RAW message or body]

This patch adds filtering by and printing of 'scope' to the
ip route command, taken from the upstream ip command.

x86_64:
function                                             old     new   delta
iproute_list_or_flush                               1548    1674    +126
print_route                                         2394    2469     +75
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 201/0)             Total: 201 bytes

mipsel:
function                                             old     new   delta
iproute_list_or_flush                               1952    2096    +144
print_route                                         2580    2696    +116
------------------------------------------------------------------------------
(add/remove: 3/0 grow/shrink: 2/0 up/down: 260/0)             Total: 260 bytes

Signed-off-by: André Draszik <git@andred.net>
---
 networking/libiproute/iproute.c | 25 +++++++++++++++++++++----
 1 file changed, 21 insertions(+), 4 deletions(-)

diff --git a/networking/libiproute/iproute.c b/networking/libiproute/iproute.c
index cc3443a92..7524dea2f 100644
--- a/networking/libiproute/iproute.c
+++ b/networking/libiproute/iproute.c
@@ -28,7 +28,7 @@ struct filter_t {
 	int flushe;
 	struct rtnl_handle *rth;
 	//int protocol, protocolmask; - write-only fields?!
-	//int scope, scopemask; - unused
+	int scope, scopemask;
 	//int type; - read-only
 	//int typemask; - unused
 	//int tos, tosmask; - unused
@@ -120,6 +120,8 @@ static int FAST_FUNC print_route(const struct sockaddr_nl *who UNUSED_PARAM,
 			return 0;
 		}
 	}
+	if ((G_filter.scope ^ r->rtm_scope) & G_filter.scopemask)
+		return 0;
 	if (G_filter.rdst.family
 	 && (r->rtm_family != G_filter.rdst.family || G_filter.rdst.bitlen > r->rtm_dst_len)
 	) {
@@ -270,7 +272,11 @@ static int FAST_FUNC print_route(const struct sockaddr_nl *who UNUSED_PARAM,
 		printf("table %s ", rtnl_rttable_n2a(tid));
 #endif
 
-	/* Todo: parse & show "proto kernel", "scope link" here */
+	/* Todo: parse & show "proto kernel" here */
+	if (!(r->rtm_flags & RTM_F_CLONED)) {
+		if ((r->rtm_scope != RT_SCOPE_UNIVERSE) && G_filter.scopemask != -1)
+			printf("scope %s ", rtnl_rtscope_n2a(r->rtm_scope));
+	}
 
 	if (tb[RTA_PREFSRC] && /*G_filter.rprefsrc.bitlen - always 0*/ 0 != host_len) {
 		/* Do not use format_host(). It is our local addr
@@ -764,7 +770,7 @@ static int iproute_list_or_flush(char **argv, int flush)
 		/* "ip route list/flush" parameters: */
 		"protocol\0" "dev\0"   "oif\0"   "iif\0"
 		"via\0"      "table\0" "cache\0"
-		"from\0"     "to\0"
+		"from\0"     "to\0"    "scope\0"
 		/* and possible further keywords */
 		"all\0"
 		"root\0"
@@ -775,7 +781,7 @@ static int iproute_list_or_flush(char **argv, int flush)
 	enum {
 		KW_proto, KW_dev,   KW_oif,  KW_iif,
 		KW_via,   KW_table, KW_cache,
-		KW_from,  KW_to,
+		KW_from,  KW_to,    KW_scope,
 		/* */
 		KW_all,
 		KW_root,
@@ -834,6 +840,17 @@ static int iproute_list_or_flush(char **argv, int flush)
 			/* The command 'ip route flush cache' is used by OpenSWAN.
 			 * Assuming it's a synonym for 'ip route flush table cache' */
 			G_filter.tb = -1;
+		} else if (arg == KW_scope) {
+			uint32_t scope;
+			NEXT_ARG();
+			G_filter.scopemask = -1;
+			if (rtnl_rtscope_a2n(&scope, *argv)) {
+				if (strcmp(*argv, "all") != 0)
+					invarg_1_to_2(*argv, "scope");
+				scope = RT_SCOPE_NOWHERE;
+				G_filter.scopemask = 0;
+			}
+			G_filter.scope = scope;
 		} else if (arg == KW_from) {
 			NEXT_ARG();
 			parm = index_in_substrings(keywords, *argv);
-- 
2.11.0

_______________________________________________
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic