blob: 0042896676fee6e94665b15d8e40c134cf7f5973 [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 Vlasenkoe0a62202010-07-24 23:26:58 +02003 * "ip" utility frontend.
Glenn L McGrath9a2d2722002-11-10 01:33:55 +00004 *
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 *
Denys Vlasenkoe0a62202010-07-24 23:26:58 +02007 * Authors: Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru>
Glenn L McGrath9a2d2722002-11-10 01:33:55 +00008 *
9 * Changes:
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000010 * Rani Assaf <rani@magic.metawire.com> 980929: resolve addresses
Bernhard Reutner-Fischer6c4dade2008-09-25 12:13:34 +000011 * Bernhard Reutner-Fischer rewrote to use index_in_substr_array
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000012 */
13
Denis Vlasenkob6adbf12007-05-26 19:00:18 +000014#include "libbb.h"
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000015
Bernhard Reutner-Fischerab187822005-10-26 10:47:26 +000016#include "libiproute/utils.h"
17#include "libiproute/ip_common.h"
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000018
Denis Vlasenkod46e6d12007-05-17 12:58:30 +000019#if ENABLE_FEATURE_IP_ADDRESS \
20 || ENABLE_FEATURE_IP_ROUTE \
21 || ENABLE_FEATURE_IP_LINK \
22 || ENABLE_FEATURE_IP_TUNNEL \
23 || ENABLE_FEATURE_IP_RULE
24
Denys Vlasenko2e9b5512010-07-24 23:27:38 +020025static int FAST_FUNC ip_print_help(char **argv UNUSED_PARAM)
Bernhard Reutner-Fischere87d7952007-04-10 18:43:27 +000026{
27 bb_show_usage();
28}
Bernhard Reutner-Fischer07c394e2007-04-10 20:11:12 +000029
Denys Vlasenko2e9b5512010-07-24 23:27:38 +020030typedef int FAST_FUNC (*ip_func_ptr_t)(char**);
Denys Vlasenkoe0a62202010-07-24 23:26:58 +020031
32static int ip_do(ip_func_ptr_t ip_func, char **argv)
Bernhard Reutner-Fischer07c394e2007-04-10 20:11:12 +000033{
Denis Vlasenko3246c0d2008-12-04 12:15:19 +000034 argv = ip_parse_common_args(argv + 1);
Denis Vlasenkoed6a49c2007-11-18 22:56:25 +000035 return ip_func(argv);
Bernhard Reutner-Fischer07c394e2007-04-10 20:11:12 +000036}
37
38#if ENABLE_FEATURE_IP_ADDRESS
Denis Vlasenko9b49a5e2007-10-11 10:05:36 +000039int ipaddr_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
Denis Vlasenkoa60f84e2008-07-05 09:18:54 +000040int ipaddr_main(int argc UNUSED_PARAM, char **argv)
Bernhard Reutner-Fischer07c394e2007-04-10 20:11:12 +000041{
Denis Vlasenko2570b2e2008-03-28 01:00:09 +000042 return ip_do(do_ipaddr, argv);
Bernhard Reutner-Fischer07c394e2007-04-10 20:11:12 +000043}
44#endif
45#if ENABLE_FEATURE_IP_LINK
Denis Vlasenko9b49a5e2007-10-11 10:05:36 +000046int iplink_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
Denis Vlasenkoa60f84e2008-07-05 09:18:54 +000047int iplink_main(int argc UNUSED_PARAM, char **argv)
Bernhard Reutner-Fischer07c394e2007-04-10 20:11:12 +000048{
Denis Vlasenko2570b2e2008-03-28 01:00:09 +000049 return ip_do(do_iplink, argv);
Bernhard Reutner-Fischer07c394e2007-04-10 20:11:12 +000050}
51#endif
52#if ENABLE_FEATURE_IP_ROUTE
Denis Vlasenko9b49a5e2007-10-11 10:05:36 +000053int iproute_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
Denis Vlasenkoa60f84e2008-07-05 09:18:54 +000054int iproute_main(int argc UNUSED_PARAM, char **argv)
Bernhard Reutner-Fischer07c394e2007-04-10 20:11:12 +000055{
Denis Vlasenko2570b2e2008-03-28 01:00:09 +000056 return ip_do(do_iproute, argv);
Bernhard Reutner-Fischer07c394e2007-04-10 20:11:12 +000057}
58#endif
59#if ENABLE_FEATURE_IP_RULE
Denis Vlasenko9b49a5e2007-10-11 10:05:36 +000060int iprule_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
Denis Vlasenkoa60f84e2008-07-05 09:18:54 +000061int iprule_main(int argc UNUSED_PARAM, char **argv)
Bernhard Reutner-Fischer07c394e2007-04-10 20:11:12 +000062{
Denis Vlasenko2570b2e2008-03-28 01:00:09 +000063 return ip_do(do_iprule, argv);
Bernhard Reutner-Fischer07c394e2007-04-10 20:11:12 +000064}
65#endif
66#if ENABLE_FEATURE_IP_TUNNEL
Denis Vlasenko9b49a5e2007-10-11 10:05:36 +000067int iptunnel_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
Denis Vlasenkoa60f84e2008-07-05 09:18:54 +000068int iptunnel_main(int argc UNUSED_PARAM, char **argv)
Bernhard Reutner-Fischer07c394e2007-04-10 20:11:12 +000069{
Denis Vlasenko2570b2e2008-03-28 01:00:09 +000070 return ip_do(do_iptunnel, argv);
Bernhard Reutner-Fischer07c394e2007-04-10 20:11:12 +000071}
72#endif
73
74
Denis Vlasenko9b49a5e2007-10-11 10:05:36 +000075int ip_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
Denis Vlasenkoa60f84e2008-07-05 09:18:54 +000076int ip_main(int argc UNUSED_PARAM, char **argv)
Glenn L McGrathf112daa2002-12-01 23:04:06 +000077{
Denis Vlasenko6ca409e2007-08-12 20:58:27 +000078 static const char keywords[] ALIGN1 =
Denis Vlasenko5e34ff22009-04-21 11:09:40 +000079 IF_FEATURE_IP_ADDRESS("address\0")
80 IF_FEATURE_IP_ROUTE("route\0")
Denys Vlasenkoe0a62202010-07-24 23:26:58 +020081 IF_FEATURE_IP_ROUTE("r\0")
Denis Vlasenko5e34ff22009-04-21 11:09:40 +000082 IF_FEATURE_IP_LINK("link\0")
Denys Vlasenkoe0a62202010-07-24 23:26:58 +020083 IF_FEATURE_IP_TUNNEL("tunnel\0")
84 IF_FEATURE_IP_TUNNEL("tunl\0")
Denis Vlasenko5e34ff22009-04-21 11:09:40 +000085 IF_FEATURE_IP_RULE("rule\0")
Denis Vlasenko990d0f62007-07-24 15:54:42 +000086 ;
Denys Vlasenkoe0a62202010-07-24 23:26:58 +020087 static const ip_func_ptr_t ip_func_ptrs[] = {
88 ip_print_help,
89 IF_FEATURE_IP_ADDRESS(do_ipaddr,)
90 IF_FEATURE_IP_ROUTE(do_iproute,)
91 IF_FEATURE_IP_ROUTE(do_iproute,)
92 IF_FEATURE_IP_LINK(do_iplink,)
93 IF_FEATURE_IP_TUNNEL(do_iptunnel,)
94 IF_FEATURE_IP_TUNNEL(do_iptunnel,)
95 IF_FEATURE_IP_RULE(do_iprule,)
Bernhard Reutner-Fischere87d7952007-04-10 18:43:27 +000096 };
Denys Vlasenkoe0a62202010-07-24 23:26:58 +020097 ip_func_ptr_t ip_func;
98 int key;
Bernhard Reutner-Fischere87d7952007-04-10 18:43:27 +000099
Denis Vlasenkoed6a49c2007-11-18 22:56:25 +0000100 argv = ip_parse_common_args(argv + 1);
Denys Vlasenkoe0a62202010-07-24 23:26:58 +0200101 key = *argv ? index_in_substrings(keywords, *argv++) : -1;
102 ip_func = ip_func_ptrs[key + 1];
103
Denis Vlasenkoed6a49c2007-11-18 22:56:25 +0000104 return ip_func(argv);
Glenn L McGrath9a2d2722002-11-10 01:33:55 +0000105}
Denis Vlasenkod46e6d12007-05-17 12:58:30 +0000106
107#endif /* any of ENABLE_FEATURE_IP_xxx is 1 */