12 #include <linux/module.h>
13 #include <linux/slab.h>
16 #include <linux/string.h>
18 #include <linux/ppp_defs.h>
19 #include <linux/ppp-comp.h>
22 #include <asm/unaligned.h>
37 #define DEFLATE_OVHD 2
39 static void *z_comp_alloc(
unsigned char *
options,
int opt_len);
40 static void *z_decomp_alloc(
unsigned char *
options,
int opt_len);
41 static void z_comp_free(
void *
state);
42 static void z_decomp_free(
void *
state);
43 static int z_comp_init(
void *
state,
unsigned char *
options,
46 static int z_decomp_init(
void *
state,
unsigned char *
options,
49 static int z_compress(
void *
state,
unsigned char *
rptr,
51 int isize,
int osize);
52 static void z_incomp(
void *
state,
unsigned char *ibuf,
int icnt);
53 static int z_decompress(
void *
state,
unsigned char *ibuf,
54 int isize,
unsigned char *obuf,
int osize);
55 static void z_comp_reset(
void *
state);
56 static void z_decomp_reset(
void *
state);
63 static void z_comp_free(
void *
arg)
88 static void *z_comp_alloc(
unsigned char *
options,
int opt_len)
103 state = kzalloc(
sizeof(*state),
118 return (
void *)
state;
140 static int z_comp_init(
void *arg,
unsigned char *options,
int opt_len,
169 static void z_comp_reset(
void *arg)
188 static int z_compress(
void *arg,
unsigned char *
rptr,
unsigned char *obuf,
189 int isize,
int osize)
192 int r,
proto, off, olen, oavail;
199 if (proto > 0x3fff || proto == 0xfd || proto == 0xfb)
214 put_unaligned_be16(
PPP_COMP, wptr + 2);
216 put_unaligned_be16(state->
seqno, wptr);
223 off = (proto > 0xff) ? 2 : 3;
233 "z_compress: deflate returned %d\n", r);
250 state->
stats.comp_bytes += olen;
251 state->
stats.comp_packets++;
253 state->
stats.inc_bytes += isize;
254 state->
stats.inc_packets++;
257 state->
stats.unc_bytes += isize;
258 state->
stats.unc_packets++;
273 *stats = state->
stats;
280 static void z_decomp_free(
void *arg)
305 static void *z_decomp_alloc(
unsigned char *options,
int opt_len)
317 if (w_size < DEFLATE_MIN_SIZE || w_size > DEFLATE_MAX_SIZE)
332 return (
void *)
state;
335 z_decomp_free(state);
355 static int z_decomp_init(
void *arg,
unsigned char *options,
int opt_len,
356 int unit,
int hdrlen,
int mru,
int debug)
385 static void z_decomp_reset(
void *arg)
414 static int z_decompress(
void *arg,
unsigned char *ibuf,
int isize,
415 unsigned char *obuf,
int osize)
420 unsigned char overflow_buf[1];
431 if (seq != (state->
seqno & 0xffff)) {
434 state->
unit, seq, state->
seqno & 0xffff);
474 if ((obuf[3] & 1) == 0) {
481 }
else if (!overflow) {
506 state->
stats.unc_bytes += olen;
507 state->
stats.unc_packets++;
508 state->
stats.comp_bytes += isize;
509 state->
stats.comp_packets++;
520 static void z_incomp(
void *arg,
unsigned char *ibuf,
int icnt)
529 if (proto > 0x3fff || proto == 0xfd || proto == 0xfb)
559 state->
stats.inc_packets++;
561 state->
stats.unc_packets++;
577 .comp_alloc = z_comp_alloc,
578 .comp_free = z_comp_free,
579 .comp_init = z_comp_init,
580 .comp_reset = z_comp_reset,
581 .compress = z_compress,
582 .comp_stat = z_comp_stats,
583 .decomp_alloc = z_decomp_alloc,
584 .decomp_free = z_decomp_free,
585 .decomp_init = z_decomp_init,
586 .decomp_reset = z_decomp_reset,
587 .decompress = z_decompress,
589 .decomp_stat = z_comp_stats,
593 static struct compressor ppp_deflate_draft = {
595 .comp_alloc = z_comp_alloc,
596 .comp_free = z_comp_free,
597 .comp_init = z_comp_init,
598 .comp_reset = z_comp_reset,
599 .compress = z_compress,
600 .comp_stat = z_comp_stats,
601 .decomp_alloc = z_decomp_alloc,
602 .decomp_free = z_decomp_free,
603 .decomp_init = z_decomp_init,
604 .decomp_reset = z_decomp_reset,
605 .decompress = z_decompress,
607 .decomp_stat = z_comp_stats,
611 static int __init deflate_init(
void)
616 "PPP Deflate Compression module registered\n");
621 static void __exit deflate_cleanup(
void)