diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2020-12-19 00:03:38 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2020-12-19 00:07:13 +0100 |
commit | ddc6dfdb4d56009d16e1a1d7aef441dbe4315027 (patch) | |
tree | 29548646f8ed28b4434c17e2c19d7b91d6a07126 | |
parent | b164cdb854e6722ab39aa62dbfad84ea37a29a30 (diff) | |
download | busybox-w32-ddc6dfdb4d56009d16e1a1d7aef441dbe4315027.tar.gz busybox-w32-ddc6dfdb4d56009d16e1a1d7aef441dbe4315027.tar.bz2 busybox-w32-ddc6dfdb4d56009d16e1a1d7aef441dbe4315027.zip |
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>
-rw-r--r-- | networking/route.c | 59 |
1 files changed, 26 insertions, 33 deletions
diff --git a/networking/route.c b/networking/route.c index b08ab5c68..ff5daa8a7 100644 --- a/networking/route.c +++ b/networking/route.c | |||
@@ -75,17 +75,15 @@ | |||
75 | #define RTACTION_ADD 1 | 75 | #define RTACTION_ADD 1 |
76 | #define RTACTION_DEL 2 | 76 | #define RTACTION_DEL 2 |
77 | 77 | ||
78 | /* For the various tbl_*[] arrays, the 1st byte is the offset to | 78 | /* For the various tbl_*[] arrays, the 1st byte is return value. */ |
79 | * the next entry and the 2nd byte is return value. */ | ||
80 | 79 | ||
81 | #define NET_FLAG 1 | 80 | #define NET_FLAG 1 |
82 | #define HOST_FLAG 2 | 81 | #define HOST_FLAG 2 |
83 | 82 | ||
84 | /* We remap '-' to '#' to avoid problems with getopt. */ | 83 | /* We remap '-' to '#' to avoid problems with getopt. */ |
85 | static const char tbl_hash_net_host[] ALIGN1 = | 84 | static const char tbl_hash_net_host[] ALIGN1 = |
86 | "\007\001#net\0" | 85 | "\001#net\0" |
87 | /* "\010\002#host\0" */ | 86 | "\002#host\0" |
88 | "\007\002#host" /* Since last, we can save a byte. */ | ||
89 | ; | 87 | ; |
90 | 88 | ||
91 | #define KW_TAKES_ARG 020 | 89 | #define KW_TAKES_ARG 020 |
@@ -108,29 +106,28 @@ static const char tbl_hash_net_host[] ALIGN1 = | |||
108 | static const char tbl_ipvx[] ALIGN1 = | 106 | static const char tbl_ipvx[] ALIGN1 = |
109 | /* 020 is the "takes an arg" bit */ | 107 | /* 020 is the "takes an arg" bit */ |
110 | #if HAVE_NEW_ADDRT | 108 | #if HAVE_NEW_ADDRT |
111 | "\011\020metric\0" | 109 | "\020metric\0" |
112 | #endif | 110 | #endif |
113 | "\012\021netmask\0" | 111 | "\021netmask\0" |
114 | "\005\022gw\0" | 112 | "\022gw\0" |
115 | "\012\022gateway\0" | 113 | "\022gateway\0" |
116 | "\006\023mss\0" | 114 | "\023mss\0" |
117 | "\011\024window\0" | 115 | "\024window\0" |
118 | #ifdef RTF_IRTT | 116 | #ifdef RTF_IRTT |
119 | "\007\025irtt\0" | 117 | "\025irtt\0" |
120 | #endif | 118 | #endif |
121 | "\006\026dev\0" | 119 | "\026dev\0" |
122 | "\011\026device\0" | 120 | "\026device\0" |
123 | /* 040 is the "sets a flag" bit - MUST match flags_ipvx[] values below. */ | 121 | /* 040 is the "sets a flag" bit - MUST match flags_ipvx[] values below. */ |
124 | #ifdef RTF_REJECT | 122 | #ifdef RTF_REJECT |
125 | "\011\040reject\0" | 123 | "\040reject\0" |
126 | #endif | 124 | #endif |
127 | "\006\041mod\0" | 125 | "\041mod\0" |
128 | "\006\042dyn\0" | 126 | "\042dyn\0" |
129 | /* "\014\043reinstate\0" */ | 127 | "\043reinstate\0" |
130 | "\013\043reinstate" /* Since last, we can save a byte. */ | ||
131 | ; | 128 | ; |
132 | 129 | ||
133 | static const uint16_t flags_ipvx[] = { /* MUST match tbl_ipvx[] values above. */ | 130 | static const uint16_t flags_ipvx[] ALIGN2 = { /* MUST match tbl_ipvx[] values above. */ |
134 | #ifdef RTF_REJECT | 131 | #ifdef RTF_REJECT |
135 | RTF_REJECT, | 132 | RTF_REJECT, |
136 | #endif | 133 | #endif |
@@ -143,17 +140,17 @@ static int kw_lookup(const char *kwtbl, char ***pargs) | |||
143 | { | 140 | { |
144 | if (**pargs) { | 141 | if (**pargs) { |
145 | do { | 142 | do { |
146 | if (strcmp(kwtbl+2, **pargs) == 0) { /* Found a match. */ | 143 | if (strcmp(kwtbl + 1, **pargs) == 0) { /* Found a match. */ |
147 | *pargs += 1; | 144 | *pargs += 1; |
148 | if (kwtbl[1] & KW_TAKES_ARG) { | 145 | if (kwtbl[0] & KW_TAKES_ARG) { |
149 | if (!**pargs) { /* No more args! */ | 146 | if (!**pargs) { /* No more args! */ |
150 | bb_show_usage(); | 147 | bb_show_usage(); |
151 | } | 148 | } |
152 | *pargs += 1; /* Calling routine will use args[-1]. */ | 149 | *pargs += 1; /* Calling routine will use args[-1]. */ |
153 | } | 150 | } |
154 | return kwtbl[1]; | 151 | return kwtbl[0]; |
155 | } | 152 | } |
156 | kwtbl += *kwtbl; | 153 | kwtbl += strlen(kwtbl) + 1; |
157 | } while (*kwtbl); | 154 | } while (*kwtbl); |
158 | } | 155 | } |
159 | return 0; | 156 | return 0; |
@@ -536,7 +533,6 @@ void FAST_FUNC bb_displayroutes(int noresolve, int netstatfmt) | |||
536 | flags[0] = '!'; | 533 | flags[0] = '!'; |
537 | } | 534 | } |
538 | #endif | 535 | #endif |
539 | |||
540 | memset(&s_addr, 0, sizeof(struct sockaddr_in)); | 536 | memset(&s_addr, 0, sizeof(struct sockaddr_in)); |
541 | s_addr.sin_family = AF_INET; | 537 | s_addr.sin_family = AF_INET; |
542 | s_addr.sin_addr.s_addr = d; | 538 | s_addr.sin_addr.s_addr = d; |
@@ -626,7 +622,6 @@ static void INET6_displayroutes(void) | |||
626 | naddr6 = INET6_rresolve((struct sockaddr_in6 *) &snaddr6, | 622 | naddr6 = INET6_rresolve((struct sockaddr_in6 *) &snaddr6, |
627 | 0x0fff /* Apparently, upstream never resolves. */ | 623 | 0x0fff /* Apparently, upstream never resolves. */ |
628 | ); | 624 | ); |
629 | |||
630 | if (!r) { /* 1st pass */ | 625 | if (!r) { /* 1st pass */ |
631 | snprintf(addr6, sizeof(addr6), "%s/%d", naddr6, prefix_len); | 626 | snprintf(addr6, sizeof(addr6), "%s/%d", naddr6, prefix_len); |
632 | r += 40; | 627 | r += 40; |
@@ -648,7 +643,7 @@ static void INET6_displayroutes(void) | |||
648 | //usage:#define route_trivial_usage | 643 | //usage:#define route_trivial_usage |
649 | ///////: "[-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]]" | 644 | ///////: "[-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]]" |
650 | ///////too wordy | 645 | ///////too wordy |
651 | //usage: "[-ne]"IF_FEATURE_IPV6(" [-A inet[6]]")" [{add|del} TARGET [netmask MASK]\n" | 646 | //usage: "[-ne]"IF_FEATURE_IPV6(" [-A inet[6]]")" [{add|del} [-net|-host] TARGET [netmask MASK]\n" |
652 | //usage: " [gw GATEWAY] [metric N] [mss BYTES] [window BYTES] [reject] [IFACE]]" | 647 | //usage: " [gw GATEWAY] [metric N] [mss BYTES] [window BYTES] [reject] [IFACE]]" |
653 | //usage:#define route_full_usage "\n\n" | 648 | //usage:#define route_full_usage "\n\n" |
654 | //usage: "Show or edit kernel routing tables\n" | 649 | //usage: "Show or edit kernel routing tables\n" |
@@ -661,13 +656,11 @@ static void INET6_displayroutes(void) | |||
661 | #define ROUTE_OPT_e 0x04 | 656 | #define ROUTE_OPT_e 0x04 |
662 | #define ROUTE_OPT_INET6 0x08 /* Not an actual option. See below. */ | 657 | #define ROUTE_OPT_INET6 0x08 /* Not an actual option. See below. */ |
663 | 658 | ||
664 | /* 1st byte is offset to next entry offset. 2nd byte is return value. */ | 659 | /* 1st byte is return value, matches RTACTION_* code */ |
665 | /* 2nd byte matches RTACTION_* code */ | ||
666 | static const char tbl_verb[] ALIGN1 = | 660 | static const char tbl_verb[] ALIGN1 = |
667 | "\006\001add\0" | 661 | "\001add\0" |
668 | "\006\002del\0" | 662 | "\002del\0" |
669 | /* "\011\002delete\0" */ | 663 | "\002delete\0" |
670 | "\010\002delete" /* Since it's last, we can save a byte. */ | ||
671 | ; | 664 | ; |
672 | 665 | ||
673 | int route_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | 666 | int route_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |