summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--networking/ip.c70
-rw-r--r--networking/libiproute/utils.h2
2 files changed, 49 insertions, 23 deletions
diff --git a/networking/ip.c b/networking/ip.c
index d51689542..dc9ca1f91 100644
--- a/networking/ip.c
+++ b/networking/ip.c
@@ -10,6 +10,7 @@
* Changes:
*
* Rani Assaf <rani@magic.metawire.com> 980929: resolve addresses
+ * Bernhard Fischer rewrote to use index_in_substr_array
*/
#include "busybox.h"
@@ -17,31 +18,56 @@
#include "libiproute/utils.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)
{
- ip_parse_common_args(&argc, &argv);
-
- if (argc <= 1)
- bb_show_usage();
+ 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;
- if (ENABLE_FEATURE_IP_ADDRESS && matches(argv[1], "address") == 0) {
- return do_ipaddr(argc-2, argv+2);
- }
- if (ENABLE_FEATURE_IP_ROUTE && matches(argv[1], "route") == 0) {
- 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);
+ ip_parse_common_args(&argc, &argv);
+ if (argc > 1) {
+ int key = index_in_substr_array(keywords, argv[1]);
+ argc -= 2;
+ argv += 2;
+#if ENABLE_FEATURE_IP_ADDRESS
+ 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
}
-
- bb_show_usage();
+ return (ip_func(argc, argv));
}
diff --git a/networking/libiproute/utils.h b/networking/libiproute/utils.h
index 27afb32ac..3b6fef1e3 100644
--- a/networking/libiproute/utils.h
+++ b/networking/libiproute/utils.h
@@ -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 duparg(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);
const char *dnet_ntop(int af, const void *addr, char *str, size_t len);