iptunnel.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579
  1. /* vi: set sw=4 ts=4: */
  2. /*
  3. * iptunnel.c "ip tunnel"
  4. *
  5. * Licensed under the GPL v2 or later, see the file LICENSE in this tarball.
  6. *
  7. * Authors: Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru>
  8. *
  9. * Changes:
  10. *
  11. * Rani Assaf <rani@magic.metawire.com> 980929: resolve addresses
  12. * Rani Assaf <rani@magic.metawire.com> 980930: do not allow key for ipip/sit
  13. * Phil Karn <karn@ka9q.ampr.org> 990408: "pmtudisc" flag
  14. */
  15. #include <netinet/ip.h>
  16. #include <net/if.h>
  17. #include <net/if_arp.h>
  18. #include <asm/types.h>
  19. #ifndef __constant_htons
  20. #define __constant_htons htons
  21. #endif
  22. // FYI: #define SIOCDEVPRIVATE 0x89F0
  23. /* From linux/if_tunnel.h. #including it proved troublesome
  24. * (redefiniton errors due to name collisions in linux/ and net[inet]/) */
  25. #define SIOCGETTUNNEL (SIOCDEVPRIVATE + 0)
  26. #define SIOCADDTUNNEL (SIOCDEVPRIVATE + 1)
  27. #define SIOCDELTUNNEL (SIOCDEVPRIVATE + 2)
  28. #define SIOCCHGTUNNEL (SIOCDEVPRIVATE + 3)
  29. //#define SIOCGETPRL (SIOCDEVPRIVATE + 4)
  30. //#define SIOCADDPRL (SIOCDEVPRIVATE + 5)
  31. //#define SIOCDELPRL (SIOCDEVPRIVATE + 6)
  32. //#define SIOCCHGPRL (SIOCDEVPRIVATE + 7)
  33. #define GRE_CSUM __constant_htons(0x8000)
  34. //#define GRE_ROUTING __constant_htons(0x4000)
  35. #define GRE_KEY __constant_htons(0x2000)
  36. #define GRE_SEQ __constant_htons(0x1000)
  37. //#define GRE_STRICT __constant_htons(0x0800)
  38. //#define GRE_REC __constant_htons(0x0700)
  39. //#define GRE_FLAGS __constant_htons(0x00F8)
  40. //#define GRE_VERSION __constant_htons(0x0007)
  41. struct ip_tunnel_parm {
  42. char name[IFNAMSIZ];
  43. int link;
  44. uint16_t i_flags;
  45. uint16_t o_flags;
  46. uint32_t i_key;
  47. uint32_t o_key;
  48. struct iphdr iph;
  49. };
  50. /* SIT-mode i_flags */
  51. //#define SIT_ISATAP 0x0001
  52. //struct ip_tunnel_prl {
  53. // uint32_t addr;
  54. // uint16_t flags;
  55. // uint16_t __reserved;
  56. // uint32_t datalen;
  57. // uint32_t __reserved2;
  58. // /* data follows */
  59. //};
  60. ///* PRL flags */
  61. //#define PRL_DEFAULT 0x0001
  62. #include "ip_common.h" /* #include "libbb.h" is inside */
  63. #include "rt_names.h"
  64. #include "utils.h"
  65. /* Dies on error */
  66. static int do_ioctl_get_ifindex(char *dev)
  67. {
  68. struct ifreq ifr;
  69. int fd;
  70. strncpy_IFNAMSIZ(ifr.ifr_name, dev);
  71. fd = xsocket(AF_INET, SOCK_DGRAM, 0);
  72. xioctl(fd, SIOCGIFINDEX, &ifr);
  73. close(fd);
  74. return ifr.ifr_ifindex;
  75. }
  76. static int do_ioctl_get_iftype(char *dev)
  77. {
  78. struct ifreq ifr;
  79. int fd;
  80. int err;
  81. strncpy_IFNAMSIZ(ifr.ifr_name, dev);
  82. fd = xsocket(AF_INET, SOCK_DGRAM, 0);
  83. err = ioctl_or_warn(fd, SIOCGIFHWADDR, &ifr);
  84. close(fd);
  85. return err ? -1 : ifr.ifr_addr.sa_family;
  86. }
  87. static char *do_ioctl_get_ifname(int idx)
  88. {
  89. struct ifreq ifr;
  90. int fd;
  91. int err;
  92. ifr.ifr_ifindex = idx;
  93. fd = xsocket(AF_INET, SOCK_DGRAM, 0);
  94. err = ioctl_or_warn(fd, SIOCGIFNAME, &ifr);
  95. close(fd);
  96. return err ? NULL : xstrndup(ifr.ifr_name, sizeof(ifr.ifr_name));
  97. }
  98. static int do_get_ioctl(const char *basedev, struct ip_tunnel_parm *p)
  99. {
  100. struct ifreq ifr;
  101. int fd;
  102. int err;
  103. strncpy_IFNAMSIZ(ifr.ifr_name, basedev);
  104. ifr.ifr_ifru.ifru_data = (void*)p;
  105. fd = xsocket(AF_INET, SOCK_DGRAM, 0);
  106. err = ioctl_or_warn(fd, SIOCGETTUNNEL, &ifr);
  107. close(fd);
  108. return err;
  109. }
  110. /* Dies on error, otherwise returns 0 */
  111. static int do_add_ioctl(int cmd, const char *basedev, struct ip_tunnel_parm *p)
  112. {
  113. struct ifreq ifr;
  114. int fd;
  115. if (cmd == SIOCCHGTUNNEL && p->name[0]) {
  116. strncpy_IFNAMSIZ(ifr.ifr_name, p->name);
  117. } else {
  118. strncpy_IFNAMSIZ(ifr.ifr_name, basedev);
  119. }
  120. ifr.ifr_ifru.ifru_data = (void*)p;
  121. fd = xsocket(AF_INET, SOCK_DGRAM, 0);
  122. #if ENABLE_IOCTL_HEX2STR_ERROR
  123. /* #define magic will turn ioctl# into string */
  124. if (cmd == SIOCCHGTUNNEL)
  125. xioctl(fd, SIOCCHGTUNNEL, &ifr);
  126. else
  127. xioctl(fd, SIOCADDTUNNEL, &ifr);
  128. #else
  129. xioctl(fd, cmd, &ifr);
  130. #endif
  131. close(fd);
  132. return 0;
  133. }
  134. /* Dies on error, otherwise returns 0 */
  135. static int do_del_ioctl(const char *basedev, struct ip_tunnel_parm *p)
  136. {
  137. struct ifreq ifr;
  138. int fd;
  139. if (p->name[0]) {
  140. strncpy_IFNAMSIZ(ifr.ifr_name, p->name);
  141. } else {
  142. strncpy_IFNAMSIZ(ifr.ifr_name, basedev);
  143. }
  144. ifr.ifr_ifru.ifru_data = (void*)p;
  145. fd = xsocket(AF_INET, SOCK_DGRAM, 0);
  146. xioctl(fd, SIOCDELTUNNEL, &ifr);
  147. close(fd);
  148. return 0;
  149. }
  150. /* Dies on error */
  151. static void parse_args(char **argv, int cmd, struct ip_tunnel_parm *p)
  152. {
  153. static const char keywords[] ALIGN1 =
  154. "mode\0""ipip\0""ip/ip\0""gre\0""gre/ip\0""sit\0""ipv6/ip\0"
  155. "key\0""ikey\0""okey\0""seq\0""iseq\0""oseq\0"
  156. "csum\0""icsum\0""ocsum\0""nopmtudisc\0""pmtudisc\0"
  157. "remote\0""any\0""local\0""dev\0"
  158. "ttl\0""inherit\0""tos\0""dsfield\0"
  159. "name\0";
  160. enum {
  161. ARG_mode, ARG_ipip, ARG_ip_ip, ARG_gre, ARG_gre_ip, ARG_sit, ARG_ip6_ip,
  162. ARG_key, ARG_ikey, ARG_okey, ARG_seq, ARG_iseq, ARG_oseq,
  163. ARG_csum, ARG_icsum, ARG_ocsum, ARG_nopmtudisc, ARG_pmtudisc,
  164. ARG_remote, ARG_any, ARG_local, ARG_dev,
  165. ARG_ttl, ARG_inherit, ARG_tos, ARG_dsfield,
  166. ARG_name
  167. };
  168. int count = 0;
  169. char medium[IFNAMSIZ];
  170. int key;
  171. memset(p, 0, sizeof(*p));
  172. medium[0] = '\0';
  173. p->iph.version = 4;
  174. p->iph.ihl = 5;
  175. #ifndef IP_DF
  176. #define IP_DF 0x4000 /* Flag: "Don't Fragment" */
  177. #endif
  178. p->iph.frag_off = htons(IP_DF);
  179. while (*argv) {
  180. key = index_in_strings(keywords, *argv);
  181. if (key == ARG_mode) {
  182. NEXT_ARG();
  183. key = index_in_strings(keywords, *argv);
  184. if (key == ARG_ipip ||
  185. key == ARG_ip_ip
  186. ) {
  187. if (p->iph.protocol && p->iph.protocol != IPPROTO_IPIP) {
  188. bb_error_msg_and_die("%s tunnel mode", "you managed to ask for more than one");
  189. }
  190. p->iph.protocol = IPPROTO_IPIP;
  191. } else if (key == ARG_gre ||
  192. key == ARG_gre_ip
  193. ) {
  194. if (p->iph.protocol && p->iph.protocol != IPPROTO_GRE) {
  195. bb_error_msg_and_die("%s tunnel mode", "you managed to ask for more than one");
  196. }
  197. p->iph.protocol = IPPROTO_GRE;
  198. } else if (key == ARG_sit ||
  199. key == ARG_ip6_ip
  200. ) {
  201. if (p->iph.protocol && p->iph.protocol != IPPROTO_IPV6) {
  202. bb_error_msg_and_die("%s tunnel mode", "you managed to ask for more than one");
  203. }
  204. p->iph.protocol = IPPROTO_IPV6;
  205. } else {
  206. bb_error_msg_and_die("%s tunnel mode", "can't guess");
  207. }
  208. } else if (key == ARG_key) {
  209. unsigned uval;
  210. NEXT_ARG();
  211. p->i_flags |= GRE_KEY;
  212. p->o_flags |= GRE_KEY;
  213. if (strchr(*argv, '.'))
  214. p->i_key = p->o_key = get_addr32(*argv);
  215. else {
  216. uval = get_unsigned(*argv, "key");
  217. p->i_key = p->o_key = htonl(uval);
  218. }
  219. } else if (key == ARG_ikey) {
  220. unsigned uval;
  221. NEXT_ARG();
  222. p->i_flags |= GRE_KEY;
  223. if (strchr(*argv, '.'))
  224. p->o_key = get_addr32(*argv);
  225. else {
  226. uval = get_unsigned(*argv, "ikey");
  227. p->i_key = htonl(uval);
  228. }
  229. } else if (key == ARG_okey) {
  230. unsigned uval;
  231. NEXT_ARG();
  232. p->o_flags |= GRE_KEY;
  233. if (strchr(*argv, '.'))
  234. p->o_key = get_addr32(*argv);
  235. else {
  236. uval = get_unsigned(*argv, "okey");
  237. p->o_key = htonl(uval);
  238. }
  239. } else if (key == ARG_seq) {
  240. p->i_flags |= GRE_SEQ;
  241. p->o_flags |= GRE_SEQ;
  242. } else if (key == ARG_iseq) {
  243. p->i_flags |= GRE_SEQ;
  244. } else if (key == ARG_oseq) {
  245. p->o_flags |= GRE_SEQ;
  246. } else if (key == ARG_csum) {
  247. p->i_flags |= GRE_CSUM;
  248. p->o_flags |= GRE_CSUM;
  249. } else if (key == ARG_icsum) {
  250. p->i_flags |= GRE_CSUM;
  251. } else if (key == ARG_ocsum) {
  252. p->o_flags |= GRE_CSUM;
  253. } else if (key == ARG_nopmtudisc) {
  254. p->iph.frag_off = 0;
  255. } else if (key == ARG_pmtudisc) {
  256. p->iph.frag_off = htons(IP_DF);
  257. } else if (key == ARG_remote) {
  258. NEXT_ARG();
  259. key = index_in_strings(keywords, *argv);
  260. if (key != ARG_any)
  261. p->iph.daddr = get_addr32(*argv);
  262. } else if (key == ARG_local) {
  263. NEXT_ARG();
  264. key = index_in_strings(keywords, *argv);
  265. if (key != ARG_any)
  266. p->iph.saddr = get_addr32(*argv);
  267. } else if (key == ARG_dev) {
  268. NEXT_ARG();
  269. strncpy_IFNAMSIZ(medium, *argv);
  270. } else if (key == ARG_ttl) {
  271. unsigned uval;
  272. NEXT_ARG();
  273. key = index_in_strings(keywords, *argv);
  274. if (key != ARG_inherit) {
  275. uval = get_unsigned(*argv, "TTL");
  276. if (uval > 255)
  277. invarg(*argv, "TTL must be <=255");
  278. p->iph.ttl = uval;
  279. }
  280. } else if (key == ARG_tos ||
  281. key == ARG_dsfield
  282. ) {
  283. uint32_t uval;
  284. NEXT_ARG();
  285. key = index_in_strings(keywords, *argv);
  286. if (key != ARG_inherit) {
  287. if (rtnl_dsfield_a2n(&uval, *argv))
  288. invarg(*argv, "TOS");
  289. p->iph.tos = uval;
  290. } else
  291. p->iph.tos = 1;
  292. } else {
  293. if (key == ARG_name) {
  294. NEXT_ARG();
  295. }
  296. if (p->name[0])
  297. duparg2("name", *argv);
  298. strncpy_IFNAMSIZ(p->name, *argv);
  299. if (cmd == SIOCCHGTUNNEL && count == 0) {
  300. struct ip_tunnel_parm old_p;
  301. memset(&old_p, 0, sizeof(old_p));
  302. if (do_get_ioctl(*argv, &old_p))
  303. exit(EXIT_FAILURE);
  304. *p = old_p;
  305. }
  306. }
  307. count++;
  308. argv++;
  309. }
  310. if (p->iph.protocol == 0) {
  311. if (memcmp(p->name, "gre", 3) == 0)
  312. p->iph.protocol = IPPROTO_GRE;
  313. else if (memcmp(p->name, "ipip", 4) == 0)
  314. p->iph.protocol = IPPROTO_IPIP;
  315. else if (memcmp(p->name, "sit", 3) == 0)
  316. p->iph.protocol = IPPROTO_IPV6;
  317. }
  318. if (p->iph.protocol == IPPROTO_IPIP || p->iph.protocol == IPPROTO_IPV6) {
  319. if ((p->i_flags & GRE_KEY) || (p->o_flags & GRE_KEY)) {
  320. bb_error_msg_and_die("keys are not allowed with ipip and sit");
  321. }
  322. }
  323. if (medium[0]) {
  324. p->link = do_ioctl_get_ifindex(medium);
  325. }
  326. if (p->i_key == 0 && IN_MULTICAST(ntohl(p->iph.daddr))) {
  327. p->i_key = p->iph.daddr;
  328. p->i_flags |= GRE_KEY;
  329. }
  330. if (p->o_key == 0 && IN_MULTICAST(ntohl(p->iph.daddr))) {
  331. p->o_key = p->iph.daddr;
  332. p->o_flags |= GRE_KEY;
  333. }
  334. if (IN_MULTICAST(ntohl(p->iph.daddr)) && !p->iph.saddr) {
  335. bb_error_msg_and_die("broadcast tunnel requires a source address");
  336. }
  337. }
  338. /* Return value becomes exitcode. It's okay to not return at all */
  339. static int do_add(int cmd, char **argv)
  340. {
  341. struct ip_tunnel_parm p;
  342. parse_args(argv, cmd, &p);
  343. if (p.iph.ttl && p.iph.frag_off == 0) {
  344. bb_error_msg_and_die("ttl != 0 and noptmudisc are incompatible");
  345. }
  346. switch (p.iph.protocol) {
  347. case IPPROTO_IPIP:
  348. return do_add_ioctl(cmd, "tunl0", &p);
  349. case IPPROTO_GRE:
  350. return do_add_ioctl(cmd, "gre0", &p);
  351. case IPPROTO_IPV6:
  352. return do_add_ioctl(cmd, "sit0", &p);
  353. default:
  354. bb_error_msg_and_die("can't determine tunnel mode (ipip, gre or sit)");
  355. }
  356. }
  357. /* Return value becomes exitcode. It's okay to not return at all */
  358. static int do_del(char **argv)
  359. {
  360. struct ip_tunnel_parm p;
  361. parse_args(argv, SIOCDELTUNNEL, &p);
  362. switch (p.iph.protocol) {
  363. case IPPROTO_IPIP:
  364. return do_del_ioctl("tunl0", &p);
  365. case IPPROTO_GRE:
  366. return do_del_ioctl("gre0", &p);
  367. case IPPROTO_IPV6:
  368. return do_del_ioctl("sit0", &p);
  369. default:
  370. return do_del_ioctl(p.name, &p);
  371. }
  372. }
  373. static void print_tunnel(struct ip_tunnel_parm *p)
  374. {
  375. char s1[256];
  376. char s2[256];
  377. char s3[64];
  378. char s4[64];
  379. format_host(AF_INET, 4, &p->iph.daddr, s1, sizeof(s1));
  380. format_host(AF_INET, 4, &p->iph.saddr, s2, sizeof(s2));
  381. inet_ntop(AF_INET, &p->i_key, s3, sizeof(s3));
  382. inet_ntop(AF_INET, &p->o_key, s4, sizeof(s4));
  383. printf("%s: %s/ip remote %s local %s ",
  384. p->name,
  385. p->iph.protocol == IPPROTO_IPIP ? "ip" :
  386. (p->iph.protocol == IPPROTO_GRE ? "gre" :
  387. (p->iph.protocol == IPPROTO_IPV6 ? "ipv6" : "unknown")),
  388. p->iph.daddr ? s1 : "any", p->iph.saddr ? s2 : "any");
  389. if (p->link) {
  390. char *n = do_ioctl_get_ifname(p->link);
  391. if (n) {
  392. printf(" dev %s ", n);
  393. free(n);
  394. }
  395. }
  396. if (p->iph.ttl)
  397. printf(" ttl %d ", p->iph.ttl);
  398. else
  399. printf(" ttl inherit ");
  400. if (p->iph.tos) {
  401. SPRINT_BUF(b1);
  402. printf(" tos");
  403. if (p->iph.tos & 1)
  404. printf(" inherit");
  405. if (p->iph.tos & ~1)
  406. printf("%c%s ", p->iph.tos & 1 ? '/' : ' ',
  407. rtnl_dsfield_n2a(p->iph.tos & ~1, b1));
  408. }
  409. if (!(p->iph.frag_off & htons(IP_DF)))
  410. printf(" nopmtudisc");
  411. if ((p->i_flags & GRE_KEY) && (p->o_flags & GRE_KEY) && p->o_key == p->i_key)
  412. printf(" key %s", s3);
  413. else if ((p->i_flags | p->o_flags) & GRE_KEY) {
  414. if (p->i_flags & GRE_KEY)
  415. printf(" ikey %s ", s3);
  416. if (p->o_flags & GRE_KEY)
  417. printf(" okey %s ", s4);
  418. }
  419. if (p->i_flags & GRE_SEQ)
  420. printf("%c Drop packets out of sequence.\n", _SL_);
  421. if (p->i_flags & GRE_CSUM)
  422. printf("%c Checksum in received packet is required.", _SL_);
  423. if (p->o_flags & GRE_SEQ)
  424. printf("%c Sequence packets on output.", _SL_);
  425. if (p->o_flags & GRE_CSUM)
  426. printf("%c Checksum output packets.", _SL_);
  427. }
  428. static void do_tunnels_list(struct ip_tunnel_parm *p)
  429. {
  430. char name[IFNAMSIZ];
  431. unsigned long rx_bytes, rx_packets, rx_errs, rx_drops,
  432. rx_fifo, rx_frame,
  433. tx_bytes, tx_packets, tx_errs, tx_drops,
  434. tx_fifo, tx_colls, tx_carrier, rx_multi;
  435. int type;
  436. struct ip_tunnel_parm p1;
  437. char buf[512];
  438. FILE *fp = fopen_or_warn("/proc/net/dev", "r");
  439. if (fp == NULL) {
  440. return;
  441. }
  442. /* skip headers */
  443. fgets(buf, sizeof(buf), fp);
  444. fgets(buf, sizeof(buf), fp);
  445. while (fgets(buf, sizeof(buf), fp) != NULL) {
  446. char *ptr;
  447. /*buf[sizeof(buf) - 1] = 0; - fgets is safe anyway */
  448. ptr = strchr(buf, ':');
  449. if (ptr == NULL ||
  450. (*ptr++ = 0, sscanf(buf, "%s", name) != 1)
  451. ) {
  452. bb_error_msg("wrong format of /proc/net/dev");
  453. return;
  454. }
  455. if (sscanf(ptr, "%lu%lu%lu%lu%lu%lu%lu%*d%lu%lu%lu%lu%lu%lu%lu",
  456. &rx_bytes, &rx_packets, &rx_errs, &rx_drops,
  457. &rx_fifo, &rx_frame, &rx_multi,
  458. &tx_bytes, &tx_packets, &tx_errs, &tx_drops,
  459. &tx_fifo, &tx_colls, &tx_carrier) != 14)
  460. continue;
  461. if (p->name[0] && strcmp(p->name, name))
  462. continue;
  463. type = do_ioctl_get_iftype(name);
  464. if (type == -1) {
  465. bb_error_msg("can't get type of [%s]", name);
  466. continue;
  467. }
  468. if (type != ARPHRD_TUNNEL && type != ARPHRD_IPGRE && type != ARPHRD_SIT)
  469. continue;
  470. memset(&p1, 0, sizeof(p1));
  471. if (do_get_ioctl(name, &p1))
  472. continue;
  473. if ((p->link && p1.link != p->link) ||
  474. (p->name[0] && strcmp(p1.name, p->name)) ||
  475. (p->iph.daddr && p1.iph.daddr != p->iph.daddr) ||
  476. (p->iph.saddr && p1.iph.saddr != p->iph.saddr) ||
  477. (p->i_key && p1.i_key != p->i_key)
  478. ) {
  479. continue;
  480. }
  481. print_tunnel(&p1);
  482. bb_putchar('\n');
  483. }
  484. }
  485. /* Return value becomes exitcode. It's okay to not return at all */
  486. static int do_show(char **argv)
  487. {
  488. int err;
  489. struct ip_tunnel_parm p;
  490. parse_args(argv, SIOCGETTUNNEL, &p);
  491. switch (p.iph.protocol) {
  492. case IPPROTO_IPIP:
  493. err = do_get_ioctl(p.name[0] ? p.name : "tunl0", &p);
  494. break;
  495. case IPPROTO_GRE:
  496. err = do_get_ioctl(p.name[0] ? p.name : "gre0", &p);
  497. break;
  498. case IPPROTO_IPV6:
  499. err = do_get_ioctl(p.name[0] ? p.name : "sit0", &p);
  500. break;
  501. default:
  502. do_tunnels_list(&p);
  503. return 0;
  504. }
  505. if (err)
  506. return -1;
  507. print_tunnel(&p);
  508. bb_putchar('\n');
  509. return 0;
  510. }
  511. /* Return value becomes exitcode. It's okay to not return at all */
  512. int do_iptunnel(char **argv)
  513. {
  514. static const char keywords[] ALIGN1 =
  515. "add\0""change\0""delete\0""show\0""list\0""lst\0";
  516. enum { ARG_add = 0, ARG_change, ARG_del, ARG_show, ARG_list, ARG_lst };
  517. int key;
  518. if (*argv) {
  519. key = index_in_substrings(keywords, *argv);
  520. if (key < 0)
  521. bb_error_msg_and_die(bb_msg_invalid_arg, *argv, applet_name);
  522. argv++;
  523. if (key == ARG_add)
  524. return do_add(SIOCADDTUNNEL, argv);
  525. if (key == ARG_change)
  526. return do_add(SIOCCHGTUNNEL, argv);
  527. if (key == ARG_del)
  528. return do_del(argv);
  529. }
  530. return do_show(argv);
  531. }