blob: de3a65bae92fed29654737dad1a780ab8dba5eed [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/*
Denys Vlasenko0ef64bd2010-08-16 20:14:46 +02003 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
Glenn L McGrath9a2d2722002-11-10 01:33:55 +00004 *
Denys Vlasenkoe0a62202010-07-24 23:26:58 +02005 * Authors: Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru>
Glenn L McGrath9a2d2722002-11-10 01:33:55 +00006 *
7 * Changes:
Denys Vlasenkofb132e42010-10-29 11:46:52 +02008 * Rani Assaf <rani@magic.metawire.com> 980929: resolve addresses
Bernhard Reutner-Fischer6c4dade2008-09-25 12:13:34 +00009 * Bernhard Reutner-Fischer rewrote to use index_in_substr_array
Glenn L McGrath9a2d2722002-11-10 01:33:55 +000010 */
Denys Vlasenko47367e12016-11-23 09:05:14 +010011//config:config IP
Denys Vlasenko4eed2c62017-07-18 22:01:24 +020012//config: bool "ip (34 kb)"
Denys Vlasenko47367e12016-11-23 09:05:14 +010013//config: default y
14//config: select PLATFORM_LINUX
15//config: help
16//config: The "ip" applet is a TCP/IP interface configuration and routing
17//config: utility. You generally don't need "ip" to use busybox with
18//config: TCP/IP.
19//config:
Denys Vlasenko7c5dea32016-12-22 22:30:13 +010020//config:config IPADDR
Denys Vlasenko4eed2c62017-07-18 22:01:24 +020021//config: bool "ipaddr (14 kb)"
Denys Vlasenko7c5dea32016-12-22 22:30:13 +010022//config: default y
23//config: select FEATURE_IP_ADDRESS
24//config: select PLATFORM_LINUX
25//config: help
26//config: Support short form of ip addr: ipaddr
27//config:
28//config:config IPLINK
Denys Vlasenko4eed2c62017-07-18 22:01:24 +020029//config: bool "iplink (16 kb)"
Denys Vlasenko7c5dea32016-12-22 22:30:13 +010030//config: default y
31//config: select FEATURE_IP_LINK
32//config: select PLATFORM_LINUX
33//config: help
34//config: Support short form of ip link: iplink
35//config:
36//config:config IPROUTE
Denys Vlasenko4eed2c62017-07-18 22:01:24 +020037//config: bool "iproute (15 kb)"
Denys Vlasenko7c5dea32016-12-22 22:30:13 +010038//config: default y
39//config: select FEATURE_IP_ROUTE
40//config: select PLATFORM_LINUX
41//config: help
42//config: Support short form of ip route: iproute
43//config:
44//config:config IPTUNNEL
Denys Vlasenko4eed2c62017-07-18 22:01:24 +020045//config: bool "iptunnel (9.6 kb)"
Denys Vlasenko7c5dea32016-12-22 22:30:13 +010046//config: default y
47//config: select FEATURE_IP_TUNNEL
48//config: select PLATFORM_LINUX
49//config: help
50//config: Support short form of ip tunnel: iptunnel
51//config:
52//config:config IPRULE
Denys Vlasenko4eed2c62017-07-18 22:01:24 +020053//config: bool "iprule (10 kb)"
Denys Vlasenko7c5dea32016-12-22 22:30:13 +010054//config: default y
55//config: select FEATURE_IP_RULE
56//config: select PLATFORM_LINUX
57//config: help
58//config: Support short form of ip rule: iprule
59//config:
60//config:config IPNEIGH
Denys Vlasenko4eed2c62017-07-18 22:01:24 +020061//config: bool "ipneigh (8.3 kb)"
Denys Vlasenko7c5dea32016-12-22 22:30:13 +010062//config: default y
63//config: select FEATURE_IP_NEIGH
64//config: select PLATFORM_LINUX
65//config: help
66//config: Support short form of ip neigh: ipneigh
67//config:
Denys Vlasenko47367e12016-11-23 09:05:14 +010068//config:config FEATURE_IP_ADDRESS
69//config: bool "ip address"
70//config: default y
Denys Vlasenko7c5dea32016-12-22 22:30:13 +010071//config: depends on IP || IPADDR
Denys Vlasenko47367e12016-11-23 09:05:14 +010072//config: help
73//config: Address manipulation support for the "ip" applet.
74//config:
75//config:config FEATURE_IP_LINK
76//config: bool "ip link"
77//config: default y
Denys Vlasenko7c5dea32016-12-22 22:30:13 +010078//config: depends on IP || IPLINK
Denys Vlasenko47367e12016-11-23 09:05:14 +010079//config: help
80//config: Configure network devices with "ip".
81//config:
82//config:config FEATURE_IP_ROUTE
83//config: bool "ip route"
84//config: default y
Denys Vlasenko7c5dea32016-12-22 22:30:13 +010085//config: depends on IP || IPROUTE
Denys Vlasenko47367e12016-11-23 09:05:14 +010086//config: help
87//config: Add support for routing table management to "ip".
88//config:
89//config:config FEATURE_IP_ROUTE_DIR
90//config: string "ip route configuration directory"
91//config: default "/etc/iproute2"
92//config: depends on FEATURE_IP_ROUTE
93//config: help
94//config: Location of the "ip" applet routing configuration.
95//config:
96//config:config FEATURE_IP_TUNNEL
97//config: bool "ip tunnel"
98//config: default y
Denys Vlasenko7c5dea32016-12-22 22:30:13 +010099//config: depends on IP || IPTUNNEL
Denys Vlasenko47367e12016-11-23 09:05:14 +0100100//config: help
101//config: Add support for tunneling commands to "ip".
102//config:
103//config:config FEATURE_IP_RULE
104//config: bool "ip rule"
105//config: default y
Denys Vlasenko7c5dea32016-12-22 22:30:13 +0100106//config: depends on IP || IPRULE
Denys Vlasenko47367e12016-11-23 09:05:14 +0100107//config: help
108//config: Add support for rule commands to "ip".
109//config:
110//config:config FEATURE_IP_NEIGH
111//config: bool "ip neighbor"
112//config: default y
Denys Vlasenko7c5dea32016-12-22 22:30:13 +0100113//config: depends on IP || IPNEIGH
Denys Vlasenko47367e12016-11-23 09:05:14 +0100114//config: help
115//config: Add support for neighbor commands to "ip".
116//config:
Denys Vlasenko47367e12016-11-23 09:05:14 +0100117//config:config FEATURE_IP_RARE_PROTOCOLS
118//config: bool "Support displaying rarely used link types"
119//config: default n
Denys Vlasenko7c5dea32016-12-22 22:30:13 +0100120//config: depends on IP || IPADDR || IPLINK || IPROUTE || IPTUNNEL || IPRULE || IPNEIGH
Denys Vlasenko47367e12016-11-23 09:05:14 +0100121//config: help
122//config: If you are not going to use links of type "frad", "econet",
123//config: "bif" etc, you probably don't need to enable this.
124//config: Ethernet, wireless, infrared, ppp/slip, ip tunnelling
125//config: link types are supported without this option selected.
Denys Vlasenko47367e12016-11-23 09:05:14 +0100126
Denys Vlasenko47367e12016-11-23 09:05:14 +0100127//applet:IF_IP(APPLET(ip, BB_DIR_SBIN, BB_SUID_DROP))
Denys Vlasenko47367e12016-11-23 09:05:14 +0100128//applet:IF_IPADDR(APPLET(ipaddr, BB_DIR_SBIN, BB_SUID_DROP))
129//applet:IF_IPLINK(APPLET(iplink, BB_DIR_SBIN, BB_SUID_DROP))
130//applet:IF_IPROUTE(APPLET(iproute, BB_DIR_SBIN, BB_SUID_DROP))
131//applet:IF_IPRULE(APPLET(iprule, BB_DIR_SBIN, BB_SUID_DROP))
132//applet:IF_IPTUNNEL(APPLET(iptunnel, BB_DIR_SBIN, BB_SUID_DROP))
Denys Vlasenko6bfab0c2016-11-23 09:18:05 +0100133//applet:IF_IPNEIGH(APPLET(ipneigh, BB_DIR_SBIN, BB_SUID_DROP))
Denys Vlasenko47367e12016-11-23 09:05:14 +0100134
135//kbuild:lib-$(CONFIG_IP) += ip.o
Denys Vlasenko7c5dea32016-12-22 22:30:13 +0100136//kbuild:lib-$(CONFIG_IPADDR) += ip.o
137//kbuild:lib-$(CONFIG_IPLINK) += ip.o
138//kbuild:lib-$(CONFIG_IPROUTE) += ip.o
139//kbuild:lib-$(CONFIG_IPRULE) += ip.o
140//kbuild:lib-$(CONFIG_IPTUNNEL) += ip.o
141//kbuild:lib-$(CONFIG_IPNEIGH) += ip.o
Glenn L McGrath9a2d2722002-11-10 01:33:55 +0000142
Denys Vlasenko4eaa0f72017-04-07 18:14:46 +0200143//--------------123456789.123456789.123456789.123456789.123456789.123456789.123456789.123....79
Pere Orga5bc8c002011-04-11 03:29:49 +0200144//usage:#define ipaddr_trivial_usage
Denys Vlasenko12389882017-01-21 14:27:07 +0100145//usage: "add|del IFADDR dev IFACE | show|flush [dev IFACE] [to PREFIX]"
Pere Orga5bc8c002011-04-11 03:29:49 +0200146//usage:#define ipaddr_full_usage "\n\n"
Denys Vlasenko7121bb82017-04-07 18:22:41 +0200147//usage: "ipaddr add|change|replace|delete dev IFACE IFADDR\n"
148//usage: " IFADDR := PREFIX | ADDR peer PREFIX [broadcast ADDR|+|-]\n"
149//usage: " [anycast ADDR] [label STRING] [scope SCOPE]\n"
150//usage: " PREFIX := ADDR[/MASK]\n"
151//usage: " SCOPE := [host|link|global|NUMBER]\n"
152//usage: "ipaddr show|flush [dev IFACE] [scope SCOPE] [to PREFIX] [label PATTERN]"
Pere Orga5bc8c002011-04-11 03:29:49 +0200153//usage:
Denys Vlasenko4eaa0f72017-04-07 18:14:46 +0200154//--------------123456789.123456789.123456789.123456789.123456789.123456789.123456789.123....79
Pere Orga5bc8c002011-04-11 03:29:49 +0200155//usage:#define iplink_trivial_usage
Denys Vlasenko12389882017-01-21 14:27:07 +0100156//usage: "set IFACE [up|down] [arp on|off] | show [IFACE]"
Pere Orga5bc8c002011-04-11 03:29:49 +0200157//usage:#define iplink_full_usage "\n\n"
Denys Vlasenko2d4823b2017-04-06 16:06:04 +0200158//usage: "iplink set IFACE [up|down] [arp on|off] [multicast on|off] [promisc on|off]\n"
159//usage: " [mtu NUM] [name NAME] [qlen NUM] [address MAC]\n"
Denys Vlasenko12389882017-01-21 14:27:07 +0100160//usage: "iplink show [IFACE]"
Pere Orga5bc8c002011-04-11 03:29:49 +0200161//usage:
Denys Vlasenko4eaa0f72017-04-07 18:14:46 +0200162//--------------123456789.123456789.123456789.123456789.123456789.123456789.123456789.123....79
Pere Orga5bc8c002011-04-11 03:29:49 +0200163//usage:#define iproute_trivial_usage
Denys Vlasenkof3d705f2017-01-21 03:46:35 +0100164//usage: "list|flush|add|del|change|append|replace|test ROUTE"
Pere Orga5bc8c002011-04-11 03:29:49 +0200165//usage:#define iproute_full_usage "\n\n"
Denys Vlasenkof3d705f2017-01-21 03:46:35 +0100166//usage: "iproute list|flush SELECTOR\n"
Denys Vlasenko53782d92011-12-06 18:59:55 +0100167//usage: " SELECTOR := [root PREFIX] [match PREFIX] [proto RTPROTO]\n"
Denys Vlasenko7121bb82017-04-07 18:22:41 +0200168//usage: " PREFIX := default|ADDR[/MASK]\n"
Denys Vlasenko4eaa0f72017-04-07 18:14:46 +0200169//usage: "iproute get ADDR [from ADDR iif IFACE]\n"
Denys Vlasenko1140bf32017-04-06 17:54:38 +0200170//usage: " [oif IFACE] [tos TOS]\n"
171//usage: "iproute add|del|change|append|replace|test ROUTE\n"
172//usage: " ROUTE := NODE_SPEC [INFO_SPEC]\n"
173//usage: " NODE_SPEC := PREFIX"IF_FEATURE_IP_RULE(" [table TABLE_ID]")" [proto RTPROTO] [scope SCOPE] [metric METRIC]\n"
174//usage: " INFO_SPEC := NH OPTIONS\n"
Denys Vlasenko4eaa0f72017-04-07 18:14:46 +0200175//usage: " NH := [via [inet|inet6] ADDR] [dev IFACE] [src ADDR] [onlink]\n"
Denys Vlasenkod5342a12017-04-07 17:00:53 +0200176//usage: " OPTIONS := [mtu [lock] NUM] [advmss [lock] NUM]"
Denys Vlasenko1140bf32017-04-06 17:54:38 +0200177//upstream man ip-route:
178//======================
179//ip route { show | flush } SELECTOR
180//ip route save SELECTOR
181//ip route restore
182//ip route get ADDRESS [ from ADDRESS iif STRING ] [ oif STRING ] [ tos TOS ]
183//ip route { add | del | change | append | replace } ROUTE
184//SELECTOR := [ root PREFIX ] [ match PREFIX ] [ exact PREFIX ] [ table TABLE_ID ] [ proto RTPROTO ] [ type TYPE ] [ scope SCOPE ]
185//ROUTE := NODE_SPEC [ INFO_SPEC ]
186//NODE_SPEC := [ TYPE ] PREFIX [ tos TOS ] [ table TABLE_ID ] [ proto RTPROTO ] [ scope SCOPE ] [ metric METRIC ]
187//INFO_SPEC := NH OPTIONS FLAGS [ nexthop NH ] ...
188//NH := [ encap ENCAP ] [ via [ FAMILY ] ADDRESS ] [ dev STRING ] [ weight NUMBER ] NHFLAGS
189// ..............................................................^ I guess [src ADDRESS] should be here
190//FAMILY := [ inet | inet6 | ipx | dnet | mpls | bridge | link ]
191//OPTIONS := FLAGS [ mtu NUMBER ] [ advmss NUMBER ] [ as [ to ] ADDRESS ] rtt TIME ] [ rttvar TIME ] [ reordering NUMBER ] [ window NUMBER ] [ cwnd NUMBER ] [ ssthresh REALM ] [ realms REALM ]
192// [ rto_min TIME ] [ initcwnd NUMBER ] [ initrwnd NUMBER ] [ features FEATURES ] [ quickack BOOL ] [ congctl NAME ] [ pref PREF ] [ expires TIME ]
193//TYPE := [ unicast | local | broadcast | multicast | throw | unreachable | prohibit | blackhole | nat ]
194//TABLE_ID := [ local | main | default | all | NUMBER ]
195//SCOPE := [ host | link | global | NUMBER ]
196//NHFLAGS := [ onlink | pervasive ]
197//RTPROTO := [ kernel | boot | static | NUMBER ]
198//FEATURES := [ ecn | ]
199//PREF := [ low | medium | high ]
200//ENCAP := [ MPLS | IP ]
201//ENCAP_MPLS := mpls [ LABEL ]
202//ENCAP_IP := ip id TUNNEL_ID dst REMOTE_IP [ tos TOS ] [ ttl TTL ]
Pere Orga5bc8c002011-04-11 03:29:49 +0200203//usage:
Denys Vlasenko4eaa0f72017-04-07 18:14:46 +0200204//--------------123456789.123456789.123456789.123456789.123456789.123456789.123456789.123....79
Pere Orga5bc8c002011-04-11 03:29:49 +0200205//usage:#define iprule_trivial_usage
Denys Vlasenko12389882017-01-21 14:27:07 +0100206//usage: "[list] | add|del SELECTOR ACTION"
Pere Orga5bc8c002011-04-11 03:29:49 +0200207//usage:#define iprule_full_usage "\n\n"
Pere Orga5bc8c002011-04-11 03:29:49 +0200208//usage: " SELECTOR := [from PREFIX] [to PREFIX] [tos TOS] [fwmark FWMARK]\n"
Denys Vlasenko12389882017-01-21 14:27:07 +0100209//usage: " [dev IFACE] [pref NUMBER]\n"
Denys Vlasenko4eaa0f72017-04-07 18:14:46 +0200210//usage: " ACTION := [table TABLE_ID] [nat ADDR]\n"
Denys Vlasenko8908c1d2017-01-21 03:56:46 +0100211//usage: " [prohibit|reject|unreachable]\n"
Pere Orga5bc8c002011-04-11 03:29:49 +0200212//usage: " [realms [SRCREALM/]DSTREALM]\n"
Denys Vlasenko8908c1d2017-01-21 03:56:46 +0100213//usage: " TABLE_ID := [local|main|default|NUMBER]"
Pere Orga5bc8c002011-04-11 03:29:49 +0200214//usage:
Denys Vlasenko4eaa0f72017-04-07 18:14:46 +0200215//--------------123456789.123456789.123456789.123456789.123456789.123456789.123456789.123....79
Pere Orga5bc8c002011-04-11 03:29:49 +0200216//usage:#define iptunnel_trivial_usage
Denys Vlasenkof3d705f2017-01-21 03:46:35 +0100217//usage: "add|change|del|show [NAME]\n"
218//usage: " [mode ipip|gre|sit]\n"
Pere Orga5bc8c002011-04-11 03:29:49 +0200219//usage: " [remote ADDR] [local ADDR] [ttl TTL]"
220//usage:#define iptunnel_full_usage "\n\n"
Denys Vlasenkof3d705f2017-01-21 03:46:35 +0100221//usage: "iptunnel add|change|del|show [NAME]\n"
222//usage: " [mode ipip|gre|sit] [remote ADDR] [local ADDR]\n"
Pere Orga5bc8c002011-04-11 03:29:49 +0200223//usage: " [[i|o]seq] [[i|o]key KEY] [[i|o]csum]\n"
224//usage: " [ttl TTL] [tos TOS] [[no]pmtudisc] [dev PHYS_DEV]"
Curt Brune69934702015-10-14 12:53:47 +0200225//usage:
226//usage:#define ipneigh_trivial_usage
Denys Vlasenkof3d705f2017-01-21 03:46:35 +0100227//usage: "show|flush [to PREFIX] [dev DEV] [nud STATE]"
Denys Vlasenko12389882017-01-21 14:27:07 +0100228//usage:#define ipneigh_full_usage ""
229//usage:
230//usage:#if ENABLE_FEATURE_IP_ADDRESS || ENABLE_FEATURE_IP_ROUTE
231//usage:# define IP_BAR_LINK "|"
232//usage:#else
233//usage:# define IP_BAR_LINK ""
234//usage:#endif
235//usage:#if ENABLE_FEATURE_IP_ADDRESS || ENABLE_FEATURE_IP_ROUTE || ENABLE_FEATURE_IP_LINK
236//usage:# define IP_BAR_TUNNEL "|"
237//usage:#else
238//usage:# define IP_BAR_TUNNEL ""
239//usage:#endif
240//usage:#if ENABLE_FEATURE_IP_ADDRESS || ENABLE_FEATURE_IP_ROUTE || ENABLE_FEATURE_IP_LINK || ENABLE_FEATURE_IP_TUNNEL
241//usage:# define IP_BAR_NEIGH "|"
242//usage:#else
243//usage:# define IP_BAR_NEIGH ""
244//usage:#endif
245//usage:#if ENABLE_FEATURE_IP_ADDRESS || ENABLE_FEATURE_IP_ROUTE || ENABLE_FEATURE_IP_LINK || ENABLE_FEATURE_IP_TUNNEL || ENABLE_FEATURE_IP_NEIGH
246//usage:# define IP_BAR_RULE "|"
247//usage:#else
248//usage:# define IP_BAR_RULE ""
249//usage:#endif
250//usage:
251//usage:#define ip_trivial_usage
252//usage: "[OPTIONS] "
253//usage: IF_FEATURE_IP_ADDRESS("address")
254//usage: IF_FEATURE_IP_ROUTE( IF_FEATURE_IP_ADDRESS("|")"route")
255//usage: IF_FEATURE_IP_LINK( IP_BAR_LINK "link")
256//usage: IF_FEATURE_IP_TUNNEL( IP_BAR_TUNNEL"tunnel")
257//usage: IF_FEATURE_IP_NEIGH( IP_BAR_NEIGH "neigh")
258//usage: IF_FEATURE_IP_RULE( IP_BAR_RULE "rule")
259//usage: " [COMMAND]"
260//usage:#define ip_full_usage "\n\n"
261//usage: "OPTIONS := -f[amily] inet|inet6|link | -o[neline]\n"
262//usage: "COMMAND :="
263//usage: IF_FEATURE_IP_ADDRESS("\n"
264//usage: "ip addr "ipaddr_trivial_usage)
265//usage: IF_FEATURE_IP_ROUTE("\n"
266//usage: "ip route "iproute_trivial_usage)
267//usage: IF_FEATURE_IP_LINK("\n"
268//usage: "ip link "iplink_trivial_usage)
269//usage: IF_FEATURE_IP_TUNNEL("\n"
270//usage: "ip tunnel "iptunnel_trivial_usage)
271//usage: IF_FEATURE_IP_NEIGH("\n"
272//usage: "ip neigh "ipneigh_trivial_usage)
273//usage: IF_FEATURE_IP_RULE("\n"
274//usage: "ip rule "iprule_trivial_usage)
Pere Orga5bc8c002011-04-11 03:29:49 +0200275
Denis Vlasenkob6adbf12007-05-26 19:00:18 +0000276#include "libbb.h"
Glenn L McGrath9a2d2722002-11-10 01:33:55 +0000277
Bernhard Reutner-Fischerab187822005-10-26 10:47:26 +0000278#include "libiproute/utils.h"
279#include "libiproute/ip_common.h"
Glenn L McGrath9a2d2722002-11-10 01:33:55 +0000280
Denys Vlasenko2e9b5512010-07-24 23:27:38 +0200281typedef int FAST_FUNC (*ip_func_ptr_t)(char**);
Denys Vlasenkoe0a62202010-07-24 23:26:58 +0200282
Denys Vlasenko7c5dea32016-12-22 22:30:13 +0100283#if ENABLE_IPADDR \
284 || ENABLE_IPLINK \
285 || ENABLE_IPROUTE \
286 || ENABLE_IPRULE \
287 || ENABLE_IPTUNNEL \
288 || ENABLE_IPNEIGH
Denys Vlasenkoe0a62202010-07-24 23:26:58 +0200289static int ip_do(ip_func_ptr_t ip_func, char **argv)
Bernhard Reutner-Fischer07c394e2007-04-10 20:11:12 +0000290{
Denis Vlasenko3246c0d2008-12-04 12:15:19 +0000291 argv = ip_parse_common_args(argv + 1);
Denis Vlasenkoed6a49c2007-11-18 22:56:25 +0000292 return ip_func(argv);
Bernhard Reutner-Fischer07c394e2007-04-10 20:11:12 +0000293}
Denys Vlasenko7c5dea32016-12-22 22:30:13 +0100294#endif
Bernhard Reutner-Fischer07c394e2007-04-10 20:11:12 +0000295
Denys Vlasenko7c5dea32016-12-22 22:30:13 +0100296#if ENABLE_IPADDR
Denis Vlasenko9b49a5e2007-10-11 10:05:36 +0000297int ipaddr_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
Denis Vlasenkoa60f84e2008-07-05 09:18:54 +0000298int ipaddr_main(int argc UNUSED_PARAM, char **argv)
Bernhard Reutner-Fischer07c394e2007-04-10 20:11:12 +0000299{
Denis Vlasenko2570b2e2008-03-28 01:00:09 +0000300 return ip_do(do_ipaddr, argv);
Bernhard Reutner-Fischer07c394e2007-04-10 20:11:12 +0000301}
302#endif
Denys Vlasenko7c5dea32016-12-22 22:30:13 +0100303#if ENABLE_IPLINK
Denis Vlasenko9b49a5e2007-10-11 10:05:36 +0000304int iplink_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
Denis Vlasenkoa60f84e2008-07-05 09:18:54 +0000305int iplink_main(int argc UNUSED_PARAM, char **argv)
Bernhard Reutner-Fischer07c394e2007-04-10 20:11:12 +0000306{
Denis Vlasenko2570b2e2008-03-28 01:00:09 +0000307 return ip_do(do_iplink, argv);
Bernhard Reutner-Fischer07c394e2007-04-10 20:11:12 +0000308}
309#endif
Denys Vlasenko7c5dea32016-12-22 22:30:13 +0100310#if ENABLE_IPROUTE
Denis Vlasenko9b49a5e2007-10-11 10:05:36 +0000311int iproute_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
Denis Vlasenkoa60f84e2008-07-05 09:18:54 +0000312int iproute_main(int argc UNUSED_PARAM, char **argv)
Bernhard Reutner-Fischer07c394e2007-04-10 20:11:12 +0000313{
Denis Vlasenko2570b2e2008-03-28 01:00:09 +0000314 return ip_do(do_iproute, argv);
Bernhard Reutner-Fischer07c394e2007-04-10 20:11:12 +0000315}
316#endif
Denys Vlasenko7c5dea32016-12-22 22:30:13 +0100317#if ENABLE_IPRULE
Denis Vlasenko9b49a5e2007-10-11 10:05:36 +0000318int iprule_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
Denis Vlasenkoa60f84e2008-07-05 09:18:54 +0000319int iprule_main(int argc UNUSED_PARAM, char **argv)
Bernhard Reutner-Fischer07c394e2007-04-10 20:11:12 +0000320{
Denis Vlasenko2570b2e2008-03-28 01:00:09 +0000321 return ip_do(do_iprule, argv);
Bernhard Reutner-Fischer07c394e2007-04-10 20:11:12 +0000322}
323#endif
Denys Vlasenko7c5dea32016-12-22 22:30:13 +0100324#if ENABLE_IPTUNNEL
Denis Vlasenko9b49a5e2007-10-11 10:05:36 +0000325int iptunnel_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
Denis Vlasenkoa60f84e2008-07-05 09:18:54 +0000326int iptunnel_main(int argc UNUSED_PARAM, char **argv)
Bernhard Reutner-Fischer07c394e2007-04-10 20:11:12 +0000327{
Denis Vlasenko2570b2e2008-03-28 01:00:09 +0000328 return ip_do(do_iptunnel, argv);
Bernhard Reutner-Fischer07c394e2007-04-10 20:11:12 +0000329}
330#endif
Denys Vlasenko7c5dea32016-12-22 22:30:13 +0100331#if ENABLE_IPNEIGH
Curt Brune69934702015-10-14 12:53:47 +0200332int ipneigh_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
333int ipneigh_main(int argc UNUSED_PARAM, char **argv)
334{
335 return ip_do(do_ipneigh, argv);
336}
337#endif
Bernhard Reutner-Fischer07c394e2007-04-10 20:11:12 +0000338
Denys Vlasenko7c5dea32016-12-22 22:30:13 +0100339#if ENABLE_IP
340static int FAST_FUNC ip_print_help(char **argv UNUSED_PARAM)
341{
342 bb_show_usage();
343}
Bernhard Reutner-Fischer07c394e2007-04-10 20:11:12 +0000344
Denis Vlasenko9b49a5e2007-10-11 10:05:36 +0000345int ip_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
Denis Vlasenkoa60f84e2008-07-05 09:18:54 +0000346int ip_main(int argc UNUSED_PARAM, char **argv)
Glenn L McGrathf112daa2002-12-01 23:04:06 +0000347{
Denys Vlasenko7c5dea32016-12-22 22:30:13 +0100348 static const char keywords[] ALIGN1 = ""
Denis Vlasenko5e34ff22009-04-21 11:09:40 +0000349 IF_FEATURE_IP_ADDRESS("address\0")
350 IF_FEATURE_IP_ROUTE("route\0")
Denys Vlasenkoe0a62202010-07-24 23:26:58 +0200351 IF_FEATURE_IP_ROUTE("r\0")
Denis Vlasenko5e34ff22009-04-21 11:09:40 +0000352 IF_FEATURE_IP_LINK("link\0")
Denys Vlasenkoe0a62202010-07-24 23:26:58 +0200353 IF_FEATURE_IP_TUNNEL("tunnel\0")
354 IF_FEATURE_IP_TUNNEL("tunl\0")
Denis Vlasenko5e34ff22009-04-21 11:09:40 +0000355 IF_FEATURE_IP_RULE("rule\0")
Curt Brune69934702015-10-14 12:53:47 +0200356 IF_FEATURE_IP_NEIGH("neigh\0")
Denis Vlasenko990d0f62007-07-24 15:54:42 +0000357 ;
Denys Vlasenkoe0a62202010-07-24 23:26:58 +0200358 static const ip_func_ptr_t ip_func_ptrs[] = {
359 ip_print_help,
360 IF_FEATURE_IP_ADDRESS(do_ipaddr,)
361 IF_FEATURE_IP_ROUTE(do_iproute,)
362 IF_FEATURE_IP_ROUTE(do_iproute,)
363 IF_FEATURE_IP_LINK(do_iplink,)
364 IF_FEATURE_IP_TUNNEL(do_iptunnel,)
365 IF_FEATURE_IP_TUNNEL(do_iptunnel,)
366 IF_FEATURE_IP_RULE(do_iprule,)
Curt Brune69934702015-10-14 12:53:47 +0200367 IF_FEATURE_IP_NEIGH(do_ipneigh,)
Bernhard Reutner-Fischere87d7952007-04-10 18:43:27 +0000368 };
Denys Vlasenkoe0a62202010-07-24 23:26:58 +0200369 ip_func_ptr_t ip_func;
370 int key;
Bernhard Reutner-Fischere87d7952007-04-10 18:43:27 +0000371
Denis Vlasenkoed6a49c2007-11-18 22:56:25 +0000372 argv = ip_parse_common_args(argv + 1);
Denys Vlasenko7c5dea32016-12-22 22:30:13 +0100373 if (ARRAY_SIZE(ip_func_ptrs) > 1 && *argv)
374 key = index_in_substrings(keywords, *argv++);
375 else
376 key = -1;
Denys Vlasenkoe0a62202010-07-24 23:26:58 +0200377 ip_func = ip_func_ptrs[key + 1];
378
Denis Vlasenkoed6a49c2007-11-18 22:56:25 +0000379 return ip_func(argv);
Glenn L McGrath9a2d2722002-11-10 01:33:55 +0000380}
Denys Vlasenko7c5dea32016-12-22 22:30:13 +0100381#endif