route: code shrink
function old new delta kw_lookup 84 86 +2 tbl_hash_net_host 15 14 -1 tbl_verb 21 19 -2 tbl_ipvx 104 92 -12 packed_usage 33527 33493 -34 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 1/4 up/down: 2/-49) Total: -47 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
parent
b164cdb854
commit
ddc6dfdb4d
@ -75,17 +75,15 @@
|
|||||||
#define RTACTION_ADD 1
|
#define RTACTION_ADD 1
|
||||||
#define RTACTION_DEL 2
|
#define RTACTION_DEL 2
|
||||||
|
|
||||||
/* For the various tbl_*[] arrays, the 1st byte is the offset to
|
/* For the various tbl_*[] arrays, the 1st byte is return value. */
|
||||||
* the next entry and the 2nd byte is return value. */
|
|
||||||
|
|
||||||
#define NET_FLAG 1
|
#define NET_FLAG 1
|
||||||
#define HOST_FLAG 2
|
#define HOST_FLAG 2
|
||||||
|
|
||||||
/* We remap '-' to '#' to avoid problems with getopt. */
|
/* We remap '-' to '#' to avoid problems with getopt. */
|
||||||
static const char tbl_hash_net_host[] ALIGN1 =
|
static const char tbl_hash_net_host[] ALIGN1 =
|
||||||
"\007\001#net\0"
|
"\001#net\0"
|
||||||
/* "\010\002#host\0" */
|
"\002#host\0"
|
||||||
"\007\002#host" /* Since last, we can save a byte. */
|
|
||||||
;
|
;
|
||||||
|
|
||||||
#define KW_TAKES_ARG 020
|
#define KW_TAKES_ARG 020
|
||||||
@ -108,29 +106,28 @@ static const char tbl_hash_net_host[] ALIGN1 =
|
|||||||
static const char tbl_ipvx[] ALIGN1 =
|
static const char tbl_ipvx[] ALIGN1 =
|
||||||
/* 020 is the "takes an arg" bit */
|
/* 020 is the "takes an arg" bit */
|
||||||
#if HAVE_NEW_ADDRT
|
#if HAVE_NEW_ADDRT
|
||||||
"\011\020metric\0"
|
"\020metric\0"
|
||||||
#endif
|
#endif
|
||||||
"\012\021netmask\0"
|
"\021netmask\0"
|
||||||
"\005\022gw\0"
|
"\022gw\0"
|
||||||
"\012\022gateway\0"
|
"\022gateway\0"
|
||||||
"\006\023mss\0"
|
"\023mss\0"
|
||||||
"\011\024window\0"
|
"\024window\0"
|
||||||
#ifdef RTF_IRTT
|
#ifdef RTF_IRTT
|
||||||
"\007\025irtt\0"
|
"\025irtt\0"
|
||||||
#endif
|
#endif
|
||||||
"\006\026dev\0"
|
"\026dev\0"
|
||||||
"\011\026device\0"
|
"\026device\0"
|
||||||
/* 040 is the "sets a flag" bit - MUST match flags_ipvx[] values below. */
|
/* 040 is the "sets a flag" bit - MUST match flags_ipvx[] values below. */
|
||||||
#ifdef RTF_REJECT
|
#ifdef RTF_REJECT
|
||||||
"\011\040reject\0"
|
"\040reject\0"
|
||||||
#endif
|
#endif
|
||||||
"\006\041mod\0"
|
"\041mod\0"
|
||||||
"\006\042dyn\0"
|
"\042dyn\0"
|
||||||
/* "\014\043reinstate\0" */
|
"\043reinstate\0"
|
||||||
"\013\043reinstate" /* Since last, we can save a byte. */
|
|
||||||
;
|
;
|
||||||
|
|
||||||
static const uint16_t flags_ipvx[] = { /* MUST match tbl_ipvx[] values above. */
|
static const uint16_t flags_ipvx[] ALIGN2 = { /* MUST match tbl_ipvx[] values above. */
|
||||||
#ifdef RTF_REJECT
|
#ifdef RTF_REJECT
|
||||||
RTF_REJECT,
|
RTF_REJECT,
|
||||||
#endif
|
#endif
|
||||||
@ -143,17 +140,17 @@ static int kw_lookup(const char *kwtbl, char ***pargs)
|
|||||||
{
|
{
|
||||||
if (**pargs) {
|
if (**pargs) {
|
||||||
do {
|
do {
|
||||||
if (strcmp(kwtbl+2, **pargs) == 0) { /* Found a match. */
|
if (strcmp(kwtbl + 1, **pargs) == 0) { /* Found a match. */
|
||||||
*pargs += 1;
|
*pargs += 1;
|
||||||
if (kwtbl[1] & KW_TAKES_ARG) {
|
if (kwtbl[0] & KW_TAKES_ARG) {
|
||||||
if (!**pargs) { /* No more args! */
|
if (!**pargs) { /* No more args! */
|
||||||
bb_show_usage();
|
bb_show_usage();
|
||||||
}
|
}
|
||||||
*pargs += 1; /* Calling routine will use args[-1]. */
|
*pargs += 1; /* Calling routine will use args[-1]. */
|
||||||
}
|
}
|
||||||
return kwtbl[1];
|
return kwtbl[0];
|
||||||
}
|
}
|
||||||
kwtbl += *kwtbl;
|
kwtbl += strlen(kwtbl) + 1;
|
||||||
} while (*kwtbl);
|
} while (*kwtbl);
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
@ -536,7 +533,6 @@ void FAST_FUNC bb_displayroutes(int noresolve, int netstatfmt)
|
|||||||
flags[0] = '!';
|
flags[0] = '!';
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
memset(&s_addr, 0, sizeof(struct sockaddr_in));
|
memset(&s_addr, 0, sizeof(struct sockaddr_in));
|
||||||
s_addr.sin_family = AF_INET;
|
s_addr.sin_family = AF_INET;
|
||||||
s_addr.sin_addr.s_addr = d;
|
s_addr.sin_addr.s_addr = d;
|
||||||
@ -626,7 +622,6 @@ static void INET6_displayroutes(void)
|
|||||||
naddr6 = INET6_rresolve((struct sockaddr_in6 *) &snaddr6,
|
naddr6 = INET6_rresolve((struct sockaddr_in6 *) &snaddr6,
|
||||||
0x0fff /* Apparently, upstream never resolves. */
|
0x0fff /* Apparently, upstream never resolves. */
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!r) { /* 1st pass */
|
if (!r) { /* 1st pass */
|
||||||
snprintf(addr6, sizeof(addr6), "%s/%d", naddr6, prefix_len);
|
snprintf(addr6, sizeof(addr6), "%s/%d", naddr6, prefix_len);
|
||||||
r += 40;
|
r += 40;
|
||||||
@ -648,7 +643,7 @@ static void INET6_displayroutes(void)
|
|||||||
//usage:#define route_trivial_usage
|
//usage:#define route_trivial_usage
|
||||||
///////: "[-ne]"IF_FEATURE_IPV6(" [-A inet[6]]")" [{add|del|delete} [-net|-host] TARGET [netmask MASK] [gw GATEWAY] [metric N] [mss BYTES] [window BYTES] [irtt MSEC] [reject] [mod] [dyn] [reinstate] [[dev] IFACE]]"
|
///////: "[-ne]"IF_FEATURE_IPV6(" [-A inet[6]]")" [{add|del|delete} [-net|-host] TARGET [netmask MASK] [gw GATEWAY] [metric N] [mss BYTES] [window BYTES] [irtt MSEC] [reject] [mod] [dyn] [reinstate] [[dev] IFACE]]"
|
||||||
///////too wordy
|
///////too wordy
|
||||||
//usage: "[-ne]"IF_FEATURE_IPV6(" [-A inet[6]]")" [{add|del} TARGET [netmask MASK]\n"
|
//usage: "[-ne]"IF_FEATURE_IPV6(" [-A inet[6]]")" [{add|del} [-net|-host] TARGET [netmask MASK]\n"
|
||||||
//usage: " [gw GATEWAY] [metric N] [mss BYTES] [window BYTES] [reject] [IFACE]]"
|
//usage: " [gw GATEWAY] [metric N] [mss BYTES] [window BYTES] [reject] [IFACE]]"
|
||||||
//usage:#define route_full_usage "\n\n"
|
//usage:#define route_full_usage "\n\n"
|
||||||
//usage: "Show or edit kernel routing tables\n"
|
//usage: "Show or edit kernel routing tables\n"
|
||||||
@ -661,13 +656,11 @@ static void INET6_displayroutes(void)
|
|||||||
#define ROUTE_OPT_e 0x04
|
#define ROUTE_OPT_e 0x04
|
||||||
#define ROUTE_OPT_INET6 0x08 /* Not an actual option. See below. */
|
#define ROUTE_OPT_INET6 0x08 /* Not an actual option. See below. */
|
||||||
|
|
||||||
/* 1st byte is offset to next entry offset. 2nd byte is return value. */
|
/* 1st byte is return value, matches RTACTION_* code */
|
||||||
/* 2nd byte matches RTACTION_* code */
|
|
||||||
static const char tbl_verb[] ALIGN1 =
|
static const char tbl_verb[] ALIGN1 =
|
||||||
"\006\001add\0"
|
"\001add\0"
|
||||||
"\006\002del\0"
|
"\002del\0"
|
||||||
/* "\011\002delete\0" */
|
"\002delete\0"
|
||||||
"\010\002delete" /* Since it's last, we can save a byte. */
|
|
||||||
;
|
;
|
||||||
|
|
||||||
int route_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
int route_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||||
|
Loading…
Reference in New Issue
Block a user