blob: 0105bd98b246fc8265832522e00710f2699aa922 [file] [log] [blame]
"Robert P. J. Day"63fc1a92006-07-02 19:47:05 +00001/* vi: set sw=4 ts=4: */
Glenn L McGrath9a2d2722002-11-10 01:33:55 +00002/*
3 * ip.c "ip" utility frontend.
4 *
Bernhard Reutner-Fischerab187822005-10-26 10:47:26 +00005 * Licensed under the GPL v2 or later, see the file LICENSE in this tarball.
Glenn L McGrath9a2d2722002-11-10 01:33:55 +00006 *
7 * Authors: Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru>
8 *
9 *
10 * Changes:
11 *
12 * Rani Assaf <rani@magic.metawire.com> 980929: resolve addresses
Bernhard Reutner-Fischere87d7952007-04-10 18:43:27 +000013 * Bernhard Fischer rewrote to use index_in_substr_array
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000014 */
15
Denis Vlasenkob6adbf12007-05-26 19:00:18 +000016#include "libbb.h"
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000017
Bernhard Reutner-Fischerab187822005-10-26 10:47:26 +000018#include "libiproute/utils.h"
19#include "libiproute/ip_common.h"
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000020
Denis Vlasenkod46e6d12007-05-17 12:58:30 +000021#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
26
Bernhard Reutner-Fischere87d7952007-04-10 18:43:27 +000027static int ATTRIBUTE_NORETURN ip_print_help(int ATTRIBUTE_UNUSED ac, char ATTRIBUTE_UNUSED **av)
28{
29 bb_show_usage();
30}
Bernhard Reutner-Fischer07c394e2007-04-10 20:11:12 +000031
32static int (*ip_func)(int argc, char **argv) = ip_print_help;
33
34static int ip_do(int argc, char **argv)
35{
36 ip_parse_common_args(&argc, &argv);
37 return ip_func(argc-1, argv+1);
38}
39
40#if ENABLE_FEATURE_IP_ADDRESS
41int ipaddr_main(int argc, char **argv);
42int ipaddr_main(int argc, char **argv)
43{
44 ip_func = do_ipaddr;
45 return ip_do(argc, argv);
46}
47#endif
48#if ENABLE_FEATURE_IP_LINK
49int iplink_main(int argc, char **argv);
50int iplink_main(int argc, char **argv)
51{
52 ip_func = do_iplink;
53 return ip_do(argc, argv);
54}
55#endif
56#if ENABLE_FEATURE_IP_ROUTE
57int iproute_main(int argc, char **argv);
58int iproute_main(int argc, char **argv)
59{
60 ip_func = do_iproute;
61 return ip_do(argc, argv);
62}
63#endif
64#if ENABLE_FEATURE_IP_RULE
65int iprule_main(int argc, char **argv);
66int iprule_main(int argc, char **argv)
67{
68 ip_func = do_iprule;
69 return ip_do(argc, argv);
70}
71#endif
72#if ENABLE_FEATURE_IP_TUNNEL
73int iptunnel_main(int argc, char **argv);
74int iptunnel_main(int argc, char **argv)
75{
76 ip_func = do_iptunnel;
77 return ip_do(argc, argv);
78}
79#endif
80
81
Denis Vlasenko06af2162007-02-03 17:28:39 +000082int ip_main(int argc, char **argv);
Glenn L McGrathf112daa2002-12-01 23:04:06 +000083int ip_main(int argc, char **argv)
84{
Bernhard Reutner-Fischere87d7952007-04-10 18:43:27 +000085 const char * const keywords[] = {
86 USE_FEATURE_IP_ADDRESS("address",)
87 USE_FEATURE_IP_ROUTE("route",)
88 USE_FEATURE_IP_LINK("link",)
89 USE_FEATURE_IP_TUNNEL("tunnel", "tunl",)
90 USE_FEATURE_IP_RULE("rule",)
91 NULL
92 };
93 enum {
94 USE_FEATURE_IP_ADDRESS(IP_addr,)
95 USE_FEATURE_IP_ROUTE(IP_route,)
96 USE_FEATURE_IP_LINK(IP_link,)
97 USE_FEATURE_IP_TUNNEL(IP_tunnel, IP_tunl,)
98 USE_FEATURE_IP_RULE(IP_rule,)
99 IP_none
100 };
Bernhard Reutner-Fischere87d7952007-04-10 18:43:27 +0000101
Glenn L McGrathf112daa2002-12-01 23:04:06 +0000102 ip_parse_common_args(&argc, &argv);
Bernhard Reutner-Fischere87d7952007-04-10 18:43:27 +0000103 if (argc > 1) {
104 int key = index_in_substr_array(keywords, argv[1]);
105 argc -= 2;
106 argv += 2;
107#if ENABLE_FEATURE_IP_ADDRESS
108 if (key == IP_addr)
109 ip_func = do_ipaddr;
110#endif
111#if ENABLE_FEATURE_IP_ROUTE
112 if (key == IP_route)
113 ip_func = do_iproute;
114#endif
115#if ENABLE_FEATURE_IP_LINK
116 if (key == IP_link)
117 ip_func = do_iplink;
118#endif
119#if ENABLE_FEATURE_IP_TUNNEL
120 if (key == IP_tunnel || key == IP_tunl)
121 ip_func = do_iptunnel;
122#endif
123#if ENABLE_FEATURE_IP_RULE
124 if (key == IP_rule)
125 ip_func = do_iprule;
126#endif
Glenn L McGrathf112daa2002-12-01 23:04:06 +0000127 }
Bernhard Reutner-Fischere87d7952007-04-10 18:43:27 +0000128 return (ip_func(argc, argv));
Glenn L McGrath9a2d2722002-11-10 01:33:55 +0000129}
Denis Vlasenkod46e6d12007-05-17 12:58:30 +0000130
131#endif /* any of ENABLE_FEATURE_IP_xxx is 1 */