ip rule: unify parsing args

function                                             old     new   delta
do_iprule                                             83     134     +51
print_rule                                           736     726     -10
iprule_list                                           73       -     -73
------------------------------------------------------------------------------
(add/remove: 0/1 grow/shrink: 1/1 up/down: 51/-83)            Total: -32 bytes

Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
This commit is contained in:
Bernhard Reutner-Fischer 2010-05-25 17:22:17 +02:00
parent 96913f9254
commit 1b3549875c

View File

@ -69,11 +69,9 @@ static int FAST_FUNC print_rule(const struct sockaddr_nl *who UNUSED_PARAM,
else if (r->rtm_family == AF_IPX) else if (r->rtm_family == AF_IPX)
host_len = 80; host_len = 80;
*/ */
if (tb[RTA_PRIORITY]) printf("%u:\t", tb[RTA_PRIORITY] ?
printf("%u:\t", *(unsigned*)RTA_DATA(tb[RTA_PRIORITY])); *(unsigned*)RTA_DATA(tb[RTA_PRIORITY])
else : 0);
printf("0:\t");
printf("from "); printf("from ");
if (tb[RTA_SRC]) { if (tb[RTA_SRC]) {
if (r->rtm_src_len != host_len) { if (r->rtm_src_len != host_len) {
@ -310,25 +308,13 @@ int do_iprule(char **argv)
{ {
static const char ip_rule_commands[] ALIGN1 = static const char ip_rule_commands[] ALIGN1 =
"add\0""delete\0""list\0""show\0"; "add\0""delete\0""list\0""show\0";
int cmd = 2; /* list */ if (*argv) {
smalluint cmd = index_in_substrings(ip_rule_commands, *argv);
if (!*argv) if (cmd > 3)
return iprule_list(argv); bb_error_msg_and_die(bb_msg_invalid_arg, *argv, applet_name);
argv++;
cmd = index_in_substrings(ip_rule_commands, *argv); if (cmd < 2)
switch (cmd) { return iprule_modify((cmd == 0) ? RTM_NEWRULE : RTM_DELRULE, argv);
case 0: /* add */
cmd = RTM_NEWRULE;
break;
case 1: /* delete */
cmd = RTM_DELRULE;
break;
case 2: /* list */
case 3: /* show */
return iprule_list(argv+1);
break;
default:
bb_error_msg_and_die("unknown command %s", *argv);
} }
return iprule_modify(cmd, argv+1); return iprule_list(argv);
} }