svn commit: trunk/busybox/networking: libiproute

aldot at busybox.net aldot at busybox.net
Tue Apr 10 18:43:27 UTC 2007


Author: aldot
Date: 2007-04-10 11:43:27 -0700 (Tue, 10 Apr 2007)
New Revision: 18387

Log:
- 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.


Modified:
   trunk/busybox/networking/ip.c
   trunk/busybox/networking/libiproute/utils.h


Changeset:
Modified: trunk/busybox/networking/ip.c
===================================================================
--- trunk/busybox/networking/ip.c	2007-04-10 18:40:05 UTC (rev 18386)
+++ trunk/busybox/networking/ip.c	2007-04-10 18:43:27 UTC (rev 18387)
@@ -10,6 +10,7 @@
  * Changes:
  *
  * Rani Assaf <rani at 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)
 {
+	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);
-
-	if (argc <= 1)
-		bb_show_usage();
-
-	if (ENABLE_FEATURE_IP_ADDRESS && matches(argv[1], "address") == 0) {
-		return do_ipaddr(argc-2, argv+2);
+	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
 	}
-	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);
-	}
-
-	bb_show_usage();
+	return (ip_func(argc, argv));
 }

Modified: trunk/busybox/networking/libiproute/utils.h
===================================================================
--- trunk/busybox/networking/libiproute/utils.h	2007-04-10 18:40:05 UTC (rev 18386)
+++ trunk/busybox/networking/libiproute/utils.h	2007-04-10 18:43:27 UTC (rev 18387)
@@ -78,7 +78,7 @@
 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);




More information about the busybox-cvs mailing list