2006-07-03 01:17:05 +05:30
|
|
|
/* vi: set sw=4 ts=4: */
|
2002-11-10 07:03:55 +05:30
|
|
|
/*
|
|
|
|
* ip.c "ip" utility frontend.
|
|
|
|
*
|
2005-10-26 16:17:26 +05:30
|
|
|
* Licensed under the GPL v2 or later, see the file LICENSE in this tarball.
|
2002-11-10 07:03:55 +05:30
|
|
|
*
|
|
|
|
* Authors: Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru>
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Changes:
|
|
|
|
*
|
|
|
|
* Rani Assaf <rani@magic.metawire.com> 980929: resolve addresses
|
2007-04-11 00:13:27 +05:30
|
|
|
* Bernhard Fischer rewrote to use index_in_substr_array
|
2002-11-10 07:03:55 +05:30
|
|
|
*/
|
|
|
|
|
2006-11-05 23:35:09 +05:30
|
|
|
#include "busybox.h"
|
2002-11-10 07:03:55 +05:30
|
|
|
|
2005-10-26 16:17:26 +05:30
|
|
|
#include "libiproute/utils.h"
|
|
|
|
#include "libiproute/ip_common.h"
|
2002-11-10 07:03:55 +05:30
|
|
|
|
2007-04-11 00:13:27 +05:30
|
|
|
static int ATTRIBUTE_NORETURN ip_print_help(int ATTRIBUTE_UNUSED ac, char ATTRIBUTE_UNUSED **av)
|
|
|
|
{
|
|
|
|
bb_show_usage();
|
|
|
|
}
|
2007-04-11 01:41:12 +05:30
|
|
|
|
|
|
|
static int (*ip_func)(int argc, char **argv) = ip_print_help;
|
|
|
|
|
|
|
|
static int ip_do(int argc, char **argv)
|
|
|
|
{
|
|
|
|
ip_parse_common_args(&argc, &argv);
|
|
|
|
return ip_func(argc-1, argv+1);
|
|
|
|
}
|
|
|
|
|
|
|
|
#if ENABLE_FEATURE_IP_ADDRESS
|
|
|
|
int ipaddr_main(int argc, char **argv);
|
|
|
|
int ipaddr_main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
ip_func = do_ipaddr;
|
|
|
|
return ip_do(argc, argv);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#if ENABLE_FEATURE_IP_LINK
|
|
|
|
int iplink_main(int argc, char **argv);
|
|
|
|
int iplink_main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
ip_func = do_iplink;
|
|
|
|
return ip_do(argc, argv);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#if ENABLE_FEATURE_IP_ROUTE
|
|
|
|
int iproute_main(int argc, char **argv);
|
|
|
|
int iproute_main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
ip_func = do_iproute;
|
|
|
|
return ip_do(argc, argv);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#if ENABLE_FEATURE_IP_RULE
|
|
|
|
int iprule_main(int argc, char **argv);
|
|
|
|
int iprule_main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
ip_func = do_iprule;
|
|
|
|
return ip_do(argc, argv);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#if ENABLE_FEATURE_IP_TUNNEL
|
|
|
|
int iptunnel_main(int argc, char **argv);
|
|
|
|
int iptunnel_main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
ip_func = do_iptunnel;
|
|
|
|
return ip_do(argc, argv);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2007-02-03 22:58:39 +05:30
|
|
|
int ip_main(int argc, char **argv);
|
2002-12-02 04:34:06 +05:30
|
|
|
int ip_main(int argc, char **argv)
|
|
|
|
{
|
2007-04-11 00:13:27 +05:30
|
|
|
const char * const keywords[] = {
|
|
|
|
USE_FEATURE_IP_ADDRESS("address",)
|
|
|
|
USE_FEATURE_IP_ROUTE("route",)
|
|
|
|
USE_FEATURE_IP_LINK("link",)
|
|
|
|
USE_FEATURE_IP_TUNNEL("tunnel", "tunl",)
|
|
|
|
USE_FEATURE_IP_RULE("rule",)
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
enum {
|
|
|
|
USE_FEATURE_IP_ADDRESS(IP_addr,)
|
|
|
|
USE_FEATURE_IP_ROUTE(IP_route,)
|
|
|
|
USE_FEATURE_IP_LINK(IP_link,)
|
|
|
|
USE_FEATURE_IP_TUNNEL(IP_tunnel, IP_tunl,)
|
|
|
|
USE_FEATURE_IP_RULE(IP_rule,)
|
|
|
|
IP_none
|
|
|
|
};
|
2007-04-07 06:44:45 +05:30
|
|
|
|
2007-04-11 00:13:27 +05:30
|
|
|
ip_parse_common_args(&argc, &argv);
|
|
|
|
if (argc > 1) {
|
|
|
|
int key = index_in_substr_array(keywords, argv[1]);
|
|
|
|
argc -= 2;
|
|
|
|
argv += 2;
|
|
|
|
#if ENABLE_FEATURE_IP_ADDRESS
|
|
|
|
if (key == IP_addr)
|
|
|
|
ip_func = do_ipaddr;
|
|
|
|
#endif
|
|
|
|
#if ENABLE_FEATURE_IP_ROUTE
|
|
|
|
if (key == IP_route)
|
|
|
|
ip_func = do_iproute;
|
|
|
|
#endif
|
|
|
|
#if ENABLE_FEATURE_IP_LINK
|
|
|
|
if (key == IP_link)
|
|
|
|
ip_func = do_iplink;
|
|
|
|
#endif
|
|
|
|
#if ENABLE_FEATURE_IP_TUNNEL
|
|
|
|
if (key == IP_tunnel || key == IP_tunl)
|
|
|
|
ip_func = do_iptunnel;
|
|
|
|
#endif
|
|
|
|
#if ENABLE_FEATURE_IP_RULE
|
|
|
|
if (key == IP_rule)
|
|
|
|
ip_func = do_iprule;
|
|
|
|
#endif
|
2007-04-07 06:44:45 +05:30
|
|
|
}
|
2007-04-11 00:13:27 +05:30
|
|
|
return (ip_func(argc, argv));
|
2002-11-10 07:03:55 +05:30
|
|
|
}
|