blob: dc9ca1f91700d8c16018587bb1ea92c5ce2eaa9e [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/*
3 * ip.c "ip" utility frontend.
4 *
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 *
7 * Authors: Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru>
8 *
9 *
10 * Changes:
11 *
12 * Rani Assaf <rani@magic.metawire.com> 980929: resolve addresses
Bernhard Reutner-Fischere87d7952007-04-10 18:43:27 +000013 * Bernhard Fischer rewrote to use index_in_substr_array
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000014 */
15
Denis Vlasenko5af906e2006-11-05 18:05:09 +000016#include "busybox.h"
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000017
Bernhard Reutner-Fischerab187822005-10-26 10:47:26 +000018#include "libiproute/utils.h"
19#include "libiproute/ip_common.h"
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000020
Bernhard Reutner-Fischere87d7952007-04-10 18:43:27 +000021static int ATTRIBUTE_NORETURN ip_print_help(int ATTRIBUTE_UNUSED ac, char ATTRIBUTE_UNUSED **av)
22{
23 bb_show_usage();
24}
Denis Vlasenko06af2162007-02-03 17:28:39 +000025int ip_main(int argc, char **argv);
Glenn L McGrathf112daa2002-12-01 23:04:06 +000026int ip_main(int argc, char **argv)
27{
Bernhard Reutner-Fischere87d7952007-04-10 18:43:27 +000028 const char * const keywords[] = {
29 USE_FEATURE_IP_ADDRESS("address",)
30 USE_FEATURE_IP_ROUTE("route",)
31 USE_FEATURE_IP_LINK("link",)
32 USE_FEATURE_IP_TUNNEL("tunnel", "tunl",)
33 USE_FEATURE_IP_RULE("rule",)
34 NULL
35 };
36 enum {
37 USE_FEATURE_IP_ADDRESS(IP_addr,)
38 USE_FEATURE_IP_ROUTE(IP_route,)
39 USE_FEATURE_IP_LINK(IP_link,)
40 USE_FEATURE_IP_TUNNEL(IP_tunnel, IP_tunl,)
41 USE_FEATURE_IP_RULE(IP_rule,)
42 IP_none
43 };
44 int (*ip_func)(int argc, char **argv) = ip_print_help;
45
Glenn L McGrathf112daa2002-12-01 23:04:06 +000046 ip_parse_common_args(&argc, &argv);
Bernhard Reutner-Fischere87d7952007-04-10 18:43:27 +000047 if (argc > 1) {
48 int key = index_in_substr_array(keywords, argv[1]);
49 argc -= 2;
50 argv += 2;
51#if ENABLE_FEATURE_IP_ADDRESS
52 if (key == IP_addr)
53 ip_func = do_ipaddr;
54#endif
55#if ENABLE_FEATURE_IP_ROUTE
56 if (key == IP_route)
57 ip_func = do_iproute;
58#endif
59#if ENABLE_FEATURE_IP_LINK
60 if (key == IP_link)
61 ip_func = do_iplink;
62#endif
63#if ENABLE_FEATURE_IP_TUNNEL
64 if (key == IP_tunnel || key == IP_tunl)
65 ip_func = do_iptunnel;
66#endif
67#if ENABLE_FEATURE_IP_RULE
68 if (key == IP_rule)
69 ip_func = do_iprule;
70#endif
Glenn L McGrathf112daa2002-12-01 23:04:06 +000071 }
Bernhard Reutner-Fischere87d7952007-04-10 18:43:27 +000072 return (ip_func(argc, argv));
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000073}