ia64/linux-2.6.18-xen.hg

view net/ipv6/tunnel6.c @ 673:3161879fdf22

[IA64] xencomm: support XENMEM_add_to_physmap and XENMEM_remove_from_phsymap

support XENMEM_add_to_physmap and XENMEM_remove_from_phsymap.

Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>
author Isaku Yamahata <yamahata@valinux.co.jp>
date Tue Sep 16 21:26:15 2008 +0900 (2008-09-16)
parents 831230e53067
children
line source
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 */
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)
36 {
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;
48 }
50 handler->next = *pprev;
51 *pprev = handler;
53 ret = 0;
55 err:
56 mutex_unlock(&tunnel6_mutex);
58 return ret;
59 }
61 EXPORT_SYMBOL(xfrm6_tunnel_register);
63 int xfrm6_tunnel_deregister(struct xfrm6_tunnel *handler)
64 {
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;
75 }
76 }
78 mutex_unlock(&tunnel6_mutex);
80 synchronize_net();
82 return ret;
83 }
85 EXPORT_SYMBOL(xfrm6_tunnel_deregister);
87 static int tunnel6_rcv(struct sk_buff **pskb)
88 {
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;
104 }
106 static void tunnel6_err(struct sk_buff *skb, struct inet6_skb_parm *opt,
107 int type, int code, int offset, __u32 info)
108 {
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;
114 }
116 static struct inet6_protocol tunnel6_protocol = {
117 .handler = tunnel6_rcv,
118 .err_handler = tunnel6_err,
119 .flags = INET6_PROTO_NOPOLICY|INET6_PROTO_FINAL,
120 };
122 static int __init tunnel6_init(void)
123 {
124 if (inet6_add_protocol(&tunnel6_protocol, IPPROTO_IPV6)) {
125 printk(KERN_ERR "tunnel6 init(): can't add protocol\n");
126 return -EAGAIN;
127 }
128 return 0;
129 }
131 static void __exit tunnel6_fini(void)
132 {
133 if (inet6_del_protocol(&tunnel6_protocol, IPPROTO_IPV6))
134 printk(KERN_ERR "tunnel6 close: can't remove protocol\n");
135 }
137 module_init(tunnel6_init);
138 module_exit(tunnel6_fini);
139 MODULE_LICENSE("GPL");