3
0

iptunnel.c 15 KB

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