X-Git-Url: http://git.ozlabs.org/?p=ppp.git;a=blobdiff_plain;f=linux%2Fppp_deflate.c;h=1b13f71e7cc183e4d4d467d68ccfbf5634e8eab7;hp=bd2234277475917e6a73f2206356f482e5050104;hb=7f417198cd0911ddbd890565298a4a400e09cae2;hpb=6df1318f7c7c2afa76293e90671aac884488a19d diff --git a/linux/ppp_deflate.c b/linux/ppp_deflate.c index bd22342..1b13f71 100644 --- a/linux/ppp_deflate.c +++ b/linux/ppp_deflate.c @@ -1,32 +1,40 @@ /* - * ==FILEVERSION 971001== + * ==FILEVERSION 980319== * * ppp_deflate.c - interface the zlib procedures for Deflate compression * and decompression (as used by gzip) to the PPP code. - * This version is for use with Linux kernel 1.3.X. + * This version is for use with Linux kernel 1.3.X and later. * - * Copyright (c) 1994 The Australian National University. - * All rights reserved. + * Copyright (c) 1994 Paul Mackerras. All rights reserved. * - * Permission to use, copy, modify, and distribute this software and its - * documentation is hereby granted, provided that the above copyright - * notice appears in all copies. This software is provided without any - * warranty, express or implied. The Australian National University - * makes no representations about the suitability of this software for - * any purpose. + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: * - * IN NO EVENT SHALL THE AUSTRALIAN NATIONAL UNIVERSITY BE LIABLE TO ANY - * PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES - * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF - * THE AUSTRALIAN NATIONAL UNIVERSITY HAS BEEN ADVISED OF THE POSSIBILITY - * OF SUCH DAMAGE. + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. * - * THE AUSTRALIAN NATIONAL UNIVERSITY SPECIFICALLY DISCLAIMS ANY WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY - * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS - * ON AN "AS IS" BASIS, AND THE AUSTRALIAN NATIONAL UNIVERSITY HAS NO - * OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, - * OR MODIFICATIONS. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * 3. The name(s) of the authors of this software must not be used to + * endorse or promote products derived from this software without + * prior written permission. + * + * 4. Redistributions of any form whatsoever must retain the following + * acknowledgment: + * "This product includes software developed by Paul Mackerras + * ". + * + * THE AUTHORS OF THIS SOFTWARE DISCLAIM ALL WARRANTIES WITH REGARD TO + * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY + * AND FITNESS, IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY + * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN + * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING + * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * * From: deflate.c,v 1.1 1996/01/18 03:17:48 paulus Exp */ @@ -197,7 +205,8 @@ z_comp_alloc(options, opt_len) struct ppp_deflate_state *state; int w_size; - if (opt_len != CILEN_DEFLATE || options[0] != CI_DEFLATE + if (opt_len != CILEN_DEFLATE + || (options[0] != CI_DEFLATE && options[0] != CI_DEFLATE_DRAFT) || options[1] != CILEN_DEFLATE || DEFLATE_METHOD(options[2]) != DEFLATE_METHOD_VAL || options[3] != DEFLATE_CHK_SEQUENCE) @@ -219,13 +228,15 @@ z_comp_alloc(options, opt_len) if (deflateInit2(&state->strm, Z_DEFAULT_COMPRESSION, DEFLATE_METHOD_VAL, -w_size, 8, Z_DEFAULT_STRATEGY) - != Z_OK) { - z_comp_free(state); - return NULL; - } - + != Z_OK) + goto out_free; state->strm.zalloc = zalloc; return (void *) state; + +out_free: + z_comp_free(state); + MOD_DEC_USE_COUNT; + return NULL; } static int @@ -236,7 +247,8 @@ z_comp_init(arg, options, opt_len, unit, hdrlen, debug) { struct ppp_deflate_state *state = (struct ppp_deflate_state *) arg; - if (opt_len < CILEN_DEFLATE || options[0] != CI_DEFLATE + if (opt_len < CILEN_DEFLATE + || (options[0] != CI_DEFLATE && options[0] != CI_DEFLATE_DRAFT) || options[1] != CILEN_DEFLATE || DEFLATE_METHOD(options[2]) != DEFLATE_METHOD_VAL || DEFLATE_SIZE(options[2]) != state->w_size @@ -270,7 +282,7 @@ z_compress(arg, rptr, obuf, isize, osize) int isize, osize; { struct ppp_deflate_state *state = (struct ppp_deflate_state *) arg; - int r, proto, off, olen; + int r, proto, off, olen, oavail; unsigned char *wptr; /* @@ -297,9 +309,10 @@ z_compress(arg, rptr, obuf, isize, osize) wptr += PPP_HDRLEN; wptr[0] = state->seqno >> 8; wptr[1] = state->seqno; - wptr += 2; + wptr += DEFLATE_OVHD; + olen = PPP_HDRLEN + DEFLATE_OVHD; state->strm.next_out = wptr; - state->strm.avail_out = osize - (PPP_HDRLEN + 2); + state->strm.avail_out = oavail = osize - olen; ++state->seqno; off = (proto > 0xff) ? 2 : 3; /* skip 1st proto byte if 0 */ @@ -307,25 +320,23 @@ z_compress(arg, rptr, obuf, isize, osize) state->strm.next_in = rptr; state->strm.avail_in = (isize - off); - olen = 0; for (;;) { r = deflate(&state->strm, Z_PACKET_FLUSH); if (r != Z_OK) { if (state->debug) - printk(KERN_DEBUG "z_compress: deflate returned %d (%s)\n", - r, (state->strm.msg? state->strm.msg: "")); + printk(KERN_ERR + "z_compress: deflate returned %d\n", r); break; } if (state->strm.avail_out == 0) { - olen += osize; + olen += oavail; state->strm.next_out = NULL; - state->strm.avail_out = 1000000; + state->strm.avail_out = oavail = 1000000; } else { break; /* all done */ } } - if (olen < osize) - olen += osize - state->strm.avail_out; + olen += oavail - state->strm.avail_out; /* * See if we managed to reduce the size of the packet. @@ -378,7 +389,8 @@ z_decomp_alloc(options, opt_len) struct ppp_deflate_state *state; int w_size; - if (opt_len != CILEN_DEFLATE || options[0] != CI_DEFLATE + if (opt_len != CILEN_DEFLATE + || (options[0] != CI_DEFLATE && options[0] != CI_DEFLATE_DRAFT) || options[1] != CILEN_DEFLATE || DEFLATE_METHOD(options[2]) != DEFLATE_METHOD_VAL || options[3] != DEFLATE_CHK_SEQUENCE) @@ -398,13 +410,15 @@ z_decomp_alloc(options, opt_len) state->strm.zalloc = zalloc_init; state->strm.zfree = zfree; - if (inflateInit2(&state->strm, -w_size) != Z_OK) { - z_decomp_free(state); - return NULL; - } - + if (inflateInit2(&state->strm, -w_size) != Z_OK) + goto out_free; state->strm.zalloc = zalloc; return (void *) state; + +out_free: + z_decomp_free(state); + MOD_DEC_USE_COUNT; + return NULL; } static int @@ -415,7 +429,8 @@ z_decomp_init(arg, options, opt_len, unit, hdrlen, mru, debug) { struct ppp_deflate_state *state = (struct ppp_deflate_state *) arg; - if (opt_len < CILEN_DEFLATE || options[0] != CI_DEFLATE + if (opt_len < CILEN_DEFLATE + || (options[0] != CI_DEFLATE && options[0] != CI_DEFLATE_DRAFT) || options[1] != CILEN_DEFLATE || DEFLATE_METHOD(options[2]) != DEFLATE_METHOD_VAL || DEFLATE_SIZE(options[2]) != state->w_size @@ -547,8 +562,12 @@ z_decompress(arg, ibuf, isize, obuf, osize) } } - if (decode_proto) + if (decode_proto) { + if (state->debug) + printk(KERN_DEBUG "z_decompress%d: didn't get proto\n", + state->unit); return DECOMP_ERROR; + } olen = osize + overflow - state->strm.avail_out; state->stats.unc_bytes += olen; @@ -638,6 +657,23 @@ struct compressor ppp_deflate = { z_comp_stats, /* decomp_stat */ }; +struct compressor ppp_deflate_draft = { + CI_DEFLATE_DRAFT, /* compress_proto */ + z_comp_alloc, /* comp_alloc */ + z_comp_free, /* comp_free */ + z_comp_init, /* comp_init */ + z_comp_reset, /* comp_reset */ + z_compress, /* compress */ + z_comp_stats, /* comp_stat */ + z_decomp_alloc, /* decomp_alloc */ + z_decomp_free, /* decomp_free */ + z_decomp_init, /* decomp_init */ + z_decomp_reset, /* decomp_reset */ + z_decompress, /* decompress */ + z_incomp, /* incomp */ + z_comp_stats, /* decomp_stat */ +}; + #ifdef MODULE /************************************************************* * Module support routines @@ -650,6 +686,7 @@ init_module(void) if (answer == 0) printk (KERN_INFO "PPP Deflate Compression module registered\n"); + ppp_register_compressor(&ppp_deflate_draft); return answer; } @@ -659,7 +696,9 @@ cleanup_module(void) if (MOD_IN_USE) printk (KERN_INFO "Deflate Compression module busy, remove delayed\n"); - else + else { ppp_unregister_compressor (&ppp_deflate); + ppp_unregister_compressor (&ppp_deflate_draft); + } } #endif