blob: 58b60b2fb01175fb4c02fb72598619dfb38df716 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * IP Payload Compression Protocol (IPComp) - RFC3173.
3 *
4 * Copyright (c) 2003 James Morris <jmorris@intercode.com.au>
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the Free
YOSHIFUJI Hideakie905a9e2007-02-09 23:24:47 +09008 * Software Foundation; either version 2 of the License, or (at your option)
Linus Torvalds1da177e2005-04-16 15:20:36 -07009 * any later version.
10 *
11 * Todo:
12 * - Tunable compression parameters.
13 * - Compression stats.
14 * - Adaptive compression.
15 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070016#include <linux/module.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070017#include <asm/semaphore.h>
18#include <linux/crypto.h>
Herbert Xu4999f362007-11-07 02:21:47 -080019#include <linux/err.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070020#include <linux/pfkeyv2.h>
21#include <linux/percpu.h>
22#include <linux/smp.h>
23#include <linux/list.h>
24#include <linux/vmalloc.h>
25#include <linux/rtnetlink.h>
Arjan van de Ven4a3e2f72006-03-20 22:33:17 -080026#include <linux/mutex.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070027#include <net/ip.h>
28#include <net/xfrm.h>
29#include <net/icmp.h>
30#include <net/ipcomp.h>
Arnaldo Carvalho de Melo14c85022005-12-27 02:43:12 -020031#include <net/protocol.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070032
33struct ipcomp_tfms {
34 struct list_head list;
Herbert Xue4d5b792006-08-26 18:12:40 +100035 struct crypto_comp **tfms;
Linus Torvalds1da177e2005-04-16 15:20:36 -070036 int users;
37};
38
Arjan van de Ven4a3e2f72006-03-20 22:33:17 -080039static DEFINE_MUTEX(ipcomp_resource_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -070040static void **ipcomp_scratches;
41static int ipcomp_scratch_users;
42static LIST_HEAD(ipcomp_tfms_list);
43
44static int ipcomp_decompress(struct xfrm_state *x, struct sk_buff *skb)
45{
Linus Torvalds1da177e2005-04-16 15:20:36 -070046 struct ipcomp_data *ipcd = x->data;
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -070047 const int plen = skb->len;
48 int dlen = IPCOMP_SCRATCH_SIZE;
49 const u8 *start = skb->data;
50 const int cpu = get_cpu();
51 u8 *scratch = *per_cpu_ptr(ipcomp_scratches, cpu);
52 struct crypto_comp *tfm = *per_cpu_ptr(ipcd->tfms, cpu);
53 int err = crypto_comp_decompress(tfm, start, plen, scratch, &dlen);
YOSHIFUJI Hideakie905a9e2007-02-09 23:24:47 +090054
Linus Torvalds1da177e2005-04-16 15:20:36 -070055 if (err)
56 goto out;
57
58 if (dlen < (plen + sizeof(struct ip_comp_hdr))) {
59 err = -EINVAL;
60 goto out;
61 }
62
63 err = pskb_expand_head(skb, 0, dlen - plen, GFP_ATOMIC);
64 if (err)
65 goto out;
YOSHIFUJI Hideakie905a9e2007-02-09 23:24:47 +090066
Herbert Xuda952312006-07-11 13:50:09 -070067 skb->truesize += dlen - plen;
68 __skb_put(skb, dlen - plen);
Arnaldo Carvalho de Melo27d7ff42007-03-31 11:55:19 -030069 skb_copy_to_linear_data(skb, scratch, dlen);
YOSHIFUJI Hideakie905a9e2007-02-09 23:24:47 +090070out:
Linus Torvalds1da177e2005-04-16 15:20:36 -070071 put_cpu();
72 return err;
73}
74
Herbert Xue6956332006-04-01 00:52:46 -080075static int ipcomp_input(struct xfrm_state *x, struct sk_buff *skb)
Linus Torvalds1da177e2005-04-16 15:20:36 -070076{
Herbert Xu2614fa52008-01-29 21:11:46 -080077 int nexthdr;
Herbert Xu364c6ba2006-06-09 16:10:40 -070078 int err = -ENOMEM;
Herbert Xu31a4ab92006-05-27 23:06:13 -070079 struct ip_comp_hdr *ipch;
Linus Torvalds1da177e2005-04-16 15:20:36 -070080
Herbert Xu364c6ba2006-06-09 16:10:40 -070081 if (skb_linearize_cow(skb))
YOSHIFUJI Hideakie905a9e2007-02-09 23:24:47 +090082 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -070083
84 skb->ip_summed = CHECKSUM_NONE;
85
YOSHIFUJI Hideakie905a9e2007-02-09 23:24:47 +090086 /* Remove ipcomp header and decompress original payload */
Herbert Xu31a4ab92006-05-27 23:06:13 -070087 ipch = (void *)skb->data;
Herbert Xu2614fa52008-01-29 21:11:46 -080088 nexthdr = ipch->nexthdr;
89
Arnaldo Carvalho de Melob0e380b2007-04-10 21:21:55 -070090 skb->transport_header = skb->network_header + sizeof(*ipch);
Herbert Xu31a4ab92006-05-27 23:06:13 -070091 __skb_pull(skb, sizeof(*ipch));
Linus Torvalds1da177e2005-04-16 15:20:36 -070092 err = ipcomp_decompress(x, skb);
Herbert Xu631a66982007-10-10 15:46:21 -070093 if (err)
94 goto out;
95
Herbert Xu2614fa52008-01-29 21:11:46 -080096 err = nexthdr;
Linus Torvalds1da177e2005-04-16 15:20:36 -070097
YOSHIFUJI Hideakie905a9e2007-02-09 23:24:47 +090098out:
Linus Torvalds1da177e2005-04-16 15:20:36 -070099 return err;
100}
101
102static int ipcomp_compress(struct xfrm_state *x, struct sk_buff *skb)
103{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104 struct ipcomp_data *ipcd = x->data;
Herbert Xuceb1eec82007-10-10 15:45:52 -0700105 const int plen = skb->len;
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -0700106 int dlen = IPCOMP_SCRATCH_SIZE;
Herbert Xuceb1eec82007-10-10 15:45:52 -0700107 u8 *start = skb->data;
Arnaldo Carvalho de Meloeddc9ec2007-04-20 22:47:35 -0700108 const int cpu = get_cpu();
109 u8 *scratch = *per_cpu_ptr(ipcomp_scratches, cpu);
110 struct crypto_comp *tfm = *per_cpu_ptr(ipcd->tfms, cpu);
Herbert Xu21e43182008-02-28 11:23:17 -0800111 int err;
YOSHIFUJI Hideakie905a9e2007-02-09 23:24:47 +0900112
Herbert Xu21e43182008-02-28 11:23:17 -0800113 local_bh_disable();
114 err = crypto_comp_compress(tfm, start, plen, scratch, &dlen);
115 local_bh_enable();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116 if (err)
117 goto out;
118
119 if ((dlen + sizeof(struct ip_comp_hdr)) >= plen) {
120 err = -EMSGSIZE;
121 goto out;
122 }
YOSHIFUJI Hideakie905a9e2007-02-09 23:24:47 +0900123
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124 memcpy(start + sizeof(struct ip_comp_hdr), scratch, dlen);
125 put_cpu();
126
Herbert Xuceb1eec82007-10-10 15:45:52 -0700127 pskb_trim(skb, dlen + sizeof(struct ip_comp_hdr));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128 return 0;
YOSHIFUJI Hideakie905a9e2007-02-09 23:24:47 +0900129
130out:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131 put_cpu();
132 return err;
133}
134
135static int ipcomp_output(struct xfrm_state *x, struct sk_buff *skb)
136{
137 int err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138 struct ip_comp_hdr *ipch;
139 struct ipcomp_data *ipcd = x->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140
Herbert Xuceb1eec82007-10-10 15:45:52 -0700141 if (skb->len < ipcd->threshold) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142 /* Don't bother compressing */
143 goto out_ok;
144 }
145
Herbert Xu364c6ba2006-06-09 16:10:40 -0700146 if (skb_linearize_cow(skb))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147 goto out_ok;
YOSHIFUJI Hideakie905a9e2007-02-09 23:24:47 +0900148
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149 err = ipcomp_compress(x, skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150
151 if (err) {
152 goto out_ok;
153 }
154
155 /* Install ipcomp header, convert into ipcomp datagram. */
Herbert Xu87bdc482007-10-10 15:45:25 -0700156 ipch = ip_comp_hdr(skb);
Herbert Xu37fedd32007-10-10 15:44:44 -0700157 ipch->nexthdr = *skb_mac_header(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158 ipch->flags = 0;
159 ipch->cpi = htons((u16 )ntohl(x->id.spi));
Herbert Xu37fedd32007-10-10 15:44:44 -0700160 *skb_mac_header(skb) = IPPROTO_COMP;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161out_ok:
Herbert Xuceb1eec82007-10-10 15:45:52 -0700162 skb_push(skb, -skb_network_offset(skb));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163 return 0;
164}
165
166static void ipcomp4_err(struct sk_buff *skb, u32 info)
167{
Al Viroa94cfd12006-09-27 18:47:24 -0700168 __be32 spi;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169 struct iphdr *iph = (struct iphdr *)skb->data;
170 struct ip_comp_hdr *ipch = (struct ip_comp_hdr *)(skb->data+(iph->ihl<<2));
171 struct xfrm_state *x;
172
Arnaldo Carvalho de Melo88c76642007-03-13 14:43:18 -0300173 if (icmp_hdr(skb)->type != ICMP_DEST_UNREACH ||
174 icmp_hdr(skb)->code != ICMP_FRAG_NEEDED)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175 return;
176
Alexey Dobriyan4195f812006-05-22 16:53:22 -0700177 spi = htonl(ntohs(ipch->cpi));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178 x = xfrm_state_lookup((xfrm_address_t *)&iph->daddr,
YOSHIFUJI Hideakie905a9e2007-02-09 23:24:47 +0900179 spi, IPPROTO_COMP, AF_INET);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180 if (!x)
181 return;
Patrick McHardy64ce2072005-08-09 20:50:53 -0700182 NETDEBUG(KERN_DEBUG "pmtu discovery on SA IPCOMP/%08x/%u.%u.%u.%u\n",
183 spi, NIPQUAD(iph->daddr));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184 xfrm_state_put(x);
185}
186
YOSHIFUJI Hideakie905a9e2007-02-09 23:24:47 +0900187/* We always hold one tunnel user reference to indicate a tunnel */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188static struct xfrm_state *ipcomp_tunnel_create(struct xfrm_state *x)
189{
190 struct xfrm_state *t;
YOSHIFUJI Hideakie905a9e2007-02-09 23:24:47 +0900191
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192 t = xfrm_state_alloc();
193 if (t == NULL)
194 goto out;
195
196 t->id.proto = IPPROTO_IPIP;
197 t->id.spi = x->props.saddr.a4;
198 t->id.daddr.a4 = x->id.daddr.a4;
199 memcpy(&t->sel, &x->sel, sizeof(t->sel));
200 t->props.family = AF_INET;
Herbert Xue40b3282007-11-13 21:39:08 -0800201 t->props.mode = x->props.mode;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202 t->props.saddr.a4 = x->props.saddr.a4;
203 t->props.flags = x->props.flags;
Herbert Xu72cb6962005-06-20 13:18:08 -0700204
205 if (xfrm_init_state(t))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206 goto error;
207
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208 atomic_set(&t->tunnel_users, 1);
209out:
210 return t;
211
212error:
213 t->km.state = XFRM_STATE_DEAD;
214 xfrm_state_put(t);
215 t = NULL;
216 goto out;
217}
218
219/*
Arjan van de Ven4a3e2f72006-03-20 22:33:17 -0800220 * Must be protected by xfrm_cfg_mutex. State and tunnel user references are
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221 * always incremented on success.
222 */
223static int ipcomp_tunnel_attach(struct xfrm_state *x)
224{
225 int err = 0;
226 struct xfrm_state *t;
227
228 t = xfrm_state_lookup((xfrm_address_t *)&x->id.daddr.a4,
YOSHIFUJI Hideakie905a9e2007-02-09 23:24:47 +0900229 x->props.saddr.a4, IPPROTO_IPIP, AF_INET);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230 if (!t) {
231 t = ipcomp_tunnel_create(x);
232 if (!t) {
233 err = -EINVAL;
234 goto out;
235 }
236 xfrm_state_insert(t);
237 xfrm_state_hold(t);
238 }
239 x->tunnel = t;
240 atomic_inc(&t->tunnel_users);
241out:
242 return err;
243}
244
245static void ipcomp_free_scratches(void)
246{
247 int i;
248 void **scratches;
249
250 if (--ipcomp_scratch_users)
251 return;
252
253 scratches = ipcomp_scratches;
254 if (!scratches)
255 return;
256
Jesper Juhl63903ca2006-04-18 14:51:44 -0700257 for_each_possible_cpu(i)
258 vfree(*per_cpu_ptr(scratches, i));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259
260 free_percpu(scratches);
261}
262
263static void **ipcomp_alloc_scratches(void)
264{
265 int i;
266 void **scratches;
267
268 if (ipcomp_scratch_users++)
269 return ipcomp_scratches;
270
271 scratches = alloc_percpu(void *);
272 if (!scratches)
273 return NULL;
274
275 ipcomp_scratches = scratches;
276
KAMEZAWA Hiroyuki6f912042006-04-10 22:52:50 -0700277 for_each_possible_cpu(i) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278 void *scratch = vmalloc(IPCOMP_SCRATCH_SIZE);
279 if (!scratch)
280 return NULL;
281 *per_cpu_ptr(scratches, i) = scratch;
282 }
283
284 return scratches;
285}
286
Herbert Xue4d5b792006-08-26 18:12:40 +1000287static void ipcomp_free_tfms(struct crypto_comp **tfms)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288{
289 struct ipcomp_tfms *pos;
290 int cpu;
291
292 list_for_each_entry(pos, &ipcomp_tfms_list, list) {
293 if (pos->tfms == tfms)
294 break;
295 }
296
297 BUG_TRAP(pos);
298
299 if (--pos->users)
300 return;
301
302 list_del(&pos->list);
303 kfree(pos);
304
305 if (!tfms)
306 return;
307
KAMEZAWA Hiroyuki6f912042006-04-10 22:52:50 -0700308 for_each_possible_cpu(cpu) {
Herbert Xue4d5b792006-08-26 18:12:40 +1000309 struct crypto_comp *tfm = *per_cpu_ptr(tfms, cpu);
310 crypto_free_comp(tfm);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311 }
312 free_percpu(tfms);
313}
314
Herbert Xue4d5b792006-08-26 18:12:40 +1000315static struct crypto_comp **ipcomp_alloc_tfms(const char *alg_name)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316{
317 struct ipcomp_tfms *pos;
Herbert Xue4d5b792006-08-26 18:12:40 +1000318 struct crypto_comp **tfms;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319 int cpu;
320
321 /* This can be any valid CPU ID so we don't need locking. */
Herbert Xu6fc8b9e2005-08-18 14:36:59 -0700322 cpu = raw_smp_processor_id();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323
324 list_for_each_entry(pos, &ipcomp_tfms_list, list) {
Herbert Xue4d5b792006-08-26 18:12:40 +1000325 struct crypto_comp *tfm;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326
327 tfms = pos->tfms;
328 tfm = *per_cpu_ptr(tfms, cpu);
329
Herbert Xue4d5b792006-08-26 18:12:40 +1000330 if (!strcmp(crypto_comp_name(tfm), alg_name)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331 pos->users++;
332 return tfms;
333 }
334 }
335
336 pos = kmalloc(sizeof(*pos), GFP_KERNEL);
337 if (!pos)
338 return NULL;
339
340 pos->users = 1;
341 INIT_LIST_HEAD(&pos->list);
342 list_add(&pos->list, &ipcomp_tfms_list);
343
Herbert Xue4d5b792006-08-26 18:12:40 +1000344 pos->tfms = tfms = alloc_percpu(struct crypto_comp *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345 if (!tfms)
346 goto error;
347
KAMEZAWA Hiroyuki6f912042006-04-10 22:52:50 -0700348 for_each_possible_cpu(cpu) {
Herbert Xue4d5b792006-08-26 18:12:40 +1000349 struct crypto_comp *tfm = crypto_alloc_comp(alg_name, 0,
350 CRYPTO_ALG_ASYNC);
Herbert Xu4999f362007-11-07 02:21:47 -0800351 if (IS_ERR(tfm))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352 goto error;
353 *per_cpu_ptr(tfms, cpu) = tfm;
354 }
355
356 return tfms;
357
358error:
359 ipcomp_free_tfms(tfms);
360 return NULL;
361}
362
363static void ipcomp_free_data(struct ipcomp_data *ipcd)
364{
365 if (ipcd->tfms)
366 ipcomp_free_tfms(ipcd->tfms);
367 ipcomp_free_scratches();
368}
369
370static void ipcomp_destroy(struct xfrm_state *x)
371{
372 struct ipcomp_data *ipcd = x->data;
373 if (!ipcd)
374 return;
375 xfrm_state_delete_tunnel(x);
Arjan van de Ven4a3e2f72006-03-20 22:33:17 -0800376 mutex_lock(&ipcomp_resource_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377 ipcomp_free_data(ipcd);
Arjan van de Ven4a3e2f72006-03-20 22:33:17 -0800378 mutex_unlock(&ipcomp_resource_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379 kfree(ipcd);
380}
381
Herbert Xu72cb6962005-06-20 13:18:08 -0700382static int ipcomp_init_state(struct xfrm_state *x)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383{
384 int err;
385 struct ipcomp_data *ipcd;
386 struct xfrm_algo_desc *calg_desc;
387
388 err = -EINVAL;
389 if (!x->calg)
390 goto out;
391
392 if (x->encap)
393 goto out;
394
Herbert Xue40b3282007-11-13 21:39:08 -0800395 x->props.header_len = 0;
396 switch (x->props.mode) {
397 case XFRM_MODE_TRANSPORT:
398 break;
399 case XFRM_MODE_TUNNEL:
400 x->props.header_len += sizeof(struct iphdr);
401 break;
402 default:
403 goto out;
404 }
405
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406 err = -ENOMEM;
Panagiotis Issaris0da974f2006-07-21 14:51:30 -0700407 ipcd = kzalloc(sizeof(*ipcd), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408 if (!ipcd)
409 goto out;
410
Arjan van de Ven4a3e2f72006-03-20 22:33:17 -0800411 mutex_lock(&ipcomp_resource_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412 if (!ipcomp_alloc_scratches())
413 goto error;
414
415 ipcd->tfms = ipcomp_alloc_tfms(x->calg->alg_name);
416 if (!ipcd->tfms)
417 goto error;
Arjan van de Ven4a3e2f72006-03-20 22:33:17 -0800418 mutex_unlock(&ipcomp_resource_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419
Masahide NAKAMURA7e49e6d2006-09-22 15:05:15 -0700420 if (x->props.mode == XFRM_MODE_TUNNEL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421 err = ipcomp_tunnel_attach(x);
422 if (err)
423 goto error_tunnel;
424 }
425
426 calg_desc = xfrm_calg_get_byname(x->calg->alg_name, 0);
427 BUG_ON(!calg_desc);
428 ipcd->threshold = calg_desc->uinfo.comp.threshold;
429 x->data = ipcd;
430 err = 0;
431out:
432 return err;
433
434error_tunnel:
Arjan van de Ven4a3e2f72006-03-20 22:33:17 -0800435 mutex_lock(&ipcomp_resource_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436error:
437 ipcomp_free_data(ipcd);
Arjan van de Ven4a3e2f72006-03-20 22:33:17 -0800438 mutex_unlock(&ipcomp_resource_mutex);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439 kfree(ipcd);
440 goto out;
441}
442
Eric Dumazet533cb5b2008-01-30 19:11:50 -0800443static const struct xfrm_type ipcomp_type = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444 .description = "IPCOMP4",
445 .owner = THIS_MODULE,
446 .proto = IPPROTO_COMP,
447 .init_state = ipcomp_init_state,
448 .destructor = ipcomp_destroy,
449 .input = ipcomp_input,
450 .output = ipcomp_output
451};
452
453static struct net_protocol ipcomp4_protocol = {
454 .handler = xfrm4_rcv,
455 .err_handler = ipcomp4_err,
456 .no_policy = 1,
457};
458
459static int __init ipcomp4_init(void)
460{
461 if (xfrm_register_type(&ipcomp_type, AF_INET) < 0) {
462 printk(KERN_INFO "ipcomp init: can't add xfrm type\n");
463 return -EAGAIN;
464 }
465 if (inet_add_protocol(&ipcomp4_protocol, IPPROTO_COMP) < 0) {
466 printk(KERN_INFO "ipcomp init: can't add protocol\n");
467 xfrm_unregister_type(&ipcomp_type, AF_INET);
468 return -EAGAIN;
469 }
470 return 0;
471}
472
473static void __exit ipcomp4_fini(void)
474{
475 if (inet_del_protocol(&ipcomp4_protocol, IPPROTO_COMP) < 0)
476 printk(KERN_INFO "ip ipcomp close: can't remove protocol\n");
477 if (xfrm_unregister_type(&ipcomp_type, AF_INET) < 0)
478 printk(KERN_INFO "ip ipcomp close: can't remove xfrm type\n");
479}
480
481module_init(ipcomp4_init);
482module_exit(ipcomp4_fini);
483
484MODULE_LICENSE("GPL");
485MODULE_DESCRIPTION("IP Payload Compression Protocol (IPComp) - RFC3173");
486MODULE_AUTHOR("James Morris <jmorris@intercode.com.au>");
487
Masahide NAKAMURAd3d6dd32007-06-26 23:57:49 -0700488MODULE_ALIAS_XFRM_TYPE(AF_INET, XFRM_PROTO_COMP);