1 /* tunnel4.c: Generic IP tunnel transformer.
3 * Copyright (C) 2003 David S. Miller (davem@redhat.com)
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/protocol.h>
14 static struct xfrm_tunnel *tunnel4_handlers;
15 static DEFINE_MUTEX(tunnel4_mutex);
17 int xfrm4_tunnel_register(struct xfrm_tunnel *handler)
19 struct xfrm_tunnel **pprev;
21 int priority = handler->priority;
23 mutex_lock(&tunnel4_mutex);
25 for (pprev = &tunnel4_handlers; *pprev; pprev = &(*pprev)->next) {
26 if ((*pprev)->priority > priority)
28 if ((*pprev)->priority == priority)
32 handler->next = *pprev;
38 mutex_unlock(&tunnel4_mutex);
43 EXPORT_SYMBOL(xfrm4_tunnel_register);
45 int xfrm4_tunnel_deregister(struct xfrm_tunnel *handler)
47 struct xfrm_tunnel **pprev;
50 mutex_lock(&tunnel4_mutex);
52 for (pprev = &tunnel4_handlers; *pprev; pprev = &(*pprev)->next) {
53 if (*pprev == handler) {
54 *pprev = handler->next;
60 mutex_unlock(&tunnel4_mutex);
67 EXPORT_SYMBOL(xfrm4_tunnel_deregister);
69 static int tunnel4_rcv(struct sk_buff *skb)
71 struct xfrm_tunnel *handler;
73 for (handler = tunnel4_handlers; handler; handler = handler->next)
74 if (!handler->handler(skb))
81 static void tunnel4_err(struct sk_buff *skb, u32 info)
83 struct xfrm_tunnel *handler;
85 for (handler = tunnel4_handlers; handler; handler = handler->next)
86 if (!handler->err_handler(skb, info))
90 static struct net_protocol tunnel4_protocol = {
91 .handler = tunnel4_rcv,
92 .err_handler = tunnel4_err,
96 static int __init tunnel4_init(void)
98 if (inet_add_protocol(&tunnel4_protocol, IPPROTO_IPIP)) {
99 printk(KERN_ERR "tunnel4 init: can't add protocol\n");
105 static void __exit tunnel4_fini(void)
107 if (inet_del_protocol(&tunnel4_protocol, IPPROTO_IPIP))
108 printk(KERN_ERR "tunnel4 close: can't remove protocol\n");
111 module_init(tunnel4_init);
112 module_exit(tunnel4_fini);
113 MODULE_LICENSE("GPL");