"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 | /* |
Denys Vlasenko | 0ef64bd | 2010-08-16 20:14:46 +0200 | [diff] [blame] | 3 | * Licensed under GPLv2 or later, see file LICENSE in this source tree. |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 4 | * |
Denys Vlasenko | e0a6220 | 2010-07-24 23:26:58 +0200 | [diff] [blame] | 5 | * Authors: Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru> |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 6 | * |
| 7 | * Changes: |
Denys Vlasenko | fb132e4 | 2010-10-29 11:46:52 +0200 | [diff] [blame] | 8 | * Rani Assaf <rani@magic.metawire.com> 980929: resolve addresses |
Bernhard Reutner-Fischer | 6c4dade | 2008-09-25 12:13:34 +0000 | [diff] [blame] | 9 | * Bernhard Reutner-Fischer rewrote to use index_in_substr_array |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 10 | */ |
Denys Vlasenko | 47367e1 | 2016-11-23 09:05:14 +0100 | [diff] [blame] | 11 | //config:config IP |
| 12 | //config: bool "ip" |
| 13 | //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 Vlasenko | 7c5dea3 | 2016-12-22 22:30:13 +0100 | [diff] [blame] | 20 | //config:config IPADDR |
| 21 | //config: bool "ipaddr" |
| 22 | //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 |
| 29 | //config: bool "iplink" |
| 30 | //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 |
| 37 | //config: bool "iproute" |
| 38 | //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 |
| 45 | //config: bool "iptunnel" |
| 46 | //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 |
| 53 | //config: bool "iprule" |
| 54 | //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 |
| 61 | //config: bool "ipneigh" |
| 62 | //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 Vlasenko | 47367e1 | 2016-11-23 09:05:14 +0100 | [diff] [blame] | 68 | //config:config FEATURE_IP_ADDRESS |
| 69 | //config: bool "ip address" |
| 70 | //config: default y |
Denys Vlasenko | 7c5dea3 | 2016-12-22 22:30:13 +0100 | [diff] [blame] | 71 | //config: depends on IP || IPADDR |
Denys Vlasenko | 47367e1 | 2016-11-23 09:05:14 +0100 | [diff] [blame] | 72 | //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 Vlasenko | 7c5dea3 | 2016-12-22 22:30:13 +0100 | [diff] [blame] | 78 | //config: depends on IP || IPLINK |
Denys Vlasenko | 47367e1 | 2016-11-23 09:05:14 +0100 | [diff] [blame] | 79 | //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 Vlasenko | 7c5dea3 | 2016-12-22 22:30:13 +0100 | [diff] [blame] | 85 | //config: depends on IP || IPROUTE |
Denys Vlasenko | 47367e1 | 2016-11-23 09:05:14 +0100 | [diff] [blame] | 86 | //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 Vlasenko | 7c5dea3 | 2016-12-22 22:30:13 +0100 | [diff] [blame] | 99 | //config: depends on IP || IPTUNNEL |
Denys Vlasenko | 47367e1 | 2016-11-23 09:05:14 +0100 | [diff] [blame] | 100 | //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 Vlasenko | 7c5dea3 | 2016-12-22 22:30:13 +0100 | [diff] [blame] | 106 | //config: depends on IP || IPRULE |
Denys Vlasenko | 47367e1 | 2016-11-23 09:05:14 +0100 | [diff] [blame] | 107 | //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 Vlasenko | 7c5dea3 | 2016-12-22 22:30:13 +0100 | [diff] [blame] | 113 | //config: depends on IP || IPNEIGH |
Denys Vlasenko | 47367e1 | 2016-11-23 09:05:14 +0100 | [diff] [blame] | 114 | //config: help |
| 115 | //config: Add support for neighbor commands to "ip". |
| 116 | //config: |
Denys Vlasenko | 47367e1 | 2016-11-23 09:05:14 +0100 | [diff] [blame] | 117 | //config:config FEATURE_IP_RARE_PROTOCOLS |
| 118 | //config: bool "Support displaying rarely used link types" |
| 119 | //config: default n |
Denys Vlasenko | 7c5dea3 | 2016-12-22 22:30:13 +0100 | [diff] [blame] | 120 | //config: depends on IP || IPADDR || IPLINK || IPROUTE || IPTUNNEL || IPRULE || IPNEIGH |
Denys Vlasenko | 47367e1 | 2016-11-23 09:05:14 +0100 | [diff] [blame] | 121 | //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 Vlasenko | 47367e1 | 2016-11-23 09:05:14 +0100 | [diff] [blame] | 126 | |
Denys Vlasenko | 47367e1 | 2016-11-23 09:05:14 +0100 | [diff] [blame] | 127 | //applet:IF_IP(APPLET(ip, BB_DIR_SBIN, BB_SUID_DROP)) |
Denys Vlasenko | 47367e1 | 2016-11-23 09:05:14 +0100 | [diff] [blame] | 128 | //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 Vlasenko | 6bfab0c | 2016-11-23 09:18:05 +0100 | [diff] [blame] | 133 | //applet:IF_IPNEIGH(APPLET(ipneigh, BB_DIR_SBIN, BB_SUID_DROP)) |
Denys Vlasenko | 47367e1 | 2016-11-23 09:05:14 +0100 | [diff] [blame] | 134 | |
| 135 | //kbuild:lib-$(CONFIG_IP) += ip.o |
Denys Vlasenko | 7c5dea3 | 2016-12-22 22:30:13 +0100 | [diff] [blame] | 136 | //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 McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 142 | |
Pere Orga | 5bc8c00 | 2011-04-11 03:29:49 +0200 | [diff] [blame] | 143 | //usage:#define ipaddr_trivial_usage |
Denys Vlasenko | 1238988 | 2017-01-21 14:27:07 +0100 | [diff] [blame] | 144 | //usage: "add|del IFADDR dev IFACE | show|flush [dev IFACE] [to PREFIX]" |
Pere Orga | 5bc8c00 | 2011-04-11 03:29:49 +0200 | [diff] [blame] | 145 | //usage:#define ipaddr_full_usage "\n\n" |
Denys Vlasenko | 1238988 | 2017-01-21 14:27:07 +0100 | [diff] [blame] | 146 | //usage: "ipaddr add|change|replace|delete IFADDR dev IFACE\n" |
| 147 | //usage: "ipaddr show|flush [dev IFACE] [scope SCOPE-ID]\n" |
Denys Vlasenko | 8908c1d | 2017-01-21 03:56:46 +0100 | [diff] [blame] | 148 | //usage: " [to PREFIX] [label PATTERN]\n" |
Pere Orga | 5bc8c00 | 2011-04-11 03:29:49 +0200 | [diff] [blame] | 149 | //usage: " IFADDR := PREFIX | ADDR peer PREFIX\n" |
Denys Vlasenko | 8908c1d | 2017-01-21 03:56:46 +0100 | [diff] [blame] | 150 | //usage: " [broadcast ADDR] [anycast ADDR]\n" |
| 151 | //usage: " [label STRING] [scope SCOPE-ID]\n" |
Denys Vlasenko | f3d705f | 2017-01-21 03:46:35 +0100 | [diff] [blame] | 152 | //usage: " SCOPE-ID := [host|link|global|NUMBER]" |
Pere Orga | 5bc8c00 | 2011-04-11 03:29:49 +0200 | [diff] [blame] | 153 | //usage: |
| 154 | //usage:#define iplink_trivial_usage |
Denys Vlasenko | 1238988 | 2017-01-21 14:27:07 +0100 | [diff] [blame] | 155 | //usage: "set IFACE [up|down] [arp on|off] | show [IFACE]" |
Pere Orga | 5bc8c00 | 2011-04-11 03:29:49 +0200 | [diff] [blame] | 156 | //usage:#define iplink_full_usage "\n\n" |
Denys Vlasenko | 2d4823b | 2017-04-06 16:06:04 +0200 | [diff] [blame] | 157 | //usage: "iplink set IFACE [up|down] [arp on|off] [multicast on|off] [promisc on|off]\n" |
| 158 | //usage: " [mtu NUM] [name NAME] [qlen NUM] [address MAC]\n" |
Denys Vlasenko | 1238988 | 2017-01-21 14:27:07 +0100 | [diff] [blame] | 159 | //usage: "iplink show [IFACE]" |
Pere Orga | 5bc8c00 | 2011-04-11 03:29:49 +0200 | [diff] [blame] | 160 | //usage: |
| 161 | //usage:#define iproute_trivial_usage |
Denys Vlasenko | f3d705f | 2017-01-21 03:46:35 +0100 | [diff] [blame] | 162 | //usage: "list|flush|add|del|change|append|replace|test ROUTE" |
Pere Orga | 5bc8c00 | 2011-04-11 03:29:49 +0200 | [diff] [blame] | 163 | //usage:#define iproute_full_usage "\n\n" |
Denys Vlasenko | f3d705f | 2017-01-21 03:46:35 +0100 | [diff] [blame] | 164 | //usage: "iproute list|flush SELECTOR\n" |
Denys Vlasenko | 53782d9 | 2011-12-06 18:59:55 +0100 | [diff] [blame] | 165 | //usage: " SELECTOR := [root PREFIX] [match PREFIX] [proto RTPROTO]\n" |
Denys Vlasenko | 1140bf3 | 2017-04-06 17:54:38 +0200 | [diff] [blame^] | 166 | //usage: " PREFIX := default|ADDRESS/MASK\n" |
| 167 | //usage: "iproute get ADDRESS [from ADDRESS iif IFACE]\n" |
| 168 | //usage: " [oif IFACE] [tos TOS]\n" |
| 169 | //usage: "iproute add|del|change|append|replace|test ROUTE\n" |
| 170 | //usage: " ROUTE := NODE_SPEC [INFO_SPEC]\n" |
| 171 | //usage: " NODE_SPEC := PREFIX"IF_FEATURE_IP_RULE(" [table TABLE_ID]")" [proto RTPROTO] [scope SCOPE] [metric METRIC]\n" |
| 172 | //usage: " INFO_SPEC := NH OPTIONS\n" |
| 173 | //usage: " NH := [via [inet|inet6] ADDRESS] [dev IFACE] [src ADDRESS] [onlink]\n" |
| 174 | //usage: " OPTIONS := [mtu NUM]" |
| 175 | //upstream man ip-route: |
| 176 | //====================== |
| 177 | //ip route { show | flush } SELECTOR |
| 178 | //ip route save SELECTOR |
| 179 | //ip route restore |
| 180 | //ip route get ADDRESS [ from ADDRESS iif STRING ] [ oif STRING ] [ tos TOS ] |
| 181 | //ip route { add | del | change | append | replace } ROUTE |
| 182 | //SELECTOR := [ root PREFIX ] [ match PREFIX ] [ exact PREFIX ] [ table TABLE_ID ] [ proto RTPROTO ] [ type TYPE ] [ scope SCOPE ] |
| 183 | //ROUTE := NODE_SPEC [ INFO_SPEC ] |
| 184 | //NODE_SPEC := [ TYPE ] PREFIX [ tos TOS ] [ table TABLE_ID ] [ proto RTPROTO ] [ scope SCOPE ] [ metric METRIC ] |
| 185 | //INFO_SPEC := NH OPTIONS FLAGS [ nexthop NH ] ... |
| 186 | //NH := [ encap ENCAP ] [ via [ FAMILY ] ADDRESS ] [ dev STRING ] [ weight NUMBER ] NHFLAGS |
| 187 | // ..............................................................^ I guess [src ADDRESS] should be here |
| 188 | //FAMILY := [ inet | inet6 | ipx | dnet | mpls | bridge | link ] |
| 189 | //OPTIONS := FLAGS [ mtu NUMBER ] [ advmss NUMBER ] [ as [ to ] ADDRESS ] rtt TIME ] [ rttvar TIME ] [ reordering NUMBER ] [ window NUMBER ] [ cwnd NUMBER ] [ ssthresh REALM ] [ realms REALM ] |
| 190 | // [ rto_min TIME ] [ initcwnd NUMBER ] [ initrwnd NUMBER ] [ features FEATURES ] [ quickack BOOL ] [ congctl NAME ] [ pref PREF ] [ expires TIME ] |
| 191 | //TYPE := [ unicast | local | broadcast | multicast | throw | unreachable | prohibit | blackhole | nat ] |
| 192 | //TABLE_ID := [ local | main | default | all | NUMBER ] |
| 193 | //SCOPE := [ host | link | global | NUMBER ] |
| 194 | //NHFLAGS := [ onlink | pervasive ] |
| 195 | //RTPROTO := [ kernel | boot | static | NUMBER ] |
| 196 | //FEATURES := [ ecn | ] |
| 197 | //PREF := [ low | medium | high ] |
| 198 | //ENCAP := [ MPLS | IP ] |
| 199 | //ENCAP_MPLS := mpls [ LABEL ] |
| 200 | //ENCAP_IP := ip id TUNNEL_ID dst REMOTE_IP [ tos TOS ] [ ttl TTL ] |
Pere Orga | 5bc8c00 | 2011-04-11 03:29:49 +0200 | [diff] [blame] | 201 | //usage: |
| 202 | //usage:#define iprule_trivial_usage |
Denys Vlasenko | 1238988 | 2017-01-21 14:27:07 +0100 | [diff] [blame] | 203 | //usage: "[list] | add|del SELECTOR ACTION" |
Pere Orga | 5bc8c00 | 2011-04-11 03:29:49 +0200 | [diff] [blame] | 204 | //usage:#define iprule_full_usage "\n\n" |
Pere Orga | 5bc8c00 | 2011-04-11 03:29:49 +0200 | [diff] [blame] | 205 | //usage: " SELECTOR := [from PREFIX] [to PREFIX] [tos TOS] [fwmark FWMARK]\n" |
Denys Vlasenko | 1238988 | 2017-01-21 14:27:07 +0100 | [diff] [blame] | 206 | //usage: " [dev IFACE] [pref NUMBER]\n" |
Pere Orga | 5bc8c00 | 2011-04-11 03:29:49 +0200 | [diff] [blame] | 207 | //usage: " ACTION := [table TABLE_ID] [nat ADDRESS]\n" |
Denys Vlasenko | 8908c1d | 2017-01-21 03:56:46 +0100 | [diff] [blame] | 208 | //usage: " [prohibit|reject|unreachable]\n" |
Pere Orga | 5bc8c00 | 2011-04-11 03:29:49 +0200 | [diff] [blame] | 209 | //usage: " [realms [SRCREALM/]DSTREALM]\n" |
Denys Vlasenko | 8908c1d | 2017-01-21 03:56:46 +0100 | [diff] [blame] | 210 | //usage: " TABLE_ID := [local|main|default|NUMBER]" |
Pere Orga | 5bc8c00 | 2011-04-11 03:29:49 +0200 | [diff] [blame] | 211 | //usage: |
| 212 | //usage:#define iptunnel_trivial_usage |
Denys Vlasenko | f3d705f | 2017-01-21 03:46:35 +0100 | [diff] [blame] | 213 | //usage: "add|change|del|show [NAME]\n" |
| 214 | //usage: " [mode ipip|gre|sit]\n" |
Pere Orga | 5bc8c00 | 2011-04-11 03:29:49 +0200 | [diff] [blame] | 215 | //usage: " [remote ADDR] [local ADDR] [ttl TTL]" |
| 216 | //usage:#define iptunnel_full_usage "\n\n" |
Denys Vlasenko | f3d705f | 2017-01-21 03:46:35 +0100 | [diff] [blame] | 217 | //usage: "iptunnel add|change|del|show [NAME]\n" |
| 218 | //usage: " [mode ipip|gre|sit] [remote ADDR] [local ADDR]\n" |
Pere Orga | 5bc8c00 | 2011-04-11 03:29:49 +0200 | [diff] [blame] | 219 | //usage: " [[i|o]seq] [[i|o]key KEY] [[i|o]csum]\n" |
| 220 | //usage: " [ttl TTL] [tos TOS] [[no]pmtudisc] [dev PHYS_DEV]" |
Curt Brune | 6993470 | 2015-10-14 12:53:47 +0200 | [diff] [blame] | 221 | //usage: |
| 222 | //usage:#define ipneigh_trivial_usage |
Denys Vlasenko | f3d705f | 2017-01-21 03:46:35 +0100 | [diff] [blame] | 223 | //usage: "show|flush [to PREFIX] [dev DEV] [nud STATE]" |
Denys Vlasenko | 1238988 | 2017-01-21 14:27:07 +0100 | [diff] [blame] | 224 | //usage:#define ipneigh_full_usage "" |
| 225 | //usage: |
| 226 | //usage:#if ENABLE_FEATURE_IP_ADDRESS || ENABLE_FEATURE_IP_ROUTE |
| 227 | //usage:# define IP_BAR_LINK "|" |
| 228 | //usage:#else |
| 229 | //usage:# define IP_BAR_LINK "" |
| 230 | //usage:#endif |
| 231 | //usage:#if ENABLE_FEATURE_IP_ADDRESS || ENABLE_FEATURE_IP_ROUTE || ENABLE_FEATURE_IP_LINK |
| 232 | //usage:# define IP_BAR_TUNNEL "|" |
| 233 | //usage:#else |
| 234 | //usage:# define IP_BAR_TUNNEL "" |
| 235 | //usage:#endif |
| 236 | //usage:#if ENABLE_FEATURE_IP_ADDRESS || ENABLE_FEATURE_IP_ROUTE || ENABLE_FEATURE_IP_LINK || ENABLE_FEATURE_IP_TUNNEL |
| 237 | //usage:# define IP_BAR_NEIGH "|" |
| 238 | //usage:#else |
| 239 | //usage:# define IP_BAR_NEIGH "" |
| 240 | //usage:#endif |
| 241 | //usage:#if ENABLE_FEATURE_IP_ADDRESS || ENABLE_FEATURE_IP_ROUTE || ENABLE_FEATURE_IP_LINK || ENABLE_FEATURE_IP_TUNNEL || ENABLE_FEATURE_IP_NEIGH |
| 242 | //usage:# define IP_BAR_RULE "|" |
| 243 | //usage:#else |
| 244 | //usage:# define IP_BAR_RULE "" |
| 245 | //usage:#endif |
| 246 | //usage: |
| 247 | //usage:#define ip_trivial_usage |
| 248 | //usage: "[OPTIONS] " |
| 249 | //usage: IF_FEATURE_IP_ADDRESS("address") |
| 250 | //usage: IF_FEATURE_IP_ROUTE( IF_FEATURE_IP_ADDRESS("|")"route") |
| 251 | //usage: IF_FEATURE_IP_LINK( IP_BAR_LINK "link") |
| 252 | //usage: IF_FEATURE_IP_TUNNEL( IP_BAR_TUNNEL"tunnel") |
| 253 | //usage: IF_FEATURE_IP_NEIGH( IP_BAR_NEIGH "neigh") |
| 254 | //usage: IF_FEATURE_IP_RULE( IP_BAR_RULE "rule") |
| 255 | //usage: " [COMMAND]" |
| 256 | //usage:#define ip_full_usage "\n\n" |
| 257 | //usage: "OPTIONS := -f[amily] inet|inet6|link | -o[neline]\n" |
| 258 | //usage: "COMMAND :=" |
| 259 | //usage: IF_FEATURE_IP_ADDRESS("\n" |
| 260 | //usage: "ip addr "ipaddr_trivial_usage) |
| 261 | //usage: IF_FEATURE_IP_ROUTE("\n" |
| 262 | //usage: "ip route "iproute_trivial_usage) |
| 263 | //usage: IF_FEATURE_IP_LINK("\n" |
| 264 | //usage: "ip link "iplink_trivial_usage) |
| 265 | //usage: IF_FEATURE_IP_TUNNEL("\n" |
| 266 | //usage: "ip tunnel "iptunnel_trivial_usage) |
| 267 | //usage: IF_FEATURE_IP_NEIGH("\n" |
| 268 | //usage: "ip neigh "ipneigh_trivial_usage) |
| 269 | //usage: IF_FEATURE_IP_RULE("\n" |
| 270 | //usage: "ip rule "iprule_trivial_usage) |
Pere Orga | 5bc8c00 | 2011-04-11 03:29:49 +0200 | [diff] [blame] | 271 | |
Denis Vlasenko | b6adbf1 | 2007-05-26 19:00:18 +0000 | [diff] [blame] | 272 | #include "libbb.h" |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 273 | |
Bernhard Reutner-Fischer | ab18782 | 2005-10-26 10:47:26 +0000 | [diff] [blame] | 274 | #include "libiproute/utils.h" |
| 275 | #include "libiproute/ip_common.h" |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 276 | |
Denys Vlasenko | 2e9b551 | 2010-07-24 23:27:38 +0200 | [diff] [blame] | 277 | typedef int FAST_FUNC (*ip_func_ptr_t)(char**); |
Denys Vlasenko | e0a6220 | 2010-07-24 23:26:58 +0200 | [diff] [blame] | 278 | |
Denys Vlasenko | 7c5dea3 | 2016-12-22 22:30:13 +0100 | [diff] [blame] | 279 | #if ENABLE_IPADDR \ |
| 280 | || ENABLE_IPLINK \ |
| 281 | || ENABLE_IPROUTE \ |
| 282 | || ENABLE_IPRULE \ |
| 283 | || ENABLE_IPTUNNEL \ |
| 284 | || ENABLE_IPNEIGH |
Denys Vlasenko | e0a6220 | 2010-07-24 23:26:58 +0200 | [diff] [blame] | 285 | static int ip_do(ip_func_ptr_t ip_func, char **argv) |
Bernhard Reutner-Fischer | 07c394e | 2007-04-10 20:11:12 +0000 | [diff] [blame] | 286 | { |
Denis Vlasenko | 3246c0d | 2008-12-04 12:15:19 +0000 | [diff] [blame] | 287 | argv = ip_parse_common_args(argv + 1); |
Denis Vlasenko | ed6a49c | 2007-11-18 22:56:25 +0000 | [diff] [blame] | 288 | return ip_func(argv); |
Bernhard Reutner-Fischer | 07c394e | 2007-04-10 20:11:12 +0000 | [diff] [blame] | 289 | } |
Denys Vlasenko | 7c5dea3 | 2016-12-22 22:30:13 +0100 | [diff] [blame] | 290 | #endif |
Bernhard Reutner-Fischer | 07c394e | 2007-04-10 20:11:12 +0000 | [diff] [blame] | 291 | |
Denys Vlasenko | 7c5dea3 | 2016-12-22 22:30:13 +0100 | [diff] [blame] | 292 | #if ENABLE_IPADDR |
Denis Vlasenko | 9b49a5e | 2007-10-11 10:05:36 +0000 | [diff] [blame] | 293 | int ipaddr_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
Denis Vlasenko | a60f84e | 2008-07-05 09:18:54 +0000 | [diff] [blame] | 294 | int ipaddr_main(int argc UNUSED_PARAM, char **argv) |
Bernhard Reutner-Fischer | 07c394e | 2007-04-10 20:11:12 +0000 | [diff] [blame] | 295 | { |
Denis Vlasenko | 2570b2e | 2008-03-28 01:00:09 +0000 | [diff] [blame] | 296 | return ip_do(do_ipaddr, argv); |
Bernhard Reutner-Fischer | 07c394e | 2007-04-10 20:11:12 +0000 | [diff] [blame] | 297 | } |
| 298 | #endif |
Denys Vlasenko | 7c5dea3 | 2016-12-22 22:30:13 +0100 | [diff] [blame] | 299 | #if ENABLE_IPLINK |
Denis Vlasenko | 9b49a5e | 2007-10-11 10:05:36 +0000 | [diff] [blame] | 300 | int iplink_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
Denis Vlasenko | a60f84e | 2008-07-05 09:18:54 +0000 | [diff] [blame] | 301 | int iplink_main(int argc UNUSED_PARAM, char **argv) |
Bernhard Reutner-Fischer | 07c394e | 2007-04-10 20:11:12 +0000 | [diff] [blame] | 302 | { |
Denis Vlasenko | 2570b2e | 2008-03-28 01:00:09 +0000 | [diff] [blame] | 303 | return ip_do(do_iplink, argv); |
Bernhard Reutner-Fischer | 07c394e | 2007-04-10 20:11:12 +0000 | [diff] [blame] | 304 | } |
| 305 | #endif |
Denys Vlasenko | 7c5dea3 | 2016-12-22 22:30:13 +0100 | [diff] [blame] | 306 | #if ENABLE_IPROUTE |
Denis Vlasenko | 9b49a5e | 2007-10-11 10:05:36 +0000 | [diff] [blame] | 307 | int iproute_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
Denis Vlasenko | a60f84e | 2008-07-05 09:18:54 +0000 | [diff] [blame] | 308 | int iproute_main(int argc UNUSED_PARAM, char **argv) |
Bernhard Reutner-Fischer | 07c394e | 2007-04-10 20:11:12 +0000 | [diff] [blame] | 309 | { |
Denis Vlasenko | 2570b2e | 2008-03-28 01:00:09 +0000 | [diff] [blame] | 310 | return ip_do(do_iproute, argv); |
Bernhard Reutner-Fischer | 07c394e | 2007-04-10 20:11:12 +0000 | [diff] [blame] | 311 | } |
| 312 | #endif |
Denys Vlasenko | 7c5dea3 | 2016-12-22 22:30:13 +0100 | [diff] [blame] | 313 | #if ENABLE_IPRULE |
Denis Vlasenko | 9b49a5e | 2007-10-11 10:05:36 +0000 | [diff] [blame] | 314 | int iprule_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
Denis Vlasenko | a60f84e | 2008-07-05 09:18:54 +0000 | [diff] [blame] | 315 | int iprule_main(int argc UNUSED_PARAM, char **argv) |
Bernhard Reutner-Fischer | 07c394e | 2007-04-10 20:11:12 +0000 | [diff] [blame] | 316 | { |
Denis Vlasenko | 2570b2e | 2008-03-28 01:00:09 +0000 | [diff] [blame] | 317 | return ip_do(do_iprule, argv); |
Bernhard Reutner-Fischer | 07c394e | 2007-04-10 20:11:12 +0000 | [diff] [blame] | 318 | } |
| 319 | #endif |
Denys Vlasenko | 7c5dea3 | 2016-12-22 22:30:13 +0100 | [diff] [blame] | 320 | #if ENABLE_IPTUNNEL |
Denis Vlasenko | 9b49a5e | 2007-10-11 10:05:36 +0000 | [diff] [blame] | 321 | int iptunnel_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
Denis Vlasenko | a60f84e | 2008-07-05 09:18:54 +0000 | [diff] [blame] | 322 | int iptunnel_main(int argc UNUSED_PARAM, char **argv) |
Bernhard Reutner-Fischer | 07c394e | 2007-04-10 20:11:12 +0000 | [diff] [blame] | 323 | { |
Denis Vlasenko | 2570b2e | 2008-03-28 01:00:09 +0000 | [diff] [blame] | 324 | return ip_do(do_iptunnel, argv); |
Bernhard Reutner-Fischer | 07c394e | 2007-04-10 20:11:12 +0000 | [diff] [blame] | 325 | } |
| 326 | #endif |
Denys Vlasenko | 7c5dea3 | 2016-12-22 22:30:13 +0100 | [diff] [blame] | 327 | #if ENABLE_IPNEIGH |
Curt Brune | 6993470 | 2015-10-14 12:53:47 +0200 | [diff] [blame] | 328 | int ipneigh_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
| 329 | int ipneigh_main(int argc UNUSED_PARAM, char **argv) |
| 330 | { |
| 331 | return ip_do(do_ipneigh, argv); |
| 332 | } |
| 333 | #endif |
Bernhard Reutner-Fischer | 07c394e | 2007-04-10 20:11:12 +0000 | [diff] [blame] | 334 | |
Denys Vlasenko | 7c5dea3 | 2016-12-22 22:30:13 +0100 | [diff] [blame] | 335 | #if ENABLE_IP |
| 336 | static int FAST_FUNC ip_print_help(char **argv UNUSED_PARAM) |
| 337 | { |
| 338 | bb_show_usage(); |
| 339 | } |
Bernhard Reutner-Fischer | 07c394e | 2007-04-10 20:11:12 +0000 | [diff] [blame] | 340 | |
Denis Vlasenko | 9b49a5e | 2007-10-11 10:05:36 +0000 | [diff] [blame] | 341 | int ip_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
Denis Vlasenko | a60f84e | 2008-07-05 09:18:54 +0000 | [diff] [blame] | 342 | int ip_main(int argc UNUSED_PARAM, char **argv) |
Glenn L McGrath | f112daa | 2002-12-01 23:04:06 +0000 | [diff] [blame] | 343 | { |
Denys Vlasenko | 7c5dea3 | 2016-12-22 22:30:13 +0100 | [diff] [blame] | 344 | static const char keywords[] ALIGN1 = "" |
Denis Vlasenko | 5e34ff2 | 2009-04-21 11:09:40 +0000 | [diff] [blame] | 345 | IF_FEATURE_IP_ADDRESS("address\0") |
| 346 | IF_FEATURE_IP_ROUTE("route\0") |
Denys Vlasenko | e0a6220 | 2010-07-24 23:26:58 +0200 | [diff] [blame] | 347 | IF_FEATURE_IP_ROUTE("r\0") |
Denis Vlasenko | 5e34ff2 | 2009-04-21 11:09:40 +0000 | [diff] [blame] | 348 | IF_FEATURE_IP_LINK("link\0") |
Denys Vlasenko | e0a6220 | 2010-07-24 23:26:58 +0200 | [diff] [blame] | 349 | IF_FEATURE_IP_TUNNEL("tunnel\0") |
| 350 | IF_FEATURE_IP_TUNNEL("tunl\0") |
Denis Vlasenko | 5e34ff2 | 2009-04-21 11:09:40 +0000 | [diff] [blame] | 351 | IF_FEATURE_IP_RULE("rule\0") |
Curt Brune | 6993470 | 2015-10-14 12:53:47 +0200 | [diff] [blame] | 352 | IF_FEATURE_IP_NEIGH("neigh\0") |
Denis Vlasenko | 990d0f6 | 2007-07-24 15:54:42 +0000 | [diff] [blame] | 353 | ; |
Denys Vlasenko | e0a6220 | 2010-07-24 23:26:58 +0200 | [diff] [blame] | 354 | static const ip_func_ptr_t ip_func_ptrs[] = { |
| 355 | ip_print_help, |
| 356 | IF_FEATURE_IP_ADDRESS(do_ipaddr,) |
| 357 | IF_FEATURE_IP_ROUTE(do_iproute,) |
| 358 | IF_FEATURE_IP_ROUTE(do_iproute,) |
| 359 | IF_FEATURE_IP_LINK(do_iplink,) |
| 360 | IF_FEATURE_IP_TUNNEL(do_iptunnel,) |
| 361 | IF_FEATURE_IP_TUNNEL(do_iptunnel,) |
| 362 | IF_FEATURE_IP_RULE(do_iprule,) |
Curt Brune | 6993470 | 2015-10-14 12:53:47 +0200 | [diff] [blame] | 363 | IF_FEATURE_IP_NEIGH(do_ipneigh,) |
Bernhard Reutner-Fischer | e87d795 | 2007-04-10 18:43:27 +0000 | [diff] [blame] | 364 | }; |
Denys Vlasenko | e0a6220 | 2010-07-24 23:26:58 +0200 | [diff] [blame] | 365 | ip_func_ptr_t ip_func; |
| 366 | int key; |
Bernhard Reutner-Fischer | e87d795 | 2007-04-10 18:43:27 +0000 | [diff] [blame] | 367 | |
Denis Vlasenko | ed6a49c | 2007-11-18 22:56:25 +0000 | [diff] [blame] | 368 | argv = ip_parse_common_args(argv + 1); |
Denys Vlasenko | 7c5dea3 | 2016-12-22 22:30:13 +0100 | [diff] [blame] | 369 | if (ARRAY_SIZE(ip_func_ptrs) > 1 && *argv) |
| 370 | key = index_in_substrings(keywords, *argv++); |
| 371 | else |
| 372 | key = -1; |
Denys Vlasenko | e0a6220 | 2010-07-24 23:26:58 +0200 | [diff] [blame] | 373 | ip_func = ip_func_ptrs[key + 1]; |
| 374 | |
Denis Vlasenko | ed6a49c | 2007-11-18 22:56:25 +0000 | [diff] [blame] | 375 | return ip_func(argv); |
Glenn L McGrath | 9a2d272 | 2002-11-10 01:33:55 +0000 | [diff] [blame] | 376 | } |
Denys Vlasenko | 7c5dea3 | 2016-12-22 22:30:13 +0100 | [diff] [blame] | 377 | #endif |