]> git.ozlabs.org Git - ppp.git/blob - ultrix/ppp-deflate.c
Fixed bugs with regards to using other device names than "ppp"
[ppp.git] / ultrix / ppp-deflate.c
1 /*      $Id: ppp-deflate.c,v 1.5 1998/03/25 03:11:37 paulus Exp $       */
2
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 mbufs on BSD-derived systems.
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
32 #include "../h/param.h"
33 #include "../h/types.h"
34 #include "../h/mbuf.h"
35 #include "../h/socket.h"
36 #include "../net/net/if.h"
37 #include "ppp_defs.h"
38 #include "zlib.h"
39
40 #define PACKETPTR       struct mbuf *
41 #include "ppp-comp.h"
42
43 #if DO_DEFLATE
44
45 /*
46  * State for a Deflate (de)compressor.
47  */
48 struct deflate_state {
49     int         seqno;
50     int         w_size;
51     int         unit;
52     int         hdrlen;
53     int         mru;
54     int         debug;
55     z_stream    strm;
56     struct compstat stats;
57 };
58
59 #define DEFLATE_OVHD    2               /* Deflate overhead/packet */
60
61 static void     *zalloc __P((void *, u_int items, u_int size));
62 static void     zfree __P((void *, void *ptr));
63 static void     *z_comp_alloc __P((u_char *options, int opt_len));
64 static void     *z_decomp_alloc __P((u_char *options, int opt_len));
65 static void     z_comp_free __P((void *state));
66 static void     z_decomp_free __P((void *state));
67 static int      z_comp_init __P((void *state, u_char *options, int opt_len,
68                                  int unit, int hdrlen, int debug));
69 static int      z_decomp_init __P((void *state, u_char *options, int opt_len,
70                                      int unit, int hdrlen, int mru, int debug));
71 static int      z_compress __P((void *state, struct mbuf **mret,
72                                   struct mbuf *mp, int slen, int maxolen));
73 static void     z_incomp __P((void *state, struct mbuf *dmsg));
74 static int      z_decompress __P((void *state, struct mbuf *cmp,
75                                     struct mbuf **dmpp));
76 static void     z_comp_reset __P((void *state));
77 static void     z_decomp_reset __P((void *state));
78 static void     z_comp_stats __P((void *state, struct compstat *stats));
79
80 /*
81  * Procedures exported to if_ppp.c.
82  */
83 struct compressor ppp_deflate = {
84     CI_DEFLATE,                 /* compress_proto */
85     z_comp_alloc,               /* comp_alloc */
86     z_comp_free,                /* comp_free */
87     z_comp_init,                /* comp_init */
88     z_comp_reset,               /* comp_reset */
89     z_compress,                 /* compress */
90     z_comp_stats,               /* comp_stat */
91     z_decomp_alloc,             /* decomp_alloc */
92     z_decomp_free,              /* decomp_free */
93     z_decomp_init,              /* decomp_init */
94     z_decomp_reset,             /* decomp_reset */
95     z_decompress,               /* decompress */
96     z_incomp,                   /* incomp */
97     z_comp_stats,               /* decomp_stat */
98 };
99
100 struct compressor ppp_deflate_draft = {
101     CI_DEFLATE_DRAFT,           /* compress_proto */
102     z_comp_alloc,               /* comp_alloc */
103     z_comp_free,                /* comp_free */
104     z_comp_init,                /* comp_init */
105     z_comp_reset,               /* comp_reset */
106     z_compress,                 /* compress */
107     z_comp_stats,               /* comp_stat */
108     z_decomp_alloc,             /* decomp_alloc */
109     z_decomp_free,              /* decomp_free */
110     z_decomp_init,              /* decomp_init */
111     z_decomp_reset,             /* decomp_reset */
112     z_decompress,               /* decompress */
113     z_incomp,                   /* incomp */
114     z_comp_stats,               /* decomp_stat */
115 };
116
117 /*
118  * Some useful mbuf macros not in mbuf.h.
119  */
120 #define M_IS_CLUSTER(m) ((m)->m_off > MMAXOFF)
121
122 #define M_TRAILINGSPACE(m) \
123         ((M_IS_CLUSTER(m) ? (u_int)(m)->m_clptr + M_CLUSTERSZ : MSIZE) \
124          - ((m)->m_off + (m)->m_len))
125
126 /*
127  * Space allocation and freeing routines for use by zlib routines.
128  */
129 void *
130 zalloc(notused, items, size)
131     void *notused;
132     u_int items, size;
133 {
134     void *ptr;
135
136     KM_ALLOC(ptr, void *, items * size, KM_DEVBUF, KM_NOARG);
137     return ptr;
138 }
139
140 void
141 zfree(notused, ptr)
142     void *notused;
143     void *ptr;
144 {
145     KM_FREE(ptr, KM_DEVBUF);
146 }
147
148 /*
149  * Allocate space for a compressor.
150  */
151 static void *
152 z_comp_alloc(options, opt_len)
153     u_char *options;
154     int opt_len;
155 {
156     struct deflate_state *state;
157     int w_size;
158
159     if (opt_len != CILEN_DEFLATE
160         || (options[0] != CI_DEFLATE && options[0] != CI_DEFLATE_DRAFT)
161         || options[1] != CILEN_DEFLATE
162         || DEFLATE_METHOD(options[2]) != DEFLATE_METHOD_VAL
163         || options[3] != DEFLATE_CHK_SEQUENCE)
164         return NULL;
165     w_size = DEFLATE_SIZE(options[2]);
166     if (w_size < DEFLATE_MIN_SIZE || w_size > DEFLATE_MAX_SIZE)
167         return NULL;
168
169     KM_ALLOC(state, struct deflate_state *, sizeof(struct deflate_state),
170              KM_DEVBUF, KM_NOARG);
171     if (state == NULL)
172         return NULL;
173     bzero(state, sizeof(struct deflate_state));
174
175     state->strm.next_in = NULL;
176     state->strm.zalloc = (alloc_func) zalloc;
177     state->strm.zfree = (free_func) zfree;
178     if (deflateInit2(&state->strm, Z_DEFAULT_COMPRESSION, DEFLATE_METHOD_VAL,
179                      -w_size, 8, Z_DEFAULT_STRATEGY) != Z_OK) {
180         KM_FREE(state, KM_DEVBUF);
181         return NULL;
182     }
183
184     state->w_size = w_size;
185     bzero(&state->stats, sizeof(state->stats));
186     return (void *) state;
187 }
188
189 static void
190 z_comp_free(arg)
191     void *arg;
192 {
193     struct deflate_state *state = (struct deflate_state *) arg;
194
195     deflateEnd(&state->strm);
196     KM_FREE(state, KM_DEVBUF);
197 }
198
199 static int
200 z_comp_init(arg, options, opt_len, unit, hdrlen, debug)
201     void *arg;
202     u_char *options;
203     int opt_len, unit, hdrlen, debug;
204 {
205     struct deflate_state *state = (struct deflate_state *) arg;
206
207     if (opt_len < CILEN_DEFLATE
208         || (options[0] != CI_DEFLATE && options[0] != CI_DEFLATE_DRAFT)
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 int
236 z_compress(arg, mret, mp, orig_len, maxolen)
237     void *arg;
238     struct mbuf **mret;         /* compressed packet (out) */
239     struct mbuf *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     struct mbuf *m, *clp;
246
247     /*
248      * Check that the protocol is in the range we handle.
249      */
250     rptr = mtod(mp, u_char *);
251     proto = PPP_PROTOCOL(rptr);
252     if (proto > 0x3fff || proto == 0xfd || proto == 0xfb) {
253         *mret = NULL;
254         return orig_len;
255     }
256
257     /* Allocate one mbuf initially. */
258     if (maxolen > orig_len)
259         maxolen = orig_len;
260     MGET(m, M_DONTWAIT, MT_DATA);
261     *mret = m;
262     if (m != NULL) {
263         if (maxolen + state->hdrlen > MLEN) {
264             /* MCLGET is not a single statement!!! */
265             MCLGET(m, clp)
266         }
267         m->m_len = 0;
268         wspace = M_TRAILINGSPACE(m);
269         if (state->hdrlen > 0 && state->hdrlen + PPP_HDRLEN + 2 < wspace) {
270             m->m_off += state->hdrlen;
271             wspace -= state->hdrlen;
272         }
273         wptr = mtod(m, u_char *);
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         wptr = NULL;
292         wspace = 0;
293     }
294     ++state->seqno;
295
296     rptr += (proto > 0xff)? 2: 3;       /* skip 1st proto byte if 0 */
297     state->strm.next_in = rptr;
298     state->strm.avail_in = mtod(mp, u_char *) + mp->m_len - rptr;
299     mp = mp->m_next;
300     flush = (mp == NULL)? Z_PACKET_FLUSH: Z_NO_FLUSH;
301     olen = 0;
302     for (;;) {
303         r = deflate(&state->strm, flush);
304         if (r != Z_OK) {
305             printf("z_compress: deflate returned %d (%s)\n",
306                    r, (state->strm.msg? state->strm.msg: ""));
307             break;
308         }
309         if (flush != Z_NO_FLUSH && state->strm.avail_out != 0)
310             break;              /* all done */
311         if (state->strm.avail_in == 0 && mp != NULL) {
312             state->strm.next_in = mtod(mp, u_char *);
313             state->strm.avail_in = mp->m_len;
314             mp = mp->m_next;
315             if (mp == NULL)
316                 flush = Z_PACKET_FLUSH;
317         }
318         if (state->strm.avail_out == 0) {
319             if (m != NULL) {
320                 m->m_len = wspace;
321                 olen += wspace;
322                 MGET(m->m_next, M_DONTWAIT, MT_DATA);
323                 m = m->m_next;
324                 if (m != NULL) {
325                     if (maxolen - olen > MLEN) {
326                         MCLGET(m, clp)
327                     }
328                     m->m_len = 0;
329                     state->strm.next_out = mtod(m, u_char *);
330                     state->strm.avail_out = wspace = M_TRAILINGSPACE(m);
331                 }
332             }
333             if (m == NULL) {
334                 state->strm.next_out = NULL;
335                 state->strm.avail_out = 1000000;
336             }
337         }
338     }
339     if (m != NULL)
340         olen += (m->m_len = wspace - state->strm.avail_out);
341
342     /*
343      * See if we managed to reduce the size of the packet.
344      * If the compressor just gave us a single zero byte, it means
345      * the packet was incompressible.
346      */
347     if (m != NULL && olen < orig_len
348         && !(olen == PPP_HDRLEN + 3 && *wptr == 0)) {
349         state->stats.comp_bytes += olen;
350         state->stats.comp_packets++;
351     } else {
352         if (*mret != NULL) {
353             m_freem(*mret);
354             *mret = NULL;
355         }
356         state->stats.inc_bytes += orig_len;
357         state->stats.inc_packets++;
358         olen = orig_len;
359     }
360     state->stats.unc_bytes += orig_len;
361     state->stats.unc_packets++;
362
363     return olen;
364 }
365
366 static void
367 z_comp_stats(arg, stats)
368     void *arg;
369     struct compstat *stats;
370 {
371     struct deflate_state *state = (struct deflate_state *) arg;
372     u_int out;
373
374     *stats = state->stats;
375     stats->ratio = stats->unc_bytes;
376     out = stats->comp_bytes + stats->inc_bytes;
377     if (stats->ratio <= 0x7ffffff)
378         stats->ratio <<= 8;
379     else
380         out >>= 8;
381     if (out != 0)
382         stats->ratio /= out;
383 }
384
385 /*
386  * Allocate space for a decompressor.
387  */
388 static void *
389 z_decomp_alloc(options, opt_len)
390     u_char *options;
391     int opt_len;
392 {
393     struct deflate_state *state;
394     int w_size;
395
396     if (opt_len != CILEN_DEFLATE
397         || (options[0] != CI_DEFLATE && options[0] != CI_DEFLATE_DRAFT)
398         || options[1] != CILEN_DEFLATE
399         || DEFLATE_METHOD(options[2]) != DEFLATE_METHOD_VAL
400         || options[3] != DEFLATE_CHK_SEQUENCE)
401         return NULL;
402     w_size = DEFLATE_SIZE(options[2]);
403     if (w_size < DEFLATE_MIN_SIZE || w_size > DEFLATE_MAX_SIZE)
404         return NULL;
405
406     KM_ALLOC(state, struct deflate_state *, sizeof(struct deflate_state),
407              KM_DEVBUF, KM_NOARG);
408     if (state == NULL)
409         return NULL;
410     bzero(state, sizeof(struct deflate_state));
411
412     state->strm.next_out = NULL;
413     state->strm.zalloc = (alloc_func) zalloc;
414     state->strm.zfree = (free_func) zfree;
415     if (inflateInit2(&state->strm, -w_size) != Z_OK) {
416         KM_FREE(state, KM_DEVBUF);
417         return NULL;
418     }
419
420     state->w_size = w_size;
421     bzero(&state->stats, sizeof(state->stats));
422     return (void *) state;
423 }
424
425 static void
426 z_decomp_free(arg)
427     void *arg;
428 {
429     struct deflate_state *state = (struct deflate_state *) arg;
430
431     inflateEnd(&state->strm);
432     KM_FREE(state, KM_DEVBUF);
433 }
434
435 static int
436 z_decomp_init(arg, options, opt_len, unit, hdrlen, mru, debug)
437     void *arg;
438     u_char *options;
439     int opt_len, unit, hdrlen, mru, debug;
440 {
441     struct deflate_state *state = (struct deflate_state *) arg;
442
443     if (opt_len < CILEN_DEFLATE
444         || (options[0] != CI_DEFLATE && options[0] != CI_DEFLATE_DRAFT)
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 int
489 z_decompress(arg, mi, mop)
490     void *arg;
491     struct mbuf *mi, **mop;
492 {
493     struct deflate_state *state = (struct deflate_state *) arg;
494     struct mbuf *mo, *mo_head, *clp;
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 = mtod(mi, u_char *);
502     rlen = mi->m_len;
503     for (i = 0; i < PPP_HDRLEN + DEFLATE_OVHD; ++i) {
504         while (rlen <= 0) {
505             mi = mi->m_next;
506             if (mi == NULL)
507                 return DECOMP_ERROR;
508             rptr = mtod(mi, u_char *);
509             rlen = mi->m_len;
510         }
511         hdr[i] = *rptr++;
512         --rlen;
513     }
514
515     /* Check the sequence number. */
516     seq = (hdr[PPP_HDRLEN] << 8) + hdr[PPP_HDRLEN+1];
517     if (seq != state->seqno) {
518         if (state->debug)
519             printf("z_decompress%d: bad seq # %d, expected %d\n",
520                    state->unit, seq, state->seqno);
521         return DECOMP_ERROR;
522     }
523     ++state->seqno;
524
525     /* Allocate an output mbuf. */
526     MGET(mo, M_DONTWAIT, MT_DATA);
527     if (mo == NULL)
528         return DECOMP_ERROR;
529     mo_head = mo;
530     mo->m_next = NULL;
531     MCLGET(mo, clp)
532     mo->m_len = 0;
533     ospace = M_TRAILINGSPACE(mo);
534     if (state->hdrlen > 0 && state->hdrlen + PPP_HDRLEN < ospace) {
535         mo->m_off += state->hdrlen;
536         ospace -= state->hdrlen;
537     }
538
539     /*
540      * Fill in the first part of the PPP header.  The protocol field
541      * comes from the decompressed data.
542      */
543     wptr = mtod(mo, u_char *);
544     wptr[0] = PPP_ADDRESS(hdr);
545     wptr[1] = PPP_CONTROL(hdr);
546     wptr[2] = 0;
547
548     /*
549      * Set up to call inflate.  We set avail_out to 1 initially so we can
550      * look at the first byte of the output and decide whether we have
551      * a 1-byte or 2-byte protocol field.
552      */
553     state->strm.next_in = rptr;
554     state->strm.avail_in = rlen;
555     mi = mi->m_next;
556     flush = (mi == NULL)? Z_PACKET_FLUSH: Z_NO_FLUSH;
557     rlen += PPP_HDRLEN + DEFLATE_OVHD;
558     state->strm.next_out = wptr + 3;
559     state->strm.avail_out = 1;
560     decode_proto = 1;
561     olen = PPP_HDRLEN;
562
563     /*
564      * Call inflate, supplying more input or output as needed.
565      */
566     for (;;) {
567         r = inflate(&state->strm, flush);
568         if (r != Z_OK) {
569             if (state->debug)
570                 printf("z_decompress%d: inflate returned %d (%s)\n",
571                        state->unit, r, (state->strm.msg? state->strm.msg: ""));
572             m_freem(mo_head);
573             return DECOMP_FATALERROR;
574         }
575         if (flush != Z_NO_FLUSH && state->strm.avail_out != 0)
576             break;              /* all done */
577         if (state->strm.avail_in == 0 && mi != NULL) {
578             state->strm.next_in = mtod(mi, u_char *);
579             state->strm.avail_in = mi->m_len;
580             rlen += mi->m_len;
581             mi = mi->m_next;
582             if (mi == NULL)
583                 flush = Z_PACKET_FLUSH;
584         }
585         if (state->strm.avail_out == 0) {
586             if (decode_proto) {
587                 state->strm.avail_out = ospace - PPP_HDRLEN;
588                 if ((wptr[3] & 1) == 0) {
589                     /* 2-byte protocol field */
590                     wptr[2] = wptr[3];
591                     --state->strm.next_out;
592                     ++state->strm.avail_out;
593                     --olen;
594                 }
595                 decode_proto = 0;
596             } else {
597                 mo->m_len = ospace;
598                 olen += ospace;
599                 MGET(mo->m_next, M_DONTWAIT, MT_DATA);
600                 mo = mo->m_next;
601                 if (mo == NULL) {
602                     m_freem(mo_head);
603                     return DECOMP_ERROR;
604                 }
605                 MCLGET(mo, clp)
606                 mo->m_len = 0;
607                 state->strm.next_out = mtod(mo, u_char *);
608                 state->strm.avail_out = ospace = M_TRAILINGSPACE(mo);
609             }
610         }
611     }
612     if (decode_proto) {
613         m_freem(mo_head);
614         return DECOMP_ERROR;
615     }
616     olen += (mo->m_len = ospace - state->strm.avail_out);
617
618     state->stats.unc_bytes += olen;
619     state->stats.unc_packets++;
620     state->stats.comp_bytes += rlen;
621     state->stats.comp_packets++;
622
623     *mop = mo_head;
624     return DECOMP_OK;
625 }
626
627 /*
628  * Incompressible data has arrived - add it to the history.
629  */
630 static void
631 z_incomp(arg, mi)
632     void *arg;
633     struct mbuf *mi;
634 {
635     struct deflate_state *state = (struct deflate_state *) arg;
636     u_char *rptr;
637     int rlen, proto, r;
638
639     /*
640      * Check that the protocol is one we handle.
641      */
642     rptr = mtod(mi, u_char *);
643     proto = PPP_PROTOCOL(rptr);
644     if (proto > 0x3fff || proto == 0xfd || proto == 0xfb)
645         return;
646
647     ++state->seqno;
648
649     /*
650      * Iterate through the mbufs, adding the characters in them
651      * to the decompressor's history.  For the first mbuf, we start
652      * at the either the 1st or 2nd byte of the protocol field,
653      * depending on whether the protocol value is compressible.
654      */
655     rlen = mi->m_len;
656     state->strm.next_in = rptr + 3;
657     state->strm.avail_in = rlen - 3;
658     if (proto > 0xff) {
659         --state->strm.next_in;
660         ++state->strm.avail_in;
661     }
662     for (;;) {
663         r = inflateIncomp(&state->strm);
664         if (r != Z_OK) {
665             /* gak! */
666             if (state->debug) {
667                 printf("z_incomp%d: inflateIncomp returned %d (%s)\n",
668                        state->unit, r, (state->strm.msg? state->strm.msg: ""));
669             }
670             return;
671         }
672         mi = mi->m_next;
673         if (mi == NULL)
674             break;
675         state->strm.next_in = mtod(mi, u_char *);
676         state->strm.avail_in = mi->m_len;
677         rlen += mi->m_len;
678     }
679
680     /*
681      * Update stats.
682      */
683     state->stats.inc_bytes += rlen;
684     state->stats.inc_packets++;
685     state->stats.unc_bytes += rlen;
686     state->stats.unc_packets++;
687 }
688
689 #endif /* DO_DEFLATE */