blob: 350656cef76d8a658bac0ed172ba75a203348ff0 [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/*
Denys Vlasenko0ef64bd2010-08-16 20:14:46 +02003 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
Glenn L McGrath9a2d2722002-11-10 01:33:55 +00004 *
Denys Vlasenkoe0a62202010-07-24 23:26:58 +02005 * Authors: Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru>
Glenn L McGrath9a2d2722002-11-10 01:33:55 +00006 *
7 * Changes:
Denys Vlasenkofb132e42010-10-29 11:46:52 +02008 * Rani Assaf <rani@magic.metawire.com> 980929: resolve addresses
Bernhard Reutner-Fischer6c4dade2008-09-25 12:13:34 +00009 * Bernhard Reutner-Fischer rewrote to use index_in_substr_array
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000010 */
11
Denis Vlasenkob6adbf12007-05-26 19:00:18 +000012#include "libbb.h"
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000013
Bernhard Reutner-Fischerab187822005-10-26 10:47:26 +000014#include "libiproute/utils.h"
15#include "libiproute/ip_common.h"
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000016
Denis Vlasenkod46e6d12007-05-17 12:58:30 +000017#if ENABLE_FEATURE_IP_ADDRESS \
18 || ENABLE_FEATURE_IP_ROUTE \
19 || ENABLE_FEATURE_IP_LINK \
20 || ENABLE_FEATURE_IP_TUNNEL \
21 || ENABLE_FEATURE_IP_RULE
22
Denys Vlasenko2e9b5512010-07-24 23:27:38 +020023static int FAST_FUNC ip_print_help(char **argv UNUSED_PARAM)
Bernhard Reutner-Fischere87d7952007-04-10 18:43:27 +000024{
25 bb_show_usage();
26}
Bernhard Reutner-Fischer07c394e2007-04-10 20:11:12 +000027
Denys Vlasenko2e9b5512010-07-24 23:27:38 +020028typedef int FAST_FUNC (*ip_func_ptr_t)(char**);
Denys Vlasenkoe0a62202010-07-24 23:26:58 +020029
30static int ip_do(ip_func_ptr_t ip_func, char **argv)
Bernhard Reutner-Fischer07c394e2007-04-10 20:11:12 +000031{
Denis Vlasenko3246c0d2008-12-04 12:15:19 +000032 argv = ip_parse_common_args(argv + 1);
Denis Vlasenkoed6a49c2007-11-18 22:56:25 +000033 return ip_func(argv);
Bernhard Reutner-Fischer07c394e2007-04-10 20:11:12 +000034}
35
36#if ENABLE_FEATURE_IP_ADDRESS
Denis Vlasenko9b49a5e2007-10-11 10:05:36 +000037int ipaddr_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
Denis Vlasenkoa60f84e2008-07-05 09:18:54 +000038int ipaddr_main(int argc UNUSED_PARAM, char **argv)
Bernhard Reutner-Fischer07c394e2007-04-10 20:11:12 +000039{
Denis Vlasenko2570b2e2008-03-28 01:00:09 +000040 return ip_do(do_ipaddr, argv);
Bernhard Reutner-Fischer07c394e2007-04-10 20:11:12 +000041}
42#endif
43#if ENABLE_FEATURE_IP_LINK
Denis Vlasenko9b49a5e2007-10-11 10:05:36 +000044int iplink_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
Denis Vlasenkoa60f84e2008-07-05 09:18:54 +000045int iplink_main(int argc UNUSED_PARAM, char **argv)
Bernhard Reutner-Fischer07c394e2007-04-10 20:11:12 +000046{
Denis Vlasenko2570b2e2008-03-28 01:00:09 +000047 return ip_do(do_iplink, argv);
Bernhard Reutner-Fischer07c394e2007-04-10 20:11:12 +000048}
49#endif
50#if ENABLE_FEATURE_IP_ROUTE
Denis Vlasenko9b49a5e2007-10-11 10:05:36 +000051int iproute_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
Denis Vlasenkoa60f84e2008-07-05 09:18:54 +000052int iproute_main(int argc UNUSED_PARAM, char **argv)
Bernhard Reutner-Fischer07c394e2007-04-10 20:11:12 +000053{
Denis Vlasenko2570b2e2008-03-28 01:00:09 +000054 return ip_do(do_iproute, argv);
Bernhard Reutner-Fischer07c394e2007-04-10 20:11:12 +000055}
56#endif
57#if ENABLE_FEATURE_IP_RULE
Denis Vlasenko9b49a5e2007-10-11 10:05:36 +000058int iprule_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
Denis Vlasenkoa60f84e2008-07-05 09:18:54 +000059int iprule_main(int argc UNUSED_PARAM, char **argv)
Bernhard Reutner-Fischer07c394e2007-04-10 20:11:12 +000060{
Denis Vlasenko2570b2e2008-03-28 01:00:09 +000061 return ip_do(do_iprule, argv);
Bernhard Reutner-Fischer07c394e2007-04-10 20:11:12 +000062}
63#endif
64#if ENABLE_FEATURE_IP_TUNNEL
Denis Vlasenko9b49a5e2007-10-11 10:05:36 +000065int iptunnel_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
Denis Vlasenkoa60f84e2008-07-05 09:18:54 +000066int iptunnel_main(int argc UNUSED_PARAM, char **argv)
Bernhard Reutner-Fischer07c394e2007-04-10 20:11:12 +000067{
Denis Vlasenko2570b2e2008-03-28 01:00:09 +000068 return ip_do(do_iptunnel, argv);
Bernhard Reutner-Fischer07c394e2007-04-10 20:11:12 +000069}
70#endif
71
72
Denis Vlasenko9b49a5e2007-10-11 10:05:36 +000073int ip_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
Denis Vlasenkoa60f84e2008-07-05 09:18:54 +000074int ip_main(int argc UNUSED_PARAM, char **argv)
Glenn L McGrathf112daa2002-12-01 23:04:06 +000075{
Denis Vlasenko6ca409e2007-08-12 20:58:27 +000076 static const char keywords[] ALIGN1 =
Denis Vlasenko5e34ff22009-04-21 11:09:40 +000077 IF_FEATURE_IP_ADDRESS("address\0")
78 IF_FEATURE_IP_ROUTE("route\0")
Denys Vlasenkoe0a62202010-07-24 23:26:58 +020079 IF_FEATURE_IP_ROUTE("r\0")
Denis Vlasenko5e34ff22009-04-21 11:09:40 +000080 IF_FEATURE_IP_LINK("link\0")
Denys Vlasenkoe0a62202010-07-24 23:26:58 +020081 IF_FEATURE_IP_TUNNEL("tunnel\0")
82 IF_FEATURE_IP_TUNNEL("tunl\0")
Denis Vlasenko5e34ff22009-04-21 11:09:40 +000083 IF_FEATURE_IP_RULE("rule\0")
Denis Vlasenko990d0f62007-07-24 15:54:42 +000084 ;
Denys Vlasenkoe0a62202010-07-24 23:26:58 +020085 static const ip_func_ptr_t ip_func_ptrs[] = {
86 ip_print_help,
87 IF_FEATURE_IP_ADDRESS(do_ipaddr,)
88 IF_FEATURE_IP_ROUTE(do_iproute,)
89 IF_FEATURE_IP_ROUTE(do_iproute,)
90 IF_FEATURE_IP_LINK(do_iplink,)
91 IF_FEATURE_IP_TUNNEL(do_iptunnel,)
92 IF_FEATURE_IP_TUNNEL(do_iptunnel,)
93 IF_FEATURE_IP_RULE(do_iprule,)
Bernhard Reutner-Fischere87d7952007-04-10 18:43:27 +000094 };
Denys Vlasenkoe0a62202010-07-24 23:26:58 +020095 ip_func_ptr_t ip_func;
96 int key;
Bernhard Reutner-Fischere87d7952007-04-10 18:43:27 +000097
Denis Vlasenkoed6a49c2007-11-18 22:56:25 +000098 argv = ip_parse_common_args(argv + 1);
Denys Vlasenkoe0a62202010-07-24 23:26:58 +020099 key = *argv ? index_in_substrings(keywords, *argv++) : -1;
100 ip_func = ip_func_ptrs[key + 1];
101
Denis Vlasenkoed6a49c2007-11-18 22:56:25 +0000102 return ip_func(argv);
Glenn L McGrath9a2d2722002-11-10 01:33:55 +0000103}
Denis Vlasenkod46e6d12007-05-17 12:58:30 +0000104
105#endif /* any of ENABLE_FEATURE_IP_xxx is 1 */