]> git.ozlabs.org Git - ppp.git/blob - modules/deflate.c
prototype callback functions
[ppp.git] / modules / deflate.c
1 /*
2  * ppp_deflate.c - interface the zlib procedures for Deflate compression
3  * and decompression (as used by gzip) to the PPP code.
4  * This version is for use with STREAMS under SunOS 4.x, Solaris 2,
5  * SVR4, OSF/1 and AIX 4.x.
6  *
7  * Copyright (c) 1994 The Australian National University.
8  * All rights reserved.
9  *
10  * Permission to use, copy, modify, and distribute this software and its
11  * documentation is hereby granted, provided that the above copyright
12  * notice appears in all copies.  This software is provided without any
13  * warranty, express or implied. The Australian National University
14  * makes no representations about the suitability of this software for
15  * any purpose.
16  *
17  * IN NO EVENT SHALL THE AUSTRALIAN NATIONAL UNIVERSITY BE LIABLE TO ANY
18  * PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
19  * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
20  * THE AUSTRALIAN NATIONAL UNIVERSITY HAS BEEN ADVISED OF THE POSSIBILITY
21  * OF SUCH DAMAGE.
22  *
23  * THE AUSTRALIAN NATIONAL UNIVERSITY SPECIFICALLY DISCLAIMS ANY WARRANTIES,
24  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
25  * AND FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
26  * ON AN "AS IS" BASIS, AND THE AUSTRALIAN NATIONAL UNIVERSITY HAS NO
27  * OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS,
28  * OR MODIFICATIONS.
29  *
30  * $Id: deflate.c,v 1.5 1997/04/30 05:43:39 paulus Exp $
31  */
32
33 #ifdef AIX4
34 #include <net/net_globals.h>
35 #endif
36 #include <sys/param.h>
37 #include <sys/types.h>
38 #include <sys/stream.h>
39 #include <net/ppp_defs.h>
40 #include "ppp_mod.h"
41
42 #define PACKETPTR       mblk_t *
43 #include <net/ppp-comp.h>
44
45 #ifdef __osf__
46 #include "zlib.h"
47 #else
48 #include "common/zlib.h"
49 #endif
50
51 #if DO_DEFLATE
52
53 #define DEFLATE_DEBUG   1
54
55 /*
56  * State for a Deflate (de)compressor.
57  */
58 struct deflate_state {
59     int         seqno;
60     int         w_size;
61     int         unit;
62     int         hdrlen;
63     int         mru;
64     int         debug;
65     z_stream    strm;
66     struct compstat stats;
67 };
68
69 #define DEFLATE_OVHD    2               /* Deflate overhead/packet */
70
71 static void     *z_alloc __P((void *, u_int items, u_int size));
72 static void     *z_alloc_init __P((void *, u_int items, u_int size));
73 static void     z_free __P((void *, void *ptr, u_int nb));
74 static void     *z_comp_alloc __P((u_char *options, int opt_len));
75 static void     *z_decomp_alloc __P((u_char *options, int opt_len));
76 static void     z_comp_free __P((void *state));
77 static void     z_decomp_free __P((void *state));
78 static int      z_comp_init __P((void *state, u_char *options, int opt_len,
79                                  int unit, int hdrlen, int debug));
80 static int      z_decomp_init __P((void *state, u_char *options, int opt_len,
81                                      int unit, int hdrlen, int mru, int debug));
82 static int      z_compress __P((void *state, mblk_t **mret,
83                                   mblk_t *mp, int slen, int maxolen));
84 static void     z_incomp __P((void *state, mblk_t *dmsg));
85 static int      z_decompress __P((void *state, mblk_t *cmp,
86                                     mblk_t **dmpp));
87 static void     z_comp_reset __P((void *state));
88 static void     z_decomp_reset __P((void *state));
89 static void     z_comp_stats __P((void *state, struct compstat *stats));
90
91 /*
92  * Procedures exported to if_ppp.c.
93  */
94 struct compressor ppp_deflate = {
95     CI_DEFLATE,                 /* compress_proto */
96     z_comp_alloc,               /* comp_alloc */
97     z_comp_free,                /* comp_free */
98     z_comp_init,                /* comp_init */
99     z_comp_reset,               /* comp_reset */
100     z_compress,                 /* compress */
101     z_comp_stats,               /* comp_stat */
102     z_decomp_alloc,             /* decomp_alloc */
103     z_decomp_free,              /* decomp_free */
104     z_decomp_init,              /* decomp_init */
105     z_decomp_reset,             /* decomp_reset */
106     z_decompress,               /* decompress */
107     z_incomp,                   /* incomp */
108     z_comp_stats,               /* decomp_stat */
109 };
110
111 #define DECOMP_CHUNK    512
112
113 /*
114  * Space allocation and freeing routines for use by zlib routines.
115  */
116 static void *
117 z_alloc_init(notused, items, size)
118     void *notused;
119     u_int items, size;
120 {
121 #ifdef __osf__
122     return ALLOC_SLEEP(items * size);
123 #else
124     return ALLOC_NOSLEEP(items * size);
125 #endif
126 }
127
128 static void *
129 z_alloc(notused, items, size)
130     void *notused;
131     u_int items, size;
132 {
133     return ALLOC_NOSLEEP(items * size);
134 }
135
136 static void
137 z_free(notused, ptr, nbytes)
138     void *notused;
139     void *ptr;
140     u_int nbytes;
141 {
142     FREE(ptr, nbytes);
143 }
144
145 /*
146  * Allocate space for a compressor.
147  */
148 static void *
149 z_comp_alloc(options, opt_len)
150     u_char *options;
151     int opt_len;
152 {
153     struct deflate_state *state;
154     int w_size;
155
156     if (opt_len != CILEN_DEFLATE || options[0] != CI_DEFLATE
157         || options[1] != CILEN_DEFLATE
158         || DEFLATE_METHOD(options[2]) != DEFLATE_METHOD_VAL
159         || options[3] != DEFLATE_CHK_SEQUENCE)
160         return NULL;
161     w_size = DEFLATE_SIZE(options[2]);
162     if (w_size < DEFLATE_MIN_SIZE || w_size > DEFLATE_MAX_SIZE)
163         return NULL;
164
165
166 #ifdef __osf__
167     state = (struct deflate_state *) ALLOC_SLEEP(sizeof(*state));
168 #else
169     state = (struct deflate_state *) ALLOC_NOSLEEP(sizeof(*state));
170 #endif
171
172     if (state == NULL)
173         return NULL;
174
175     state->strm.next_in = NULL;
176     state->strm.zalloc = (alloc_func) z_alloc;
177     state->strm.zalloc_init = (alloc_func) z_alloc_init;
178     state->strm.zfree = (free_func) z_free;
179     if (deflateInit2(&state->strm, Z_DEFAULT_COMPRESSION, DEFLATE_METHOD_VAL,
180                      -w_size, 8, Z_DEFAULT_STRATEGY, DEFLATE_OVHD+2) != Z_OK) {
181         FREE(state, sizeof(*state));
182         return NULL;
183     }
184
185     state->w_size = w_size;
186     bzero(&state->stats, sizeof(state->stats));
187     return (void *) state;
188 }
189
190 static void
191 z_comp_free(arg)
192     void *arg;
193 {
194     struct deflate_state *state = (struct deflate_state *) arg;
195
196     deflateEnd(&state->strm);
197     FREE(state, sizeof(*state));
198 }
199
200 static int
201 z_comp_init(arg, options, opt_len, unit, hdrlen, debug)
202     void *arg;
203     u_char *options;
204     int opt_len, unit, hdrlen, debug;
205 {
206     struct deflate_state *state = (struct deflate_state *) arg;
207
208     if (opt_len < CILEN_DEFLATE || options[0] != CI_DEFLATE
209         || options[1] != CILEN_DEFLATE
210         || DEFLATE_METHOD(options[2]) != DEFLATE_METHOD_VAL
211         || DEFLATE_SIZE(options[2]) != state->w_size
212         || options[3] != DEFLATE_CHK_SEQUENCE)
213         return 0;
214
215     state->seqno = 0;
216     state->unit = unit;
217     state->hdrlen = hdrlen;
218     state->debug = debug;
219
220     deflateReset(&state->strm);
221
222     return 1;
223 }
224
225 static void
226 z_comp_reset(arg)
227     void *arg;
228 {
229     struct deflate_state *state = (struct deflate_state *) arg;
230
231     state->seqno = 0;
232     deflateReset(&state->strm);
233 }
234
235 static int
236 z_compress(arg, mret, mp, orig_len, maxolen)
237     void *arg;
238     mblk_t **mret;              /* compressed packet (out) */
239     mblk_t *mp;         /* uncompressed packet (in) */
240     int orig_len, maxolen;
241 {
242     struct deflate_state *state = (struct deflate_state *) arg;
243     u_char *rptr, *wptr;
244     int proto, olen, wspace, r, flush;
245     mblk_t *m;
246
247     /*
248      * Check that the protocol is in the range we handle.
249      */
250     *mret = NULL;
251     rptr = mp->b_rptr;
252     if (rptr + PPP_HDRLEN > mp->b_wptr) {
253         if (!pullupmsg(mp, PPP_HDRLEN))
254             return 0;
255         rptr = mp->b_rptr;
256     }
257     proto = PPP_PROTOCOL(rptr);
258     if (proto > 0x3fff || proto == 0xfd || proto == 0xfb)
259         return orig_len;
260
261     /* Allocate one mblk initially. */
262     if (maxolen > orig_len)
263         maxolen = orig_len;
264     wspace = maxolen < 4096? maxolen: 4096;
265     m = allocb(wspace, BPRI_MED);
266     if (m != NULL) {
267         *mret = m;
268         if (state->hdrlen + PPP_HDRLEN + 2 < wspace) {
269             m->b_rptr += state->hdrlen;
270             m->b_wptr = m->b_rptr;
271             wspace -= state->hdrlen;
272         }
273         wptr = m->b_wptr;
274
275         /*
276          * Copy over the PPP header and store the 2-byte sequence number.
277          */
278         wptr[0] = PPP_ADDRESS(rptr);
279         wptr[1] = PPP_CONTROL(rptr);
280         wptr[2] = PPP_COMP >> 8;
281         wptr[3] = PPP_COMP;
282         wptr += PPP_HDRLEN;
283         wptr[0] = state->seqno >> 8;
284         wptr[1] = state->seqno;
285         wptr += 2;
286         state->strm.next_out = wptr;
287         state->strm.avail_out = wspace - (PPP_HDRLEN + 2);
288     } else {
289         state->strm.next_out = NULL;
290         state->strm.avail_out = 1000000;
291     }
292     ++state->seqno;
293
294     rptr += (proto > 0xff)? 2: 3;       /* skip 1st proto byte if 0 */
295     state->strm.next_in = rptr;
296     state->strm.avail_in = mp->b_wptr - rptr;
297     mp = mp->b_cont;
298     flush = (mp == NULL)? Z_PACKET_FLUSH: Z_NO_FLUSH;
299     olen = 0;
300     for (;;) {
301         r = deflate(&state->strm, flush);
302         if (r != Z_OK) {
303             printf("z_compress: deflate returned %d (%s)\n",
304                    r, (state->strm.msg? state->strm.msg: ""));
305             break;
306         }
307         if (flush != Z_NO_FLUSH && state->strm.avail_out != 0)
308             break;              /* all done */
309         if (state->strm.avail_in == 0 && mp != NULL) {
310             state->strm.next_in = mp->b_rptr;
311             state->strm.avail_in = mp->b_wptr - mp->b_rptr;
312             mp = mp->b_cont;
313             if (mp == NULL)
314                 flush = Z_PACKET_FLUSH;
315         }
316         if (state->strm.avail_out == 0) {
317             if (m != NULL) {
318                 m->b_wptr += wspace;
319                 olen += wspace;
320                 wspace = maxolen - olen;
321                 if (wspace < 32)
322                     wspace = 32;
323                 else if (wspace > 4096)
324                     wspace = 4096;
325                 m->b_cont = allocb(wspace, BPRI_MED);
326                 m = m->b_cont;
327                 if (m != NULL) {
328                     state->strm.next_out = m->b_wptr;
329                     state->strm.avail_out = wspace;
330                 }
331             }
332             if (m == NULL) {
333                 state->strm.next_out = NULL;
334                 state->strm.avail_out = 1000000;
335             }
336         }
337     }
338     m->b_wptr += wspace - state->strm.avail_out;
339     olen += wspace - state->strm.avail_out;
340
341     /*
342      * See if we managed to reduce the size of the packet.
343      * If the compressor just gave us a single zero byte, it means
344      * the packet was incompressible.
345      */
346     if (olen < orig_len && m != NULL
347         && !(olen == PPP_HDRLEN + 3 && *wptr == 0)) {
348         state->stats.comp_bytes += olen;
349         state->stats.comp_packets++;
350     } else {
351         if (*mret != NULL) {
352             freemsg(*mret);
353             *mret = NULL;
354         }
355         state->stats.inc_bytes += orig_len;
356         state->stats.inc_packets++;
357         olen = orig_len;
358     }
359     state->stats.unc_bytes += orig_len;
360     state->stats.unc_packets++;
361
362     return olen;
363 }
364
365 static void
366 z_comp_stats(arg, stats)
367     void *arg;
368     struct compstat *stats;
369 {
370     struct deflate_state *state = (struct deflate_state *) arg;
371     u_int out;
372
373     *stats = state->stats;
374     stats->ratio = stats->unc_bytes;
375     out = stats->comp_bytes + stats->unc_bytes;
376     if (stats->ratio <= 0x7ffffff)
377         stats->ratio <<= 8;
378     else
379         out >>= 8;
380     if (out != 0)
381         stats->ratio /= out;
382 }
383
384 /*
385  * Allocate space for a decompressor.
386  */
387 static void *
388 z_decomp_alloc(options, opt_len)
389     u_char *options;
390     int opt_len;
391 {
392     struct deflate_state *state;
393     int w_size;
394
395     if (opt_len != CILEN_DEFLATE || options[0] != CI_DEFLATE
396         || options[1] != CILEN_DEFLATE
397         || DEFLATE_METHOD(options[2]) != DEFLATE_METHOD_VAL
398         || options[3] != DEFLATE_CHK_SEQUENCE)
399         return NULL;
400     w_size = DEFLATE_SIZE(options[2]);
401     if (w_size < DEFLATE_MIN_SIZE || w_size > DEFLATE_MAX_SIZE)
402         return NULL;
403
404 #ifdef __osf__
405     state = (struct deflate_state *) ALLOC_SLEEP(sizeof(*state));
406 #else
407     state = (struct deflate_state *) ALLOC_NOSLEEP(sizeof(*state));
408 #endif
409     if (state == NULL)
410         return NULL;
411
412     state->strm.next_out = NULL;
413     state->strm.zalloc = (alloc_func) z_alloc;
414     state->strm.zalloc_init = (alloc_func) z_alloc_init;
415     state->strm.zfree = (free_func) z_free;
416     if (inflateInit2(&state->strm, -w_size) != Z_OK) {
417         FREE(state, sizeof(*state));
418         return NULL;
419     }
420
421     state->w_size = w_size;
422     bzero(&state->stats, sizeof(state->stats));
423     return (void *) state;
424 }
425
426 static void
427 z_decomp_free(arg)
428     void *arg;
429 {
430     struct deflate_state *state = (struct deflate_state *) arg;
431
432     inflateEnd(&state->strm);
433     FREE(state, sizeof(*state));
434 }
435
436 static int
437 z_decomp_init(arg, options, opt_len, unit, hdrlen, mru, debug)
438     void *arg;
439     u_char *options;
440     int opt_len, unit, hdrlen, mru, debug;
441 {
442     struct deflate_state *state = (struct deflate_state *) arg;
443
444     if (opt_len < CILEN_DEFLATE || options[0] != CI_DEFLATE
445         || options[1] != CILEN_DEFLATE
446         || DEFLATE_METHOD(options[2]) != DEFLATE_METHOD_VAL
447         || DEFLATE_SIZE(options[2]) != state->w_size
448         || options[3] != DEFLATE_CHK_SEQUENCE)
449         return 0;
450
451     state->seqno = 0;
452     state->unit = unit;
453     state->hdrlen = hdrlen;
454     state->debug = debug;
455     state->mru = mru;
456
457     inflateReset(&state->strm);
458
459     return 1;
460 }
461
462 static void
463 z_decomp_reset(arg)
464     void *arg;
465 {
466     struct deflate_state *state = (struct deflate_state *) arg;
467
468     state->seqno = 0;
469     inflateReset(&state->strm);
470 }
471
472 /*
473  * Decompress a Deflate-compressed packet.
474  *
475  * Because of patent problems, we return DECOMP_ERROR for errors
476  * found by inspecting the input data and for system problems, but
477  * DECOMP_FATALERROR for any errors which could possibly be said to
478  * be being detected "after" decompression.  For DECOMP_ERROR,
479  * we can issue a CCP reset-request; for DECOMP_FATALERROR, we may be
480  * infringing a patent of Motorola's if we do, so we take CCP down
481  * instead.
482  *
483  * Given that the frame has the correct sequence number and a good FCS,
484  * errors such as invalid codes in the input most likely indicate a
485  * bug, so we return DECOMP_FATALERROR for them in order to turn off
486  * compression, even though they are detected by inspecting the input.
487  */
488 static int
489 z_decompress(arg, mi, mop)
490     void *arg;
491     mblk_t *mi, **mop;
492 {
493     struct deflate_state *state = (struct deflate_state *) arg;
494     mblk_t *mo, *mo_head;
495     u_char *rptr, *wptr;
496     int rlen, olen, ospace;
497     int seq, i, flush, r, decode_proto;
498     u_char hdr[PPP_HDRLEN + DEFLATE_OVHD];
499
500     *mop = NULL;
501     rptr = mi->b_rptr;
502     for (i = 0; i < PPP_HDRLEN + DEFLATE_OVHD; ++i) {
503         while (rptr >= mi->b_wptr) {
504             mi = mi->b_cont;
505             if (mi == NULL)
506                 return DECOMP_ERROR;
507             rptr = mi->b_rptr;
508         }
509         hdr[i] = *rptr++;
510     }
511
512     /* Check the sequence number. */
513     seq = (hdr[PPP_HDRLEN] << 8) + hdr[PPP_HDRLEN+1];
514     if (seq != state->seqno) {
515 #if !DEFLATE_DEBUG
516         if (state->debug)
517 #endif
518             printf("z_decompress%d: bad seq # %d, expected %d\n",
519                    state->unit, seq, state->seqno);
520         return DECOMP_ERROR;
521     }
522     ++state->seqno;
523
524     /* Allocate an output message block. */
525     mo = allocb(DECOMP_CHUNK + state->hdrlen, BPRI_MED);
526     if (mo == NULL)
527         return DECOMP_ERROR;
528     mo_head = mo;
529     mo->b_cont = NULL;
530     mo->b_rptr += state->hdrlen;
531     mo->b_wptr = wptr = mo->b_rptr;
532     ospace = DECOMP_CHUNK;
533
534     /*
535      * Fill in the first part of the PPP header.  The protocol field
536      * comes from the decompressed data.
537      */
538     wptr[0] = PPP_ADDRESS(hdr);
539     wptr[1] = PPP_CONTROL(hdr);
540     wptr[2] = 0;
541
542     /*
543      * Set up to call inflate.  We set avail_out to 1 initially so we can
544      * look at the first byte of the output and decide whether we have
545      * a 1-byte or 2-byte protocol field.
546      */
547     state->strm.next_in = rptr;
548     state->strm.avail_in = mi->b_wptr - rptr;
549     mi = mi->b_cont;
550     flush = (mi == NULL)? Z_PACKET_FLUSH: Z_NO_FLUSH;
551     rlen = state->strm.avail_in + PPP_HDRLEN + DEFLATE_OVHD;
552     state->strm.next_out = wptr + 3;
553     state->strm.avail_out = 1;
554     decode_proto = 1;
555     olen = PPP_HDRLEN;
556
557     /*
558      * Call inflate, supplying more input or output as needed.
559      */
560     for (;;) {
561         r = inflate(&state->strm, flush);
562         if (r != Z_OK) {
563 #if !DEFLATE_DEBUG
564             if (state->debug)
565 #endif
566                 printf("z_decompress%d: inflate returned %d (%s)\n",
567                        state->unit, r, (state->strm.msg? state->strm.msg: ""));
568             freemsg(mo_head);
569             return DECOMP_FATALERROR;
570         }
571         if (flush != Z_NO_FLUSH && state->strm.avail_out != 0)
572             break;              /* all done */
573         if (state->strm.avail_in == 0 && mi != NULL) {
574             state->strm.next_in = mi->b_rptr;
575             state->strm.avail_in = mi->b_wptr - mi->b_rptr;
576             rlen += state->strm.avail_in;
577             mi = mi->b_cont;
578             if (mi == NULL)
579                 flush = Z_PACKET_FLUSH;
580         }
581         if (state->strm.avail_out == 0) {
582             if (decode_proto) {
583                 state->strm.avail_out = ospace - PPP_HDRLEN;
584                 if ((wptr[3] & 1) == 0) {
585                     /* 2-byte protocol field */
586                     wptr[2] = wptr[3];
587                     --state->strm.next_out;
588                     ++state->strm.avail_out;
589                     --olen;
590                 }
591                 decode_proto = 0;
592             } else {
593                 mo->b_wptr += ospace;
594                 olen += ospace;
595                 mo->b_cont = allocb(DECOMP_CHUNK, BPRI_MED);
596                 mo = mo->b_cont;
597                 if (mo == NULL) {
598                     freemsg(mo_head);
599                     return DECOMP_ERROR;
600                 }
601                 state->strm.next_out = mo->b_rptr;
602                 state->strm.avail_out = ospace = DECOMP_CHUNK;
603             }
604         }
605     }
606     if (decode_proto) {
607         freemsg(mo_head);
608         return DECOMP_ERROR;
609     }
610     mo->b_wptr += ospace - state->strm.avail_out;
611     olen += ospace - state->strm.avail_out;
612
613 #if DEFLATE_DEBUG
614     if (olen > state->mru + PPP_HDRLEN)
615         printf("ppp_deflate%d: exceeded mru (%d > %d)\n",
616                state->unit, olen, state->mru + PPP_HDRLEN);
617 #endif
618
619     state->stats.unc_bytes += olen;
620     state->stats.unc_packets++;
621     state->stats.comp_bytes += rlen;
622     state->stats.comp_packets++;
623
624     *mop = mo_head;
625     return DECOMP_OK;
626 }
627
628 /*
629  * Incompressible data has arrived - add it to the history.
630  */
631 static void
632 z_incomp(arg, mi)
633     void *arg;
634     mblk_t *mi;
635 {
636     struct deflate_state *state = (struct deflate_state *) arg;
637     u_char *rptr;
638     int rlen, proto, r;
639
640     /*
641      * Check that the protocol is one we handle.
642      */
643     rptr = mi->b_rptr;
644     if (rptr + PPP_HDRLEN > mi->b_wptr) {
645         if (!pullupmsg(mi, PPP_HDRLEN))
646             return;
647         rptr = mi->b_rptr;
648     }
649     proto = PPP_PROTOCOL(rptr);
650     if (proto > 0x3fff || proto == 0xfd || proto == 0xfb)
651         return;
652
653     ++state->seqno;
654
655     /*
656      * Iterate through the message blocks, adding the characters in them
657      * to the decompressor's history.  For the first block, we start
658      * at the either the 1st or 2nd byte of the protocol field,
659      * depending on whether the protocol value is compressible.
660      */
661     rlen = mi->b_wptr - mi->b_rptr;
662     state->strm.next_in = rptr + 3;
663     state->strm.avail_in = rlen - 3;
664     if (proto > 0xff) {
665         --state->strm.next_in;
666         ++state->strm.avail_in;
667     }
668     for (;;) {
669         r = inflateIncomp(&state->strm);
670         if (r != Z_OK) {
671             /* gak! */
672 #if !DEFLATE_DEBUG
673             if (state->debug)
674 #endif
675                 printf("z_incomp%d: inflateIncomp returned %d (%s)\n",
676                        state->unit, r, (state->strm.msg? state->strm.msg: ""));
677             return;
678         }
679         mi = mi->b_cont;
680         if (mi == NULL)
681             break;
682         state->strm.next_in = mi->b_rptr;
683         state->strm.avail_in = mi->b_wptr - mi->b_rptr;
684         rlen += state->strm.avail_in;
685     }
686
687     /*
688      * Update stats.
689      */
690     state->stats.inc_bytes += rlen;
691     state->stats.inc_packets++;
692     state->stats.unc_bytes += rlen;
693     state->stats.unc_packets++;
694 }
695
696 #endif /* DO_DEFLATE */