"Robert P. J. Day" | 63fc1a9 | 2006-07-02 19:47:05 +0000 | [diff] [blame] | 1 | /* vi: set sw=4 ts=4: */ |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 2 | /* |
Denys Vlasenko | e0a6220 | 2010-07-24 23:26:58 +0200 | [diff] [blame] | 3 | * "ip" utility frontend. |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 4 | * |
Denys Vlasenko | 0ef64bd | 2010-08-16 20:14:46 +0200 | [diff] [blame^] | 5 | * Licensed under GPLv2 or later, see file LICENSE in this source tree. |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 6 | * |
Denys Vlasenko | e0a6220 | 2010-07-24 23:26:58 +0200 | [diff] [blame] | 7 | * Authors: Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru> |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 8 | * |
| 9 | * Changes: |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 10 | * Rani Assaf <rani@magic.metawire.com> 980929: resolve addresses |
Bernhard Reutner-Fischer | 6c4dade | 2008-09-25 12:13:34 +0000 | [diff] [blame] | 11 | * Bernhard Reutner-Fischer rewrote to use index_in_substr_array |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 12 | */ |
| 13 | |
Denis Vlasenko | b6adbf1 | 2007-05-26 19:00:18 +0000 | [diff] [blame] | 14 | #include "libbb.h" |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 15 | |
Bernhard Reutner-Fischer | ab18782 | 2005-10-26 10:47:26 +0000 | [diff] [blame] | 16 | #include "libiproute/utils.h" |
| 17 | #include "libiproute/ip_common.h" |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 18 | |
Denis Vlasenko | d46e6d1 | 2007-05-17 12:58:30 +0000 | [diff] [blame] | 19 | #if ENABLE_FEATURE_IP_ADDRESS \ |
| 20 | || ENABLE_FEATURE_IP_ROUTE \ |
| 21 | || ENABLE_FEATURE_IP_LINK \ |
| 22 | || ENABLE_FEATURE_IP_TUNNEL \ |
| 23 | || ENABLE_FEATURE_IP_RULE |
| 24 | |
Denys Vlasenko | 2e9b551 | 2010-07-24 23:27:38 +0200 | [diff] [blame] | 25 | static int FAST_FUNC ip_print_help(char **argv UNUSED_PARAM) |
Bernhard Reutner-Fischer | e87d795 | 2007-04-10 18:43:27 +0000 | [diff] [blame] | 26 | { |
| 27 | bb_show_usage(); |
| 28 | } |
Bernhard Reutner-Fischer | 07c394e | 2007-04-10 20:11:12 +0000 | [diff] [blame] | 29 | |
Denys Vlasenko | 2e9b551 | 2010-07-24 23:27:38 +0200 | [diff] [blame] | 30 | typedef int FAST_FUNC (*ip_func_ptr_t)(char**); |
Denys Vlasenko | e0a6220 | 2010-07-24 23:26:58 +0200 | [diff] [blame] | 31 | |
| 32 | static int ip_do(ip_func_ptr_t ip_func, char **argv) |
Bernhard Reutner-Fischer | 07c394e | 2007-04-10 20:11:12 +0000 | [diff] [blame] | 33 | { |
Denis Vlasenko | 3246c0d | 2008-12-04 12:15:19 +0000 | [diff] [blame] | 34 | argv = ip_parse_common_args(argv + 1); |
Denis Vlasenko | ed6a49c | 2007-11-18 22:56:25 +0000 | [diff] [blame] | 35 | return ip_func(argv); |
Bernhard Reutner-Fischer | 07c394e | 2007-04-10 20:11:12 +0000 | [diff] [blame] | 36 | } |
| 37 | |
| 38 | #if ENABLE_FEATURE_IP_ADDRESS |
Denis Vlasenko | 9b49a5e | 2007-10-11 10:05:36 +0000 | [diff] [blame] | 39 | int ipaddr_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
Denis Vlasenko | a60f84e | 2008-07-05 09:18:54 +0000 | [diff] [blame] | 40 | int ipaddr_main(int argc UNUSED_PARAM, char **argv) |
Bernhard Reutner-Fischer | 07c394e | 2007-04-10 20:11:12 +0000 | [diff] [blame] | 41 | { |
Denis Vlasenko | 2570b2e | 2008-03-28 01:00:09 +0000 | [diff] [blame] | 42 | return ip_do(do_ipaddr, argv); |
Bernhard Reutner-Fischer | 07c394e | 2007-04-10 20:11:12 +0000 | [diff] [blame] | 43 | } |
| 44 | #endif |
| 45 | #if ENABLE_FEATURE_IP_LINK |
Denis Vlasenko | 9b49a5e | 2007-10-11 10:05:36 +0000 | [diff] [blame] | 46 | int iplink_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
Denis Vlasenko | a60f84e | 2008-07-05 09:18:54 +0000 | [diff] [blame] | 47 | int iplink_main(int argc UNUSED_PARAM, char **argv) |
Bernhard Reutner-Fischer | 07c394e | 2007-04-10 20:11:12 +0000 | [diff] [blame] | 48 | { |
Denis Vlasenko | 2570b2e | 2008-03-28 01:00:09 +0000 | [diff] [blame] | 49 | return ip_do(do_iplink, argv); |
Bernhard Reutner-Fischer | 07c394e | 2007-04-10 20:11:12 +0000 | [diff] [blame] | 50 | } |
| 51 | #endif |
| 52 | #if ENABLE_FEATURE_IP_ROUTE |
Denis Vlasenko | 9b49a5e | 2007-10-11 10:05:36 +0000 | [diff] [blame] | 53 | int iproute_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
Denis Vlasenko | a60f84e | 2008-07-05 09:18:54 +0000 | [diff] [blame] | 54 | int iproute_main(int argc UNUSED_PARAM, char **argv) |
Bernhard Reutner-Fischer | 07c394e | 2007-04-10 20:11:12 +0000 | [diff] [blame] | 55 | { |
Denis Vlasenko | 2570b2e | 2008-03-28 01:00:09 +0000 | [diff] [blame] | 56 | return ip_do(do_iproute, argv); |
Bernhard Reutner-Fischer | 07c394e | 2007-04-10 20:11:12 +0000 | [diff] [blame] | 57 | } |
| 58 | #endif |
| 59 | #if ENABLE_FEATURE_IP_RULE |
Denis Vlasenko | 9b49a5e | 2007-10-11 10:05:36 +0000 | [diff] [blame] | 60 | int iprule_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
Denis Vlasenko | a60f84e | 2008-07-05 09:18:54 +0000 | [diff] [blame] | 61 | int iprule_main(int argc UNUSED_PARAM, char **argv) |
Bernhard Reutner-Fischer | 07c394e | 2007-04-10 20:11:12 +0000 | [diff] [blame] | 62 | { |
Denis Vlasenko | 2570b2e | 2008-03-28 01:00:09 +0000 | [diff] [blame] | 63 | return ip_do(do_iprule, argv); |
Bernhard Reutner-Fischer | 07c394e | 2007-04-10 20:11:12 +0000 | [diff] [blame] | 64 | } |
| 65 | #endif |
| 66 | #if ENABLE_FEATURE_IP_TUNNEL |
Denis Vlasenko | 9b49a5e | 2007-10-11 10:05:36 +0000 | [diff] [blame] | 67 | int iptunnel_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
Denis Vlasenko | a60f84e | 2008-07-05 09:18:54 +0000 | [diff] [blame] | 68 | int iptunnel_main(int argc UNUSED_PARAM, char **argv) |
Bernhard Reutner-Fischer | 07c394e | 2007-04-10 20:11:12 +0000 | [diff] [blame] | 69 | { |
Denis Vlasenko | 2570b2e | 2008-03-28 01:00:09 +0000 | [diff] [blame] | 70 | return ip_do(do_iptunnel, argv); |
Bernhard Reutner-Fischer | 07c394e | 2007-04-10 20:11:12 +0000 | [diff] [blame] | 71 | } |
| 72 | #endif |
| 73 | |
| 74 | |
Denis Vlasenko | 9b49a5e | 2007-10-11 10:05:36 +0000 | [diff] [blame] | 75 | int ip_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
Denis Vlasenko | a60f84e | 2008-07-05 09:18:54 +0000 | [diff] [blame] | 76 | int ip_main(int argc UNUSED_PARAM, char **argv) |
Glenn L McGrath | f112daa | 2002-12-01 23:04:06 +0000 | [diff] [blame] | 77 | { |
Denis Vlasenko | 6ca409e | 2007-08-12 20:58:27 +0000 | [diff] [blame] | 78 | static const char keywords[] ALIGN1 = |
Denis Vlasenko | 5e34ff2 | 2009-04-21 11:09:40 +0000 | [diff] [blame] | 79 | IF_FEATURE_IP_ADDRESS("address\0") |
| 80 | IF_FEATURE_IP_ROUTE("route\0") |
Denys Vlasenko | e0a6220 | 2010-07-24 23:26:58 +0200 | [diff] [blame] | 81 | IF_FEATURE_IP_ROUTE("r\0") |
Denis Vlasenko | 5e34ff2 | 2009-04-21 11:09:40 +0000 | [diff] [blame] | 82 | IF_FEATURE_IP_LINK("link\0") |
Denys Vlasenko | e0a6220 | 2010-07-24 23:26:58 +0200 | [diff] [blame] | 83 | IF_FEATURE_IP_TUNNEL("tunnel\0") |
| 84 | IF_FEATURE_IP_TUNNEL("tunl\0") |
Denis Vlasenko | 5e34ff2 | 2009-04-21 11:09:40 +0000 | [diff] [blame] | 85 | IF_FEATURE_IP_RULE("rule\0") |
Denis Vlasenko | 990d0f6 | 2007-07-24 15:54:42 +0000 | [diff] [blame] | 86 | ; |
Denys Vlasenko | e0a6220 | 2010-07-24 23:26:58 +0200 | [diff] [blame] | 87 | static const ip_func_ptr_t ip_func_ptrs[] = { |
| 88 | ip_print_help, |
| 89 | IF_FEATURE_IP_ADDRESS(do_ipaddr,) |
| 90 | IF_FEATURE_IP_ROUTE(do_iproute,) |
| 91 | IF_FEATURE_IP_ROUTE(do_iproute,) |
| 92 | IF_FEATURE_IP_LINK(do_iplink,) |
| 93 | IF_FEATURE_IP_TUNNEL(do_iptunnel,) |
| 94 | IF_FEATURE_IP_TUNNEL(do_iptunnel,) |
| 95 | IF_FEATURE_IP_RULE(do_iprule,) |
Bernhard Reutner-Fischer | e87d795 | 2007-04-10 18:43:27 +0000 | [diff] [blame] | 96 | }; |
Denys Vlasenko | e0a6220 | 2010-07-24 23:26:58 +0200 | [diff] [blame] | 97 | ip_func_ptr_t ip_func; |
| 98 | int key; |
Bernhard Reutner-Fischer | e87d795 | 2007-04-10 18:43:27 +0000 | [diff] [blame] | 99 | |
Denis Vlasenko | ed6a49c | 2007-11-18 22:56:25 +0000 | [diff] [blame] | 100 | argv = ip_parse_common_args(argv + 1); |
Denys Vlasenko | e0a6220 | 2010-07-24 23:26:58 +0200 | [diff] [blame] | 101 | key = *argv ? index_in_substrings(keywords, *argv++) : -1; |
| 102 | ip_func = ip_func_ptrs[key + 1]; |
| 103 | |
Denis Vlasenko | ed6a49c | 2007-11-18 22:56:25 +0000 | [diff] [blame] | 104 | return ip_func(argv); |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 105 | } |
Denis Vlasenko | d46e6d1 | 2007-05-17 12:58:30 +0000 | [diff] [blame] | 106 | |
| 107 | #endif /* any of ENABLE_FEATURE_IP_xxx is 1 */ |