1 /* vi: set sw=4 ts=4: */
3 * ip.c "ip" utility frontend.
5 * Licensed under the GPL v2 or later, see the file LICENSE in this tarball.
7 * Authors: Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru>
12 * Rani Assaf <rani@magic.metawire.com> 980929: resolve addresses
13 * Bernhard Reutner-Fischer rewrote to use index_in_substr_array
18 #include "libiproute/utils.h"
19 #include "libiproute/ip_common.h"
21 #if ENABLE_FEATURE_IP_ADDRESS \
22 || ENABLE_FEATURE_IP_ROUTE \
23 || ENABLE_FEATURE_IP_LINK \
24 || ENABLE_FEATURE_IP_TUNNEL \
25 || ENABLE_FEATURE_IP_RULE
27 static int NORETURN ip_print_help(char **argv UNUSED_PARAM)
32 static int ip_do(int (*ip_func)(char **argv), char **argv)
34 argv = ip_parse_common_args(argv + 1);
38 #if ENABLE_FEATURE_IP_ADDRESS
39 int ipaddr_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
40 int ipaddr_main(int argc UNUSED_PARAM, char **argv)
42 return ip_do(do_ipaddr, argv);
45 #if ENABLE_FEATURE_IP_LINK
46 int iplink_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
47 int iplink_main(int argc UNUSED_PARAM, char **argv)
49 return ip_do(do_iplink, argv);
52 #if ENABLE_FEATURE_IP_ROUTE
53 int iproute_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
54 int iproute_main(int argc UNUSED_PARAM, char **argv)
56 return ip_do(do_iproute, argv);
59 #if ENABLE_FEATURE_IP_RULE
60 int iprule_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
61 int iprule_main(int argc UNUSED_PARAM, char **argv)
63 return ip_do(do_iprule, argv);
66 #if ENABLE_FEATURE_IP_TUNNEL
67 int iptunnel_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
68 int iptunnel_main(int argc UNUSED_PARAM, char **argv)
70 return ip_do(do_iptunnel, argv);
75 int ip_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
76 int ip_main(int argc UNUSED_PARAM, char **argv)
78 static const char keywords[] ALIGN1 =
79 USE_FEATURE_IP_ADDRESS("address\0")
80 USE_FEATURE_IP_ROUTE("route\0")
81 USE_FEATURE_IP_LINK("link\0")
82 USE_FEATURE_IP_TUNNEL("tunnel\0" "tunl\0")
83 USE_FEATURE_IP_RULE("rule\0")
86 USE_FEATURE_IP_ADDRESS(IP_addr,)
87 USE_FEATURE_IP_ROUTE(IP_route,)
88 USE_FEATURE_IP_LINK(IP_link,)
89 USE_FEATURE_IP_TUNNEL(IP_tunnel, IP_tunl,)
90 USE_FEATURE_IP_RULE(IP_rule,)
93 int (*ip_func)(char**) = ip_print_help;
95 argv = ip_parse_common_args(argv + 1);
97 int key = index_in_substrings(keywords, *argv);
99 #if ENABLE_FEATURE_IP_ADDRESS
103 #if ENABLE_FEATURE_IP_ROUTE
105 ip_func = do_iproute;
107 #if ENABLE_FEATURE_IP_LINK
111 #if ENABLE_FEATURE_IP_TUNNEL
112 if (key == IP_tunnel || key == IP_tunl)
113 ip_func = do_iptunnel;
115 #if ENABLE_FEATURE_IP_RULE
120 return ip_func(argv);
123 #endif /* any of ENABLE_FEATURE_IP_xxx is 1 */