2006-07-02 19:47:05 +00:00
|
|
|
/* vi: set sw=4 ts=4: */
|
2002-11-10 01:33:55 +00:00
|
|
|
/*
|
2010-07-24 21:26:58 +00:00
|
|
|
* "ip" utility frontend.
|
2002-11-10 01:33:55 +00:00
|
|
|
*
|
2010-08-16 18:14:46 +00:00
|
|
|
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
|
2002-11-10 01:33:55 +00:00
|
|
|
*
|
2010-07-24 21:26:58 +00:00
|
|
|
* Authors: Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru>
|
2002-11-10 01:33:55 +00:00
|
|
|
*
|
|
|
|
* Changes:
|
|
|
|
* Rani Assaf <rani@magic.metawire.com> 980929: resolve addresses
|
2008-09-25 12:13:34 +00:00
|
|
|
* Bernhard Reutner-Fischer rewrote to use index_in_substr_array
|
2002-11-10 01:33:55 +00:00
|
|
|
*/
|
|
|
|
|
2007-05-26 19:00:18 +00:00
|
|
|
#include "libbb.h"
|
2002-11-10 01:33:55 +00:00
|
|
|
|
2005-10-26 10:47:26 +00:00
|
|
|
#include "libiproute/utils.h"
|
|
|
|
#include "libiproute/ip_common.h"
|
2002-11-10 01:33:55 +00:00
|
|
|
|
2007-05-17 12:58:30 +00:00
|
|
|
#if ENABLE_FEATURE_IP_ADDRESS \
|
|
|
|
|| ENABLE_FEATURE_IP_ROUTE \
|
|
|
|
|| ENABLE_FEATURE_IP_LINK \
|
|
|
|
|| ENABLE_FEATURE_IP_TUNNEL \
|
|
|
|
|| ENABLE_FEATURE_IP_RULE
|
|
|
|
|
2010-07-24 21:27:38 +00:00
|
|
|
static int FAST_FUNC ip_print_help(char **argv UNUSED_PARAM)
|
2007-04-10 18:43:27 +00:00
|
|
|
{
|
|
|
|
bb_show_usage();
|
|
|
|
}
|
2007-04-10 20:11:12 +00:00
|
|
|
|
2010-07-24 21:27:38 +00:00
|
|
|
typedef int FAST_FUNC (*ip_func_ptr_t)(char**);
|
2010-07-24 21:26:58 +00:00
|
|
|
|
|
|
|
static int ip_do(ip_func_ptr_t ip_func, char **argv)
|
2007-04-10 20:11:12 +00:00
|
|
|
{
|
2008-12-04 12:15:19 +00:00
|
|
|
argv = ip_parse_common_args(argv + 1);
|
2007-11-18 22:56:25 +00:00
|
|
|
return ip_func(argv);
|
2007-04-10 20:11:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#if ENABLE_FEATURE_IP_ADDRESS
|
2007-10-11 10:05:36 +00:00
|
|
|
int ipaddr_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
2008-07-05 09:18:54 +00:00
|
|
|
int ipaddr_main(int argc UNUSED_PARAM, char **argv)
|
2007-04-10 20:11:12 +00:00
|
|
|
{
|
2008-03-28 01:00:09 +00:00
|
|
|
return ip_do(do_ipaddr, argv);
|
2007-04-10 20:11:12 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#if ENABLE_FEATURE_IP_LINK
|
2007-10-11 10:05:36 +00:00
|
|
|
int iplink_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
2008-07-05 09:18:54 +00:00
|
|
|
int iplink_main(int argc UNUSED_PARAM, char **argv)
|
2007-04-10 20:11:12 +00:00
|
|
|
{
|
2008-03-28 01:00:09 +00:00
|
|
|
return ip_do(do_iplink, argv);
|
2007-04-10 20:11:12 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#if ENABLE_FEATURE_IP_ROUTE
|
2007-10-11 10:05:36 +00:00
|
|
|
int iproute_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
2008-07-05 09:18:54 +00:00
|
|
|
int iproute_main(int argc UNUSED_PARAM, char **argv)
|
2007-04-10 20:11:12 +00:00
|
|
|
{
|
2008-03-28 01:00:09 +00:00
|
|
|
return ip_do(do_iproute, argv);
|
2007-04-10 20:11:12 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#if ENABLE_FEATURE_IP_RULE
|
2007-10-11 10:05:36 +00:00
|
|
|
int iprule_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
2008-07-05 09:18:54 +00:00
|
|
|
int iprule_main(int argc UNUSED_PARAM, char **argv)
|
2007-04-10 20:11:12 +00:00
|
|
|
{
|
2008-03-28 01:00:09 +00:00
|
|
|
return ip_do(do_iprule, argv);
|
2007-04-10 20:11:12 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#if ENABLE_FEATURE_IP_TUNNEL
|
2007-10-11 10:05:36 +00:00
|
|
|
int iptunnel_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
2008-07-05 09:18:54 +00:00
|
|
|
int iptunnel_main(int argc UNUSED_PARAM, char **argv)
|
2007-04-10 20:11:12 +00:00
|
|
|
{
|
2008-03-28 01:00:09 +00:00
|
|
|
return ip_do(do_iptunnel, argv);
|
2007-04-10 20:11:12 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2007-10-11 10:05:36 +00:00
|
|
|
int ip_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
2008-07-05 09:18:54 +00:00
|
|
|
int ip_main(int argc UNUSED_PARAM, char **argv)
|
2002-12-01 23:04:06 +00:00
|
|
|
{
|
2007-08-12 20:58:27 +00:00
|
|
|
static const char keywords[] ALIGN1 =
|
2009-04-21 11:09:40 +00:00
|
|
|
IF_FEATURE_IP_ADDRESS("address\0")
|
|
|
|
IF_FEATURE_IP_ROUTE("route\0")
|
2010-07-24 21:26:58 +00:00
|
|
|
IF_FEATURE_IP_ROUTE("r\0")
|
2009-04-21 11:09:40 +00:00
|
|
|
IF_FEATURE_IP_LINK("link\0")
|
2010-07-24 21:26:58 +00:00
|
|
|
IF_FEATURE_IP_TUNNEL("tunnel\0")
|
|
|
|
IF_FEATURE_IP_TUNNEL("tunl\0")
|
2009-04-21 11:09:40 +00:00
|
|
|
IF_FEATURE_IP_RULE("rule\0")
|
2007-07-24 15:54:42 +00:00
|
|
|
;
|
2010-07-24 21:26:58 +00:00
|
|
|
static const ip_func_ptr_t ip_func_ptrs[] = {
|
|
|
|
ip_print_help,
|
|
|
|
IF_FEATURE_IP_ADDRESS(do_ipaddr,)
|
|
|
|
IF_FEATURE_IP_ROUTE(do_iproute,)
|
|
|
|
IF_FEATURE_IP_ROUTE(do_iproute,)
|
|
|
|
IF_FEATURE_IP_LINK(do_iplink,)
|
|
|
|
IF_FEATURE_IP_TUNNEL(do_iptunnel,)
|
|
|
|
IF_FEATURE_IP_TUNNEL(do_iptunnel,)
|
|
|
|
IF_FEATURE_IP_RULE(do_iprule,)
|
2007-04-10 18:43:27 +00:00
|
|
|
};
|
2010-07-24 21:26:58 +00:00
|
|
|
ip_func_ptr_t ip_func;
|
|
|
|
int key;
|
2007-04-07 01:14:45 +00:00
|
|
|
|
2007-11-18 22:56:25 +00:00
|
|
|
argv = ip_parse_common_args(argv + 1);
|
2010-07-24 21:26:58 +00:00
|
|
|
key = *argv ? index_in_substrings(keywords, *argv++) : -1;
|
|
|
|
ip_func = ip_func_ptrs[key + 1];
|
|
|
|
|
2007-11-18 22:56:25 +00:00
|
|
|
return ip_func(argv);
|
2002-11-10 01:33:55 +00:00
|
|
|
}
|
2007-05-17 12:58:30 +00:00
|
|
|
|
|
|
|
#endif /* any of ENABLE_FEATURE_IP_xxx is 1 */
|