- rewrite the ip applet to be less bloaty

- mark libiproute's matches() as deprecated. Convert to index_in_(sub)str_array()!
   text    data     bss     dec     hex filename
    314       0       0     314     13a ip.o.orig
    200       0       0     200      c8 ip.o
Using a smallint for the key would save another byte.
This commit is contained in:
Bernhard Reutner-Fischer
2007-04-10 18:43:27 +00:00
parent 51f7ab6162
commit e87d7955f8
2 changed files with 49 additions and 23 deletions

View File

@ -10,6 +10,7 @@
* Changes: * Changes:
* *
* Rani Assaf <rani@magic.metawire.com> 980929: resolve addresses * Rani Assaf <rani@magic.metawire.com> 980929: resolve addresses
* Bernhard Fischer rewrote to use index_in_substr_array
*/ */
#include "busybox.h" #include "busybox.h"
@ -17,31 +18,56 @@
#include "libiproute/utils.h" #include "libiproute/utils.h"
#include "libiproute/ip_common.h" #include "libiproute/ip_common.h"
static int ATTRIBUTE_NORETURN ip_print_help(int ATTRIBUTE_UNUSED ac, char ATTRIBUTE_UNUSED **av)
{
bb_show_usage();
}
int ip_main(int argc, char **argv); int ip_main(int argc, char **argv);
int ip_main(int argc, char **argv) int ip_main(int argc, char **argv)
{ {
const char * const keywords[] = {
USE_FEATURE_IP_ADDRESS("address",)
USE_FEATURE_IP_ROUTE("route",)
USE_FEATURE_IP_LINK("link",)
USE_FEATURE_IP_TUNNEL("tunnel", "tunl",)
USE_FEATURE_IP_RULE("rule",)
NULL
};
enum {
USE_FEATURE_IP_ADDRESS(IP_addr,)
USE_FEATURE_IP_ROUTE(IP_route,)
USE_FEATURE_IP_LINK(IP_link,)
USE_FEATURE_IP_TUNNEL(IP_tunnel, IP_tunl,)
USE_FEATURE_IP_RULE(IP_rule,)
IP_none
};
int (*ip_func)(int argc, char **argv) = ip_print_help;
ip_parse_common_args(&argc, &argv); ip_parse_common_args(&argc, &argv);
if (argc > 1) {
if (argc <= 1) int key = index_in_substr_array(keywords, argv[1]);
bb_show_usage(); argc -= 2;
argv += 2;
if (ENABLE_FEATURE_IP_ADDRESS && matches(argv[1], "address") == 0) { #if ENABLE_FEATURE_IP_ADDRESS
return do_ipaddr(argc-2, argv+2); if (key == IP_addr)
ip_func = do_ipaddr;
#endif
#if ENABLE_FEATURE_IP_ROUTE
if (key == IP_route)
ip_func = do_iproute;
#endif
#if ENABLE_FEATURE_IP_LINK
if (key == IP_link)
ip_func = do_iplink;
#endif
#if ENABLE_FEATURE_IP_TUNNEL
if (key == IP_tunnel || key == IP_tunl)
ip_func = do_iptunnel;
#endif
#if ENABLE_FEATURE_IP_RULE
if (key == IP_rule)
ip_func = do_iprule;
#endif
} }
if (ENABLE_FEATURE_IP_ROUTE && matches(argv[1], "route") == 0) { return (ip_func(argc, argv));
return do_iproute(argc-2, argv+2);
}
if (ENABLE_FEATURE_IP_LINK && matches(argv[1], "link") == 0) {
return do_iplink(argc-2, argv+2);
}
if (ENABLE_FEATURE_IP_TUNNEL
&& (matches(argv[1], "tunnel") == 0 || strcmp(argv[1], "tunl") == 0)
) {
return do_iptunnel(argc-2, argv+2);
}
if (ENABLE_FEATURE_IP_RULE && matches(argv[1], "rule") == 0) {
return do_iprule(argc-2, argv+2);
}
bb_show_usage();
} }

View File

@ -78,7 +78,7 @@ extern const char *rt_addr_n2a(int af, int len, void *addr, char *buf, int bufle
void invarg(const char *, const char *) ATTRIBUTE_NORETURN; void invarg(const char *, const char *) ATTRIBUTE_NORETURN;
void duparg(const char *, const char *) ATTRIBUTE_NORETURN; void duparg(const char *, const char *) ATTRIBUTE_NORETURN;
void duparg2(const char *, const char *) ATTRIBUTE_NORETURN; void duparg2(const char *, const char *) ATTRIBUTE_NORETURN;
int matches(const char *arg, const char *pattern); int ATTRIBUTE_DEPRECATED matches(const char *arg, const char *pattern);
int inet_addr_match(inet_prefix *a, inet_prefix *b, int bits); int inet_addr_match(inet_prefix *a, inet_prefix *b, int bits);
const char *dnet_ntop(int af, const void *addr, char *str, size_t len); const char *dnet_ntop(int af, const void *addr, char *str, size_t len);