aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndré Draszik <git@andred.net>2017-06-13 19:59:59 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2017-06-13 19:59:59 +0200
commit2f24d30d0133f81cf3e0639746039a8ed58426e9 (patch)
tree1bea338ed67e719c45eb0d0178f557176b74f65b
parent978307f8a19084ffb6e977ee28c731445e37dbbd (diff)
downloadbusybox-w32-2f24d30d0133f81cf3e0639746039a8ed58426e9.tar.gz
busybox-w32-2f24d30d0133f81cf3e0639746039a8ed58426e9.tar.bz2
busybox-w32-2f24d30d0133f81cf3e0639746039a8ed58426e9.zip
iproute: support for filtering by and printing of scope
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: 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> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--networking/libiproute/iproute.c26
1 files changed, 22 insertions, 4 deletions
diff --git a/networking/libiproute/iproute.c b/networking/libiproute/iproute.c
index cc3443a92..6a41b8331 100644
--- a/networking/libiproute/iproute.c
+++ b/networking/libiproute/iproute.c
@@ -28,7 +28,7 @@ struct filter_t {
28 int flushe; 28 int flushe;
29 struct rtnl_handle *rth; 29 struct rtnl_handle *rth;
30 //int protocol, protocolmask; - write-only fields?! 30 //int protocol, protocolmask; - write-only fields?!
31 //int scope, scopemask; - unused 31 int scope, scopemask;
32 //int type; - read-only 32 //int type; - read-only
33 //int typemask; - unused 33 //int typemask; - unused
34 //int tos, tosmask; - unused 34 //int tos, tosmask; - unused
@@ -120,6 +120,8 @@ static int FAST_FUNC print_route(const struct sockaddr_nl *who UNUSED_PARAM,
120 return 0; 120 return 0;
121 } 121 }
122 } 122 }
123 if ((G_filter.scope ^ r->rtm_scope) & G_filter.scopemask)
124 return 0;
123 if (G_filter.rdst.family 125 if (G_filter.rdst.family
124 && (r->rtm_family != G_filter.rdst.family || G_filter.rdst.bitlen > r->rtm_dst_len) 126 && (r->rtm_family != G_filter.rdst.family || G_filter.rdst.bitlen > r->rtm_dst_len)
125 ) { 127 ) {
@@ -270,7 +272,11 @@ static int FAST_FUNC print_route(const struct sockaddr_nl *who UNUSED_PARAM,
270 printf("table %s ", rtnl_rttable_n2a(tid)); 272 printf("table %s ", rtnl_rttable_n2a(tid));
271#endif 273#endif
272 274
273 /* Todo: parse & show "proto kernel", "scope link" here */ 275 /* Todo: parse & show "proto kernel" here */
276 if (!(r->rtm_flags & RTM_F_CLONED)) {
277 if ((r->rtm_scope != RT_SCOPE_UNIVERSE) && G_filter.scopemask != -1)
278 printf("scope %s ", rtnl_rtscope_n2a(r->rtm_scope));
279 }
274 280
275 if (tb[RTA_PREFSRC] && /*G_filter.rprefsrc.bitlen - always 0*/ 0 != host_len) { 281 if (tb[RTA_PREFSRC] && /*G_filter.rprefsrc.bitlen - always 0*/ 0 != host_len) {
276 /* Do not use format_host(). It is our local addr 282 /* Do not use format_host(). It is our local addr
@@ -761,10 +767,11 @@ static int iproute_list_or_flush(char **argv, int flush)
761 char *id = NULL; 767 char *id = NULL;
762 char *od = NULL; 768 char *od = NULL;
763 static const char keywords[] ALIGN1 = 769 static const char keywords[] ALIGN1 =
770 /* If you add stuff here, update iproute_full_usage */
764 /* "ip route list/flush" parameters: */ 771 /* "ip route list/flush" parameters: */
765 "protocol\0" "dev\0" "oif\0" "iif\0" 772 "protocol\0" "dev\0" "oif\0" "iif\0"
766 "via\0" "table\0" "cache\0" 773 "via\0" "table\0" "cache\0"
767 "from\0" "to\0" 774 "from\0" "to\0" "scope\0"
768 /* and possible further keywords */ 775 /* and possible further keywords */
769 "all\0" 776 "all\0"
770 "root\0" 777 "root\0"
@@ -775,7 +782,7 @@ static int iproute_list_or_flush(char **argv, int flush)
775 enum { 782 enum {
776 KW_proto, KW_dev, KW_oif, KW_iif, 783 KW_proto, KW_dev, KW_oif, KW_iif,
777 KW_via, KW_table, KW_cache, 784 KW_via, KW_table, KW_cache,
778 KW_from, KW_to, 785 KW_from, KW_to, KW_scope,
779 /* */ 786 /* */
780 KW_all, 787 KW_all,
781 KW_root, 788 KW_root,
@@ -834,6 +841,17 @@ static int iproute_list_or_flush(char **argv, int flush)
834 /* The command 'ip route flush cache' is used by OpenSWAN. 841 /* The command 'ip route flush cache' is used by OpenSWAN.
835 * Assuming it's a synonym for 'ip route flush table cache' */ 842 * Assuming it's a synonym for 'ip route flush table cache' */
836 G_filter.tb = -1; 843 G_filter.tb = -1;
844 } else if (arg == KW_scope) {
845 uint32_t scope;
846 NEXT_ARG();
847 G_filter.scopemask = -1;
848 if (rtnl_rtscope_a2n(&scope, *argv)) {
849 if (strcmp(*argv, "all") != 0)
850 invarg_1_to_2(*argv, "scope");
851 scope = RT_SCOPE_NOWHERE;
852 G_filter.scopemask = 0;
853 }
854 G_filter.scope = scope;
837 } else if (arg == KW_from) { 855 } else if (arg == KW_from) {
838 NEXT_ARG(); 856 NEXT_ARG();
839 parm = index_in_substrings(keywords, *argv); 857 parm = index_in_substrings(keywords, *argv);