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