"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 | 5af906e | 2006-11-05 18:05:09 +0000 | [diff] [blame] | 16 | #include "busybox.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 | |
Bernhard Reutner-Fischer | e87d795 | 2007-04-10 18:43:27 +0000 | [diff] [blame^] | 21 | static int ATTRIBUTE_NORETURN ip_print_help(int ATTRIBUTE_UNUSED ac, char ATTRIBUTE_UNUSED **av) |
| 22 | { |
| 23 | bb_show_usage(); |
| 24 | } |
Denis Vlasenko | 06af216 | 2007-02-03 17:28:39 +0000 | [diff] [blame] | 25 | int ip_main(int argc, char **argv); |
Glenn L McGrath | f112daa | 2002-12-01 23:04:06 +0000 | [diff] [blame] | 26 | int ip_main(int argc, char **argv) |
| 27 | { |
Bernhard Reutner-Fischer | e87d795 | 2007-04-10 18:43:27 +0000 | [diff] [blame^] | 28 | 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 McGrath | f112daa | 2002-12-01 23:04:06 +0000 | [diff] [blame] | 46 | ip_parse_common_args(&argc, &argv); |
Bernhard Reutner-Fischer | e87d795 | 2007-04-10 18:43:27 +0000 | [diff] [blame^] | 47 | 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 McGrath | f112daa | 2002-12-01 23:04:06 +0000 | [diff] [blame] | 71 | } |
Bernhard Reutner-Fischer | e87d795 | 2007-04-10 18:43:27 +0000 | [diff] [blame^] | 72 | return (ip_func(argc, argv)); |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 73 | } |