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/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>
30 static struct xfrm6_tunnel
*tunnel6_handlers
;
31 static DEFINE_MUTEX(tunnel6_mutex
);
33 int xfrm6_tunnel_register(struct xfrm6_tunnel
*handler
)
35 struct xfrm6_tunnel
**pprev
;
37 int priority
= handler
->priority
;
39 mutex_lock(&tunnel6_mutex
);
41 for (pprev
= &tunnel6_handlers
; *pprev
; pprev
= &(*pprev
)->next
) {
42 if ((*pprev
)->priority
> priority
)
44 if ((*pprev
)->priority
== priority
)
48 handler
->next
= *pprev
;
54 mutex_unlock(&tunnel6_mutex
);
59 EXPORT_SYMBOL(xfrm6_tunnel_register
);
61 int xfrm6_tunnel_deregister(struct xfrm6_tunnel
*handler
)
63 struct xfrm6_tunnel
**pprev
;
66 mutex_lock(&tunnel6_mutex
);
68 for (pprev
= &tunnel6_handlers
; *pprev
; pprev
= &(*pprev
)->next
) {
69 if (*pprev
== handler
) {
70 *pprev
= handler
->next
;
76 mutex_unlock(&tunnel6_mutex
);
83 EXPORT_SYMBOL(xfrm6_tunnel_deregister
);
85 static int tunnel6_rcv(struct sk_buff
**pskb
)
87 struct sk_buff
*skb
= *pskb
;
88 struct xfrm6_tunnel
*handler
;
90 for (handler
= tunnel6_handlers
; handler
; handler
= handler
->next
)
91 if (!handler
->handler(skb
))
98 static void tunnel6_err(struct sk_buff
*skb
, struct inet6_skb_parm
*opt
,
99 int type
, int code
, int offset
, __u32 info
)
101 struct xfrm6_tunnel
*handler
;
103 for (handler
= tunnel6_handlers
; handler
; handler
= handler
->next
)
104 if (!handler
->err_handler(skb
, opt
, type
, code
, offset
, info
))
108 static struct inet6_protocol tunnel6_protocol
= {
109 .handler
= tunnel6_rcv
,
110 .err_handler
= tunnel6_err
,
111 .flags
= INET6_PROTO_NOPOLICY
|INET6_PROTO_FINAL
,
114 static int __init
tunnel6_init(void)
116 if (inet6_add_protocol(&tunnel6_protocol
, IPPROTO_IPV6
)) {
117 printk(KERN_ERR
"tunnel6 init(): can't add protocol\n");
123 static void __exit
tunnel6_fini(void)
125 if (inet6_del_protocol(&tunnel6_protocol
, IPPROTO_IPV6
))
126 printk(KERN_ERR
"tunnel6 close: can't remove protocol\n");
129 module_init(tunnel6_init
);
130 module_exit(tunnel6_fini
);
131 MODULE_LICENSE("GPL");