aboutsummaryrefslogtreecommitdiffstats
path: root/net/ipv6/tunnel6.c
diff options
context:
space:
mode:
authorHerbert Xu <herbert@gondor.apana.org.au>2006-03-28 04:12:13 -0500
committerDavid S. Miller <davem@sunset.davemloft.net>2006-03-28 20:02:46 -0500
commitd2acc3479cbccd5cfbca6c787be713ef1de12ec6 (patch)
treeaa348e19e15027db9abdd2da175a0c9055047858 /net/ipv6/tunnel6.c
parentf0088a50e7c49d1ba285c88fe06345f223652fd3 (diff)
[INET]: Introduce tunnel4/tunnel6
Basically this patch moves the generic tunnel protocol stuff out of xfrm4_tunnel/xfrm6_tunnel and moves it into the new files of tunnel4.c and tunnel6 respectively. The reason for this is that the problem that Hugo uncovered is only the tip of the iceberg. The real problem is that when we removed the dependency of ipip on xfrm4_tunnel we didn't really consider the module case at all. For instance, as it is it's possible to build both ipip and xfrm4_tunnel as modules and if the latter is loaded then ipip simply won't load. After considering the alternatives I've decided that the best way out of this is to restore the dependency of ipip on the non-xfrm-specific part of xfrm4_tunnel. This is acceptable IMHO because the intention of the removal was really to be able to use ipip without the xfrm subsystem. This is still preserved by this patch. So now both ipip/xfrm4_tunnel depend on the new tunnel4.c which handles the arbitration between the two. The order of processing is determined by a simple integer which ensures that ipip gets processed before xfrm4_tunnel. The situation for ICMP handling is a little bit more complicated since we may not have enough information to determine who it's for. It's not a big deal at the moment since the xfrm ICMP handlers are basically no-ops. In future we can deal with this when we look at ICMP caching in general. The user-visible change to this is the removal of the TUNNEL Kconfig prompts. This makes sense because it can only be used through IPCOMP as it stands. The addition of the new modules shouldn't introduce any problems since module dependency will cause them to be loaded. Oh and I also turned some unnecessary pskb's in IPv6 related to this patch to skb's. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/ipv6/tunnel6.c')
-rw-r--r--net/ipv6/tunnel6.c131
1 files changed, 131 insertions, 0 deletions
diff --git a/net/ipv6/tunnel6.c b/net/ipv6/tunnel6.c
new file mode 100644
index 000000000000..5659b52284bd
--- /dev/null
+++ b/net/ipv6/tunnel6.c
@@ -0,0 +1,131 @@
1/*
2 * Copyright (C)2003,2004 USAGI/WIDE Project
3 *
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.
8 *
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.
13 *
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
17 *
18 * Authors Mitsuru KANDA <mk@linux-ipv6.org>
19 * YOSHIFUJI Hideaki <yoshfuji@linux-ipv6.org>
20 */
21
22#include <linux/init.h>
23#include <linux/module.h>
24#include <linux/mutex.h>
25#include <linux/netdevice.h>
26#include <linux/skbuff.h>
27#include <net/protocol.h>
28#include <net/xfrm.h>
29
30static struct xfrm6_tunnel *tunnel6_handlers;
31static DEFINE_MUTEX(tunnel6_mutex);
32
33int xfrm6_tunnel_register(struct xfrm6_tunnel *handler)
34{
35 struct xfrm6_tunnel **pprev;
36 int ret = -EEXIST;
37 int priority = handler->priority;
38
39 mutex_lock(&tunnel6_mutex);
40
41 for (pprev = &tunnel6_handlers; *pprev; pprev = &(*pprev)->next) {
42 if ((*pprev)->priority > priority)
43 break;
44 if ((*pprev)->priority == priority)
45 goto err;
46 }
47
48 handler->next = *pprev;
49 *pprev = handler;
50
51 ret = 0;
52
53err:
54 mutex_unlock(&tunnel6_mutex);
55
56 return ret;
57}
58
59EXPORT_SYMBOL(xfrm6_tunnel_register);
60
61int xfrm6_tunnel_deregister(struct xfrm6_tunnel *handler)
62{
63 struct xfrm6_tunnel **pprev;
64 int ret = -ENOENT;
65
66 mutex_lock(&tunnel6_mutex);
67
68 for (pprev = &tunnel6_handlers; *pprev; pprev = &(*pprev)->next) {
69 if (*pprev == handler) {
70 *pprev = handler->next;
71 ret = 0;
72 break;
73 }
74 }
75
76 mutex_unlock(&tunnel6_mutex);
77
78 synchronize_net();
79
80 return ret;
81}
82
83EXPORT_SYMBOL(xfrm6_tunnel_deregister);
84
85static int tunnel6_rcv(struct sk_buff **pskb)
86{
87 struct sk_buff *skb = *pskb;
88 struct xfrm6_tunnel *handler;
89
90 for (handler = tunnel6_handlers; handler; handler = handler->next)
91 if (!handler->handler(skb))
92 return 0;
93
94 kfree_skb(skb);
95 return 0;
96}
97
98static void tunnel6_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
99 int type, int code, int offset, __u32 info)
100{
101 struct xfrm6_tunnel *handler;
102
103 for (handler = tunnel6_handlers; handler; handler = handler->next)
104 if (!handler->err_handler(skb, opt, type, code, offset, info))
105 break;
106}
107
108static struct inet6_protocol tunnel6_protocol = {
109 .handler = tunnel6_rcv,
110 .err_handler = tunnel6_err,
111 .flags = INET6_PROTO_NOPOLICY|INET6_PROTO_FINAL,
112};
113
114static int __init tunnel6_init(void)
115{
116 if (inet6_add_protocol(&tunnel6_protocol, IPPROTO_IPV6)) {
117 printk(KERN_ERR "tunnel6 init(): can't add protocol\n");
118 return -EAGAIN;
119 }
120 return 0;
121}
122
123static void __exit tunnel6_fini(void)
124{
125 if (inet6_del_protocol(&tunnel6_protocol, IPPROTO_IPV6))
126 printk(KERN_ERR "tunnel6 close: can't remove protocol\n");
127}
128
129module_init(tunnel6_init);
130module_exit(tunnel6_fini);
131MODULE_LICENSE("GPL");