"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 | /* |
| 3 | * ip.c "ip" utility frontend. |
| 4 | * |
Bernhard Reutner-Fischer | ab18782 | 2005-10-26 10:47:26 +0000 | [diff] [blame] | 5 | * Licensed under the GPL v2 or later, see the file LICENSE in this tarball. |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 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 |
Bernhard Reutner-Fischer | e87d795 | 2007-04-10 18:43:27 +0000 | [diff] [blame] | 13 | * Bernhard Fischer rewrote to use index_in_substr_array |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 14 | */ |
| 15 | |
Denis Vlasenko | b6adbf1 | 2007-05-26 19:00:18 +0000 | [diff] [blame] | 16 | #include "libbb.h" |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 17 | |
Bernhard Reutner-Fischer | ab18782 | 2005-10-26 10:47:26 +0000 | [diff] [blame] | 18 | #include "libiproute/utils.h" |
| 19 | #include "libiproute/ip_common.h" |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 20 | |
Denis Vlasenko | d46e6d1 | 2007-05-17 12:58:30 +0000 | [diff] [blame] | 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 |
| 26 | |
Bernhard Reutner-Fischer | e87d795 | 2007-04-10 18:43:27 +0000 | [diff] [blame] | 27 | static int ATTRIBUTE_NORETURN ip_print_help(int ATTRIBUTE_UNUSED ac, char ATTRIBUTE_UNUSED **av) |
| 28 | { |
| 29 | bb_show_usage(); |
| 30 | } |
Bernhard Reutner-Fischer | 07c394e | 2007-04-10 20:11:12 +0000 | [diff] [blame] | 31 | |
| 32 | static int (*ip_func)(int argc, char **argv) = ip_print_help; |
| 33 | |
| 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 | } |
| 39 | |
| 40 | #if ENABLE_FEATURE_IP_ADDRESS |
Denis Vlasenko | 9b49a5e | 2007-10-11 10:05:36 +0000 | [diff] [blame] | 41 | int ipaddr_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
Bernhard Reutner-Fischer | 07c394e | 2007-04-10 20:11:12 +0000 | [diff] [blame] | 42 | int ipaddr_main(int argc, char **argv) |
| 43 | { |
| 44 | ip_func = do_ipaddr; |
| 45 | return ip_do(argc, argv); |
| 46 | } |
| 47 | #endif |
| 48 | #if ENABLE_FEATURE_IP_LINK |
Denis Vlasenko | 9b49a5e | 2007-10-11 10:05:36 +0000 | [diff] [blame] | 49 | int iplink_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
Bernhard Reutner-Fischer | 07c394e | 2007-04-10 20:11:12 +0000 | [diff] [blame] | 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 |
Denis Vlasenko | 9b49a5e | 2007-10-11 10:05:36 +0000 | [diff] [blame] | 57 | int iproute_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
Bernhard Reutner-Fischer | 07c394e | 2007-04-10 20:11:12 +0000 | [diff] [blame] | 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 |
Denis Vlasenko | 9b49a5e | 2007-10-11 10:05:36 +0000 | [diff] [blame] | 65 | int iprule_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
Bernhard Reutner-Fischer | 07c394e | 2007-04-10 20:11:12 +0000 | [diff] [blame] | 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 |
Denis Vlasenko | 9b49a5e | 2007-10-11 10:05:36 +0000 | [diff] [blame] | 73 | int iptunnel_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
Bernhard Reutner-Fischer | 07c394e | 2007-04-10 20:11:12 +0000 | [diff] [blame] | 74 | int iptunnel_main(int argc, char **argv) |
| 75 | { |
| 76 | ip_func = do_iptunnel; |
| 77 | return ip_do(argc, argv); |
| 78 | } |
| 79 | #endif |
| 80 | |
| 81 | |
Denis Vlasenko | 9b49a5e | 2007-10-11 10:05:36 +0000 | [diff] [blame] | 82 | int ip_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
Glenn L McGrath | f112daa | 2002-12-01 23:04:06 +0000 | [diff] [blame] | 83 | int ip_main(int argc, char **argv) |
| 84 | { |
Denis Vlasenko | 6ca409e | 2007-08-12 20:58:27 +0000 | [diff] [blame] | 85 | static const char keywords[] ALIGN1 = |
Denis Vlasenko | 990d0f6 | 2007-07-24 15:54:42 +0000 | [diff] [blame] | 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 | ; |
Bernhard Reutner-Fischer | e87d795 | 2007-04-10 18:43:27 +0000 | [diff] [blame] | 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 | }; |
Bernhard Reutner-Fischer | e87d795 | 2007-04-10 18:43:27 +0000 | [diff] [blame] | 100 | |
Glenn L McGrath | f112daa | 2002-12-01 23:04:06 +0000 | [diff] [blame] | 101 | ip_parse_common_args(&argc, &argv); |
Bernhard Reutner-Fischer | e87d795 | 2007-04-10 18:43:27 +0000 | [diff] [blame] | 102 | if (argc > 1) { |
Denis Vlasenko | 990d0f6 | 2007-07-24 15:54:42 +0000 | [diff] [blame] | 103 | int key = index_in_substrings(keywords, argv[1]); |
Bernhard Reutner-Fischer | e87d795 | 2007-04-10 18:43:27 +0000 | [diff] [blame] | 104 | argc -= 2; |
| 105 | argv += 2; |
| 106 | #if ENABLE_FEATURE_IP_ADDRESS |
| 107 | if (key == IP_addr) |
| 108 | ip_func = do_ipaddr; |
| 109 | #endif |
| 110 | #if ENABLE_FEATURE_IP_ROUTE |
| 111 | if (key == IP_route) |
| 112 | ip_func = do_iproute; |
| 113 | #endif |
| 114 | #if ENABLE_FEATURE_IP_LINK |
| 115 | if (key == IP_link) |
| 116 | ip_func = do_iplink; |
| 117 | #endif |
| 118 | #if ENABLE_FEATURE_IP_TUNNEL |
| 119 | if (key == IP_tunnel || key == IP_tunl) |
| 120 | ip_func = do_iptunnel; |
| 121 | #endif |
| 122 | #if ENABLE_FEATURE_IP_RULE |
| 123 | if (key == IP_rule) |
| 124 | ip_func = do_iprule; |
| 125 | #endif |
Glenn L McGrath | f112daa | 2002-12-01 23:04:06 +0000 | [diff] [blame] | 126 | } |
Denis Vlasenko | 990d0f6 | 2007-07-24 15:54:42 +0000 | [diff] [blame] | 127 | return ip_func(argc, argv); |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 128 | } |
Denis Vlasenko | d46e6d1 | 2007-05-17 12:58:30 +0000 | [diff] [blame] | 129 | |
| 130 | #endif /* any of ENABLE_FEATURE_IP_xxx is 1 */ |