[PATCH] fix update_mmu_cache in fremap.c
[linux-2.6.22.y-op.git] / net / ipv4 / tunnel4.c
blob8d30c48f090e59dd9ac96b40252b0ac4c9099246
1 /* tunnel4.c: Generic IP tunnel transformer.
3 * Copyright (C) 2003 David S. Miller (davem@redhat.com)
4 */
6 #include <linux/init.h>
7 #include <linux/module.h>
8 #include <linux/mutex.h>
9 #include <linux/netdevice.h>
10 #include <linux/skbuff.h>
11 #include <net/icmp.h>
12 #include <net/ip.h>
13 #include <net/protocol.h>
14 #include <net/xfrm.h>
16 static struct xfrm_tunnel *tunnel4_handlers;
17 static DEFINE_MUTEX(tunnel4_mutex);
19 int xfrm4_tunnel_register(struct xfrm_tunnel *handler)
21 struct xfrm_tunnel **pprev;
22 int ret = -EEXIST;
23 int priority = handler->priority;
25 mutex_lock(&tunnel4_mutex);
27 for (pprev = &tunnel4_handlers; *pprev; pprev = &(*pprev)->next) {
28 if ((*pprev)->priority > priority)
29 break;
30 if ((*pprev)->priority == priority)
31 goto err;
34 handler->next = *pprev;
35 *pprev = handler;
37 ret = 0;
39 err:
40 mutex_unlock(&tunnel4_mutex);
42 return ret;
45 EXPORT_SYMBOL(xfrm4_tunnel_register);
47 int xfrm4_tunnel_deregister(struct xfrm_tunnel *handler)
49 struct xfrm_tunnel **pprev;
50 int ret = -ENOENT;
52 mutex_lock(&tunnel4_mutex);
54 for (pprev = &tunnel4_handlers; *pprev; pprev = &(*pprev)->next) {
55 if (*pprev == handler) {
56 *pprev = handler->next;
57 ret = 0;
58 break;
62 mutex_unlock(&tunnel4_mutex);
64 synchronize_net();
66 return ret;
69 EXPORT_SYMBOL(xfrm4_tunnel_deregister);
71 static int tunnel4_rcv(struct sk_buff *skb)
73 struct xfrm_tunnel *handler;
75 if (!pskb_may_pull(skb, sizeof(struct iphdr)))
76 goto drop;
78 for (handler = tunnel4_handlers; handler; handler = handler->next)
79 if (!handler->handler(skb))
80 return 0;
82 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
84 drop:
85 kfree_skb(skb);
86 return 0;
89 static void tunnel4_err(struct sk_buff *skb, u32 info)
91 struct xfrm_tunnel *handler;
93 for (handler = tunnel4_handlers; handler; handler = handler->next)
94 if (!handler->err_handler(skb, info))
95 break;
98 static struct net_protocol tunnel4_protocol = {
99 .handler = tunnel4_rcv,
100 .err_handler = tunnel4_err,
101 .no_policy = 1,
104 static int __init tunnel4_init(void)
106 if (inet_add_protocol(&tunnel4_protocol, IPPROTO_IPIP)) {
107 printk(KERN_ERR "tunnel4 init: can't add protocol\n");
108 return -EAGAIN;
110 return 0;
113 static void __exit tunnel4_fini(void)
115 if (inet_del_protocol(&tunnel4_protocol, IPPROTO_IPIP))
116 printk(KERN_ERR "tunnel4 close: can't remove protocol\n");
119 module_init(tunnel4_init);
120 module_exit(tunnel4_fini);
121 MODULE_LICENSE("GPL");