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