diff options
author | brian <brian@FreeBSD.org> | 1998-05-21 21:49:08 +0000 |
---|---|---|
committer | brian <brian@FreeBSD.org> | 1998-05-21 21:49:08 +0000 |
commit | 56df88b778aee0e60678672b107a48a8ea05cb48 (patch) | |
tree | 13b88ca17b38e787c84b0cd242677b3c3c0b93c3 /usr.sbin/ppp/deflate.c | |
parent | e077fa331b8a428923ded3a95d0b8d47084cf670 (diff) | |
download | FreeBSD-src-56df88b778aee0e60678672b107a48a8ea05cb48.zip FreeBSD-src-56df88b778aee0e60678672b107a48a8ea05cb48.tar.gz |
MFMP: Make ppp multilink capable.
See the file README.changes, and re-read the man page.
Diffstat (limited to 'usr.sbin/ppp/deflate.c')
-rw-r--r-- | usr.sbin/ppp/deflate.c | 466 |
1 files changed, 220 insertions, 246 deletions
diff --git a/usr.sbin/ppp/deflate.c b/usr.sbin/ppp/deflate.c index f3e6d17..08e5f85 100644 --- a/usr.sbin/ppp/deflate.c +++ b/usr.sbin/ppp/deflate.c @@ -23,67 +23,64 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: deflate.c,v 1.6 1998/01/10 01:55:09 brian Exp $ + * $Id: deflate.c,v 1.6.4.16 1998/05/15 18:21:03 brian Exp $ */ -#include <sys/param.h> -#include <netinet/in.h> +#include <sys/types.h> #include <stdio.h> #include <stdlib.h> #include <zlib.h> -#include "command.h" #include "mbuf.h" #include "log.h" -#include "defs.h" -#include "loadalias.h" -#include "vars.h" +#include "timer.h" +#include "lqr.h" #include "hdlc.h" +#include "fsm.h" #include "lcp.h" #include "ccp.h" -#include "lcpproto.h" -#include "timer.h" -#include "fsm.h" #include "deflate.h" /* Our state */ struct deflate_state { u_short seqno; int uncomp_rec; + int winsize; z_stream cx; }; -static int iWindowSize = 15; -static int oWindowSize = 15; -static struct deflate_state InputState, OutputState; static char garbage[10]; static u_char EMPTY_BLOCK[4] = { 0x00, 0x00, 0xff, 0xff }; #define DEFLATE_CHUNK_LEN 1024 /* Allocate mbufs this size */ static void -DeflateResetOutput(void) +DeflateResetOutput(void *v) { - OutputState.seqno = 0; - OutputState.uncomp_rec = 0; - deflateReset(&OutputState.cx); - LogPrintf(LogCCP, "Deflate: Output channel reset\n"); + struct deflate_state *state = (struct deflate_state *)v; + + state->seqno = 0; + state->uncomp_rec = 0; + deflateReset(&state->cx); + log_Printf(LogCCP, "Deflate: Output channel reset\n"); } static int -DeflateOutput(int pri, u_short proto, struct mbuf *mp) +DeflateOutput(void *v, struct ccp *ccp, struct link *l, int pri, u_short proto, + struct mbuf *mp) { + struct deflate_state *state = (struct deflate_state *)v; u_char *wp, *rp; int olen, ilen, len, res, flush; struct mbuf *mo_head, *mo, *mi_head, *mi; - ilen = plength(mp); - LogPrintf(LogDEBUG, "DeflateOutput: Proto %02x (%d bytes)\n", proto, ilen); - LogDumpBp(LogDEBUG, "DeflateOutput: Compress packet:", mp); + ilen = mbuf_Length(mp); + log_Printf(LogDEBUG, "DeflateOutput: Proto %02x (%d bytes)\n", proto, ilen); + log_DumpBp(LogDEBUG, "DeflateOutput: Compress packet:", mp); /* Stuff the protocol in front of the input */ - mi_head = mi = mballoc(2, MB_HDLCOUT); + mi_head = mi = mbuf_Alloc(2, MB_HDLCOUT); mi->next = mp; rp = MBUF_CTOP(mi); if (proto < 0x100) { /* Compress the protocol */ @@ -96,74 +93,73 @@ DeflateOutput(int pri, u_short proto, struct mbuf *mp) } /* Allocate the initial output mbuf */ - mo_head = mo = mballoc(DEFLATE_CHUNK_LEN, MB_HDLCOUT); + mo_head = mo = mbuf_Alloc(DEFLATE_CHUNK_LEN, MB_HDLCOUT); mo->cnt = 2; wp = MBUF_CTOP(mo); - *wp++ = OutputState.seqno >> 8; - *wp++ = OutputState.seqno & 0377; - LogPrintf(LogDEBUG, "DeflateOutput: Seq %d\n", OutputState.seqno); - OutputState.seqno++; + *wp++ = state->seqno >> 8; + *wp++ = state->seqno & 0377; + log_Printf(LogDEBUG, "DeflateOutput: Seq %d\n", state->seqno); + state->seqno++; /* Set up the deflation context */ - OutputState.cx.next_out = wp; - OutputState.cx.avail_out = DEFLATE_CHUNK_LEN - 2; - OutputState.cx.next_in = MBUF_CTOP(mi); - OutputState.cx.avail_in = mi->cnt; + state->cx.next_out = wp; + state->cx.avail_out = DEFLATE_CHUNK_LEN - 2; + state->cx.next_in = MBUF_CTOP(mi); + state->cx.avail_in = mi->cnt; flush = Z_NO_FLUSH; olen = 0; while (1) { - if ((res = deflate(&OutputState.cx, flush)) != Z_OK) { + if ((res = deflate(&state->cx, flush)) != Z_OK) { if (res == Z_STREAM_END) break; /* Done */ - LogPrintf(LogERROR, "DeflateOutput: deflate returned %d (%s)\n", - res, OutputState.cx.msg ? OutputState.cx.msg : ""); - pfree(mo_head); - mbfree(mi_head); - OutputState.seqno--; + log_Printf(LogERROR, "DeflateOutput: deflate returned %d (%s)\n", + res, state->cx.msg ? state->cx.msg : ""); + mbuf_Free(mo_head); + mbuf_FreeSeg(mi_head); + state->seqno--; return 1; /* packet dropped */ } - if (flush == Z_SYNC_FLUSH && OutputState.cx.avail_out != 0) + if (flush == Z_SYNC_FLUSH && state->cx.avail_out != 0) break; - if (OutputState.cx.avail_in == 0 && mi->next != NULL) { + if (state->cx.avail_in == 0 && mi->next != NULL) { mi = mi->next; - OutputState.cx.next_in = MBUF_CTOP(mi); - OutputState.cx.avail_in = mi->cnt; + state->cx.next_in = MBUF_CTOP(mi); + state->cx.avail_in = mi->cnt; if (mi->next == NULL) flush = Z_SYNC_FLUSH; } - if (OutputState.cx.avail_out == 0) { - mo->next = mballoc(DEFLATE_CHUNK_LEN, MB_HDLCOUT); + if (state->cx.avail_out == 0) { + mo->next = mbuf_Alloc(DEFLATE_CHUNK_LEN, MB_HDLCOUT); olen += (mo->cnt = DEFLATE_CHUNK_LEN); mo = mo->next; mo->cnt = 0; - OutputState.cx.next_out = MBUF_CTOP(mo); - OutputState.cx.avail_out = DEFLATE_CHUNK_LEN; + state->cx.next_out = MBUF_CTOP(mo); + state->cx.avail_out = DEFLATE_CHUNK_LEN; } } - olen += (mo->cnt = DEFLATE_CHUNK_LEN - OutputState.cx.avail_out); + olen += (mo->cnt = DEFLATE_CHUNK_LEN - state->cx.avail_out); olen -= 4; /* exclude the trailing EMPTY_BLOCK */ /* * If the output packet (including seqno and excluding the EMPTY_BLOCK) - * got bigger, send the original - returning 0 to HdlcOutput() will - * continue to send ``mp''. + * got bigger, send the original. */ if (olen >= ilen) { - pfree(mo_head); - mbfree(mi_head); - LogPrintf(LogDEBUG, "DeflateOutput: %d => %d: Uncompressible (0x%04x)\n", + mbuf_Free(mo_head); + mbuf_FreeSeg(mi_head); + log_Printf(LogDEBUG, "DeflateOutput: %d => %d: Uncompressible (0x%04x)\n", ilen, olen, proto); - CcpInfo.uncompout += ilen; - CcpInfo.compout += ilen; /* We measure this stuff too */ + ccp->uncompout += ilen; + ccp->compout += ilen; /* We measure this stuff too */ return 0; } - pfree(mi_head); + mbuf_Free(mi_head); /* * Lose the last four bytes of our output. @@ -174,66 +170,69 @@ DeflateOutput(int pri, u_short proto, struct mbuf *mp) ; mo->cnt -= len - olen; if (mo->next != NULL) { - pfree(mo->next); + mbuf_Free(mo->next); mo->next = NULL; } - CcpInfo.uncompout += ilen; - CcpInfo.compout += olen; + ccp->uncompout += ilen; + ccp->compout += olen; - LogPrintf(LogDEBUG, "DeflateOutput: %d => %d bytes, proto 0x%04x\n", + log_Printf(LogDEBUG, "DeflateOutput: %d => %d bytes, proto 0x%04x\n", ilen, olen, proto); - HdlcOutput(PRI_NORMAL, PROTO_COMPD, mo_head); + hdlc_Output(l, PRI_NORMAL, ccp_Proto(ccp), mo_head); return 1; } static void -DeflateResetInput(void) +DeflateResetInput(void *v) { - InputState.seqno = 0; - InputState.uncomp_rec = 0; - inflateReset(&InputState.cx); - LogPrintf(LogCCP, "Deflate: Input channel reset\n"); + struct deflate_state *state = (struct deflate_state *)v; + + state->seqno = 0; + state->uncomp_rec = 0; + inflateReset(&state->cx); + log_Printf(LogCCP, "Deflate: Input channel reset\n"); } static struct mbuf * -DeflateInput(u_short *proto, struct mbuf *mi) +DeflateInput(void *v, struct ccp *ccp, u_short *proto, struct mbuf *mi) { + struct deflate_state *state = (struct deflate_state *)v; struct mbuf *mo, *mo_head, *mi_head; u_char *wp; int ilen, olen; int seq, flush, res, first; u_char hdr[2]; - LogDumpBp(LogDEBUG, "DeflateInput: Decompress packet:", mi); - mi_head = mi = mbread(mi, hdr, 2); + log_DumpBp(LogDEBUG, "DeflateInput: Decompress packet:", mi); + mi_head = mi = mbuf_Read(mi, hdr, 2); ilen = 2; /* Check the sequence number. */ seq = (hdr[0] << 8) + hdr[1]; - LogPrintf(LogDEBUG, "DeflateInput: Seq %d\n", seq); - if (seq != InputState.seqno) { - if (seq <= InputState.uncomp_rec) + log_Printf(LogDEBUG, "DeflateInput: Seq %d\n", seq); + if (seq != state->seqno) { + if (seq <= state->uncomp_rec) /* * So the peer's started at zero again - fine ! If we're wrong, * inflate() will fail. This is better than getting into a loop * trying to get a ResetReq to a busy sender. */ - InputState.seqno = seq; + state->seqno = seq; else { - LogPrintf(LogERROR, "DeflateInput: Seq error: Got %d, expected %d\n", - seq, InputState.seqno); - pfree(mi_head); - CcpSendResetReq(&CcpFsm); + log_Printf(LogERROR, "DeflateInput: Seq error: Got %d, expected %d\n", + seq, state->seqno); + mbuf_Free(mi_head); + ccp_SendResetReq(&ccp->fsm); return NULL; } } - InputState.seqno++; - InputState.uncomp_rec = 0; + state->seqno++; + state->uncomp_rec = 0; /* Allocate an output mbuf */ - mo_head = mo = mballoc(DEFLATE_CHUNK_LEN, MB_IPIN); + mo_head = mo = mbuf_Alloc(DEFLATE_CHUNK_LEN, MB_IPIN); /* Our proto starts with 0 if it's compressed */ wp = MBUF_CTOP(mo); @@ -244,10 +243,10 @@ DeflateInput(u_short *proto, struct mbuf *mi) * byte of the output and decide whether we have a compressed * proto field. */ - InputState.cx.next_in = MBUF_CTOP(mi); - InputState.cx.avail_in = mi->cnt; - InputState.cx.next_out = wp + 1; - InputState.cx.avail_out = 1; + state->cx.next_in = MBUF_CTOP(mi); + state->cx.avail_in = mi->cnt; + state->cx.next_out = wp + 1; + state->cx.avail_out = 1; ilen += mi->cnt; flush = mi->next ? Z_NO_FLUSH : Z_SYNC_FLUSH; @@ -255,102 +254,103 @@ DeflateInput(u_short *proto, struct mbuf *mi) olen = 0; while (1) { - if ((res = inflate(&InputState.cx, flush)) != Z_OK) { + if ((res = inflate(&state->cx, flush)) != Z_OK) { if (res == Z_STREAM_END) break; /* Done */ - LogPrintf(LogERROR, "DeflateInput: inflate returned %d (%s)\n", - res, InputState.cx.msg ? InputState.cx.msg : ""); - pfree(mo_head); - pfree(mi); - CcpSendResetReq(&CcpFsm); + log_Printf(LogERROR, "DeflateInput: inflate returned %d (%s)\n", + res, state->cx.msg ? state->cx.msg : ""); + mbuf_Free(mo_head); + mbuf_Free(mi); + ccp_SendResetReq(&ccp->fsm); return NULL; } - if (flush == Z_SYNC_FLUSH && InputState.cx.avail_out != 0) + if (flush == Z_SYNC_FLUSH && state->cx.avail_out != 0) break; - if (InputState.cx.avail_in == 0 && mi && (mi = mbfree(mi)) != NULL) { + if (state->cx.avail_in == 0 && mi && (mi = mbuf_FreeSeg(mi)) != NULL) { /* underflow */ - InputState.cx.next_in = MBUF_CTOP(mi); - ilen += (InputState.cx.avail_in = mi->cnt); + state->cx.next_in = MBUF_CTOP(mi); + ilen += (state->cx.avail_in = mi->cnt); if (mi->next == NULL) flush = Z_SYNC_FLUSH; } - if (InputState.cx.avail_out == 0) { + if (state->cx.avail_out == 0) { /* overflow */ if (first) { if (!(wp[1] & 1)) { /* 2 byte proto, shuffle it back in output */ wp[0] = wp[1]; - InputState.cx.next_out--; - InputState.cx.avail_out = DEFLATE_CHUNK_LEN-1; + state->cx.next_out--; + state->cx.avail_out = DEFLATE_CHUNK_LEN-1; } else - InputState.cx.avail_out = DEFLATE_CHUNK_LEN-2; + state->cx.avail_out = DEFLATE_CHUNK_LEN-2; first = 0; } else { olen += (mo->cnt = DEFLATE_CHUNK_LEN); - mo->next = mballoc(DEFLATE_CHUNK_LEN, MB_IPIN); + mo->next = mbuf_Alloc(DEFLATE_CHUNK_LEN, MB_IPIN); mo = mo->next; - InputState.cx.next_out = MBUF_CTOP(mo); - InputState.cx.avail_out = DEFLATE_CHUNK_LEN; + state->cx.next_out = MBUF_CTOP(mo); + state->cx.avail_out = DEFLATE_CHUNK_LEN; } } } if (mi != NULL) - pfree(mi); + mbuf_Free(mi); if (first) { - LogPrintf(LogERROR, "DeflateInput: Length error\n"); - pfree(mo_head); - CcpSendResetReq(&CcpFsm); + log_Printf(LogERROR, "DeflateInput: Length error\n"); + mbuf_Free(mo_head); + ccp_SendResetReq(&ccp->fsm); return NULL; } - olen += (mo->cnt = DEFLATE_CHUNK_LEN - InputState.cx.avail_out); + olen += (mo->cnt = DEFLATE_CHUNK_LEN - state->cx.avail_out); *proto = ((u_short)wp[0] << 8) | wp[1]; mo_head->offset += 2; mo_head->cnt -= 2; olen -= 2; - CcpInfo.compin += ilen; - CcpInfo.uncompin += olen; + ccp->compin += ilen; + ccp->uncompin += olen; - LogPrintf(LogDEBUG, "DeflateInput: %d => %d bytes, proto 0x%04x\n", + log_Printf(LogDEBUG, "DeflateInput: %d => %d bytes, proto 0x%04x\n", ilen, olen, *proto); /* * Simulate an EMPTY_BLOCK so that our dictionary stays in sync. * The peer will have silently removed this! */ - InputState.cx.next_out = garbage; - InputState.cx.avail_out = sizeof garbage; - InputState.cx.next_in = EMPTY_BLOCK; - InputState.cx.avail_in = sizeof EMPTY_BLOCK; - inflate(&InputState.cx, Z_SYNC_FLUSH); + state->cx.next_out = garbage; + state->cx.avail_out = sizeof garbage; + state->cx.next_in = EMPTY_BLOCK; + state->cx.avail_in = sizeof EMPTY_BLOCK; + inflate(&state->cx, Z_SYNC_FLUSH); return mo_head; } static void -DeflateDictSetup(u_short proto, struct mbuf *mi) +DeflateDictSetup(void *v, struct ccp *ccp, u_short proto, struct mbuf *mi) { + struct deflate_state *state = (struct deflate_state *)v; int res, flush, expect_error; u_char *rp; struct mbuf *mi_head; short len; - LogPrintf(LogDEBUG, "DeflateDictSetup: Got seq %d\n", InputState.seqno); + log_Printf(LogDEBUG, "DeflateDictSetup: Got seq %d\n", state->seqno); /* * Stuff an ``uncompressed data'' block header followed by the * protocol in front of the input */ - mi_head = mballoc(7, MB_HDLCOUT); + mi_head = mbuf_Alloc(7, MB_HDLCOUT); mi_head->next = mi; - len = plength(mi); + len = mbuf_Length(mi); mi = mi_head; rp = MBUF_CTOP(mi); if (proto < 0x100) { /* Compress the protocol */ @@ -369,41 +369,41 @@ DeflateDictSetup(u_short proto, struct mbuf *mi) rp[3] = (~len) & 0377; /* One's compliment of the length */ rp[4] = (~len) >> 8; - InputState.cx.next_in = rp; - InputState.cx.avail_in = mi->cnt; - InputState.cx.next_out = garbage; - InputState.cx.avail_out = sizeof garbage; + state->cx.next_in = rp; + state->cx.avail_in = mi->cnt; + state->cx.next_out = garbage; + state->cx.avail_out = sizeof garbage; flush = Z_NO_FLUSH; expect_error = 0; while (1) { - if ((res = inflate(&InputState.cx, flush)) != Z_OK) { + if ((res = inflate(&state->cx, flush)) != Z_OK) { if (res == Z_STREAM_END) break; /* Done */ if (expect_error && res == Z_BUF_ERROR) break; - LogPrintf(LogERROR, "DeflateDictSetup: inflate returned %d (%s)\n", - res, InputState.cx.msg ? InputState.cx.msg : ""); - LogPrintf(LogERROR, "DeflateDictSetup: avail_in %d, avail_out %d\n", - InputState.cx.avail_in, InputState.cx.avail_out); - CcpSendResetReq(&CcpFsm); - mbfree(mi_head); /* lose our allocated ``head'' buf */ + log_Printf(LogERROR, "DeflateDictSetup: inflate returned %d (%s)\n", + res, state->cx.msg ? state->cx.msg : ""); + log_Printf(LogERROR, "DeflateDictSetup: avail_in %d, avail_out %d\n", + state->cx.avail_in, state->cx.avail_out); + ccp_SendResetReq(&ccp->fsm); + mbuf_FreeSeg(mi_head); /* lose our allocated ``head'' buf */ return; } - if (flush == Z_SYNC_FLUSH && InputState.cx.avail_out != 0) + if (flush == Z_SYNC_FLUSH && state->cx.avail_out != 0) break; - if (InputState.cx.avail_in == 0 && mi && (mi = mi->next) != NULL) { + if (state->cx.avail_in == 0 && mi && (mi = mi->next) != NULL) { /* underflow */ - InputState.cx.next_in = MBUF_CTOP(mi); - InputState.cx.avail_in = mi->cnt; + state->cx.next_in = MBUF_CTOP(mi); + state->cx.avail_in = mi->cnt; if (mi->next == NULL) flush = Z_SYNC_FLUSH; } - if (InputState.cx.avail_out == 0) { - if (InputState.cx.avail_in == 0) + if (state->cx.avail_out == 0) { + if (state->cx.avail_in == 0) /* * This seems to be a bug in libz ! If inflate() finished * with 0 avail_in and 0 avail_out *and* this is the end of @@ -417,17 +417,17 @@ DeflateDictSetup(u_short proto, struct mbuf *mi) */ expect_error = 1; /* overflow */ - InputState.cx.next_out = garbage; - InputState.cx.avail_out = sizeof garbage; + state->cx.next_out = garbage; + state->cx.avail_out = sizeof garbage; } } - CcpInfo.compin += len; - CcpInfo.uncompin += len; + ccp->compin += len; + ccp->uncompin += len; - InputState.seqno++; - InputState.uncomp_rec++; - mbfree(mi_head); /* lose our allocated ``head'' buf */ + state->seqno++; + state->uncomp_rec++; + mbuf_FreeSeg(mi_head); /* lose our allocated ``head'' buf */ } static const char * @@ -440,144 +440,119 @@ DeflateDispOpts(struct lcp_opt *o) } static void -DeflateGetInputOpts(struct lcp_opt *o) +DeflateInitOptsOutput(struct lcp_opt *o, const struct ccp_config *cfg) { - o->id = TY_DEFLATE; o->len = 4; - o->data[0] = ((iWindowSize-8)<<4)+8; + o->data[0] = ((cfg->deflate.out.winsize - 8) << 4) + 8; o->data[1] = '\0'; } -static void -DeflateGetOutputOpts(struct lcp_opt *o) +static int +DeflateSetOptsOutput(struct lcp_opt *o) { - o->id = TY_DEFLATE; - o->len = 4; - o->data[0] = ((oWindowSize-8)<<4)+8; - o->data[1] = '\0'; -} + if (o->len != 4 || (o->data[0] & 15) != 8 || o->data[1] != '\0') + return MODE_REJ; -static void -PppdDeflateGetInputOpts(struct lcp_opt *o) -{ - o->id = TY_PPPD_DEFLATE; - o->len = 4; - o->data[0] = ((iWindowSize-8)<<4)+8; - o->data[1] = '\0'; -} + if ((o->data[0] >> 4) + 8 > 15) { + o->data[0] = ((15 - 8) << 4) + 8; + return MODE_NAK; + } -static void -PppdDeflateGetOutputOpts(struct lcp_opt *o) -{ - o->id = TY_PPPD_DEFLATE; - o->len = 4; - o->data[0] = ((oWindowSize-8)<<4)+8; - o->data[1] = '\0'; + return MODE_ACK; } static int -DeflateSetOpts(struct lcp_opt *o, int *sz) +DeflateSetOptsInput(struct lcp_opt *o, const struct ccp_config *cfg) { - if (o->len != 4 || (o->data[0]&15) != 8 || o->data[1] != '\0') { + int want; + + if (o->len != 4 || (o->data[0] & 15) != 8 || o->data[1] != '\0') return MODE_REJ; - } - *sz = (o->data[0] >> 4) + 8; - if (*sz > 15) { - *sz = 15; + + want = (o->data[0] >> 4) + 8; + if (cfg->deflate.in.winsize == 0) { + if (want < 8 || want > 15) { + o->data[0] = ((15 - 8) << 4) + 8; + } + } else if (want != cfg->deflate.in.winsize) { + o->data[0] = ((cfg->deflate.in.winsize - 8) << 4) + 8; return MODE_NAK; } return MODE_ACK; } -static int -DeflateSetInputOpts(struct lcp_opt *o) +static void * +DeflateInitInput(struct lcp_opt *o) { - int res; - res = DeflateSetOpts(o, &iWindowSize); - if (res != MODE_ACK) - DeflateGetInputOpts(o); - return res; -} + struct deflate_state *state; + + state = (struct deflate_state *)malloc(sizeof(struct deflate_state)); + if (state != NULL) { + state->winsize = (o->data[0] >> 4) + 8; + state->cx.zalloc = NULL; + state->cx.opaque = NULL; + state->cx.zfree = NULL; + state->cx.next_out = NULL; + if (inflateInit2(&state->cx, -state->winsize) == Z_OK) + DeflateResetInput(state); + else { + free(state); + state = NULL; + } + } -static int -DeflateSetOutputOpts(struct lcp_opt *o) -{ - int res; - res = DeflateSetOpts(o, &oWindowSize); - if (res != MODE_ACK) - DeflateGetOutputOpts(o); - return res; + return state; } -static int -PppdDeflateSetInputOpts(struct lcp_opt *o) +static void * +DeflateInitOutput(struct lcp_opt *o) { - int res; - res = DeflateSetOpts(o, &iWindowSize); - if (res != MODE_ACK) - PppdDeflateGetInputOpts(o); - return res; -} + struct deflate_state *state; + + state = (struct deflate_state *)malloc(sizeof(struct deflate_state)); + if (state != NULL) { + state->winsize = (o->data[0] >> 4) + 8; + state->cx.zalloc = NULL; + state->cx.opaque = NULL; + state->cx.zfree = NULL; + state->cx.next_in = NULL; + if (deflateInit2(&state->cx, Z_DEFAULT_COMPRESSION, 8, + -state->winsize, 8, Z_DEFAULT_STRATEGY) == Z_OK) + DeflateResetOutput(state); + else { + free(state); + state = NULL; + } + } -static int -PppdDeflateSetOutputOpts(struct lcp_opt *o) -{ - int res; - res = DeflateSetOpts(o, &oWindowSize); - if (res != MODE_ACK) - PppdDeflateGetOutputOpts(o); - return res; + return state; } -static int -DeflateInitInput(void) +static void +DeflateTermInput(void *v) { - InputState.cx.zalloc = NULL; - InputState.cx.opaque = NULL; - InputState.cx.zfree = NULL; - InputState.cx.next_out = NULL; - if (inflateInit2(&InputState.cx, -iWindowSize) != Z_OK) - return 0; - DeflateResetInput(); - return 1; -} + struct deflate_state *state = (struct deflate_state *)v; -static int -DeflateInitOutput(void) -{ - OutputState.cx.zalloc = NULL; - OutputState.cx.opaque = NULL; - OutputState.cx.zfree = NULL; - OutputState.cx.next_in = NULL; - if (deflateInit2(&OutputState.cx, Z_DEFAULT_COMPRESSION, 8, - -oWindowSize, 8, Z_DEFAULT_STRATEGY) != Z_OK) - return 0; - DeflateResetOutput(); - return 1; + inflateEnd(&state->cx); + free(state); } static void -DeflateTermInput(void) +DeflateTermOutput(void *v) { - iWindowSize = 15; - inflateEnd(&InputState.cx); -} + struct deflate_state *state = (struct deflate_state *)v; -static void -DeflateTermOutput(void) -{ - oWindowSize = 15; - deflateEnd(&OutputState.cx); + deflateEnd(&state->cx); + free(state); } const struct ccp_algorithm PppdDeflateAlgorithm = { TY_PPPD_DEFLATE, /* pppd (wrongly) expects this ``type'' field */ - ConfPppdDeflate, + CCP_NEG_DEFLATE24, DeflateDispOpts, { - PppdDeflateGetInputOpts, - PppdDeflateSetInputOpts, + DeflateSetOptsInput, DeflateInitInput, DeflateTermInput, DeflateResetInput, @@ -585,8 +560,8 @@ const struct ccp_algorithm PppdDeflateAlgorithm = { DeflateDictSetup }, { - PppdDeflateGetOutputOpts, - PppdDeflateSetOutputOpts, + DeflateInitOptsOutput, + DeflateSetOptsOutput, DeflateInitOutput, DeflateTermOutput, DeflateResetOutput, @@ -596,11 +571,10 @@ const struct ccp_algorithm PppdDeflateAlgorithm = { const struct ccp_algorithm DeflateAlgorithm = { TY_DEFLATE, /* rfc 1979 */ - ConfDeflate, + CCP_NEG_DEFLATE, DeflateDispOpts, { - DeflateGetInputOpts, - DeflateSetInputOpts, + DeflateSetOptsInput, DeflateInitInput, DeflateTermInput, DeflateResetInput, @@ -608,8 +582,8 @@ const struct ccp_algorithm DeflateAlgorithm = { DeflateDictSetup }, { - DeflateGetOutputOpts, - DeflateSetOutputOpts, + DeflateInitOptsOutput, + DeflateSetOptsOutput, DeflateInitOutput, DeflateTermOutput, DeflateResetOutput, |