X-Git-Url: https://git.ozlabs.org/?p=ppp.git;a=blobdiff_plain;f=modules%2Fbsd-comp.c;h=d30e0d25f69da08dc4781cdfc6e1b58e85f0e9c0;hp=dfa73aaa538346266f9f2a5d689200fbcab2a551;hb=05ab4543ab743f88b7a26f17d77ce18560358fea;hpb=4891176be9475e37377e36e578657288f2b68770 diff --git a/modules/bsd-comp.c b/modules/bsd-comp.c index dfa73aa..d30e0d2 100644 --- a/modules/bsd-comp.c +++ b/modules/bsd-comp.c @@ -38,20 +38,40 @@ */ /* - * This version is for use with STREAMS under SunOS 4.x. + * This version is for use with STREAMS under SunOS 4.x, + * DEC Alpha OSF/1, and AIX 4.x. * - * $Id: bsd-comp.c,v 1.6 1994/10/24 04:28:14 paulus Exp $ + * $Id: bsd-comp.c,v 1.8 1994/12/08 00:35:33 paulus Exp $ */ +#ifdef __aix4__ +#include +#endif #include #include #include -#include #include #include #include #include +#ifdef sun +#include +#define ALLOCATE(n) kmem_alloc((n), KMEM_NOSLEEP) +#define FREE(p, n) kmem_free((p), (n)) +#endif + +#ifdef __osf__ +#include +#define ALLOCATE(n) kalloc((n)) +#define FREE(p, n) kfree((p), (n)) +#endif + +#ifdef __aix4__ +#define ALLOCATE(n) xmalloc((n), 0, pinned_heap) +#define FREE(p, n) xmfree((p), pinned_heap) +#endif + #define PACKETPTR mblk_t * #include @@ -98,6 +118,7 @@ struct bsd_db { u_char debug; u_char unit; u_short seqno; /* sequence number of next packet */ + u_int hdrlen; /* header length to preallocate */ u_int mru; u_int maxmaxcode; /* largest valid code */ u_int max_ent; /* largest code in use */ @@ -144,7 +165,7 @@ static void bsd_free __P((void *state)); static int bsd_comp_init __P((void *state, u_char *options, int opt_len, int unit, int debug)); static int bsd_decomp_init __P((void *state, u_char *options, int opt_len, - int unit, int mru, int debug)); + int unit, int hdrlen, int mru, int debug)); static int bsd_compress __P((void *state, mblk_t **mret, mblk_t *mp, int slen, int maxolen)); static void bsd_incomp __P((void *state, mblk_t *dmsg)); @@ -351,7 +372,7 @@ bsd_alloc(options, opt_len, decomp) maxmaxcode = MAXCODE(bits); newlen = sizeof(*db) + (hsize-1) * (sizeof(db->dict[0])); - db = (struct bsd_db *) kmem_alloc(newlen, KMEM_NOSLEEP); + db = (struct bsd_db *) ALLOCATE(newlen); if (!db) return NULL; bzero(db, sizeof(*db) - sizeof(db->dict)); @@ -359,10 +380,9 @@ bsd_alloc(options, opt_len, decomp) if (!decomp) { db->lens = NULL; } else { - db->lens = (u_short *) kmem_alloc((maxmaxcode+1) * sizeof(db->lens[0]), - KMEM_NOSLEEP); + db->lens = (u_short *) ALLOCATE((maxmaxcode+1) * sizeof(db->lens[0])); if (!db->lens) { - kmem_free(db, newlen); + FREE(db, newlen); return NULL; } } @@ -383,8 +403,8 @@ bsd_free(state) struct bsd_db *db = (struct bsd_db *) state; if (db->lens) - kmem_free(db->lens, (db->maxmaxcode+1) * sizeof(db->lens[0])); - kmem_free(db, db->totlen); + FREE(db->lens, (db->maxmaxcode+1) * sizeof(db->lens[0])); + FREE(db, db->totlen); } static void * @@ -407,10 +427,10 @@ bsd_decomp_alloc(options, opt_len) * Initialize the database. */ static int -bsd_init(db, options, opt_len, unit, mru, debug, decomp) +bsd_init(db, options, opt_len, unit, hdrlen, mru, debug, decomp) struct bsd_db *db; u_char *options; - int opt_len, unit, mru, debug, decomp; + int opt_len, unit, hdrlen, mru, debug, decomp; { int i; @@ -432,6 +452,7 @@ bsd_init(db, options, opt_len, unit, mru, debug, decomp) } db->unit = unit; + db->hdrlen = hdrlen; db->mru = mru; if (debug) db->debug = 1; @@ -448,17 +469,17 @@ bsd_comp_init(state, options, opt_len, unit, debug) int opt_len, unit, debug; { return bsd_init((struct bsd_db *) state, options, opt_len, - unit, 0, debug, 0); + unit, 0, 0, debug, 0); } static int -bsd_decomp_init(state, options, opt_len, unit, mru, debug) +bsd_decomp_init(state, options, opt_len, unit, hdrlen, mru, debug) void *state; u_char *options; - int opt_len, unit, mru, debug; + int opt_len, unit, hdrlen, mru, debug; { return bsd_init((struct bsd_db *) state, options, opt_len, - unit, mru, debug, 1); + unit, hdrlen, mru, debug, 1); } @@ -881,9 +902,10 @@ bsd_decompress(state, cmsg, dmpp) /* * Allocate one message block to start with. */ - if ((dmsg = allocb(DECOMP_CHUNK, BPRI_MED)) == NULL) + if ((dmsg = allocb(DECOMP_CHUNK + db->hdrlen, BPRI_MED)) == NULL) return DECOMP_ERROR; mret = dmsg; + dmsg->b_wptr += db->hdrlen; dmsg->b_rptr = wptr = dmsg->b_wptr; /* Fill in the ppp header, but not the last byte of the protocol