[1770] | 1 | /* vi: set sw=4 ts=4: */
|
---|
[821] | 2 | /*
|
---|
| 3 | * ip.c "ip" utility frontend.
|
---|
| 4 | *
|
---|
| 5 | * Licensed under the GPL v2 or later, see the file LICENSE in this tarball.
|
---|
| 6 | *
|
---|
| 7 | * Authors: Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru>
|
---|
| 8 | *
|
---|
| 9 | *
|
---|
| 10 | * Changes:
|
---|
| 11 | *
|
---|
| 12 | * Rani Assaf <rani@magic.metawire.com> 980929: resolve addresses
|
---|
[1770] | 13 | * Bernhard Fischer rewrote to use index_in_substr_array
|
---|
[821] | 14 | */
|
---|
| 15 |
|
---|
[1770] | 16 | #include "libbb.h"
|
---|
[821] | 17 |
|
---|
| 18 | #include "libiproute/utils.h"
|
---|
| 19 | #include "libiproute/ip_common.h"
|
---|
| 20 |
|
---|
[1770] | 21 | #if ENABLE_FEATURE_IP_ADDRESS \
|
---|
| 22 | || ENABLE_FEATURE_IP_ROUTE \
|
---|
| 23 | || ENABLE_FEATURE_IP_LINK \
|
---|
| 24 | || ENABLE_FEATURE_IP_TUNNEL \
|
---|
| 25 | || ENABLE_FEATURE_IP_RULE
|
---|
[821] | 26 |
|
---|
[1770] | 27 | static int ATTRIBUTE_NORETURN ip_print_help(int ATTRIBUTE_UNUSED ac, char ATTRIBUTE_UNUSED **av)
|
---|
[821] | 28 | {
|
---|
[1770] | 29 | bb_show_usage();
|
---|
| 30 | }
|
---|
[821] | 31 |
|
---|
[1770] | 32 | static int (*ip_func)(int argc, char **argv) = ip_print_help;
|
---|
[821] | 33 |
|
---|
[1770] | 34 | static int ip_do(int argc, char **argv)
|
---|
| 35 | {
|
---|
| 36 | ip_parse_common_args(&argc, &argv);
|
---|
| 37 | return ip_func(argc-1, argv+1);
|
---|
| 38 | }
|
---|
[821] | 39 |
|
---|
[1770] | 40 | #if ENABLE_FEATURE_IP_ADDRESS
|
---|
| 41 | int ipaddr_main(int argc, char **argv);
|
---|
| 42 | int ipaddr_main(int argc, char **argv)
|
---|
| 43 | {
|
---|
| 44 | ip_func = do_ipaddr;
|
---|
| 45 | return ip_do(argc, argv);
|
---|
[821] | 46 | }
|
---|
| 47 | #endif
|
---|
[1770] | 48 | #if ENABLE_FEATURE_IP_LINK
|
---|
| 49 | int iplink_main(int argc, char **argv);
|
---|
| 50 | int iplink_main(int argc, char **argv)
|
---|
| 51 | {
|
---|
| 52 | ip_func = do_iplink;
|
---|
| 53 | return ip_do(argc, argv);
|
---|
| 54 | }
|
---|
| 55 | #endif
|
---|
| 56 | #if ENABLE_FEATURE_IP_ROUTE
|
---|
| 57 | int iproute_main(int argc, char **argv);
|
---|
| 58 | int iproute_main(int argc, char **argv)
|
---|
| 59 | {
|
---|
| 60 | ip_func = do_iproute;
|
---|
| 61 | return ip_do(argc, argv);
|
---|
| 62 | }
|
---|
| 63 | #endif
|
---|
| 64 | #if ENABLE_FEATURE_IP_RULE
|
---|
| 65 | int iprule_main(int argc, char **argv);
|
---|
| 66 | int iprule_main(int argc, char **argv)
|
---|
| 67 | {
|
---|
| 68 | ip_func = do_iprule;
|
---|
| 69 | return ip_do(argc, argv);
|
---|
| 70 | }
|
---|
| 71 | #endif
|
---|
| 72 | #if ENABLE_FEATURE_IP_TUNNEL
|
---|
| 73 | int iptunnel_main(int argc, char **argv);
|
---|
| 74 | int iptunnel_main(int argc, char **argv)
|
---|
| 75 | {
|
---|
| 76 | ip_func = do_iptunnel;
|
---|
| 77 | return ip_do(argc, argv);
|
---|
| 78 | }
|
---|
| 79 | #endif
|
---|
[821] | 80 |
|
---|
[1770] | 81 |
|
---|
| 82 | int ip_main(int argc, char **argv);
|
---|
[821] | 83 | int ip_main(int argc, char **argv)
|
---|
| 84 | {
|
---|
[1770] | 85 | static const char keywords[] ALIGN1 =
|
---|
| 86 | USE_FEATURE_IP_ADDRESS("address\0")
|
---|
| 87 | USE_FEATURE_IP_ROUTE("route\0")
|
---|
| 88 | USE_FEATURE_IP_LINK("link\0")
|
---|
| 89 | USE_FEATURE_IP_TUNNEL("tunnel\0" "tunl\0")
|
---|
| 90 | USE_FEATURE_IP_RULE("rule\0")
|
---|
| 91 | ;
|
---|
| 92 | enum {
|
---|
| 93 | USE_FEATURE_IP_ADDRESS(IP_addr,)
|
---|
| 94 | USE_FEATURE_IP_ROUTE(IP_route,)
|
---|
| 95 | USE_FEATURE_IP_LINK(IP_link,)
|
---|
| 96 | USE_FEATURE_IP_TUNNEL(IP_tunnel, IP_tunl,)
|
---|
| 97 | USE_FEATURE_IP_RULE(IP_rule,)
|
---|
| 98 | IP_none
|
---|
| 99 | };
|
---|
[821] | 100 |
|
---|
| 101 | ip_parse_common_args(&argc, &argv);
|
---|
| 102 | if (argc > 1) {
|
---|
[1770] | 103 | int key = index_in_substrings(keywords, argv[1]);
|
---|
| 104 | argc -= 2;
|
---|
| 105 | argv += 2;
|
---|
| 106 | #if ENABLE_FEATURE_IP_ADDRESS
|
---|
| 107 | if (key == IP_addr)
|
---|
| 108 | ip_func = do_ipaddr;
|
---|
[821] | 109 | #endif
|
---|
[1770] | 110 | #if ENABLE_FEATURE_IP_ROUTE
|
---|
| 111 | if (key == IP_route)
|
---|
| 112 | ip_func = do_iproute;
|
---|
[821] | 113 | #endif
|
---|
[1770] | 114 | #if ENABLE_FEATURE_IP_LINK
|
---|
| 115 | if (key == IP_link)
|
---|
| 116 | ip_func = do_iplink;
|
---|
[821] | 117 | #endif
|
---|
[1770] | 118 | #if ENABLE_FEATURE_IP_TUNNEL
|
---|
| 119 | if (key == IP_tunnel || key == IP_tunl)
|
---|
| 120 | ip_func = do_iptunnel;
|
---|
[821] | 121 | #endif
|
---|
[1770] | 122 | #if ENABLE_FEATURE_IP_RULE
|
---|
| 123 | if (key == IP_rule)
|
---|
| 124 | ip_func = do_iprule;
|
---|
| 125 | #endif
|
---|
[821] | 126 | }
|
---|
[1770] | 127 | return ip_func(argc, argv);
|
---|
[821] | 128 | }
|
---|
[1770] | 129 |
|
---|
| 130 | #endif /* any of ENABLE_FEATURE_IP_xxx is 1 */
|
---|