[PATCH] cpufreq: documentation for 'ondemand' and 'conservative'
[linux-2.6/mini2440.git] / net / ipv4 / xfrm4_tunnel.c
blobafbb0d4cc305317add1c93b719abbcdcd2bb41ca
1 /* xfrm4_tunnel.c: Generic IP tunnel transformer.
3 * Copyright (C) 2003 David S. Miller (davem@redhat.com)
4 */
6 #include <linux/skbuff.h>
7 #include <linux/module.h>
8 #include <net/xfrm.h>
9 #include <net/ip.h>
10 #include <net/protocol.h>
12 static int ipip_output(struct xfrm_state *x, struct sk_buff *skb)
14 struct iphdr *iph;
16 iph = skb->nh.iph;
17 iph->tot_len = htons(skb->len);
18 ip_send_check(iph);
20 return 0;
23 static int ipip_xfrm_rcv(struct xfrm_state *x, struct xfrm_decap_state *decap, struct sk_buff *skb)
25 return 0;
28 static struct xfrm_tunnel *ipip_handler;
29 static DECLARE_MUTEX(xfrm4_tunnel_sem);
31 int xfrm4_tunnel_register(struct xfrm_tunnel *handler)
33 int ret;
35 down(&xfrm4_tunnel_sem);
36 ret = 0;
37 if (ipip_handler != NULL)
38 ret = -EINVAL;
39 if (!ret)
40 ipip_handler = handler;
41 up(&xfrm4_tunnel_sem);
43 return ret;
46 EXPORT_SYMBOL(xfrm4_tunnel_register);
48 int xfrm4_tunnel_deregister(struct xfrm_tunnel *handler)
50 int ret;
52 down(&xfrm4_tunnel_sem);
53 ret = 0;
54 if (ipip_handler != handler)
55 ret = -EINVAL;
56 if (!ret)
57 ipip_handler = NULL;
58 up(&xfrm4_tunnel_sem);
60 synchronize_net();
62 return ret;
65 EXPORT_SYMBOL(xfrm4_tunnel_deregister);
67 static int ipip_rcv(struct sk_buff *skb)
69 struct xfrm_tunnel *handler = ipip_handler;
71 /* Tunnel devices take precedence. */
72 if (handler && handler->handler(skb) == 0)
73 return 0;
75 return xfrm4_rcv(skb);
78 static void ipip_err(struct sk_buff *skb, u32 info)
80 struct xfrm_tunnel *handler = ipip_handler;
82 if (handler)
83 handler->err_handler(skb, info);
86 static int ipip_init_state(struct xfrm_state *x)
88 if (!x->props.mode)
89 return -EINVAL;
91 if (x->encap)
92 return -EINVAL;
94 x->props.header_len = sizeof(struct iphdr);
96 return 0;
99 static void ipip_destroy(struct xfrm_state *x)
103 static struct xfrm_type ipip_type = {
104 .description = "IPIP",
105 .owner = THIS_MODULE,
106 .proto = IPPROTO_IPIP,
107 .init_state = ipip_init_state,
108 .destructor = ipip_destroy,
109 .input = ipip_xfrm_rcv,
110 .output = ipip_output
113 static struct net_protocol ipip_protocol = {
114 .handler = ipip_rcv,
115 .err_handler = ipip_err,
116 .no_policy = 1,
119 static int __init ipip_init(void)
121 if (xfrm_register_type(&ipip_type, AF_INET) < 0) {
122 printk(KERN_INFO "ipip init: can't add xfrm type\n");
123 return -EAGAIN;
125 if (inet_add_protocol(&ipip_protocol, IPPROTO_IPIP) < 0) {
126 printk(KERN_INFO "ipip init: can't add protocol\n");
127 xfrm_unregister_type(&ipip_type, AF_INET);
128 return -EAGAIN;
130 return 0;
133 static void __exit ipip_fini(void)
135 if (inet_del_protocol(&ipip_protocol, IPPROTO_IPIP) < 0)
136 printk(KERN_INFO "ipip close: can't remove protocol\n");
137 if (xfrm_unregister_type(&ipip_type, AF_INET) < 0)
138 printk(KERN_INFO "ipip close: can't remove xfrm type\n");
141 module_init(ipip_init);
142 module_exit(ipip_fini);
143 MODULE_LICENSE("GPL");