blob: 3eef06454da943e24599d5ca7051a5c6c5ae34c4 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/* xfrm4_tunnel.c: Generic IP tunnel transformer.
2 *
3 * Copyright (C) 2003 David S. Miller (davem@redhat.com)
4 */
5
6#include <linux/skbuff.h>
7#include <linux/module.h>
Arjan van de Ven4a3e2f72006-03-20 22:33:17 -08008#include <linux/mutex.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07009#include <net/xfrm.h>
10#include <net/ip.h>
11#include <net/protocol.h>
12
13static int ipip_output(struct xfrm_state *x, struct sk_buff *skb)
14{
15 struct iphdr *iph;
YOSHIFUJI Hideakie905a9e2007-02-09 23:24:47 +090016
Linus Torvalds1da177e2005-04-16 15:20:36 -070017 iph = skb->nh.iph;
18 iph->tot_len = htons(skb->len);
19 ip_send_check(iph);
20
21 return 0;
22}
23
Herbert Xue6956332006-04-01 00:52:46 -080024static int ipip_xfrm_rcv(struct xfrm_state *x, struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -070025{
26 return 0;
27}
28
Herbert Xu72cb6962005-06-20 13:18:08 -070029static int ipip_init_state(struct xfrm_state *x)
Linus Torvalds1da177e2005-04-16 15:20:36 -070030{
Masahide NAKAMURA7e49e6d2006-09-22 15:05:15 -070031 if (x->props.mode != XFRM_MODE_TUNNEL)
Linus Torvalds1da177e2005-04-16 15:20:36 -070032 return -EINVAL;
33
34 if (x->encap)
35 return -EINVAL;
36
37 x->props.header_len = sizeof(struct iphdr);
38
39 return 0;
40}
41
42static void ipip_destroy(struct xfrm_state *x)
43{
44}
45
46static struct xfrm_type ipip_type = {
47 .description = "IPIP",
48 .owner = THIS_MODULE,
49 .proto = IPPROTO_IPIP,
50 .init_state = ipip_init_state,
51 .destructor = ipip_destroy,
52 .input = ipip_xfrm_rcv,
53 .output = ipip_output
54};
55
Herbert Xud2acc342006-03-28 01:12:13 -080056static int xfrm_tunnel_err(struct sk_buff *skb, u32 info)
57{
58 return -ENOENT;
59}
60
61static struct xfrm_tunnel xfrm_tunnel_handler = {
62 .handler = xfrm4_rcv,
63 .err_handler = xfrm_tunnel_err,
64 .priority = 2,
Linus Torvalds1da177e2005-04-16 15:20:36 -070065};
66
Kazunori MIYAZAWAc0d56402007-02-13 12:54:47 -080067#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
68static struct xfrm_tunnel xfrm64_tunnel_handler = {
69 .handler = xfrm4_rcv,
70 .err_handler = xfrm_tunnel_err,
71 .priority = 2,
72};
73#endif
74
Linus Torvalds1da177e2005-04-16 15:20:36 -070075static int __init ipip_init(void)
76{
77 if (xfrm_register_type(&ipip_type, AF_INET) < 0) {
78 printk(KERN_INFO "ipip init: can't add xfrm type\n");
79 return -EAGAIN;
80 }
Kazunori MIYAZAWAc0d56402007-02-13 12:54:47 -080081
82 if (xfrm4_tunnel_register(&xfrm_tunnel_handler, AF_INET)) {
83 printk(KERN_INFO "ipip init: can't add xfrm handler for AF_INET\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -070084 xfrm_unregister_type(&ipip_type, AF_INET);
85 return -EAGAIN;
86 }
Kazunori MIYAZAWAc0d56402007-02-13 12:54:47 -080087#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
88 if (xfrm4_tunnel_register(&xfrm64_tunnel_handler, AF_INET6)) {
89 printk(KERN_INFO "ipip init: can't add xfrm handler for AF_INET6\n");
90 xfrm4_tunnel_deregister(&xfrm_tunnel_handler, AF_INET);
91 xfrm_unregister_type(&ipip_type, AF_INET);
92 return -EAGAIN;
93 }
94#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070095 return 0;
96}
97
98static void __exit ipip_fini(void)
99{
Kazunori MIYAZAWAc0d56402007-02-13 12:54:47 -0800100#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
101 if (xfrm4_tunnel_deregister(&xfrm64_tunnel_handler, AF_INET6))
102 printk(KERN_INFO "ipip close: can't remove xfrm handler for AF_INET6\n");
103#endif
104 if (xfrm4_tunnel_deregister(&xfrm_tunnel_handler, AF_INET))
105 printk(KERN_INFO "ipip close: can't remove xfrm handler for AF_INET\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106 if (xfrm_unregister_type(&ipip_type, AF_INET) < 0)
107 printk(KERN_INFO "ipip close: can't remove xfrm type\n");
108}
109
110module_init(ipip_init);
111module_exit(ipip_fini);
112MODULE_LICENSE("GPL");