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
|
2008-09-25 17:43:34 +05:30
|
|
|
* Bernhard Reutner-Fischer rewrote to use index_in_substr_array
|
2002-11-10 07:03:55 +05:30
|
|
|
*/
|
|
|
|
|
2007-05-27 00:30:18 +05:30
|
|
|
#include "libbb.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-05-17 18:28:30 +05:30
|
|
|
#if ENABLE_FEATURE_IP_ADDRESS \
|
|
|
|
|| ENABLE_FEATURE_IP_ROUTE \
|
|
|
|
|| ENABLE_FEATURE_IP_LINK \
|
|
|
|
|| ENABLE_FEATURE_IP_TUNNEL \
|
|
|
|
|| ENABLE_FEATURE_IP_RULE
|
|
|
|
|
2008-07-05 14:48:54 +05:30
|
|
|
static int NORETURN ip_print_help(char **argv UNUSED_PARAM)
|
2007-04-11 00:13:27 +05:30
|
|
|
{
|
|
|
|
bb_show_usage();
|
|
|
|
}
|
2007-04-11 01:41:12 +05:30
|
|
|
|
2007-11-19 04:26:25 +05:30
|
|
|
static int ip_do(int (*ip_func)(char **argv), char **argv)
|
2007-04-11 01:41:12 +05:30
|
|
|
{
|
2008-12-04 17:45:19 +05:30
|
|
|
argv = ip_parse_common_args(argv + 1);
|
2007-11-19 04:26:25 +05:30
|
|
|
return ip_func(argv);
|
2007-04-11 01:41:12 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
#if ENABLE_FEATURE_IP_ADDRESS
|
2007-10-11 15:35:36 +05:30
|
|
|
int ipaddr_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
2008-07-05 14:48:54 +05:30
|
|
|
int ipaddr_main(int argc UNUSED_PARAM, char **argv)
|
2007-04-11 01:41:12 +05:30
|
|
|
{
|
2008-03-28 06:30:09 +05:30
|
|
|
return ip_do(do_ipaddr, argv);
|
2007-04-11 01:41:12 +05:30
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#if ENABLE_FEATURE_IP_LINK
|
2007-10-11 15:35:36 +05:30
|
|
|
int iplink_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
2008-07-05 14:48:54 +05:30
|
|
|
int iplink_main(int argc UNUSED_PARAM, char **argv)
|
2007-04-11 01:41:12 +05:30
|
|
|
{
|
2008-03-28 06:30:09 +05:30
|
|
|
return ip_do(do_iplink, argv);
|
2007-04-11 01:41:12 +05:30
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#if ENABLE_FEATURE_IP_ROUTE
|
2007-10-11 15:35:36 +05:30
|
|
|
int iproute_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
2008-07-05 14:48:54 +05:30
|
|
|
int iproute_main(int argc UNUSED_PARAM, char **argv)
|
2007-04-11 01:41:12 +05:30
|
|
|
{
|
2008-03-28 06:30:09 +05:30
|
|
|
return ip_do(do_iproute, argv);
|
2007-04-11 01:41:12 +05:30
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#if ENABLE_FEATURE_IP_RULE
|
2007-10-11 15:35:36 +05:30
|
|
|
int iprule_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
2008-07-05 14:48:54 +05:30
|
|
|
int iprule_main(int argc UNUSED_PARAM, char **argv)
|
2007-04-11 01:41:12 +05:30
|
|
|
{
|
2008-03-28 06:30:09 +05:30
|
|
|
return ip_do(do_iprule, argv);
|
2007-04-11 01:41:12 +05:30
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#if ENABLE_FEATURE_IP_TUNNEL
|
2007-10-11 15:35:36 +05:30
|
|
|
int iptunnel_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
2008-07-05 14:48:54 +05:30
|
|
|
int iptunnel_main(int argc UNUSED_PARAM, char **argv)
|
2007-04-11 01:41:12 +05:30
|
|
|
{
|
2008-03-28 06:30:09 +05:30
|
|
|
return ip_do(do_iptunnel, argv);
|
2007-04-11 01:41:12 +05:30
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2007-10-11 15:35:36 +05:30
|
|
|
int ip_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
2008-07-05 14:48:54 +05:30
|
|
|
int ip_main(int argc UNUSED_PARAM, char **argv)
|
2002-12-02 04:34:06 +05:30
|
|
|
{
|
2007-08-13 02:28:27 +05:30
|
|
|
static const char keywords[] ALIGN1 =
|
2009-04-21 16:39:40 +05:30
|
|
|
IF_FEATURE_IP_ADDRESS("address\0")
|
|
|
|
IF_FEATURE_IP_ROUTE("route\0")
|
|
|
|
IF_FEATURE_IP_LINK("link\0")
|
|
|
|
IF_FEATURE_IP_TUNNEL("tunnel\0" "tunl\0")
|
|
|
|
IF_FEATURE_IP_RULE("rule\0")
|
2007-07-24 21:24:42 +05:30
|
|
|
;
|
2007-04-11 00:13:27 +05:30
|
|
|
enum {
|
2009-04-21 16:39:40 +05:30
|
|
|
IF_FEATURE_IP_ADDRESS(IP_addr,)
|
|
|
|
IF_FEATURE_IP_ROUTE(IP_route,)
|
|
|
|
IF_FEATURE_IP_LINK(IP_link,)
|
|
|
|
IF_FEATURE_IP_TUNNEL(IP_tunnel, IP_tunl,)
|
|
|
|
IF_FEATURE_IP_RULE(IP_rule,)
|
2007-04-11 00:13:27 +05:30
|
|
|
IP_none
|
|
|
|
};
|
2007-12-22 22:30:11 +05:30
|
|
|
int (*ip_func)(char**) = ip_print_help;
|
2007-04-07 06:44:45 +05:30
|
|
|
|
2007-11-19 04:26:25 +05:30
|
|
|
argv = ip_parse_common_args(argv + 1);
|
|
|
|
if (*argv) {
|
|
|
|
int key = index_in_substrings(keywords, *argv);
|
|
|
|
argv++;
|
2007-04-11 00:13:27 +05:30
|
|
|
#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-11-19 04:26:25 +05:30
|
|
|
return ip_func(argv);
|
2002-11-10 07:03:55 +05:30
|
|
|
}
|
2007-05-17 18:28:30 +05:30
|
|
|
|
|
|
|
#endif /* any of ENABLE_FEATURE_IP_xxx is 1 */
|