ppp_deflate.c 19 KB

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