]> git.proxmox.com Git - mirror_iproute2.git/blob - ip/iptunnel.c
ip: fix format string when reading statistics
[mirror_iproute2.git] / ip / iptunnel.c
1 /*
2 * iptunnel.c "ip tunnel"
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version
7 * 2 of the License, or (at your option) any later version.
8 *
9 * Authors: Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru>
10 *
11 */
12
13 #include <stdio.h>
14 #include <stdlib.h>
15 #include <string.h>
16 #include <unistd.h>
17 #include <sys/types.h>
18 #include <sys/socket.h>
19 #include <arpa/inet.h>
20 #include <sys/ioctl.h>
21 #include <net/if.h>
22 #include <net/if_arp.h>
23 #include <linux/ip.h>
24 #include <linux/if_tunnel.h>
25
26 #include "rt_names.h"
27 #include "utils.h"
28 #include "ip_common.h"
29 #include "tunnel.h"
30
31 static void usage(void) __attribute__((noreturn));
32
33 static void usage(void)
34 {
35 fprintf(stderr, "Usage: ip tunnel { add | change | del | show | prl | 6rd } [ NAME ]\n");
36 fprintf(stderr, " [ mode { ipip | gre | sit | isatap | vti } ] [ remote ADDR ] [ local ADDR ]\n");
37 fprintf(stderr, " [ [i|o]seq ] [ [i|o]key KEY ] [ [i|o]csum ]\n");
38 fprintf(stderr, " [ prl-default ADDR ] [ prl-nodefault ADDR ] [ prl-delete ADDR ]\n");
39 fprintf(stderr, " [ 6rd-prefix ADDR ] [ 6rd-relay_prefix ADDR ] [ 6rd-reset ]\n");
40 fprintf(stderr, " [ ttl TTL ] [ tos TOS ] [ [no]pmtudisc ] [ dev PHYS_DEV ]\n");
41 fprintf(stderr, "\n");
42 fprintf(stderr, "Where: NAME := STRING\n");
43 fprintf(stderr, " ADDR := { IP_ADDRESS | any }\n");
44 fprintf(stderr, " TOS := { STRING | 00..ff | inherit | inherit/STRING | inherit/00..ff }\n");
45 fprintf(stderr, " TTL := { 1..255 | inherit }\n");
46 fprintf(stderr, " KEY := { DOTTED_QUAD | NUMBER }\n");
47 exit(-1);
48 }
49
50 static void set_tunnel_proto(struct ip_tunnel_parm *p, int proto)
51 {
52 if (p->iph.protocol && p->iph.protocol != proto) {
53 fprintf(stderr,
54 "You managed to ask for more than one tunnel mode.\n");
55 exit(-1);
56 }
57 p->iph.protocol = proto;
58 }
59
60 static int parse_args(int argc, char **argv, int cmd, struct ip_tunnel_parm *p)
61 {
62 int count = 0;
63 char medium[IFNAMSIZ];
64 int isatap = 0;
65
66 memset(p, 0, sizeof(*p));
67 memset(&medium, 0, sizeof(medium));
68
69 p->iph.version = 4;
70 p->iph.ihl = 5;
71 #ifndef IP_DF
72 #define IP_DF 0x4000 /* Flag: "Don't Fragment" */
73 #endif
74 p->iph.frag_off = htons(IP_DF);
75
76 while (argc > 0) {
77 if (strcmp(*argv, "mode") == 0) {
78 NEXT_ARG();
79 if (strcmp(*argv, "ipip") == 0 ||
80 strcmp(*argv, "ip/ip") == 0) {
81 set_tunnel_proto(p, IPPROTO_IPIP);
82 } else if (strcmp(*argv, "gre") == 0 ||
83 strcmp(*argv, "gre/ip") == 0) {
84 set_tunnel_proto(p, IPPROTO_GRE);
85 } else if (strcmp(*argv, "sit") == 0 ||
86 strcmp(*argv, "ipv6/ip") == 0) {
87 set_tunnel_proto(p, IPPROTO_IPV6);
88 } else if (strcmp(*argv, "isatap") == 0) {
89 set_tunnel_proto(p, IPPROTO_IPV6);
90 isatap++;
91 } else if (strcmp(*argv, "vti") == 0) {
92 set_tunnel_proto(p, IPPROTO_IPIP);
93 p->i_flags |= VTI_ISVTI;
94 } else {
95 fprintf(stderr,
96 "Unknown tunnel mode \"%s\"\n", *argv);
97 exit(-1);
98 }
99 } else if (strcmp(*argv, "key") == 0) {
100 NEXT_ARG();
101 p->i_flags |= GRE_KEY;
102 p->o_flags |= GRE_KEY;
103 p->i_key = p->o_key = tnl_parse_key("key", *argv);
104 } else if (strcmp(*argv, "ikey") == 0) {
105 NEXT_ARG();
106 p->i_flags |= GRE_KEY;
107 p->i_key = tnl_parse_key("ikey", *argv);
108 } else if (strcmp(*argv, "okey") == 0) {
109 NEXT_ARG();
110 p->o_flags |= GRE_KEY;
111 p->o_key = tnl_parse_key("okey", *argv);
112 } else if (strcmp(*argv, "seq") == 0) {
113 p->i_flags |= GRE_SEQ;
114 p->o_flags |= GRE_SEQ;
115 } else if (strcmp(*argv, "iseq") == 0) {
116 p->i_flags |= GRE_SEQ;
117 } else if (strcmp(*argv, "oseq") == 0) {
118 p->o_flags |= GRE_SEQ;
119 } else if (strcmp(*argv, "csum") == 0) {
120 p->i_flags |= GRE_CSUM;
121 p->o_flags |= GRE_CSUM;
122 } else if (strcmp(*argv, "icsum") == 0) {
123 p->i_flags |= GRE_CSUM;
124 } else if (strcmp(*argv, "ocsum") == 0) {
125 p->o_flags |= GRE_CSUM;
126 } else if (strcmp(*argv, "nopmtudisc") == 0) {
127 p->iph.frag_off = 0;
128 } else if (strcmp(*argv, "pmtudisc") == 0) {
129 p->iph.frag_off = htons(IP_DF);
130 } else if (strcmp(*argv, "remote") == 0) {
131 NEXT_ARG();
132 if (strcmp(*argv, "any"))
133 p->iph.daddr = get_addr32(*argv);
134 else
135 p->iph.daddr = htonl(INADDR_ANY);
136 } else if (strcmp(*argv, "local") == 0) {
137 NEXT_ARG();
138 if (strcmp(*argv, "any"))
139 p->iph.saddr = get_addr32(*argv);
140 else
141 p->iph.saddr = htonl(INADDR_ANY);
142 } else if (strcmp(*argv, "dev") == 0) {
143 NEXT_ARG();
144 strncpy(medium, *argv, IFNAMSIZ - 1);
145 } else if (strcmp(*argv, "ttl") == 0 ||
146 strcmp(*argv, "hoplimit") == 0 ||
147 strcmp(*argv, "hlim") == 0) {
148 __u8 uval;
149
150 NEXT_ARG();
151 if (strcmp(*argv, "inherit") != 0) {
152 if (get_u8(&uval, *argv, 0))
153 invarg("invalid TTL\n", *argv);
154 p->iph.ttl = uval;
155 }
156 } else if (strcmp(*argv, "tos") == 0 ||
157 strcmp(*argv, "tclass") == 0 ||
158 matches(*argv, "dsfield") == 0) {
159 char *dsfield;
160 __u32 uval;
161
162 NEXT_ARG();
163 dsfield = *argv;
164 strsep(&dsfield, "/");
165 if (strcmp(*argv, "inherit") != 0) {
166 dsfield = *argv;
167 p->iph.tos = 0;
168 } else
169 p->iph.tos = 1;
170 if (dsfield) {
171 if (rtnl_dsfield_a2n(&uval, dsfield))
172 invarg("bad TOS value", *argv);
173 p->iph.tos |= uval;
174 }
175 } else {
176 if (strcmp(*argv, "name") == 0)
177 NEXT_ARG();
178 else if (matches(*argv, "help") == 0)
179 usage();
180
181 if (p->name[0])
182 duparg2("name", *argv);
183 strncpy(p->name, *argv, IFNAMSIZ - 1);
184 if (cmd == SIOCCHGTUNNEL && count == 0) {
185 struct ip_tunnel_parm old_p;
186
187 memset(&old_p, 0, sizeof(old_p));
188 if (tnl_get_ioctl(*argv, &old_p))
189 return -1;
190 *p = old_p;
191 }
192 }
193 count++;
194 argc--; argv++;
195 }
196
197
198 if (p->iph.protocol == 0) {
199 if (memcmp(p->name, "gre", 3) == 0)
200 p->iph.protocol = IPPROTO_GRE;
201 else if (memcmp(p->name, "ipip", 4) == 0)
202 p->iph.protocol = IPPROTO_IPIP;
203 else if (memcmp(p->name, "sit", 3) == 0)
204 p->iph.protocol = IPPROTO_IPV6;
205 else if (memcmp(p->name, "isatap", 6) == 0) {
206 p->iph.protocol = IPPROTO_IPV6;
207 isatap++;
208 } else if (memcmp(p->name, "vti", 3) == 0) {
209 p->iph.protocol = IPPROTO_IPIP;
210 p->i_flags |= VTI_ISVTI;
211 }
212 }
213
214 if ((p->i_flags & GRE_KEY) || (p->o_flags & GRE_KEY)) {
215 if (!(p->i_flags & VTI_ISVTI) &&
216 (p->iph.protocol != IPPROTO_GRE)) {
217 fprintf(stderr, "Keys are not allowed with ipip and sit tunnels\n");
218 return -1;
219 }
220 }
221
222 if (medium[0]) {
223 p->link = ll_name_to_index(medium);
224 if (p->link == 0) {
225 fprintf(stderr, "Cannot find device \"%s\"\n", medium);
226 return -1;
227 }
228 }
229
230 if (p->i_key == 0 && IN_MULTICAST(ntohl(p->iph.daddr))) {
231 p->i_key = p->iph.daddr;
232 p->i_flags |= GRE_KEY;
233 }
234 if (p->o_key == 0 && IN_MULTICAST(ntohl(p->iph.daddr))) {
235 p->o_key = p->iph.daddr;
236 p->o_flags |= GRE_KEY;
237 }
238 if (IN_MULTICAST(ntohl(p->iph.daddr)) && !p->iph.saddr) {
239 fprintf(stderr, "A broadcast tunnel requires a source address\n");
240 return -1;
241 }
242 if (isatap)
243 p->i_flags |= SIT_ISATAP;
244
245 return 0;
246 }
247
248 static const char *tnl_defname(const struct ip_tunnel_parm *p)
249 {
250 switch (p->iph.protocol) {
251 case IPPROTO_IPIP:
252 if (p->i_flags & VTI_ISVTI)
253 return "ip_vti0";
254 else
255 return "tunl0";
256 case IPPROTO_GRE:
257 return "gre0";
258 case IPPROTO_IPV6:
259 return "sit0";
260 }
261 return NULL;
262 }
263
264 static int do_add(int cmd, int argc, char **argv)
265 {
266 struct ip_tunnel_parm p;
267 const char *basedev;
268
269 if (parse_args(argc, argv, cmd, &p) < 0)
270 return -1;
271
272 if (p.iph.ttl && p.iph.frag_off == 0) {
273 fprintf(stderr, "ttl != 0 and nopmtudisc are incompatible\n");
274 return -1;
275 }
276
277 basedev = tnl_defname(&p);
278 if (!basedev) {
279 fprintf(stderr,
280 "cannot determine tunnel mode (ipip, gre, vti or sit)\n");
281 return -1;
282 }
283
284 return tnl_add_ioctl(cmd, basedev, p.name, &p);
285 }
286
287 static int do_del(int argc, char **argv)
288 {
289 struct ip_tunnel_parm p;
290
291 if (parse_args(argc, argv, SIOCDELTUNNEL, &p) < 0)
292 return -1;
293
294 return tnl_del_ioctl(tnl_defname(&p) ? : p.name, p.name, &p);
295 }
296
297 static void print_tunnel(struct ip_tunnel_parm *p)
298 {
299 struct ip_tunnel_6rd ip6rd;
300 char s1[1024];
301 char s2[1024];
302
303 memset(&ip6rd, 0, sizeof(ip6rd));
304
305 /* Do not use format_host() for local addr,
306 * symbolic name will not be useful.
307 */
308 printf("%s: %s/ip remote %s local %s",
309 p->name,
310 tnl_strproto(p->iph.protocol),
311 p->iph.daddr ? format_host(AF_INET, 4, &p->iph.daddr, s1, sizeof(s1)) : "any",
312 p->iph.saddr ? rt_addr_n2a(AF_INET, 4, &p->iph.saddr, s2, sizeof(s2)) : "any");
313
314 if (p->iph.protocol == IPPROTO_IPV6 && (p->i_flags & SIT_ISATAP)) {
315 struct ip_tunnel_prl prl[16];
316 int i;
317
318 memset(prl, 0, sizeof(prl));
319 prl[0].datalen = sizeof(prl) - sizeof(prl[0]);
320 prl[0].addr = htonl(INADDR_ANY);
321
322 if (!tnl_prl_ioctl(SIOCGETPRL, p->name, prl))
323 for (i = 1; i < ARRAY_SIZE(prl); i++) {
324 if (prl[i].addr != htonl(INADDR_ANY)) {
325 printf(" %s %s ",
326 (prl[i].flags & PRL_DEFAULT) ? "pdr" : "pr",
327 format_host(AF_INET, 4, &prl[i].addr, s1, sizeof(s1)));
328 }
329 }
330 }
331
332 if (p->link) {
333 const char *n = ll_index_to_name(p->link);
334
335 if (n)
336 printf(" dev %s", n);
337 }
338
339 if (p->iph.ttl)
340 printf(" ttl %d", p->iph.ttl);
341 else
342 printf(" ttl inherit");
343
344 if (p->iph.tos) {
345 SPRINT_BUF(b1);
346 printf(" tos");
347 if (p->iph.tos & 1)
348 printf(" inherit");
349 if (p->iph.tos & ~1)
350 printf("%c%s ", p->iph.tos & 1 ? '/' : ' ',
351 rtnl_dsfield_n2a(p->iph.tos & ~1, b1, sizeof(b1)));
352 }
353
354 if (!(p->iph.frag_off & htons(IP_DF)))
355 printf(" nopmtudisc");
356
357 if (p->iph.protocol == IPPROTO_IPV6 && !tnl_ioctl_get_6rd(p->name, &ip6rd) && ip6rd.prefixlen) {
358 printf(" 6rd-prefix %s/%u",
359 inet_ntop(AF_INET6, &ip6rd.prefix, s1, sizeof(s1)),
360 ip6rd.prefixlen);
361 if (ip6rd.relay_prefix) {
362 printf(" 6rd-relay_prefix %s/%u",
363 format_host(AF_INET, 4, &ip6rd.relay_prefix, s1, sizeof(s1)),
364 ip6rd.relay_prefixlen);
365 }
366 }
367
368 if ((p->i_flags & GRE_KEY) && (p->o_flags & GRE_KEY) && p->o_key == p->i_key)
369 printf(" key %u", ntohl(p->i_key));
370 else if ((p->i_flags | p->o_flags) & GRE_KEY) {
371 if (p->i_flags & GRE_KEY)
372 printf(" ikey %u", ntohl(p->i_key));
373 if (p->o_flags & GRE_KEY)
374 printf(" okey %u", ntohl(p->o_key));
375 }
376
377 if (p->i_flags & GRE_SEQ)
378 printf("%s Drop packets out of sequence.", _SL_);
379 if (p->i_flags & GRE_CSUM)
380 printf("%s Checksum in received packet is required.", _SL_);
381 if (p->o_flags & GRE_SEQ)
382 printf("%s Sequence packets on output.", _SL_);
383 if (p->o_flags & GRE_CSUM)
384 printf("%s Checksum output packets.", _SL_);
385 }
386
387 static int do_tunnels_list(struct ip_tunnel_parm *p)
388 {
389 char buf[512];
390 int err = -1;
391 FILE *fp = fopen("/proc/net/dev", "r");
392
393 if (fp == NULL) {
394 perror("fopen");
395 return -1;
396 }
397
398 /* skip header lines */
399 if (!fgets(buf, sizeof(buf), fp) ||
400 !fgets(buf, sizeof(buf), fp)) {
401 fprintf(stderr, "/proc/net/dev read error\n");
402 goto end;
403 }
404
405 while (fgets(buf, sizeof(buf), fp) != NULL) {
406 char name[IFNAMSIZ];
407 int index, type;
408 unsigned long rx_bytes, rx_packets, rx_errs, rx_drops,
409 rx_fifo, rx_frame,
410 tx_bytes, tx_packets, tx_errs, tx_drops,
411 tx_fifo, tx_colls, tx_carrier, rx_multi;
412 struct ip_tunnel_parm p1;
413 char *ptr;
414
415 buf[sizeof(buf) - 1] = 0;
416 ptr = strchr(buf, ':');
417 if (ptr == NULL ||
418 (*ptr++ = 0, sscanf(buf, "%s", name) != 1)) {
419 fprintf(stderr, "Wrong format for /proc/net/dev. Giving up.\n");
420 goto end;
421 }
422 if (sscanf(ptr, "%lu%lu%lu%lu%lu%lu%lu%*d%lu%lu%lu%lu%lu%lu%lu",
423 &rx_bytes, &rx_packets, &rx_errs, &rx_drops,
424 &rx_fifo, &rx_frame, &rx_multi,
425 &tx_bytes, &tx_packets, &tx_errs, &tx_drops,
426 &tx_fifo, &tx_colls, &tx_carrier) != 14)
427 continue;
428 if (p->name[0] && strcmp(p->name, name))
429 continue;
430 index = ll_name_to_index(name);
431 if (index == 0)
432 continue;
433 type = ll_index_to_type(index);
434 if (type == -1) {
435 fprintf(stderr, "Failed to get type of \"%s\"\n", name);
436 continue;
437 }
438 if (type != ARPHRD_TUNNEL && type != ARPHRD_IPGRE && type != ARPHRD_SIT)
439 continue;
440 memset(&p1, 0, sizeof(p1));
441 if (tnl_get_ioctl(name, &p1))
442 continue;
443 if ((p->link && p1.link != p->link) ||
444 (p->name[0] && strcmp(p1.name, p->name)) ||
445 (p->iph.daddr && p1.iph.daddr != p->iph.daddr) ||
446 (p->iph.saddr && p1.iph.saddr != p->iph.saddr) ||
447 (p->i_key && p1.i_key != p->i_key))
448 continue;
449 print_tunnel(&p1);
450 if (show_stats) {
451 printf("%s", _SL_);
452 printf("RX: Packets Bytes Errors CsumErrs OutOfSeq Mcasts%s", _SL_);
453 printf(" %-10ld %-12ld %-6ld %-8ld %-8ld %-8ld%s",
454 rx_packets, rx_bytes, rx_errs, rx_frame, rx_fifo, rx_multi, _SL_);
455 printf("TX: Packets Bytes Errors DeadLoop NoRoute NoBufs%s", _SL_);
456 printf(" %-10ld %-12ld %-6ld %-8ld %-8ld %-6ld",
457 tx_packets, tx_bytes, tx_errs, tx_colls, tx_carrier, tx_drops);
458 }
459 printf("\n");
460 }
461 err = 0;
462 end:
463 fclose(fp);
464 return err;
465 }
466
467 static int do_show(int argc, char **argv)
468 {
469 struct ip_tunnel_parm p;
470 const char *basedev;
471
472 ll_init_map(&rth);
473 if (parse_args(argc, argv, SIOCGETTUNNEL, &p) < 0)
474 return -1;
475
476 basedev = tnl_defname(&p);
477 if (!basedev)
478 return do_tunnels_list(&p);
479
480 if (tnl_get_ioctl(p.name[0] ? p.name : basedev, &p))
481 return -1;
482
483 print_tunnel(&p);
484 printf("\n");
485 return 0;
486 }
487
488 static int do_prl(int argc, char **argv)
489 {
490 struct ip_tunnel_prl p;
491 int count = 0;
492 int devname = 0;
493 int cmd = 0;
494 char medium[IFNAMSIZ];
495
496 memset(&p, 0, sizeof(p));
497 memset(&medium, 0, sizeof(medium));
498
499 while (argc > 0) {
500 if (strcmp(*argv, "prl-default") == 0) {
501 NEXT_ARG();
502 cmd = SIOCADDPRL;
503 p.addr = get_addr32(*argv);
504 p.flags |= PRL_DEFAULT;
505 count++;
506 } else if (strcmp(*argv, "prl-nodefault") == 0) {
507 NEXT_ARG();
508 cmd = SIOCADDPRL;
509 p.addr = get_addr32(*argv);
510 count++;
511 } else if (strcmp(*argv, "prl-delete") == 0) {
512 NEXT_ARG();
513 cmd = SIOCDELPRL;
514 p.addr = get_addr32(*argv);
515 count++;
516 } else if (strcmp(*argv, "dev") == 0) {
517 NEXT_ARG();
518 strncpy(medium, *argv, IFNAMSIZ-1);
519 devname++;
520 } else {
521 fprintf(stderr,
522 "Invalid PRL parameter \"%s\"\n", *argv);
523 exit(-1);
524 }
525 if (count > 1) {
526 fprintf(stderr,
527 "One PRL entry at a time\n");
528 exit(-1);
529 }
530 argc--; argv++;
531 }
532 if (devname == 0) {
533 fprintf(stderr, "Must specify device\n");
534 exit(-1);
535 }
536
537 return tnl_prl_ioctl(cmd, medium, &p);
538 }
539
540 static int do_6rd(int argc, char **argv)
541 {
542 struct ip_tunnel_6rd ip6rd;
543 int devname = 0;
544 int cmd = 0;
545 char medium[IFNAMSIZ];
546 inet_prefix prefix;
547
548 memset(&ip6rd, 0, sizeof(ip6rd));
549 memset(&medium, 0, sizeof(medium));
550
551 while (argc > 0) {
552 if (strcmp(*argv, "6rd-prefix") == 0) {
553 NEXT_ARG();
554 if (get_prefix(&prefix, *argv, AF_INET6))
555 invarg("invalid 6rd_prefix\n", *argv);
556 cmd = SIOCADD6RD;
557 memcpy(&ip6rd.prefix, prefix.data, 16);
558 ip6rd.prefixlen = prefix.bitlen;
559 } else if (strcmp(*argv, "6rd-relay_prefix") == 0) {
560 NEXT_ARG();
561 if (get_prefix(&prefix, *argv, AF_INET))
562 invarg("invalid 6rd-relay_prefix\n", *argv);
563 cmd = SIOCADD6RD;
564 memcpy(&ip6rd.relay_prefix, prefix.data, 4);
565 ip6rd.relay_prefixlen = prefix.bitlen;
566 } else if (strcmp(*argv, "6rd-reset") == 0) {
567 cmd = SIOCDEL6RD;
568 } else if (strcmp(*argv, "dev") == 0) {
569 NEXT_ARG();
570 strncpy(medium, *argv, IFNAMSIZ-1);
571 devname++;
572 } else {
573 fprintf(stderr,
574 "Invalid 6RD parameter \"%s\"\n", *argv);
575 exit(-1);
576 }
577 argc--; argv++;
578 }
579 if (devname == 0) {
580 fprintf(stderr, "Must specify device\n");
581 exit(-1);
582 }
583
584 return tnl_6rd_ioctl(cmd, medium, &ip6rd);
585 }
586
587 static int tunnel_mode_is_ipv6(char *tunnel_mode)
588 {
589 static const char * const ipv6_modes[] = {
590 "ipv6/ipv6", "ip6ip6",
591 "vti6",
592 "ip/ipv6", "ipv4/ipv6", "ipip6", "ip4ip6",
593 "ip6gre", "gre/ipv6",
594 "any/ipv6", "any"
595 };
596 int i;
597
598 for (i = 0; i < ARRAY_SIZE(ipv6_modes); i++) {
599 if (strcmp(ipv6_modes[i], tunnel_mode) == 0)
600 return 1;
601 }
602 return 0;
603 }
604
605 int do_iptunnel(int argc, char **argv)
606 {
607 int i;
608
609 for (i = 0; i < argc - 1; i++) {
610 if (strcmp(argv[i], "mode") == 0) {
611 if (tunnel_mode_is_ipv6(argv[i + 1]))
612 preferred_family = AF_INET6;
613 break;
614 }
615 }
616 switch (preferred_family) {
617 case AF_UNSPEC:
618 preferred_family = AF_INET;
619 break;
620 case AF_INET:
621 break;
622 /*
623 * This is silly enough but we have no easy way to make it
624 * protocol-independent because of unarranged structure between
625 * IPv4 and IPv6.
626 */
627 case AF_INET6:
628 return do_ip6tunnel(argc, argv);
629 default:
630 fprintf(stderr, "Unsupported protocol family: %d\n", preferred_family);
631 exit(-1);
632 }
633
634 if (argc > 0) {
635 if (matches(*argv, "add") == 0)
636 return do_add(SIOCADDTUNNEL, argc - 1, argv + 1);
637 if (matches(*argv, "change") == 0)
638 return do_add(SIOCCHGTUNNEL, argc - 1, argv + 1);
639 if (matches(*argv, "delete") == 0)
640 return do_del(argc - 1, argv + 1);
641 if (matches(*argv, "show") == 0 ||
642 matches(*argv, "lst") == 0 ||
643 matches(*argv, "list") == 0)
644 return do_show(argc - 1, argv + 1);
645 if (matches(*argv, "prl") == 0)
646 return do_prl(argc - 1, argv + 1);
647 if (matches(*argv, "6rd") == 0)
648 return do_6rd(argc - 1, argv + 1);
649 if (matches(*argv, "help") == 0)
650 usage();
651 } else
652 return do_show(0, NULL);
653
654 fprintf(stderr, "Command \"%s\" is unknown, try \"ip tunnel help\"\n", *argv);
655 exit(-1);
656 }