aboutsummaryrefslogtreecommitdiffstats
path: root/net/ipv4/xfrm4_tunnel.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
commit1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch)
tree0bba044c4ce775e45a88a51686b5d9f90697ea9d /net/ipv4/xfrm4_tunnel.c
Linux-2.6.12-rc2v2.6.12-rc2
Initial git repository build. I'm not bothering with the full history, even though we have it. We can create a separate "historical" git archive of that later if we want to, and in the meantime it's about 3.2GB when imported into git - space that would just make the early git days unnecessarily complicated, when we don't have a lot of good infrastructure for it. Let it rip!
Diffstat (limited to 'net/ipv4/xfrm4_tunnel.c')
-rw-r--r--net/ipv4/xfrm4_tunnel.c144
1 files changed, 144 insertions, 0 deletions
diff --git a/net/ipv4/xfrm4_tunnel.c b/net/ipv4/xfrm4_tunnel.c
new file mode 100644
index 000000000000..413191f585f6
--- /dev/null
+++ b/net/ipv4/xfrm4_tunnel.c
@@ -0,0 +1,144 @@
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>
8#include <net/xfrm.h>
9#include <net/ip.h>
10#include <net/protocol.h>
11
12static int ipip_output(struct xfrm_state *x, struct sk_buff *skb)
13{
14 struct iphdr *iph;
15
16 iph = skb->nh.iph;
17 iph->tot_len = htons(skb->len);
18 ip_send_check(iph);
19
20 return 0;
21}
22
23static int ipip_xfrm_rcv(struct xfrm_state *x, struct xfrm_decap_state *decap, struct sk_buff *skb)
24{
25 return 0;
26}
27
28static struct xfrm_tunnel *ipip_handler;
29static DECLARE_MUTEX(xfrm4_tunnel_sem);
30
31int xfrm4_tunnel_register(struct xfrm_tunnel *handler)
32{
33 int ret;
34
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);
42
43 return ret;
44}
45
46EXPORT_SYMBOL(xfrm4_tunnel_register);
47
48int xfrm4_tunnel_deregister(struct xfrm_tunnel *handler)
49{
50 int ret;
51
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);
59
60 synchronize_net();
61
62 return ret;
63}
64
65EXPORT_SYMBOL(xfrm4_tunnel_deregister);
66
67static int ipip_rcv(struct sk_buff *skb)
68{
69 struct xfrm_tunnel *handler = ipip_handler;
70
71 /* Tunnel devices take precedence. */
72 if (handler && handler->handler(skb) == 0)
73 return 0;
74
75 return xfrm4_rcv(skb);
76}
77
78static void ipip_err(struct sk_buff *skb, u32 info)
79{
80 struct xfrm_tunnel *handler = ipip_handler;
81 u32 arg = info;
82
83 if (handler)
84 handler->err_handler(skb, &arg);
85}
86
87static int ipip_init_state(struct xfrm_state *x, void *args)
88{
89 if (!x->props.mode)
90 return -EINVAL;
91
92 if (x->encap)
93 return -EINVAL;
94
95 x->props.header_len = sizeof(struct iphdr);
96
97 return 0;
98}
99
100static void ipip_destroy(struct xfrm_state *x)
101{
102}
103
104static struct xfrm_type ipip_type = {
105 .description = "IPIP",
106 .owner = THIS_MODULE,
107 .proto = IPPROTO_IPIP,
108 .init_state = ipip_init_state,
109 .destructor = ipip_destroy,
110 .input = ipip_xfrm_rcv,
111 .output = ipip_output
112};
113
114static struct net_protocol ipip_protocol = {
115 .handler = ipip_rcv,
116 .err_handler = ipip_err,
117 .no_policy = 1,
118};
119
120static int __init ipip_init(void)
121{
122 if (xfrm_register_type(&ipip_type, AF_INET) < 0) {
123 printk(KERN_INFO "ipip init: can't add xfrm type\n");
124 return -EAGAIN;
125 }
126 if (inet_add_protocol(&ipip_protocol, IPPROTO_IPIP) < 0) {
127 printk(KERN_INFO "ipip init: can't add protocol\n");
128 xfrm_unregister_type(&ipip_type, AF_INET);
129 return -EAGAIN;
130 }
131 return 0;
132}
133
134static void __exit ipip_fini(void)
135{
136 if (inet_del_protocol(&ipip_protocol, IPPROTO_IPIP) < 0)
137 printk(KERN_INFO "ipip close: can't remove protocol\n");
138 if (xfrm_unregister_type(&ipip_type, AF_INET) < 0)
139 printk(KERN_INFO "ipip close: can't remove xfrm type\n");
140}
141
142module_init(ipip_init);
143module_exit(ipip_fini);
144MODULE_LICENSE("GPL");