blob: ee0cc28516915a12738323cb7359188bd5e44233 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * IPv6 over IPv4 tunnel device - Simple Internet Transition (SIT)
3 * Linux INET6 implementation
4 *
5 * Authors:
YOSHIFUJI Hideaki1ab14572007-02-09 23:24:49 +09006 * Pedro Roque <roque@di.fc.ul.pt>
Linus Torvalds1da177e2005-04-16 15:20:36 -07007 * Alexey Kuznetsov <kuznet@ms2.inr.ac.ru>
8 *
9 * $Id: sit.c,v 1.53 2001/09/25 05:09:53 davem Exp $
10 *
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version
14 * 2 of the License, or (at your option) any later version.
15 *
16 * Changes:
17 * Roger Venning <r.venning@telstra.com>: 6to4 support
18 * Nate Thompson <nate@thebog.net>: 6to4 support
Templin, Fred Lfadf6bf2008-03-11 18:35:59 -040019 * Fred Templin <fred.l.templin@boeing.com>: isatap support
Linus Torvalds1da177e2005-04-16 15:20:36 -070020 */
21
Linus Torvalds1da177e2005-04-16 15:20:36 -070022#include <linux/module.h>
Randy Dunlap4fc268d2006-01-11 12:17:47 -080023#include <linux/capability.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070024#include <linux/errno.h>
25#include <linux/types.h>
26#include <linux/socket.h>
27#include <linux/sockios.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070028#include <linux/net.h>
29#include <linux/in6.h>
30#include <linux/netdevice.h>
31#include <linux/if_arp.h>
32#include <linux/icmp.h>
33#include <asm/uaccess.h>
34#include <linux/init.h>
35#include <linux/netfilter_ipv4.h>
Kris Katterjohn46f25df2006-01-05 16:35:42 -080036#include <linux/if_ether.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070037
38#include <net/sock.h>
39#include <net/snmp.h>
40
41#include <net/ipv6.h>
42#include <net/protocol.h>
43#include <net/transp_v6.h>
44#include <net/ip6_fib.h>
45#include <net/ip6_route.h>
46#include <net/ndisc.h>
47#include <net/addrconf.h>
48#include <net/ip.h>
49#include <net/udp.h>
50#include <net/icmp.h>
51#include <net/ipip.h>
52#include <net/inet_ecn.h>
53#include <net/xfrm.h>
54#include <net/dsfield.h>
55
56/*
57 This version of net/ipv6/sit.c is cloned of net/ipv4/ip_gre.c
58
59 For comments look at net/ipv4/ip_gre.c --ANK
60 */
61
62#define HASH_SIZE 16
Al Viroe69a4adc2006-11-14 20:56:00 -080063#define HASH(addr) (((__force u32)addr^((__force u32)addr>>4))&0xF)
Linus Torvalds1da177e2005-04-16 15:20:36 -070064
65static int ipip6_fb_tunnel_init(struct net_device *dev);
66static int ipip6_tunnel_init(struct net_device *dev);
67static void ipip6_tunnel_setup(struct net_device *dev);
68
69static struct net_device *ipip6_fb_tunnel_dev;
70
71static struct ip_tunnel *tunnels_r_l[HASH_SIZE];
72static struct ip_tunnel *tunnels_r[HASH_SIZE];
73static struct ip_tunnel *tunnels_l[HASH_SIZE];
74static struct ip_tunnel *tunnels_wc[1];
75static struct ip_tunnel **tunnels[4] = { tunnels_wc, tunnels_l, tunnels_r, tunnels_r_l };
76
77static DEFINE_RWLOCK(ipip6_lock);
78
Al Viroe69a4adc2006-11-14 20:56:00 -080079static struct ip_tunnel * ipip6_tunnel_lookup(__be32 remote, __be32 local)
Linus Torvalds1da177e2005-04-16 15:20:36 -070080{
81 unsigned h0 = HASH(remote);
82 unsigned h1 = HASH(local);
83 struct ip_tunnel *t;
84
85 for (t = tunnels_r_l[h0^h1]; t; t = t->next) {
86 if (local == t->parms.iph.saddr &&
87 remote == t->parms.iph.daddr && (t->dev->flags&IFF_UP))
88 return t;
89 }
90 for (t = tunnels_r[h0]; t; t = t->next) {
91 if (remote == t->parms.iph.daddr && (t->dev->flags&IFF_UP))
92 return t;
93 }
94 for (t = tunnels_l[h1]; t; t = t->next) {
95 if (local == t->parms.iph.saddr && (t->dev->flags&IFF_UP))
96 return t;
97 }
98 if ((t = tunnels_wc[0]) != NULL && (t->dev->flags&IFF_UP))
99 return t;
100 return NULL;
101}
102
YOSHIFUJI Hideaki420fe232007-04-24 20:44:47 +0900103static struct ip_tunnel **__ipip6_bucket(struct ip_tunnel_parm *parms)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104{
YOSHIFUJI Hideaki420fe232007-04-24 20:44:47 +0900105 __be32 remote = parms->iph.daddr;
106 __be32 local = parms->iph.saddr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107 unsigned h = 0;
108 int prio = 0;
109
110 if (remote) {
111 prio |= 2;
112 h ^= HASH(remote);
113 }
114 if (local) {
115 prio |= 1;
116 h ^= HASH(local);
117 }
118 return &tunnels[prio][h];
119}
120
YOSHIFUJI Hideaki420fe232007-04-24 20:44:47 +0900121static inline struct ip_tunnel **ipip6_bucket(struct ip_tunnel *t)
122{
123 return __ipip6_bucket(&t->parms);
124}
125
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126static void ipip6_tunnel_unlink(struct ip_tunnel *t)
127{
128 struct ip_tunnel **tp;
129
130 for (tp = ipip6_bucket(t); *tp; tp = &(*tp)->next) {
131 if (t == *tp) {
132 write_lock_bh(&ipip6_lock);
133 *tp = t->next;
134 write_unlock_bh(&ipip6_lock);
135 break;
136 }
137 }
138}
139
140static void ipip6_tunnel_link(struct ip_tunnel *t)
141{
142 struct ip_tunnel **tp = ipip6_bucket(t);
143
144 t->next = *tp;
145 write_lock_bh(&ipip6_lock);
146 *tp = t;
147 write_unlock_bh(&ipip6_lock);
148}
149
150static struct ip_tunnel * ipip6_tunnel_locate(struct ip_tunnel_parm *parms, int create)
151{
Al Viroe69a4adc2006-11-14 20:56:00 -0800152 __be32 remote = parms->iph.daddr;
153 __be32 local = parms->iph.saddr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154 struct ip_tunnel *t, **tp, *nt;
155 struct net_device *dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156 char name[IFNAMSIZ];
157
YOSHIFUJI Hideaki420fe232007-04-24 20:44:47 +0900158 for (tp = __ipip6_bucket(parms); (t = *tp) != NULL; tp = &t->next) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159 if (local == t->parms.iph.saddr && remote == t->parms.iph.daddr)
160 return t;
161 }
162 if (!create)
163 goto failed;
164
165 if (parms->name[0])
166 strlcpy(name, parms->name, IFNAMSIZ);
Pavel Emelyanov34cc7ba2008-02-23 20:19:20 -0800167 else
168 sprintf(name, "sit%%d");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169
170 dev = alloc_netdev(sizeof(*t), name, ipip6_tunnel_setup);
171 if (dev == NULL)
172 return NULL;
173
Pavel Emelyanovb37d428b2008-02-26 23:51:04 -0800174 if (strchr(name, '%')) {
175 if (dev_alloc_name(dev, name) < 0)
176 goto failed_free;
177 }
178
Patrick McHardy2941a482006-01-08 22:05:26 -0800179 nt = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180 dev->init = ipip6_tunnel_init;
181 nt->parms = *parms;
182
Fred L. Templinc7dc89c2007-11-29 22:11:40 +1100183 if (parms->i_flags & SIT_ISATAP)
184 dev->priv_flags |= IFF_ISATAP;
185
Pavel Emelyanovb37d428b2008-02-26 23:51:04 -0800186 if (register_netdevice(dev) < 0)
187 goto failed_free;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188
189 dev_hold(dev);
190
191 ipip6_tunnel_link(nt);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192 return nt;
193
Pavel Emelyanovb37d428b2008-02-26 23:51:04 -0800194failed_free:
195 free_netdev(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196failed:
197 return NULL;
198}
199
Templin, Fred Lfadf6bf2008-03-11 18:35:59 -0400200static struct ip_tunnel_prl_entry *
YOSHIFUJI Hideaki3fcfa122008-03-22 17:42:57 +0900201__ipip6_tunnel_locate_prl(struct ip_tunnel *t, __be32 addr)
Templin, Fred Lfadf6bf2008-03-11 18:35:59 -0400202{
203 struct ip_tunnel_prl_entry *p = (struct ip_tunnel_prl_entry *)NULL;
204
205 for (p = t->prl; p; p = p->next)
206 if (p->entry.addr == addr)
207 break;
208 return p;
209
210}
211
212static int
213ipip6_tunnel_add_prl(struct ip_tunnel *t, struct ip_tunnel_prl *a, int chg)
214{
215 struct ip_tunnel_prl_entry *p;
YOSHIFUJI Hideaki3fcfa122008-03-22 17:42:57 +0900216 int err = 0;
217
218 write_lock(&ipip6_lock);
Templin, Fred Lfadf6bf2008-03-11 18:35:59 -0400219
220 for (p = t->prl; p; p = p->next) {
221 if (p->entry.addr == a->addr) {
YOSHIFUJI Hideaki3fcfa122008-03-22 17:42:57 +0900222 if (chg)
223 goto update;
224 err = -EEXIST;
225 goto out;
Templin, Fred Lfadf6bf2008-03-11 18:35:59 -0400226 }
227 }
228
YOSHIFUJI Hideaki3fcfa122008-03-22 17:42:57 +0900229 if (chg) {
230 err = -ENXIO;
231 goto out;
232 }
Templin, Fred Lfadf6bf2008-03-11 18:35:59 -0400233
234 p = kzalloc(sizeof(struct ip_tunnel_prl_entry), GFP_KERNEL);
YOSHIFUJI Hideaki3fcfa122008-03-22 17:42:57 +0900235 if (!p) {
236 err = -ENOBUFS;
237 goto out;
238 }
Templin, Fred Lfadf6bf2008-03-11 18:35:59 -0400239
Templin, Fred Lfadf6bf2008-03-11 18:35:59 -0400240 p->next = t->prl;
241 t->prl = p;
YOSHIFUJI Hideaki3fcfa122008-03-22 17:42:57 +0900242update:
243 p->entry = *a;
244out:
245 write_unlock(&ipip6_lock);
246 return err;
Templin, Fred Lfadf6bf2008-03-11 18:35:59 -0400247}
248
249static int
250ipip6_tunnel_del_prl(struct ip_tunnel *t, struct ip_tunnel_prl *a)
251{
252 struct ip_tunnel_prl_entry *x, **p;
YOSHIFUJI Hideaki3fcfa122008-03-22 17:42:57 +0900253 int err = 0;
254
255 write_lock(&ipip6_lock);
Templin, Fred Lfadf6bf2008-03-11 18:35:59 -0400256
257 if (a) {
258 for (p = &t->prl; *p; p = &(*p)->next) {
259 if ((*p)->entry.addr == a->addr) {
260 x = *p;
261 *p = x->next;
262 kfree(x);
YOSHIFUJI Hideaki3fcfa122008-03-22 17:42:57 +0900263 goto out;
Templin, Fred Lfadf6bf2008-03-11 18:35:59 -0400264 }
265 }
YOSHIFUJI Hideaki3fcfa122008-03-22 17:42:57 +0900266 err = -ENXIO;
Templin, Fred Lfadf6bf2008-03-11 18:35:59 -0400267 } else {
268 while (t->prl) {
269 x = t->prl;
270 t->prl = t->prl->next;
271 kfree(x);
272 }
273 }
YOSHIFUJI Hideaki3fcfa122008-03-22 17:42:57 +0900274out:
275 write_unlock(&ipip6_lock);
Templin, Fred Lfadf6bf2008-03-11 18:35:59 -0400276 return 0;
277}
278
279/* copied directly from anycast.c */
280static int
281ipip6_onlink(struct in6_addr *addr, struct net_device *dev)
282{
283 struct inet6_dev *idev;
284 struct inet6_ifaddr *ifa;
285 int onlink;
286
287 onlink = 0;
288 rcu_read_lock();
289 idev = __in6_dev_get(dev);
290 if (idev) {
291 read_lock_bh(&idev->lock);
292 for (ifa=idev->addr_list; ifa; ifa=ifa->if_next) {
293 onlink = ipv6_prefix_equal(addr, &ifa->addr,
294 ifa->prefix_len);
295 if (onlink)
296 break;
297 }
298 read_unlock_bh(&idev->lock);
299 }
300 rcu_read_unlock();
301 return onlink;
302}
303
304static int
305isatap_chksrc(struct sk_buff *skb, struct iphdr *iph, struct ip_tunnel *t)
306{
YOSHIFUJI Hideaki3fcfa122008-03-22 17:42:57 +0900307 struct ip_tunnel_prl_entry *p;
Templin, Fred Lfadf6bf2008-03-11 18:35:59 -0400308 int ok = 1;
309
YOSHIFUJI Hideaki3fcfa122008-03-22 17:42:57 +0900310 read_lock(&ipip6_lock);
311 p = __ipip6_tunnel_locate_prl(t, iph->saddr);
Templin, Fred Lfadf6bf2008-03-11 18:35:59 -0400312 if (p) {
313 if (p->entry.flags & PRL_DEFAULT)
314 skb->ndisc_nodetype = NDISC_NODETYPE_DEFAULT;
315 else
316 skb->ndisc_nodetype = NDISC_NODETYPE_NODEFAULT;
317 } else {
318 struct in6_addr *addr6 = &ipv6_hdr(skb)->saddr;
319 if (ipv6_addr_is_isatap(addr6) &&
320 (addr6->s6_addr32[3] == iph->saddr) &&
321 ipip6_onlink(addr6, t->dev))
322 skb->ndisc_nodetype = NDISC_NODETYPE_HOST;
323 else
324 ok = 0;
325 }
YOSHIFUJI Hideaki3fcfa122008-03-22 17:42:57 +0900326 read_unlock(&ipip6_lock);
Templin, Fred Lfadf6bf2008-03-11 18:35:59 -0400327 return ok;
328}
329
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330static void ipip6_tunnel_uninit(struct net_device *dev)
331{
332 if (dev == ipip6_fb_tunnel_dev) {
333 write_lock_bh(&ipip6_lock);
334 tunnels_wc[0] = NULL;
335 write_unlock_bh(&ipip6_lock);
336 dev_put(dev);
337 } else {
Patrick McHardy2941a482006-01-08 22:05:26 -0800338 ipip6_tunnel_unlink(netdev_priv(dev));
Templin, Fred Lfadf6bf2008-03-11 18:35:59 -0400339 ipip6_tunnel_del_prl(netdev_priv(dev), 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340 dev_put(dev);
341 }
342}
343
344
Kazunori MIYAZAWAc73cb5a2007-02-13 12:55:25 -0800345static int ipip6_err(struct sk_buff *skb, u32 info)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346{
347#ifndef I_WISH_WORLD_WERE_PERFECT
348
349/* It is not :-( All the routers (except for Linux) return only
350 8 bytes of packet payload. It means, that precise relaying of
351 ICMP in the real Internet is absolutely infeasible.
352 */
353 struct iphdr *iph = (struct iphdr*)skb->data;
Arnaldo Carvalho de Melo88c76642007-03-13 14:43:18 -0300354 const int type = icmp_hdr(skb)->type;
355 const int code = icmp_hdr(skb)->code;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356 struct ip_tunnel *t;
Kazunori MIYAZAWAc73cb5a2007-02-13 12:55:25 -0800357 int err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358
359 switch (type) {
360 default:
361 case ICMP_PARAMETERPROB:
Kazunori MIYAZAWAc73cb5a2007-02-13 12:55:25 -0800362 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363
364 case ICMP_DEST_UNREACH:
365 switch (code) {
366 case ICMP_SR_FAILED:
367 case ICMP_PORT_UNREACH:
368 /* Impossible event. */
Kazunori MIYAZAWAc73cb5a2007-02-13 12:55:25 -0800369 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370 case ICMP_FRAG_NEEDED:
371 /* Soft state for pmtu is maintained by IP core. */
Kazunori MIYAZAWAc73cb5a2007-02-13 12:55:25 -0800372 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373 default:
374 /* All others are translated to HOST_UNREACH.
375 rfc2003 contains "deep thoughts" about NET_UNREACH,
376 I believe they are just ether pollution. --ANK
377 */
378 break;
379 }
380 break;
381 case ICMP_TIME_EXCEEDED:
382 if (code != ICMP_EXC_TTL)
Kazunori MIYAZAWAc73cb5a2007-02-13 12:55:25 -0800383 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384 break;
385 }
386
Kazunori MIYAZAWAc73cb5a2007-02-13 12:55:25 -0800387 err = -ENOENT;
388
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389 read_lock(&ipip6_lock);
390 t = ipip6_tunnel_lookup(iph->daddr, iph->saddr);
391 if (t == NULL || t->parms.iph.daddr == 0)
392 goto out;
Kazunori MIYAZAWAc73cb5a2007-02-13 12:55:25 -0800393
394 err = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395 if (t->parms.iph.ttl == 0 && type == ICMP_TIME_EXCEEDED)
396 goto out;
397
398 if (jiffies - t->err_time < IPTUNNEL_ERR_TIMEO)
399 t->err_count++;
400 else
401 t->err_count = 1;
402 t->err_time = jiffies;
403out:
404 read_unlock(&ipip6_lock);
Kazunori MIYAZAWAc73cb5a2007-02-13 12:55:25 -0800405 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406#else
407 struct iphdr *iph = (struct iphdr*)dp;
408 int hlen = iph->ihl<<2;
409 struct ipv6hdr *iph6;
Arnaldo Carvalho de Melo88c76642007-03-13 14:43:18 -0300410 const int type = icmp_hdr(skb)->type;
411 const int code = icmp_hdr(skb)->code;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412 int rel_type = 0;
413 int rel_code = 0;
414 int rel_info = 0;
415 struct sk_buff *skb2;
416 struct rt6_info *rt6i;
417
418 if (len < hlen + sizeof(struct ipv6hdr))
419 return;
420 iph6 = (struct ipv6hdr*)(dp + hlen);
421
422 switch (type) {
423 default:
424 return;
425 case ICMP_PARAMETERPROB:
Arnaldo Carvalho de Melo88c76642007-03-13 14:43:18 -0300426 if (icmp_hdr(skb)->un.gateway < hlen)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427 return;
428
429 /* So... This guy found something strange INSIDE encapsulated
430 packet. Well, he is fool, but what can we do ?
431 */
432 rel_type = ICMPV6_PARAMPROB;
Arnaldo Carvalho de Melo88c76642007-03-13 14:43:18 -0300433 rel_info = icmp_hdr(skb)->un.gateway - hlen;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434 break;
435
436 case ICMP_DEST_UNREACH:
437 switch (code) {
438 case ICMP_SR_FAILED:
439 case ICMP_PORT_UNREACH:
440 /* Impossible event. */
441 return;
442 case ICMP_FRAG_NEEDED:
443 /* Too complicated case ... */
444 return;
445 default:
446 /* All others are translated to HOST_UNREACH.
447 rfc2003 contains "deep thoughts" about NET_UNREACH,
448 I believe, it is just ether pollution. --ANK
449 */
450 rel_type = ICMPV6_DEST_UNREACH;
451 rel_code = ICMPV6_ADDR_UNREACH;
452 break;
453 }
454 break;
455 case ICMP_TIME_EXCEEDED:
456 if (code != ICMP_EXC_TTL)
457 return;
458 rel_type = ICMPV6_TIME_EXCEED;
459 rel_code = ICMPV6_EXC_HOPLIMIT;
460 break;
461 }
462
463 /* Prepare fake skb to feed it to icmpv6_send */
464 skb2 = skb_clone(skb, GFP_ATOMIC);
465 if (skb2 == NULL)
Kazunori MIYAZAWAc73cb5a2007-02-13 12:55:25 -0800466 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467 dst_release(skb2->dst);
468 skb2->dst = NULL;
469 skb_pull(skb2, skb->data - (u8*)iph6);
Arnaldo Carvalho de Meloc1d2bbe2007-04-10 20:45:18 -0700470 skb_reset_network_header(skb2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471
472 /* Try to guess incoming interface */
Daniel Lezcano606a2b42008-03-04 13:45:59 -0800473 rt6i = rt6_lookup(&init_net, &iph6->saddr, NULL, NULL, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474 if (rt6i && rt6i->rt6i_dev) {
475 skb2->dev = rt6i->rt6i_dev;
476
Daniel Lezcano606a2b42008-03-04 13:45:59 -0800477 rt6i = rt6_lookup(&init_net, &iph6->daddr, &iph6->saddr, NULL, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478
479 if (rt6i && rt6i->rt6i_dev && rt6i->rt6i_dev->type == ARPHRD_SIT) {
Patrick McHardy2941a482006-01-08 22:05:26 -0800480 struct ip_tunnel *t = netdev_priv(rt6i->rt6i_dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481 if (rel_type == ICMPV6_TIME_EXCEED && t->parms.iph.ttl) {
482 rel_type = ICMPV6_DEST_UNREACH;
483 rel_code = ICMPV6_ADDR_UNREACH;
484 }
485 icmpv6_send(skb2, rel_type, rel_code, rel_info, skb2->dev);
486 }
487 }
488 kfree_skb(skb2);
Kazunori MIYAZAWAc73cb5a2007-02-13 12:55:25 -0800489 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490#endif
491}
492
493static inline void ipip6_ecn_decapsulate(struct iphdr *iph, struct sk_buff *skb)
494{
495 if (INET_ECN_is_ce(iph->tos))
Arnaldo Carvalho de Melo0660e032007-04-25 17:54:47 -0700496 IP6_ECN_set_ce(ipv6_hdr(skb));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497}
498
499static int ipip6_rcv(struct sk_buff *skb)
500{
501 struct iphdr *iph;
502 struct ip_tunnel *tunnel;
503
504 if (!pskb_may_pull(skb, sizeof(struct ipv6hdr)))
505 goto out;
506
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -0700507 iph = ip_hdr(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508
509 read_lock(&ipip6_lock);
510 if ((tunnel = ipip6_tunnel_lookup(iph->saddr, iph->daddr)) != NULL) {
511 secpath_reset(skb);
Arnaldo Carvalho de Melob0e380b2007-04-10 21:21:55 -0700512 skb->mac_header = skb->network_header;
Arnaldo Carvalho de Meloc1d2bbe2007-04-10 20:45:18 -0700513 skb_reset_network_header(skb);
Patrick McHardy8cdfab82006-01-06 23:04:01 -0800514 IPCB(skb)->flags = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515 skb->protocol = htons(ETH_P_IPV6);
516 skb->pkt_type = PACKET_HOST;
Fred L. Templinc7dc89c2007-11-29 22:11:40 +1100517
518 if ((tunnel->dev->priv_flags & IFF_ISATAP) &&
Templin, Fred Lfadf6bf2008-03-11 18:35:59 -0400519 !isatap_chksrc(skb, iph, tunnel)) {
Fred L. Templinc7dc89c2007-11-29 22:11:40 +1100520 tunnel->stat.rx_errors++;
521 read_unlock(&ipip6_lock);
522 kfree_skb(skb);
523 return 0;
524 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525 tunnel->stat.rx_packets++;
526 tunnel->stat.rx_bytes += skb->len;
527 skb->dev = tunnel->dev;
528 dst_release(skb->dst);
529 skb->dst = NULL;
530 nf_reset(skb);
531 ipip6_ecn_decapsulate(iph, skb);
532 netif_rx(skb);
533 read_unlock(&ipip6_lock);
534 return 0;
535 }
536
Herbert Xu45af08b2006-04-05 22:31:19 -0700537 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538 kfree_skb(skb);
539 read_unlock(&ipip6_lock);
540out:
541 return 0;
542}
543
544/* Returns the embedded IPv4 address if the IPv6 address
545 comes from 6to4 (RFC 3056) addr space */
546
Al Viroe69a4adc2006-11-14 20:56:00 -0800547static inline __be32 try_6to4(struct in6_addr *v6dst)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548{
Al Viroe69a4adc2006-11-14 20:56:00 -0800549 __be32 dst = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550
551 if (v6dst->s6_addr16[0] == htons(0x2002)) {
YOSHIFUJI Hideaki1ab14572007-02-09 23:24:49 +0900552 /* 6to4 v6 addr has 16 bits prefix, 32 v4addr, 16 SLA, ... */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553 memcpy(&dst, &v6dst->s6_addr16[1], 4);
554 }
555 return dst;
556}
557
558/*
559 * This function assumes it is being called from dev_queue_xmit()
560 * and that skb is filled properly by that function.
561 */
562
563static int ipip6_tunnel_xmit(struct sk_buff *skb, struct net_device *dev)
564{
Patrick McHardy2941a482006-01-08 22:05:26 -0800565 struct ip_tunnel *tunnel = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700566 struct net_device_stats *stats = &tunnel->stat;
567 struct iphdr *tiph = &tunnel->parms.iph;
Arnaldo Carvalho de Melo0660e032007-04-25 17:54:47 -0700568 struct ipv6hdr *iph6 = ipv6_hdr(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569 u8 tos = tunnel->parms.iph.tos;
570 struct rtable *rt; /* Route to the other host */
571 struct net_device *tdev; /* Device to other host */
572 struct iphdr *iph; /* Our new IP header */
Chuck Leverc2636b42007-10-23 21:07:32 -0700573 unsigned int max_headroom; /* The extra header space needed */
Al Viroe69a4adc2006-11-14 20:56:00 -0800574 __be32 dst = tiph->daddr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575 int mtu;
YOSHIFUJI Hideaki1ab14572007-02-09 23:24:49 +0900576 struct in6_addr *addr6;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577 int addr_type;
578
579 if (tunnel->recursion++) {
580 tunnel->stat.collisions++;
581 goto tx_error;
582 }
583
584 if (skb->protocol != htons(ETH_P_IPV6))
585 goto tx_error;
586
Fred L. Templinc7dc89c2007-11-29 22:11:40 +1100587 /* ISATAP (RFC4214) - must come before 6to4 */
588 if (dev->priv_flags & IFF_ISATAP) {
589 struct neighbour *neigh = NULL;
590
591 if (skb->dst)
592 neigh = skb->dst->neighbour;
593
594 if (neigh == NULL) {
595 if (net_ratelimit())
596 printk(KERN_DEBUG "sit: nexthop == NULL\n");
597 goto tx_error;
598 }
599
600 addr6 = (struct in6_addr*)&neigh->primary_key;
601 addr_type = ipv6_addr_type(addr6);
602
603 if ((addr_type & IPV6_ADDR_UNICAST) &&
604 ipv6_addr_is_isatap(addr6))
605 dst = addr6->s6_addr32[3];
606 else
607 goto tx_error;
608 }
609
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610 if (!dst)
611 dst = try_6to4(&iph6->daddr);
612
613 if (!dst) {
614 struct neighbour *neigh = NULL;
615
616 if (skb->dst)
617 neigh = skb->dst->neighbour;
618
619 if (neigh == NULL) {
620 if (net_ratelimit())
621 printk(KERN_DEBUG "sit: nexthop == NULL\n");
622 goto tx_error;
623 }
624
625 addr6 = (struct in6_addr*)&neigh->primary_key;
626 addr_type = ipv6_addr_type(addr6);
627
628 if (addr_type == IPV6_ADDR_ANY) {
Arnaldo Carvalho de Melo0660e032007-04-25 17:54:47 -0700629 addr6 = &ipv6_hdr(skb)->daddr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700630 addr_type = ipv6_addr_type(addr6);
631 }
632
633 if ((addr_type & IPV6_ADDR_COMPATv4) == 0)
634 goto tx_error_icmp;
635
636 dst = addr6->s6_addr32[3];
637 }
638
639 {
640 struct flowi fl = { .nl_u = { .ip4_u =
641 { .daddr = dst,
642 .saddr = tiph->saddr,
643 .tos = RT_TOS(tos) } },
644 .oif = tunnel->parms.link,
645 .proto = IPPROTO_IPV6 };
Denis V. Lunevf2063512008-01-22 22:07:34 -0800646 if (ip_route_output_key(&init_net, &rt, &fl)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647 tunnel->stat.tx_carrier_errors++;
648 goto tx_error_icmp;
649 }
650 }
651 if (rt->rt_type != RTN_UNICAST) {
652 ip_rt_put(rt);
653 tunnel->stat.tx_carrier_errors++;
654 goto tx_error_icmp;
655 }
656 tdev = rt->u.dst.dev;
657
658 if (tdev == dev) {
659 ip_rt_put(rt);
660 tunnel->stat.collisions++;
661 goto tx_error;
662 }
663
664 if (tiph->frag_off)
665 mtu = dst_mtu(&rt->u.dst) - sizeof(struct iphdr);
666 else
667 mtu = skb->dst ? dst_mtu(skb->dst) : dev->mtu;
668
669 if (mtu < 68) {
670 tunnel->stat.collisions++;
671 ip_rt_put(rt);
672 goto tx_error;
673 }
674 if (mtu < IPV6_MIN_MTU)
675 mtu = IPV6_MIN_MTU;
676 if (tunnel->parms.iph.daddr && skb->dst)
677 skb->dst->ops->update_pmtu(skb->dst, mtu);
678
679 if (skb->len > mtu) {
680 icmpv6_send(skb, ICMPV6_PKT_TOOBIG, 0, mtu, dev);
681 ip_rt_put(rt);
682 goto tx_error;
683 }
684
685 if (tunnel->err_count > 0) {
686 if (jiffies - tunnel->err_time < IPTUNNEL_ERR_TIMEO) {
687 tunnel->err_count--;
688 dst_link_failure(skb);
689 } else
690 tunnel->err_count = 0;
691 }
692
693 /*
694 * Okay, now see if we can stuff it in the buffer as-is.
695 */
696 max_headroom = LL_RESERVED_SPACE(tdev)+sizeof(struct iphdr);
697
Patrick McHardycfbba492007-07-09 15:33:40 -0700698 if (skb_headroom(skb) < max_headroom || skb_shared(skb) ||
699 (skb_cloned(skb) && !skb_clone_writable(skb, 0))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700700 struct sk_buff *new_skb = skb_realloc_headroom(skb, max_headroom);
701 if (!new_skb) {
702 ip_rt_put(rt);
YOSHIFUJI Hideaki1ab14572007-02-09 23:24:49 +0900703 stats->tx_dropped++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700704 dev_kfree_skb(skb);
705 tunnel->recursion--;
706 return 0;
707 }
708 if (skb->sk)
709 skb_set_owner_w(new_skb, skb->sk);
710 dev_kfree_skb(skb);
711 skb = new_skb;
Arnaldo Carvalho de Melo0660e032007-04-25 17:54:47 -0700712 iph6 = ipv6_hdr(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700713 }
714
Arnaldo Carvalho de Melob0e380b2007-04-10 21:21:55 -0700715 skb->transport_header = skb->network_header;
Arnaldo Carvalho de Meloe2d1bca2007-04-10 20:46:21 -0700716 skb_push(skb, sizeof(struct iphdr));
717 skb_reset_network_header(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700718 memset(&(IPCB(skb)->opt), 0, sizeof(IPCB(skb)->opt));
Patrick McHardy8cdfab82006-01-06 23:04:01 -0800719 IPCB(skb)->flags = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700720 dst_release(skb->dst);
721 skb->dst = &rt->u.dst;
722
723 /*
724 * Push down and install the IPIP header.
725 */
726
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -0700727 iph = ip_hdr(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700728 iph->version = 4;
729 iph->ihl = sizeof(struct iphdr)>>2;
730 if (mtu > IPV6_MIN_MTU)
731 iph->frag_off = htons(IP_DF);
732 else
733 iph->frag_off = 0;
734
735 iph->protocol = IPPROTO_IPV6;
736 iph->tos = INET_ECN_encapsulate(tos, ipv6_get_dsfield(iph6));
737 iph->daddr = rt->rt_dst;
738 iph->saddr = rt->rt_src;
739
740 if ((iph->ttl = tiph->ttl) == 0)
741 iph->ttl = iph6->hop_limit;
742
743 nf_reset(skb);
744
745 IPTUNNEL_XMIT();
746 tunnel->recursion--;
747 return 0;
748
749tx_error_icmp:
750 dst_link_failure(skb);
751tx_error:
752 stats->tx_errors++;
753 dev_kfree_skb(skb);
754 tunnel->recursion--;
755 return 0;
756}
757
Michal Schmidt8a4a50f2007-12-13 09:47:00 -0800758static void ipip6_tunnel_bind_dev(struct net_device *dev)
759{
760 struct net_device *tdev = NULL;
761 struct ip_tunnel *tunnel;
762 struct iphdr *iph;
763
764 tunnel = netdev_priv(dev);
765 iph = &tunnel->parms.iph;
766
767 if (iph->daddr) {
768 struct flowi fl = { .nl_u = { .ip4_u =
769 { .daddr = iph->daddr,
770 .saddr = iph->saddr,
771 .tos = RT_TOS(iph->tos) } },
772 .oif = tunnel->parms.link,
773 .proto = IPPROTO_IPV6 };
774 struct rtable *rt;
Denis V. Lunevf2063512008-01-22 22:07:34 -0800775 if (!ip_route_output_key(&init_net, &rt, &fl)) {
Michal Schmidt8a4a50f2007-12-13 09:47:00 -0800776 tdev = rt->u.dst.dev;
777 ip_rt_put(rt);
778 }
779 dev->flags |= IFF_POINTOPOINT;
780 }
781
782 if (!tdev && tunnel->parms.link)
783 tdev = __dev_get_by_index(&init_net, tunnel->parms.link);
784
785 if (tdev) {
786 dev->hard_header_len = tdev->hard_header_len + sizeof(struct iphdr);
787 dev->mtu = tdev->mtu - sizeof(struct iphdr);
788 if (dev->mtu < IPV6_MIN_MTU)
789 dev->mtu = IPV6_MIN_MTU;
790 }
791 dev->iflink = tunnel->parms.link;
792}
793
Linus Torvalds1da177e2005-04-16 15:20:36 -0700794static int
795ipip6_tunnel_ioctl (struct net_device *dev, struct ifreq *ifr, int cmd)
796{
797 int err = 0;
798 struct ip_tunnel_parm p;
Templin, Fred Lfadf6bf2008-03-11 18:35:59 -0400799 struct ip_tunnel_prl prl;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700800 struct ip_tunnel *t;
801
802 switch (cmd) {
803 case SIOCGETTUNNEL:
804 t = NULL;
805 if (dev == ipip6_fb_tunnel_dev) {
806 if (copy_from_user(&p, ifr->ifr_ifru.ifru_data, sizeof(p))) {
807 err = -EFAULT;
808 break;
809 }
810 t = ipip6_tunnel_locate(&p, 0);
811 }
812 if (t == NULL)
Patrick McHardy2941a482006-01-08 22:05:26 -0800813 t = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700814 memcpy(&p, &t->parms, sizeof(p));
815 if (copy_to_user(ifr->ifr_ifru.ifru_data, &p, sizeof(p)))
816 err = -EFAULT;
817 break;
818
819 case SIOCADDTUNNEL:
820 case SIOCCHGTUNNEL:
821 err = -EPERM;
822 if (!capable(CAP_NET_ADMIN))
823 goto done;
824
825 err = -EFAULT;
826 if (copy_from_user(&p, ifr->ifr_ifru.ifru_data, sizeof(p)))
827 goto done;
828
829 err = -EINVAL;
830 if (p.iph.version != 4 || p.iph.protocol != IPPROTO_IPV6 ||
831 p.iph.ihl != 5 || (p.iph.frag_off&htons(~IP_DF)))
832 goto done;
833 if (p.iph.ttl)
834 p.iph.frag_off |= htons(IP_DF);
835
836 t = ipip6_tunnel_locate(&p, cmd == SIOCADDTUNNEL);
837
838 if (dev != ipip6_fb_tunnel_dev && cmd == SIOCCHGTUNNEL) {
839 if (t != NULL) {
840 if (t->dev != dev) {
841 err = -EEXIST;
842 break;
843 }
844 } else {
845 if (((dev->flags&IFF_POINTOPOINT) && !p.iph.daddr) ||
846 (!(dev->flags&IFF_POINTOPOINT) && p.iph.daddr)) {
847 err = -EINVAL;
848 break;
849 }
Patrick McHardy2941a482006-01-08 22:05:26 -0800850 t = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700851 ipip6_tunnel_unlink(t);
852 t->parms.iph.saddr = p.iph.saddr;
853 t->parms.iph.daddr = p.iph.daddr;
854 memcpy(dev->dev_addr, &p.iph.saddr, 4);
855 memcpy(dev->broadcast, &p.iph.daddr, 4);
856 ipip6_tunnel_link(t);
857 netdev_state_change(dev);
858 }
859 }
860
861 if (t) {
862 err = 0;
863 if (cmd == SIOCCHGTUNNEL) {
864 t->parms.iph.ttl = p.iph.ttl;
865 t->parms.iph.tos = p.iph.tos;
Michal Schmidt8a4a50f2007-12-13 09:47:00 -0800866 if (t->parms.link != p.link) {
867 t->parms.link = p.link;
868 ipip6_tunnel_bind_dev(dev);
869 netdev_state_change(dev);
870 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700871 }
872 if (copy_to_user(ifr->ifr_ifru.ifru_data, &t->parms, sizeof(p)))
873 err = -EFAULT;
874 } else
875 err = (cmd == SIOCADDTUNNEL ? -ENOBUFS : -ENOENT);
876 break;
877
878 case SIOCDELTUNNEL:
879 err = -EPERM;
880 if (!capable(CAP_NET_ADMIN))
881 goto done;
882
883 if (dev == ipip6_fb_tunnel_dev) {
884 err = -EFAULT;
885 if (copy_from_user(&p, ifr->ifr_ifru.ifru_data, sizeof(p)))
886 goto done;
887 err = -ENOENT;
888 if ((t = ipip6_tunnel_locate(&p, 0)) == NULL)
889 goto done;
890 err = -EPERM;
Patrick McHardy2941a482006-01-08 22:05:26 -0800891 if (t == netdev_priv(ipip6_fb_tunnel_dev))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700892 goto done;
893 dev = t->dev;
894 }
Stephen Hemminger22f8cde2007-02-07 00:09:58 -0800895 unregister_netdevice(dev);
896 err = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700897 break;
898
Templin, Fred Lfadf6bf2008-03-11 18:35:59 -0400899 case SIOCADDPRL:
900 case SIOCDELPRL:
901 case SIOCCHGPRL:
902 err = -EPERM;
903 if (!capable(CAP_NET_ADMIN))
904 goto done;
905 err = -EINVAL;
906 if (dev == ipip6_fb_tunnel_dev)
907 goto done;
908 err = -EFAULT;
909 if (copy_from_user(&prl, ifr->ifr_ifru.ifru_data, sizeof(prl)))
910 goto done;
911 err = -ENOENT;
912 if (!(t = netdev_priv(dev)))
913 goto done;
914
Templin, Fred Lfadf6bf2008-03-11 18:35:59 -0400915 if (cmd == SIOCDELPRL)
916 err = ipip6_tunnel_del_prl(t, &prl);
917 else
918 err = ipip6_tunnel_add_prl(t, &prl, cmd == SIOCCHGPRL);
Templin, Fred Lfadf6bf2008-03-11 18:35:59 -0400919 netdev_state_change(dev);
920 break;
921
Linus Torvalds1da177e2005-04-16 15:20:36 -0700922 default:
923 err = -EINVAL;
924 }
925
926done:
927 return err;
928}
929
930static struct net_device_stats *ipip6_tunnel_get_stats(struct net_device *dev)
931{
Patrick McHardy2941a482006-01-08 22:05:26 -0800932 return &(((struct ip_tunnel*)netdev_priv(dev))->stat);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700933}
934
935static int ipip6_tunnel_change_mtu(struct net_device *dev, int new_mtu)
936{
937 if (new_mtu < IPV6_MIN_MTU || new_mtu > 0xFFF8 - sizeof(struct iphdr))
938 return -EINVAL;
939 dev->mtu = new_mtu;
940 return 0;
941}
942
943static void ipip6_tunnel_setup(struct net_device *dev)
944{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700945 dev->uninit = ipip6_tunnel_uninit;
946 dev->destructor = free_netdev;
947 dev->hard_start_xmit = ipip6_tunnel_xmit;
948 dev->get_stats = ipip6_tunnel_get_stats;
949 dev->do_ioctl = ipip6_tunnel_ioctl;
950 dev->change_mtu = ipip6_tunnel_change_mtu;
951
952 dev->type = ARPHRD_SIT;
953 dev->hard_header_len = LL_MAX_HEADER + sizeof(struct iphdr);
Kris Katterjohn46f25df2006-01-05 16:35:42 -0800954 dev->mtu = ETH_DATA_LEN - sizeof(struct iphdr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700955 dev->flags = IFF_NOARP;
956 dev->iflink = 0;
957 dev->addr_len = 4;
958}
959
960static int ipip6_tunnel_init(struct net_device *dev)
961{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700962 struct ip_tunnel *tunnel;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700963
Patrick McHardy2941a482006-01-08 22:05:26 -0800964 tunnel = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700965
966 tunnel->dev = dev;
967 strcpy(tunnel->parms.name, dev->name);
968
969 memcpy(dev->dev_addr, &tunnel->parms.iph.saddr, 4);
970 memcpy(dev->broadcast, &tunnel->parms.iph.daddr, 4);
971
Michal Schmidt8a4a50f2007-12-13 09:47:00 -0800972 ipip6_tunnel_bind_dev(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700973
974 return 0;
975}
976
Arnaldo Carvalho de Melo20380732005-08-16 02:18:02 -0300977static int __init ipip6_fb_tunnel_init(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700978{
Patrick McHardy2941a482006-01-08 22:05:26 -0800979 struct ip_tunnel *tunnel = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700980 struct iphdr *iph = &tunnel->parms.iph;
981
982 tunnel->dev = dev;
983 strcpy(tunnel->parms.name, dev->name);
984
985 iph->version = 4;
986 iph->protocol = IPPROTO_IPV6;
987 iph->ihl = 5;
988 iph->ttl = 64;
989
990 dev_hold(dev);
991 tunnels_wc[0] = tunnel;
992 return 0;
993}
994
Kazunori MIYAZAWAc73cb5a2007-02-13 12:55:25 -0800995static struct xfrm_tunnel sit_handler = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700996 .handler = ipip6_rcv,
997 .err_handler = ipip6_err,
Kazunori MIYAZAWAc73cb5a2007-02-13 12:55:25 -0800998 .priority = 1,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700999};
1000
Alexey Kuznetsovdb445752005-07-30 17:46:44 -07001001static void __exit sit_destroy_tunnels(void)
1002{
1003 int prio;
1004
1005 for (prio = 1; prio < 4; prio++) {
1006 int h;
1007 for (h = 0; h < HASH_SIZE; h++) {
1008 struct ip_tunnel *t;
1009 while ((t = tunnels[prio][h]) != NULL)
1010 unregister_netdevice(t->dev);
1011 }
1012 }
1013}
1014
Adrian Bunk89c89452006-11-20 16:56:48 -08001015static void __exit sit_cleanup(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001016{
Kazunori MIYAZAWAc73cb5a2007-02-13 12:55:25 -08001017 xfrm4_tunnel_deregister(&sit_handler, AF_INET6);
Alexey Kuznetsovdb445752005-07-30 17:46:44 -07001018
1019 rtnl_lock();
1020 sit_destroy_tunnels();
1021 unregister_netdevice(ipip6_fb_tunnel_dev);
1022 rtnl_unlock();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001023}
1024
Adrian Bunk89c89452006-11-20 16:56:48 -08001025static int __init sit_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001026{
1027 int err;
1028
1029 printk(KERN_INFO "IPv6 over IPv4 tunneling driver\n");
1030
Kazunori MIYAZAWAc73cb5a2007-02-13 12:55:25 -08001031 if (xfrm4_tunnel_register(&sit_handler, AF_INET6) < 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001032 printk(KERN_INFO "sit init: Can't add protocol\n");
1033 return -EAGAIN;
1034 }
1035
YOSHIFUJI Hideaki1ab14572007-02-09 23:24:49 +09001036 ipip6_fb_tunnel_dev = alloc_netdev(sizeof(struct ip_tunnel), "sit0",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001037 ipip6_tunnel_setup);
1038 if (!ipip6_fb_tunnel_dev) {
1039 err = -ENOMEM;
1040 goto err1;
1041 }
1042
1043 ipip6_fb_tunnel_dev->init = ipip6_fb_tunnel_init;
1044
1045 if ((err = register_netdev(ipip6_fb_tunnel_dev)))
1046 goto err2;
1047
1048 out:
1049 return err;
1050 err2:
1051 free_netdev(ipip6_fb_tunnel_dev);
1052 err1:
Kazunori MIYAZAWAc73cb5a2007-02-13 12:55:25 -08001053 xfrm4_tunnel_deregister(&sit_handler, AF_INET6);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001054 goto out;
1055}
Joerg Roedel989e5b92006-10-10 14:47:44 -07001056
1057module_init(sit_init);
1058module_exit(sit_cleanup);
Jan Dittmer39c85082006-10-13 15:05:53 -07001059MODULE_LICENSE("GPL");
Patrick McHardydaccff02006-11-05 15:47:04 -08001060MODULE_ALIAS("sit0");