diff options
Diffstat (limited to 'usr.sbin/ppp/pred.c')
-rw-r--r-- | usr.sbin/ppp/pred.c | 147 |
1 files changed, 123 insertions, 24 deletions
diff --git a/usr.sbin/ppp/pred.c b/usr.sbin/ppp/pred.c index 3b4cfff..23b9ec3 100644 --- a/usr.sbin/ppp/pred.c +++ b/usr.sbin/ppp/pred.c @@ -5,24 +5,28 @@ * Updated by: Carsten Bormann <cabo@cs.tu-berlin.de> * Original : Dave Rand <dlr@bungi.com>/<dave_rand@novell.com> * - * $Id: pred.c,v 1.16 1997/11/09 06:22:46 brian Exp $ + * $Id: pred.c,v 1.17 1997/11/22 03:37:44 brian Exp $ * */ -#include <sys/types.h> +#include <sys/param.h> #include <netinet/in.h> #include <stdio.h> +#include <stdlib.h> #include <string.h> #include "command.h" #include "mbuf.h" #include "log.h" #include "defs.h" +#include "loadalias.h" +#include "vars.h" #include "timer.h" #include "fsm.h" #include "hdlc.h" #include "lcpproto.h" +#include "lcp.h" #include "ccp.h" #include "pred.h" @@ -34,10 +38,11 @@ */ #define IHASH(x) do {iHash = (iHash << 4) ^ (x);} while(0) #define OHASH(x) do {oHash = (oHash << 4) ^ (x);} while(0) +#define GUESS_TABLE_SIZE 65536 static unsigned short int iHash, oHash; -static unsigned char InputGuessTable[65536]; -static unsigned char OutputGuessTable[65536]; +static unsigned char *InputGuessTable; +static unsigned char *OutputGuessTable; static int compress(u_char * source, u_char * dest, int len) @@ -102,20 +107,61 @@ decompress(u_char * source, u_char * dest, int len) return (dest - orgdest); } -void -Pred1Init(int direction) +static void +Pred1TermInput(void) { - if (direction & 1) { /* Input part */ - iHash = 0; - memset(InputGuessTable, '\0', sizeof(InputGuessTable)); + if (InputGuessTable != NULL) { + free(InputGuessTable); + InputGuessTable = NULL; } - if (direction & 2) { /* Output part */ - oHash = 0; - memset(OutputGuessTable, '\0', sizeof(OutputGuessTable)); +} + +static void +Pred1TermOutput(void) +{ + if (OutputGuessTable != NULL) { + free(OutputGuessTable); + OutputGuessTable = NULL; } } -void +static void +Pred1ResetInput(void) +{ + iHash = 0; + memset(InputGuessTable, '\0', GUESS_TABLE_SIZE); + LogPrintf(LogCCP, "Predictor1: Input channel reset\n"); +} + +static void +Pred1ResetOutput(void) +{ + oHash = 0; + memset(OutputGuessTable, '\0', GUESS_TABLE_SIZE); + LogPrintf(LogCCP, "Predictor1: Output channel reset\n"); +} + +static int +Pred1InitInput(void) +{ + if (InputGuessTable == NULL) + if ((InputGuessTable = malloc(GUESS_TABLE_SIZE)) == NULL) + return 0; + Pred1ResetInput(); + return 1; +} + +static int +Pred1InitOutput(void) +{ + if (OutputGuessTable == NULL) + if ((OutputGuessTable = malloc(GUESS_TABLE_SIZE)) == NULL) + return 0; + Pred1ResetOutput(); + return 1; +} + +static int Pred1Output(int pri, u_short proto, struct mbuf * bp) { struct mbuf *mwp; @@ -138,7 +184,7 @@ Pred1Output(int pri, u_short proto, struct mbuf * bp) len = compress(bufp + 2, wp, orglen); LogPrintf(LogDEBUG, "Pred1Output: orglen (%d) --> len (%d)\n", orglen, len); - CcpInfo.orgout += orglen; + CcpInfo.uncompout += orglen; if (len < orglen) { *hp |= 0x80; wp += len; @@ -153,16 +199,17 @@ Pred1Output(int pri, u_short proto, struct mbuf * bp) *wp++ = fcs >> 8; mwp->cnt = wp - MBUF_CTOP(mwp); HdlcOutput(PRI_NORMAL, PROTO_COMPD, mwp); + return 1; } -void -Pred1Input(struct mbuf * bp) +static struct mbuf * +Pred1Input(u_short *proto, struct mbuf *bp) { u_char *cp, *pp; int len, olen, len1; struct mbuf *wp; u_char *bufp; - u_short fcs, proto; + u_short fcs; wp = mballoc(MAX_MTU + 2, MB_IPIN); cp = MBUF_CTOP(bp); @@ -172,17 +219,17 @@ Pred1Input(struct mbuf * bp) len = *cp++ << 8; *pp++ = *cp; len += *cp++; - CcpInfo.orgin += len & 0x7fff; + CcpInfo.uncompin += len & 0x7fff; if (len & 0x8000) { len1 = decompress(cp, pp, olen - 4); CcpInfo.compin += olen; len &= 0x7fff; if (len != len1) { /* Error is detected. Send reset request */ - LogPrintf(LogLCP, "%s: Length Error\n", CcpFsm.name); + LogPrintf(LogCCP, "Pred1: Length error\n"); CcpSendResetReq(&CcpFsm); pfree(bp); pfree(wp); - return; + return NULL; } cp += olen - 4; pp += len1; @@ -203,20 +250,72 @@ Pred1Input(struct mbuf * bp) wp->offset += 2; /* skip length */ wp->cnt -= 4; /* skip length & CRC */ pp = MBUF_CTOP(wp); - proto = *pp++; - if (proto & 1) { + *proto = *pp++; + if (*proto & 1) { wp->offset++; wp->cnt--; } else { wp->offset += 2; wp->cnt -= 2; - proto = (proto << 8) | *pp++; + *proto = (*proto << 8) | *pp++; } - DecodePacket(proto, wp); + return wp; } else { LogDumpBp(LogHDLC, "Bad FCS", wp); CcpSendResetReq(&CcpFsm); pfree(wp); } pfree(bp); + return NULL; +} + +static void +Pred1DictSetup(u_short proto, struct mbuf * bp) +{ +} + +static const char * +Pred1DispOpts(struct lcp_opt *o) +{ + return NULL; } + +static void +Pred1GetOpts(struct lcp_opt *o) +{ + o->id = TY_PRED1; + o->len = 2; +} + +static int +Pred1SetOpts(struct lcp_opt *o) +{ + if (o->id != TY_PRED1 || o->len != 2) { + Pred1GetOpts(o); + return MODE_NAK; + } + return MODE_ACK; +} + +const struct ccp_algorithm Pred1Algorithm = { + TY_PRED1, + ConfPred1, + Pred1DispOpts, + { + Pred1GetOpts, + Pred1SetOpts, + Pred1InitInput, + Pred1TermInput, + Pred1ResetInput, + Pred1Input, + Pred1DictSetup + }, + { + Pred1GetOpts, + Pred1SetOpts, + Pred1InitOutput, + Pred1TermOutput, + Pred1ResetOutput, + Pred1Output + }, +}; |