Import 2.3.41pre2
[davej-history.git] / net / ipv6 / sit.c
blob818ad66caa0c338eff4d36d473461d31a6c0e774
1 /*
2 * IPv6 over IPv4 tunnel device - Simple Internet Transition (SIT)
3 * Linux INET6 implementation
5 * Authors:
6 * Pedro Roque <roque@di.fc.ul.pt>
7 * Alexey Kuznetsov <kuznet@ms2.inr.ac.ru>
9 * $Id: sit.c,v 1.35 2000/01/06 00:42:08 davem Exp $
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.
17 #define __NO_VERSION__
18 #include <linux/module.h>
19 #include <linux/errno.h>
20 #include <linux/types.h>
21 #include <linux/socket.h>
22 #include <linux/sockios.h>
23 #include <linux/sched.h>
24 #include <linux/net.h>
25 #include <linux/in6.h>
26 #include <linux/netdevice.h>
27 #include <linux/if_arp.h>
28 #include <linux/icmp.h>
29 #include <asm/uaccess.h>
30 #include <linux/init.h>
32 #include <net/sock.h>
33 #include <net/snmp.h>
35 #include <net/ipv6.h>
36 #include <net/protocol.h>
37 #include <net/transp_v6.h>
38 #include <net/ip6_fib.h>
39 #include <net/ip6_route.h>
40 #include <net/ndisc.h>
41 #include <net/addrconf.h>
42 #include <net/ip.h>
43 #include <net/udp.h>
44 #include <net/icmp.h>
45 #include <net/ipip.h>
48 This version of net/ipv6/sit.c is cloned of net/ipv4/ip_gre.c
50 For comments look at net/ipv4/ip_gre.c --ANK
53 #define HASH_SIZE 16
54 #define HASH(addr) ((addr^(addr>>4))&0xF)
56 static int ipip6_fb_tunnel_init(struct net_device *dev);
57 static int ipip6_tunnel_init(struct net_device *dev);
59 static struct net_device ipip6_fb_tunnel_dev = {
60 NULL, 0x0, 0x0, 0x0, 0x0, 0, 0, 0, 0, 0, NULL, ipip6_fb_tunnel_init,
63 static struct ip_tunnel ipip6_fb_tunnel = {
64 NULL, &ipip6_fb_tunnel_dev, {0, }, 0, 0, 0, 0, 0, 0, 0, {"sit0", }
67 static struct ip_tunnel *tunnels_r_l[HASH_SIZE];
68 static struct ip_tunnel *tunnels_r[HASH_SIZE];
69 static struct ip_tunnel *tunnels_l[HASH_SIZE];
70 static struct ip_tunnel *tunnels_wc[1];
71 static struct ip_tunnel **tunnels[4] = { tunnels_wc, tunnels_l, tunnels_r, tunnels_r_l };
73 static rwlock_t ipip6_lock = RW_LOCK_UNLOCKED;
75 static struct ip_tunnel * ipip6_tunnel_lookup(u32 remote, u32 local)
77 unsigned h0 = HASH(remote);
78 unsigned h1 = HASH(local);
79 struct ip_tunnel *t;
81 for (t = tunnels_r_l[h0^h1]; t; t = t->next) {
82 if (local == t->parms.iph.saddr &&
83 remote == t->parms.iph.daddr && (t->dev->flags&IFF_UP))
84 return t;
86 for (t = tunnels_r[h0]; t; t = t->next) {
87 if (remote == t->parms.iph.daddr && (t->dev->flags&IFF_UP))
88 return t;
90 for (t = tunnels_l[h1]; t; t = t->next) {
91 if (local == t->parms.iph.saddr && (t->dev->flags&IFF_UP))
92 return t;
94 if ((t = tunnels_wc[0]) != NULL && (t->dev->flags&IFF_UP))
95 return t;
96 return NULL;
99 static struct ip_tunnel ** ipip6_bucket(struct ip_tunnel *t)
101 u32 remote = t->parms.iph.daddr;
102 u32 local = t->parms.iph.saddr;
103 unsigned h = 0;
104 int prio = 0;
106 if (remote) {
107 prio |= 2;
108 h ^= HASH(remote);
110 if (local) {
111 prio |= 1;
112 h ^= HASH(local);
114 return &tunnels[prio][h];
117 static void ipip6_tunnel_unlink(struct ip_tunnel *t)
119 struct ip_tunnel **tp;
121 for (tp = ipip6_bucket(t); *tp; tp = &(*tp)->next) {
122 if (t == *tp) {
123 write_lock_bh(&ipip6_lock);
124 *tp = t->next;
125 write_unlock_bh(&ipip6_lock);
126 break;
131 static void ipip6_tunnel_link(struct ip_tunnel *t)
133 struct ip_tunnel **tp = ipip6_bucket(t);
135 write_lock_bh(&ipip6_lock);
136 t->next = *tp;
137 write_unlock_bh(&ipip6_lock);
138 *tp = t;
141 struct ip_tunnel * ipip6_tunnel_locate(struct ip_tunnel_parm *parms, int create)
143 u32 remote = parms->iph.daddr;
144 u32 local = parms->iph.saddr;
145 struct ip_tunnel *t, **tp, *nt;
146 struct net_device *dev;
147 unsigned h = 0;
148 int prio = 0;
150 if (remote) {
151 prio |= 2;
152 h ^= HASH(remote);
154 if (local) {
155 prio |= 1;
156 h ^= HASH(local);
158 for (tp = &tunnels[prio][h]; (t = *tp) != NULL; tp = &t->next) {
159 if (local == t->parms.iph.saddr && remote == t->parms.iph.daddr)
160 return t;
162 if (!create)
163 return NULL;
165 MOD_INC_USE_COUNT;
166 dev = kmalloc(sizeof(*dev) + sizeof(*t), GFP_KERNEL);
167 if (dev == NULL) {
168 MOD_DEC_USE_COUNT;
169 return NULL;
171 memset(dev, 0, sizeof(*dev) + sizeof(*t));
172 dev->priv = (void*)(dev+1);
173 nt = (struct ip_tunnel*)dev->priv;
174 nt->dev = dev;
175 dev->name = nt->parms.name;
176 dev->init = ipip6_tunnel_init;
177 dev->new_style = 1;
178 memcpy(&nt->parms, parms, sizeof(*parms));
179 if (dev->name[0] == 0) {
180 int i;
181 for (i=1; i<100; i++) {
182 sprintf(dev->name, "sit%d", i);
183 if (__dev_get_by_name(dev->name) == NULL)
184 break;
186 if (i==100)
187 goto failed;
188 memcpy(parms->name, dev->name, IFNAMSIZ);
190 if (register_netdevice(dev) < 0)
191 goto failed;
193 dev_hold(dev);
194 ipip6_tunnel_link(nt);
195 /* Do not decrement MOD_USE_COUNT here. */
196 return nt;
198 failed:
199 kfree(dev);
200 MOD_DEC_USE_COUNT;
201 return NULL;
204 static void ipip6_tunnel_destructor(struct net_device *dev)
206 if (dev != &ipip6_fb_tunnel_dev) {
207 MOD_DEC_USE_COUNT;
211 static void ipip6_tunnel_uninit(struct net_device *dev)
213 if (dev == &ipip6_fb_tunnel_dev) {
214 write_lock_bh(&ipip6_lock);
215 tunnels_wc[0] = NULL;
216 write_unlock_bh(&ipip6_lock);
217 dev_put(dev);
218 } else {
219 ipip6_tunnel_unlink((struct ip_tunnel*)dev->priv);
220 dev_put(dev);
225 void ipip6_err(struct sk_buff *skb, unsigned char *dp, int len)
227 #ifndef I_WISH_WORLD_WERE_PERFECT
229 /* It is not :-( All the routers (except for Linux) return only
230 8 bytes of packet payload. It means, that precise relaying of
231 ICMP in the real Internet is absolutely infeasible.
233 struct iphdr *iph = (struct iphdr*)dp;
234 int type = skb->h.icmph->type;
235 int code = skb->h.icmph->code;
236 struct ip_tunnel *t;
238 if (len < sizeof(struct iphdr))
239 return;
241 switch (type) {
242 default:
243 case ICMP_PARAMETERPROB:
244 return;
246 case ICMP_DEST_UNREACH:
247 switch (code) {
248 case ICMP_SR_FAILED:
249 case ICMP_PORT_UNREACH:
250 /* Impossible event. */
251 return;
252 case ICMP_FRAG_NEEDED:
253 /* Soft state for pmtu is maintained by IP core. */
254 return;
255 default:
256 /* All others are translated to HOST_UNREACH.
257 rfc2003 contains "deep thoughts" about NET_UNREACH,
258 I believe they are just ether pollution. --ANK
260 break;
262 break;
263 case ICMP_TIME_EXCEEDED:
264 if (code != ICMP_EXC_TTL)
265 return;
266 break;
269 read_lock(&ipip6_lock);
270 t = ipip6_tunnel_lookup(iph->daddr, iph->saddr);
271 if (t == NULL || t->parms.iph.daddr == 0)
272 goto out;
273 if (t->parms.iph.ttl == 0 && type == ICMP_TIME_EXCEEDED)
274 goto out;
276 if (jiffies - t->err_time < IPTUNNEL_ERR_TIMEO)
277 t->err_count++;
278 else
279 t->err_count = 1;
280 t->err_time = jiffies;
281 out:
282 read_unlock(&ipip6_lock);
283 return;
284 #else
285 struct iphdr *iph = (struct iphdr*)dp;
286 int hlen = iph->ihl<<2;
287 struct ipv6hdr *iph6;
288 int type = skb->h.icmph->type;
289 int code = skb->h.icmph->code;
290 int rel_type = 0;
291 int rel_code = 0;
292 int rel_info = 0;
293 struct sk_buff *skb2;
294 struct rt6_info *rt6i;
296 if (len < hlen + sizeof(struct ipv6hdr))
297 return;
298 iph6 = (struct ipv6hdr*)(dp + hlen);
300 switch (type) {
301 default:
302 return;
303 case ICMP_PARAMETERPROB:
304 if (skb->h.icmph->un.gateway < hlen)
305 return;
307 /* So... This guy found something strange INSIDE encapsulated
308 packet. Well, he is fool, but what can we do ?
310 rel_type = ICMPV6_PARAMPROB;
311 rel_info = skb->h.icmph->un.gateway - hlen;
312 break;
314 case ICMP_DEST_UNREACH:
315 switch (code) {
316 case ICMP_SR_FAILED:
317 case ICMP_PORT_UNREACH:
318 /* Impossible event. */
319 return;
320 case ICMP_FRAG_NEEDED:
321 /* Too complicated case ... */
322 return;
323 default:
324 /* All others are translated to HOST_UNREACH.
325 rfc2003 contains "deep thoughts" about NET_UNREACH,
326 I believe, it is just ether pollution. --ANK
328 rel_type = ICMPV6_DEST_UNREACH;
329 rel_code = ICMPV6_ADDR_UNREACH;
330 break;
332 break;
333 case ICMP_TIME_EXCEEDED:
334 if (code != ICMP_EXC_TTL)
335 return;
336 rel_type = ICMPV6_TIME_EXCEED;
337 rel_code = ICMPV6_EXC_HOPLIMIT;
338 break;
341 /* Prepare fake skb to feed it to icmpv6_send */
342 skb2 = skb_clone(skb, GFP_ATOMIC);
343 if (skb2 == NULL)
344 return;
345 dst_release(skb2->dst);
346 skb2->dst = NULL;
347 skb_pull(skb2, skb->data - (u8*)iph6);
348 skb2->nh.raw = skb2->data;
350 /* Try to guess incoming interface */
351 rt6i = rt6_lookup(&iph6->saddr, NULL, NULL, 0);
352 if (rt6i && rt6i->rt6i_dev) {
353 skb2->dev = rt6i->rt6i_dev;
355 rt6i = rt6_lookup(&iph6->daddr, &iph6->saddr, NULL, 0);
357 if (rt6i && rt6i->rt6i_dev && rt6i->rt6i_dev->type == ARPHRD_SIT) {
358 struct ip_tunnel * t = (struct ip_tunnel*)rt6i->rt6i_dev->priv;
359 if (rel_type == ICMPV6_TIME_EXCEED && t->parms.iph.ttl) {
360 rel_type = ICMPV6_DEST_UNREACH;
361 rel_code = ICMPV6_ADDR_UNREACH;
363 icmpv6_send(skb2, rel_type, rel_code, rel_info, skb2->dev);
366 kfree_skb(skb2);
367 return;
368 #endif
371 int ipip6_rcv(struct sk_buff *skb, unsigned short len)
373 struct iphdr *iph;
374 struct ip_tunnel *tunnel;
376 iph = skb->nh.iph;
378 read_lock(&ipip6_lock);
379 if ((tunnel = ipip6_tunnel_lookup(iph->saddr, iph->daddr)) != NULL) {
380 skb->mac.raw = skb->nh.raw;
381 skb->nh.raw = skb_pull(skb, skb->h.raw - skb->data);
382 memset(&(IPCB(skb)->opt), 0, sizeof(struct ip_options));
383 skb->protocol = __constant_htons(ETH_P_IPV6);
384 skb->ip_summed = 0;
385 skb->pkt_type = PACKET_HOST;
386 tunnel->stat.rx_packets++;
387 tunnel->stat.rx_bytes += skb->len;
388 skb->dev = tunnel->dev;
389 dst_release(skb->dst);
390 skb->dst = NULL;
391 netif_rx(skb);
392 read_unlock(&ipip6_lock);
393 return 0;
396 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PROT_UNREACH, 0);
397 kfree_skb(skb);
398 read_unlock(&ipip6_lock);
399 return 0;
403 * This function assumes it is being called from dev_queue_xmit()
404 * and that skb is filled properly by that function.
407 static int ipip6_tunnel_xmit(struct sk_buff *skb, struct net_device *dev)
409 struct ip_tunnel *tunnel = (struct ip_tunnel*)dev->priv;
410 struct net_device_stats *stats = &tunnel->stat;
411 struct iphdr *tiph = &tunnel->parms.iph;
412 struct ipv6hdr *iph6 = skb->nh.ipv6h;
413 u8 tos = tunnel->parms.iph.tos;
414 struct rtable *rt; /* Route to the other host */
415 struct net_device *tdev; /* Device to other host */
416 struct iphdr *iph; /* Our new IP header */
417 int max_headroom; /* The extra header space needed */
418 u32 dst = tiph->daddr;
419 int mtu;
420 struct in6_addr *addr6;
421 int addr_type;
423 if (tunnel->recursion++) {
424 tunnel->stat.collisions++;
425 goto tx_error;
428 if (skb->protocol != __constant_htons(ETH_P_IPV6))
429 goto tx_error;
431 if (!dst) {
432 struct neighbour *neigh = NULL;
434 if (skb->dst)
435 neigh = skb->dst->neighbour;
437 if (neigh == NULL) {
438 printk(KERN_DEBUG "sit: nexthop == NULL\n");
439 goto tx_error;
442 addr6 = (struct in6_addr*)&neigh->primary_key;
443 addr_type = ipv6_addr_type(addr6);
445 if (addr_type == IPV6_ADDR_ANY) {
446 addr6 = &skb->nh.ipv6h->daddr;
447 addr_type = ipv6_addr_type(addr6);
450 if ((addr_type & IPV6_ADDR_COMPATv4) == 0)
451 goto tx_error_icmp;
453 dst = addr6->s6_addr32[3];
456 if (ip_route_output(&rt, dst, tiph->saddr, RT_TOS(tos), tunnel->parms.link)) {
457 tunnel->stat.tx_carrier_errors++;
458 goto tx_error_icmp;
460 tdev = rt->u.dst.dev;
462 if (tdev == dev) {
463 ip_rt_put(rt);
464 tunnel->stat.collisions++;
465 goto tx_error;
468 mtu = rt->u.dst.pmtu - sizeof(struct iphdr);
469 if (mtu < 68) {
470 tunnel->stat.collisions++;
471 ip_rt_put(rt);
472 goto tx_error;
474 if (mtu < IPV6_MIN_MTU)
475 mtu = IPV6_MIN_MTU;
476 if (skb->dst && mtu < skb->dst->pmtu) {
477 struct rt6_info *rt6 = (struct rt6_info*)skb->dst;
478 if (mtu < rt6->u.dst.pmtu) {
479 if (tunnel->parms.iph.daddr || rt6->rt6i_dst.plen == 128) {
480 rt6->rt6i_flags |= RTF_MODIFIED;
481 rt6->u.dst.pmtu = mtu;
485 if (skb->len > mtu) {
486 icmpv6_send(skb, ICMPV6_PKT_TOOBIG, 0, mtu, dev);
487 ip_rt_put(rt);
488 goto tx_error;
491 if (tunnel->err_count > 0) {
492 if (jiffies - tunnel->err_time < IPTUNNEL_ERR_TIMEO) {
493 tunnel->err_count--;
494 dst_link_failure(skb);
495 } else
496 tunnel->err_count = 0;
499 skb->h.raw = skb->nh.raw;
502 * Okay, now see if we can stuff it in the buffer as-is.
504 max_headroom = (((tdev->hard_header_len+15)&~15)+sizeof(struct iphdr));
506 if (skb_headroom(skb) < max_headroom || skb_cloned(skb) || skb_shared(skb)) {
507 struct sk_buff *new_skb = skb_realloc_headroom(skb, max_headroom);
508 if (!new_skb) {
509 ip_rt_put(rt);
510 stats->tx_dropped++;
511 dev_kfree_skb(skb);
512 tunnel->recursion--;
513 return 0;
515 if (skb->sk)
516 skb_set_owner_w(new_skb, skb->sk);
517 dev_kfree_skb(skb);
518 skb = new_skb;
521 skb->nh.raw = skb_push(skb, sizeof(struct iphdr));
522 memset(&(IPCB(skb)->opt), 0, sizeof(IPCB(skb)->opt));
523 dst_release(skb->dst);
524 skb->dst = &rt->u.dst;
527 * Push down and install the IPIP header.
530 iph = skb->nh.iph;
531 iph->version = 4;
532 iph->ihl = sizeof(struct iphdr)>>2;
533 if (mtu > IPV6_MIN_MTU)
534 iph->frag_off = __constant_htons(IP_DF);
535 else
536 iph->frag_off = 0;
538 iph->protocol = IPPROTO_IPV6;
539 iph->tos = tos;
540 iph->daddr = rt->rt_dst;
541 iph->saddr = rt->rt_src;
543 if ((iph->ttl = tiph->ttl) == 0)
544 iph->ttl = iph6->hop_limit;
546 iph->tot_len = htons(skb->len);
547 ip_select_ident(iph, &rt->u.dst);
548 ip_send_check(iph);
550 stats->tx_bytes += skb->len;
551 stats->tx_packets++;
552 ip_send(skb);
554 tunnel->recursion--;
555 return 0;
557 tx_error_icmp:
558 dst_link_failure(skb);
559 tx_error:
560 stats->tx_errors++;
561 dev_kfree_skb(skb);
562 tunnel->recursion--;
563 return 0;
566 static int
567 ipip6_tunnel_ioctl (struct net_device *dev, struct ifreq *ifr, int cmd)
569 int err = 0;
570 struct ip_tunnel_parm p;
571 struct ip_tunnel *t;
573 MOD_INC_USE_COUNT;
575 switch (cmd) {
576 case SIOCGETTUNNEL:
577 t = NULL;
578 if (dev == &ipip6_fb_tunnel_dev) {
579 if (copy_from_user(&p, ifr->ifr_ifru.ifru_data, sizeof(p))) {
580 err = -EFAULT;
581 break;
583 t = ipip6_tunnel_locate(&p, 0);
585 if (t == NULL)
586 t = (struct ip_tunnel*)dev->priv;
587 memcpy(&p, &t->parms, sizeof(p));
588 if (copy_to_user(ifr->ifr_ifru.ifru_data, &p, sizeof(p)))
589 err = -EFAULT;
590 break;
592 case SIOCADDTUNNEL:
593 case SIOCCHGTUNNEL:
594 err = -EPERM;
595 if (!capable(CAP_NET_ADMIN))
596 goto done;
598 err = -EFAULT;
599 if (copy_from_user(&p, ifr->ifr_ifru.ifru_data, sizeof(p)))
600 goto done;
602 err = -EINVAL;
603 if (p.iph.version != 4 || p.iph.protocol != IPPROTO_IPV6 ||
604 p.iph.ihl != 5 || (p.iph.frag_off&__constant_htons(~IP_DF)))
605 goto done;
606 if (p.iph.ttl)
607 p.iph.frag_off |= __constant_htons(IP_DF);
609 t = ipip6_tunnel_locate(&p, cmd == SIOCADDTUNNEL);
611 if (dev != &ipip6_fb_tunnel_dev && cmd == SIOCCHGTUNNEL &&
612 t != &ipip6_fb_tunnel) {
613 if (t != NULL) {
614 if (t->dev != dev) {
615 err = -EEXIST;
616 break;
618 } else {
619 if (((dev->flags&IFF_POINTOPOINT) && !p.iph.daddr) ||
620 (!(dev->flags&IFF_POINTOPOINT) && p.iph.daddr)) {
621 err = -EINVAL;
622 break;
624 t = (struct ip_tunnel*)dev->priv;
625 ipip6_tunnel_unlink(t);
626 t->parms.iph.saddr = p.iph.saddr;
627 t->parms.iph.daddr = p.iph.daddr;
628 memcpy(dev->dev_addr, &p.iph.saddr, 4);
629 memcpy(dev->broadcast, &p.iph.daddr, 4);
630 ipip6_tunnel_link(t);
631 netdev_state_change(dev);
635 if (t) {
636 err = 0;
637 if (cmd == SIOCCHGTUNNEL) {
638 t->parms.iph.ttl = p.iph.ttl;
639 t->parms.iph.tos = p.iph.tos;
641 if (copy_to_user(ifr->ifr_ifru.ifru_data, &t->parms, sizeof(p)))
642 err = -EFAULT;
643 } else
644 err = (cmd == SIOCADDTUNNEL ? -ENOBUFS : -ENOENT);
645 break;
647 case SIOCDELTUNNEL:
648 err = -EPERM;
649 if (!capable(CAP_NET_ADMIN))
650 goto done;
652 if (dev == &ipip6_fb_tunnel_dev) {
653 err = -EFAULT;
654 if (copy_from_user(&p, ifr->ifr_ifru.ifru_data, sizeof(p)))
655 goto done;
656 err = -ENOENT;
657 if ((t = ipip6_tunnel_locate(&p, 0)) == NULL)
658 goto done;
659 err = -EPERM;
660 if (t == &ipip6_fb_tunnel)
661 goto done;
663 err = unregister_netdevice(dev);
664 break;
666 default:
667 err = -EINVAL;
670 done:
671 MOD_DEC_USE_COUNT;
672 return err;
675 static struct net_device_stats *ipip6_tunnel_get_stats(struct net_device *dev)
677 return &(((struct ip_tunnel*)dev->priv)->stat);
680 static int ipip6_tunnel_change_mtu(struct net_device *dev, int new_mtu)
682 if (new_mtu < IPV6_MIN_MTU || new_mtu > 0xFFF8 - sizeof(struct iphdr))
683 return -EINVAL;
684 dev->mtu = new_mtu;
685 return 0;
688 static void ipip6_tunnel_init_gen(struct net_device *dev)
690 struct ip_tunnel *t = (struct ip_tunnel*)dev->priv;
692 dev->destructor = ipip6_tunnel_destructor;
693 dev->uninit = ipip6_tunnel_uninit;
694 dev->hard_start_xmit = ipip6_tunnel_xmit;
695 dev->get_stats = ipip6_tunnel_get_stats;
696 dev->do_ioctl = ipip6_tunnel_ioctl;
697 dev->change_mtu = ipip6_tunnel_change_mtu;
699 dev_init_buffers(dev);
701 dev->type = ARPHRD_SIT;
702 dev->hard_header_len = LL_MAX_HEADER + sizeof(struct iphdr);
703 dev->mtu = 1500 - sizeof(struct iphdr);
704 dev->flags = IFF_NOARP;
705 dev->iflink = 0;
706 dev->addr_len = 4;
707 memcpy(dev->dev_addr, &t->parms.iph.saddr, 4);
708 memcpy(dev->broadcast, &t->parms.iph.daddr, 4);
711 static int ipip6_tunnel_init(struct net_device *dev)
713 struct net_device *tdev = NULL;
714 struct ip_tunnel *tunnel;
715 struct iphdr *iph;
717 tunnel = (struct ip_tunnel*)dev->priv;
718 iph = &tunnel->parms.iph;
720 ipip6_tunnel_init_gen(dev);
722 if (iph->daddr) {
723 struct rtable *rt;
724 if (!ip_route_output(&rt, iph->daddr, iph->saddr, RT_TOS(iph->tos), tunnel->parms.link)) {
725 tdev = rt->u.dst.dev;
726 ip_rt_put(rt);
728 dev->flags |= IFF_POINTOPOINT;
731 if (!tdev && tunnel->parms.link)
732 tdev = __dev_get_by_index(tunnel->parms.link);
734 if (tdev) {
735 dev->hard_header_len = tdev->hard_header_len + sizeof(struct iphdr);
736 dev->mtu = tdev->mtu - sizeof(struct iphdr);
737 if (dev->mtu < IPV6_MIN_MTU)
738 dev->mtu = IPV6_MIN_MTU;
740 dev->iflink = tunnel->parms.link;
742 return 0;
745 #ifdef MODULE
746 static int ipip6_fb_tunnel_open(struct net_device *dev)
748 MOD_INC_USE_COUNT;
749 return 0;
752 static int ipip6_fb_tunnel_close(struct net_device *dev)
754 MOD_DEC_USE_COUNT;
755 return 0;
757 #endif
759 int __init ipip6_fb_tunnel_init(struct net_device *dev)
761 struct iphdr *iph;
763 ipip6_tunnel_init_gen(dev);
764 #ifdef MODULE
765 dev->open = ipip6_fb_tunnel_open;
766 dev->stop = ipip6_fb_tunnel_close;
767 #endif
769 iph = &ipip6_fb_tunnel.parms.iph;
770 iph->version = 4;
771 iph->protocol = IPPROTO_IPV6;
772 iph->ihl = 5;
773 iph->ttl = 64;
775 dev_hold(dev);
776 tunnels_wc[0] = &ipip6_fb_tunnel;
777 return 0;
780 static struct inet_protocol sit_protocol = {
781 ipip6_rcv,
782 ipip6_err,
784 IPPROTO_IPV6,
786 NULL,
787 "IPv6"
790 #ifdef MODULE
791 void sit_cleanup(void)
793 inet_del_protocol(&sit_protocol);
794 unregister_netdevice(&ipip6_fb_tunnel_dev);
796 #endif
798 int __init sit_init(void)
800 printk(KERN_INFO "IPv6 over IPv4 tunneling driver\n");
802 ipip6_fb_tunnel_dev.priv = (void*)&ipip6_fb_tunnel;
803 ipip6_fb_tunnel_dev.name = ipip6_fb_tunnel.parms.name;
804 #ifdef MODULE
805 register_netdev(&ipip6_fb_tunnel_dev);
806 #else
807 register_netdevice(&ipip6_fb_tunnel_dev);
808 #endif
809 inet_add_protocol(&sit_protocol);
810 return 0;