ip: stop propagating argc; optimize ip_parse_common_args
function old new delta
find_pair 167 187 +20
static.families - 17 +17
die_must_be_on_off - 11 +11
...
on_off 33 22 -11
do_ipaddr 103 90 -13
do_iptunnel 1001 986 -15
iproute_list_or_flush 1237 1217 -20
static.ip_common_commands 43 22 -21
do_iproute 2217 2193 -24
parse_args 1444 1414 -30
ip_do 47 16 -31
do_iprule 994 963 -31
ip_main 153 113 -40
ipaddr_modify 1357 1305 -52
ipaddr_list_or_flush 2543 2490 -53
ip_parse_common_args 294 159 -135
------------------------------------------------------------------------------
(add/remove: 4/1 grow/shrink: 4/24 up/down: 85/-563) Total: -478 bytes
text data bss dec hex filename
775561 966 9236 785763 bfd63 busybox_old
775073 962 9236 785271 bfb77 busybox_unstripped
diff --git a/networking/libiproute/iprule.c b/networking/libiproute/iprule.c
index 3c276e6..6442992 100644
--- a/networking/libiproute/iprule.c
+++ b/networking/libiproute/iprule.c
@@ -161,7 +161,7 @@
}
/* Return value becomes exitcode. It's okay to not return at all */
-static int iprule_list(int argc, char **argv)
+static int iprule_list(char **argv)
{
struct rtnl_handle rth;
int af = preferred_family;
@@ -169,9 +169,9 @@
if (af == AF_UNSPEC)
af = AF_INET;
- if (argc > 0) {
+ if (*argv) {
//bb_error_msg("\"rule show\" needs no arguments");
- bb_warn_ignoring_args(argc);
+ bb_warn_ignoring_args(1);
return -1;
}
@@ -184,7 +184,7 @@
}
/* Return value becomes exitcode. It's okay to not return at all */
-static int iprule_modify(int cmd, int argc, char **argv)
+static int iprule_modify(int cmd, char **argv)
{
static const char keywords[] ALIGN1 =
"from\0""to\0""preference\0""order\0""priority\0"
@@ -220,7 +220,7 @@
req.r.rtm_type = RTN_UNICAST;
}
- while (argc > 0) {
+ while (*argv) {
key = index_in_substrings(keywords, *argv) + 1;
if (key == 0) /* no match found in keywords array, bail out. */
bb_error_msg_and_die(bb_msg_invalid_arg, *argv, applet_name);
@@ -291,7 +291,6 @@
invarg(*argv, "type");
req.r.rtm_type = type;
}
- argc--;
argv++;
}
@@ -310,17 +309,16 @@
}
/* Return value becomes exitcode. It's okay to not return at all */
-int do_iprule(int argc, char **argv)
+int do_iprule(char **argv)
{
static const char ip_rule_commands[] ALIGN1 =
"add\0""delete\0""list\0""show\0";
int cmd = 2; /* list */
- if (argc < 1)
- return iprule_list(0, NULL);
- if (*argv)
- cmd = index_in_substrings(ip_rule_commands, *argv);
+ if (!*argv)
+ return iprule_list(argv);
+ cmd = index_in_substrings(ip_rule_commands, *argv);
switch (cmd) {
case 0: /* add */
cmd = RTM_NEWRULE;
@@ -330,10 +328,10 @@
break;
case 2: /* list */
case 3: /* show */
- return iprule_list(argc-1, argv+1);
+ return iprule_list(argv+1);
break;
default:
bb_error_msg_and_die("unknown command %s", *argv);
}
- return iprule_modify(cmd, argc-1, argv+1);
+ return iprule_modify(cmd, argv+1);
}