1998-01-29 00:44:16 +00:00
|
|
|
/*
|
|
|
|
* PPP Compression Control Protocol (CCP) Module
|
|
|
|
*
|
|
|
|
* Written by Toshiharu OHNO (tony-o@iij.ad.jp)
|
|
|
|
*
|
|
|
|
* Copyright (C) 1994, Internet Initiative Japan, Inc. All rights reserverd.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms are permitted
|
|
|
|
* provided that the above copyright notice and this paragraph are
|
|
|
|
* duplicated in all such forms and that any documentation,
|
|
|
|
* advertising materials, and other materials related to such
|
|
|
|
* distribution and use acknowledge that the software was developed
|
|
|
|
* by the Internet Initiative Japan, Inc. The name of the
|
|
|
|
* IIJ may not be used to endorse or promote products derived
|
|
|
|
* from this software without specific prior written permission.
|
|
|
|
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
|
|
|
|
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
|
|
|
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
*
|
1998-02-10 03:23:50 +00:00
|
|
|
* $Id: ccp.c,v 1.30.2.8 1998/02/08 11:04:45 brian Exp $
|
1998-01-29 00:44:16 +00:00
|
|
|
*
|
|
|
|
* TODO:
|
|
|
|
* o Support other compression protocols
|
|
|
|
*/
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <netinet/in.h>
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
1998-02-10 03:23:50 +00:00
|
|
|
#include <termios.h>
|
1998-01-29 00:44:16 +00:00
|
|
|
|
|
|
|
#include "command.h"
|
|
|
|
#include "mbuf.h"
|
|
|
|
#include "log.h"
|
|
|
|
#include "defs.h"
|
|
|
|
#include "timer.h"
|
|
|
|
#include "fsm.h"
|
|
|
|
#include "lcpproto.h"
|
|
|
|
#include "lcp.h"
|
|
|
|
#include "ccp.h"
|
|
|
|
#include "loadalias.h"
|
|
|
|
#include "vars.h"
|
|
|
|
#include "pred.h"
|
|
|
|
#include "deflate.h"
|
1998-02-07 20:50:08 +00:00
|
|
|
#include "bundle.h"
|
1998-02-10 03:23:50 +00:00
|
|
|
#include "descriptor.h"
|
|
|
|
#include "prompt.h"
|
1998-01-29 00:44:16 +00:00
|
|
|
|
|
|
|
static void CcpSendConfigReq(struct fsm *);
|
|
|
|
static void CcpSendTerminateReq(struct fsm *);
|
|
|
|
static void CcpSendTerminateAck(struct fsm *);
|
1998-02-06 02:24:29 +00:00
|
|
|
static void CcpDecodeConfig(struct fsm *, u_char *, int, int);
|
1998-01-29 00:44:16 +00:00
|
|
|
static void CcpLayerStart(struct fsm *);
|
|
|
|
static void CcpLayerFinish(struct fsm *);
|
|
|
|
static void CcpLayerUp(struct fsm *);
|
|
|
|
static void CcpLayerDown(struct fsm *);
|
|
|
|
static void CcpInitRestartCounter(struct fsm *);
|
|
|
|
|
1998-02-06 02:24:29 +00:00
|
|
|
static struct fsm_callbacks ccp_Callbacks = {
|
|
|
|
CcpLayerUp,
|
|
|
|
CcpLayerDown,
|
|
|
|
CcpLayerStart,
|
|
|
|
CcpLayerFinish,
|
|
|
|
CcpInitRestartCounter,
|
|
|
|
CcpSendConfigReq,
|
|
|
|
CcpSendTerminateReq,
|
|
|
|
CcpSendTerminateAck,
|
|
|
|
CcpDecodeConfig
|
|
|
|
};
|
|
|
|
|
1998-02-08 11:05:01 +00:00
|
|
|
struct ccp CcpInfo = {
|
1998-01-31 02:48:30 +00:00
|
|
|
{
|
|
|
|
"CCP",
|
|
|
|
PROTO_CCP,
|
|
|
|
CCP_MAXCODE,
|
|
|
|
0,
|
|
|
|
ST_INITIAL,
|
|
|
|
0, 0, 0,
|
|
|
|
{0, 0, 0, NULL, NULL, NULL}, /* FSM timer */
|
|
|
|
{0, 0, 0, NULL, NULL, NULL}, /* Open timer */
|
|
|
|
{0, 0, 0, NULL, NULL, NULL}, /* Stopped timer */
|
|
|
|
LogCCP,
|
1998-02-02 19:32:16 +00:00
|
|
|
NULL, /* link */
|
|
|
|
NULL, /* bundle */
|
1998-02-06 02:24:29 +00:00
|
|
|
&ccp_Callbacks
|
1998-01-31 02:48:30 +00:00
|
|
|
},
|
|
|
|
-1, -1, -1, -1, -1, -1
|
1998-01-29 00:44:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static char const *cftypes[] = {
|
|
|
|
/* Check out the latest ``Compression Control Protocol'' rfc (rfc1962.txt) */
|
|
|
|
"OUI", /* 0: OUI */
|
|
|
|
"PRED1", /* 1: Predictor type 1 */
|
|
|
|
"PRED2", /* 2: Predictor type 2 */
|
|
|
|
"PUDDLE", /* 3: Puddle Jumber */
|
|
|
|
"???", "???", "???", "???", "???", "???",
|
|
|
|
"???", "???", "???", "???", "???", "???",
|
|
|
|
"HWPPC", /* 16: Hewlett-Packard PPC */
|
|
|
|
"STAC", /* 17: Stac Electronics LZS (rfc1974) */
|
|
|
|
"MSPPC", /* 18: Microsoft PPC */
|
|
|
|
"GAND", /* 19: Gandalf FZA (rfc1993) */
|
|
|
|
"V42BIS", /* 20: ARG->DATA.42bis compression */
|
|
|
|
"BSD", /* 21: BSD LZW Compress */
|
|
|
|
"???",
|
|
|
|
"LZS-DCP", /* 23: LZS-DCP Compression Protocol (rfc1967) */
|
|
|
|
"MAGNALINK/DEFLATE", /* 24: Magnalink Variable Resource (rfc1975) */
|
|
|
|
/* 24: Deflate (according to pppd-2.3.1) */
|
|
|
|
"DCE", /* 25: Data Circuit-Terminating Equip (rfc1976) */
|
|
|
|
"DEFLATE", /* 26: Deflate (rfc1979) */
|
|
|
|
};
|
|
|
|
|
|
|
|
#define NCFTYPES (sizeof cftypes/sizeof cftypes[0])
|
|
|
|
|
|
|
|
static const char *
|
|
|
|
protoname(int proto)
|
|
|
|
{
|
|
|
|
if (proto < 0 || proto > NCFTYPES)
|
|
|
|
return "none";
|
|
|
|
return cftypes[proto];
|
|
|
|
}
|
|
|
|
|
|
|
|
/* We support these algorithms, and Req them in the given order */
|
|
|
|
static const struct ccp_algorithm *algorithm[] = {
|
|
|
|
&DeflateAlgorithm,
|
|
|
|
&Pred1Algorithm,
|
|
|
|
&PppdDeflateAlgorithm
|
|
|
|
};
|
|
|
|
|
|
|
|
#define NALGORITHMS (sizeof algorithm/sizeof algorithm[0])
|
|
|
|
|
|
|
|
int
|
|
|
|
ReportCcpStatus(struct cmdargs const *arg)
|
|
|
|
{
|
1998-02-10 03:23:50 +00:00
|
|
|
prompt_Printf(&prompt, "%s [%s]\n", CcpInfo.fsm.name,
|
|
|
|
StateNames[CcpInfo.fsm.state]);
|
|
|
|
prompt_Printf(&prompt, "My protocol = %s, His protocol = %s\n",
|
|
|
|
protoname(CcpInfo.my_proto), protoname(CcpInfo.his_proto));
|
|
|
|
prompt_Printf(&prompt, "Output: %ld --> %ld, Input: %ld --> %ld\n",
|
|
|
|
CcpInfo.uncompout, CcpInfo.compout,
|
|
|
|
CcpInfo.compin, CcpInfo.uncompin);
|
1998-01-29 00:44:16 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1998-02-02 19:32:16 +00:00
|
|
|
CcpInit(struct bundle *bundle, struct link *l)
|
1998-01-29 00:44:16 +00:00
|
|
|
{
|
1998-01-31 02:48:30 +00:00
|
|
|
/* Initialise ourselves */
|
1998-02-02 19:32:16 +00:00
|
|
|
FsmInit(&CcpInfo.fsm, bundle, l);
|
1998-01-31 02:48:30 +00:00
|
|
|
CcpInfo.his_proto = CcpInfo.my_proto = -1;
|
|
|
|
CcpInfo.reset_sent = CcpInfo.last_reset = -1;
|
|
|
|
CcpInfo.in_algorithm = CcpInfo.out_algorithm = -1;
|
|
|
|
CcpInfo.his_reject = CcpInfo.my_reject = 0;
|
|
|
|
CcpInfo.out_init = CcpInfo.in_init = 0;
|
|
|
|
CcpInfo.uncompout = CcpInfo.compout = 0;
|
|
|
|
CcpInfo.uncompin = CcpInfo.compin = 0;
|
|
|
|
CcpInfo.fsm.maxconfig = 10;
|
1998-01-29 00:44:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
CcpInitRestartCounter(struct fsm *fp)
|
|
|
|
{
|
1998-01-31 02:48:30 +00:00
|
|
|
/* Set fsm timer load */
|
1998-01-29 00:44:16 +00:00
|
|
|
fp->FsmTimer.load = VarRetryTimeout * SECTICKS;
|
|
|
|
fp->restart = 5;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
CcpSendConfigReq(struct fsm *fp)
|
|
|
|
{
|
1998-01-31 02:48:30 +00:00
|
|
|
/* Send config REQ please */
|
1998-02-08 11:05:01 +00:00
|
|
|
struct ccp *ccp = fsm2ccp(fp);
|
1998-01-29 00:44:16 +00:00
|
|
|
u_char *cp;
|
|
|
|
int f;
|
|
|
|
|
|
|
|
LogPrintf(LogCCP, "CcpSendConfigReq\n");
|
|
|
|
cp = ReqBuff;
|
1998-02-06 02:24:29 +00:00
|
|
|
ccp->my_proto = -1;
|
|
|
|
ccp->out_algorithm = -1;
|
1998-01-29 00:44:16 +00:00
|
|
|
for (f = 0; f < NALGORITHMS; f++)
|
1998-02-06 02:24:29 +00:00
|
|
|
if (Enabled(algorithm[f]->Conf) && !REJECTED(ccp, algorithm[f]->id)) {
|
1998-01-29 00:44:16 +00:00
|
|
|
struct lcp_opt o;
|
|
|
|
|
|
|
|
(*algorithm[f]->o.Get)(&o);
|
|
|
|
cp += LcpPutConf(LogCCP, cp, &o, cftypes[o.id],
|
|
|
|
(*algorithm[f]->Disp)(&o));
|
1998-02-06 02:24:29 +00:00
|
|
|
ccp->my_proto = o.id;
|
|
|
|
ccp->out_algorithm = f;
|
1998-01-29 00:44:16 +00:00
|
|
|
}
|
|
|
|
FsmOutput(fp, CODE_CONFIGREQ, fp->reqid++, ReqBuff, cp - ReqBuff);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CcpSendResetReq(struct fsm *fp)
|
|
|
|
{
|
1998-01-31 02:48:30 +00:00
|
|
|
/* We can't read our input - ask peer to reset */
|
1998-02-08 11:05:01 +00:00
|
|
|
struct ccp *ccp = fsm2ccp(fp);
|
1998-01-29 00:44:16 +00:00
|
|
|
LogPrintf(LogCCP, "SendResetReq(%d)\n", fp->reqid);
|
1998-02-06 02:24:29 +00:00
|
|
|
ccp->reset_sent = fp->reqid;
|
|
|
|
ccp->last_reset = -1;
|
1998-01-29 00:44:16 +00:00
|
|
|
FsmOutput(fp, CODE_RESETREQ, fp->reqid, NULL, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
CcpSendTerminateReq(struct fsm *fp)
|
|
|
|
{
|
1998-01-31 02:48:30 +00:00
|
|
|
/* Term REQ just sent by FSM */
|
1998-01-29 00:44:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
CcpSendTerminateAck(struct fsm *fp)
|
|
|
|
{
|
1998-01-31 02:48:30 +00:00
|
|
|
/* Send Term ACK please */
|
1998-01-29 00:44:16 +00:00
|
|
|
LogPrintf(LogCCP, "CcpSendTerminateAck\n");
|
|
|
|
FsmOutput(fp, CODE_TERMACK, fp->reqid++, NULL, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CcpRecvResetReq(struct fsm *fp)
|
|
|
|
{
|
1998-01-31 02:48:30 +00:00
|
|
|
/* Got a reset REQ, reset outgoing dictionary */
|
1998-02-08 11:05:01 +00:00
|
|
|
struct ccp *ccp = fsm2ccp(fp);
|
1998-02-06 02:24:29 +00:00
|
|
|
if (ccp->out_init)
|
|
|
|
(*algorithm[ccp->out_algorithm]->o.Reset)();
|
1998-01-29 00:44:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
CcpLayerStart(struct fsm *fp)
|
|
|
|
{
|
1998-01-31 02:48:30 +00:00
|
|
|
/* We're about to start up ! */
|
1998-01-29 00:44:16 +00:00
|
|
|
LogPrintf(LogCCP, "CcpLayerStart.\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
CcpLayerFinish(struct fsm *fp)
|
|
|
|
{
|
1998-01-31 02:48:30 +00:00
|
|
|
/* We're now down */
|
1998-02-08 11:05:01 +00:00
|
|
|
struct ccp *ccp = fsm2ccp(fp);
|
1998-01-29 00:44:16 +00:00
|
|
|
LogPrintf(LogCCP, "CcpLayerFinish.\n");
|
1998-02-06 02:24:29 +00:00
|
|
|
if (ccp->in_init) {
|
|
|
|
(*algorithm[ccp->in_algorithm]->i.Term)();
|
|
|
|
ccp->in_init = 0;
|
1998-01-31 02:48:30 +00:00
|
|
|
}
|
1998-02-06 02:24:29 +00:00
|
|
|
if (ccp->out_init) {
|
|
|
|
(*algorithm[ccp->out_algorithm]->o.Term)();
|
|
|
|
ccp->out_init = 0;
|
1998-01-31 02:48:30 +00:00
|
|
|
}
|
1998-01-29 00:44:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
CcpLayerDown(struct fsm *fp)
|
|
|
|
{
|
1998-01-31 02:48:30 +00:00
|
|
|
/* About to come down */
|
1998-01-29 00:44:16 +00:00
|
|
|
LogPrintf(LogCCP, "CcpLayerDown.\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Called when CCP has reached the OPEN state
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
CcpLayerUp(struct fsm *fp)
|
|
|
|
{
|
1998-01-31 02:48:30 +00:00
|
|
|
/* We're now up */
|
1998-02-08 11:05:01 +00:00
|
|
|
struct ccp *ccp = fsm2ccp(fp);
|
1998-02-07 20:50:08 +00:00
|
|
|
LogPrintf(LogCCP, "CcpLayerUp.\n");
|
1998-02-06 02:24:29 +00:00
|
|
|
if (!ccp->in_init && ccp->in_algorithm >= 0 &&
|
|
|
|
ccp->in_algorithm < NALGORITHMS)
|
|
|
|
if ((*algorithm[ccp->in_algorithm]->i.Init)())
|
|
|
|
ccp->in_init = 1;
|
1998-01-29 20:45:16 +00:00
|
|
|
else {
|
|
|
|
LogPrintf(LogERROR, "%s (in) initialisation failure\n",
|
1998-02-06 02:24:29 +00:00
|
|
|
protoname(ccp->his_proto));
|
|
|
|
ccp->his_proto = ccp->my_proto = -1;
|
1998-01-29 20:45:16 +00:00
|
|
|
FsmClose(fp);
|
|
|
|
}
|
1998-02-06 02:24:29 +00:00
|
|
|
if (!ccp->out_init && ccp->out_algorithm >= 0 &&
|
|
|
|
ccp->out_algorithm < NALGORITHMS)
|
|
|
|
if ((*algorithm[ccp->out_algorithm]->o.Init)())
|
|
|
|
ccp->out_init = 1;
|
1998-01-29 20:45:16 +00:00
|
|
|
else {
|
|
|
|
LogPrintf(LogERROR, "%s (out) initialisation failure\n",
|
1998-02-06 02:24:29 +00:00
|
|
|
protoname(ccp->my_proto));
|
|
|
|
ccp->his_proto = ccp->my_proto = -1;
|
1998-01-29 20:45:16 +00:00
|
|
|
FsmClose(fp);
|
|
|
|
}
|
1998-01-29 00:44:16 +00:00
|
|
|
LogPrintf(LogCCP, "Out = %s[%d], In = %s[%d]\n",
|
1998-02-06 02:24:29 +00:00
|
|
|
protoname(ccp->my_proto), ccp->my_proto,
|
|
|
|
protoname(ccp->his_proto), ccp->his_proto);
|
1998-01-29 00:44:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CcpUp()
|
|
|
|
{
|
1998-01-31 02:48:30 +00:00
|
|
|
/* Lower layers are ready.... go */
|
|
|
|
FsmUp(&CcpInfo.fsm);
|
1998-01-29 00:44:16 +00:00
|
|
|
LogPrintf(LogCCP, "CCP Up event!!\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CcpOpen()
|
|
|
|
{
|
1998-01-31 02:48:30 +00:00
|
|
|
/* Start CCP please */
|
1998-01-29 00:44:16 +00:00
|
|
|
int f;
|
|
|
|
|
|
|
|
for (f = 0; f < NALGORITHMS; f++)
|
|
|
|
if (Enabled(algorithm[f]->Conf)) {
|
1998-01-31 02:48:30 +00:00
|
|
|
CcpInfo.fsm.open_mode = 0;
|
|
|
|
FsmOpen(&CcpInfo.fsm);
|
1998-01-29 00:44:16 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (f == NALGORITHMS)
|
|
|
|
for (f = 0; f < NALGORITHMS; f++)
|
|
|
|
if (Acceptable(algorithm[f]->Conf)) {
|
1998-01-31 02:48:30 +00:00
|
|
|
CcpInfo.fsm.open_mode = OPEN_PASSIVE;
|
|
|
|
FsmOpen(&CcpInfo.fsm);
|
1998-01-29 00:44:16 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
1998-02-06 02:24:29 +00:00
|
|
|
CcpDecodeConfig(struct fsm *fp, u_char *cp, int plen, int mode_type)
|
1998-01-29 00:44:16 +00:00
|
|
|
{
|
1998-01-31 02:48:30 +00:00
|
|
|
/* Deal with incoming data */
|
1998-02-08 11:05:01 +00:00
|
|
|
struct ccp *ccp = fsm2ccp(fp);
|
1998-01-29 00:44:16 +00:00
|
|
|
int type, length;
|
|
|
|
int f;
|
|
|
|
|
|
|
|
ackp = AckBuff;
|
|
|
|
nakp = NakBuff;
|
|
|
|
rejp = RejBuff;
|
|
|
|
|
|
|
|
while (plen >= sizeof(struct fsmconfig)) {
|
|
|
|
type = *cp;
|
|
|
|
length = cp[1];
|
|
|
|
if (type < NCFTYPES)
|
|
|
|
LogPrintf(LogCCP, " %s[%d]\n", cftypes[type], length);
|
|
|
|
else
|
|
|
|
LogPrintf(LogCCP, " ???[%d]\n", length);
|
|
|
|
|
|
|
|
for (f = NALGORITHMS-1; f > -1; f--)
|
|
|
|
if (algorithm[f]->id == type)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (f == -1) {
|
|
|
|
/* Don't understand that :-( */
|
|
|
|
if (mode_type == MODE_REQ) {
|
1998-02-06 02:24:29 +00:00
|
|
|
ccp->my_reject |= (1 << type);
|
1998-01-29 00:44:16 +00:00
|
|
|
memcpy(rejp, cp, length);
|
|
|
|
rejp += length;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
struct lcp_opt o;
|
|
|
|
|
|
|
|
switch (mode_type) {
|
|
|
|
case MODE_REQ:
|
1998-02-06 02:24:29 +00:00
|
|
|
if (Acceptable(algorithm[f]->Conf) && ccp->in_algorithm == -1) {
|
1998-01-29 00:44:16 +00:00
|
|
|
memcpy(&o, cp, length);
|
|
|
|
switch ((*algorithm[f]->i.Set)(&o)) {
|
|
|
|
case MODE_REJ:
|
|
|
|
memcpy(rejp, &o, o.len);
|
|
|
|
rejp += o.len;
|
|
|
|
break;
|
|
|
|
case MODE_NAK:
|
|
|
|
memcpy(nakp, &o, o.len);
|
|
|
|
nakp += o.len;
|
|
|
|
break;
|
|
|
|
case MODE_ACK:
|
|
|
|
memcpy(ackp, cp, length);
|
|
|
|
ackp += length;
|
1998-02-06 02:24:29 +00:00
|
|
|
ccp->his_proto = type;
|
|
|
|
ccp->in_algorithm = f; /* This one'll do ! */
|
1998-01-29 00:44:16 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
memcpy(rejp, cp, length);
|
|
|
|
rejp += length;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case MODE_NAK:
|
|
|
|
memcpy(&o, cp, length);
|
|
|
|
if ((*algorithm[f]->o.Set)(&o) == MODE_ACK)
|
1998-02-06 02:24:29 +00:00
|
|
|
ccp->my_proto = algorithm[f]->id;
|
1998-01-29 00:44:16 +00:00
|
|
|
else {
|
1998-02-06 02:24:29 +00:00
|
|
|
ccp->his_reject |= (1 << type);
|
|
|
|
ccp->my_proto = -1;
|
1998-01-29 00:44:16 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case MODE_REJ:
|
1998-02-06 02:24:29 +00:00
|
|
|
ccp->his_reject |= (1 << type);
|
|
|
|
ccp->my_proto = -1;
|
1998-01-29 00:44:16 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
plen -= length;
|
|
|
|
cp += length;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rejp != RejBuff) {
|
|
|
|
ackp = AckBuff; /* let's not send both ! */
|
1998-02-06 02:24:29 +00:00
|
|
|
if (!ccp->in_init) {
|
|
|
|
ccp->his_proto = -1;
|
|
|
|
ccp->in_algorithm = -1;
|
1998-01-29 20:45:16 +00:00
|
|
|
}
|
1998-01-29 00:44:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1998-02-07 20:50:08 +00:00
|
|
|
CcpInput(struct bundle *bundle, struct mbuf *bp)
|
1998-01-29 00:44:16 +00:00
|
|
|
{
|
1998-01-31 02:48:30 +00:00
|
|
|
/* Got PROTO_CCP from link */
|
1998-02-07 20:50:08 +00:00
|
|
|
if (bundle_Phase(bundle) == PHASE_NETWORK)
|
1998-01-31 02:48:30 +00:00
|
|
|
FsmInput(&CcpInfo.fsm, bp);
|
1998-02-07 20:50:08 +00:00
|
|
|
else if (bundle_Phase(bundle) < PHASE_NETWORK) {
|
|
|
|
LogPrintf(LogCCP, "Error: Unexpected CCP in phase %s (ignored)\n",
|
|
|
|
bundle_PhaseName(bundle));
|
1998-01-29 00:44:16 +00:00
|
|
|
pfree(bp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CcpResetInput(u_char id)
|
|
|
|
{
|
1998-01-31 02:48:30 +00:00
|
|
|
/* Got a reset ACK, reset incoming dictionary */
|
1998-01-29 00:44:16 +00:00
|
|
|
if (CcpInfo.reset_sent != -1) {
|
|
|
|
if (id != CcpInfo.reset_sent) {
|
|
|
|
LogPrintf(LogWARN, "CCP: Incorrect ResetAck (id %d, not %d) ignored\n",
|
|
|
|
id, CcpInfo.reset_sent);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
/* Whaddaya know - a correct reset ack */
|
|
|
|
} else if (id == CcpInfo.last_reset)
|
|
|
|
LogPrintf(LogCCP, "Duplicate ResetAck (resetting again)\n");
|
|
|
|
else {
|
|
|
|
LogPrintf(LogWARN, "CCP: Unexpected ResetAck (id %d) ignored\n", id);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
CcpInfo.last_reset = CcpInfo.reset_sent;
|
|
|
|
CcpInfo.reset_sent = -1;
|
1998-01-29 20:45:16 +00:00
|
|
|
if (CcpInfo.in_init)
|
|
|
|
(*algorithm[CcpInfo.in_algorithm]->i.Reset)();
|
1998-01-29 00:44:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
1998-01-30 19:46:07 +00:00
|
|
|
CcpOutput(struct link *l, int pri, u_short proto, struct mbuf *m)
|
1998-01-29 00:44:16 +00:00
|
|
|
{
|
1998-01-31 02:48:30 +00:00
|
|
|
/* Compress outgoing data */
|
1998-01-29 20:45:16 +00:00
|
|
|
if (CcpInfo.out_init)
|
1998-01-30 19:46:07 +00:00
|
|
|
return (*algorithm[CcpInfo.out_algorithm]->o.Write)(l, pri, proto, m);
|
1998-01-29 00:44:16 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct mbuf *
|
|
|
|
CompdInput(u_short *proto, struct mbuf *m)
|
|
|
|
{
|
1998-01-31 02:48:30 +00:00
|
|
|
/* Decompress incoming data */
|
1998-01-29 00:44:16 +00:00
|
|
|
if (CcpInfo.reset_sent != -1) {
|
|
|
|
/* Send another REQ and put the packet in the bit bucket */
|
|
|
|
LogPrintf(LogCCP, "ReSendResetReq(%d)\n", CcpInfo.reset_sent);
|
1998-01-31 02:48:30 +00:00
|
|
|
FsmOutput(&CcpInfo.fsm, CODE_RESETREQ, CcpInfo.reset_sent, NULL, 0);
|
1998-01-29 00:44:16 +00:00
|
|
|
pfree(m);
|
1998-01-29 20:45:16 +00:00
|
|
|
} else if (CcpInfo.in_init)
|
|
|
|
return (*algorithm[CcpInfo.in_algorithm]->i.Read)(proto, m);
|
1998-01-29 00:44:16 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
CcpDictSetup(u_short proto, struct mbuf *m)
|
|
|
|
{
|
1998-01-31 02:48:30 +00:00
|
|
|
/* Add incoming data to the dictionary */
|
1998-01-29 20:45:16 +00:00
|
|
|
if (CcpInfo.in_init)
|
|
|
|
(*algorithm[CcpInfo.in_algorithm]->i.DictSetup)(proto, m);
|
1998-01-29 00:44:16 +00:00
|
|
|
}
|