diff options
Diffstat (limited to 'net/ipv4/tunnel4.c')
-rw-r--r-- | net/ipv4/tunnel4.c | 50 |
1 files changed, 46 insertions, 4 deletions
diff --git a/net/ipv4/tunnel4.c b/net/ipv4/tunnel4.c index 8d30c48f090e..a794a8ca8b4f 100644 --- a/net/ipv4/tunnel4.c +++ b/net/ipv4/tunnel4.c | |||
@@ -14,9 +14,10 @@ | |||
14 | #include <net/xfrm.h> | 14 | #include <net/xfrm.h> |
15 | 15 | ||
16 | static struct xfrm_tunnel *tunnel4_handlers; | 16 | static struct xfrm_tunnel *tunnel4_handlers; |
17 | static struct xfrm_tunnel *tunnel64_handlers; | ||
17 | static DEFINE_MUTEX(tunnel4_mutex); | 18 | static DEFINE_MUTEX(tunnel4_mutex); |
18 | 19 | ||
19 | int xfrm4_tunnel_register(struct xfrm_tunnel *handler) | 20 | int xfrm4_tunnel_register(struct xfrm_tunnel *handler, unsigned short family) |
20 | { | 21 | { |
21 | struct xfrm_tunnel **pprev; | 22 | struct xfrm_tunnel **pprev; |
22 | int ret = -EEXIST; | 23 | int ret = -EEXIST; |
@@ -24,7 +25,8 @@ int xfrm4_tunnel_register(struct xfrm_tunnel *handler) | |||
24 | 25 | ||
25 | mutex_lock(&tunnel4_mutex); | 26 | mutex_lock(&tunnel4_mutex); |
26 | 27 | ||
27 | for (pprev = &tunnel4_handlers; *pprev; pprev = &(*pprev)->next) { | 28 | for (pprev = (family == AF_INET) ? &tunnel4_handlers : &tunnel64_handlers; |
29 | *pprev; pprev = &(*pprev)->next) { | ||
28 | if ((*pprev)->priority > priority) | 30 | if ((*pprev)->priority > priority) |
29 | break; | 31 | break; |
30 | if ((*pprev)->priority == priority) | 32 | if ((*pprev)->priority == priority) |
@@ -44,14 +46,15 @@ err: | |||
44 | 46 | ||
45 | EXPORT_SYMBOL(xfrm4_tunnel_register); | 47 | EXPORT_SYMBOL(xfrm4_tunnel_register); |
46 | 48 | ||
47 | int xfrm4_tunnel_deregister(struct xfrm_tunnel *handler) | 49 | int xfrm4_tunnel_deregister(struct xfrm_tunnel *handler, unsigned short family) |
48 | { | 50 | { |
49 | struct xfrm_tunnel **pprev; | 51 | struct xfrm_tunnel **pprev; |
50 | int ret = -ENOENT; | 52 | int ret = -ENOENT; |
51 | 53 | ||
52 | mutex_lock(&tunnel4_mutex); | 54 | mutex_lock(&tunnel4_mutex); |
53 | 55 | ||
54 | for (pprev = &tunnel4_handlers; *pprev; pprev = &(*pprev)->next) { | 56 | for (pprev = (family == AF_INET) ? &tunnel4_handlers : &tunnel64_handlers; |
57 | *pprev; pprev = &(*pprev)->next) { | ||
55 | if (*pprev == handler) { | 58 | if (*pprev == handler) { |
56 | *pprev = handler->next; | 59 | *pprev = handler->next; |
57 | ret = 0; | 60 | ret = 0; |
@@ -86,6 +89,26 @@ drop: | |||
86 | return 0; | 89 | return 0; |
87 | } | 90 | } |
88 | 91 | ||
92 | #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE) | ||
93 | static int tunnel64_rcv(struct sk_buff *skb) | ||
94 | { | ||
95 | struct xfrm_tunnel *handler; | ||
96 | |||
97 | if (!pskb_may_pull(skb, sizeof(struct iphdr))) | ||
98 | goto drop; | ||
99 | |||
100 | for (handler = tunnel64_handlers; handler; handler = handler->next) | ||
101 | if (!handler->handler(skb)) | ||
102 | return 0; | ||
103 | |||
104 | icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0); | ||
105 | |||
106 | drop: | ||
107 | kfree_skb(skb); | ||
108 | return 0; | ||
109 | } | ||
110 | #endif | ||
111 | |||
89 | static void tunnel4_err(struct sk_buff *skb, u32 info) | 112 | static void tunnel4_err(struct sk_buff *skb, u32 info) |
90 | { | 113 | { |
91 | struct xfrm_tunnel *handler; | 114 | struct xfrm_tunnel *handler; |
@@ -101,17 +124,36 @@ static struct net_protocol tunnel4_protocol = { | |||
101 | .no_policy = 1, | 124 | .no_policy = 1, |
102 | }; | 125 | }; |
103 | 126 | ||
127 | #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE) | ||
128 | static struct net_protocol tunnel64_protocol = { | ||
129 | .handler = tunnel64_rcv, | ||
130 | .err_handler = tunnel4_err, | ||
131 | .no_policy = 1, | ||
132 | }; | ||
133 | #endif | ||
134 | |||
104 | static int __init tunnel4_init(void) | 135 | static int __init tunnel4_init(void) |
105 | { | 136 | { |
106 | if (inet_add_protocol(&tunnel4_protocol, IPPROTO_IPIP)) { | 137 | if (inet_add_protocol(&tunnel4_protocol, IPPROTO_IPIP)) { |
107 | printk(KERN_ERR "tunnel4 init: can't add protocol\n"); | 138 | printk(KERN_ERR "tunnel4 init: can't add protocol\n"); |
108 | return -EAGAIN; | 139 | return -EAGAIN; |
109 | } | 140 | } |
141 | #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE) | ||
142 | if (inet_add_protocol(&tunnel64_protocol, IPPROTO_IPV6)) { | ||
143 | printk(KERN_ERR "tunnel64 init: can't add protocol\n"); | ||
144 | inet_del_protocol(&tunnel4_protocol, IPPROTO_IPIP); | ||
145 | return -EAGAIN; | ||
146 | } | ||
147 | #endif | ||
110 | return 0; | 148 | return 0; |
111 | } | 149 | } |
112 | 150 | ||
113 | static void __exit tunnel4_fini(void) | 151 | static void __exit tunnel4_fini(void) |
114 | { | 152 | { |
153 | #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE) | ||
154 | if (inet_del_protocol(&tunnel64_protocol, IPPROTO_IPV6)) | ||
155 | printk(KERN_ERR "tunnel64 close: can't remove protocol\n"); | ||
156 | #endif | ||
115 | if (inet_del_protocol(&tunnel4_protocol, IPPROTO_IPIP)) | 157 | if (inet_del_protocol(&tunnel4_protocol, IPPROTO_IPIP)) |
116 | printk(KERN_ERR "tunnel4 close: can't remove protocol\n"); | 158 | printk(KERN_ERR "tunnel4 close: can't remove protocol\n"); |
117 | } | 159 | } |