- rewrite the ip applet to be less bloaty
[oweals/busybox.git] / networking / ip.c
1 /* vi: set sw=4 ts=4: */
2 /*
3  * ip.c         "ip" utility frontend.
4  *
5  * Licensed under the GPL v2 or later, see the file LICENSE in this tarball.
6  *
7  * Authors:     Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru>
8  *
9  *
10  * Changes:
11  *
12  * Rani Assaf <rani@magic.metawire.com> 980929: resolve addresses
13  * Bernhard Fischer rewrote to use index_in_substr_array
14  */
15
16 #include "busybox.h"
17
18 #include "libiproute/utils.h"
19 #include "libiproute/ip_common.h"
20
21 static int ATTRIBUTE_NORETURN ip_print_help(int ATTRIBUTE_UNUSED ac, char ATTRIBUTE_UNUSED **av)
22 {
23         bb_show_usage();
24 }
25 int ip_main(int argc, char **argv);
26 int ip_main(int argc, char **argv)
27 {
28         const char * const keywords[] = {
29                 USE_FEATURE_IP_ADDRESS("address",)
30                 USE_FEATURE_IP_ROUTE("route",)
31                 USE_FEATURE_IP_LINK("link",)
32                 USE_FEATURE_IP_TUNNEL("tunnel", "tunl",)
33                 USE_FEATURE_IP_RULE("rule",)
34                 NULL
35         };
36         enum {
37                 USE_FEATURE_IP_ADDRESS(IP_addr,)
38                 USE_FEATURE_IP_ROUTE(IP_route,)
39                 USE_FEATURE_IP_LINK(IP_link,)
40                 USE_FEATURE_IP_TUNNEL(IP_tunnel, IP_tunl,)
41                 USE_FEATURE_IP_RULE(IP_rule,)
42                 IP_none
43         };
44         int (*ip_func)(int argc, char **argv) = ip_print_help;
45
46         ip_parse_common_args(&argc, &argv);
47         if (argc > 1) {
48                 int key = index_in_substr_array(keywords, argv[1]);
49                 argc -= 2;
50                 argv += 2;
51 #if ENABLE_FEATURE_IP_ADDRESS
52                 if (key == IP_addr)
53                         ip_func = do_ipaddr;
54 #endif
55 #if ENABLE_FEATURE_IP_ROUTE
56                 if (key == IP_route)
57                         ip_func = do_iproute;
58 #endif
59 #if ENABLE_FEATURE_IP_LINK
60                 if (key == IP_link)
61                         ip_func = do_iplink;
62 #endif
63 #if ENABLE_FEATURE_IP_TUNNEL
64                 if (key == IP_tunnel || key == IP_tunl)
65                         ip_func = do_iptunnel;
66 #endif
67 #if ENABLE_FEATURE_IP_RULE
68                 if (key == IP_rule)
69                         ip_func = do_iprule;
70 #endif
71         }
72         return (ip_func(argc, argv));
73 }