1*0Sstevel@tonic-gate /* Because this code is derived from the 4.3BSD compress source:
2*0Sstevel@tonic-gate *
3*0Sstevel@tonic-gate *
4*0Sstevel@tonic-gate * Copyright (c) 1985, 1986 The Regents of the University of California.
5*0Sstevel@tonic-gate * All rights reserved.
6*0Sstevel@tonic-gate *
7*0Sstevel@tonic-gate * This code is derived from software contributed to Berkeley by
8*0Sstevel@tonic-gate * James A. Woods, derived from original work by Spencer Thomas
9*0Sstevel@tonic-gate * and Joseph Orost.
10*0Sstevel@tonic-gate *
11*0Sstevel@tonic-gate * Redistribution and use in source and binary forms, with or without
12*0Sstevel@tonic-gate * modification, are permitted provided that the following conditions
13*0Sstevel@tonic-gate * are met:
14*0Sstevel@tonic-gate * 1. Redistributions of source code must retain the above copyright
15*0Sstevel@tonic-gate * notice, this list of conditions and the following disclaimer.
16*0Sstevel@tonic-gate * 2. Redistributions in binary form must reproduce the above copyright
17*0Sstevel@tonic-gate * notice, this list of conditions and the following disclaimer in the
18*0Sstevel@tonic-gate * documentation and/or other materials provided with the distribution.
19*0Sstevel@tonic-gate * 3. All advertising materials mentioning features or use of this software
20*0Sstevel@tonic-gate * must display the following acknowledgement:
21*0Sstevel@tonic-gate * This product includes software developed by the University of
22*0Sstevel@tonic-gate * California, Berkeley and its contributors.
23*0Sstevel@tonic-gate * 4. Neither the name of the University nor the names of its contributors
24*0Sstevel@tonic-gate * may be used to endorse or promote products derived from this software
25*0Sstevel@tonic-gate * without specific prior written permission.
26*0Sstevel@tonic-gate *
27*0Sstevel@tonic-gate * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
28*0Sstevel@tonic-gate * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29*0Sstevel@tonic-gate * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
30*0Sstevel@tonic-gate * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
31*0Sstevel@tonic-gate * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
32*0Sstevel@tonic-gate * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
33*0Sstevel@tonic-gate * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
34*0Sstevel@tonic-gate * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
35*0Sstevel@tonic-gate * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
36*0Sstevel@tonic-gate * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37*0Sstevel@tonic-gate * SUCH DAMAGE.
38*0Sstevel@tonic-gate */
39*0Sstevel@tonic-gate
40*0Sstevel@tonic-gate /*
41*0Sstevel@tonic-gate * $Id: bsd-comp.c,v 1.3 1999/04/16 11:35:59 paulus Exp $
42*0Sstevel@tonic-gate */
43*0Sstevel@tonic-gate
44*0Sstevel@tonic-gate #include <sys/types.h>
45*0Sstevel@tonic-gate #include <stddef.h>
46*0Sstevel@tonic-gate #include <stdlib.h>
47*0Sstevel@tonic-gate #ifdef PPP_DEFS_IN_NET
48*0Sstevel@tonic-gate #include <net/ppp_defs.h>
49*0Sstevel@tonic-gate #else
50*0Sstevel@tonic-gate #include "ppp_defs.h"
51*0Sstevel@tonic-gate #endif
52*0Sstevel@tonic-gate #include "ppp-comp.h"
53*0Sstevel@tonic-gate
54*0Sstevel@tonic-gate #if DO_BSD_COMPRESS
55*0Sstevel@tonic-gate
56*0Sstevel@tonic-gate /*
57*0Sstevel@tonic-gate * PPP "BSD compress" compression
58*0Sstevel@tonic-gate * The differences between this compression and the classic BSD LZW
59*0Sstevel@tonic-gate * source are obvious from the requirement that the classic code worked
60*0Sstevel@tonic-gate * with files while this handles arbitrarily long streams that
61*0Sstevel@tonic-gate * are broken into packets. They are:
62*0Sstevel@tonic-gate *
63*0Sstevel@tonic-gate * When the code size expands, a block of junk is not emitted by
64*0Sstevel@tonic-gate * the compressor and not expected by the decompressor.
65*0Sstevel@tonic-gate *
66*0Sstevel@tonic-gate * New codes are not necessarily assigned every time an old
67*0Sstevel@tonic-gate * code is output by the compressor. This is because a packet
68*0Sstevel@tonic-gate * end forces a code to be emitted, but does not imply that a
69*0Sstevel@tonic-gate * new sequence has been seen.
70*0Sstevel@tonic-gate *
71*0Sstevel@tonic-gate * The compression ratio is checked at the first end of a packet
72*0Sstevel@tonic-gate * after the appropriate gap. Besides simplifying and speeding
73*0Sstevel@tonic-gate * things up, this makes it more likely that the transmitter
74*0Sstevel@tonic-gate * and receiver will agree when the dictionary is cleared when
75*0Sstevel@tonic-gate * compression is not going well.
76*0Sstevel@tonic-gate */
77*0Sstevel@tonic-gate
78*0Sstevel@tonic-gate /*
79*0Sstevel@tonic-gate * A dictionary for doing BSD compress.
80*0Sstevel@tonic-gate */
81*0Sstevel@tonic-gate struct bsd_db {
82*0Sstevel@tonic-gate int totlen; /* length of this structure */
83*0Sstevel@tonic-gate u_int hsize; /* size of the hash table */
84*0Sstevel@tonic-gate u_char hshift; /* used in hash function */
85*0Sstevel@tonic-gate u_char n_bits; /* current bits/code */
86*0Sstevel@tonic-gate u_char maxbits;
87*0Sstevel@tonic-gate u_char debug;
88*0Sstevel@tonic-gate u_char unit;
89*0Sstevel@tonic-gate u_short seqno; /* sequence number of next packet */
90*0Sstevel@tonic-gate u_int hdrlen; /* header length to preallocate */
91*0Sstevel@tonic-gate u_int mru;
92*0Sstevel@tonic-gate u_int maxmaxcode; /* largest valid code */
93*0Sstevel@tonic-gate u_int max_ent; /* largest code in use */
94*0Sstevel@tonic-gate u_int in_count; /* uncompressed bytes, aged */
95*0Sstevel@tonic-gate u_int bytes_out; /* compressed bytes, aged */
96*0Sstevel@tonic-gate u_int ratio; /* recent compression ratio */
97*0Sstevel@tonic-gate u_int checkpoint; /* when to next check the ratio */
98*0Sstevel@tonic-gate u_int clear_count; /* times dictionary cleared */
99*0Sstevel@tonic-gate u_int incomp_count; /* incompressible packets */
100*0Sstevel@tonic-gate u_int incomp_bytes; /* incompressible bytes */
101*0Sstevel@tonic-gate u_int uncomp_count; /* uncompressed packets */
102*0Sstevel@tonic-gate u_int uncomp_bytes; /* uncompressed bytes */
103*0Sstevel@tonic-gate u_int comp_count; /* compressed packets */
104*0Sstevel@tonic-gate u_int comp_bytes; /* compressed bytes */
105*0Sstevel@tonic-gate u_short *lens; /* array of lengths of codes */
106*0Sstevel@tonic-gate struct bsd_dict {
107*0Sstevel@tonic-gate union { /* hash value */
108*0Sstevel@tonic-gate u_int32_t fcode;
109*0Sstevel@tonic-gate struct {
110*0Sstevel@tonic-gate #ifdef BSD_LITTLE_ENDIAN
111*0Sstevel@tonic-gate u_short prefix; /* preceding code */
112*0Sstevel@tonic-gate u_char suffix; /* last character of new code */
113*0Sstevel@tonic-gate u_char pad;
114*0Sstevel@tonic-gate #else
115*0Sstevel@tonic-gate u_char pad;
116*0Sstevel@tonic-gate u_char suffix; /* last character of new code */
117*0Sstevel@tonic-gate u_short prefix; /* preceding code */
118*0Sstevel@tonic-gate #endif
119*0Sstevel@tonic-gate } hs;
120*0Sstevel@tonic-gate } f;
121*0Sstevel@tonic-gate u_short codem1; /* output of hash table -1 */
122*0Sstevel@tonic-gate u_short cptr; /* map code to hash table entry */
123*0Sstevel@tonic-gate } dict[1];
124*0Sstevel@tonic-gate };
125*0Sstevel@tonic-gate
126*0Sstevel@tonic-gate #define BSD_OVHD 2 /* BSD compress overhead/packet */
127*0Sstevel@tonic-gate #define BSD_INIT_BITS BSD_MIN_BITS
128*0Sstevel@tonic-gate
129*0Sstevel@tonic-gate static void *bsd_decomp_alloc __P((u_char *options, int opt_len));
130*0Sstevel@tonic-gate static void bsd_free __P((void *state));
131*0Sstevel@tonic-gate static int bsd_decomp_init __P((void *state, u_char *options, int opt_len,
132*0Sstevel@tonic-gate int unit, int hdrlen, int mru, int debug));
133*0Sstevel@tonic-gate static void bsd_incomp __P((void *state, u_char *dmsg, int len));
134*0Sstevel@tonic-gate static int bsd_decompress __P((void *state, u_char *cmp, int inlen,
135*0Sstevel@tonic-gate u_char *dmp, int *outlen));
136*0Sstevel@tonic-gate static void bsd_reset __P((void *state));
137*0Sstevel@tonic-gate static void bsd_comp_stats __P((void *state, struct compstat *stats));
138*0Sstevel@tonic-gate
139*0Sstevel@tonic-gate /*
140*0Sstevel@tonic-gate * Exported procedures.
141*0Sstevel@tonic-gate */
142*0Sstevel@tonic-gate struct compressor ppp_bsd_compress = {
143*0Sstevel@tonic-gate CI_BSD_COMPRESS, /* compress_proto */
144*0Sstevel@tonic-gate bsd_decomp_alloc, /* decomp_alloc */
145*0Sstevel@tonic-gate bsd_free, /* decomp_free */
146*0Sstevel@tonic-gate bsd_decomp_init, /* decomp_init */
147*0Sstevel@tonic-gate bsd_reset, /* decomp_reset */
148*0Sstevel@tonic-gate bsd_decompress, /* decompress */
149*0Sstevel@tonic-gate bsd_incomp, /* incomp */
150*0Sstevel@tonic-gate bsd_comp_stats, /* decomp_stat */
151*0Sstevel@tonic-gate };
152*0Sstevel@tonic-gate
153*0Sstevel@tonic-gate /*
154*0Sstevel@tonic-gate * the next two codes should not be changed lightly, as they must not
155*0Sstevel@tonic-gate * lie within the contiguous general code space.
156*0Sstevel@tonic-gate */
157*0Sstevel@tonic-gate #define CLEAR 256 /* table clear output code */
158*0Sstevel@tonic-gate #define FIRST 257 /* first free entry */
159*0Sstevel@tonic-gate #define LAST 255
160*0Sstevel@tonic-gate
161*0Sstevel@tonic-gate #define MAXCODE(b) ((1 << (b)) - 1)
162*0Sstevel@tonic-gate #define BADCODEM1 MAXCODE(BSD_MAX_BITS)
163*0Sstevel@tonic-gate
164*0Sstevel@tonic-gate #define BSD_HASH(prefix,suffix,hshift) ((((u_int32_t)(suffix)) << (hshift)) \
165*0Sstevel@tonic-gate ^ (u_int32_t)(prefix))
166*0Sstevel@tonic-gate #define BSD_KEY(prefix,suffix) ((((u_int32_t)(suffix)) << 16) \
167*0Sstevel@tonic-gate + (u_int32_t)(prefix))
168*0Sstevel@tonic-gate
169*0Sstevel@tonic-gate #define CHECK_GAP 10000 /* Ratio check interval */
170*0Sstevel@tonic-gate
171*0Sstevel@tonic-gate #define RATIO_SCALE_LOG 8
172*0Sstevel@tonic-gate #define RATIO_SCALE (1<<RATIO_SCALE_LOG)
173*0Sstevel@tonic-gate #define RATIO_MAX (0x7fffffff>>RATIO_SCALE_LOG)
174*0Sstevel@tonic-gate
175*0Sstevel@tonic-gate /*
176*0Sstevel@tonic-gate * clear the dictionary
177*0Sstevel@tonic-gate */
178*0Sstevel@tonic-gate static void
bsd_clear(db)179*0Sstevel@tonic-gate bsd_clear(db)
180*0Sstevel@tonic-gate struct bsd_db *db;
181*0Sstevel@tonic-gate {
182*0Sstevel@tonic-gate db->clear_count++;
183*0Sstevel@tonic-gate db->max_ent = FIRST-1;
184*0Sstevel@tonic-gate db->n_bits = BSD_INIT_BITS;
185*0Sstevel@tonic-gate db->ratio = 0;
186*0Sstevel@tonic-gate db->bytes_out = 0;
187*0Sstevel@tonic-gate db->in_count = 0;
188*0Sstevel@tonic-gate db->checkpoint = CHECK_GAP;
189*0Sstevel@tonic-gate }
190*0Sstevel@tonic-gate
191*0Sstevel@tonic-gate /*
192*0Sstevel@tonic-gate * If the dictionary is full, then see if it is time to reset it.
193*0Sstevel@tonic-gate *
194*0Sstevel@tonic-gate * Compute the compression ratio using fixed-point arithmetic
195*0Sstevel@tonic-gate * with 8 fractional bits.
196*0Sstevel@tonic-gate *
197*0Sstevel@tonic-gate * Since we have an infinite stream instead of a single file,
198*0Sstevel@tonic-gate * watch only the local compression ratio.
199*0Sstevel@tonic-gate *
200*0Sstevel@tonic-gate * Since both peers must reset the dictionary at the same time even in
201*0Sstevel@tonic-gate * the absence of CLEAR codes (while packets are incompressible), they
202*0Sstevel@tonic-gate * must compute the same ratio.
203*0Sstevel@tonic-gate */
204*0Sstevel@tonic-gate static int /* 1=output CLEAR */
bsd_check(db)205*0Sstevel@tonic-gate bsd_check(db)
206*0Sstevel@tonic-gate struct bsd_db *db;
207*0Sstevel@tonic-gate {
208*0Sstevel@tonic-gate u_int new_ratio;
209*0Sstevel@tonic-gate
210*0Sstevel@tonic-gate if (db->in_count >= db->checkpoint) {
211*0Sstevel@tonic-gate /* age the ratio by limiting the size of the counts */
212*0Sstevel@tonic-gate if (db->in_count >= RATIO_MAX
213*0Sstevel@tonic-gate || db->bytes_out >= RATIO_MAX) {
214*0Sstevel@tonic-gate db->in_count -= db->in_count/4;
215*0Sstevel@tonic-gate db->bytes_out -= db->bytes_out/4;
216*0Sstevel@tonic-gate }
217*0Sstevel@tonic-gate
218*0Sstevel@tonic-gate db->checkpoint = db->in_count + CHECK_GAP;
219*0Sstevel@tonic-gate
220*0Sstevel@tonic-gate if (db->max_ent >= db->maxmaxcode) {
221*0Sstevel@tonic-gate /* Reset the dictionary only if the ratio is worse,
222*0Sstevel@tonic-gate * or if it looks as if it has been poisoned
223*0Sstevel@tonic-gate * by incompressible data.
224*0Sstevel@tonic-gate *
225*0Sstevel@tonic-gate * This does not overflow, because
226*0Sstevel@tonic-gate * db->in_count <= RATIO_MAX.
227*0Sstevel@tonic-gate */
228*0Sstevel@tonic-gate new_ratio = db->in_count << RATIO_SCALE_LOG;
229*0Sstevel@tonic-gate if (db->bytes_out != 0)
230*0Sstevel@tonic-gate new_ratio /= db->bytes_out;
231*0Sstevel@tonic-gate
232*0Sstevel@tonic-gate if (new_ratio < db->ratio || new_ratio < 1 * RATIO_SCALE) {
233*0Sstevel@tonic-gate bsd_clear(db);
234*0Sstevel@tonic-gate return 1;
235*0Sstevel@tonic-gate }
236*0Sstevel@tonic-gate db->ratio = new_ratio;
237*0Sstevel@tonic-gate }
238*0Sstevel@tonic-gate }
239*0Sstevel@tonic-gate return 0;
240*0Sstevel@tonic-gate }
241*0Sstevel@tonic-gate
242*0Sstevel@tonic-gate /*
243*0Sstevel@tonic-gate * Return statistics.
244*0Sstevel@tonic-gate */
245*0Sstevel@tonic-gate static void
bsd_comp_stats(state,stats)246*0Sstevel@tonic-gate bsd_comp_stats(state, stats)
247*0Sstevel@tonic-gate void *state;
248*0Sstevel@tonic-gate struct compstat *stats;
249*0Sstevel@tonic-gate {
250*0Sstevel@tonic-gate struct bsd_db *db = (struct bsd_db *) state;
251*0Sstevel@tonic-gate u_int out;
252*0Sstevel@tonic-gate
253*0Sstevel@tonic-gate stats->unc_bytes = db->uncomp_bytes;
254*0Sstevel@tonic-gate stats->unc_packets = db->uncomp_count;
255*0Sstevel@tonic-gate stats->comp_bytes = db->comp_bytes;
256*0Sstevel@tonic-gate stats->comp_packets = db->comp_count;
257*0Sstevel@tonic-gate stats->inc_bytes = db->incomp_bytes;
258*0Sstevel@tonic-gate stats->inc_packets = db->incomp_count;
259*0Sstevel@tonic-gate stats->ratio = db->in_count;
260*0Sstevel@tonic-gate out = db->bytes_out;
261*0Sstevel@tonic-gate if (stats->ratio <= 0x7fffff)
262*0Sstevel@tonic-gate stats->ratio <<= 8;
263*0Sstevel@tonic-gate else
264*0Sstevel@tonic-gate out >>= 8;
265*0Sstevel@tonic-gate if (out != 0)
266*0Sstevel@tonic-gate stats->ratio /= out;
267*0Sstevel@tonic-gate }
268*0Sstevel@tonic-gate
269*0Sstevel@tonic-gate /*
270*0Sstevel@tonic-gate * Reset state, as on a CCP ResetReq.
271*0Sstevel@tonic-gate */
272*0Sstevel@tonic-gate static void
bsd_reset(state)273*0Sstevel@tonic-gate bsd_reset(state)
274*0Sstevel@tonic-gate void *state;
275*0Sstevel@tonic-gate {
276*0Sstevel@tonic-gate struct bsd_db *db = (struct bsd_db *) state;
277*0Sstevel@tonic-gate
278*0Sstevel@tonic-gate db->seqno = 0;
279*0Sstevel@tonic-gate bsd_clear(db);
280*0Sstevel@tonic-gate db->clear_count = 0;
281*0Sstevel@tonic-gate }
282*0Sstevel@tonic-gate
283*0Sstevel@tonic-gate /*
284*0Sstevel@tonic-gate * Allocate space for a (de) compressor.
285*0Sstevel@tonic-gate */
286*0Sstevel@tonic-gate static void *
bsd_alloc(options,opt_len,decomp)287*0Sstevel@tonic-gate bsd_alloc(options, opt_len, decomp)
288*0Sstevel@tonic-gate u_char *options;
289*0Sstevel@tonic-gate int opt_len, decomp;
290*0Sstevel@tonic-gate {
291*0Sstevel@tonic-gate int bits;
292*0Sstevel@tonic-gate u_int newlen, hsize, hshift, maxmaxcode;
293*0Sstevel@tonic-gate struct bsd_db *db;
294*0Sstevel@tonic-gate
295*0Sstevel@tonic-gate if (opt_len != 3 || options[0] != CI_BSD_COMPRESS || options[1] != 3
296*0Sstevel@tonic-gate || BSD_VERSION(options[2]) != BSD_CURRENT_VERSION)
297*0Sstevel@tonic-gate return NULL;
298*0Sstevel@tonic-gate
299*0Sstevel@tonic-gate bits = BSD_NBITS(options[2]);
300*0Sstevel@tonic-gate switch (bits) {
301*0Sstevel@tonic-gate case 9: /* needs 82152 for both directions */
302*0Sstevel@tonic-gate case 10: /* needs 84144 */
303*0Sstevel@tonic-gate case 11: /* needs 88240 */
304*0Sstevel@tonic-gate case 12: /* needs 96432 */
305*0Sstevel@tonic-gate hsize = 5003;
306*0Sstevel@tonic-gate hshift = 4;
307*0Sstevel@tonic-gate break;
308*0Sstevel@tonic-gate case 13: /* needs 176784 */
309*0Sstevel@tonic-gate hsize = 9001;
310*0Sstevel@tonic-gate hshift = 5;
311*0Sstevel@tonic-gate break;
312*0Sstevel@tonic-gate case 14: /* needs 353744 */
313*0Sstevel@tonic-gate hsize = 18013;
314*0Sstevel@tonic-gate hshift = 6;
315*0Sstevel@tonic-gate break;
316*0Sstevel@tonic-gate case 15: /* needs 691440 */
317*0Sstevel@tonic-gate hsize = 35023;
318*0Sstevel@tonic-gate hshift = 7;
319*0Sstevel@tonic-gate break;
320*0Sstevel@tonic-gate case 16: /* needs 1366160--far too much, */
321*0Sstevel@tonic-gate /* hsize = 69001; */ /* and 69001 is too big for cptr */
322*0Sstevel@tonic-gate /* hshift = 8; */ /* in struct bsd_db */
323*0Sstevel@tonic-gate /* break; */
324*0Sstevel@tonic-gate default:
325*0Sstevel@tonic-gate return NULL;
326*0Sstevel@tonic-gate }
327*0Sstevel@tonic-gate
328*0Sstevel@tonic-gate maxmaxcode = MAXCODE(bits);
329*0Sstevel@tonic-gate newlen = sizeof(*db) + (hsize-1) * (sizeof(db->dict[0]));
330*0Sstevel@tonic-gate db = (struct bsd_db *) malloc(newlen);
331*0Sstevel@tonic-gate if (!db)
332*0Sstevel@tonic-gate return NULL;
333*0Sstevel@tonic-gate memset(db, 0, sizeof(*db) - sizeof(db->dict));
334*0Sstevel@tonic-gate
335*0Sstevel@tonic-gate if (!decomp) {
336*0Sstevel@tonic-gate db->lens = NULL;
337*0Sstevel@tonic-gate } else {
338*0Sstevel@tonic-gate db->lens = (u_short *) malloc((maxmaxcode+1) * sizeof(db->lens[0]));
339*0Sstevel@tonic-gate if (!db->lens) {
340*0Sstevel@tonic-gate free(db);
341*0Sstevel@tonic-gate return NULL;
342*0Sstevel@tonic-gate }
343*0Sstevel@tonic-gate }
344*0Sstevel@tonic-gate
345*0Sstevel@tonic-gate db->totlen = newlen;
346*0Sstevel@tonic-gate db->hsize = hsize;
347*0Sstevel@tonic-gate db->hshift = hshift;
348*0Sstevel@tonic-gate db->maxmaxcode = maxmaxcode;
349*0Sstevel@tonic-gate db->maxbits = bits;
350*0Sstevel@tonic-gate
351*0Sstevel@tonic-gate return (void *) db;
352*0Sstevel@tonic-gate }
353*0Sstevel@tonic-gate
354*0Sstevel@tonic-gate static void
bsd_free(state)355*0Sstevel@tonic-gate bsd_free(state)
356*0Sstevel@tonic-gate void *state;
357*0Sstevel@tonic-gate {
358*0Sstevel@tonic-gate struct bsd_db *db = (struct bsd_db *) state;
359*0Sstevel@tonic-gate
360*0Sstevel@tonic-gate if (db->lens)
361*0Sstevel@tonic-gate free(db->lens);
362*0Sstevel@tonic-gate free(db);
363*0Sstevel@tonic-gate }
364*0Sstevel@tonic-gate
365*0Sstevel@tonic-gate static void *
bsd_decomp_alloc(options,opt_len)366*0Sstevel@tonic-gate bsd_decomp_alloc(options, opt_len)
367*0Sstevel@tonic-gate u_char *options;
368*0Sstevel@tonic-gate int opt_len;
369*0Sstevel@tonic-gate {
370*0Sstevel@tonic-gate return bsd_alloc(options, opt_len, 1);
371*0Sstevel@tonic-gate }
372*0Sstevel@tonic-gate
373*0Sstevel@tonic-gate /*
374*0Sstevel@tonic-gate * Initialize the database.
375*0Sstevel@tonic-gate */
376*0Sstevel@tonic-gate static int
bsd_init(db,options,opt_len,unit,hdrlen,mru,debug,decomp)377*0Sstevel@tonic-gate bsd_init(db, options, opt_len, unit, hdrlen, mru, debug, decomp)
378*0Sstevel@tonic-gate struct bsd_db *db;
379*0Sstevel@tonic-gate u_char *options;
380*0Sstevel@tonic-gate int opt_len, unit, hdrlen, mru, debug, decomp;
381*0Sstevel@tonic-gate {
382*0Sstevel@tonic-gate int i;
383*0Sstevel@tonic-gate
384*0Sstevel@tonic-gate if (opt_len < CILEN_BSD_COMPRESS
385*0Sstevel@tonic-gate || options[0] != CI_BSD_COMPRESS || options[1] != CILEN_BSD_COMPRESS
386*0Sstevel@tonic-gate || BSD_VERSION(options[2]) != BSD_CURRENT_VERSION
387*0Sstevel@tonic-gate || BSD_NBITS(options[2]) != db->maxbits
388*0Sstevel@tonic-gate || decomp && db->lens == NULL)
389*0Sstevel@tonic-gate return 0;
390*0Sstevel@tonic-gate
391*0Sstevel@tonic-gate if (decomp) {
392*0Sstevel@tonic-gate i = LAST+1;
393*0Sstevel@tonic-gate while (i != 0)
394*0Sstevel@tonic-gate db->lens[--i] = 1;
395*0Sstevel@tonic-gate }
396*0Sstevel@tonic-gate i = db->hsize;
397*0Sstevel@tonic-gate while (i != 0) {
398*0Sstevel@tonic-gate db->dict[--i].codem1 = BADCODEM1;
399*0Sstevel@tonic-gate db->dict[i].cptr = 0;
400*0Sstevel@tonic-gate }
401*0Sstevel@tonic-gate
402*0Sstevel@tonic-gate db->unit = unit;
403*0Sstevel@tonic-gate db->hdrlen = hdrlen;
404*0Sstevel@tonic-gate db->mru = mru;
405*0Sstevel@tonic-gate if (debug)
406*0Sstevel@tonic-gate db->debug = 1;
407*0Sstevel@tonic-gate
408*0Sstevel@tonic-gate bsd_reset(db);
409*0Sstevel@tonic-gate
410*0Sstevel@tonic-gate return 1;
411*0Sstevel@tonic-gate }
412*0Sstevel@tonic-gate
413*0Sstevel@tonic-gate static int
bsd_decomp_init(state,options,opt_len,unit,hdrlen,mru,debug)414*0Sstevel@tonic-gate bsd_decomp_init(state, options, opt_len, unit, hdrlen, mru, debug)
415*0Sstevel@tonic-gate void *state;
416*0Sstevel@tonic-gate u_char *options;
417*0Sstevel@tonic-gate int opt_len, unit, hdrlen, mru, debug;
418*0Sstevel@tonic-gate {
419*0Sstevel@tonic-gate return bsd_init((struct bsd_db *) state, options, opt_len,
420*0Sstevel@tonic-gate unit, hdrlen, mru, debug, 1);
421*0Sstevel@tonic-gate }
422*0Sstevel@tonic-gate
423*0Sstevel@tonic-gate
424*0Sstevel@tonic-gate /*
425*0Sstevel@tonic-gate * Update the "BSD Compress" dictionary on the receiver for
426*0Sstevel@tonic-gate * incompressible data by pretending to compress the incoming data.
427*0Sstevel@tonic-gate */
428*0Sstevel@tonic-gate static void
bsd_incomp(state,dmsg,mlen)429*0Sstevel@tonic-gate bsd_incomp(state, dmsg, mlen)
430*0Sstevel@tonic-gate void *state;
431*0Sstevel@tonic-gate u_char *dmsg;
432*0Sstevel@tonic-gate int mlen;
433*0Sstevel@tonic-gate {
434*0Sstevel@tonic-gate struct bsd_db *db = (struct bsd_db *) state;
435*0Sstevel@tonic-gate u_int hshift = db->hshift;
436*0Sstevel@tonic-gate u_int max_ent = db->max_ent;
437*0Sstevel@tonic-gate u_int n_bits = db->n_bits;
438*0Sstevel@tonic-gate struct bsd_dict *dictp;
439*0Sstevel@tonic-gate u_int32_t fcode;
440*0Sstevel@tonic-gate u_char c;
441*0Sstevel@tonic-gate long hval, disp;
442*0Sstevel@tonic-gate int slen, ilen;
443*0Sstevel@tonic-gate u_int bitno = 7;
444*0Sstevel@tonic-gate u_char *rptr;
445*0Sstevel@tonic-gate u_int ent;
446*0Sstevel@tonic-gate
447*0Sstevel@tonic-gate rptr = dmsg;
448*0Sstevel@tonic-gate ent = rptr[0]; /* get the protocol */
449*0Sstevel@tonic-gate if (ent == 0) {
450*0Sstevel@tonic-gate ++rptr;
451*0Sstevel@tonic-gate --mlen;
452*0Sstevel@tonic-gate ent = rptr[0];
453*0Sstevel@tonic-gate }
454*0Sstevel@tonic-gate if ((ent & 1) == 0 || ent < 0x21 || ent > 0xf9)
455*0Sstevel@tonic-gate return;
456*0Sstevel@tonic-gate
457*0Sstevel@tonic-gate db->seqno++;
458*0Sstevel@tonic-gate ilen = 1; /* count the protocol as 1 byte */
459*0Sstevel@tonic-gate ++rptr;
460*0Sstevel@tonic-gate slen = dmsg + mlen - rptr;
461*0Sstevel@tonic-gate ilen += slen;
462*0Sstevel@tonic-gate for (; slen > 0; --slen) {
463*0Sstevel@tonic-gate c = *rptr++;
464*0Sstevel@tonic-gate fcode = BSD_KEY(ent, c);
465*0Sstevel@tonic-gate hval = BSD_HASH(ent, c, hshift);
466*0Sstevel@tonic-gate dictp = &db->dict[hval];
467*0Sstevel@tonic-gate
468*0Sstevel@tonic-gate /* validate and then check the entry */
469*0Sstevel@tonic-gate if (dictp->codem1 >= max_ent)
470*0Sstevel@tonic-gate goto nomatch;
471*0Sstevel@tonic-gate if (dictp->f.fcode == fcode) {
472*0Sstevel@tonic-gate ent = dictp->codem1+1;
473*0Sstevel@tonic-gate continue; /* found (prefix,suffix) */
474*0Sstevel@tonic-gate }
475*0Sstevel@tonic-gate
476*0Sstevel@tonic-gate /* continue probing until a match or invalid entry */
477*0Sstevel@tonic-gate disp = (hval == 0) ? 1 : hval;
478*0Sstevel@tonic-gate do {
479*0Sstevel@tonic-gate hval += disp;
480*0Sstevel@tonic-gate if (hval >= db->hsize)
481*0Sstevel@tonic-gate hval -= db->hsize;
482*0Sstevel@tonic-gate dictp = &db->dict[hval];
483*0Sstevel@tonic-gate if (dictp->codem1 >= max_ent)
484*0Sstevel@tonic-gate goto nomatch;
485*0Sstevel@tonic-gate } while (dictp->f.fcode != fcode);
486*0Sstevel@tonic-gate ent = dictp->codem1+1;
487*0Sstevel@tonic-gate continue; /* finally found (prefix,suffix) */
488*0Sstevel@tonic-gate
489*0Sstevel@tonic-gate nomatch: /* output (count) the prefix */
490*0Sstevel@tonic-gate bitno += n_bits;
491*0Sstevel@tonic-gate
492*0Sstevel@tonic-gate /* code -> hashtable */
493*0Sstevel@tonic-gate if (max_ent < db->maxmaxcode) {
494*0Sstevel@tonic-gate struct bsd_dict *dictp2;
495*0Sstevel@tonic-gate /* expand code size if needed */
496*0Sstevel@tonic-gate if (max_ent >= MAXCODE(n_bits))
497*0Sstevel@tonic-gate db->n_bits = ++n_bits;
498*0Sstevel@tonic-gate
499*0Sstevel@tonic-gate /* Invalidate previous hash table entry
500*0Sstevel@tonic-gate * assigned this code, and then take it over.
501*0Sstevel@tonic-gate */
502*0Sstevel@tonic-gate dictp2 = &db->dict[max_ent+1];
503*0Sstevel@tonic-gate if (db->dict[dictp2->cptr].codem1 == max_ent)
504*0Sstevel@tonic-gate db->dict[dictp2->cptr].codem1 = BADCODEM1;
505*0Sstevel@tonic-gate dictp2->cptr = hval;
506*0Sstevel@tonic-gate dictp->codem1 = max_ent;
507*0Sstevel@tonic-gate dictp->f.fcode = fcode;
508*0Sstevel@tonic-gate
509*0Sstevel@tonic-gate db->max_ent = ++max_ent;
510*0Sstevel@tonic-gate db->lens[max_ent] = db->lens[ent]+1;
511*0Sstevel@tonic-gate }
512*0Sstevel@tonic-gate ent = c;
513*0Sstevel@tonic-gate }
514*0Sstevel@tonic-gate bitno += n_bits; /* output (count) the last code */
515*0Sstevel@tonic-gate db->bytes_out += bitno/8;
516*0Sstevel@tonic-gate db->in_count += ilen;
517*0Sstevel@tonic-gate (void)bsd_check(db);
518*0Sstevel@tonic-gate
519*0Sstevel@tonic-gate ++db->incomp_count;
520*0Sstevel@tonic-gate db->incomp_bytes += ilen;
521*0Sstevel@tonic-gate ++db->uncomp_count;
522*0Sstevel@tonic-gate db->uncomp_bytes += ilen;
523*0Sstevel@tonic-gate
524*0Sstevel@tonic-gate /* Increase code size if we would have without the packet
525*0Sstevel@tonic-gate * boundary and as the decompressor will.
526*0Sstevel@tonic-gate */
527*0Sstevel@tonic-gate if (max_ent >= MAXCODE(n_bits) && max_ent < db->maxmaxcode)
528*0Sstevel@tonic-gate db->n_bits++;
529*0Sstevel@tonic-gate }
530*0Sstevel@tonic-gate
531*0Sstevel@tonic-gate
532*0Sstevel@tonic-gate /*
533*0Sstevel@tonic-gate * Decompress "BSD Compress"
534*0Sstevel@tonic-gate *
535*0Sstevel@tonic-gate * Because of patent problems, we return DECOMP_ERROR for errors
536*0Sstevel@tonic-gate * found by inspecting the input data and for system problems, but
537*0Sstevel@tonic-gate * DECOMP_FATALERROR for any errors which could possibly be said to
538*0Sstevel@tonic-gate * be being detected "after" decompression. For DECOMP_ERROR,
539*0Sstevel@tonic-gate * we can issue a CCP reset-request; for DECOMP_FATALERROR, we may be
540*0Sstevel@tonic-gate * infringing a patent of Motorola's if we do, so we take CCP down
541*0Sstevel@tonic-gate * instead.
542*0Sstevel@tonic-gate *
543*0Sstevel@tonic-gate * Given that the frame has the correct sequence number and a good FCS,
544*0Sstevel@tonic-gate * errors such as invalid codes in the input most likely indicate a
545*0Sstevel@tonic-gate * bug, so we return DECOMP_FATALERROR for them in order to turn off
546*0Sstevel@tonic-gate * compression, even though they are detected by inspecting the input.
547*0Sstevel@tonic-gate */
548*0Sstevel@tonic-gate static int
bsd_decompress(state,cmsg,inlen,dmp,outlenp)549*0Sstevel@tonic-gate bsd_decompress(state, cmsg, inlen, dmp, outlenp)
550*0Sstevel@tonic-gate void *state;
551*0Sstevel@tonic-gate u_char *cmsg, *dmp;
552*0Sstevel@tonic-gate int inlen, *outlenp;
553*0Sstevel@tonic-gate {
554*0Sstevel@tonic-gate struct bsd_db *db = (struct bsd_db *) state;
555*0Sstevel@tonic-gate u_int max_ent = db->max_ent;
556*0Sstevel@tonic-gate u_int32_t accm = 0;
557*0Sstevel@tonic-gate u_int bitno = 32; /* 1st valid bit in accm */
558*0Sstevel@tonic-gate u_int n_bits = db->n_bits;
559*0Sstevel@tonic-gate u_int tgtbitno = 32-n_bits; /* bitno when we have a code */
560*0Sstevel@tonic-gate struct bsd_dict *dictp;
561*0Sstevel@tonic-gate int explen, i, seq, len;
562*0Sstevel@tonic-gate u_int incode, oldcode, finchar;
563*0Sstevel@tonic-gate u_char *p, *rptr, *wptr;
564*0Sstevel@tonic-gate int ilen;
565*0Sstevel@tonic-gate int dlen, space, codelen, extra;
566*0Sstevel@tonic-gate
567*0Sstevel@tonic-gate rptr = cmsg;
568*0Sstevel@tonic-gate if (*rptr == 0)
569*0Sstevel@tonic-gate ++rptr;
570*0Sstevel@tonic-gate ++rptr; /* skip protocol (assumed 0xfd) */
571*0Sstevel@tonic-gate seq = (rptr[0] << 8) + rptr[1];
572*0Sstevel@tonic-gate rptr += BSD_OVHD;
573*0Sstevel@tonic-gate ilen = len = cmsg + inlen - rptr;
574*0Sstevel@tonic-gate
575*0Sstevel@tonic-gate /*
576*0Sstevel@tonic-gate * Check the sequence number and give up if it is not what we expect.
577*0Sstevel@tonic-gate */
578*0Sstevel@tonic-gate if (seq != db->seqno++) {
579*0Sstevel@tonic-gate if (db->debug)
580*0Sstevel@tonic-gate printf("bsd_decomp%d: bad sequence # %d, expected %d\n",
581*0Sstevel@tonic-gate db->unit, seq, db->seqno - 1);
582*0Sstevel@tonic-gate return DECOMP_ERROR;
583*0Sstevel@tonic-gate }
584*0Sstevel@tonic-gate
585*0Sstevel@tonic-gate wptr = dmp + db->hdrlen;
586*0Sstevel@tonic-gate
587*0Sstevel@tonic-gate oldcode = CLEAR;
588*0Sstevel@tonic-gate explen = 0;
589*0Sstevel@tonic-gate while (len > 0) {
590*0Sstevel@tonic-gate /*
591*0Sstevel@tonic-gate * Accumulate bytes until we have a complete code.
592*0Sstevel@tonic-gate * Then get the next code, relying on the 32-bit,
593*0Sstevel@tonic-gate * unsigned accm to mask the result.
594*0Sstevel@tonic-gate */
595*0Sstevel@tonic-gate bitno -= 8;
596*0Sstevel@tonic-gate accm |= *rptr++ << bitno;
597*0Sstevel@tonic-gate --len;
598*0Sstevel@tonic-gate if (tgtbitno < bitno)
599*0Sstevel@tonic-gate continue;
600*0Sstevel@tonic-gate incode = accm >> tgtbitno;
601*0Sstevel@tonic-gate accm <<= n_bits;
602*0Sstevel@tonic-gate bitno += n_bits;
603*0Sstevel@tonic-gate
604*0Sstevel@tonic-gate if (incode == CLEAR) {
605*0Sstevel@tonic-gate /*
606*0Sstevel@tonic-gate * The dictionary must only be cleared at
607*0Sstevel@tonic-gate * the end of a packet. But there could be an
608*0Sstevel@tonic-gate * empty message block at the end.
609*0Sstevel@tonic-gate */
610*0Sstevel@tonic-gate if (len > 0) {
611*0Sstevel@tonic-gate if (db->debug)
612*0Sstevel@tonic-gate printf("bsd_decomp%d: bad CLEAR\n", db->unit);
613*0Sstevel@tonic-gate return DECOMP_FATALERROR;
614*0Sstevel@tonic-gate }
615*0Sstevel@tonic-gate bsd_clear(db);
616*0Sstevel@tonic-gate explen = ilen = 0;
617*0Sstevel@tonic-gate break;
618*0Sstevel@tonic-gate }
619*0Sstevel@tonic-gate
620*0Sstevel@tonic-gate if (incode > max_ent + 2 || incode > db->maxmaxcode
621*0Sstevel@tonic-gate || incode > max_ent && oldcode == CLEAR) {
622*0Sstevel@tonic-gate if (db->debug) {
623*0Sstevel@tonic-gate printf("bsd_decomp%d: bad code 0x%x oldcode=0x%x ",
624*0Sstevel@tonic-gate db->unit, incode, oldcode);
625*0Sstevel@tonic-gate printf("max_ent=0x%x dlen=%d seqno=%d\n",
626*0Sstevel@tonic-gate max_ent, dlen, db->seqno);
627*0Sstevel@tonic-gate }
628*0Sstevel@tonic-gate return DECOMP_FATALERROR; /* probably a bug */
629*0Sstevel@tonic-gate }
630*0Sstevel@tonic-gate
631*0Sstevel@tonic-gate /* Special case for KwKwK string. */
632*0Sstevel@tonic-gate if (incode > max_ent) {
633*0Sstevel@tonic-gate finchar = oldcode;
634*0Sstevel@tonic-gate extra = 1;
635*0Sstevel@tonic-gate } else {
636*0Sstevel@tonic-gate finchar = incode;
637*0Sstevel@tonic-gate extra = 0;
638*0Sstevel@tonic-gate }
639*0Sstevel@tonic-gate
640*0Sstevel@tonic-gate codelen = db->lens[finchar];
641*0Sstevel@tonic-gate explen += codelen + extra;
642*0Sstevel@tonic-gate if (explen > db->mru + 1) {
643*0Sstevel@tonic-gate if (db->debug)
644*0Sstevel@tonic-gate printf("bsd_decomp%d: ran out of mru\n", db->unit);
645*0Sstevel@tonic-gate return DECOMP_FATALERROR;
646*0Sstevel@tonic-gate }
647*0Sstevel@tonic-gate
648*0Sstevel@tonic-gate /*
649*0Sstevel@tonic-gate * Decode this code and install it in the decompressed buffer.
650*0Sstevel@tonic-gate */
651*0Sstevel@tonic-gate p = (wptr += codelen);
652*0Sstevel@tonic-gate while (finchar > LAST) {
653*0Sstevel@tonic-gate dictp = &db->dict[db->dict[finchar].cptr];
654*0Sstevel@tonic-gate #ifdef DEBUG
655*0Sstevel@tonic-gate --codelen;
656*0Sstevel@tonic-gate if (codelen <= 0) {
657*0Sstevel@tonic-gate printf("bsd_decomp%d: fell off end of chain ", db->unit);
658*0Sstevel@tonic-gate printf("0x%x at 0x%x by 0x%x, max_ent=0x%x\n",
659*0Sstevel@tonic-gate incode, finchar, db->dict[finchar].cptr, max_ent);
660*0Sstevel@tonic-gate return DECOMP_FATALERROR;
661*0Sstevel@tonic-gate }
662*0Sstevel@tonic-gate if (dictp->codem1 != finchar-1) {
663*0Sstevel@tonic-gate printf("bsd_decomp%d: bad code chain 0x%x finchar=0x%x ",
664*0Sstevel@tonic-gate db->unit, incode, finchar);
665*0Sstevel@tonic-gate printf("oldcode=0x%x cptr=0x%x codem1=0x%x\n", oldcode,
666*0Sstevel@tonic-gate db->dict[finchar].cptr, dictp->codem1);
667*0Sstevel@tonic-gate return DECOMP_FATALERROR;
668*0Sstevel@tonic-gate }
669*0Sstevel@tonic-gate #endif
670*0Sstevel@tonic-gate *--p = dictp->f.hs.suffix;
671*0Sstevel@tonic-gate finchar = dictp->f.hs.prefix;
672*0Sstevel@tonic-gate }
673*0Sstevel@tonic-gate *--p = finchar;
674*0Sstevel@tonic-gate
675*0Sstevel@tonic-gate #ifdef DEBUG
676*0Sstevel@tonic-gate if (--codelen != 0)
677*0Sstevel@tonic-gate printf("bsd_decomp%d: short by %d after code 0x%x, max_ent=0x%x\n",
678*0Sstevel@tonic-gate db->unit, codelen, incode, max_ent);
679*0Sstevel@tonic-gate #endif
680*0Sstevel@tonic-gate
681*0Sstevel@tonic-gate if (extra) /* the KwKwK case again */
682*0Sstevel@tonic-gate *wptr++ = finchar;
683*0Sstevel@tonic-gate
684*0Sstevel@tonic-gate /*
685*0Sstevel@tonic-gate * If not first code in a packet, and
686*0Sstevel@tonic-gate * if not out of code space, then allocate a new code.
687*0Sstevel@tonic-gate *
688*0Sstevel@tonic-gate * Keep the hash table correct so it can be used
689*0Sstevel@tonic-gate * with uncompressed packets.
690*0Sstevel@tonic-gate */
691*0Sstevel@tonic-gate if (oldcode != CLEAR && max_ent < db->maxmaxcode) {
692*0Sstevel@tonic-gate struct bsd_dict *dictp2;
693*0Sstevel@tonic-gate u_int32_t fcode;
694*0Sstevel@tonic-gate int hval, disp;
695*0Sstevel@tonic-gate
696*0Sstevel@tonic-gate fcode = BSD_KEY(oldcode,finchar);
697*0Sstevel@tonic-gate hval = BSD_HASH(oldcode,finchar,db->hshift);
698*0Sstevel@tonic-gate dictp = &db->dict[hval];
699*0Sstevel@tonic-gate
700*0Sstevel@tonic-gate /* look for a free hash table entry */
701*0Sstevel@tonic-gate if (dictp->codem1 < max_ent) {
702*0Sstevel@tonic-gate disp = (hval == 0) ? 1 : hval;
703*0Sstevel@tonic-gate do {
704*0Sstevel@tonic-gate hval += disp;
705*0Sstevel@tonic-gate if (hval >= db->hsize)
706*0Sstevel@tonic-gate hval -= db->hsize;
707*0Sstevel@tonic-gate dictp = &db->dict[hval];
708*0Sstevel@tonic-gate } while (dictp->codem1 < max_ent);
709*0Sstevel@tonic-gate }
710*0Sstevel@tonic-gate
711*0Sstevel@tonic-gate /*
712*0Sstevel@tonic-gate * Invalidate previous hash table entry
713*0Sstevel@tonic-gate * assigned this code, and then take it over
714*0Sstevel@tonic-gate */
715*0Sstevel@tonic-gate dictp2 = &db->dict[max_ent+1];
716*0Sstevel@tonic-gate if (db->dict[dictp2->cptr].codem1 == max_ent) {
717*0Sstevel@tonic-gate db->dict[dictp2->cptr].codem1 = BADCODEM1;
718*0Sstevel@tonic-gate }
719*0Sstevel@tonic-gate dictp2->cptr = hval;
720*0Sstevel@tonic-gate dictp->codem1 = max_ent;
721*0Sstevel@tonic-gate dictp->f.fcode = fcode;
722*0Sstevel@tonic-gate
723*0Sstevel@tonic-gate db->max_ent = ++max_ent;
724*0Sstevel@tonic-gate db->lens[max_ent] = db->lens[oldcode]+1;
725*0Sstevel@tonic-gate
726*0Sstevel@tonic-gate /* Expand code size if needed. */
727*0Sstevel@tonic-gate if (max_ent >= MAXCODE(n_bits) && max_ent < db->maxmaxcode) {
728*0Sstevel@tonic-gate db->n_bits = ++n_bits;
729*0Sstevel@tonic-gate tgtbitno = 32-n_bits;
730*0Sstevel@tonic-gate }
731*0Sstevel@tonic-gate }
732*0Sstevel@tonic-gate oldcode = incode;
733*0Sstevel@tonic-gate }
734*0Sstevel@tonic-gate *outlenp = wptr - (dmp + db->hdrlen);
735*0Sstevel@tonic-gate
736*0Sstevel@tonic-gate /*
737*0Sstevel@tonic-gate * Keep the checkpoint right so that incompressible packets
738*0Sstevel@tonic-gate * clear the dictionary at the right times.
739*0Sstevel@tonic-gate */
740*0Sstevel@tonic-gate db->bytes_out += ilen;
741*0Sstevel@tonic-gate db->in_count += explen;
742*0Sstevel@tonic-gate if (bsd_check(db) && db->debug) {
743*0Sstevel@tonic-gate printf("bsd_decomp%d: peer should have cleared dictionary\n",
744*0Sstevel@tonic-gate db->unit);
745*0Sstevel@tonic-gate }
746*0Sstevel@tonic-gate
747*0Sstevel@tonic-gate ++db->comp_count;
748*0Sstevel@tonic-gate db->comp_bytes += ilen + BSD_OVHD;
749*0Sstevel@tonic-gate ++db->uncomp_count;
750*0Sstevel@tonic-gate db->uncomp_bytes += explen;
751*0Sstevel@tonic-gate
752*0Sstevel@tonic-gate return DECOMP_OK;
753*0Sstevel@tonic-gate }
754*0Sstevel@tonic-gate #endif /* DO_BSD_COMPRESS */
755