[ARM] 4134/1: Add generic support for outer caches
[linux-2.6/linux-2.6-openrd.git] / net / ipv6 / tunnel6.c
blob918d07dd12197f7da36820cd8010e0192a1cb4a4
1 /*
2 * Copyright (C)2003,2004 USAGI/WIDE Project
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 * Authors Mitsuru KANDA <mk@linux-ipv6.org>
19 * YOSHIFUJI Hideaki <yoshfuji@linux-ipv6.org>
22 #include <linux/icmpv6.h>
23 #include <linux/init.h>
24 #include <linux/module.h>
25 #include <linux/mutex.h>
26 #include <linux/netdevice.h>
27 #include <linux/skbuff.h>
28 #include <net/ipv6.h>
29 #include <net/protocol.h>
30 #include <net/xfrm.h>
32 static struct xfrm6_tunnel *tunnel6_handlers;
33 static DEFINE_MUTEX(tunnel6_mutex);
35 int xfrm6_tunnel_register(struct xfrm6_tunnel *handler)
37 struct xfrm6_tunnel **pprev;
38 int ret = -EEXIST;
39 int priority = handler->priority;
41 mutex_lock(&tunnel6_mutex);
43 for (pprev = &tunnel6_handlers; *pprev; pprev = &(*pprev)->next) {
44 if ((*pprev)->priority > priority)
45 break;
46 if ((*pprev)->priority == priority)
47 goto err;
50 handler->next = *pprev;
51 *pprev = handler;
53 ret = 0;
55 err:
56 mutex_unlock(&tunnel6_mutex);
58 return ret;
61 EXPORT_SYMBOL(xfrm6_tunnel_register);
63 int xfrm6_tunnel_deregister(struct xfrm6_tunnel *handler)
65 struct xfrm6_tunnel **pprev;
66 int ret = -ENOENT;
68 mutex_lock(&tunnel6_mutex);
70 for (pprev = &tunnel6_handlers; *pprev; pprev = &(*pprev)->next) {
71 if (*pprev == handler) {
72 *pprev = handler->next;
73 ret = 0;
74 break;
78 mutex_unlock(&tunnel6_mutex);
80 synchronize_net();
82 return ret;
85 EXPORT_SYMBOL(xfrm6_tunnel_deregister);
87 static int tunnel6_rcv(struct sk_buff **pskb)
89 struct sk_buff *skb = *pskb;
90 struct xfrm6_tunnel *handler;
92 if (!pskb_may_pull(skb, sizeof(struct ipv6hdr)))
93 goto drop;
95 for (handler = tunnel6_handlers; handler; handler = handler->next)
96 if (!handler->handler(skb))
97 return 0;
99 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0, skb->dev);
101 drop:
102 kfree_skb(skb);
103 return 0;
106 static void tunnel6_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
107 int type, int code, int offset, __be32 info)
109 struct xfrm6_tunnel *handler;
111 for (handler = tunnel6_handlers; handler; handler = handler->next)
112 if (!handler->err_handler(skb, opt, type, code, offset, info))
113 break;
116 static struct inet6_protocol tunnel6_protocol = {
117 .handler = tunnel6_rcv,
118 .err_handler = tunnel6_err,
119 .flags = INET6_PROTO_NOPOLICY|INET6_PROTO_FINAL,
122 static int __init tunnel6_init(void)
124 if (inet6_add_protocol(&tunnel6_protocol, IPPROTO_IPV6)) {
125 printk(KERN_ERR "tunnel6 init(): can't add protocol\n");
126 return -EAGAIN;
128 return 0;
131 static void __exit tunnel6_fini(void)
133 if (inet6_del_protocol(&tunnel6_protocol, IPPROTO_IPV6))
134 printk(KERN_ERR "tunnel6 close: can't remove protocol\n");
137 module_init(tunnel6_init);
138 module_exit(tunnel6_fini);
139 MODULE_LICENSE("GPL");