1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate * ppp_deflate.c - interface the zlib procedures for Deflate compression
3*7c478bd9Sstevel@tonic-gate * and decompression (as used by gzip) to the PPP code.
4*7c478bd9Sstevel@tonic-gate *
5*7c478bd9Sstevel@tonic-gate * Copyright (c) 1994 The Australian National University.
6*7c478bd9Sstevel@tonic-gate * All rights reserved.
7*7c478bd9Sstevel@tonic-gate *
8*7c478bd9Sstevel@tonic-gate * Permission to use, copy, modify, and distribute this software and its
9*7c478bd9Sstevel@tonic-gate * documentation is hereby granted, provided that the above copyright
10*7c478bd9Sstevel@tonic-gate * notice appears in all copies. This software is provided without any
11*7c478bd9Sstevel@tonic-gate * warranty, express or implied. The Australian National University
12*7c478bd9Sstevel@tonic-gate * makes no representations about the suitability of this software for
13*7c478bd9Sstevel@tonic-gate * any purpose.
14*7c478bd9Sstevel@tonic-gate *
15*7c478bd9Sstevel@tonic-gate * IN NO EVENT SHALL THE AUSTRALIAN NATIONAL UNIVERSITY BE LIABLE TO ANY
16*7c478bd9Sstevel@tonic-gate * PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
17*7c478bd9Sstevel@tonic-gate * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
18*7c478bd9Sstevel@tonic-gate * THE AUSTRALIAN NATIONAL UNIVERSITY HAS BEEN ADVISED OF THE POSSIBILITY
19*7c478bd9Sstevel@tonic-gate * OF SUCH DAMAGE.
20*7c478bd9Sstevel@tonic-gate *
21*7c478bd9Sstevel@tonic-gate * THE AUSTRALIAN NATIONAL UNIVERSITY SPECIFICALLY DISCLAIMS ANY WARRANTIES,
22*7c478bd9Sstevel@tonic-gate * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
23*7c478bd9Sstevel@tonic-gate * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
24*7c478bd9Sstevel@tonic-gate * ON AN "AS IS" BASIS, AND THE AUSTRALIAN NATIONAL UNIVERSITY HAS NO
25*7c478bd9Sstevel@tonic-gate * OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS,
26*7c478bd9Sstevel@tonic-gate * OR MODIFICATIONS.
27*7c478bd9Sstevel@tonic-gate *
28*7c478bd9Sstevel@tonic-gate * $Id: deflate.c,v 1.3 1999/04/16 11:35:59 paulus Exp $
29*7c478bd9Sstevel@tonic-gate */
30*7c478bd9Sstevel@tonic-gate
31*7c478bd9Sstevel@tonic-gate #include <sys/types.h>
32*7c478bd9Sstevel@tonic-gate #include <stddef.h>
33*7c478bd9Sstevel@tonic-gate #include <stdlib.h>
34*7c478bd9Sstevel@tonic-gate #ifdef PPP_DEFS_IN_NET
35*7c478bd9Sstevel@tonic-gate #include <net/ppp_defs.h>
36*7c478bd9Sstevel@tonic-gate #else
37*7c478bd9Sstevel@tonic-gate #include "ppp_defs.h"
38*7c478bd9Sstevel@tonic-gate #endif
39*7c478bd9Sstevel@tonic-gate #include "ppp-comp.h"
40*7c478bd9Sstevel@tonic-gate #include "zlib.h"
41*7c478bd9Sstevel@tonic-gate
42*7c478bd9Sstevel@tonic-gate #if DO_DEFLATE
43*7c478bd9Sstevel@tonic-gate
44*7c478bd9Sstevel@tonic-gate #define DEFLATE_DEBUG 1
45*7c478bd9Sstevel@tonic-gate
46*7c478bd9Sstevel@tonic-gate /*
47*7c478bd9Sstevel@tonic-gate * State for a Deflate (de)compressor.
48*7c478bd9Sstevel@tonic-gate */
49*7c478bd9Sstevel@tonic-gate struct deflate_state {
50*7c478bd9Sstevel@tonic-gate int seqno;
51*7c478bd9Sstevel@tonic-gate int w_size;
52*7c478bd9Sstevel@tonic-gate int unit;
53*7c478bd9Sstevel@tonic-gate int hdrlen;
54*7c478bd9Sstevel@tonic-gate int mru;
55*7c478bd9Sstevel@tonic-gate int debug;
56*7c478bd9Sstevel@tonic-gate z_stream strm;
57*7c478bd9Sstevel@tonic-gate struct compstat stats;
58*7c478bd9Sstevel@tonic-gate };
59*7c478bd9Sstevel@tonic-gate
60*7c478bd9Sstevel@tonic-gate #define DEFLATE_OVHD 2 /* Deflate overhead/packet */
61*7c478bd9Sstevel@tonic-gate
62*7c478bd9Sstevel@tonic-gate static void *z_alloc __P((void *, u_int items, u_int size));
63*7c478bd9Sstevel@tonic-gate static void z_free __P((void *, void *ptr, u_int nb));
64*7c478bd9Sstevel@tonic-gate static void *z_decomp_alloc __P((u_char *options, int opt_len));
65*7c478bd9Sstevel@tonic-gate static void z_decomp_free __P((void *state));
66*7c478bd9Sstevel@tonic-gate static int z_decomp_init __P((void *state, u_char *options, int opt_len,
67*7c478bd9Sstevel@tonic-gate int unit, int hdrlen, int mru, int debug));
68*7c478bd9Sstevel@tonic-gate static void z_incomp __P((void *state, u_char *dmsg, int len));
69*7c478bd9Sstevel@tonic-gate static int z_decompress __P((void *state, u_char *cmp, int inlen,
70*7c478bd9Sstevel@tonic-gate u_char *dmp, int *outlenp));
71*7c478bd9Sstevel@tonic-gate static void z_decomp_reset __P((void *state));
72*7c478bd9Sstevel@tonic-gate static void z_comp_stats __P((void *state, struct compstat *stats));
73*7c478bd9Sstevel@tonic-gate
74*7c478bd9Sstevel@tonic-gate /*
75*7c478bd9Sstevel@tonic-gate * Procedures exported to if_ppp.c.
76*7c478bd9Sstevel@tonic-gate */
77*7c478bd9Sstevel@tonic-gate struct compressor ppp_deflate = {
78*7c478bd9Sstevel@tonic-gate CI_DEFLATE, /* compress_proto */
79*7c478bd9Sstevel@tonic-gate z_decomp_alloc, /* decomp_alloc */
80*7c478bd9Sstevel@tonic-gate z_decomp_free, /* decomp_free */
81*7c478bd9Sstevel@tonic-gate z_decomp_init, /* decomp_init */
82*7c478bd9Sstevel@tonic-gate z_decomp_reset, /* decomp_reset */
83*7c478bd9Sstevel@tonic-gate z_decompress, /* decompress */
84*7c478bd9Sstevel@tonic-gate z_incomp, /* incomp */
85*7c478bd9Sstevel@tonic-gate z_comp_stats, /* decomp_stat */
86*7c478bd9Sstevel@tonic-gate };
87*7c478bd9Sstevel@tonic-gate
88*7c478bd9Sstevel@tonic-gate /*
89*7c478bd9Sstevel@tonic-gate * Space allocation and freeing routines for use by zlib routines.
90*7c478bd9Sstevel@tonic-gate */
91*7c478bd9Sstevel@tonic-gate static void *
z_alloc(notused,items,size)92*7c478bd9Sstevel@tonic-gate z_alloc(notused, items, size)
93*7c478bd9Sstevel@tonic-gate void *notused;
94*7c478bd9Sstevel@tonic-gate u_int items, size;
95*7c478bd9Sstevel@tonic-gate {
96*7c478bd9Sstevel@tonic-gate return malloc(items * size);
97*7c478bd9Sstevel@tonic-gate }
98*7c478bd9Sstevel@tonic-gate
99*7c478bd9Sstevel@tonic-gate static void
z_free(notused,ptr,nbytes)100*7c478bd9Sstevel@tonic-gate z_free(notused, ptr, nbytes)
101*7c478bd9Sstevel@tonic-gate void *notused;
102*7c478bd9Sstevel@tonic-gate void *ptr;
103*7c478bd9Sstevel@tonic-gate u_int nbytes;
104*7c478bd9Sstevel@tonic-gate {
105*7c478bd9Sstevel@tonic-gate free(ptr);
106*7c478bd9Sstevel@tonic-gate }
107*7c478bd9Sstevel@tonic-gate
108*7c478bd9Sstevel@tonic-gate static void
z_comp_stats(arg,stats)109*7c478bd9Sstevel@tonic-gate z_comp_stats(arg, stats)
110*7c478bd9Sstevel@tonic-gate void *arg;
111*7c478bd9Sstevel@tonic-gate struct compstat *stats;
112*7c478bd9Sstevel@tonic-gate {
113*7c478bd9Sstevel@tonic-gate struct deflate_state *state = (struct deflate_state *) arg;
114*7c478bd9Sstevel@tonic-gate u_int out;
115*7c478bd9Sstevel@tonic-gate
116*7c478bd9Sstevel@tonic-gate *stats = state->stats;
117*7c478bd9Sstevel@tonic-gate stats->ratio = stats->unc_bytes;
118*7c478bd9Sstevel@tonic-gate out = stats->comp_bytes + stats->unc_bytes;
119*7c478bd9Sstevel@tonic-gate if (stats->ratio <= 0x7ffffff)
120*7c478bd9Sstevel@tonic-gate stats->ratio <<= 8;
121*7c478bd9Sstevel@tonic-gate else
122*7c478bd9Sstevel@tonic-gate out >>= 8;
123*7c478bd9Sstevel@tonic-gate if (out != 0)
124*7c478bd9Sstevel@tonic-gate stats->ratio /= out;
125*7c478bd9Sstevel@tonic-gate }
126*7c478bd9Sstevel@tonic-gate
127*7c478bd9Sstevel@tonic-gate /*
128*7c478bd9Sstevel@tonic-gate * Allocate space for a decompressor.
129*7c478bd9Sstevel@tonic-gate */
130*7c478bd9Sstevel@tonic-gate static void *
z_decomp_alloc(options,opt_len)131*7c478bd9Sstevel@tonic-gate z_decomp_alloc(options, opt_len)
132*7c478bd9Sstevel@tonic-gate u_char *options;
133*7c478bd9Sstevel@tonic-gate int opt_len;
134*7c478bd9Sstevel@tonic-gate {
135*7c478bd9Sstevel@tonic-gate struct deflate_state *state;
136*7c478bd9Sstevel@tonic-gate int w_size;
137*7c478bd9Sstevel@tonic-gate
138*7c478bd9Sstevel@tonic-gate if (opt_len != CILEN_DEFLATE || options[0] != CI_DEFLATE
139*7c478bd9Sstevel@tonic-gate || options[1] != CILEN_DEFLATE
140*7c478bd9Sstevel@tonic-gate || DEFLATE_METHOD(options[2]) != DEFLATE_METHOD_VAL
141*7c478bd9Sstevel@tonic-gate || options[3] != DEFLATE_CHK_SEQUENCE)
142*7c478bd9Sstevel@tonic-gate return NULL;
143*7c478bd9Sstevel@tonic-gate w_size = DEFLATE_SIZE(options[2]);
144*7c478bd9Sstevel@tonic-gate if (w_size < DEFLATE_MIN_SIZE || w_size > DEFLATE_MAX_SIZE)
145*7c478bd9Sstevel@tonic-gate return NULL;
146*7c478bd9Sstevel@tonic-gate
147*7c478bd9Sstevel@tonic-gate state = (struct deflate_state *) malloc(sizeof(*state));
148*7c478bd9Sstevel@tonic-gate if (state == NULL)
149*7c478bd9Sstevel@tonic-gate return NULL;
150*7c478bd9Sstevel@tonic-gate
151*7c478bd9Sstevel@tonic-gate state->strm.next_out = NULL;
152*7c478bd9Sstevel@tonic-gate state->strm.zalloc = (alloc_func) z_alloc;
153*7c478bd9Sstevel@tonic-gate state->strm.zfree = (free_func) z_free;
154*7c478bd9Sstevel@tonic-gate if (inflateInit2(&state->strm, -w_size) != Z_OK) {
155*7c478bd9Sstevel@tonic-gate free(state);
156*7c478bd9Sstevel@tonic-gate return NULL;
157*7c478bd9Sstevel@tonic-gate }
158*7c478bd9Sstevel@tonic-gate
159*7c478bd9Sstevel@tonic-gate state->w_size = w_size;
160*7c478bd9Sstevel@tonic-gate memset(&state->stats, 0, sizeof(state->stats));
161*7c478bd9Sstevel@tonic-gate return (void *) state;
162*7c478bd9Sstevel@tonic-gate }
163*7c478bd9Sstevel@tonic-gate
164*7c478bd9Sstevel@tonic-gate static void
z_decomp_free(arg)165*7c478bd9Sstevel@tonic-gate z_decomp_free(arg)
166*7c478bd9Sstevel@tonic-gate void *arg;
167*7c478bd9Sstevel@tonic-gate {
168*7c478bd9Sstevel@tonic-gate struct deflate_state *state = (struct deflate_state *) arg;
169*7c478bd9Sstevel@tonic-gate
170*7c478bd9Sstevel@tonic-gate inflateEnd(&state->strm);
171*7c478bd9Sstevel@tonic-gate free(state);
172*7c478bd9Sstevel@tonic-gate }
173*7c478bd9Sstevel@tonic-gate
174*7c478bd9Sstevel@tonic-gate static int
z_decomp_init(arg,options,opt_len,unit,hdrlen,mru,debug)175*7c478bd9Sstevel@tonic-gate z_decomp_init(arg, options, opt_len, unit, hdrlen, mru, debug)
176*7c478bd9Sstevel@tonic-gate void *arg;
177*7c478bd9Sstevel@tonic-gate u_char *options;
178*7c478bd9Sstevel@tonic-gate int opt_len, unit, hdrlen, mru, debug;
179*7c478bd9Sstevel@tonic-gate {
180*7c478bd9Sstevel@tonic-gate struct deflate_state *state = (struct deflate_state *) arg;
181*7c478bd9Sstevel@tonic-gate
182*7c478bd9Sstevel@tonic-gate if (opt_len < CILEN_DEFLATE || options[0] != CI_DEFLATE
183*7c478bd9Sstevel@tonic-gate || options[1] != CILEN_DEFLATE
184*7c478bd9Sstevel@tonic-gate || DEFLATE_METHOD(options[2]) != DEFLATE_METHOD_VAL
185*7c478bd9Sstevel@tonic-gate || DEFLATE_SIZE(options[2]) != state->w_size
186*7c478bd9Sstevel@tonic-gate || options[3] != DEFLATE_CHK_SEQUENCE)
187*7c478bd9Sstevel@tonic-gate return 0;
188*7c478bd9Sstevel@tonic-gate
189*7c478bd9Sstevel@tonic-gate state->seqno = 0;
190*7c478bd9Sstevel@tonic-gate state->unit = unit;
191*7c478bd9Sstevel@tonic-gate state->hdrlen = hdrlen;
192*7c478bd9Sstevel@tonic-gate state->debug = debug;
193*7c478bd9Sstevel@tonic-gate state->mru = mru;
194*7c478bd9Sstevel@tonic-gate
195*7c478bd9Sstevel@tonic-gate inflateReset(&state->strm);
196*7c478bd9Sstevel@tonic-gate
197*7c478bd9Sstevel@tonic-gate return 1;
198*7c478bd9Sstevel@tonic-gate }
199*7c478bd9Sstevel@tonic-gate
200*7c478bd9Sstevel@tonic-gate static void
z_decomp_reset(arg)201*7c478bd9Sstevel@tonic-gate z_decomp_reset(arg)
202*7c478bd9Sstevel@tonic-gate void *arg;
203*7c478bd9Sstevel@tonic-gate {
204*7c478bd9Sstevel@tonic-gate struct deflate_state *state = (struct deflate_state *) arg;
205*7c478bd9Sstevel@tonic-gate
206*7c478bd9Sstevel@tonic-gate state->seqno = 0;
207*7c478bd9Sstevel@tonic-gate inflateReset(&state->strm);
208*7c478bd9Sstevel@tonic-gate }
209*7c478bd9Sstevel@tonic-gate
210*7c478bd9Sstevel@tonic-gate /*
211*7c478bd9Sstevel@tonic-gate * Decompress a Deflate-compressed packet.
212*7c478bd9Sstevel@tonic-gate *
213*7c478bd9Sstevel@tonic-gate * Because of patent problems, we return DECOMP_ERROR for errors
214*7c478bd9Sstevel@tonic-gate * found by inspecting the input data and for system problems, but
215*7c478bd9Sstevel@tonic-gate * DECOMP_FATALERROR for any errors which could possibly be said to
216*7c478bd9Sstevel@tonic-gate * be being detected "after" decompression. For DECOMP_ERROR,
217*7c478bd9Sstevel@tonic-gate * we can issue a CCP reset-request; for DECOMP_FATALERROR, we may be
218*7c478bd9Sstevel@tonic-gate * infringing a patent of Motorola's if we do, so we take CCP down
219*7c478bd9Sstevel@tonic-gate * instead.
220*7c478bd9Sstevel@tonic-gate *
221*7c478bd9Sstevel@tonic-gate * Given that the frame has the correct sequence number and a good FCS,
222*7c478bd9Sstevel@tonic-gate * errors such as invalid codes in the input most likely indicate a
223*7c478bd9Sstevel@tonic-gate * bug, so we return DECOMP_FATALERROR for them in order to turn off
224*7c478bd9Sstevel@tonic-gate * compression, even though they are detected by inspecting the input.
225*7c478bd9Sstevel@tonic-gate */
226*7c478bd9Sstevel@tonic-gate static int
z_decompress(arg,mi,inlen,mo,outlenp)227*7c478bd9Sstevel@tonic-gate z_decompress(arg, mi, inlen, mo, outlenp)
228*7c478bd9Sstevel@tonic-gate void *arg;
229*7c478bd9Sstevel@tonic-gate u_char *mi, *mo;
230*7c478bd9Sstevel@tonic-gate int inlen, *outlenp;
231*7c478bd9Sstevel@tonic-gate {
232*7c478bd9Sstevel@tonic-gate struct deflate_state *state = (struct deflate_state *) arg;
233*7c478bd9Sstevel@tonic-gate u_char *rptr, *wptr;
234*7c478bd9Sstevel@tonic-gate int rlen, olen, ospace;
235*7c478bd9Sstevel@tonic-gate int seq, i, flush, r, decode_proto;
236*7c478bd9Sstevel@tonic-gate
237*7c478bd9Sstevel@tonic-gate rptr = mi;
238*7c478bd9Sstevel@tonic-gate if (*rptr == 0)
239*7c478bd9Sstevel@tonic-gate ++rptr;
240*7c478bd9Sstevel@tonic-gate ++rptr;
241*7c478bd9Sstevel@tonic-gate
242*7c478bd9Sstevel@tonic-gate /* Check the sequence number. */
243*7c478bd9Sstevel@tonic-gate seq = (rptr[0] << 8) + rptr[1];
244*7c478bd9Sstevel@tonic-gate rptr += 2;
245*7c478bd9Sstevel@tonic-gate if (seq != state->seqno) {
246*7c478bd9Sstevel@tonic-gate #if !DEFLATE_DEBUG
247*7c478bd9Sstevel@tonic-gate if (state->debug)
248*7c478bd9Sstevel@tonic-gate #endif
249*7c478bd9Sstevel@tonic-gate printf("z_decompress%d: bad seq # %d, expected %d\n",
250*7c478bd9Sstevel@tonic-gate state->unit, seq, state->seqno);
251*7c478bd9Sstevel@tonic-gate return DECOMP_ERROR;
252*7c478bd9Sstevel@tonic-gate }
253*7c478bd9Sstevel@tonic-gate ++state->seqno;
254*7c478bd9Sstevel@tonic-gate
255*7c478bd9Sstevel@tonic-gate /*
256*7c478bd9Sstevel@tonic-gate * Set up to call inflate.
257*7c478bd9Sstevel@tonic-gate */
258*7c478bd9Sstevel@tonic-gate wptr = mo;
259*7c478bd9Sstevel@tonic-gate state->strm.next_in = rptr;
260*7c478bd9Sstevel@tonic-gate state->strm.avail_in = mi + inlen - rptr;
261*7c478bd9Sstevel@tonic-gate rlen = state->strm.avail_in + PPP_HDRLEN + DEFLATE_OVHD;
262*7c478bd9Sstevel@tonic-gate state->strm.next_out = wptr;
263*7c478bd9Sstevel@tonic-gate state->strm.avail_out = state->mru + 2;
264*7c478bd9Sstevel@tonic-gate
265*7c478bd9Sstevel@tonic-gate r = inflate(&state->strm, Z_PACKET_FLUSH);
266*7c478bd9Sstevel@tonic-gate if (r != Z_OK) {
267*7c478bd9Sstevel@tonic-gate #if !DEFLATE_DEBUG
268*7c478bd9Sstevel@tonic-gate if (state->debug)
269*7c478bd9Sstevel@tonic-gate #endif
270*7c478bd9Sstevel@tonic-gate printf("z_decompress%d: inflate returned %d (%s)\n",
271*7c478bd9Sstevel@tonic-gate state->unit, r, (state->strm.msg? state->strm.msg: ""));
272*7c478bd9Sstevel@tonic-gate return DECOMP_FATALERROR;
273*7c478bd9Sstevel@tonic-gate }
274*7c478bd9Sstevel@tonic-gate olen = state->mru + 2 - state->strm.avail_out;
275*7c478bd9Sstevel@tonic-gate *outlenp = olen;
276*7c478bd9Sstevel@tonic-gate
277*7c478bd9Sstevel@tonic-gate if ((wptr[0] & 1) != 0)
278*7c478bd9Sstevel@tonic-gate ++olen; /* for suppressed protocol high byte */
279*7c478bd9Sstevel@tonic-gate olen += 2; /* for address, control */
280*7c478bd9Sstevel@tonic-gate
281*7c478bd9Sstevel@tonic-gate #if DEFLATE_DEBUG
282*7c478bd9Sstevel@tonic-gate if (olen > state->mru + PPP_HDRLEN)
283*7c478bd9Sstevel@tonic-gate printf("ppp_deflate%d: exceeded mru (%d > %d)\n",
284*7c478bd9Sstevel@tonic-gate state->unit, olen, state->mru + PPP_HDRLEN);
285*7c478bd9Sstevel@tonic-gate #endif
286*7c478bd9Sstevel@tonic-gate
287*7c478bd9Sstevel@tonic-gate state->stats.unc_bytes += olen;
288*7c478bd9Sstevel@tonic-gate state->stats.unc_packets++;
289*7c478bd9Sstevel@tonic-gate state->stats.comp_bytes += rlen;
290*7c478bd9Sstevel@tonic-gate state->stats.comp_packets++;
291*7c478bd9Sstevel@tonic-gate
292*7c478bd9Sstevel@tonic-gate return DECOMP_OK;
293*7c478bd9Sstevel@tonic-gate }
294*7c478bd9Sstevel@tonic-gate
295*7c478bd9Sstevel@tonic-gate /*
296*7c478bd9Sstevel@tonic-gate * Incompressible data has arrived - add it to the history.
297*7c478bd9Sstevel@tonic-gate */
298*7c478bd9Sstevel@tonic-gate static void
z_incomp(arg,mi,mlen)299*7c478bd9Sstevel@tonic-gate z_incomp(arg, mi, mlen)
300*7c478bd9Sstevel@tonic-gate void *arg;
301*7c478bd9Sstevel@tonic-gate u_char *mi;
302*7c478bd9Sstevel@tonic-gate int mlen;
303*7c478bd9Sstevel@tonic-gate {
304*7c478bd9Sstevel@tonic-gate struct deflate_state *state = (struct deflate_state *) arg;
305*7c478bd9Sstevel@tonic-gate u_char *rptr;
306*7c478bd9Sstevel@tonic-gate int rlen, proto, r;
307*7c478bd9Sstevel@tonic-gate
308*7c478bd9Sstevel@tonic-gate /*
309*7c478bd9Sstevel@tonic-gate * Check that the protocol is one we handle.
310*7c478bd9Sstevel@tonic-gate */
311*7c478bd9Sstevel@tonic-gate rptr = mi;
312*7c478bd9Sstevel@tonic-gate proto = rptr[0];
313*7c478bd9Sstevel@tonic-gate if ((proto & 1) == 0)
314*7c478bd9Sstevel@tonic-gate proto = (proto << 8) + rptr[1];
315*7c478bd9Sstevel@tonic-gate if (proto > 0x3fff || proto == 0xfd || proto == 0xfb)
316*7c478bd9Sstevel@tonic-gate return;
317*7c478bd9Sstevel@tonic-gate
318*7c478bd9Sstevel@tonic-gate ++state->seqno;
319*7c478bd9Sstevel@tonic-gate
320*7c478bd9Sstevel@tonic-gate if (rptr[0] == 0)
321*7c478bd9Sstevel@tonic-gate ++rptr;
322*7c478bd9Sstevel@tonic-gate rlen = mi + mlen - rptr;
323*7c478bd9Sstevel@tonic-gate state->strm.next_in = rptr;
324*7c478bd9Sstevel@tonic-gate state->strm.avail_in = rlen;
325*7c478bd9Sstevel@tonic-gate r = inflateIncomp(&state->strm);
326*7c478bd9Sstevel@tonic-gate if (r != Z_OK) {
327*7c478bd9Sstevel@tonic-gate /* gak! */
328*7c478bd9Sstevel@tonic-gate #if !DEFLATE_DEBUG
329*7c478bd9Sstevel@tonic-gate if (state->debug)
330*7c478bd9Sstevel@tonic-gate #endif
331*7c478bd9Sstevel@tonic-gate printf("z_incomp%d: inflateIncomp returned %d (%s)\n",
332*7c478bd9Sstevel@tonic-gate state->unit, r, (state->strm.msg? state->strm.msg: ""));
333*7c478bd9Sstevel@tonic-gate return;
334*7c478bd9Sstevel@tonic-gate }
335*7c478bd9Sstevel@tonic-gate
336*7c478bd9Sstevel@tonic-gate /*
337*7c478bd9Sstevel@tonic-gate * Update stats.
338*7c478bd9Sstevel@tonic-gate */
339*7c478bd9Sstevel@tonic-gate if (proto <= 0xff)
340*7c478bd9Sstevel@tonic-gate ++rlen;
341*7c478bd9Sstevel@tonic-gate rlen += 2;
342*7c478bd9Sstevel@tonic-gate state->stats.inc_bytes += rlen;
343*7c478bd9Sstevel@tonic-gate state->stats.inc_packets++;
344*7c478bd9Sstevel@tonic-gate state->stats.unc_bytes += rlen;
345*7c478bd9Sstevel@tonic-gate state->stats.unc_packets++;
346*7c478bd9Sstevel@tonic-gate }
347*7c478bd9Sstevel@tonic-gate
348*7c478bd9Sstevel@tonic-gate #endif /* DO_DEFLATE */
349