ppp_deflate.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654
  1. /*
  2. * ==FILEVERSION 980319==
  3. *
  4. * ppp_deflate.c - interface the zlib procedures for Deflate compression
  5. * and decompression (as used by gzip) to the PPP code.
  6. * This version is for use with Linux kernel 1.3.X.
  7. *
  8. * Copyright (c) 1994 The Australian National University.
  9. * All rights reserved.
  10. *
  11. * Permission to use, copy, modify, and distribute this software and its
  12. * documentation is hereby granted, provided that the above copyright
  13. * notice appears in all copies. This software is provided without any
  14. * warranty, express or implied. The Australian National University
  15. * makes no representations about the suitability of this software for
  16. * any purpose.
  17. *
  18. * IN NO EVENT SHALL THE AUSTRALIAN NATIONAL UNIVERSITY BE LIABLE TO ANY
  19. * PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
  20. * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
  21. * THE AUSTRALIAN NATIONAL UNIVERSITY HAS BEEN ADVISED OF THE POSSIBILITY
  22. * OF SUCH DAMAGE.
  23. *
  24. * THE AUSTRALIAN NATIONAL UNIVERSITY SPECIFICALLY DISCLAIMS ANY WARRANTIES,
  25. * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
  26. * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
  27. * ON AN "AS IS" BASIS, AND THE AUSTRALIAN NATIONAL UNIVERSITY HAS NO
  28. * OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS,
  29. * OR MODIFICATIONS.
  30. *
  31. * From: deflate.c,v 1.1 1996/01/18 03:17:48 paulus Exp
  32. */
  33. #include <linux/module.h>
  34. #include <linux/slab.h>
  35. #include <linux/vmalloc.h>
  36. #include <linux/init.h>
  37. #include <linux/string.h>
  38. #include <linux/ppp_defs.h>
  39. #include <linux/ppp-comp.h>
  40. #include <linux/zlib.h>
  41. #include <asm/unaligned.h>
  42. /*
  43. * State for a Deflate (de)compressor.
  44. */
  45. struct ppp_deflate_state {
  46. int seqno;
  47. int w_size;
  48. int unit;
  49. int mru;
  50. int debug;
  51. z_stream strm;
  52. struct compstat stats;
  53. };
  54. #define DEFLATE_OVHD 2 /* Deflate overhead/packet */
  55. static void *z_comp_alloc(unsigned char *options, int opt_len);
  56. static void *z_decomp_alloc(unsigned char *options, int opt_len);
  57. static void z_comp_free(void *state);
  58. static void z_decomp_free(void *state);
  59. static int z_comp_init(void *state, unsigned char *options,
  60. int opt_len,
  61. int unit, int hdrlen, int debug);
  62. static int z_decomp_init(void *state, unsigned char *options,
  63. int opt_len,
  64. int unit, int hdrlen, int mru, int debug);
  65. static int z_compress(void *state, unsigned char *rptr,
  66. unsigned char *obuf,
  67. int isize, int osize);
  68. static void z_incomp(void *state, unsigned char *ibuf, int icnt);
  69. static int z_decompress(void *state, unsigned char *ibuf,
  70. int isize, unsigned char *obuf, int osize);
  71. static void z_comp_reset(void *state);
  72. static void z_decomp_reset(void *state);
  73. static void z_comp_stats(void *state, struct compstat *stats);
  74. /**
  75. * z_comp_free - free the memory used by a compressor
  76. * @arg: pointer to the private state for the compressor.
  77. */
  78. static void z_comp_free(void *arg)
  79. {
  80. struct ppp_deflate_state *state = (struct ppp_deflate_state *) arg;
  81. if (state) {
  82. zlib_deflateEnd(&state->strm);
  83. vfree(state->strm.workspace);
  84. kfree(state);
  85. }
  86. }
  87. /**
  88. * z_comp_alloc - allocate space for a compressor.
  89. * @options: pointer to CCP option data
  90. * @opt_len: length of the CCP option at @options.
  91. *
  92. * The @options pointer points to the a buffer containing the
  93. * CCP option data for the compression being negotiated. It is
  94. * formatted according to RFC1979, and describes the window
  95. * size that the peer is requesting that we use in compressing
  96. * data to be sent to it.
  97. *
  98. * Returns the pointer to the private state for the compressor,
  99. * or NULL if we could not allocate enough memory.
  100. */
  101. static void *z_comp_alloc(unsigned char *options, int opt_len)
  102. {
  103. struct ppp_deflate_state *state;
  104. int w_size;
  105. if (opt_len != CILEN_DEFLATE ||
  106. (options[0] != CI_DEFLATE && options[0] != CI_DEFLATE_DRAFT) ||
  107. options[1] != CILEN_DEFLATE ||
  108. DEFLATE_METHOD(options[2]) != DEFLATE_METHOD_VAL ||
  109. options[3] != DEFLATE_CHK_SEQUENCE)
  110. return NULL;
  111. w_size = DEFLATE_SIZE(options[2]);
  112. if (w_size < DEFLATE_MIN_SIZE || w_size > DEFLATE_MAX_SIZE)
  113. return NULL;
  114. state = kzalloc(sizeof(*state),
  115. GFP_KERNEL);
  116. if (state == NULL)
  117. return NULL;
  118. state->strm.next_in = NULL;
  119. state->w_size = w_size;
  120. state->strm.workspace = vmalloc(zlib_deflate_workspacesize(-w_size, 8));
  121. if (state->strm.workspace == NULL)
  122. goto out_free;
  123. if (zlib_deflateInit2(&state->strm, Z_DEFAULT_COMPRESSION,
  124. DEFLATE_METHOD_VAL, -w_size, 8, Z_DEFAULT_STRATEGY)
  125. != Z_OK)
  126. goto out_free;
  127. return (void *) state;
  128. out_free:
  129. z_comp_free(state);
  130. return NULL;
  131. }
  132. /**
  133. * z_comp_init - initialize a previously-allocated compressor.
  134. * @arg: pointer to the private state for the compressor
  135. * @options: pointer to the CCP option data describing the
  136. * compression that was negotiated with the peer
  137. * @opt_len: length of the CCP option data at @options
  138. * @unit: PPP unit number for diagnostic messages
  139. * @hdrlen: ignored (present for backwards compatibility)
  140. * @debug: debug flag; if non-zero, debug messages are printed.
  141. *
  142. * The CCP options described by @options must match the options
  143. * specified when the compressor was allocated. The compressor
  144. * history is reset. Returns 0 for failure (CCP options don't
  145. * match) or 1 for success.
  146. */
  147. static int z_comp_init(void *arg, unsigned char *options, int opt_len,
  148. int unit, int hdrlen, int debug)
  149. {
  150. struct ppp_deflate_state *state = (struct ppp_deflate_state *) arg;
  151. if (opt_len < CILEN_DEFLATE ||
  152. (options[0] != CI_DEFLATE && options[0] != CI_DEFLATE_DRAFT) ||
  153. options[1] != CILEN_DEFLATE ||
  154. DEFLATE_METHOD(options[2]) != DEFLATE_METHOD_VAL ||
  155. DEFLATE_SIZE(options[2]) != state->w_size ||
  156. options[3] != DEFLATE_CHK_SEQUENCE)
  157. return 0;
  158. state->seqno = 0;
  159. state->unit = unit;
  160. state->debug = debug;
  161. zlib_deflateReset(&state->strm);
  162. return 1;
  163. }
  164. /**
  165. * z_comp_reset - reset a previously-allocated compressor.
  166. * @arg: pointer to private state for the compressor.
  167. *
  168. * This clears the history for the compressor and makes it
  169. * ready to start emitting a new compressed stream.
  170. */
  171. static void z_comp_reset(void *arg)
  172. {
  173. struct ppp_deflate_state *state = (struct ppp_deflate_state *) arg;
  174. state->seqno = 0;
  175. zlib_deflateReset(&state->strm);
  176. }
  177. /**
  178. * z_compress - compress a PPP packet with Deflate compression.
  179. * @arg: pointer to private state for the compressor
  180. * @rptr: uncompressed packet (input)
  181. * @obuf: compressed packet (output)
  182. * @isize: size of uncompressed packet
  183. * @osize: space available at @obuf
  184. *
  185. * Returns the length of the compressed packet, or 0 if the
  186. * packet is incompressible.
  187. */
  188. static int z_compress(void *arg, unsigned char *rptr, unsigned char *obuf,
  189. int isize, int osize)
  190. {
  191. struct ppp_deflate_state *state = (struct ppp_deflate_state *) arg;
  192. int r, proto, off, olen, oavail;
  193. unsigned char *wptr;
  194. /*
  195. * Check that the protocol is in the range we handle.
  196. */
  197. proto = PPP_PROTOCOL(rptr);
  198. if (proto > 0x3fff || proto == 0xfd || proto == 0xfb)
  199. return 0;
  200. /* Don't generate compressed packets which are larger than
  201. the uncompressed packet. */
  202. if (osize > isize)
  203. osize = isize;
  204. wptr = obuf;
  205. /*
  206. * Copy over the PPP header and store the 2-byte sequence number.
  207. */
  208. wptr[0] = PPP_ADDRESS(rptr);
  209. wptr[1] = PPP_CONTROL(rptr);
  210. put_unaligned_be16(PPP_COMP, wptr + 2);
  211. wptr += PPP_HDRLEN;
  212. put_unaligned_be16(state->seqno, wptr);
  213. wptr += DEFLATE_OVHD;
  214. olen = PPP_HDRLEN + DEFLATE_OVHD;
  215. state->strm.next_out = wptr;
  216. state->strm.avail_out = oavail = osize - olen;
  217. ++state->seqno;
  218. off = (proto > 0xff) ? 2 : 3; /* skip 1st proto byte if 0 */
  219. rptr += off;
  220. state->strm.next_in = rptr;
  221. state->strm.avail_in = (isize - off);
  222. for (;;) {
  223. r = zlib_deflate(&state->strm, Z_PACKET_FLUSH);
  224. if (r != Z_OK) {
  225. if (state->debug)
  226. printk(KERN_ERR
  227. "z_compress: deflate returned %d\n", r);
  228. break;
  229. }
  230. if (state->strm.avail_out == 0) {
  231. olen += oavail;
  232. state->strm.next_out = NULL;
  233. state->strm.avail_out = oavail = 1000000;
  234. } else {
  235. break; /* all done */
  236. }
  237. }
  238. olen += oavail - state->strm.avail_out;
  239. /*
  240. * See if we managed to reduce the size of the packet.
  241. */
  242. if (olen < isize) {
  243. state->stats.comp_bytes += olen;
  244. state->stats.comp_packets++;
  245. } else {
  246. state->stats.inc_bytes += isize;
  247. state->stats.inc_packets++;
  248. olen = 0;
  249. }
  250. state->stats.unc_bytes += isize;
  251. state->stats.unc_packets++;
  252. return olen;
  253. }
  254. /**
  255. * z_comp_stats - return compression statistics for a compressor
  256. * or decompressor.
  257. * @arg: pointer to private space for the (de)compressor
  258. * @stats: pointer to a struct compstat to receive the result.
  259. */
  260. static void z_comp_stats(void *arg, struct compstat *stats)
  261. {
  262. struct ppp_deflate_state *state = (struct ppp_deflate_state *) arg;
  263. *stats = state->stats;
  264. }
  265. /**
  266. * z_decomp_free - Free the memory used by a decompressor.
  267. * @arg: pointer to private space for the decompressor.
  268. */
  269. static void z_decomp_free(void *arg)
  270. {
  271. struct ppp_deflate_state *state = (struct ppp_deflate_state *) arg;
  272. if (state) {
  273. zlib_inflateEnd(&state->strm);
  274. vfree(state->strm.workspace);
  275. kfree(state);
  276. }
  277. }
  278. /**
  279. * z_decomp_alloc - allocate space for a decompressor.
  280. * @options: pointer to CCP option data
  281. * @opt_len: length of the CCP option at @options.
  282. *
  283. * The @options pointer points to the a buffer containing the
  284. * CCP option data for the compression being negotiated. It is
  285. * formatted according to RFC1979, and describes the window
  286. * size that we are requesting the peer to use in compressing
  287. * data to be sent to us.
  288. *
  289. * Returns the pointer to the private state for the decompressor,
  290. * or NULL if we could not allocate enough memory.
  291. */
  292. static void *z_decomp_alloc(unsigned char *options, int opt_len)
  293. {
  294. struct ppp_deflate_state *state;
  295. int w_size;
  296. if (opt_len != CILEN_DEFLATE ||
  297. (options[0] != CI_DEFLATE && options[0] != CI_DEFLATE_DRAFT) ||
  298. options[1] != CILEN_DEFLATE ||
  299. DEFLATE_METHOD(options[2]) != DEFLATE_METHOD_VAL ||
  300. options[3] != DEFLATE_CHK_SEQUENCE)
  301. return NULL;
  302. w_size = DEFLATE_SIZE(options[2]);
  303. if (w_size < DEFLATE_MIN_SIZE || w_size > DEFLATE_MAX_SIZE)
  304. return NULL;
  305. state = kzalloc(sizeof(*state), GFP_KERNEL);
  306. if (state == NULL)
  307. return NULL;
  308. state->w_size = w_size;
  309. state->strm.next_out = NULL;
  310. state->strm.workspace = vmalloc(zlib_inflate_workspacesize());
  311. if (state->strm.workspace == NULL)
  312. goto out_free;
  313. if (zlib_inflateInit2(&state->strm, -w_size) != Z_OK)
  314. goto out_free;
  315. return (void *) state;
  316. out_free:
  317. z_decomp_free(state);
  318. return NULL;
  319. }
  320. /**
  321. * z_decomp_init - initialize a previously-allocated decompressor.
  322. * @arg: pointer to the private state for the decompressor
  323. * @options: pointer to the CCP option data describing the
  324. * compression that was negotiated with the peer
  325. * @opt_len: length of the CCP option data at @options
  326. * @unit: PPP unit number for diagnostic messages
  327. * @hdrlen: ignored (present for backwards compatibility)
  328. * @mru: maximum length of decompressed packets
  329. * @debug: debug flag; if non-zero, debug messages are printed.
  330. *
  331. * The CCP options described by @options must match the options
  332. * specified when the decompressor was allocated. The decompressor
  333. * history is reset. Returns 0 for failure (CCP options don't
  334. * match) or 1 for success.
  335. */
  336. static int z_decomp_init(void *arg, unsigned char *options, int opt_len,
  337. int unit, int hdrlen, int mru, int debug)
  338. {
  339. struct ppp_deflate_state *state = (struct ppp_deflate_state *) arg;
  340. if (opt_len < CILEN_DEFLATE ||
  341. (options[0] != CI_DEFLATE && options[0] != CI_DEFLATE_DRAFT) ||
  342. options[1] != CILEN_DEFLATE ||
  343. DEFLATE_METHOD(options[2]) != DEFLATE_METHOD_VAL ||
  344. DEFLATE_SIZE(options[2]) != state->w_size ||
  345. options[3] != DEFLATE_CHK_SEQUENCE)
  346. return 0;
  347. state->seqno = 0;
  348. state->unit = unit;
  349. state->debug = debug;
  350. state->mru = mru;
  351. zlib_inflateReset(&state->strm);
  352. return 1;
  353. }
  354. /**
  355. * z_decomp_reset - reset a previously-allocated decompressor.
  356. * @arg: pointer to private state for the decompressor.
  357. *
  358. * This clears the history for the decompressor and makes it
  359. * ready to receive a new compressed stream.
  360. */
  361. static void z_decomp_reset(void *arg)
  362. {
  363. struct ppp_deflate_state *state = (struct ppp_deflate_state *) arg;
  364. state->seqno = 0;
  365. zlib_inflateReset(&state->strm);
  366. }
  367. /**
  368. * z_decompress - decompress a Deflate-compressed packet.
  369. * @arg: pointer to private state for the decompressor
  370. * @ibuf: pointer to input (compressed) packet data
  371. * @isize: length of input packet
  372. * @obuf: pointer to space for output (decompressed) packet
  373. * @osize: amount of space available at @obuf
  374. *
  375. * Because of patent problems, we return DECOMP_ERROR for errors
  376. * found by inspecting the input data and for system problems, but
  377. * DECOMP_FATALERROR for any errors which could possibly be said to
  378. * be being detected "after" decompression. For DECOMP_ERROR,
  379. * we can issue a CCP reset-request; for DECOMP_FATALERROR, we may be
  380. * infringing a patent of Motorola's if we do, so we take CCP down
  381. * instead.
  382. *
  383. * Given that the frame has the correct sequence number and a good FCS,
  384. * errors such as invalid codes in the input most likely indicate a
  385. * bug, so we return DECOMP_FATALERROR for them in order to turn off
  386. * compression, even though they are detected by inspecting the input.
  387. */
  388. static int z_decompress(void *arg, unsigned char *ibuf, int isize,
  389. unsigned char *obuf, int osize)
  390. {
  391. struct ppp_deflate_state *state = (struct ppp_deflate_state *) arg;
  392. int olen, seq, r;
  393. int decode_proto, overflow;
  394. unsigned char overflow_buf[1];
  395. if (isize <= PPP_HDRLEN + DEFLATE_OVHD) {
  396. if (state->debug)
  397. printk(KERN_DEBUG "z_decompress%d: short pkt (%d)\n",
  398. state->unit, isize);
  399. return DECOMP_ERROR;
  400. }
  401. /* Check the sequence number. */
  402. seq = get_unaligned_be16(ibuf + PPP_HDRLEN);
  403. if (seq != (state->seqno & 0xffff)) {
  404. if (state->debug)
  405. printk(KERN_DEBUG "z_decompress%d: bad seq # %d, expected %d\n",
  406. state->unit, seq, state->seqno & 0xffff);
  407. return DECOMP_ERROR;
  408. }
  409. ++state->seqno;
  410. /*
  411. * Fill in the first part of the PPP header. The protocol field
  412. * comes from the decompressed data.
  413. */
  414. obuf[0] = PPP_ADDRESS(ibuf);
  415. obuf[1] = PPP_CONTROL(ibuf);
  416. obuf[2] = 0;
  417. /*
  418. * Set up to call inflate. We set avail_out to 1 initially so we can
  419. * look at the first byte of the output and decide whether we have
  420. * a 1-byte or 2-byte protocol field.
  421. */
  422. state->strm.next_in = ibuf + PPP_HDRLEN + DEFLATE_OVHD;
  423. state->strm.avail_in = isize - (PPP_HDRLEN + DEFLATE_OVHD);
  424. state->strm.next_out = obuf + 3;
  425. state->strm.avail_out = 1;
  426. decode_proto = 1;
  427. overflow = 0;
  428. /*
  429. * Call inflate, supplying more input or output as needed.
  430. */
  431. for (;;) {
  432. r = zlib_inflate(&state->strm, Z_PACKET_FLUSH);
  433. if (r != Z_OK) {
  434. if (state->debug)
  435. printk(KERN_DEBUG "z_decompress%d: inflate returned %d (%s)\n",
  436. state->unit, r, (state->strm.msg? state->strm.msg: ""));
  437. return DECOMP_FATALERROR;
  438. }
  439. if (state->strm.avail_out != 0)
  440. break; /* all done */
  441. if (decode_proto) {
  442. state->strm.avail_out = osize - PPP_HDRLEN;
  443. if ((obuf[3] & 1) == 0) {
  444. /* 2-byte protocol field */
  445. obuf[2] = obuf[3];
  446. --state->strm.next_out;
  447. ++state->strm.avail_out;
  448. }
  449. decode_proto = 0;
  450. } else if (!overflow) {
  451. /*
  452. * We've filled up the output buffer; the only way to
  453. * find out whether inflate has any more characters
  454. * left is to give it another byte of output space.
  455. */
  456. state->strm.next_out = overflow_buf;
  457. state->strm.avail_out = 1;
  458. overflow = 1;
  459. } else {
  460. if (state->debug)
  461. printk(KERN_DEBUG "z_decompress%d: ran out of mru\n",
  462. state->unit);
  463. return DECOMP_FATALERROR;
  464. }
  465. }
  466. if (decode_proto) {
  467. if (state->debug)
  468. printk(KERN_DEBUG "z_decompress%d: didn't get proto\n",
  469. state->unit);
  470. return DECOMP_ERROR;
  471. }
  472. olen = osize + overflow - state->strm.avail_out;
  473. state->stats.unc_bytes += olen;
  474. state->stats.unc_packets++;
  475. state->stats.comp_bytes += isize;
  476. state->stats.comp_packets++;
  477. return olen;
  478. }
  479. /**
  480. * z_incomp - add incompressible input data to the history.
  481. * @arg: pointer to private state for the decompressor
  482. * @ibuf: pointer to input packet data
  483. * @icnt: length of input data.
  484. */
  485. static void z_incomp(void *arg, unsigned char *ibuf, int icnt)
  486. {
  487. struct ppp_deflate_state *state = (struct ppp_deflate_state *) arg;
  488. int proto, r;
  489. /*
  490. * Check that the protocol is one we handle.
  491. */
  492. proto = PPP_PROTOCOL(ibuf);
  493. if (proto > 0x3fff || proto == 0xfd || proto == 0xfb)
  494. return;
  495. ++state->seqno;
  496. /*
  497. * We start at the either the 1st or 2nd byte of the protocol field,
  498. * depending on whether the protocol value is compressible.
  499. */
  500. state->strm.next_in = ibuf + 3;
  501. state->strm.avail_in = icnt - 3;
  502. if (proto > 0xff) {
  503. --state->strm.next_in;
  504. ++state->strm.avail_in;
  505. }
  506. r = zlib_inflateIncomp(&state->strm);
  507. if (r != Z_OK) {
  508. /* gak! */
  509. if (state->debug) {
  510. printk(KERN_DEBUG "z_incomp%d: inflateIncomp returned %d (%s)\n",
  511. state->unit, r, (state->strm.msg? state->strm.msg: ""));
  512. }
  513. return;
  514. }
  515. /*
  516. * Update stats.
  517. */
  518. state->stats.inc_bytes += icnt;
  519. state->stats.inc_packets++;
  520. state->stats.unc_bytes += icnt;
  521. state->stats.unc_packets++;
  522. }
  523. /*************************************************************
  524. * Module interface table
  525. *************************************************************/
  526. /* These are in ppp_generic.c */
  527. extern int ppp_register_compressor (struct compressor *cp);
  528. extern void ppp_unregister_compressor (struct compressor *cp);
  529. /*
  530. * Procedures exported to if_ppp.c.
  531. */
  532. static struct compressor ppp_deflate = {
  533. .compress_proto = CI_DEFLATE,
  534. .comp_alloc = z_comp_alloc,
  535. .comp_free = z_comp_free,
  536. .comp_init = z_comp_init,
  537. .comp_reset = z_comp_reset,
  538. .compress = z_compress,
  539. .comp_stat = z_comp_stats,
  540. .decomp_alloc = z_decomp_alloc,
  541. .decomp_free = z_decomp_free,
  542. .decomp_init = z_decomp_init,
  543. .decomp_reset = z_decomp_reset,
  544. .decompress = z_decompress,
  545. .incomp = z_incomp,
  546. .decomp_stat = z_comp_stats,
  547. .owner = THIS_MODULE
  548. };
  549. static struct compressor ppp_deflate_draft = {
  550. .compress_proto = CI_DEFLATE_DRAFT,
  551. .comp_alloc = z_comp_alloc,
  552. .comp_free = z_comp_free,
  553. .comp_init = z_comp_init,
  554. .comp_reset = z_comp_reset,
  555. .compress = z_compress,
  556. .comp_stat = z_comp_stats,
  557. .decomp_alloc = z_decomp_alloc,
  558. .decomp_free = z_decomp_free,
  559. .decomp_init = z_decomp_init,
  560. .decomp_reset = z_decomp_reset,
  561. .decompress = z_decompress,
  562. .incomp = z_incomp,
  563. .decomp_stat = z_comp_stats,
  564. .owner = THIS_MODULE
  565. };
  566. static int __init deflate_init(void)
  567. {
  568. int answer = ppp_register_compressor(&ppp_deflate);
  569. if (answer == 0)
  570. printk(KERN_INFO
  571. "PPP Deflate Compression module registered\n");
  572. ppp_register_compressor(&ppp_deflate_draft);
  573. return answer;
  574. }
  575. static void __exit deflate_cleanup(void)
  576. {
  577. ppp_unregister_compressor(&ppp_deflate);
  578. ppp_unregister_compressor(&ppp_deflate_draft);
  579. }
  580. module_init(deflate_init);
  581. module_exit(deflate_cleanup);
  582. MODULE_LICENSE("Dual BSD/GPL");
  583. MODULE_ALIAS("ppp-compress-" __stringify(CI_DEFLATE));
  584. MODULE_ALIAS("ppp-compress-" __stringify(CI_DEFLATE_DRAFT));