blob: 7c320869958a71b5a4004704ac4b133fb2ddb92d [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 Vlasenkob097a842018-12-28 03:20:17 +010012//config: bool "ip (35 kb)"
Denys Vlasenko47367e12016-11-23 09:05:14 +010013//config: default y
Denys Vlasenko47367e12016-11-23 09:05:14 +010014//config: help
Denys Vlasenko72089cf2017-07-21 09:50:55 +020015//config: The "ip" applet is a TCP/IP interface configuration and routing
Denys Vlasenko68b653b2017-07-27 10:53:09 +020016//config: utility.
17//config: Short forms (enabled below) are busybox-specific extensions.
18//config: The standard "ip" utility does not provide them. If you are
19//config: trying to be portable, it's better to use "ip CMD" forms.
Denys Vlasenko47367e12016-11-23 09:05:14 +010020//config:
Denys Vlasenko7c5dea32016-12-22 22:30:13 +010021//config:config IPADDR
Denys Vlasenko4eed2c62017-07-18 22:01:24 +020022//config: bool "ipaddr (14 kb)"
Denys Vlasenko7c5dea32016-12-22 22:30:13 +010023//config: default y
24//config: select FEATURE_IP_ADDRESS
Denys Vlasenko7c5dea32016-12-22 22:30:13 +010025//config: help
Denys Vlasenko68b653b2017-07-27 10:53:09 +020026//config: Short form of "ip addr"
Denys Vlasenko7c5dea32016-12-22 22:30:13 +010027//config:
28//config:config IPLINK
Denys Vlasenkob097a842018-12-28 03:20:17 +010029//config: bool "iplink (17 kb)"
Denys Vlasenko7c5dea32016-12-22 22:30:13 +010030//config: default y
31//config: select FEATURE_IP_LINK
Denys Vlasenko7c5dea32016-12-22 22:30:13 +010032//config: help
Denys Vlasenko68b653b2017-07-27 10:53:09 +020033//config: Short form of "ip link"
Denys Vlasenko7c5dea32016-12-22 22:30:13 +010034//config:
35//config:config IPROUTE
Denys Vlasenko4eed2c62017-07-18 22:01:24 +020036//config: bool "iproute (15 kb)"
Denys Vlasenko7c5dea32016-12-22 22:30:13 +010037//config: default y
38//config: select FEATURE_IP_ROUTE
Denys Vlasenko7c5dea32016-12-22 22:30:13 +010039//config: help
Denys Vlasenko68b653b2017-07-27 10:53:09 +020040//config: Short form of "ip route"
Denys Vlasenko7c5dea32016-12-22 22:30:13 +010041//config:
42//config:config IPTUNNEL
Denys Vlasenko4eed2c62017-07-18 22:01:24 +020043//config: bool "iptunnel (9.6 kb)"
Denys Vlasenko7c5dea32016-12-22 22:30:13 +010044//config: default y
45//config: select FEATURE_IP_TUNNEL
Denys Vlasenko7c5dea32016-12-22 22:30:13 +010046//config: help
Denys Vlasenko68b653b2017-07-27 10:53:09 +020047//config: Short form of "ip tunnel"
Denys Vlasenko7c5dea32016-12-22 22:30:13 +010048//config:
49//config:config IPRULE
Denys Vlasenko4eed2c62017-07-18 22:01:24 +020050//config: bool "iprule (10 kb)"
Denys Vlasenko7c5dea32016-12-22 22:30:13 +010051//config: default y
52//config: select FEATURE_IP_RULE
Denys Vlasenko7c5dea32016-12-22 22:30:13 +010053//config: help
Denys Vlasenko68b653b2017-07-27 10:53:09 +020054//config: Short form of "ip rule"
Denys Vlasenko7c5dea32016-12-22 22:30:13 +010055//config:
56//config:config IPNEIGH
Denys Vlasenko4eed2c62017-07-18 22:01:24 +020057//config: bool "ipneigh (8.3 kb)"
Denys Vlasenko7c5dea32016-12-22 22:30:13 +010058//config: default y
59//config: select FEATURE_IP_NEIGH
Denys Vlasenko7c5dea32016-12-22 22:30:13 +010060//config: help
Denys Vlasenko68b653b2017-07-27 10:53:09 +020061//config: Short form of "ip neigh"
Denys Vlasenko7c5dea32016-12-22 22:30:13 +010062//config:
Denys Vlasenko47367e12016-11-23 09:05:14 +010063//config:config FEATURE_IP_ADDRESS
64//config: bool "ip address"
65//config: default y
Denys Vlasenko7c5dea32016-12-22 22:30:13 +010066//config: depends on IP || IPADDR
Denys Vlasenko47367e12016-11-23 09:05:14 +010067//config: help
Denys Vlasenko72089cf2017-07-21 09:50:55 +020068//config: Address manipulation support for the "ip" applet.
Denys Vlasenko47367e12016-11-23 09:05:14 +010069//config:
70//config:config FEATURE_IP_LINK
71//config: bool "ip link"
72//config: default y
Denys Vlasenko7c5dea32016-12-22 22:30:13 +010073//config: depends on IP || IPLINK
Denys Vlasenko47367e12016-11-23 09:05:14 +010074//config: help
Denys Vlasenko72089cf2017-07-21 09:50:55 +020075//config: Configure network devices with "ip".
Denys Vlasenko47367e12016-11-23 09:05:14 +010076//config:
77//config:config FEATURE_IP_ROUTE
78//config: bool "ip route"
79//config: default y
Denys Vlasenko7c5dea32016-12-22 22:30:13 +010080//config: depends on IP || IPROUTE
Denys Vlasenko47367e12016-11-23 09:05:14 +010081//config: help
Denys Vlasenko72089cf2017-07-21 09:50:55 +020082//config: Add support for routing table management to "ip".
Denys Vlasenko47367e12016-11-23 09:05:14 +010083//config:
84//config:config FEATURE_IP_ROUTE_DIR
85//config: string "ip route configuration directory"
86//config: default "/etc/iproute2"
87//config: depends on FEATURE_IP_ROUTE
88//config: help
Denys Vlasenko72089cf2017-07-21 09:50:55 +020089//config: Location of the "ip" applet routing configuration.
Denys Vlasenko47367e12016-11-23 09:05:14 +010090//config:
91//config:config FEATURE_IP_TUNNEL
92//config: bool "ip tunnel"
93//config: default y
Denys Vlasenko7c5dea32016-12-22 22:30:13 +010094//config: depends on IP || IPTUNNEL
Denys Vlasenko47367e12016-11-23 09:05:14 +010095//config: help
Denys Vlasenko72089cf2017-07-21 09:50:55 +020096//config: Add support for tunneling commands to "ip".
Denys Vlasenko47367e12016-11-23 09:05:14 +010097//config:
98//config:config FEATURE_IP_RULE
99//config: bool "ip rule"
100//config: default y
Denys Vlasenko7c5dea32016-12-22 22:30:13 +0100101//config: depends on IP || IPRULE
Denys Vlasenko47367e12016-11-23 09:05:14 +0100102//config: help
Denys Vlasenko72089cf2017-07-21 09:50:55 +0200103//config: Add support for rule commands to "ip".
Denys Vlasenko47367e12016-11-23 09:05:14 +0100104//config:
105//config:config FEATURE_IP_NEIGH
106//config: bool "ip neighbor"
107//config: default y
Denys Vlasenko7c5dea32016-12-22 22:30:13 +0100108//config: depends on IP || IPNEIGH
Denys Vlasenko47367e12016-11-23 09:05:14 +0100109//config: help
Denys Vlasenko72089cf2017-07-21 09:50:55 +0200110//config: Add support for neighbor commands to "ip".
Denys Vlasenko47367e12016-11-23 09:05:14 +0100111//config:
Denys Vlasenko47367e12016-11-23 09:05:14 +0100112//config:config FEATURE_IP_RARE_PROTOCOLS
113//config: bool "Support displaying rarely used link types"
114//config: default n
Denys Vlasenko7c5dea32016-12-22 22:30:13 +0100115//config: depends on IP || IPADDR || IPLINK || IPROUTE || IPTUNNEL || IPRULE || IPNEIGH
Denys Vlasenko47367e12016-11-23 09:05:14 +0100116//config: help
Denys Vlasenko72089cf2017-07-21 09:50:55 +0200117//config: If you are not going to use links of type "frad", "econet",
118//config: "bif" etc, you probably don't need to enable this.
119//config: Ethernet, wireless, infrared, ppp/slip, ip tunnelling
120//config: link types are supported without this option selected.
Denys Vlasenko47367e12016-11-23 09:05:14 +0100121
Denys Vlasenkob63afea2017-09-18 15:45:13 +0200122//applet:IF_IP( APPLET_NOEXEC(ip , ip , BB_DIR_SBIN, BB_SUID_DROP, ip ))
123//applet:IF_IPADDR( APPLET_NOEXEC(ipaddr , ipaddr , BB_DIR_SBIN, BB_SUID_DROP, ipaddr ))
124//applet:IF_IPLINK( APPLET_NOEXEC(iplink , iplink , BB_DIR_SBIN, BB_SUID_DROP, iplink ))
125//applet:IF_IPROUTE( APPLET_NOEXEC(iproute , iproute , BB_DIR_SBIN, BB_SUID_DROP, iproute ))
126//applet:IF_IPRULE( APPLET_NOEXEC(iprule , iprule , BB_DIR_SBIN, BB_SUID_DROP, iprule ))
127//applet:IF_IPTUNNEL(APPLET_NOEXEC(iptunnel, iptunnel, BB_DIR_SBIN, BB_SUID_DROP, iptunnel))
128//applet:IF_IPNEIGH( APPLET_NOEXEC(ipneigh , ipneigh , BB_DIR_SBIN, BB_SUID_DROP, ipneigh ))
Denys Vlasenko47367e12016-11-23 09:05:14 +0100129
130//kbuild:lib-$(CONFIG_IP) += ip.o
Denys Vlasenko7c5dea32016-12-22 22:30:13 +0100131//kbuild:lib-$(CONFIG_IPADDR) += ip.o
132//kbuild:lib-$(CONFIG_IPLINK) += ip.o
133//kbuild:lib-$(CONFIG_IPROUTE) += ip.o
134//kbuild:lib-$(CONFIG_IPRULE) += ip.o
135//kbuild:lib-$(CONFIG_IPTUNNEL) += ip.o
136//kbuild:lib-$(CONFIG_IPNEIGH) += ip.o
Glenn L McGrath9a2d2722002-11-10 01:33:55 +0000137
Denys Vlasenko4eaa0f72017-04-07 18:14:46 +0200138//--------------123456789.123456789.123456789.123456789.123456789.123456789.123456789.123....79
Pere Orga5bc8c002011-04-11 03:29:49 +0200139//usage:#define ipaddr_trivial_usage
Denys Vlasenko12389882017-01-21 14:27:07 +0100140//usage: "add|del IFADDR dev IFACE | show|flush [dev IFACE] [to PREFIX]"
Pere Orga5bc8c002011-04-11 03:29:49 +0200141//usage:#define ipaddr_full_usage "\n\n"
Christian Eggers31d34f32020-06-29 17:57:25 +0200142//usage: "ipaddr add|change|replace|delete dev IFACE [CONFFLAG-LIST] IFADDR\n"
Denys Vlasenko7121bb82017-04-07 18:22:41 +0200143//usage: " IFADDR := PREFIX | ADDR peer PREFIX [broadcast ADDR|+|-]\n"
144//usage: " [anycast ADDR] [label STRING] [scope SCOPE]\n"
145//usage: " PREFIX := ADDR[/MASK]\n"
146//usage: " SCOPE := [host|link|global|NUMBER]\n"
Christian Eggers31d34f32020-06-29 17:57:25 +0200147//usage: " CONFFLAG-LIST := [CONFFLAG-LIST] CONFFLAG\n"
148//usage: " CONFFLAG := [noprefixroute]\n"
Denys Vlasenko7121bb82017-04-07 18:22:41 +0200149//usage: "ipaddr show|flush [dev IFACE] [scope SCOPE] [to PREFIX] [label PATTERN]"
Pere Orga5bc8c002011-04-11 03:29:49 +0200150//usage:
Denys Vlasenko4eaa0f72017-04-07 18:14:46 +0200151//--------------123456789.123456789.123456789.123456789.123456789.123456789.123456789.123....79
Pere Orga5bc8c002011-04-11 03:29:49 +0200152//usage:#define iplink_trivial_usage
Jan Luebbe79cda952018-02-20 19:28:02 +0100153//usage: /*Usage:iplink*/"set IFACE [up|down] [arp on|off] [multicast on|off]\n"
Jan Luebbee789c3b2018-02-14 14:05:27 +0100154//usage: " [promisc on|off] [mtu NUM] [name NAME] [qlen NUM] [address MAC]\n"
Nicholas Niroc28313b2020-04-22 23:36:11 -0400155//usage: " [master IFACE | nomaster] [netns PID]"
Jan Luebbe79cda952018-02-20 19:28:02 +0100156// * short help shows only "set" command, long help continues (with just one "\n")
157// * and shows all other commands:
158//usage:#define iplink_full_usage "\n"
159//usage: "iplink add [link IFACE] IFACE [address MAC] type TYPE [ARGS]\n"
160//usage: "iplink delete IFACE type TYPE [ARGS]\n"
161//usage: " TYPE ARGS := vlan VLANARGS | vrf table NUM\n"
162//usage: " VLANARGS := id VLANID [protocol 802.1q|802.1ad] [reorder_hdr on|off]\n"
163//usage: " [gvrp on|off] [mvrp on|off] [loose_binding on|off]\n"
Denys Vlasenko12389882017-01-21 14:27:07 +0100164//usage: "iplink show [IFACE]"
Jan Luebbe79cda952018-02-20 19:28:02 +0100165//upstream man ip-link:
166//=====================
167//ip link add [link DEV] [ name ] NAME
168// [ txqueuelen PACKETS ]
169// [ address LLADDR ]
170// [ broadcast LLADDR ]
171// [ mtu MTU ] [index IDX ]
172// [ numtxqueues QUEUE_COUNT ]
173// [ numrxqueues QUEUE_COUNT ]
174// type TYPE [ ARGS ]
175// ip link delete { DEVICE | dev DEVICE | group DEVGROUP } type TYPE [ ARGS ]
176// ip link set { DEVICE | dev DEVICE | group DEVGROUP } [ { up | down } ]
177// [ arp { on | off } ]
178// [ dynamic { on | off } ]
179// [ multicast { on | off } ]
180// [ allmulticast { on | off } ]
181// [ promisc { on | off } ]
182// [ trailers { on | off } ]
183// [ txqueuelen PACKETS ]
184// [ name NEWNAME ]
185// [ address LLADDR ]
186// [ broadcast LLADDR ]
187// [ mtu MTU ]
188// [ netns { PID | NAME } ]
189// [ link-netnsid ID ]
190// [ alias NAME ]
191// [ vf NUM [ mac LLADDR ]
192// [ vlan VLANID [ qos VLAN-QOS ] ]
193// [ rate TXRATE ]
194// [ spoofchk { on | off} ]
195// [ query_rss { on | off} ]
196// [ state { auto | enable | disable} ] ]
197// [ trust { on | off} ] ]
198// [ master DEVICE ]
199// [ nomaster ]
200// [ addrgenmode { eui64 | none | stable_secret | random } ]
201// [ protodown { on | off } ]
202// ip link show [ DEVICE | group GROUP ] [up] [master DEV] [type TYPE]
203// ip link help [ TYPE ]
204//TYPE := { vlan | veth | vcan | dummy | ifb | macvlan | macvtap |
205// bridge | bond | ipoib | ip6tnl | ipip | sit | vxlan |
206// gre | gretap | ip6gre | ip6gretap | vti | nlmon |
207// bond_slave | ipvlan | geneve | bridge_slave | vrf }
Pere Orga5bc8c002011-04-11 03:29:49 +0200208//usage:
Denys Vlasenko4eaa0f72017-04-07 18:14:46 +0200209//--------------123456789.123456789.123456789.123456789.123456789.123456789.123456789.123....79
Pere Orga5bc8c002011-04-11 03:29:49 +0200210//usage:#define iproute_trivial_usage
Denys Vlasenkof3d705f2017-01-21 03:46:35 +0100211//usage: "list|flush|add|del|change|append|replace|test ROUTE"
Pere Orga5bc8c002011-04-11 03:29:49 +0200212//usage:#define iproute_full_usage "\n\n"
Denys Vlasenkof3d705f2017-01-21 03:46:35 +0100213//usage: "iproute list|flush SELECTOR\n"
Denys Vlasenko53782d92011-12-06 18:59:55 +0100214//usage: " SELECTOR := [root PREFIX] [match PREFIX] [proto RTPROTO]\n"
Denys Vlasenko7121bb82017-04-07 18:22:41 +0200215//usage: " PREFIX := default|ADDR[/MASK]\n"
Denys Vlasenko4eaa0f72017-04-07 18:14:46 +0200216//usage: "iproute get ADDR [from ADDR iif IFACE]\n"
Denys Vlasenko1140bf32017-04-06 17:54:38 +0200217//usage: " [oif IFACE] [tos TOS]\n"
218//usage: "iproute add|del|change|append|replace|test ROUTE\n"
219//usage: " ROUTE := NODE_SPEC [INFO_SPEC]\n"
220//usage: " NODE_SPEC := PREFIX"IF_FEATURE_IP_RULE(" [table TABLE_ID]")" [proto RTPROTO] [scope SCOPE] [metric METRIC]\n"
221//usage: " INFO_SPEC := NH OPTIONS\n"
Denys Vlasenko4eaa0f72017-04-07 18:14:46 +0200222//usage: " NH := [via [inet|inet6] ADDR] [dev IFACE] [src ADDR] [onlink]\n"
Denys Vlasenkod5342a12017-04-07 17:00:53 +0200223//usage: " OPTIONS := [mtu [lock] NUM] [advmss [lock] NUM]"
Denys Vlasenko1140bf32017-04-06 17:54:38 +0200224//upstream man ip-route:
225//======================
226//ip route { show | flush } SELECTOR
227//ip route save SELECTOR
228//ip route restore
229//ip route get ADDRESS [ from ADDRESS iif STRING ] [ oif STRING ] [ tos TOS ]
230//ip route { add | del | change | append | replace } ROUTE
231//SELECTOR := [ root PREFIX ] [ match PREFIX ] [ exact PREFIX ] [ table TABLE_ID ] [ proto RTPROTO ] [ type TYPE ] [ scope SCOPE ]
232//ROUTE := NODE_SPEC [ INFO_SPEC ]
233//NODE_SPEC := [ TYPE ] PREFIX [ tos TOS ] [ table TABLE_ID ] [ proto RTPROTO ] [ scope SCOPE ] [ metric METRIC ]
234//INFO_SPEC := NH OPTIONS FLAGS [ nexthop NH ] ...
235//NH := [ encap ENCAP ] [ via [ FAMILY ] ADDRESS ] [ dev STRING ] [ weight NUMBER ] NHFLAGS
236// ..............................................................^ I guess [src ADDRESS] should be here
237//FAMILY := [ inet | inet6 | ipx | dnet | mpls | bridge | link ]
238//OPTIONS := FLAGS [ mtu NUMBER ] [ advmss NUMBER ] [ as [ to ] ADDRESS ] rtt TIME ] [ rttvar TIME ] [ reordering NUMBER ] [ window NUMBER ] [ cwnd NUMBER ] [ ssthresh REALM ] [ realms REALM ]
239// [ rto_min TIME ] [ initcwnd NUMBER ] [ initrwnd NUMBER ] [ features FEATURES ] [ quickack BOOL ] [ congctl NAME ] [ pref PREF ] [ expires TIME ]
240//TYPE := [ unicast | local | broadcast | multicast | throw | unreachable | prohibit | blackhole | nat ]
241//TABLE_ID := [ local | main | default | all | NUMBER ]
242//SCOPE := [ host | link | global | NUMBER ]
243//NHFLAGS := [ onlink | pervasive ]
244//RTPROTO := [ kernel | boot | static | NUMBER ]
245//FEATURES := [ ecn | ]
246//PREF := [ low | medium | high ]
247//ENCAP := [ MPLS | IP ]
248//ENCAP_MPLS := mpls [ LABEL ]
249//ENCAP_IP := ip id TUNNEL_ID dst REMOTE_IP [ tos TOS ] [ ttl TTL ]
Pere Orga5bc8c002011-04-11 03:29:49 +0200250//usage:
Denys Vlasenko4eaa0f72017-04-07 18:14:46 +0200251//--------------123456789.123456789.123456789.123456789.123456789.123456789.123456789.123....79
Pere Orga5bc8c002011-04-11 03:29:49 +0200252//usage:#define iprule_trivial_usage
Denys Vlasenko12389882017-01-21 14:27:07 +0100253//usage: "[list] | add|del SELECTOR ACTION"
Pere Orga5bc8c002011-04-11 03:29:49 +0200254//usage:#define iprule_full_usage "\n\n"
Rui Salvaterraeecd6f72020-07-31 10:10:36 +0100255//usage: " SELECTOR := [from PREFIX] [to PREFIX] [tos TOS] [fwmark FWMARK[/MASK]]\n"
Denys Vlasenko12389882017-01-21 14:27:07 +0100256//usage: " [dev IFACE] [pref NUMBER]\n"
Denys Vlasenko4eaa0f72017-04-07 18:14:46 +0200257//usage: " ACTION := [table TABLE_ID] [nat ADDR]\n"
Denys Vlasenko8908c1d2017-01-21 03:56:46 +0100258//usage: " [prohibit|reject|unreachable]\n"
Pere Orga5bc8c002011-04-11 03:29:49 +0200259//usage: " [realms [SRCREALM/]DSTREALM]\n"
Denys Vlasenko8908c1d2017-01-21 03:56:46 +0100260//usage: " TABLE_ID := [local|main|default|NUMBER]"
Pere Orga5bc8c002011-04-11 03:29:49 +0200261//usage:
Denys Vlasenko4eaa0f72017-04-07 18:14:46 +0200262//--------------123456789.123456789.123456789.123456789.123456789.123456789.123456789.123....79
Pere Orga5bc8c002011-04-11 03:29:49 +0200263//usage:#define iptunnel_trivial_usage
Denys Vlasenkof3d705f2017-01-21 03:46:35 +0100264//usage: "add|change|del|show [NAME]\n"
Denys Vlasenko37595162018-08-14 11:19:09 +0200265//usage: " [mode ipip|gre|sit] [remote ADDR] [local ADDR] [ttl TTL]"
Pere Orga5bc8c002011-04-11 03:29:49 +0200266//usage:#define iptunnel_full_usage "\n\n"
Denys Vlasenkof3d705f2017-01-21 03:46:35 +0100267//usage: "iptunnel add|change|del|show [NAME]\n"
268//usage: " [mode ipip|gre|sit] [remote ADDR] [local ADDR]\n"
Pere Orga5bc8c002011-04-11 03:29:49 +0200269//usage: " [[i|o]seq] [[i|o]key KEY] [[i|o]csum]\n"
270//usage: " [ttl TTL] [tos TOS] [[no]pmtudisc] [dev PHYS_DEV]"
Curt Brune69934702015-10-14 12:53:47 +0200271//usage:
272//usage:#define ipneigh_trivial_usage
Denys Vlasenkof3d705f2017-01-21 03:46:35 +0100273//usage: "show|flush [to PREFIX] [dev DEV] [nud STATE]"
Denys Vlasenko12389882017-01-21 14:27:07 +0100274//usage:#define ipneigh_full_usage ""
275//usage:
276//usage:#if ENABLE_FEATURE_IP_ADDRESS || ENABLE_FEATURE_IP_ROUTE
277//usage:# define IP_BAR_LINK "|"
278//usage:#else
279//usage:# define IP_BAR_LINK ""
280//usage:#endif
281//usage:#if ENABLE_FEATURE_IP_ADDRESS || ENABLE_FEATURE_IP_ROUTE || ENABLE_FEATURE_IP_LINK
282//usage:# define IP_BAR_TUNNEL "|"
283//usage:#else
284//usage:# define IP_BAR_TUNNEL ""
285//usage:#endif
286//usage:#if ENABLE_FEATURE_IP_ADDRESS || ENABLE_FEATURE_IP_ROUTE || ENABLE_FEATURE_IP_LINK || ENABLE_FEATURE_IP_TUNNEL
287//usage:# define IP_BAR_NEIGH "|"
288//usage:#else
289//usage:# define IP_BAR_NEIGH ""
290//usage:#endif
291//usage:#if ENABLE_FEATURE_IP_ADDRESS || ENABLE_FEATURE_IP_ROUTE || ENABLE_FEATURE_IP_LINK || ENABLE_FEATURE_IP_TUNNEL || ENABLE_FEATURE_IP_NEIGH
292//usage:# define IP_BAR_RULE "|"
293//usage:#else
294//usage:# define IP_BAR_RULE ""
295//usage:#endif
296//usage:
297//usage:#define ip_trivial_usage
298//usage: "[OPTIONS] "
299//usage: IF_FEATURE_IP_ADDRESS("address")
300//usage: IF_FEATURE_IP_ROUTE( IF_FEATURE_IP_ADDRESS("|")"route")
301//usage: IF_FEATURE_IP_LINK( IP_BAR_LINK "link")
302//usage: IF_FEATURE_IP_TUNNEL( IP_BAR_TUNNEL"tunnel")
303//usage: IF_FEATURE_IP_NEIGH( IP_BAR_NEIGH "neigh")
304//usage: IF_FEATURE_IP_RULE( IP_BAR_RULE "rule")
Denys Vlasenko37595162018-08-14 11:19:09 +0200305//usage: " [ARGS]"
Denys Vlasenko12389882017-01-21 14:27:07 +0100306//usage:#define ip_full_usage "\n\n"
307//usage: "OPTIONS := -f[amily] inet|inet6|link | -o[neline]\n"
Denys Vlasenko12389882017-01-21 14:27:07 +0100308//usage: IF_FEATURE_IP_ADDRESS("\n"
309//usage: "ip addr "ipaddr_trivial_usage)
310//usage: IF_FEATURE_IP_ROUTE("\n"
311//usage: "ip route "iproute_trivial_usage)
312//usage: IF_FEATURE_IP_LINK("\n"
313//usage: "ip link "iplink_trivial_usage)
314//usage: IF_FEATURE_IP_TUNNEL("\n"
315//usage: "ip tunnel "iptunnel_trivial_usage)
316//usage: IF_FEATURE_IP_NEIGH("\n"
317//usage: "ip neigh "ipneigh_trivial_usage)
318//usage: IF_FEATURE_IP_RULE("\n"
319//usage: "ip rule "iprule_trivial_usage)
Pere Orga5bc8c002011-04-11 03:29:49 +0200320
Denis Vlasenkob6adbf12007-05-26 19:00:18 +0000321#include "libbb.h"
Glenn L McGrath9a2d2722002-11-10 01:33:55 +0000322
Bernhard Reutner-Fischerab187822005-10-26 10:47:26 +0000323#include "libiproute/utils.h"
324#include "libiproute/ip_common.h"
Glenn L McGrath9a2d2722002-11-10 01:33:55 +0000325
Denys Vlasenko2e9b5512010-07-24 23:27:38 +0200326typedef int FAST_FUNC (*ip_func_ptr_t)(char**);
Denys Vlasenkoe0a62202010-07-24 23:26:58 +0200327
Denys Vlasenko7c5dea32016-12-22 22:30:13 +0100328#if ENABLE_IPADDR \
329 || ENABLE_IPLINK \
330 || ENABLE_IPROUTE \
331 || ENABLE_IPRULE \
332 || ENABLE_IPTUNNEL \
333 || ENABLE_IPNEIGH
Denys Vlasenkoe0a62202010-07-24 23:26:58 +0200334static int ip_do(ip_func_ptr_t ip_func, char **argv)
Bernhard Reutner-Fischer07c394e2007-04-10 20:11:12 +0000335{
Denis Vlasenko3246c0d2008-12-04 12:15:19 +0000336 argv = ip_parse_common_args(argv + 1);
Denis Vlasenkoed6a49c2007-11-18 22:56:25 +0000337 return ip_func(argv);
Bernhard Reutner-Fischer07c394e2007-04-10 20:11:12 +0000338}
Denys Vlasenko7c5dea32016-12-22 22:30:13 +0100339#endif
Bernhard Reutner-Fischer07c394e2007-04-10 20:11:12 +0000340
Denys Vlasenko7c5dea32016-12-22 22:30:13 +0100341#if ENABLE_IPADDR
Denis Vlasenko9b49a5e2007-10-11 10:05:36 +0000342int ipaddr_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
Denis Vlasenkoa60f84e2008-07-05 09:18:54 +0000343int ipaddr_main(int argc UNUSED_PARAM, char **argv)
Bernhard Reutner-Fischer07c394e2007-04-10 20:11:12 +0000344{
Denis Vlasenko2570b2e2008-03-28 01:00:09 +0000345 return ip_do(do_ipaddr, argv);
Bernhard Reutner-Fischer07c394e2007-04-10 20:11:12 +0000346}
347#endif
Denys Vlasenko7c5dea32016-12-22 22:30:13 +0100348#if ENABLE_IPLINK
Denis Vlasenko9b49a5e2007-10-11 10:05:36 +0000349int iplink_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
Denis Vlasenkoa60f84e2008-07-05 09:18:54 +0000350int iplink_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_iplink, argv);
Bernhard Reutner-Fischer07c394e2007-04-10 20:11:12 +0000353}
354#endif
Denys Vlasenko7c5dea32016-12-22 22:30:13 +0100355#if ENABLE_IPROUTE
Denis Vlasenko9b49a5e2007-10-11 10:05:36 +0000356int iproute_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
Denis Vlasenkoa60f84e2008-07-05 09:18:54 +0000357int iproute_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_iproute, argv);
Bernhard Reutner-Fischer07c394e2007-04-10 20:11:12 +0000360}
361#endif
Denys Vlasenko7c5dea32016-12-22 22:30:13 +0100362#if ENABLE_IPRULE
Denis Vlasenko9b49a5e2007-10-11 10:05:36 +0000363int iprule_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
Denis Vlasenkoa60f84e2008-07-05 09:18:54 +0000364int iprule_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_iprule, argv);
Bernhard Reutner-Fischer07c394e2007-04-10 20:11:12 +0000367}
368#endif
Denys Vlasenko7c5dea32016-12-22 22:30:13 +0100369#if ENABLE_IPTUNNEL
Denis Vlasenko9b49a5e2007-10-11 10:05:36 +0000370int iptunnel_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
Denis Vlasenkoa60f84e2008-07-05 09:18:54 +0000371int iptunnel_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_iptunnel, argv);
Bernhard Reutner-Fischer07c394e2007-04-10 20:11:12 +0000374}
375#endif
Denys Vlasenko7c5dea32016-12-22 22:30:13 +0100376#if ENABLE_IPNEIGH
Curt Brune69934702015-10-14 12:53:47 +0200377int ipneigh_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
378int ipneigh_main(int argc UNUSED_PARAM, char **argv)
379{
380 return ip_do(do_ipneigh, argv);
381}
382#endif
Bernhard Reutner-Fischer07c394e2007-04-10 20:11:12 +0000383
Denys Vlasenko7c5dea32016-12-22 22:30:13 +0100384#if ENABLE_IP
385static int FAST_FUNC ip_print_help(char **argv UNUSED_PARAM)
386{
387 bb_show_usage();
388}
Bernhard Reutner-Fischer07c394e2007-04-10 20:11:12 +0000389
Denis Vlasenko9b49a5e2007-10-11 10:05:36 +0000390int ip_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
Denis Vlasenkoa60f84e2008-07-05 09:18:54 +0000391int ip_main(int argc UNUSED_PARAM, char **argv)
Glenn L McGrathf112daa2002-12-01 23:04:06 +0000392{
Denys Vlasenko7c5dea32016-12-22 22:30:13 +0100393 static const char keywords[] ALIGN1 = ""
Denis Vlasenko5e34ff22009-04-21 11:09:40 +0000394 IF_FEATURE_IP_ADDRESS("address\0")
395 IF_FEATURE_IP_ROUTE("route\0")
Denys Vlasenkoe0a62202010-07-24 23:26:58 +0200396 IF_FEATURE_IP_ROUTE("r\0")
Denis Vlasenko5e34ff22009-04-21 11:09:40 +0000397 IF_FEATURE_IP_LINK("link\0")
Denys Vlasenkoe0a62202010-07-24 23:26:58 +0200398 IF_FEATURE_IP_TUNNEL("tunnel\0")
399 IF_FEATURE_IP_TUNNEL("tunl\0")
Denis Vlasenko5e34ff22009-04-21 11:09:40 +0000400 IF_FEATURE_IP_RULE("rule\0")
Curt Brune69934702015-10-14 12:53:47 +0200401 IF_FEATURE_IP_NEIGH("neigh\0")
Denis Vlasenko990d0f62007-07-24 15:54:42 +0000402 ;
Denys Vlasenko965b7952020-11-30 13:03:03 +0100403 static const ip_func_ptr_t ip_func_ptrs[] ALIGN_PTR = {
Denys Vlasenkoe0a62202010-07-24 23:26:58 +0200404 ip_print_help,
405 IF_FEATURE_IP_ADDRESS(do_ipaddr,)
406 IF_FEATURE_IP_ROUTE(do_iproute,)
407 IF_FEATURE_IP_ROUTE(do_iproute,)
408 IF_FEATURE_IP_LINK(do_iplink,)
409 IF_FEATURE_IP_TUNNEL(do_iptunnel,)
410 IF_FEATURE_IP_TUNNEL(do_iptunnel,)
411 IF_FEATURE_IP_RULE(do_iprule,)
Curt Brune69934702015-10-14 12:53:47 +0200412 IF_FEATURE_IP_NEIGH(do_ipneigh,)
Bernhard Reutner-Fischere87d7952007-04-10 18:43:27 +0000413 };
Denys Vlasenkoe0a62202010-07-24 23:26:58 +0200414 ip_func_ptr_t ip_func;
415 int key;
Bernhard Reutner-Fischere87d7952007-04-10 18:43:27 +0000416
Denis Vlasenkoed6a49c2007-11-18 22:56:25 +0000417 argv = ip_parse_common_args(argv + 1);
Denys Vlasenko7c5dea32016-12-22 22:30:13 +0100418 if (ARRAY_SIZE(ip_func_ptrs) > 1 && *argv)
419 key = index_in_substrings(keywords, *argv++);
420 else
421 key = -1;
Denys Vlasenkoe0a62202010-07-24 23:26:58 +0200422 ip_func = ip_func_ptrs[key + 1];
423
Denis Vlasenkoed6a49c2007-11-18 22:56:25 +0000424 return ip_func(argv);
Glenn L McGrath9a2d2722002-11-10 01:33:55 +0000425}
Denys Vlasenko7c5dea32016-12-22 22:30:13 +0100426#endif