ip.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477
  1. /* vi: set sw=4 ts=4: */
  2. /*
  3. * Licensed under GPLv2 or later, see file LICENSE in this source tree.
  4. *
  5. * Authors: Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru>
  6. *
  7. * Changes:
  8. * Rani Assaf <rani@magic.metawire.com> 980929: resolve addresses
  9. * Bernhard Reutner-Fischer rewrote to use index_in_substr_array
  10. */
  11. //config:config IP
  12. //config: bool "ip (35 kb)"
  13. //config: default y
  14. //config: help
  15. //config: The "ip" applet is a TCP/IP interface configuration and routing
  16. //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.
  20. //config:
  21. //config:config IPADDR
  22. //config: bool "ipaddr (15 kb)"
  23. //config: default y
  24. //config: select FEATURE_IP_ADDRESS
  25. //config: help
  26. //config: Short form of "ip addr"
  27. //config:
  28. //config:config IPLINK
  29. //config: bool "iplink (17 kb)"
  30. //config: default y
  31. //config: select FEATURE_IP_LINK
  32. //config: help
  33. //config: Short form of "ip link"
  34. //config:
  35. //config:config IPROUTE
  36. //config: bool "iproute (15 kb)"
  37. //config: default y
  38. //config: select FEATURE_IP_ROUTE
  39. //config: help
  40. //config: Short form of "ip route"
  41. //config:
  42. //config:config IPTUNNEL
  43. //config: bool "iptunnel (9.8 kb)"
  44. //config: default y
  45. //config: select FEATURE_IP_TUNNEL
  46. //config: help
  47. //config: Short form of "ip tunnel"
  48. //config:
  49. //config:config IPRULE
  50. //config: bool "iprule (10 kb)"
  51. //config: default y
  52. //config: select FEATURE_IP_RULE
  53. //config: help
  54. //config: Short form of "ip rule"
  55. //config:
  56. //config:config IPNEIGH
  57. //config: bool "ipneigh (8.6 kb)"
  58. //config: default y
  59. //config: select FEATURE_IP_NEIGH
  60. //config: help
  61. //config: Short form of "ip neigh"
  62. //config:
  63. //config:config FEATURE_IP_ADDRESS
  64. //config: bool "ip address"
  65. //config: default y
  66. //config: depends on IP || IPADDR
  67. //config: help
  68. //config: Address manipulation support for the "ip" applet.
  69. //config:
  70. //config:config FEATURE_IP_LINK
  71. //config: bool "ip link"
  72. //config: default y
  73. //config: depends on IP || IPLINK
  74. //config: help
  75. //config: Configure network devices with "ip".
  76. //config:
  77. //config:config FEATURE_IP_LINK_CAN
  78. //config: bool "ip link set type can"
  79. //config: default y
  80. //config: help
  81. //config: Configure CAN devices with "ip".
  82. //config:
  83. //config:config FEATURE_IP_ROUTE
  84. //config: bool "ip route"
  85. //config: default y
  86. //config: depends on IP || IPROUTE
  87. //config: help
  88. //config: Add support for routing table management to "ip".
  89. //config:
  90. //config:config FEATURE_IP_ROUTE_DIR
  91. //config: string "ip route configuration directory"
  92. //config: default "/etc/iproute2"
  93. //config: depends on FEATURE_IP_ROUTE
  94. //config: help
  95. //config: Location of the "ip" applet routing configuration.
  96. //config:
  97. //config:config FEATURE_IP_TUNNEL
  98. //config: bool "ip tunnel"
  99. //config: default y
  100. //config: depends on IP || IPTUNNEL
  101. //config: help
  102. //config: Add support for tunneling commands to "ip".
  103. //config:
  104. //config:config FEATURE_IP_RULE
  105. //config: bool "ip rule"
  106. //config: default y
  107. //config: depends on IP || IPRULE
  108. //config: help
  109. //config: Add support for rule commands to "ip".
  110. //config:
  111. //config:config FEATURE_IP_NEIGH
  112. //config: bool "ip neighbor"
  113. //config: default y
  114. //config: depends on IP || IPNEIGH
  115. //config: help
  116. //config: Add support for neighbor commands to "ip".
  117. //config:
  118. //config:config FEATURE_IP_RARE_PROTOCOLS
  119. //config: bool "Support displaying rarely used link types"
  120. //config: default n
  121. //config: depends on IP || IPADDR || IPLINK || IPROUTE || IPTUNNEL || IPRULE || IPNEIGH
  122. //config: help
  123. //config: If you are not going to use links of type "frad", "econet",
  124. //config: "bif" etc, you probably don't need to enable this.
  125. //config: Ethernet, wireless, infrared, ppp/slip, ip tunnelling
  126. //config: link types are supported without this option selected.
  127. //applet:IF_IP( APPLET_NOEXEC(ip , ip , BB_DIR_SBIN, BB_SUID_DROP, ip ))
  128. //applet:IF_IPADDR( APPLET_NOEXEC(ipaddr , ipaddr , BB_DIR_SBIN, BB_SUID_DROP, ipaddr ))
  129. //applet:IF_IPLINK( APPLET_NOEXEC(iplink , iplink , BB_DIR_SBIN, BB_SUID_DROP, iplink ))
  130. //applet:IF_IPROUTE( APPLET_NOEXEC(iproute , iproute , BB_DIR_SBIN, BB_SUID_DROP, iproute ))
  131. //applet:IF_IPRULE( APPLET_NOEXEC(iprule , iprule , BB_DIR_SBIN, BB_SUID_DROP, iprule ))
  132. //applet:IF_IPTUNNEL(APPLET_NOEXEC(iptunnel, iptunnel, BB_DIR_SBIN, BB_SUID_DROP, iptunnel))
  133. //applet:IF_IPNEIGH( APPLET_NOEXEC(ipneigh , ipneigh , BB_DIR_SBIN, BB_SUID_DROP, ipneigh ))
  134. //kbuild:lib-$(CONFIG_IP) += ip.o
  135. //kbuild:lib-$(CONFIG_IPADDR) += ip.o
  136. //kbuild:lib-$(CONFIG_IPLINK) += ip.o
  137. //kbuild:lib-$(CONFIG_IPROUTE) += ip.o
  138. //kbuild:lib-$(CONFIG_IPRULE) += ip.o
  139. //kbuild:lib-$(CONFIG_IPTUNNEL) += ip.o
  140. //kbuild:lib-$(CONFIG_IPNEIGH) += ip.o
  141. //--------------123456789.123456789.123456789.123456789.123456789.123456789.123456789.123....79
  142. //usage:#define ipaddr_trivial_usage
  143. //usage: "add|del IFADDR dev IFACE | show|flush [dev IFACE] [to PREFIX]"
  144. //usage:#define ipaddr_full_usage "\n\n"
  145. //usage: "ipaddr add|change|replace|delete dev IFACE [CONFFLAG-LIST] IFADDR\n"
  146. //usage: " IFADDR := PREFIX | ADDR peer PREFIX [broadcast ADDR|+|-]\n"
  147. //usage: " [anycast ADDR] [label STRING] [scope SCOPE]\n"
  148. //usage: " PREFIX := ADDR[/MASK]\n"
  149. //usage: " SCOPE := [host|link|global|NUMBER]\n"
  150. //usage: " CONFFLAG-LIST := [CONFFLAG-LIST] CONFFLAG\n"
  151. //usage: " CONFFLAG := [noprefixroute]\n"
  152. //usage: "ipaddr show|flush [dev IFACE] [scope SCOPE] [to PREFIX] [label PATTERN]"
  153. //usage:
  154. //--------------123456789.123456789.123456789.123456789.123456789.123456789.123456789.123....79
  155. //usage:#define iplink_trivial_usage
  156. //usage: /*Usage:iplink*/"set IFACE [up|down] [arp on|off] [multicast on|off]\n"
  157. //usage: " [promisc on|off] [mtu NUM] [name NAME] [qlen NUM] [address MAC]\n"
  158. //usage: " [master IFACE | nomaster] [netns PID]"IF_FEATURE_IP_LINK_CAN(" [type TYPE ARGS]")
  159. // * short help shows only "set" command, long help continues (with just one "\n")
  160. // * and shows all other commands:
  161. //usage:#define iplink_full_usage "\n"
  162. //usage: "iplink add [link IFACE] IFACE [address MAC] type TYPE [ARGS]\n"
  163. //usage: "iplink delete IFACE type TYPE [ARGS]\n"
  164. //usage: " TYPE ARGS := vlan VLANARGS | vrf table NUM"IF_FEATURE_IP_LINK_CAN(" | can CANARGS")"\n"
  165. //usage: " VLANARGS := id VLANID [protocol 802.1q|802.1ad] [reorder_hdr on|off]\n"
  166. //usage: " [gvrp on|off] [mvrp on|off] [loose_binding on|off]\n"
  167. //usage: IF_FEATURE_IP_LINK_CAN(
  168. //usage: " CANARGS := [bitrate BITRATE [sample-point SAMPLE-POINT]] |\n"
  169. //usage: " [tq TQ prop-seg PROP_SEG phase-seg1 PHASE-SEG1\n"
  170. //usage: " phase-seg2 PHASE-SEG2 [sjw SJW]]\n"
  171. //usage: " [dbitrate BITRATE [dsample-point SAMPLE-POINT]] |\n"
  172. //usage: " [dtq TQ dprop-seg PROP_SEG dphase-seg1 PHASE-SEG1\n"
  173. //usage: " dphase-seg2 PHASE-SEG2 [dsjw SJW]]\n"
  174. //usage: " [loopback on|off] [listen-only on|off] [triple-sampling on|off]\n"
  175. //usage: " [one-shot on|off] [berr-reporting on|off]\n"
  176. //usage: " [fd on|off] [fd-non-iso on|off] [presume-ack on|off]\n"
  177. //usage: " [restart-ms TIME-MS] [restart]\n"
  178. //usage: " [termination 0..65535]\n"
  179. //usage: )
  180. //usage: "iplink show [IFACE]"
  181. //upstream man ip-link-can:
  182. //Usage: ip link set DEVICE type can
  183. // [ bitrate BITRATE [ sample-point SAMPLE-POINT] ] |
  184. // [ tq TQ prop-seg PROP_SEG phase-seg1 PHASE-SEG1
  185. // phase-seg2 PHASE-SEG2 [ sjw SJW ] ]
  186. //
  187. // [ dbitrate BITRATE [ dsample-point SAMPLE-POINT] ] |
  188. // [ dtq TQ dprop-seg PROP_SEG dphase-seg1 PHASE-SEG1
  189. // dphase-seg2 PHASE-SEG2 [ dsjw SJW ] ]
  190. //
  191. // [ loopback { on | off } ]
  192. // [ listen-only { on | off } ]
  193. // [ triple-sampling { on | off } ]
  194. // [ one-shot { on | off } ]
  195. // [ berr-reporting { on | off } ]
  196. // [ fd { on | off } ]
  197. // [ fd-non-iso { on | off } ]
  198. // [ presume-ack { on | off } ]
  199. //
  200. // [ restart-ms TIME-MS ]
  201. // [ restart ]
  202. //
  203. // [ termination { 0..65535 } ]
  204. //
  205. // Where: BITRATE := { 1..1000000 }
  206. // SAMPLE-POINT := { 0.000..0.999 }
  207. // TQ := { NUMBER }
  208. // PROP-SEG := { 1..8 }
  209. // PHASE-SEG1 := { 1..8 }
  210. // PHASE-SEG2 := { 1..8 }
  211. // SJW := { 1..4 }
  212. // RESTART-MS := { 0 | NUMBER }
  213. //upstream man ip-link:
  214. //=====================
  215. //ip link add [link DEV] [ name ] NAME
  216. // [ txqueuelen PACKETS ]
  217. // [ address LLADDR ]
  218. // [ broadcast LLADDR ]
  219. // [ mtu MTU ] [index IDX ]
  220. // [ numtxqueues QUEUE_COUNT ]
  221. // [ numrxqueues QUEUE_COUNT ]
  222. // type TYPE [ ARGS ]
  223. // ip link delete { DEVICE | dev DEVICE | group DEVGROUP } type TYPE [ ARGS ]
  224. // ip link set { DEVICE | dev DEVICE | group DEVGROUP } [ { up | down } ]
  225. // [ arp { on | off } ]
  226. // [ dynamic { on | off } ]
  227. // [ multicast { on | off } ]
  228. // [ allmulticast { on | off } ]
  229. // [ promisc { on | off } ]
  230. // [ trailers { on | off } ]
  231. // [ txqueuelen PACKETS ]
  232. // [ name NEWNAME ]
  233. // [ address LLADDR ]
  234. // [ broadcast LLADDR ]
  235. // [ mtu MTU ]
  236. // [ netns { PID | NAME } ]
  237. // [ link-netnsid ID ]
  238. // [ alias NAME ]
  239. // [ vf NUM [ mac LLADDR ]
  240. // [ vlan VLANID [ qos VLAN-QOS ] ]
  241. // [ rate TXRATE ]
  242. // [ spoofchk { on | off} ]
  243. // [ query_rss { on | off} ]
  244. // [ state { auto | enable | disable} ] ]
  245. // [ trust { on | off} ] ]
  246. // [ master DEVICE ]
  247. // [ nomaster ]
  248. // [ addrgenmode { eui64 | none | stable_secret | random } ]
  249. // [ protodown { on | off } ]
  250. // ip link show [ DEVICE | group GROUP ] [up] [master DEV] [type TYPE]
  251. // ip link help [ TYPE ]
  252. //TYPE := { vlan | veth | vcan | dummy | ifb | macvlan | macvtap |
  253. // bridge | bond | ipoib | ip6tnl | ipip | sit | vxlan |
  254. // gre | gretap | ip6gre | ip6gretap | vti | nlmon |
  255. // bond_slave | ipvlan | geneve | bridge_slave | vrf }
  256. //usage:
  257. //--------------123456789.123456789.123456789.123456789.123456789.123456789.123456789.123....79
  258. //usage:#define iproute_trivial_usage
  259. //usage: "list|flush|add|del|change|append|replace|test ROUTE"
  260. //usage:#define iproute_full_usage "\n\n"
  261. //usage: "iproute list|flush SELECTOR\n"
  262. //usage: " SELECTOR := [root PREFIX] [match PREFIX] [proto RTPROTO]\n"
  263. //usage: " PREFIX := default|ADDR[/MASK]\n"
  264. //usage: "iproute get ADDR [from ADDR iif IFACE]\n"
  265. //usage: " [oif IFACE] [tos TOS]\n"
  266. //usage: "iproute add|del|change|append|replace|test ROUTE\n"
  267. //usage: " ROUTE := NODE_SPEC [INFO_SPEC]\n"
  268. //usage: " NODE_SPEC := PREFIX"IF_FEATURE_IP_RULE(" [table TABLE_ID]")" [proto RTPROTO] [scope SCOPE] [metric METRIC]\n"
  269. //usage: " INFO_SPEC := NH OPTIONS\n"
  270. //usage: " NH := [via [inet|inet6] ADDR] [dev IFACE] [src ADDR] [onlink]\n"
  271. //usage: " OPTIONS := [mtu [lock] NUM] [advmss [lock] NUM]"
  272. //upstream man ip-route:
  273. //======================
  274. //ip route { show | flush } SELECTOR
  275. //ip route save SELECTOR
  276. //ip route restore
  277. //ip route get ADDRESS [ from ADDRESS iif STRING ] [ oif STRING ] [ tos TOS ]
  278. //ip route { add | del | change | append | replace } ROUTE
  279. //SELECTOR := [ root PREFIX ] [ match PREFIX ] [ exact PREFIX ] [ table TABLE_ID ] [ proto RTPROTO ] [ type TYPE ] [ scope SCOPE ]
  280. //ROUTE := NODE_SPEC [ INFO_SPEC ]
  281. //NODE_SPEC := [ TYPE ] PREFIX [ tos TOS ] [ table TABLE_ID ] [ proto RTPROTO ] [ scope SCOPE ] [ metric METRIC ]
  282. //INFO_SPEC := NH OPTIONS FLAGS [ nexthop NH ] ...
  283. //NH := [ encap ENCAP ] [ via [ FAMILY ] ADDRESS ] [ dev STRING ] [ weight NUMBER ] NHFLAGS
  284. // ..............................................................^ I guess [src ADDRESS] should be here
  285. //FAMILY := [ inet | inet6 | ipx | dnet | mpls | bridge | link ]
  286. //OPTIONS := FLAGS [ mtu NUMBER ] [ advmss NUMBER ] [ as [ to ] ADDRESS ] rtt TIME ] [ rttvar TIME ] [ reordering NUMBER ] [ window NUMBER ] [ cwnd NUMBER ] [ ssthresh REALM ] [ realms REALM ]
  287. // [ rto_min TIME ] [ initcwnd NUMBER ] [ initrwnd NUMBER ] [ features FEATURES ] [ quickack BOOL ] [ congctl NAME ] [ pref PREF ] [ expires TIME ]
  288. //TYPE := [ unicast | local | broadcast | multicast | throw | unreachable | prohibit | blackhole | nat ]
  289. //TABLE_ID := [ local | main | default | all | NUMBER ]
  290. //SCOPE := [ host | link | global | NUMBER ]
  291. //NHFLAGS := [ onlink | pervasive ]
  292. //RTPROTO := [ kernel | boot | static | NUMBER ]
  293. //FEATURES := [ ecn | ]
  294. //PREF := [ low | medium | high ]
  295. //ENCAP := [ MPLS | IP ]
  296. //ENCAP_MPLS := mpls [ LABEL ]
  297. //ENCAP_IP := ip id TUNNEL_ID dst REMOTE_IP [ tos TOS ] [ ttl TTL ]
  298. //usage:
  299. //--------------123456789.123456789.123456789.123456789.123456789.123456789.123456789.123....79
  300. //usage:#define iprule_trivial_usage
  301. //usage: "[list] | add|del SELECTOR ACTION"
  302. //usage:#define iprule_full_usage "\n\n"
  303. //usage: " SELECTOR := [from PREFIX] [to PREFIX] [tos TOS] [fwmark FWMARK[/MASK]]\n"
  304. //usage: " [dev IFACE] [pref NUMBER]\n"
  305. //usage: " ACTION := [table TABLE_ID] [nat ADDR]\n"
  306. //usage: " [prohibit|reject|unreachable]\n"
  307. //usage: " [realms [SRCREALM/]DSTREALM]\n"
  308. //usage: " TABLE_ID := [local|main|default|NUMBER]"
  309. //usage:
  310. //--------------123456789.123456789.123456789.123456789.123456789.123456789.123456789.123....79
  311. //usage:#define iptunnel_trivial_usage
  312. //usage: "add|change|del|show [NAME]\n"
  313. //usage: " [mode ipip|gre|sit] [remote ADDR] [local ADDR] [ttl TTL]"
  314. //usage:#define iptunnel_full_usage "\n\n"
  315. //usage: "iptunnel add|change|del|show [NAME]\n"
  316. //usage: " [mode ipip|gre|sit] [remote ADDR] [local ADDR]\n"
  317. //usage: " [[i|o]seq] [[i|o]key KEY] [[i|o]csum]\n"
  318. //usage: " [ttl TTL] [tos TOS] [[no]pmtudisc] [dev PHYS_DEV]"
  319. //usage:
  320. //usage:#define ipneigh_trivial_usage
  321. //usage: "show|flush [to PREFIX] [dev DEV] [nud STATE]"
  322. //usage:#define ipneigh_full_usage ""
  323. //usage:
  324. //usage:#if ENABLE_FEATURE_IP_ADDRESS || ENABLE_FEATURE_IP_ROUTE
  325. //usage:# define IP_BAR_LINK "|"
  326. //usage:#else
  327. //usage:# define IP_BAR_LINK ""
  328. //usage:#endif
  329. //usage:#if ENABLE_FEATURE_IP_ADDRESS || ENABLE_FEATURE_IP_ROUTE || ENABLE_FEATURE_IP_LINK
  330. //usage:# define IP_BAR_TUNNEL "|"
  331. //usage:#else
  332. //usage:# define IP_BAR_TUNNEL ""
  333. //usage:#endif
  334. //usage:#if ENABLE_FEATURE_IP_ADDRESS || ENABLE_FEATURE_IP_ROUTE || ENABLE_FEATURE_IP_LINK || ENABLE_FEATURE_IP_TUNNEL
  335. //usage:# define IP_BAR_NEIGH "|"
  336. //usage:#else
  337. //usage:# define IP_BAR_NEIGH ""
  338. //usage:#endif
  339. //usage:#if ENABLE_FEATURE_IP_ADDRESS || ENABLE_FEATURE_IP_ROUTE || ENABLE_FEATURE_IP_LINK || ENABLE_FEATURE_IP_TUNNEL || ENABLE_FEATURE_IP_NEIGH
  340. //usage:# define IP_BAR_RULE "|"
  341. //usage:#else
  342. //usage:# define IP_BAR_RULE ""
  343. //usage:#endif
  344. //usage:
  345. //usage:#define ip_trivial_usage
  346. //usage: "[OPTIONS] "
  347. //usage: IF_FEATURE_IP_ADDRESS("address")
  348. //usage: IF_FEATURE_IP_ROUTE( IF_FEATURE_IP_ADDRESS("|")"route")
  349. //usage: IF_FEATURE_IP_LINK( IP_BAR_LINK "link")
  350. //usage: IF_FEATURE_IP_TUNNEL( IP_BAR_TUNNEL"tunnel")
  351. //usage: IF_FEATURE_IP_NEIGH( IP_BAR_NEIGH "neigh")
  352. //usage: IF_FEATURE_IP_RULE( IP_BAR_RULE "rule")
  353. //usage: " [ARGS]"
  354. //usage:#define ip_full_usage "\n\n"
  355. //usage: "OPTIONS := -f[amily] inet|inet6|link | -o[neline]\n"
  356. //usage: IF_FEATURE_IP_ADDRESS("\n"
  357. //usage: "ip addr "ipaddr_trivial_usage)
  358. //usage: IF_FEATURE_IP_ROUTE("\n"
  359. //usage: "ip route "iproute_trivial_usage)
  360. //usage: IF_FEATURE_IP_LINK("\n"
  361. //usage: "ip link "iplink_trivial_usage)
  362. //usage: IF_FEATURE_IP_TUNNEL("\n"
  363. //usage: "ip tunnel "iptunnel_trivial_usage)
  364. //usage: IF_FEATURE_IP_NEIGH("\n"
  365. //usage: "ip neigh "ipneigh_trivial_usage)
  366. //usage: IF_FEATURE_IP_RULE("\n"
  367. //usage: "ip rule "iprule_trivial_usage)
  368. #include "libbb.h"
  369. #include "libiproute/utils.h"
  370. #include "libiproute/ip_common.h"
  371. typedef int FAST_FUNC (*ip_func_ptr_t)(char**);
  372. #if ENABLE_IPADDR \
  373. || ENABLE_IPLINK \
  374. || ENABLE_IPROUTE \
  375. || ENABLE_IPRULE \
  376. || ENABLE_IPTUNNEL \
  377. || ENABLE_IPNEIGH
  378. static int ip_do(ip_func_ptr_t ip_func, char **argv)
  379. {
  380. argv = ip_parse_common_args(argv + 1);
  381. return ip_func(argv);
  382. }
  383. #endif
  384. #if ENABLE_IPADDR
  385. int ipaddr_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
  386. int ipaddr_main(int argc UNUSED_PARAM, char **argv)
  387. {
  388. return ip_do(do_ipaddr, argv);
  389. }
  390. #endif
  391. #if ENABLE_IPLINK
  392. int iplink_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
  393. int iplink_main(int argc UNUSED_PARAM, char **argv)
  394. {
  395. return ip_do(do_iplink, argv);
  396. }
  397. #endif
  398. #if ENABLE_IPROUTE
  399. int iproute_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
  400. int iproute_main(int argc UNUSED_PARAM, char **argv)
  401. {
  402. return ip_do(do_iproute, argv);
  403. }
  404. #endif
  405. #if ENABLE_IPRULE
  406. int iprule_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
  407. int iprule_main(int argc UNUSED_PARAM, char **argv)
  408. {
  409. return ip_do(do_iprule, argv);
  410. }
  411. #endif
  412. #if ENABLE_IPTUNNEL
  413. int iptunnel_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
  414. int iptunnel_main(int argc UNUSED_PARAM, char **argv)
  415. {
  416. return ip_do(do_iptunnel, argv);
  417. }
  418. #endif
  419. #if ENABLE_IPNEIGH
  420. int ipneigh_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
  421. int ipneigh_main(int argc UNUSED_PARAM, char **argv)
  422. {
  423. return ip_do(do_ipneigh, argv);
  424. }
  425. #endif
  426. #if ENABLE_IP
  427. static int FAST_FUNC ip_print_help(char **argv UNUSED_PARAM)
  428. {
  429. bb_show_usage();
  430. }
  431. int ip_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
  432. int ip_main(int argc UNUSED_PARAM, char **argv)
  433. {
  434. static const char keywords[] ALIGN1 = ""
  435. IF_FEATURE_IP_ADDRESS("address\0")
  436. IF_FEATURE_IP_ROUTE("route\0")
  437. IF_FEATURE_IP_ROUTE("r\0")
  438. IF_FEATURE_IP_LINK("link\0")
  439. IF_FEATURE_IP_TUNNEL("tunnel\0")
  440. IF_FEATURE_IP_TUNNEL("tunl\0")
  441. IF_FEATURE_IP_RULE("rule\0")
  442. IF_FEATURE_IP_NEIGH("neigh\0")
  443. ;
  444. static const ip_func_ptr_t ip_func_ptrs[] ALIGN_PTR = {
  445. ip_print_help,
  446. IF_FEATURE_IP_ADDRESS(do_ipaddr,)
  447. IF_FEATURE_IP_ROUTE(do_iproute,)
  448. IF_FEATURE_IP_ROUTE(do_iproute,)
  449. IF_FEATURE_IP_LINK(do_iplink,)
  450. IF_FEATURE_IP_TUNNEL(do_iptunnel,)
  451. IF_FEATURE_IP_TUNNEL(do_iptunnel,)
  452. IF_FEATURE_IP_RULE(do_iprule,)
  453. IF_FEATURE_IP_NEIGH(do_ipneigh,)
  454. };
  455. ip_func_ptr_t ip_func;
  456. int key;
  457. argv = ip_parse_common_args(argv + 1);
  458. if (ARRAY_SIZE(ip_func_ptrs) > 1 && *argv)
  459. key = index_in_substrings(keywords, *argv++);
  460. else
  461. key = -1;
  462. ip_func = ip_func_ptrs[key + 1];
  463. return ip_func(argv);
  464. }
  465. #endif