[SK_BUFF]: Use skb_reset_network_header in skb_push cases
[linux-2.6/linux-loongson.git] / net / ipv6 / ip6_tunnel.c
bloba1e4f39c6793f3ea4ec1432e7cc4ed78f72b3c5c
1 /*
2 * IPv6 tunneling device
3 * Linux INET6 implementation
5 * Authors:
6 * Ville Nuorvala <vnuorval@tcs.hut.fi>
7 * Yasuyuki Kozakai <kozakai@linux-ipv6.org>
9 * $Id$
11 * Based on:
12 * linux/net/ipv6/sit.c and linux/net/ipv4/ipip.c
14 * RFC 2473
16 * This program is free software; you can redistribute it and/or
17 * modify it under the terms of the GNU General Public License
18 * as published by the Free Software Foundation; either version
19 * 2 of the License, or (at your option) any later version.
23 #include <linux/module.h>
24 #include <linux/capability.h>
25 #include <linux/errno.h>
26 #include <linux/types.h>
27 #include <linux/sockios.h>
28 #include <linux/icmp.h>
29 #include <linux/if.h>
30 #include <linux/in.h>
31 #include <linux/ip.h>
32 #include <linux/if_tunnel.h>
33 #include <linux/net.h>
34 #include <linux/in6.h>
35 #include <linux/netdevice.h>
36 #include <linux/if_arp.h>
37 #include <linux/icmpv6.h>
38 #include <linux/init.h>
39 #include <linux/route.h>
40 #include <linux/rtnetlink.h>
41 #include <linux/netfilter_ipv6.h>
43 #include <asm/uaccess.h>
44 #include <asm/atomic.h>
46 #include <net/icmp.h>
47 #include <net/ip.h>
48 #include <net/ipv6.h>
49 #include <net/ip6_route.h>
50 #include <net/addrconf.h>
51 #include <net/ip6_tunnel.h>
52 #include <net/xfrm.h>
53 #include <net/dsfield.h>
54 #include <net/inet_ecn.h>
56 MODULE_AUTHOR("Ville Nuorvala");
57 MODULE_DESCRIPTION("IPv6 tunneling device");
58 MODULE_LICENSE("GPL");
60 #define IPV6_TLV_TEL_DST_SIZE 8
62 #ifdef IP6_TNL_DEBUG
63 #define IP6_TNL_TRACE(x...) printk(KERN_DEBUG "%s:" x "\n", __FUNCTION__)
64 #else
65 #define IP6_TNL_TRACE(x...) do {;} while(0)
66 #endif
68 #define IPV6_TCLASS_MASK (IPV6_FLOWINFO_MASK & ~IPV6_FLOWLABEL_MASK)
69 #define IPV6_TCLASS_SHIFT 20
71 #define HASH_SIZE 32
73 #define HASH(addr) ((__force u32)((addr)->s6_addr32[0] ^ (addr)->s6_addr32[1] ^ \
74 (addr)->s6_addr32[2] ^ (addr)->s6_addr32[3]) & \
75 (HASH_SIZE - 1))
77 static int ip6_fb_tnl_dev_init(struct net_device *dev);
78 static int ip6_tnl_dev_init(struct net_device *dev);
79 static void ip6_tnl_dev_setup(struct net_device *dev);
81 /* the IPv6 tunnel fallback device */
82 static struct net_device *ip6_fb_tnl_dev;
85 /* lists for storing tunnels in use */
86 static struct ip6_tnl *tnls_r_l[HASH_SIZE];
87 static struct ip6_tnl *tnls_wc[1];
88 static struct ip6_tnl **tnls[2] = { tnls_wc, tnls_r_l };
90 /* lock for the tunnel lists */
91 static DEFINE_RWLOCK(ip6_tnl_lock);
93 static inline struct dst_entry *ip6_tnl_dst_check(struct ip6_tnl *t)
95 struct dst_entry *dst = t->dst_cache;
97 if (dst && dst->obsolete &&
98 dst->ops->check(dst, t->dst_cookie) == NULL) {
99 t->dst_cache = NULL;
100 dst_release(dst);
101 return NULL;
104 return dst;
107 static inline void ip6_tnl_dst_reset(struct ip6_tnl *t)
109 dst_release(t->dst_cache);
110 t->dst_cache = NULL;
113 static inline void ip6_tnl_dst_store(struct ip6_tnl *t, struct dst_entry *dst)
115 struct rt6_info *rt = (struct rt6_info *) dst;
116 t->dst_cookie = rt->rt6i_node ? rt->rt6i_node->fn_sernum : 0;
117 dst_release(t->dst_cache);
118 t->dst_cache = dst;
122 * ip6_tnl_lookup - fetch tunnel matching the end-point addresses
123 * @remote: the address of the tunnel exit-point
124 * @local: the address of the tunnel entry-point
126 * Return:
127 * tunnel matching given end-points if found,
128 * else fallback tunnel if its device is up,
129 * else %NULL
132 static struct ip6_tnl *
133 ip6_tnl_lookup(struct in6_addr *remote, struct in6_addr *local)
135 unsigned h0 = HASH(remote);
136 unsigned h1 = HASH(local);
137 struct ip6_tnl *t;
139 for (t = tnls_r_l[h0 ^ h1]; t; t = t->next) {
140 if (ipv6_addr_equal(local, &t->parms.laddr) &&
141 ipv6_addr_equal(remote, &t->parms.raddr) &&
142 (t->dev->flags & IFF_UP))
143 return t;
145 if ((t = tnls_wc[0]) != NULL && (t->dev->flags & IFF_UP))
146 return t;
148 return NULL;
152 * ip6_tnl_bucket - get head of list matching given tunnel parameters
153 * @p: parameters containing tunnel end-points
155 * Description:
156 * ip6_tnl_bucket() returns the head of the list matching the
157 * &struct in6_addr entries laddr and raddr in @p.
159 * Return: head of IPv6 tunnel list
162 static struct ip6_tnl **
163 ip6_tnl_bucket(struct ip6_tnl_parm *p)
165 struct in6_addr *remote = &p->raddr;
166 struct in6_addr *local = &p->laddr;
167 unsigned h = 0;
168 int prio = 0;
170 if (!ipv6_addr_any(remote) || !ipv6_addr_any(local)) {
171 prio = 1;
172 h = HASH(remote) ^ HASH(local);
174 return &tnls[prio][h];
178 * ip6_tnl_link - add tunnel to hash table
179 * @t: tunnel to be added
182 static void
183 ip6_tnl_link(struct ip6_tnl *t)
185 struct ip6_tnl **tp = ip6_tnl_bucket(&t->parms);
187 t->next = *tp;
188 write_lock_bh(&ip6_tnl_lock);
189 *tp = t;
190 write_unlock_bh(&ip6_tnl_lock);
194 * ip6_tnl_unlink - remove tunnel from hash table
195 * @t: tunnel to be removed
198 static void
199 ip6_tnl_unlink(struct ip6_tnl *t)
201 struct ip6_tnl **tp;
203 for (tp = ip6_tnl_bucket(&t->parms); *tp; tp = &(*tp)->next) {
204 if (t == *tp) {
205 write_lock_bh(&ip6_tnl_lock);
206 *tp = t->next;
207 write_unlock_bh(&ip6_tnl_lock);
208 break;
214 * ip6_tnl_create() - create a new tunnel
215 * @p: tunnel parameters
216 * @pt: pointer to new tunnel
218 * Description:
219 * Create tunnel matching given parameters.
221 * Return:
222 * created tunnel or NULL
225 static struct ip6_tnl *ip6_tnl_create(struct ip6_tnl_parm *p)
227 struct net_device *dev;
228 struct ip6_tnl *t;
229 char name[IFNAMSIZ];
230 int err;
232 if (p->name[0]) {
233 strlcpy(name, p->name, IFNAMSIZ);
234 } else {
235 int i;
236 for (i = 1; i < IP6_TNL_MAX; i++) {
237 sprintf(name, "ip6tnl%d", i);
238 if (__dev_get_by_name(name) == NULL)
239 break;
241 if (i == IP6_TNL_MAX)
242 goto failed;
244 dev = alloc_netdev(sizeof (*t), name, ip6_tnl_dev_setup);
245 if (dev == NULL)
246 goto failed;
248 t = netdev_priv(dev);
249 dev->init = ip6_tnl_dev_init;
250 t->parms = *p;
252 if ((err = register_netdevice(dev)) < 0) {
253 free_netdev(dev);
254 goto failed;
256 dev_hold(dev);
257 ip6_tnl_link(t);
258 return t;
259 failed:
260 return NULL;
264 * ip6_tnl_locate - find or create tunnel matching given parameters
265 * @p: tunnel parameters
266 * @create: != 0 if allowed to create new tunnel if no match found
268 * Description:
269 * ip6_tnl_locate() first tries to locate an existing tunnel
270 * based on @parms. If this is unsuccessful, but @create is set a new
271 * tunnel device is created and registered for use.
273 * Return:
274 * matching tunnel or NULL
277 static struct ip6_tnl *ip6_tnl_locate(struct ip6_tnl_parm *p, int create)
279 struct in6_addr *remote = &p->raddr;
280 struct in6_addr *local = &p->laddr;
281 struct ip6_tnl *t;
283 for (t = *ip6_tnl_bucket(p); t; t = t->next) {
284 if (ipv6_addr_equal(local, &t->parms.laddr) &&
285 ipv6_addr_equal(remote, &t->parms.raddr))
286 return t;
288 if (!create)
289 return NULL;
290 return ip6_tnl_create(p);
294 * ip6_tnl_dev_uninit - tunnel device uninitializer
295 * @dev: the device to be destroyed
297 * Description:
298 * ip6_tnl_dev_uninit() removes tunnel from its list
301 static void
302 ip6_tnl_dev_uninit(struct net_device *dev)
304 struct ip6_tnl *t = netdev_priv(dev);
306 if (dev == ip6_fb_tnl_dev) {
307 write_lock_bh(&ip6_tnl_lock);
308 tnls_wc[0] = NULL;
309 write_unlock_bh(&ip6_tnl_lock);
310 } else {
311 ip6_tnl_unlink(t);
313 ip6_tnl_dst_reset(t);
314 dev_put(dev);
318 * parse_tvl_tnl_enc_lim - handle encapsulation limit option
319 * @skb: received socket buffer
321 * Return:
322 * 0 if none was found,
323 * else index to encapsulation limit
326 static __u16
327 parse_tlv_tnl_enc_lim(struct sk_buff *skb, __u8 * raw)
329 struct ipv6hdr *ipv6h = (struct ipv6hdr *) raw;
330 __u8 nexthdr = ipv6h->nexthdr;
331 __u16 off = sizeof (*ipv6h);
333 while (ipv6_ext_hdr(nexthdr) && nexthdr != NEXTHDR_NONE) {
334 __u16 optlen = 0;
335 struct ipv6_opt_hdr *hdr;
336 if (raw + off + sizeof (*hdr) > skb->data &&
337 !pskb_may_pull(skb, raw - skb->data + off + sizeof (*hdr)))
338 break;
340 hdr = (struct ipv6_opt_hdr *) (raw + off);
341 if (nexthdr == NEXTHDR_FRAGMENT) {
342 struct frag_hdr *frag_hdr = (struct frag_hdr *) hdr;
343 if (frag_hdr->frag_off)
344 break;
345 optlen = 8;
346 } else if (nexthdr == NEXTHDR_AUTH) {
347 optlen = (hdr->hdrlen + 2) << 2;
348 } else {
349 optlen = ipv6_optlen(hdr);
351 if (nexthdr == NEXTHDR_DEST) {
352 __u16 i = off + 2;
353 while (1) {
354 struct ipv6_tlv_tnl_enc_lim *tel;
356 /* No more room for encapsulation limit */
357 if (i + sizeof (*tel) > off + optlen)
358 break;
360 tel = (struct ipv6_tlv_tnl_enc_lim *) &raw[i];
361 /* return index of option if found and valid */
362 if (tel->type == IPV6_TLV_TNL_ENCAP_LIMIT &&
363 tel->length == 1)
364 return i;
365 /* else jump to next option */
366 if (tel->type)
367 i += tel->length + 2;
368 else
369 i++;
372 nexthdr = hdr->nexthdr;
373 off += optlen;
375 return 0;
379 * ip6_tnl_err - tunnel error handler
381 * Description:
382 * ip6_tnl_err() should handle errors in the tunnel according
383 * to the specifications in RFC 2473.
386 static int
387 ip6_tnl_err(struct sk_buff *skb, __u8 ipproto, struct inet6_skb_parm *opt,
388 int *type, int *code, int *msg, __be32 *info, int offset)
390 struct ipv6hdr *ipv6h = (struct ipv6hdr *) skb->data;
391 struct ip6_tnl *t;
392 int rel_msg = 0;
393 int rel_type = ICMPV6_DEST_UNREACH;
394 int rel_code = ICMPV6_ADDR_UNREACH;
395 __u32 rel_info = 0;
396 __u16 len;
397 int err = -ENOENT;
399 /* If the packet doesn't contain the original IPv6 header we are
400 in trouble since we might need the source address for further
401 processing of the error. */
403 read_lock(&ip6_tnl_lock);
404 if ((t = ip6_tnl_lookup(&ipv6h->daddr, &ipv6h->saddr)) == NULL)
405 goto out;
407 if (t->parms.proto != ipproto && t->parms.proto != 0)
408 goto out;
410 err = 0;
412 switch (*type) {
413 __u32 teli;
414 struct ipv6_tlv_tnl_enc_lim *tel;
415 __u32 mtu;
416 case ICMPV6_DEST_UNREACH:
417 if (net_ratelimit())
418 printk(KERN_WARNING
419 "%s: Path to destination invalid "
420 "or inactive!\n", t->parms.name);
421 rel_msg = 1;
422 break;
423 case ICMPV6_TIME_EXCEED:
424 if ((*code) == ICMPV6_EXC_HOPLIMIT) {
425 if (net_ratelimit())
426 printk(KERN_WARNING
427 "%s: Too small hop limit or "
428 "routing loop in tunnel!\n",
429 t->parms.name);
430 rel_msg = 1;
432 break;
433 case ICMPV6_PARAMPROB:
434 teli = 0;
435 if ((*code) == ICMPV6_HDR_FIELD)
436 teli = parse_tlv_tnl_enc_lim(skb, skb->data);
438 if (teli && teli == ntohl(*info) - 2) {
439 tel = (struct ipv6_tlv_tnl_enc_lim *) &skb->data[teli];
440 if (tel->encap_limit == 0) {
441 if (net_ratelimit())
442 printk(KERN_WARNING
443 "%s: Too small encapsulation "
444 "limit or routing loop in "
445 "tunnel!\n", t->parms.name);
446 rel_msg = 1;
448 } else if (net_ratelimit()) {
449 printk(KERN_WARNING
450 "%s: Recipient unable to parse tunneled "
451 "packet!\n ", t->parms.name);
453 break;
454 case ICMPV6_PKT_TOOBIG:
455 mtu = ntohl(*info) - offset;
456 if (mtu < IPV6_MIN_MTU)
457 mtu = IPV6_MIN_MTU;
458 t->dev->mtu = mtu;
460 if ((len = sizeof (*ipv6h) + ntohs(ipv6h->payload_len)) > mtu) {
461 rel_type = ICMPV6_PKT_TOOBIG;
462 rel_code = 0;
463 rel_info = mtu;
464 rel_msg = 1;
466 break;
469 *type = rel_type;
470 *code = rel_code;
471 *info = rel_info;
472 *msg = rel_msg;
474 out:
475 read_unlock(&ip6_tnl_lock);
476 return err;
479 static int
480 ip4ip6_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
481 int type, int code, int offset, __u32 info)
483 int rel_msg = 0;
484 int rel_type = type;
485 int rel_code = code;
486 __u32 rel_info = info;
487 int err;
488 struct sk_buff *skb2;
489 struct iphdr *eiph;
490 struct flowi fl;
491 struct rtable *rt;
493 err = ip6_tnl_err(skb, IPPROTO_IPIP, opt, &rel_type, &rel_code,
494 &rel_msg, &rel_info, offset);
495 if (err < 0)
496 return err;
498 if (rel_msg == 0)
499 return 0;
501 switch (rel_type) {
502 case ICMPV6_DEST_UNREACH:
503 if (rel_code != ICMPV6_ADDR_UNREACH)
504 return 0;
505 rel_type = ICMP_DEST_UNREACH;
506 rel_code = ICMP_HOST_UNREACH;
507 break;
508 case ICMPV6_PKT_TOOBIG:
509 if (rel_code != 0)
510 return 0;
511 rel_type = ICMP_DEST_UNREACH;
512 rel_code = ICMP_FRAG_NEEDED;
513 break;
514 default:
515 return 0;
518 if (!pskb_may_pull(skb, offset + sizeof(struct iphdr)))
519 return 0;
521 skb2 = skb_clone(skb, GFP_ATOMIC);
522 if (!skb2)
523 return 0;
525 dst_release(skb2->dst);
526 skb2->dst = NULL;
527 skb_pull(skb2, offset);
528 skb_reset_network_header(skb2);
529 eiph = skb2->nh.iph;
531 /* Try to guess incoming interface */
532 memset(&fl, 0, sizeof(fl));
533 fl.fl4_dst = eiph->saddr;
534 fl.fl4_tos = RT_TOS(eiph->tos);
535 fl.proto = IPPROTO_IPIP;
536 if (ip_route_output_key(&rt, &fl))
537 goto out;
539 skb2->dev = rt->u.dst.dev;
541 /* route "incoming" packet */
542 if (rt->rt_flags & RTCF_LOCAL) {
543 ip_rt_put(rt);
544 rt = NULL;
545 fl.fl4_dst = eiph->daddr;
546 fl.fl4_src = eiph->saddr;
547 fl.fl4_tos = eiph->tos;
548 if (ip_route_output_key(&rt, &fl) ||
549 rt->u.dst.dev->type != ARPHRD_TUNNEL) {
550 ip_rt_put(rt);
551 goto out;
553 } else {
554 ip_rt_put(rt);
555 if (ip_route_input(skb2, eiph->daddr, eiph->saddr, eiph->tos,
556 skb2->dev) ||
557 skb2->dst->dev->type != ARPHRD_TUNNEL)
558 goto out;
561 /* change mtu on this route */
562 if (rel_type == ICMP_DEST_UNREACH && rel_code == ICMP_FRAG_NEEDED) {
563 if (rel_info > dst_mtu(skb2->dst))
564 goto out;
566 skb2->dst->ops->update_pmtu(skb2->dst, rel_info);
567 rel_info = htonl(rel_info);
570 icmp_send(skb2, rel_type, rel_code, rel_info);
572 out:
573 kfree_skb(skb2);
574 return 0;
577 static int
578 ip6ip6_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
579 int type, int code, int offset, __u32 info)
581 int rel_msg = 0;
582 int rel_type = type;
583 int rel_code = code;
584 __u32 rel_info = info;
585 int err;
587 err = ip6_tnl_err(skb, IPPROTO_IPV6, opt, &rel_type, &rel_code,
588 &rel_msg, &rel_info, offset);
589 if (err < 0)
590 return err;
592 if (rel_msg && pskb_may_pull(skb, offset + sizeof(struct ipv6hdr))) {
593 struct rt6_info *rt;
594 struct sk_buff *skb2 = skb_clone(skb, GFP_ATOMIC);
596 if (!skb2)
597 return 0;
599 dst_release(skb2->dst);
600 skb2->dst = NULL;
601 skb_pull(skb2, offset);
602 skb_reset_network_header(skb2);
604 /* Try to guess incoming interface */
605 rt = rt6_lookup(&skb2->nh.ipv6h->saddr, NULL, 0, 0);
607 if (rt && rt->rt6i_dev)
608 skb2->dev = rt->rt6i_dev;
610 icmpv6_send(skb2, rel_type, rel_code, rel_info, skb2->dev);
612 if (rt)
613 dst_release(&rt->u.dst);
615 kfree_skb(skb2);
618 return 0;
621 static void ip4ip6_dscp_ecn_decapsulate(struct ip6_tnl *t,
622 struct ipv6hdr *ipv6h,
623 struct sk_buff *skb)
625 __u8 dsfield = ipv6_get_dsfield(ipv6h) & ~INET_ECN_MASK;
627 if (t->parms.flags & IP6_TNL_F_RCV_DSCP_COPY)
628 ipv4_change_dsfield(skb->nh.iph, INET_ECN_MASK, dsfield);
630 if (INET_ECN_is_ce(dsfield))
631 IP_ECN_set_ce(skb->nh.iph);
634 static void ip6ip6_dscp_ecn_decapsulate(struct ip6_tnl *t,
635 struct ipv6hdr *ipv6h,
636 struct sk_buff *skb)
638 if (t->parms.flags & IP6_TNL_F_RCV_DSCP_COPY)
639 ipv6_copy_dscp(ipv6h, skb->nh.ipv6h);
641 if (INET_ECN_is_ce(ipv6_get_dsfield(ipv6h)))
642 IP6_ECN_set_ce(skb->nh.ipv6h);
645 static inline int ip6_tnl_rcv_ctl(struct ip6_tnl *t)
647 struct ip6_tnl_parm *p = &t->parms;
648 int ret = 0;
650 if (p->flags & IP6_TNL_F_CAP_RCV) {
651 struct net_device *ldev = NULL;
653 if (p->link)
654 ldev = dev_get_by_index(p->link);
656 if ((ipv6_addr_is_multicast(&p->laddr) ||
657 likely(ipv6_chk_addr(&p->laddr, ldev, 0))) &&
658 likely(!ipv6_chk_addr(&p->raddr, NULL, 0)))
659 ret = 1;
661 if (ldev)
662 dev_put(ldev);
664 return ret;
668 * ip6_tnl_rcv - decapsulate IPv6 packet and retransmit it locally
669 * @skb: received socket buffer
670 * @protocol: ethernet protocol ID
671 * @dscp_ecn_decapsulate: the function to decapsulate DSCP code and ECN
673 * Return: 0
676 static int ip6_tnl_rcv(struct sk_buff *skb, __u16 protocol,
677 __u8 ipproto,
678 void (*dscp_ecn_decapsulate)(struct ip6_tnl *t,
679 struct ipv6hdr *ipv6h,
680 struct sk_buff *skb))
682 struct ipv6hdr *ipv6h;
683 struct ip6_tnl *t;
685 ipv6h = skb->nh.ipv6h;
687 read_lock(&ip6_tnl_lock);
689 if ((t = ip6_tnl_lookup(&ipv6h->saddr, &ipv6h->daddr)) != NULL) {
690 if (t->parms.proto != ipproto && t->parms.proto != 0) {
691 read_unlock(&ip6_tnl_lock);
692 goto discard;
695 if (!xfrm6_policy_check(NULL, XFRM_POLICY_IN, skb)) {
696 read_unlock(&ip6_tnl_lock);
697 goto discard;
700 if (!ip6_tnl_rcv_ctl(t)) {
701 t->stat.rx_dropped++;
702 read_unlock(&ip6_tnl_lock);
703 goto discard;
705 secpath_reset(skb);
706 skb->mac.raw = skb->nh.raw;
707 skb_reset_network_header(skb);
708 skb->protocol = htons(protocol);
709 skb->pkt_type = PACKET_HOST;
710 memset(skb->cb, 0, sizeof(struct inet6_skb_parm));
711 skb->dev = t->dev;
712 dst_release(skb->dst);
713 skb->dst = NULL;
714 nf_reset(skb);
716 dscp_ecn_decapsulate(t, ipv6h, skb);
718 t->stat.rx_packets++;
719 t->stat.rx_bytes += skb->len;
720 netif_rx(skb);
721 read_unlock(&ip6_tnl_lock);
722 return 0;
724 read_unlock(&ip6_tnl_lock);
725 return 1;
727 discard:
728 kfree_skb(skb);
729 return 0;
732 static int ip4ip6_rcv(struct sk_buff *skb)
734 return ip6_tnl_rcv(skb, ETH_P_IP, IPPROTO_IPIP,
735 ip4ip6_dscp_ecn_decapsulate);
738 static int ip6ip6_rcv(struct sk_buff *skb)
740 return ip6_tnl_rcv(skb, ETH_P_IPV6, IPPROTO_IPV6,
741 ip6ip6_dscp_ecn_decapsulate);
744 struct ipv6_tel_txoption {
745 struct ipv6_txoptions ops;
746 __u8 dst_opt[8];
749 static void init_tel_txopt(struct ipv6_tel_txoption *opt, __u8 encap_limit)
751 memset(opt, 0, sizeof(struct ipv6_tel_txoption));
753 opt->dst_opt[2] = IPV6_TLV_TNL_ENCAP_LIMIT;
754 opt->dst_opt[3] = 1;
755 opt->dst_opt[4] = encap_limit;
756 opt->dst_opt[5] = IPV6_TLV_PADN;
757 opt->dst_opt[6] = 1;
759 opt->ops.dst0opt = (struct ipv6_opt_hdr *) opt->dst_opt;
760 opt->ops.opt_nflen = 8;
764 * ip6_tnl_addr_conflict - compare packet addresses to tunnel's own
765 * @t: the outgoing tunnel device
766 * @hdr: IPv6 header from the incoming packet
768 * Description:
769 * Avoid trivial tunneling loop by checking that tunnel exit-point
770 * doesn't match source of incoming packet.
772 * Return:
773 * 1 if conflict,
774 * 0 else
777 static inline int
778 ip6_tnl_addr_conflict(struct ip6_tnl *t, struct ipv6hdr *hdr)
780 return ipv6_addr_equal(&t->parms.raddr, &hdr->saddr);
783 static inline int ip6_tnl_xmit_ctl(struct ip6_tnl *t)
785 struct ip6_tnl_parm *p = &t->parms;
786 int ret = 0;
788 if (p->flags & IP6_TNL_F_CAP_XMIT) {
789 struct net_device *ldev = NULL;
791 if (p->link)
792 ldev = dev_get_by_index(p->link);
794 if (unlikely(!ipv6_chk_addr(&p->laddr, ldev, 0)))
795 printk(KERN_WARNING
796 "%s xmit: Local address not yet configured!\n",
797 p->name);
798 else if (!ipv6_addr_is_multicast(&p->raddr) &&
799 unlikely(ipv6_chk_addr(&p->raddr, NULL, 0)))
800 printk(KERN_WARNING
801 "%s xmit: Routing loop! "
802 "Remote address found on this node!\n",
803 p->name);
804 else
805 ret = 1;
806 if (ldev)
807 dev_put(ldev);
809 return ret;
812 * ip6_tnl_xmit2 - encapsulate packet and send
813 * @skb: the outgoing socket buffer
814 * @dev: the outgoing tunnel device
815 * @dsfield: dscp code for outer header
816 * @fl: flow of tunneled packet
817 * @encap_limit: encapsulation limit
818 * @pmtu: Path MTU is stored if packet is too big
820 * Description:
821 * Build new header and do some sanity checks on the packet before sending
822 * it.
824 * Return:
825 * 0 on success
826 * -1 fail
827 * %-EMSGSIZE message too big. return mtu in this case.
830 static int ip6_tnl_xmit2(struct sk_buff *skb,
831 struct net_device *dev,
832 __u8 dsfield,
833 struct flowi *fl,
834 int encap_limit,
835 __u32 *pmtu)
837 struct ip6_tnl *t = netdev_priv(dev);
838 struct net_device_stats *stats = &t->stat;
839 struct ipv6hdr *ipv6h = skb->nh.ipv6h;
840 struct ipv6_tel_txoption opt;
841 struct dst_entry *dst;
842 struct net_device *tdev;
843 int mtu;
844 int max_headroom = sizeof(struct ipv6hdr);
845 u8 proto;
846 int err = -1;
847 int pkt_len;
849 if ((dst = ip6_tnl_dst_check(t)) != NULL)
850 dst_hold(dst);
851 else {
852 dst = ip6_route_output(NULL, fl);
854 if (dst->error || xfrm_lookup(&dst, fl, NULL, 0) < 0)
855 goto tx_err_link_failure;
858 tdev = dst->dev;
860 if (tdev == dev) {
861 stats->collisions++;
862 if (net_ratelimit())
863 printk(KERN_WARNING
864 "%s: Local routing loop detected!\n",
865 t->parms.name);
866 goto tx_err_dst_release;
868 mtu = dst_mtu(dst) - sizeof (*ipv6h);
869 if (encap_limit >= 0) {
870 max_headroom += 8;
871 mtu -= 8;
873 if (mtu < IPV6_MIN_MTU)
874 mtu = IPV6_MIN_MTU;
875 if (skb->dst)
876 skb->dst->ops->update_pmtu(skb->dst, mtu);
877 if (skb->len > mtu) {
878 *pmtu = mtu;
879 err = -EMSGSIZE;
880 goto tx_err_dst_release;
884 * Okay, now see if we can stuff it in the buffer as-is.
886 max_headroom += LL_RESERVED_SPACE(tdev);
888 if (skb_headroom(skb) < max_headroom ||
889 skb_cloned(skb) || skb_shared(skb)) {
890 struct sk_buff *new_skb;
892 if (!(new_skb = skb_realloc_headroom(skb, max_headroom)))
893 goto tx_err_dst_release;
895 if (skb->sk)
896 skb_set_owner_w(new_skb, skb->sk);
897 kfree_skb(skb);
898 skb = new_skb;
900 dst_release(skb->dst);
901 skb->dst = dst_clone(dst);
903 skb->h.raw = skb->nh.raw;
905 proto = fl->proto;
906 if (encap_limit >= 0) {
907 init_tel_txopt(&opt, encap_limit);
908 ipv6_push_nfrag_opts(skb, &opt.ops, &proto, NULL);
910 skb_push(skb, sizeof(struct ipv6hdr));
911 skb_reset_network_header(skb);
912 ipv6h = skb->nh.ipv6h;
913 *(__be32*)ipv6h = fl->fl6_flowlabel | htonl(0x60000000);
914 dsfield = INET_ECN_encapsulate(0, dsfield);
915 ipv6_change_dsfield(ipv6h, ~INET_ECN_MASK, dsfield);
916 ipv6h->payload_len = htons(skb->len - sizeof(struct ipv6hdr));
917 ipv6h->hop_limit = t->parms.hop_limit;
918 ipv6h->nexthdr = proto;
919 ipv6_addr_copy(&ipv6h->saddr, &fl->fl6_src);
920 ipv6_addr_copy(&ipv6h->daddr, &fl->fl6_dst);
921 nf_reset(skb);
922 pkt_len = skb->len;
923 err = NF_HOOK(PF_INET6, NF_IP6_LOCAL_OUT, skb, NULL,
924 skb->dst->dev, dst_output);
926 if (net_xmit_eval(err) == 0) {
927 stats->tx_bytes += pkt_len;
928 stats->tx_packets++;
929 } else {
930 stats->tx_errors++;
931 stats->tx_aborted_errors++;
933 ip6_tnl_dst_store(t, dst);
934 return 0;
935 tx_err_link_failure:
936 stats->tx_carrier_errors++;
937 dst_link_failure(skb);
938 tx_err_dst_release:
939 dst_release(dst);
940 return err;
943 static inline int
944 ip4ip6_tnl_xmit(struct sk_buff *skb, struct net_device *dev)
946 struct ip6_tnl *t = netdev_priv(dev);
947 struct iphdr *iph = skb->nh.iph;
948 int encap_limit = -1;
949 struct flowi fl;
950 __u8 dsfield;
951 __u32 mtu;
952 int err;
954 if ((t->parms.proto != IPPROTO_IPIP && t->parms.proto != 0) ||
955 !ip6_tnl_xmit_ctl(t))
956 return -1;
958 if (!(t->parms.flags & IP6_TNL_F_IGN_ENCAP_LIMIT))
959 encap_limit = t->parms.encap_limit;
961 memcpy(&fl, &t->fl, sizeof (fl));
962 fl.proto = IPPROTO_IPIP;
964 dsfield = ipv4_get_dsfield(iph);
966 if ((t->parms.flags & IP6_TNL_F_USE_ORIG_TCLASS))
967 fl.fl6_flowlabel |= ntohl(((__u32)iph->tos << IPV6_TCLASS_SHIFT)
968 & IPV6_TCLASS_MASK);
970 err = ip6_tnl_xmit2(skb, dev, dsfield, &fl, encap_limit, &mtu);
971 if (err != 0) {
972 /* XXX: send ICMP error even if DF is not set. */
973 if (err == -EMSGSIZE)
974 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_FRAG_NEEDED,
975 htonl(mtu));
976 return -1;
979 return 0;
982 static inline int
983 ip6ip6_tnl_xmit(struct sk_buff *skb, struct net_device *dev)
985 struct ip6_tnl *t = netdev_priv(dev);
986 struct ipv6hdr *ipv6h = skb->nh.ipv6h;
987 int encap_limit = -1;
988 __u16 offset;
989 struct flowi fl;
990 __u8 dsfield;
991 __u32 mtu;
992 int err;
994 if ((t->parms.proto != IPPROTO_IPV6 && t->parms.proto != 0) ||
995 !ip6_tnl_xmit_ctl(t) || ip6_tnl_addr_conflict(t, ipv6h))
996 return -1;
998 if ((offset = parse_tlv_tnl_enc_lim(skb, skb->nh.raw)) > 0) {
999 struct ipv6_tlv_tnl_enc_lim *tel;
1000 tel = (struct ipv6_tlv_tnl_enc_lim *) &skb->nh.raw[offset];
1001 if (tel->encap_limit == 0) {
1002 icmpv6_send(skb, ICMPV6_PARAMPROB,
1003 ICMPV6_HDR_FIELD, offset + 2, skb->dev);
1004 return -1;
1006 encap_limit = tel->encap_limit - 1;
1007 } else if (!(t->parms.flags & IP6_TNL_F_IGN_ENCAP_LIMIT))
1008 encap_limit = t->parms.encap_limit;
1010 memcpy(&fl, &t->fl, sizeof (fl));
1011 fl.proto = IPPROTO_IPV6;
1013 dsfield = ipv6_get_dsfield(ipv6h);
1014 if ((t->parms.flags & IP6_TNL_F_USE_ORIG_TCLASS))
1015 fl.fl6_flowlabel |= (*(__be32 *) ipv6h & IPV6_TCLASS_MASK);
1016 if ((t->parms.flags & IP6_TNL_F_USE_ORIG_FLOWLABEL))
1017 fl.fl6_flowlabel |= (*(__be32 *) ipv6h & IPV6_FLOWLABEL_MASK);
1019 err = ip6_tnl_xmit2(skb, dev, dsfield, &fl, encap_limit, &mtu);
1020 if (err != 0) {
1021 if (err == -EMSGSIZE)
1022 icmpv6_send(skb, ICMPV6_PKT_TOOBIG, 0, mtu, dev);
1023 return -1;
1026 return 0;
1029 static int
1030 ip6_tnl_xmit(struct sk_buff *skb, struct net_device *dev)
1032 struct ip6_tnl *t = netdev_priv(dev);
1033 struct net_device_stats *stats = &t->stat;
1034 int ret;
1036 if (t->recursion++) {
1037 t->stat.collisions++;
1038 goto tx_err;
1041 switch (skb->protocol) {
1042 case __constant_htons(ETH_P_IP):
1043 ret = ip4ip6_tnl_xmit(skb, dev);
1044 break;
1045 case __constant_htons(ETH_P_IPV6):
1046 ret = ip6ip6_tnl_xmit(skb, dev);
1047 break;
1048 default:
1049 goto tx_err;
1052 if (ret < 0)
1053 goto tx_err;
1055 t->recursion--;
1056 return 0;
1058 tx_err:
1059 stats->tx_errors++;
1060 stats->tx_dropped++;
1061 kfree_skb(skb);
1062 t->recursion--;
1063 return 0;
1066 static void ip6_tnl_set_cap(struct ip6_tnl *t)
1068 struct ip6_tnl_parm *p = &t->parms;
1069 int ltype = ipv6_addr_type(&p->laddr);
1070 int rtype = ipv6_addr_type(&p->raddr);
1072 p->flags &= ~(IP6_TNL_F_CAP_XMIT|IP6_TNL_F_CAP_RCV);
1074 if (ltype & (IPV6_ADDR_UNICAST|IPV6_ADDR_MULTICAST) &&
1075 rtype & (IPV6_ADDR_UNICAST|IPV6_ADDR_MULTICAST) &&
1076 !((ltype|rtype) & IPV6_ADDR_LOOPBACK) &&
1077 (!((ltype|rtype) & IPV6_ADDR_LINKLOCAL) || p->link)) {
1078 if (ltype&IPV6_ADDR_UNICAST)
1079 p->flags |= IP6_TNL_F_CAP_XMIT;
1080 if (rtype&IPV6_ADDR_UNICAST)
1081 p->flags |= IP6_TNL_F_CAP_RCV;
1085 static void ip6_tnl_link_config(struct ip6_tnl *t)
1087 struct net_device *dev = t->dev;
1088 struct ip6_tnl_parm *p = &t->parms;
1089 struct flowi *fl = &t->fl;
1091 memcpy(&dev->dev_addr, &p->laddr, sizeof(struct in6_addr));
1092 memcpy(&dev->broadcast, &p->raddr, sizeof(struct in6_addr));
1094 /* Set up flowi template */
1095 ipv6_addr_copy(&fl->fl6_src, &p->laddr);
1096 ipv6_addr_copy(&fl->fl6_dst, &p->raddr);
1097 fl->oif = p->link;
1098 fl->fl6_flowlabel = 0;
1100 if (!(p->flags&IP6_TNL_F_USE_ORIG_TCLASS))
1101 fl->fl6_flowlabel |= IPV6_TCLASS_MASK & p->flowinfo;
1102 if (!(p->flags&IP6_TNL_F_USE_ORIG_FLOWLABEL))
1103 fl->fl6_flowlabel |= IPV6_FLOWLABEL_MASK & p->flowinfo;
1105 ip6_tnl_set_cap(t);
1107 if (p->flags&IP6_TNL_F_CAP_XMIT && p->flags&IP6_TNL_F_CAP_RCV)
1108 dev->flags |= IFF_POINTOPOINT;
1109 else
1110 dev->flags &= ~IFF_POINTOPOINT;
1112 dev->iflink = p->link;
1114 if (p->flags & IP6_TNL_F_CAP_XMIT) {
1115 int strict = (ipv6_addr_type(&p->raddr) &
1116 (IPV6_ADDR_MULTICAST|IPV6_ADDR_LINKLOCAL));
1118 struct rt6_info *rt = rt6_lookup(&p->raddr, &p->laddr,
1119 p->link, strict);
1121 if (rt == NULL)
1122 return;
1124 if (rt->rt6i_dev) {
1125 dev->hard_header_len = rt->rt6i_dev->hard_header_len +
1126 sizeof (struct ipv6hdr);
1128 dev->mtu = rt->rt6i_dev->mtu - sizeof (struct ipv6hdr);
1130 if (dev->mtu < IPV6_MIN_MTU)
1131 dev->mtu = IPV6_MIN_MTU;
1133 dst_release(&rt->u.dst);
1138 * ip6_tnl_change - update the tunnel parameters
1139 * @t: tunnel to be changed
1140 * @p: tunnel configuration parameters
1141 * @active: != 0 if tunnel is ready for use
1143 * Description:
1144 * ip6_tnl_change() updates the tunnel parameters
1147 static int
1148 ip6_tnl_change(struct ip6_tnl *t, struct ip6_tnl_parm *p)
1150 ipv6_addr_copy(&t->parms.laddr, &p->laddr);
1151 ipv6_addr_copy(&t->parms.raddr, &p->raddr);
1152 t->parms.flags = p->flags;
1153 t->parms.hop_limit = p->hop_limit;
1154 t->parms.encap_limit = p->encap_limit;
1155 t->parms.flowinfo = p->flowinfo;
1156 t->parms.link = p->link;
1157 t->parms.proto = p->proto;
1158 ip6_tnl_dst_reset(t);
1159 ip6_tnl_link_config(t);
1160 return 0;
1164 * ip6_tnl_ioctl - configure ipv6 tunnels from userspace
1165 * @dev: virtual device associated with tunnel
1166 * @ifr: parameters passed from userspace
1167 * @cmd: command to be performed
1169 * Description:
1170 * ip6_tnl_ioctl() is used for managing IPv6 tunnels
1171 * from userspace.
1173 * The possible commands are the following:
1174 * %SIOCGETTUNNEL: get tunnel parameters for device
1175 * %SIOCADDTUNNEL: add tunnel matching given tunnel parameters
1176 * %SIOCCHGTUNNEL: change tunnel parameters to those given
1177 * %SIOCDELTUNNEL: delete tunnel
1179 * The fallback device "ip6tnl0", created during module
1180 * initialization, can be used for creating other tunnel devices.
1182 * Return:
1183 * 0 on success,
1184 * %-EFAULT if unable to copy data to or from userspace,
1185 * %-EPERM if current process hasn't %CAP_NET_ADMIN set
1186 * %-EINVAL if passed tunnel parameters are invalid,
1187 * %-EEXIST if changing a tunnel's parameters would cause a conflict
1188 * %-ENODEV if attempting to change or delete a nonexisting device
1191 static int
1192 ip6_tnl_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
1194 int err = 0;
1195 struct ip6_tnl_parm p;
1196 struct ip6_tnl *t = NULL;
1198 switch (cmd) {
1199 case SIOCGETTUNNEL:
1200 if (dev == ip6_fb_tnl_dev) {
1201 if (copy_from_user(&p, ifr->ifr_ifru.ifru_data, sizeof (p))) {
1202 err = -EFAULT;
1203 break;
1205 t = ip6_tnl_locate(&p, 0);
1207 if (t == NULL)
1208 t = netdev_priv(dev);
1209 memcpy(&p, &t->parms, sizeof (p));
1210 if (copy_to_user(ifr->ifr_ifru.ifru_data, &p, sizeof (p))) {
1211 err = -EFAULT;
1213 break;
1214 case SIOCADDTUNNEL:
1215 case SIOCCHGTUNNEL:
1216 err = -EPERM;
1217 if (!capable(CAP_NET_ADMIN))
1218 break;
1219 err = -EFAULT;
1220 if (copy_from_user(&p, ifr->ifr_ifru.ifru_data, sizeof (p)))
1221 break;
1222 err = -EINVAL;
1223 if (p.proto != IPPROTO_IPV6 && p.proto != IPPROTO_IPIP &&
1224 p.proto != 0)
1225 break;
1226 t = ip6_tnl_locate(&p, cmd == SIOCADDTUNNEL);
1227 if (dev != ip6_fb_tnl_dev && cmd == SIOCCHGTUNNEL) {
1228 if (t != NULL) {
1229 if (t->dev != dev) {
1230 err = -EEXIST;
1231 break;
1233 } else
1234 t = netdev_priv(dev);
1236 ip6_tnl_unlink(t);
1237 err = ip6_tnl_change(t, &p);
1238 ip6_tnl_link(t);
1239 netdev_state_change(dev);
1241 if (t) {
1242 err = 0;
1243 if (copy_to_user(ifr->ifr_ifru.ifru_data, &t->parms, sizeof (p)))
1244 err = -EFAULT;
1246 } else
1247 err = (cmd == SIOCADDTUNNEL ? -ENOBUFS : -ENOENT);
1248 break;
1249 case SIOCDELTUNNEL:
1250 err = -EPERM;
1251 if (!capable(CAP_NET_ADMIN))
1252 break;
1254 if (dev == ip6_fb_tnl_dev) {
1255 err = -EFAULT;
1256 if (copy_from_user(&p, ifr->ifr_ifru.ifru_data, sizeof (p)))
1257 break;
1258 err = -ENOENT;
1259 if ((t = ip6_tnl_locate(&p, 0)) == NULL)
1260 break;
1261 err = -EPERM;
1262 if (t->dev == ip6_fb_tnl_dev)
1263 break;
1264 dev = t->dev;
1266 err = 0;
1267 unregister_netdevice(dev);
1268 break;
1269 default:
1270 err = -EINVAL;
1272 return err;
1276 * ip6_tnl_get_stats - return the stats for tunnel device
1277 * @dev: virtual device associated with tunnel
1279 * Return: stats for device
1282 static struct net_device_stats *
1283 ip6_tnl_get_stats(struct net_device *dev)
1285 return &(((struct ip6_tnl *)netdev_priv(dev))->stat);
1289 * ip6_tnl_change_mtu - change mtu manually for tunnel device
1290 * @dev: virtual device associated with tunnel
1291 * @new_mtu: the new mtu
1293 * Return:
1294 * 0 on success,
1295 * %-EINVAL if mtu too small
1298 static int
1299 ip6_tnl_change_mtu(struct net_device *dev, int new_mtu)
1301 if (new_mtu < IPV6_MIN_MTU) {
1302 return -EINVAL;
1304 dev->mtu = new_mtu;
1305 return 0;
1309 * ip6_tnl_dev_setup - setup virtual tunnel device
1310 * @dev: virtual device associated with tunnel
1312 * Description:
1313 * Initialize function pointers and device parameters
1316 static void ip6_tnl_dev_setup(struct net_device *dev)
1318 SET_MODULE_OWNER(dev);
1319 dev->uninit = ip6_tnl_dev_uninit;
1320 dev->destructor = free_netdev;
1321 dev->hard_start_xmit = ip6_tnl_xmit;
1322 dev->get_stats = ip6_tnl_get_stats;
1323 dev->do_ioctl = ip6_tnl_ioctl;
1324 dev->change_mtu = ip6_tnl_change_mtu;
1326 dev->type = ARPHRD_TUNNEL6;
1327 dev->hard_header_len = LL_MAX_HEADER + sizeof (struct ipv6hdr);
1328 dev->mtu = ETH_DATA_LEN - sizeof (struct ipv6hdr);
1329 dev->flags |= IFF_NOARP;
1330 dev->addr_len = sizeof(struct in6_addr);
1335 * ip6_tnl_dev_init_gen - general initializer for all tunnel devices
1336 * @dev: virtual device associated with tunnel
1339 static inline void
1340 ip6_tnl_dev_init_gen(struct net_device *dev)
1342 struct ip6_tnl *t = netdev_priv(dev);
1343 t->dev = dev;
1344 strcpy(t->parms.name, dev->name);
1348 * ip6_tnl_dev_init - initializer for all non fallback tunnel devices
1349 * @dev: virtual device associated with tunnel
1352 static int
1353 ip6_tnl_dev_init(struct net_device *dev)
1355 struct ip6_tnl *t = netdev_priv(dev);
1356 ip6_tnl_dev_init_gen(dev);
1357 ip6_tnl_link_config(t);
1358 return 0;
1362 * ip6_fb_tnl_dev_init - initializer for fallback tunnel device
1363 * @dev: fallback device
1365 * Return: 0
1368 static int
1369 ip6_fb_tnl_dev_init(struct net_device *dev)
1371 struct ip6_tnl *t = netdev_priv(dev);
1372 ip6_tnl_dev_init_gen(dev);
1373 t->parms.proto = IPPROTO_IPV6;
1374 dev_hold(dev);
1375 tnls_wc[0] = t;
1376 return 0;
1379 static struct xfrm6_tunnel ip4ip6_handler = {
1380 .handler = ip4ip6_rcv,
1381 .err_handler = ip4ip6_err,
1382 .priority = 1,
1385 static struct xfrm6_tunnel ip6ip6_handler = {
1386 .handler = ip6ip6_rcv,
1387 .err_handler = ip6ip6_err,
1388 .priority = 1,
1392 * ip6_tunnel_init - register protocol and reserve needed resources
1394 * Return: 0 on success
1397 static int __init ip6_tunnel_init(void)
1399 int err;
1401 if (xfrm6_tunnel_register(&ip4ip6_handler, AF_INET)) {
1402 printk(KERN_ERR "ip6_tunnel init: can't register ip4ip6\n");
1403 err = -EAGAIN;
1404 goto out;
1407 if (xfrm6_tunnel_register(&ip6ip6_handler, AF_INET6)) {
1408 printk(KERN_ERR "ip6_tunnel init: can't register ip6ip6\n");
1409 err = -EAGAIN;
1410 goto unreg_ip4ip6;
1412 ip6_fb_tnl_dev = alloc_netdev(sizeof(struct ip6_tnl), "ip6tnl0",
1413 ip6_tnl_dev_setup);
1415 if (!ip6_fb_tnl_dev) {
1416 err = -ENOMEM;
1417 goto fail;
1419 ip6_fb_tnl_dev->init = ip6_fb_tnl_dev_init;
1421 if ((err = register_netdev(ip6_fb_tnl_dev))) {
1422 free_netdev(ip6_fb_tnl_dev);
1423 goto fail;
1425 return 0;
1426 fail:
1427 xfrm6_tunnel_deregister(&ip6ip6_handler, AF_INET6);
1428 unreg_ip4ip6:
1429 xfrm6_tunnel_deregister(&ip4ip6_handler, AF_INET);
1430 out:
1431 return err;
1434 static void __exit ip6_tnl_destroy_tunnels(void)
1436 int h;
1437 struct ip6_tnl *t;
1439 for (h = 0; h < HASH_SIZE; h++) {
1440 while ((t = tnls_r_l[h]) != NULL)
1441 unregister_netdevice(t->dev);
1444 t = tnls_wc[0];
1445 unregister_netdevice(t->dev);
1449 * ip6_tunnel_cleanup - free resources and unregister protocol
1452 static void __exit ip6_tunnel_cleanup(void)
1454 if (xfrm6_tunnel_deregister(&ip4ip6_handler, AF_INET))
1455 printk(KERN_INFO "ip6_tunnel close: can't deregister ip4ip6\n");
1457 if (xfrm6_tunnel_deregister(&ip6ip6_handler, AF_INET6))
1458 printk(KERN_INFO "ip6_tunnel close: can't deregister ip6ip6\n");
1460 rtnl_lock();
1461 ip6_tnl_destroy_tunnels();
1462 rtnl_unlock();
1465 module_init(ip6_tunnel_init);
1466 module_exit(ip6_tunnel_cleanup);