blob: 3ea1b62e175314306d439c360645d7be6be1b651 [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
Denis Vlasenko9b49a5e2007-10-11 10:05:36 +000041int ipaddr_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
Bernhard Reutner-Fischer07c394e2007-04-10 20:11:12 +000042int 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
Denis Vlasenko9b49a5e2007-10-11 10:05:36 +000049int iplink_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
Bernhard Reutner-Fischer07c394e2007-04-10 20:11:12 +000050int 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
Denis Vlasenko9b49a5e2007-10-11 10:05:36 +000057int iproute_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
Bernhard Reutner-Fischer07c394e2007-04-10 20:11:12 +000058int 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
Denis Vlasenko9b49a5e2007-10-11 10:05:36 +000065int iprule_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
Bernhard Reutner-Fischer07c394e2007-04-10 20:11:12 +000066int 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
Denis Vlasenko9b49a5e2007-10-11 10:05:36 +000073int iptunnel_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
Bernhard Reutner-Fischer07c394e2007-04-10 20:11:12 +000074int iptunnel_main(int argc, char **argv)
75{
76 ip_func = do_iptunnel;
77 return ip_do(argc, argv);
78}
79#endif
80
81
Denis Vlasenko9b49a5e2007-10-11 10:05:36 +000082int ip_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
Glenn L McGrathf112daa2002-12-01 23:04:06 +000083int ip_main(int argc, char **argv)
84{
Denis Vlasenko6ca409e2007-08-12 20:58:27 +000085 static const char keywords[] ALIGN1 =
Denis Vlasenko990d0f62007-07-24 15:54:42 +000086 USE_FEATURE_IP_ADDRESS("address\0")
87 USE_FEATURE_IP_ROUTE("route\0")
88 USE_FEATURE_IP_LINK("link\0")
89 USE_FEATURE_IP_TUNNEL("tunnel\0" "tunl\0")
90 USE_FEATURE_IP_RULE("rule\0")
91 ;
Bernhard Reutner-Fischere87d7952007-04-10 18:43:27 +000092 enum {
93 USE_FEATURE_IP_ADDRESS(IP_addr,)
94 USE_FEATURE_IP_ROUTE(IP_route,)
95 USE_FEATURE_IP_LINK(IP_link,)
96 USE_FEATURE_IP_TUNNEL(IP_tunnel, IP_tunl,)
97 USE_FEATURE_IP_RULE(IP_rule,)
98 IP_none
99 };
Bernhard Reutner-Fischere87d7952007-04-10 18:43:27 +0000100
Glenn L McGrathf112daa2002-12-01 23:04:06 +0000101 ip_parse_common_args(&argc, &argv);
Bernhard Reutner-Fischere87d7952007-04-10 18:43:27 +0000102 if (argc > 1) {
Denis Vlasenko990d0f62007-07-24 15:54:42 +0000103 int key = index_in_substrings(keywords, argv[1]);
Bernhard Reutner-Fischere87d7952007-04-10 18:43:27 +0000104 argc -= 2;
105 argv += 2;
106#if ENABLE_FEATURE_IP_ADDRESS
107 if (key == IP_addr)
108 ip_func = do_ipaddr;
109#endif
110#if ENABLE_FEATURE_IP_ROUTE
111 if (key == IP_route)
112 ip_func = do_iproute;
113#endif
114#if ENABLE_FEATURE_IP_LINK
115 if (key == IP_link)
116 ip_func = do_iplink;
117#endif
118#if ENABLE_FEATURE_IP_TUNNEL
119 if (key == IP_tunnel || key == IP_tunl)
120 ip_func = do_iptunnel;
121#endif
122#if ENABLE_FEATURE_IP_RULE
123 if (key == IP_rule)
124 ip_func = do_iprule;
125#endif
Glenn L McGrathf112daa2002-12-01 23:04:06 +0000126 }
Denis Vlasenko990d0f62007-07-24 15:54:42 +0000127 return ip_func(argc, argv);
Glenn L McGrath9a2d2722002-11-10 01:33:55 +0000128}
Denis Vlasenkod46e6d12007-05-17 12:58:30 +0000129
130#endif /* any of ENABLE_FEATURE_IP_xxx is 1 */