]> bbs.cooldavid.org Git - net-next-2.6.git/blame - net/ipv4/xfrm4_tunnel.c
net/ipv4/tcp.c: Update WARN uses
[net-next-2.6.git] / net / ipv4 / xfrm4_tunnel.c
CommitLineData
1da177e4
LT
1/* 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>
4a3e2f71 8#include <linux/mutex.h>
1da177e4
LT
9#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{
7b277b1a 15 skb_push(skb, -skb_network_offset(skb));
1da177e4
LT
16 return 0;
17}
18
e695633e 19static int ipip_xfrm_rcv(struct xfrm_state *x, struct sk_buff *skb)
1da177e4 20{
04663d0b 21 return ip_hdr(skb)->protocol;
1da177e4
LT
22}
23
72cb6962 24static int ipip_init_state(struct xfrm_state *x)
1da177e4 25{
7e49e6de 26 if (x->props.mode != XFRM_MODE_TUNNEL)
1da177e4
LT
27 return -EINVAL;
28
29 if (x->encap)
30 return -EINVAL;
31
32 x->props.header_len = sizeof(struct iphdr);
33
34 return 0;
35}
36
37static void ipip_destroy(struct xfrm_state *x)
38{
39}
40
533cb5b0 41static const struct xfrm_type ipip_type = {
1da177e4
LT
42 .description = "IPIP",
43 .owner = THIS_MODULE,
44 .proto = IPPROTO_IPIP,
45 .init_state = ipip_init_state,
46 .destructor = ipip_destroy,
47 .input = ipip_xfrm_rcv,
48 .output = ipip_output
49};
50
c4541b41
HX
51static int xfrm_tunnel_rcv(struct sk_buff *skb)
52{
b1641064 53 return xfrm4_rcv_spi(skb, IPPROTO_IPIP, ip_hdr(skb)->saddr);
c4541b41
HX
54}
55
d2acc347
HX
56static int xfrm_tunnel_err(struct sk_buff *skb, u32 info)
57{
58 return -ENOENT;
59}
60
6dcd814b 61static struct xfrm_tunnel xfrm_tunnel_handler __read_mostly = {
c4541b41 62 .handler = xfrm_tunnel_rcv,
d2acc347
HX
63 .err_handler = xfrm_tunnel_err,
64 .priority = 2,
1da177e4
LT
65};
66
c0d56408 67#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
6dcd814b 68static struct xfrm_tunnel xfrm64_tunnel_handler __read_mostly = {
c4541b41 69 .handler = xfrm_tunnel_rcv,
c0d56408
KM
70 .err_handler = xfrm_tunnel_err,
71 .priority = 2,
72};
73#endif
74
1da177e4
LT
75static 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 }
c0d56408
KM
81
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");
84 xfrm_unregister_type(&ipip_type, AF_INET);
85 return -EAGAIN;
86 }
87#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);
1da177e4
LT
91 xfrm_unregister_type(&ipip_type, AF_INET);
92 return -EAGAIN;
93 }
c0d56408 94#endif
1da177e4
LT
95 return 0;
96}
97
98static void __exit ipip_fini(void)
99{
c0d56408
KM
100#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");
1da177e4
LT
106 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");
d3d6dd3a 113MODULE_ALIAS_XFRM_TYPE(AF_INET, XFRM_PROTO_IPIP);