blob: accf90759eb1d9c1314147405f54f32f050cf6ca [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
Denys Vlasenko72089cf2017-07-21 09:50:55 +020016//config: The "ip" applet is a TCP/IP interface configuration and routing
Denys Vlasenko68b653b2017-07-27 10:53:09 +020017//config: utility.
18//config: Short forms (enabled below) are busybox-specific extensions.
19//config: The standard "ip" utility does not provide them. If you are
20//config: trying to be portable, it's better to use "ip CMD" forms.
Denys Vlasenko47367e12016-11-23 09:05:14 +010021//config:
Denys Vlasenko7c5dea32016-12-22 22:30:13 +010022//config:config IPADDR
Denys Vlasenko4eed2c62017-07-18 22:01:24 +020023//config: bool "ipaddr (14 kb)"
Denys Vlasenko7c5dea32016-12-22 22:30:13 +010024//config: default y
25//config: select FEATURE_IP_ADDRESS
26//config: select PLATFORM_LINUX
27//config: help
Denys Vlasenko68b653b2017-07-27 10:53:09 +020028//config: Short form of "ip addr"
Denys Vlasenko7c5dea32016-12-22 22:30:13 +010029//config:
30//config:config IPLINK
Denys Vlasenko4eed2c62017-07-18 22:01:24 +020031//config: bool "iplink (16 kb)"
Denys Vlasenko7c5dea32016-12-22 22:30:13 +010032//config: default y
33//config: select FEATURE_IP_LINK
34//config: select PLATFORM_LINUX
35//config: help
Denys Vlasenko68b653b2017-07-27 10:53:09 +020036//config: Short form of "ip link"
Denys Vlasenko7c5dea32016-12-22 22:30:13 +010037//config:
38//config:config IPROUTE
Denys Vlasenko4eed2c62017-07-18 22:01:24 +020039//config: bool "iproute (15 kb)"
Denys Vlasenko7c5dea32016-12-22 22:30:13 +010040//config: default y
41//config: select FEATURE_IP_ROUTE
42//config: select PLATFORM_LINUX
43//config: help
Denys Vlasenko68b653b2017-07-27 10:53:09 +020044//config: Short form of "ip route"
Denys Vlasenko7c5dea32016-12-22 22:30:13 +010045//config:
46//config:config IPTUNNEL
Denys Vlasenko4eed2c62017-07-18 22:01:24 +020047//config: bool "iptunnel (9.6 kb)"
Denys Vlasenko7c5dea32016-12-22 22:30:13 +010048//config: default y
49//config: select FEATURE_IP_TUNNEL
50//config: select PLATFORM_LINUX
51//config: help
Denys Vlasenko68b653b2017-07-27 10:53:09 +020052//config: Short form of "ip tunnel"
Denys Vlasenko7c5dea32016-12-22 22:30:13 +010053//config:
54//config:config IPRULE
Denys Vlasenko4eed2c62017-07-18 22:01:24 +020055//config: bool "iprule (10 kb)"
Denys Vlasenko7c5dea32016-12-22 22:30:13 +010056//config: default y
57//config: select FEATURE_IP_RULE
58//config: select PLATFORM_LINUX
59//config: help
Denys Vlasenko68b653b2017-07-27 10:53:09 +020060//config: Short form of "ip rule"
Denys Vlasenko7c5dea32016-12-22 22:30:13 +010061//config:
62//config:config IPNEIGH
Denys Vlasenko4eed2c62017-07-18 22:01:24 +020063//config: bool "ipneigh (8.3 kb)"
Denys Vlasenko7c5dea32016-12-22 22:30:13 +010064//config: default y
65//config: select FEATURE_IP_NEIGH
66//config: select PLATFORM_LINUX
67//config: help
Denys Vlasenko68b653b2017-07-27 10:53:09 +020068//config: Short form of "ip neigh"
Denys Vlasenko7c5dea32016-12-22 22:30:13 +010069//config:
Denys Vlasenko47367e12016-11-23 09:05:14 +010070//config:config FEATURE_IP_ADDRESS
71//config: bool "ip address"
72//config: default y
Denys Vlasenko7c5dea32016-12-22 22:30:13 +010073//config: depends on IP || IPADDR
Denys Vlasenko47367e12016-11-23 09:05:14 +010074//config: help
Denys Vlasenko72089cf2017-07-21 09:50:55 +020075//config: Address manipulation support for the "ip" applet.
Denys Vlasenko47367e12016-11-23 09:05:14 +010076//config:
77//config:config FEATURE_IP_LINK
78//config: bool "ip link"
79//config: default y
Denys Vlasenko7c5dea32016-12-22 22:30:13 +010080//config: depends on IP || IPLINK
Denys Vlasenko47367e12016-11-23 09:05:14 +010081//config: help
Denys Vlasenko72089cf2017-07-21 09:50:55 +020082//config: Configure network devices with "ip".
Denys Vlasenko47367e12016-11-23 09:05:14 +010083//config:
84//config:config FEATURE_IP_ROUTE
85//config: bool "ip route"
86//config: default y
Denys Vlasenko7c5dea32016-12-22 22:30:13 +010087//config: depends on IP || IPROUTE
Denys Vlasenko47367e12016-11-23 09:05:14 +010088//config: help
Denys Vlasenko72089cf2017-07-21 09:50:55 +020089//config: Add support for routing table management to "ip".
Denys Vlasenko47367e12016-11-23 09:05:14 +010090//config:
91//config:config FEATURE_IP_ROUTE_DIR
92//config: string "ip route configuration directory"
93//config: default "/etc/iproute2"
94//config: depends on FEATURE_IP_ROUTE
95//config: help
Denys Vlasenko72089cf2017-07-21 09:50:55 +020096//config: Location of the "ip" applet routing configuration.
Denys Vlasenko47367e12016-11-23 09:05:14 +010097//config:
98//config:config FEATURE_IP_TUNNEL
99//config: bool "ip tunnel"
100//config: default y
Denys Vlasenko7c5dea32016-12-22 22:30:13 +0100101//config: depends on IP || IPTUNNEL
Denys Vlasenko47367e12016-11-23 09:05:14 +0100102//config: help
Denys Vlasenko72089cf2017-07-21 09:50:55 +0200103//config: Add support for tunneling commands to "ip".
Denys Vlasenko47367e12016-11-23 09:05:14 +0100104//config:
105//config:config FEATURE_IP_RULE
106//config: bool "ip rule"
107//config: default y
Denys Vlasenko7c5dea32016-12-22 22:30:13 +0100108//config: depends on IP || IPRULE
Denys Vlasenko47367e12016-11-23 09:05:14 +0100109//config: help
Denys Vlasenko72089cf2017-07-21 09:50:55 +0200110//config: Add support for rule commands to "ip".
Denys Vlasenko47367e12016-11-23 09:05:14 +0100111//config:
112//config:config FEATURE_IP_NEIGH
113//config: bool "ip neighbor"
114//config: default y
Denys Vlasenko7c5dea32016-12-22 22:30:13 +0100115//config: depends on IP || IPNEIGH
Denys Vlasenko47367e12016-11-23 09:05:14 +0100116//config: help
Denys Vlasenko72089cf2017-07-21 09:50:55 +0200117//config: Add support for neighbor commands to "ip".
Denys Vlasenko47367e12016-11-23 09:05:14 +0100118//config:
Denys Vlasenko47367e12016-11-23 09:05:14 +0100119//config:config FEATURE_IP_RARE_PROTOCOLS
120//config: bool "Support displaying rarely used link types"
121//config: default n
Denys Vlasenko7c5dea32016-12-22 22:30:13 +0100122//config: depends on IP || IPADDR || IPLINK || IPROUTE || IPTUNNEL || IPRULE || IPNEIGH
Denys Vlasenko47367e12016-11-23 09:05:14 +0100123//config: help
Denys Vlasenko72089cf2017-07-21 09:50:55 +0200124//config: If you are not going to use links of type "frad", "econet",
125//config: "bif" etc, you probably don't need to enable this.
126//config: Ethernet, wireless, infrared, ppp/slip, ip tunnelling
127//config: link types are supported without this option selected.
Denys Vlasenko47367e12016-11-23 09:05:14 +0100128
Denys Vlasenkob63afea2017-09-18 15:45:13 +0200129//applet:IF_IP( APPLET_NOEXEC(ip , ip , BB_DIR_SBIN, BB_SUID_DROP, ip ))
130//applet:IF_IPADDR( APPLET_NOEXEC(ipaddr , ipaddr , BB_DIR_SBIN, BB_SUID_DROP, ipaddr ))
131//applet:IF_IPLINK( APPLET_NOEXEC(iplink , iplink , BB_DIR_SBIN, BB_SUID_DROP, iplink ))
132//applet:IF_IPROUTE( APPLET_NOEXEC(iproute , iproute , BB_DIR_SBIN, BB_SUID_DROP, iproute ))
133//applet:IF_IPRULE( APPLET_NOEXEC(iprule , iprule , BB_DIR_SBIN, BB_SUID_DROP, iprule ))
134//applet:IF_IPTUNNEL(APPLET_NOEXEC(iptunnel, iptunnel, BB_DIR_SBIN, BB_SUID_DROP, iptunnel))
135//applet:IF_IPNEIGH( APPLET_NOEXEC(ipneigh , ipneigh , BB_DIR_SBIN, BB_SUID_DROP, ipneigh ))
Denys Vlasenko47367e12016-11-23 09:05:14 +0100136
137//kbuild:lib-$(CONFIG_IP) += ip.o
Denys Vlasenko7c5dea32016-12-22 22:30:13 +0100138//kbuild:lib-$(CONFIG_IPADDR) += ip.o
139//kbuild:lib-$(CONFIG_IPLINK) += ip.o
140//kbuild:lib-$(CONFIG_IPROUTE) += ip.o
141//kbuild:lib-$(CONFIG_IPRULE) += ip.o
142//kbuild:lib-$(CONFIG_IPTUNNEL) += ip.o
143//kbuild:lib-$(CONFIG_IPNEIGH) += ip.o
Glenn L McGrath9a2d2722002-11-10 01:33:55 +0000144
Denys Vlasenko4eaa0f72017-04-07 18:14:46 +0200145//--------------123456789.123456789.123456789.123456789.123456789.123456789.123456789.123....79
Pere Orga5bc8c002011-04-11 03:29:49 +0200146//usage:#define ipaddr_trivial_usage
Denys Vlasenko12389882017-01-21 14:27:07 +0100147//usage: "add|del IFADDR dev IFACE | show|flush [dev IFACE] [to PREFIX]"
Pere Orga5bc8c002011-04-11 03:29:49 +0200148//usage:#define ipaddr_full_usage "\n\n"
Denys Vlasenko7121bb82017-04-07 18:22:41 +0200149//usage: "ipaddr add|change|replace|delete dev IFACE IFADDR\n"
150//usage: " IFADDR := PREFIX | ADDR peer PREFIX [broadcast ADDR|+|-]\n"
151//usage: " [anycast ADDR] [label STRING] [scope SCOPE]\n"
152//usage: " PREFIX := ADDR[/MASK]\n"
153//usage: " SCOPE := [host|link|global|NUMBER]\n"
154//usage: "ipaddr show|flush [dev IFACE] [scope SCOPE] [to PREFIX] [label PATTERN]"
Pere Orga5bc8c002011-04-11 03:29:49 +0200155//usage:
Denys Vlasenko4eaa0f72017-04-07 18:14:46 +0200156//--------------123456789.123456789.123456789.123456789.123456789.123456789.123456789.123....79
Pere Orga5bc8c002011-04-11 03:29:49 +0200157//usage:#define iplink_trivial_usage
Jan Luebbe79cda952018-02-20 19:28:02 +0100158//usage: /*Usage:iplink*/"set IFACE [up|down] [arp on|off] [multicast on|off]\n"
Jan Luebbee789c3b2018-02-14 14:05:27 +0100159//usage: " [promisc on|off] [mtu NUM] [name NAME] [qlen NUM] [address MAC]\n"
160//usage: " [master IFACE | nomaster]\n"
Jan Luebbe79cda952018-02-20 19:28:02 +0100161// * short help shows only "set" command, long help continues (with just one "\n")
162// * and shows all other commands:
163//usage:#define iplink_full_usage "\n"
164//usage: "iplink add [link IFACE] IFACE [address MAC] type TYPE [ARGS]\n"
165//usage: "iplink delete IFACE type TYPE [ARGS]\n"
166//usage: " TYPE ARGS := vlan VLANARGS | vrf table NUM\n"
167//usage: " VLANARGS := id VLANID [protocol 802.1q|802.1ad] [reorder_hdr on|off]\n"
168//usage: " [gvrp on|off] [mvrp on|off] [loose_binding on|off]\n"
Denys Vlasenko12389882017-01-21 14:27:07 +0100169//usage: "iplink show [IFACE]"
Jan Luebbe79cda952018-02-20 19:28:02 +0100170//upstream man ip-link:
171//=====================
172//ip link add [link DEV] [ name ] NAME
173// [ txqueuelen PACKETS ]
174// [ address LLADDR ]
175// [ broadcast LLADDR ]
176// [ mtu MTU ] [index IDX ]
177// [ numtxqueues QUEUE_COUNT ]
178// [ numrxqueues QUEUE_COUNT ]
179// type TYPE [ ARGS ]
180// ip link delete { DEVICE | dev DEVICE | group DEVGROUP } type TYPE [ ARGS ]
181// ip link set { DEVICE | dev DEVICE | group DEVGROUP } [ { up | down } ]
182// [ arp { on | off } ]
183// [ dynamic { on | off } ]
184// [ multicast { on | off } ]
185// [ allmulticast { on | off } ]
186// [ promisc { on | off } ]
187// [ trailers { on | off } ]
188// [ txqueuelen PACKETS ]
189// [ name NEWNAME ]
190// [ address LLADDR ]
191// [ broadcast LLADDR ]
192// [ mtu MTU ]
193// [ netns { PID | NAME } ]
194// [ link-netnsid ID ]
195// [ alias NAME ]
196// [ vf NUM [ mac LLADDR ]
197// [ vlan VLANID [ qos VLAN-QOS ] ]
198// [ rate TXRATE ]
199// [ spoofchk { on | off} ]
200// [ query_rss { on | off} ]
201// [ state { auto | enable | disable} ] ]
202// [ trust { on | off} ] ]
203// [ master DEVICE ]
204// [ nomaster ]
205// [ addrgenmode { eui64 | none | stable_secret | random } ]
206// [ protodown { on | off } ]
207// ip link show [ DEVICE | group GROUP ] [up] [master DEV] [type TYPE]
208// ip link help [ TYPE ]
209//TYPE := { vlan | veth | vcan | dummy | ifb | macvlan | macvtap |
210// bridge | bond | ipoib | ip6tnl | ipip | sit | vxlan |
211// gre | gretap | ip6gre | ip6gretap | vti | nlmon |
212// bond_slave | ipvlan | geneve | bridge_slave | vrf }
Pere Orga5bc8c002011-04-11 03:29:49 +0200213//usage:
Denys Vlasenko4eaa0f72017-04-07 18:14:46 +0200214//--------------123456789.123456789.123456789.123456789.123456789.123456789.123456789.123....79
Pere Orga5bc8c002011-04-11 03:29:49 +0200215//usage:#define iproute_trivial_usage
Denys Vlasenkof3d705f2017-01-21 03:46:35 +0100216//usage: "list|flush|add|del|change|append|replace|test ROUTE"
Pere Orga5bc8c002011-04-11 03:29:49 +0200217//usage:#define iproute_full_usage "\n\n"
Denys Vlasenkof3d705f2017-01-21 03:46:35 +0100218//usage: "iproute list|flush SELECTOR\n"
Denys Vlasenko53782d92011-12-06 18:59:55 +0100219//usage: " SELECTOR := [root PREFIX] [match PREFIX] [proto RTPROTO]\n"
Denys Vlasenko7121bb82017-04-07 18:22:41 +0200220//usage: " PREFIX := default|ADDR[/MASK]\n"
Denys Vlasenko4eaa0f72017-04-07 18:14:46 +0200221//usage: "iproute get ADDR [from ADDR iif IFACE]\n"
Denys Vlasenko1140bf32017-04-06 17:54:38 +0200222//usage: " [oif IFACE] [tos TOS]\n"
223//usage: "iproute add|del|change|append|replace|test ROUTE\n"
224//usage: " ROUTE := NODE_SPEC [INFO_SPEC]\n"
225//usage: " NODE_SPEC := PREFIX"IF_FEATURE_IP_RULE(" [table TABLE_ID]")" [proto RTPROTO] [scope SCOPE] [metric METRIC]\n"
226//usage: " INFO_SPEC := NH OPTIONS\n"
Denys Vlasenko4eaa0f72017-04-07 18:14:46 +0200227//usage: " NH := [via [inet|inet6] ADDR] [dev IFACE] [src ADDR] [onlink]\n"
Denys Vlasenkod5342a12017-04-07 17:00:53 +0200228//usage: " OPTIONS := [mtu [lock] NUM] [advmss [lock] NUM]"
Denys Vlasenko1140bf32017-04-06 17:54:38 +0200229//upstream man ip-route:
230//======================
231//ip route { show | flush } SELECTOR
232//ip route save SELECTOR
233//ip route restore
234//ip route get ADDRESS [ from ADDRESS iif STRING ] [ oif STRING ] [ tos TOS ]
235//ip route { add | del | change | append | replace } ROUTE
236//SELECTOR := [ root PREFIX ] [ match PREFIX ] [ exact PREFIX ] [ table TABLE_ID ] [ proto RTPROTO ] [ type TYPE ] [ scope SCOPE ]
237//ROUTE := NODE_SPEC [ INFO_SPEC ]
238//NODE_SPEC := [ TYPE ] PREFIX [ tos TOS ] [ table TABLE_ID ] [ proto RTPROTO ] [ scope SCOPE ] [ metric METRIC ]
239//INFO_SPEC := NH OPTIONS FLAGS [ nexthop NH ] ...
240//NH := [ encap ENCAP ] [ via [ FAMILY ] ADDRESS ] [ dev STRING ] [ weight NUMBER ] NHFLAGS
241// ..............................................................^ I guess [src ADDRESS] should be here
242//FAMILY := [ inet | inet6 | ipx | dnet | mpls | bridge | link ]
243//OPTIONS := FLAGS [ mtu NUMBER ] [ advmss NUMBER ] [ as [ to ] ADDRESS ] rtt TIME ] [ rttvar TIME ] [ reordering NUMBER ] [ window NUMBER ] [ cwnd NUMBER ] [ ssthresh REALM ] [ realms REALM ]
244// [ rto_min TIME ] [ initcwnd NUMBER ] [ initrwnd NUMBER ] [ features FEATURES ] [ quickack BOOL ] [ congctl NAME ] [ pref PREF ] [ expires TIME ]
245//TYPE := [ unicast | local | broadcast | multicast | throw | unreachable | prohibit | blackhole | nat ]
246//TABLE_ID := [ local | main | default | all | NUMBER ]
247//SCOPE := [ host | link | global | NUMBER ]
248//NHFLAGS := [ onlink | pervasive ]
249//RTPROTO := [ kernel | boot | static | NUMBER ]
250//FEATURES := [ ecn | ]
251//PREF := [ low | medium | high ]
252//ENCAP := [ MPLS | IP ]
253//ENCAP_MPLS := mpls [ LABEL ]
254//ENCAP_IP := ip id TUNNEL_ID dst REMOTE_IP [ tos TOS ] [ ttl TTL ]
Pere Orga5bc8c002011-04-11 03:29:49 +0200255//usage:
Denys Vlasenko4eaa0f72017-04-07 18:14:46 +0200256//--------------123456789.123456789.123456789.123456789.123456789.123456789.123456789.123....79
Pere Orga5bc8c002011-04-11 03:29:49 +0200257//usage:#define iprule_trivial_usage
Denys Vlasenko12389882017-01-21 14:27:07 +0100258//usage: "[list] | add|del SELECTOR ACTION"
Pere Orga5bc8c002011-04-11 03:29:49 +0200259//usage:#define iprule_full_usage "\n\n"
Pere Orga5bc8c002011-04-11 03:29:49 +0200260//usage: " SELECTOR := [from PREFIX] [to PREFIX] [tos TOS] [fwmark FWMARK]\n"
Denys Vlasenko12389882017-01-21 14:27:07 +0100261//usage: " [dev IFACE] [pref NUMBER]\n"
Denys Vlasenko4eaa0f72017-04-07 18:14:46 +0200262//usage: " ACTION := [table TABLE_ID] [nat ADDR]\n"
Denys Vlasenko8908c1d2017-01-21 03:56:46 +0100263//usage: " [prohibit|reject|unreachable]\n"
Pere Orga5bc8c002011-04-11 03:29:49 +0200264//usage: " [realms [SRCREALM/]DSTREALM]\n"
Denys Vlasenko8908c1d2017-01-21 03:56:46 +0100265//usage: " TABLE_ID := [local|main|default|NUMBER]"
Pere Orga5bc8c002011-04-11 03:29:49 +0200266//usage:
Denys Vlasenko4eaa0f72017-04-07 18:14:46 +0200267//--------------123456789.123456789.123456789.123456789.123456789.123456789.123456789.123....79
Pere Orga5bc8c002011-04-11 03:29:49 +0200268//usage:#define iptunnel_trivial_usage
Denys Vlasenkof3d705f2017-01-21 03:46:35 +0100269//usage: "add|change|del|show [NAME]\n"
270//usage: " [mode ipip|gre|sit]\n"
Pere Orga5bc8c002011-04-11 03:29:49 +0200271//usage: " [remote ADDR] [local ADDR] [ttl TTL]"
272//usage:#define iptunnel_full_usage "\n\n"
Denys Vlasenkof3d705f2017-01-21 03:46:35 +0100273//usage: "iptunnel add|change|del|show [NAME]\n"
274//usage: " [mode ipip|gre|sit] [remote ADDR] [local ADDR]\n"
Pere Orga5bc8c002011-04-11 03:29:49 +0200275//usage: " [[i|o]seq] [[i|o]key KEY] [[i|o]csum]\n"
276//usage: " [ttl TTL] [tos TOS] [[no]pmtudisc] [dev PHYS_DEV]"
Curt Brune69934702015-10-14 12:53:47 +0200277//usage:
278//usage:#define ipneigh_trivial_usage
Denys Vlasenkof3d705f2017-01-21 03:46:35 +0100279//usage: "show|flush [to PREFIX] [dev DEV] [nud STATE]"
Denys Vlasenko12389882017-01-21 14:27:07 +0100280//usage:#define ipneigh_full_usage ""
281//usage:
282//usage:#if ENABLE_FEATURE_IP_ADDRESS || ENABLE_FEATURE_IP_ROUTE
283//usage:# define IP_BAR_LINK "|"
284//usage:#else
285//usage:# define IP_BAR_LINK ""
286//usage:#endif
287//usage:#if ENABLE_FEATURE_IP_ADDRESS || ENABLE_FEATURE_IP_ROUTE || ENABLE_FEATURE_IP_LINK
288//usage:# define IP_BAR_TUNNEL "|"
289//usage:#else
290//usage:# define IP_BAR_TUNNEL ""
291//usage:#endif
292//usage:#if ENABLE_FEATURE_IP_ADDRESS || ENABLE_FEATURE_IP_ROUTE || ENABLE_FEATURE_IP_LINK || ENABLE_FEATURE_IP_TUNNEL
293//usage:# define IP_BAR_NEIGH "|"
294//usage:#else
295//usage:# define IP_BAR_NEIGH ""
296//usage:#endif
297//usage:#if ENABLE_FEATURE_IP_ADDRESS || ENABLE_FEATURE_IP_ROUTE || ENABLE_FEATURE_IP_LINK || ENABLE_FEATURE_IP_TUNNEL || ENABLE_FEATURE_IP_NEIGH
298//usage:# define IP_BAR_RULE "|"
299//usage:#else
300//usage:# define IP_BAR_RULE ""
301//usage:#endif
302//usage:
303//usage:#define ip_trivial_usage
304//usage: "[OPTIONS] "
305//usage: IF_FEATURE_IP_ADDRESS("address")
306//usage: IF_FEATURE_IP_ROUTE( IF_FEATURE_IP_ADDRESS("|")"route")
307//usage: IF_FEATURE_IP_LINK( IP_BAR_LINK "link")
308//usage: IF_FEATURE_IP_TUNNEL( IP_BAR_TUNNEL"tunnel")
309//usage: IF_FEATURE_IP_NEIGH( IP_BAR_NEIGH "neigh")
310//usage: IF_FEATURE_IP_RULE( IP_BAR_RULE "rule")
311//usage: " [COMMAND]"
312//usage:#define ip_full_usage "\n\n"
313//usage: "OPTIONS := -f[amily] inet|inet6|link | -o[neline]\n"
314//usage: "COMMAND :="
315//usage: IF_FEATURE_IP_ADDRESS("\n"
316//usage: "ip addr "ipaddr_trivial_usage)
317//usage: IF_FEATURE_IP_ROUTE("\n"
318//usage: "ip route "iproute_trivial_usage)
319//usage: IF_FEATURE_IP_LINK("\n"
320//usage: "ip link "iplink_trivial_usage)
321//usage: IF_FEATURE_IP_TUNNEL("\n"
322//usage: "ip tunnel "iptunnel_trivial_usage)
323//usage: IF_FEATURE_IP_NEIGH("\n"
324//usage: "ip neigh "ipneigh_trivial_usage)
325//usage: IF_FEATURE_IP_RULE("\n"
326//usage: "ip rule "iprule_trivial_usage)
Pere Orga5bc8c002011-04-11 03:29:49 +0200327
Denis Vlasenkob6adbf12007-05-26 19:00:18 +0000328#include "libbb.h"
Glenn L McGrath9a2d2722002-11-10 01:33:55 +0000329
Bernhard Reutner-Fischerab187822005-10-26 10:47:26 +0000330#include "libiproute/utils.h"
331#include "libiproute/ip_common.h"
Glenn L McGrath9a2d2722002-11-10 01:33:55 +0000332
Denys Vlasenko2e9b5512010-07-24 23:27:38 +0200333typedef int FAST_FUNC (*ip_func_ptr_t)(char**);
Denys Vlasenkoe0a62202010-07-24 23:26:58 +0200334
Denys Vlasenko7c5dea32016-12-22 22:30:13 +0100335#if ENABLE_IPADDR \
336 || ENABLE_IPLINK \
337 || ENABLE_IPROUTE \
338 || ENABLE_IPRULE \
339 || ENABLE_IPTUNNEL \
340 || ENABLE_IPNEIGH
Denys Vlasenkoe0a62202010-07-24 23:26:58 +0200341static int ip_do(ip_func_ptr_t ip_func, char **argv)
Bernhard Reutner-Fischer07c394e2007-04-10 20:11:12 +0000342{
Denis Vlasenko3246c0d2008-12-04 12:15:19 +0000343 argv = ip_parse_common_args(argv + 1);
Denis Vlasenkoed6a49c2007-11-18 22:56:25 +0000344 return ip_func(argv);
Bernhard Reutner-Fischer07c394e2007-04-10 20:11:12 +0000345}
Denys Vlasenko7c5dea32016-12-22 22:30:13 +0100346#endif
Bernhard Reutner-Fischer07c394e2007-04-10 20:11:12 +0000347
Denys Vlasenko7c5dea32016-12-22 22:30:13 +0100348#if ENABLE_IPADDR
Denis Vlasenko9b49a5e2007-10-11 10:05:36 +0000349int ipaddr_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
Denis Vlasenkoa60f84e2008-07-05 09:18:54 +0000350int ipaddr_main(int argc UNUSED_PARAM, char **argv)
Bernhard Reutner-Fischer07c394e2007-04-10 20:11:12 +0000351{
Denis Vlasenko2570b2e2008-03-28 01:00:09 +0000352 return ip_do(do_ipaddr, argv);
Bernhard Reutner-Fischer07c394e2007-04-10 20:11:12 +0000353}
354#endif
Denys Vlasenko7c5dea32016-12-22 22:30:13 +0100355#if ENABLE_IPLINK
Denis Vlasenko9b49a5e2007-10-11 10:05:36 +0000356int iplink_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
Denis Vlasenkoa60f84e2008-07-05 09:18:54 +0000357int iplink_main(int argc UNUSED_PARAM, char **argv)
Bernhard Reutner-Fischer07c394e2007-04-10 20:11:12 +0000358{
Denis Vlasenko2570b2e2008-03-28 01:00:09 +0000359 return ip_do(do_iplink, argv);
Bernhard Reutner-Fischer07c394e2007-04-10 20:11:12 +0000360}
361#endif
Denys Vlasenko7c5dea32016-12-22 22:30:13 +0100362#if ENABLE_IPROUTE
Denis Vlasenko9b49a5e2007-10-11 10:05:36 +0000363int iproute_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
Denis Vlasenkoa60f84e2008-07-05 09:18:54 +0000364int iproute_main(int argc UNUSED_PARAM, char **argv)
Bernhard Reutner-Fischer07c394e2007-04-10 20:11:12 +0000365{
Denis Vlasenko2570b2e2008-03-28 01:00:09 +0000366 return ip_do(do_iproute, argv);
Bernhard Reutner-Fischer07c394e2007-04-10 20:11:12 +0000367}
368#endif
Denys Vlasenko7c5dea32016-12-22 22:30:13 +0100369#if ENABLE_IPRULE
Denis Vlasenko9b49a5e2007-10-11 10:05:36 +0000370int iprule_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
Denis Vlasenkoa60f84e2008-07-05 09:18:54 +0000371int iprule_main(int argc UNUSED_PARAM, char **argv)
Bernhard Reutner-Fischer07c394e2007-04-10 20:11:12 +0000372{
Denis Vlasenko2570b2e2008-03-28 01:00:09 +0000373 return ip_do(do_iprule, argv);
Bernhard Reutner-Fischer07c394e2007-04-10 20:11:12 +0000374}
375#endif
Denys Vlasenko7c5dea32016-12-22 22:30:13 +0100376#if ENABLE_IPTUNNEL
Denis Vlasenko9b49a5e2007-10-11 10:05:36 +0000377int iptunnel_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
Denis Vlasenkoa60f84e2008-07-05 09:18:54 +0000378int iptunnel_main(int argc UNUSED_PARAM, char **argv)
Bernhard Reutner-Fischer07c394e2007-04-10 20:11:12 +0000379{
Denis Vlasenko2570b2e2008-03-28 01:00:09 +0000380 return ip_do(do_iptunnel, argv);
Bernhard Reutner-Fischer07c394e2007-04-10 20:11:12 +0000381}
382#endif
Denys Vlasenko7c5dea32016-12-22 22:30:13 +0100383#if ENABLE_IPNEIGH
Curt Brune69934702015-10-14 12:53:47 +0200384int ipneigh_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
385int ipneigh_main(int argc UNUSED_PARAM, char **argv)
386{
387 return ip_do(do_ipneigh, argv);
388}
389#endif
Bernhard Reutner-Fischer07c394e2007-04-10 20:11:12 +0000390
Denys Vlasenko7c5dea32016-12-22 22:30:13 +0100391#if ENABLE_IP
392static int FAST_FUNC ip_print_help(char **argv UNUSED_PARAM)
393{
394 bb_show_usage();
395}
Bernhard Reutner-Fischer07c394e2007-04-10 20:11:12 +0000396
Denis Vlasenko9b49a5e2007-10-11 10:05:36 +0000397int ip_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
Denis Vlasenkoa60f84e2008-07-05 09:18:54 +0000398int ip_main(int argc UNUSED_PARAM, char **argv)
Glenn L McGrathf112daa2002-12-01 23:04:06 +0000399{
Denys Vlasenko7c5dea32016-12-22 22:30:13 +0100400 static const char keywords[] ALIGN1 = ""
Denis Vlasenko5e34ff22009-04-21 11:09:40 +0000401 IF_FEATURE_IP_ADDRESS("address\0")
402 IF_FEATURE_IP_ROUTE("route\0")
Denys Vlasenkoe0a62202010-07-24 23:26:58 +0200403 IF_FEATURE_IP_ROUTE("r\0")
Denis Vlasenko5e34ff22009-04-21 11:09:40 +0000404 IF_FEATURE_IP_LINK("link\0")
Denys Vlasenkoe0a62202010-07-24 23:26:58 +0200405 IF_FEATURE_IP_TUNNEL("tunnel\0")
406 IF_FEATURE_IP_TUNNEL("tunl\0")
Denis Vlasenko5e34ff22009-04-21 11:09:40 +0000407 IF_FEATURE_IP_RULE("rule\0")
Curt Brune69934702015-10-14 12:53:47 +0200408 IF_FEATURE_IP_NEIGH("neigh\0")
Denis Vlasenko990d0f62007-07-24 15:54:42 +0000409 ;
Denys Vlasenkoe0a62202010-07-24 23:26:58 +0200410 static const ip_func_ptr_t ip_func_ptrs[] = {
411 ip_print_help,
412 IF_FEATURE_IP_ADDRESS(do_ipaddr,)
413 IF_FEATURE_IP_ROUTE(do_iproute,)
414 IF_FEATURE_IP_ROUTE(do_iproute,)
415 IF_FEATURE_IP_LINK(do_iplink,)
416 IF_FEATURE_IP_TUNNEL(do_iptunnel,)
417 IF_FEATURE_IP_TUNNEL(do_iptunnel,)
418 IF_FEATURE_IP_RULE(do_iprule,)
Curt Brune69934702015-10-14 12:53:47 +0200419 IF_FEATURE_IP_NEIGH(do_ipneigh,)
Bernhard Reutner-Fischere87d7952007-04-10 18:43:27 +0000420 };
Denys Vlasenkoe0a62202010-07-24 23:26:58 +0200421 ip_func_ptr_t ip_func;
422 int key;
Bernhard Reutner-Fischere87d7952007-04-10 18:43:27 +0000423
Denis Vlasenkoed6a49c2007-11-18 22:56:25 +0000424 argv = ip_parse_common_args(argv + 1);
Denys Vlasenko7c5dea32016-12-22 22:30:13 +0100425 if (ARRAY_SIZE(ip_func_ptrs) > 1 && *argv)
426 key = index_in_substrings(keywords, *argv++);
427 else
428 key = -1;
Denys Vlasenkoe0a62202010-07-24 23:26:58 +0200429 ip_func = ip_func_ptrs[key + 1];
430
Denis Vlasenkoed6a49c2007-11-18 22:56:25 +0000431 return ip_func(argv);
Glenn L McGrath9a2d2722002-11-10 01:33:55 +0000432}
Denys Vlasenko7c5dea32016-12-22 22:30:13 +0100433#endif