ppp_deflate.c 19 KB

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