blob: 769e84559e43c6f33bdb5d318cef1648886c8fd4 [file] [log] [blame]
osdl.org!shemmingeraba5acd2004-04-15 20:56:59 +00001/*
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 * Changes:
13 *
14 * Rani Assaf <rani@magic.metawire.com> 980929: resolve addresses
15 * Rani Assaf <rani@magic.metawire.com> 980930: do not allow key for ipip/sit
16 * Phil Karn <karn@ka9q.ampr.org> 990408: "pmtudisc" flag
17 */
18
19#include <stdio.h>
20#include <stdlib.h>
21#include <string.h>
22#include <unistd.h>
Masahide NAKAMURAd9bd1bd2006-11-24 12:27:03 +090023#include <sys/types.h>
osdl.org!shemmingeraba5acd2004-04-15 20:56:59 +000024#include <sys/socket.h>
osdl.org!shemminger7272ddc2004-06-02 20:22:08 +000025#include <arpa/inet.h>
osdl.org!shemmingeraba5acd2004-04-15 20:56:59 +000026#include <sys/ioctl.h>
27#include <linux/if.h>
28#include <linux/if_arp.h>
osdl.org!shemminger7272ddc2004-06-02 20:22:08 +000029#include <linux/ip.h>
osdl.org!shemmingeraba5acd2004-04-15 20:56:59 +000030#include <linux/if_tunnel.h>
31
32#include "rt_names.h"
33#include "utils.h"
Masahide NAKAMURA288384f2006-11-24 12:27:09 +090034#include "ip_common.h"
Masahide NAKAMURAd9bd1bd2006-11-24 12:27:03 +090035#include "tunnel.h"
osdl.org!shemmingeraba5acd2004-04-15 20:56:59 +000036
37static void usage(void) __attribute__((noreturn));
38
39static void usage(void)
40{
41 fprintf(stderr, "Usage: ip tunnel { add | change | del | show } [ NAME ]\n");
Templin, Fred L0bd17922007-11-26 09:46:06 -080042 fprintf(stderr, " [ mode { ipip | gre | sit | isatap } ] [ remote ADDR ] [ local ADDR ]\n");
osdl.org!shemmingeraba5acd2004-04-15 20:56:59 +000043 fprintf(stderr, " [ [i|o]seq ] [ [i|o]key KEY ] [ [i|o]csum ]\n");
44 fprintf(stderr, " [ ttl TTL ] [ tos TOS ] [ [no]pmtudisc ] [ dev PHYS_DEV ]\n");
45 fprintf(stderr, "\n");
46 fprintf(stderr, "Where: NAME := STRING\n");
47 fprintf(stderr, " ADDR := { IP_ADDRESS | any }\n");
48 fprintf(stderr, " TOS := { NUMBER | inherit }\n");
49 fprintf(stderr, " TTL := { 1..255 | inherit }\n");
50 fprintf(stderr, " KEY := { DOTTED_QUAD | NUMBER }\n");
51 exit(-1);
52}
53
osdl.org!shemmingeraba5acd2004-04-15 20:56:59 +000054static int parse_args(int argc, char **argv, int cmd, struct ip_tunnel_parm *p)
55{
56 int count = 0;
57 char medium[IFNAMSIZ];
Templin, Fred L0bd17922007-11-26 09:46:06 -080058 int isatap = 0;
osdl.org!shemmingeraba5acd2004-04-15 20:56:59 +000059
60 memset(p, 0, sizeof(*p));
61 memset(&medium, 0, sizeof(medium));
62
63 p->iph.version = 4;
64 p->iph.ihl = 5;
65#ifndef IP_DF
66#define IP_DF 0x4000 /* Flag: "Don't Fragment" */
67#endif
68 p->iph.frag_off = htons(IP_DF);
69
70 while (argc > 0) {
71 if (strcmp(*argv, "mode") == 0) {
72 NEXT_ARG();
73 if (strcmp(*argv, "ipip") == 0 ||
74 strcmp(*argv, "ip/ip") == 0) {
75 if (p->iph.protocol && p->iph.protocol != IPPROTO_IPIP) {
76 fprintf(stderr,"You managed to ask for more than one tunnel mode.\n");
77 exit(-1);
78 }
79 p->iph.protocol = IPPROTO_IPIP;
80 } else if (strcmp(*argv, "gre") == 0 ||
81 strcmp(*argv, "gre/ip") == 0) {
82 if (p->iph.protocol && p->iph.protocol != IPPROTO_GRE) {
83 fprintf(stderr,"You managed to ask for more than one tunnel mode.\n");
84 exit(-1);
85 }
86 p->iph.protocol = IPPROTO_GRE;
87 } else if (strcmp(*argv, "sit") == 0 ||
88 strcmp(*argv, "ipv6/ip") == 0) {
89 if (p->iph.protocol && p->iph.protocol != IPPROTO_IPV6) {
90 fprintf(stderr,"You managed to ask for more than one tunnel mode.\n");
91 exit(-1);
92 }
93 p->iph.protocol = IPPROTO_IPV6;
Templin, Fred L0bd17922007-11-26 09:46:06 -080094 } else if (strcmp(*argv, "isatap") == 0) {
95 if (p->iph.protocol && p->iph.protocol != IPPROTO_IPV6) {
96 fprintf(stderr, "You managed to ask for more than one tunnel mode.\n");
97 exit(-1);
98 }
99 p->iph.protocol = IPPROTO_IPV6;
100 isatap++;
osdl.org!shemmingeraba5acd2004-04-15 20:56:59 +0000101 } else {
102 fprintf(stderr,"Cannot guess tunnel mode.\n");
103 exit(-1);
104 }
105 } else if (strcmp(*argv, "key") == 0) {
106 unsigned uval;
107 NEXT_ARG();
108 p->i_flags |= GRE_KEY;
109 p->o_flags |= GRE_KEY;
110 if (strchr(*argv, '.'))
111 p->i_key = p->o_key = get_addr32(*argv);
112 else {
113 if (get_unsigned(&uval, *argv, 0)<0) {
114 fprintf(stderr, "invalid value of \"key\"\n");
115 exit(-1);
116 }
117 p->i_key = p->o_key = htonl(uval);
118 }
119 } else if (strcmp(*argv, "ikey") == 0) {
120 unsigned uval;
121 NEXT_ARG();
122 p->i_flags |= GRE_KEY;
123 if (strchr(*argv, '.'))
Herbert Xu4282c6c2007-10-12 10:56:40 +0200124 p->i_key = get_addr32(*argv);
osdl.org!shemmingeraba5acd2004-04-15 20:56:59 +0000125 else {
126 if (get_unsigned(&uval, *argv, 0)<0) {
127 fprintf(stderr, "invalid value of \"ikey\"\n");
128 exit(-1);
129 }
130 p->i_key = htonl(uval);
131 }
132 } else if (strcmp(*argv, "okey") == 0) {
133 unsigned uval;
134 NEXT_ARG();
135 p->o_flags |= GRE_KEY;
136 if (strchr(*argv, '.'))
137 p->o_key = get_addr32(*argv);
138 else {
139 if (get_unsigned(&uval, *argv, 0)<0) {
140 fprintf(stderr, "invalid value of \"okey\"\n");
141 exit(-1);
142 }
143 p->o_key = htonl(uval);
144 }
145 } else if (strcmp(*argv, "seq") == 0) {
146 p->i_flags |= GRE_SEQ;
147 p->o_flags |= GRE_SEQ;
148 } else if (strcmp(*argv, "iseq") == 0) {
149 p->i_flags |= GRE_SEQ;
150 } else if (strcmp(*argv, "oseq") == 0) {
151 p->o_flags |= GRE_SEQ;
152 } else if (strcmp(*argv, "csum") == 0) {
153 p->i_flags |= GRE_CSUM;
154 p->o_flags |= GRE_CSUM;
155 } else if (strcmp(*argv, "icsum") == 0) {
156 p->i_flags |= GRE_CSUM;
157 } else if (strcmp(*argv, "ocsum") == 0) {
158 p->o_flags |= GRE_CSUM;
159 } else if (strcmp(*argv, "nopmtudisc") == 0) {
160 p->iph.frag_off = 0;
161 } else if (strcmp(*argv, "pmtudisc") == 0) {
162 p->iph.frag_off = htons(IP_DF);
163 } else if (strcmp(*argv, "remote") == 0) {
164 NEXT_ARG();
165 if (strcmp(*argv, "any"))
166 p->iph.daddr = get_addr32(*argv);
167 } else if (strcmp(*argv, "local") == 0) {
168 NEXT_ARG();
169 if (strcmp(*argv, "any"))
170 p->iph.saddr = get_addr32(*argv);
171 } else if (strcmp(*argv, "dev") == 0) {
172 NEXT_ARG();
173 strncpy(medium, *argv, IFNAMSIZ-1);
YOSHIFUJI Hideaki / 吉藤英明eddde112008-03-13 11:17:54 -0400174 } else if (strcmp(*argv, "ttl") == 0 ||
175 strcmp(*argv, "hoplimit") == 0) {
osdl.org!shemmingeraba5acd2004-04-15 20:56:59 +0000176 unsigned uval;
177 NEXT_ARG();
178 if (strcmp(*argv, "inherit") != 0) {
179 if (get_unsigned(&uval, *argv, 0))
180 invarg("invalid TTL\n", *argv);
181 if (uval > 255)
182 invarg("TTL must be <=255\n", *argv);
183 p->iph.ttl = uval;
184 }
185 } else if (strcmp(*argv, "tos") == 0 ||
YOSHIFUJI Hideaki / 吉藤英明eddde112008-03-13 11:17:54 -0400186 strcmp(*argv, "tclass") == 0 ||
osdl.org!shemmingeraba5acd2004-04-15 20:56:59 +0000187 matches(*argv, "dsfield") == 0) {
188 __u32 uval;
189 NEXT_ARG();
190 if (strcmp(*argv, "inherit") != 0) {
191 if (rtnl_dsfield_a2n(&uval, *argv))
192 invarg("bad TOS value", *argv);
193 p->iph.tos = uval;
194 } else
195 p->iph.tos = 1;
196 } else {
197 if (strcmp(*argv, "name") == 0) {
198 NEXT_ARG();
199 }
200 if (matches(*argv, "help") == 0)
201 usage();
202 if (p->name[0])
203 duparg2("name", *argv);
204 strncpy(p->name, *argv, IFNAMSIZ);
205 if (cmd == SIOCCHGTUNNEL && count == 0) {
206 struct ip_tunnel_parm old_p;
207 memset(&old_p, 0, sizeof(old_p));
Masahide NAKAMURAd9bd1bd2006-11-24 12:27:03 +0900208 if (tnl_get_ioctl(*argv, &old_p))
osdl.org!shemmingeraba5acd2004-04-15 20:56:59 +0000209 return -1;
210 *p = old_p;
211 }
212 }
213 count++;
214 argc--; argv++;
215 }
216
217
218 if (p->iph.protocol == 0) {
219 if (memcmp(p->name, "gre", 3) == 0)
220 p->iph.protocol = IPPROTO_GRE;
221 else if (memcmp(p->name, "ipip", 4) == 0)
222 p->iph.protocol = IPPROTO_IPIP;
223 else if (memcmp(p->name, "sit", 3) == 0)
224 p->iph.protocol = IPPROTO_IPV6;
Templin, Fred L0bd17922007-11-26 09:46:06 -0800225 else if (memcmp(p->name, "isatap", 6) == 0) {
226 p->iph.protocol = IPPROTO_IPV6;
227 isatap++;
228 }
osdl.org!shemmingeraba5acd2004-04-15 20:56:59 +0000229 }
230
231 if (p->iph.protocol == IPPROTO_IPIP || p->iph.protocol == IPPROTO_IPV6) {
232 if ((p->i_flags & GRE_KEY) || (p->o_flags & GRE_KEY)) {
233 fprintf(stderr, "Keys are not allowed with ipip and sit.\n");
234 return -1;
235 }
236 }
237
238 if (medium[0]) {
Masahide NAKAMURAd9bd1bd2006-11-24 12:27:03 +0900239 p->link = tnl_ioctl_get_ifindex(medium);
osdl.org!shemmingeraba5acd2004-04-15 20:56:59 +0000240 if (p->link == 0)
241 return -1;
242 }
243
244 if (p->i_key == 0 && IN_MULTICAST(ntohl(p->iph.daddr))) {
245 p->i_key = p->iph.daddr;
246 p->i_flags |= GRE_KEY;
247 }
248 if (p->o_key == 0 && IN_MULTICAST(ntohl(p->iph.daddr))) {
249 p->o_key = p->iph.daddr;
250 p->o_flags |= GRE_KEY;
251 }
252 if (IN_MULTICAST(ntohl(p->iph.daddr)) && !p->iph.saddr) {
253 fprintf(stderr, "Broadcast tunnel requires a source address.\n");
254 return -1;
255 }
Templin, Fred L0bd17922007-11-26 09:46:06 -0800256 if (isatap) {
257 if (p->iph.daddr) {
258 fprintf(stderr, "no remote with isatap.\n");
259 return -1;
260 }
261 p->i_flags |= SIT_ISATAP;
262 }
263
osdl.org!shemmingeraba5acd2004-04-15 20:56:59 +0000264 return 0;
265}
266
267
268static int do_add(int cmd, int argc, char **argv)
269{
270 struct ip_tunnel_parm p;
271
272 if (parse_args(argc, argv, cmd, &p) < 0)
273 return -1;
274
275 if (p.iph.ttl && p.iph.frag_off == 0) {
276 fprintf(stderr, "ttl != 0 and noptmudisc are incompatible\n");
277 return -1;
278 }
279
280 switch (p.iph.protocol) {
281 case IPPROTO_IPIP:
Masahide NAKAMURAd9bd1bd2006-11-24 12:27:03 +0900282 return tnl_add_ioctl(cmd, "tunl0", p.name, &p);
osdl.org!shemmingeraba5acd2004-04-15 20:56:59 +0000283 case IPPROTO_GRE:
Masahide NAKAMURAd9bd1bd2006-11-24 12:27:03 +0900284 return tnl_add_ioctl(cmd, "gre0", p.name, &p);
osdl.org!shemmingeraba5acd2004-04-15 20:56:59 +0000285 case IPPROTO_IPV6:
Masahide NAKAMURAd9bd1bd2006-11-24 12:27:03 +0900286 return tnl_add_ioctl(cmd, "sit0", p.name, &p);
Stephen Hemmingerae665a52006-12-05 10:10:22 -0800287 default:
osdl.org!shemmingeraba5acd2004-04-15 20:56:59 +0000288 fprintf(stderr, "cannot determine tunnel mode (ipip, gre or sit)\n");
289 return -1;
290 }
291 return -1;
292}
293
Masahide NAKAMURAd9bd1bd2006-11-24 12:27:03 +0900294static int do_del(int argc, char **argv)
osdl.org!shemmingeraba5acd2004-04-15 20:56:59 +0000295{
296 struct ip_tunnel_parm p;
297
298 if (parse_args(argc, argv, SIOCDELTUNNEL, &p) < 0)
299 return -1;
300
301 switch (p.iph.protocol) {
302 case IPPROTO_IPIP:
Masahide NAKAMURAd9bd1bd2006-11-24 12:27:03 +0900303 return tnl_del_ioctl("tunl0", p.name, &p);
osdl.org!shemmingeraba5acd2004-04-15 20:56:59 +0000304 case IPPROTO_GRE:
Masahide NAKAMURAd9bd1bd2006-11-24 12:27:03 +0900305 return tnl_del_ioctl("gre0", p.name, &p);
osdl.org!shemmingeraba5acd2004-04-15 20:56:59 +0000306 case IPPROTO_IPV6:
Masahide NAKAMURAd9bd1bd2006-11-24 12:27:03 +0900307 return tnl_del_ioctl("sit0", p.name, &p);
Stephen Hemmingerae665a52006-12-05 10:10:22 -0800308 default:
Masahide NAKAMURAd9bd1bd2006-11-24 12:27:03 +0900309 return tnl_del_ioctl(p.name, p.name, &p);
osdl.org!shemmingeraba5acd2004-04-15 20:56:59 +0000310 }
311 return -1;
312}
313
Masahide NAKAMURAd9bd1bd2006-11-24 12:27:03 +0900314static void print_tunnel(struct ip_tunnel_parm *p)
osdl.org!shemmingeraba5acd2004-04-15 20:56:59 +0000315{
316 char s1[1024];
317 char s2[1024];
318 char s3[64];
319 char s4[64];
320
321 inet_ntop(AF_INET, &p->i_key, s3, sizeof(s3));
322 inet_ntop(AF_INET, &p->o_key, s4, sizeof(s4));
323
324 /* Do not use format_host() for local addr,
325 * symbolic name will not be useful.
326 */
327 printf("%s: %s/ip remote %s local %s ",
328 p->name,
Masahide NAKAMURAd9bd1bd2006-11-24 12:27:03 +0900329 tnl_strproto(p->iph.protocol),
osdl.org!shemmingeraba5acd2004-04-15 20:56:59 +0000330 p->iph.daddr ? format_host(AF_INET, 4, &p->iph.daddr, s1, sizeof(s1)) : "any",
331 p->iph.saddr ? rt_addr_n2a(AF_INET, 4, &p->iph.saddr, s2, sizeof(s2)) : "any");
332
333 if (p->link) {
Masahide NAKAMURAd9bd1bd2006-11-24 12:27:03 +0900334 char *n = tnl_ioctl_get_ifname(p->link);
osdl.org!shemmingeraba5acd2004-04-15 20:56:59 +0000335 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 ");
Stephen Hemmingerae665a52006-12-05 10:10:22 -0800343
osdl.org!shemmingeraba5acd2004-04-15 20:56:59 +0000344 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->i_flags&GRE_KEY) && (p->o_flags&GRE_KEY) && p->o_key == p->i_key)
358 printf(" key %s", s3);
359 else if ((p->i_flags|p->o_flags)&GRE_KEY) {
360 if (p->i_flags&GRE_KEY)
361 printf(" ikey %s ", s3);
362 if (p->o_flags&GRE_KEY)
363 printf(" okey %s ", s4);
364 }
365
366 if (p->i_flags&GRE_SEQ)
367 printf("%s Drop packets out of sequence.\n", _SL_);
368 if (p->i_flags&GRE_CSUM)
369 printf("%s Checksum in received packet is required.", _SL_);
370 if (p->o_flags&GRE_SEQ)
371 printf("%s Sequence packets on output.", _SL_);
372 if (p->o_flags&GRE_CSUM)
373 printf("%s Checksum output packets.", _SL_);
374}
375
376static int do_tunnels_list(struct ip_tunnel_parm *p)
377{
378 char name[IFNAMSIZ];
379 unsigned long rx_bytes, rx_packets, rx_errs, rx_drops,
380 rx_fifo, rx_frame,
381 tx_bytes, tx_packets, tx_errs, tx_drops,
382 tx_fifo, tx_colls, tx_carrier, rx_multi;
383 int type;
384 struct ip_tunnel_parm p1;
385
386 char buf[512];
387 FILE *fp = fopen("/proc/net/dev", "r");
388 if (fp == NULL) {
389 perror("fopen");
390 return -1;
391 }
392
393 fgets(buf, sizeof(buf), fp);
394 fgets(buf, sizeof(buf), fp);
395
396 while (fgets(buf, sizeof(buf), fp) != NULL) {
397 char *ptr;
398 buf[sizeof(buf) - 1] = 0;
399 if ((ptr = strchr(buf, ':')) == NULL ||
400 (*ptr++ = 0, sscanf(buf, "%s", name) != 1)) {
401 fprintf(stderr, "Wrong format of /proc/net/dev. Sorry.\n");
402 return -1;
403 }
404 if (sscanf(ptr, "%ld%ld%ld%ld%ld%ld%ld%*d%ld%ld%ld%ld%ld%ld%ld",
405 &rx_bytes, &rx_packets, &rx_errs, &rx_drops,
406 &rx_fifo, &rx_frame, &rx_multi,
407 &tx_bytes, &tx_packets, &tx_errs, &tx_drops,
408 &tx_fifo, &tx_colls, &tx_carrier) != 14)
409 continue;
410 if (p->name[0] && strcmp(p->name, name))
411 continue;
Masahide NAKAMURAd9bd1bd2006-11-24 12:27:03 +0900412 type = tnl_ioctl_get_iftype(name);
osdl.org!shemmingeraba5acd2004-04-15 20:56:59 +0000413 if (type == -1) {
414 fprintf(stderr, "Failed to get type of [%s]\n", name);
415 continue;
416 }
417 if (type != ARPHRD_TUNNEL && type != ARPHRD_IPGRE && type != ARPHRD_SIT)
418 continue;
419 memset(&p1, 0, sizeof(p1));
Masahide NAKAMURAd9bd1bd2006-11-24 12:27:03 +0900420 if (tnl_get_ioctl(name, &p1))
osdl.org!shemmingeraba5acd2004-04-15 20:56:59 +0000421 continue;
422 if ((p->link && p1.link != p->link) ||
423 (p->name[0] && strcmp(p1.name, p->name)) ||
424 (p->iph.daddr && p1.iph.daddr != p->iph.daddr) ||
425 (p->iph.saddr && p1.iph.saddr != p->iph.saddr) ||
426 (p->i_key && p1.i_key != p->i_key))
427 continue;
428 print_tunnel(&p1);
429 if (show_stats) {
430 printf("%s", _SL_);
431 printf("RX: Packets Bytes Errors CsumErrs OutOfSeq Mcasts%s", _SL_);
432 printf(" %-10ld %-12ld %-6ld %-8ld %-8ld %-8ld%s",
433 rx_packets, rx_bytes, rx_errs, rx_frame, rx_fifo, rx_multi, _SL_);
434 printf("TX: Packets Bytes Errors DeadLoop NoRoute NoBufs%s", _SL_);
435 printf(" %-10ld %-12ld %-6ld %-8ld %-8ld %-6ld",
436 tx_packets, tx_bytes, tx_errs, tx_colls, tx_carrier, tx_drops);
437 }
438 printf("\n");
439 }
440 return 0;
441}
442
443static int do_show(int argc, char **argv)
444{
445 int err;
446 struct ip_tunnel_parm p;
447
448 if (parse_args(argc, argv, SIOCGETTUNNEL, &p) < 0)
449 return -1;
450
451 switch (p.iph.protocol) {
Stephen Hemmingerae665a52006-12-05 10:10:22 -0800452 case IPPROTO_IPIP:
Masahide NAKAMURAd9bd1bd2006-11-24 12:27:03 +0900453 err = tnl_get_ioctl(p.name[0] ? p.name : "tunl0", &p);
osdl.org!shemmingeraba5acd2004-04-15 20:56:59 +0000454 break;
455 case IPPROTO_GRE:
Masahide NAKAMURAd9bd1bd2006-11-24 12:27:03 +0900456 err = tnl_get_ioctl(p.name[0] ? p.name : "gre0", &p);
osdl.org!shemmingeraba5acd2004-04-15 20:56:59 +0000457 break;
458 case IPPROTO_IPV6:
Masahide NAKAMURAd9bd1bd2006-11-24 12:27:03 +0900459 err = tnl_get_ioctl(p.name[0] ? p.name : "sit0", &p);
osdl.org!shemmingeraba5acd2004-04-15 20:56:59 +0000460 break;
461 default:
462 do_tunnels_list(&p);
463 return 0;
464 }
465 if (err)
466 return -1;
467
468 print_tunnel(&p);
469 printf("\n");
470 return 0;
471}
472
473int do_iptunnel(int argc, char **argv)
474{
Masahide NAKAMURAd9bd1bd2006-11-24 12:27:03 +0900475 switch (preferred_family) {
476 case AF_UNSPEC:
477 preferred_family = AF_INET;
478 break;
479 case AF_INET:
480 break;
Masahide NAKAMURA288384f2006-11-24 12:27:09 +0900481 /*
482 * This is silly enough but we have no easy way to make it
483 * protocol-independent because of unarranged structure between
484 * IPv4 and IPv6.
485 */
486 case AF_INET6:
487 return do_ip6tunnel(argc, argv);
Masahide NAKAMURAd9bd1bd2006-11-24 12:27:03 +0900488 default:
489 fprintf(stderr, "Unsupported family:%d\n", preferred_family);
490 exit(-1);
491 }
492
osdl.org!shemmingeraba5acd2004-04-15 20:56:59 +0000493 if (argc > 0) {
494 if (matches(*argv, "add") == 0)
495 return do_add(SIOCADDTUNNEL, argc-1, argv+1);
496 if (matches(*argv, "change") == 0)
497 return do_add(SIOCCHGTUNNEL, argc-1, argv+1);
498 if (matches(*argv, "del") == 0)
499 return do_del(argc-1, argv+1);
500 if (matches(*argv, "show") == 0 ||
501 matches(*argv, "lst") == 0 ||
502 matches(*argv, "list") == 0)
503 return do_show(argc-1, argv+1);
504 if (matches(*argv, "help") == 0)
505 usage();
506 } else
507 return do_show(0, NULL);
508
509 fprintf(stderr, "Command \"%s\" is unknown, try \"ip tunnel help\".\n", *argv);
510 exit(-1);
511}