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-04-16 00:26:21 +00:00
|
|
|
* $Id: ccp.c,v 1.30.2.33 1998/04/07 00:53:22 brian Exp $
|
1998-01-29 00:44:16 +00:00
|
|
|
*
|
|
|
|
* TODO:
|
|
|
|
* o Support other compression protocols
|
|
|
|
*/
|
1998-04-07 00:54:26 +00:00
|
|
|
#include <sys/types.h>
|
1998-01-29 00:44:16 +00:00
|
|
|
#include <netinet/in.h>
|
1998-03-16 22:54:35 +00:00
|
|
|
#include <netinet/in_systm.h>
|
|
|
|
#include <netinet/ip.h>
|
1998-01-29 00:44:16 +00:00
|
|
|
|
|
|
|
#include <stdio.h>
|
1998-03-17 22:29:12 +00:00
|
|
|
#include <stdlib.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 "pred.h"
|
|
|
|
#include "deflate.h"
|
1998-03-13 21:07:46 +00:00
|
|
|
#include "throughput.h"
|
|
|
|
#include "iplist.h"
|
1998-03-16 22:54:35 +00:00
|
|
|
#include "slcompress.h"
|
1998-03-13 21:07:46 +00:00
|
|
|
#include "ipcp.h"
|
1998-03-16 22:52:54 +00:00
|
|
|
#include "filter.h"
|
1998-02-10 03:23:50 +00:00
|
|
|
#include "descriptor.h"
|
|
|
|
#include "prompt.h"
|
1998-03-13 00:44:26 +00:00
|
|
|
#include "lqr.h"
|
1998-02-21 01:45:26 +00:00
|
|
|
#include "hdlc.h"
|
|
|
|
#include "link.h"
|
1998-04-03 19:21:56 +00:00
|
|
|
#include "mp.h"
|
|
|
|
#include "bundle.h"
|
1998-01-29 00:44:16 +00:00
|
|
|
|
|
|
|
static void CcpSendConfigReq(struct fsm *);
|
1998-03-20 19:47:10 +00:00
|
|
|
static void CcpSentTerminateReq(struct fsm *);
|
|
|
|
static void CcpSendTerminateAck(struct fsm *, u_char);
|
1998-03-13 21:08:05 +00:00
|
|
|
static void CcpDecodeConfig(struct fsm *, u_char *, int, int,
|
|
|
|
struct fsm_decode *);
|
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-21 01:45:26 +00:00
|
|
|
static void CcpRecvResetReq(struct fsm *);
|
|
|
|
static void CcpRecvResetAck(struct fsm *, u_char);
|
1998-01-29 00:44:16 +00:00
|
|
|
|
1998-02-06 02:24:29 +00:00
|
|
|
static struct fsm_callbacks ccp_Callbacks = {
|
1998-02-27 01:22:39 +00:00
|
|
|
CcpLayerUp,
|
|
|
|
CcpLayerDown,
|
|
|
|
CcpLayerStart,
|
|
|
|
CcpLayerFinish,
|
1998-02-06 02:24:29 +00:00
|
|
|
CcpInitRestartCounter,
|
|
|
|
CcpSendConfigReq,
|
1998-03-20 19:47:10 +00:00
|
|
|
CcpSentTerminateReq,
|
1998-02-06 02:24:29 +00:00
|
|
|
CcpSendTerminateAck,
|
1998-02-21 01:45:26 +00:00
|
|
|
CcpDecodeConfig,
|
|
|
|
CcpRecvResetReq,
|
|
|
|
CcpRecvResetAck
|
1998-02-06 02:24:29 +00:00
|
|
|
};
|
|
|
|
|
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) */
|
1998-03-18 23:16:05 +00:00
|
|
|
"MPPC", /* 18: Microsoft PPC (rfc2118) */
|
1998-01-29 00:44:16 +00:00
|
|
|
"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) */
|
1998-04-16 00:26:21 +00:00
|
|
|
/* 24: Deflate (according to pppd-2.3.*) */
|
1998-01-29 00:44:16 +00:00
|
|
|
"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
|
1998-02-21 01:45:26 +00:00
|
|
|
ccp_ReportStatus(struct cmdargs const *arg)
|
1998-01-29 00:44:16 +00:00
|
|
|
{
|
1998-04-03 19:24:07 +00:00
|
|
|
struct link *l = ChooseLink(arg);
|
|
|
|
struct ccp *ccp = &l->ccp;
|
1998-02-21 01:45:26 +00:00
|
|
|
|
1998-04-03 19:26:02 +00:00
|
|
|
prompt_Printf(arg->prompt, "%s: %s [%s]\n", l->name, ccp->fsm.name,
|
1998-03-24 18:47:32 +00:00
|
|
|
State2Nam(ccp->fsm.state));
|
1998-04-03 19:26:02 +00:00
|
|
|
prompt_Printf(arg->prompt, " My protocol = %s, His protocol = %s\n",
|
1998-02-21 01:45:26 +00:00
|
|
|
protoname(ccp->my_proto), protoname(ccp->his_proto));
|
1998-04-03 19:26:02 +00:00
|
|
|
prompt_Printf(arg->prompt, " Output: %ld --> %ld, Input: %ld --> %ld\n",
|
1998-02-21 01:45:26 +00:00
|
|
|
ccp->uncompout, ccp->compout,
|
|
|
|
ccp->compin, ccp->uncompin);
|
1998-04-03 19:24:07 +00:00
|
|
|
|
1998-04-03 19:26:02 +00:00
|
|
|
prompt_Printf(arg->prompt, "\n Defaults: ");
|
1998-04-16 00:26:21 +00:00
|
|
|
prompt_Printf(arg->prompt, "FSM retry = %us\n", ccp->cfg.fsmretry);
|
|
|
|
prompt_Printf(arg->prompt, " deflate windows: ");
|
1998-04-03 19:26:02 +00:00
|
|
|
prompt_Printf(arg->prompt, "incoming = %d, ", ccp->cfg.deflate.in.winsize);
|
|
|
|
prompt_Printf(arg->prompt, "outgoing = %d\n", ccp->cfg.deflate.out.winsize);
|
1998-04-16 00:26:21 +00:00
|
|
|
prompt_Printf(arg->prompt, " DEFLATE: %s\n",
|
|
|
|
command_ShowNegval(ccp->cfg.neg[CCP_NEG_DEFLATE]));
|
|
|
|
prompt_Printf(arg->prompt, " PREDICTOR1: %s\n",
|
|
|
|
command_ShowNegval(ccp->cfg.neg[CCP_NEG_PRED1]));
|
|
|
|
prompt_Printf(arg->prompt, " DEFLATE24: %s\n",
|
|
|
|
command_ShowNegval(ccp->cfg.neg[CCP_NEG_DEFLATE24]));
|
1998-01-29 00:44:16 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1998-02-27 01:22:39 +00:00
|
|
|
ccp_Init(struct ccp *ccp, struct bundle *bundle, struct link *l,
|
|
|
|
const struct fsm_parent *parent)
|
1998-01-29 00:44:16 +00:00
|
|
|
{
|
1998-01-31 02:48:30 +00:00
|
|
|
/* Initialise ourselves */
|
1998-04-03 19:21:56 +00:00
|
|
|
static const char *timer_names[] =
|
|
|
|
{"CCP restart", "CCP openmode", "CCP stopped"};
|
|
|
|
|
|
|
|
fsm_Init(&ccp->fsm, "CCP", PROTO_CCP, 1, CCP_MAXCODE, 10, LogCCP,
|
|
|
|
bundle, l, parent, &ccp_Callbacks, timer_names);
|
1998-04-03 19:24:07 +00:00
|
|
|
|
1998-03-17 22:29:12 +00:00
|
|
|
ccp->cfg.deflate.in.winsize = 0;
|
|
|
|
ccp->cfg.deflate.out.winsize = 15;
|
1998-04-03 19:24:07 +00:00
|
|
|
ccp->cfg.fsmretry = DEF_FSMRETRY;
|
1998-04-16 00:26:21 +00:00
|
|
|
ccp->cfg.neg[CCP_NEG_DEFLATE] = NEG_ENABLED|NEG_ACCEPTED;
|
|
|
|
ccp->cfg.neg[CCP_NEG_PRED1] = NEG_ENABLED|NEG_ACCEPTED;
|
|
|
|
ccp->cfg.neg[CCP_NEG_DEFLATE24] = 0;
|
1998-04-03 19:24:07 +00:00
|
|
|
|
1998-02-21 01:45:26 +00:00
|
|
|
ccp_Setup(ccp);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ccp_Setup(struct ccp *ccp)
|
|
|
|
{
|
|
|
|
/* Set ourselves up for a startup */
|
|
|
|
ccp->fsm.open_mode = 0;
|
1998-02-27 21:46:26 +00:00
|
|
|
ccp->fsm.maxconfig = 10;
|
1998-02-21 01:45:26 +00:00
|
|
|
ccp->his_proto = ccp->my_proto = -1;
|
|
|
|
ccp->reset_sent = ccp->last_reset = -1;
|
1998-03-17 22:29:12 +00:00
|
|
|
ccp->in.algorithm = ccp->out.algorithm = -1;
|
|
|
|
ccp->in.state = ccp->out.state = NULL;
|
|
|
|
ccp->in.opt.id = -1;
|
|
|
|
ccp->out.opt = NULL;
|
1998-02-21 01:45:26 +00:00
|
|
|
ccp->his_reject = ccp->my_reject = 0;
|
|
|
|
ccp->uncompout = ccp->compout = 0;
|
|
|
|
ccp->uncompin = ccp->compin = 0;
|
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-04-03 19:24:07 +00:00
|
|
|
struct ccp *ccp = fsm2ccp(fp);
|
|
|
|
|
|
|
|
fp->FsmTimer.load = ccp->cfg.fsmretry * SECTICKS;
|
1998-01-29 00:44:16 +00:00
|
|
|
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-03-17 22:29:12 +00:00
|
|
|
struct ccp_opt **o;
|
1998-03-13 21:08:05 +00:00
|
|
|
u_char *cp, buff[100];
|
1998-03-17 22:29:12 +00:00
|
|
|
int f, alloc;
|
1998-01-29 00:44:16 +00:00
|
|
|
|
1998-03-13 21:08:05 +00:00
|
|
|
cp = buff;
|
1998-03-17 22:29:12 +00:00
|
|
|
o = &ccp->out.opt;
|
|
|
|
alloc = ccp->his_reject == 0 && ccp->out.opt == NULL;
|
1998-02-06 02:24:29 +00:00
|
|
|
ccp->my_proto = -1;
|
1998-03-17 22:29:12 +00:00
|
|
|
ccp->out.algorithm = -1;
|
1998-01-29 00:44:16 +00:00
|
|
|
for (f = 0; f < NALGORITHMS; f++)
|
1998-04-16 00:26:21 +00:00
|
|
|
if (IsEnabled(ccp->cfg.neg[algorithm[f]->Neg]) &&
|
|
|
|
!REJECTED(ccp, algorithm[f]->id)) {
|
1998-03-17 22:29:12 +00:00
|
|
|
if (alloc) {
|
|
|
|
*o = (struct ccp_opt *)malloc(sizeof(struct ccp_opt));
|
|
|
|
(*o)->val.id = algorithm[f]->id;
|
|
|
|
(*o)->val.len = 2;
|
|
|
|
(*o)->next = NULL;
|
|
|
|
(*o)->algorithm = f;
|
|
|
|
(*algorithm[f]->o.OptInit)(&(*o)->val, &ccp->cfg);
|
|
|
|
} else {
|
|
|
|
for (o = &ccp->out.opt; *o != NULL; o = &(*o)->next)
|
|
|
|
if ((*o)->val.id == algorithm[f]->id && (*o)->algorithm == f)
|
|
|
|
break;
|
|
|
|
if (*o == NULL) {
|
|
|
|
LogPrintf(LogERROR, "CCP REQ buffer lost !\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
1998-01-29 00:44:16 +00:00
|
|
|
|
1998-03-17 22:29:12 +00:00
|
|
|
if (cp + (*o)->val.len > buff + sizeof buff) {
|
1998-03-13 21:08:05 +00:00
|
|
|
LogPrintf(LogERROR, "CCP REQ buffer overrun !\n");
|
|
|
|
break;
|
|
|
|
}
|
1998-03-20 19:47:10 +00:00
|
|
|
memcpy(cp, &(*o)->val, (*o)->val.len);
|
|
|
|
cp += (*o)->val.len;
|
1998-03-17 22:29:12 +00:00
|
|
|
|
|
|
|
ccp->my_proto = (*o)->val.id;
|
|
|
|
ccp->out.algorithm = f;
|
|
|
|
|
|
|
|
if (alloc)
|
|
|
|
o = &(*o)->next;
|
1998-01-29 00:44:16 +00:00
|
|
|
}
|
1998-03-20 19:47:10 +00:00
|
|
|
|
|
|
|
FsmOutput(fp, CODE_CONFIGREQ, fp->reqid, buff, cp - buff);
|
1998-01-29 00:44:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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-03-20 19:47:10 +00:00
|
|
|
|
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
|
1998-03-20 19:47:10 +00:00
|
|
|
CcpSentTerminateReq(struct fsm *fp)
|
1998-01-29 00:44:16 +00:00
|
|
|
{
|
1998-01-31 02:48:30 +00:00
|
|
|
/* Term REQ just sent by FSM */
|
1998-01-29 00:44:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
1998-03-20 19:47:10 +00:00
|
|
|
CcpSendTerminateAck(struct fsm *fp, u_char id)
|
1998-01-29 00:44:16 +00:00
|
|
|
{
|
1998-01-31 02:48:30 +00:00
|
|
|
/* Send Term ACK please */
|
1998-03-20 19:47:10 +00:00
|
|
|
FsmOutput(fp, CODE_TERMACK, id, NULL, 0);
|
1998-01-29 00:44:16 +00:00
|
|
|
}
|
|
|
|
|
1998-02-21 01:45:26 +00:00
|
|
|
static void
|
1998-01-29 00:44:16 +00:00
|
|
|
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-03-17 22:29:12 +00:00
|
|
|
if (ccp->out.state != NULL)
|
|
|
|
(*algorithm[ccp->out.algorithm]->o.Reset)(ccp->out.state);
|
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-03-17 22:29:12 +00:00
|
|
|
if (ccp->in.state != NULL) {
|
|
|
|
(*algorithm[ccp->in.algorithm]->i.Term)(ccp->in.state);
|
|
|
|
ccp->in.state = NULL;
|
1998-01-31 02:48:30 +00:00
|
|
|
}
|
1998-03-17 22:29:12 +00:00
|
|
|
if (ccp->out.state != NULL) {
|
|
|
|
(*algorithm[ccp->out.algorithm]->o.Term)(ccp->out.state);
|
|
|
|
ccp->out.state = NULL;
|
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-03-17 22:29:12 +00:00
|
|
|
if (ccp->in.state == NULL && ccp->in.algorithm >= 0 &&
|
|
|
|
ccp->in.algorithm < NALGORITHMS) {
|
|
|
|
ccp->in.state = (*algorithm[ccp->in.algorithm]->i.Init)(&ccp->in.opt);
|
|
|
|
if (ccp->in.state == NULL) {
|
1998-01-29 20:45:16 +00:00
|
|
|
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-03-17 22:29:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (ccp->out.state == NULL && ccp->out.algorithm >= 0 &&
|
|
|
|
ccp->out.algorithm < NALGORITHMS) {
|
|
|
|
ccp->out.state = (*algorithm[ccp->out.algorithm]->o.Init)
|
|
|
|
(&ccp->out.opt->val);
|
|
|
|
if (ccp->out.state == NULL) {
|
1998-01-29 20:45:16 +00:00
|
|
|
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-03-17 22:29:12 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
1998-03-13 21:08:05 +00:00
|
|
|
CcpDecodeConfig(struct fsm *fp, u_char *cp, int plen, int mode_type,
|
|
|
|
struct fsm_decode *dec)
|
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;
|
1998-03-17 22:29:12 +00:00
|
|
|
const char *end;
|
1998-01-29 00:44:16 +00:00
|
|
|
|
|
|
|
while (plen >= sizeof(struct fsmconfig)) {
|
|
|
|
type = *cp;
|
|
|
|
length = cp[1];
|
1998-03-17 22:29:12 +00:00
|
|
|
|
|
|
|
if (length > sizeof(struct lcp_opt)) {
|
|
|
|
length = sizeof(struct lcp_opt);
|
|
|
|
LogPrintf(LogCCP, "Warning: Truncating length to %d\n", length);
|
|
|
|
}
|
1998-01-29 00:44:16 +00:00
|
|
|
|
|
|
|
for (f = NALGORITHMS-1; f > -1; f--)
|
|
|
|
if (algorithm[f]->id == type)
|
|
|
|
break;
|
|
|
|
|
1998-03-17 22:29:12 +00:00
|
|
|
end = f == -1 ? "" : (*algorithm[f]->Disp)((struct lcp_opt *)cp);
|
|
|
|
if (end == NULL)
|
|
|
|
end = "";
|
|
|
|
|
|
|
|
if (type < NCFTYPES)
|
|
|
|
LogPrintf(LogCCP, " %s[%d] %s\n", cftypes[type], length, end);
|
|
|
|
else
|
|
|
|
LogPrintf(LogCCP, " ???[%d] %s\n", length, end);
|
|
|
|
|
1998-01-29 00:44:16 +00:00
|
|
|
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-03-13 21:08:05 +00:00
|
|
|
memcpy(dec->rejend, cp, length);
|
|
|
|
dec->rejend += length;
|
1998-01-29 00:44:16 +00:00
|
|
|
}
|
|
|
|
} else {
|
1998-03-17 22:29:12 +00:00
|
|
|
struct ccp_opt *o;
|
1998-01-29 00:44:16 +00:00
|
|
|
|
|
|
|
switch (mode_type) {
|
|
|
|
case MODE_REQ:
|
1998-04-16 00:26:21 +00:00
|
|
|
if (IsAccepted(ccp->cfg.neg[algorithm[f]->Neg]) &&
|
|
|
|
ccp->in.algorithm == -1) {
|
1998-03-17 22:29:12 +00:00
|
|
|
memcpy(&ccp->in.opt, cp, length);
|
|
|
|
switch ((*algorithm[f]->i.Set)(&ccp->in.opt, &ccp->cfg)) {
|
1998-01-29 00:44:16 +00:00
|
|
|
case MODE_REJ:
|
1998-03-17 22:29:12 +00:00
|
|
|
memcpy(dec->rejend, &ccp->in.opt, ccp->in.opt.len);
|
|
|
|
dec->rejend += ccp->in.opt.len;
|
1998-01-29 00:44:16 +00:00
|
|
|
break;
|
|
|
|
case MODE_NAK:
|
1998-03-17 22:29:12 +00:00
|
|
|
memcpy(dec->nakend, &ccp->in.opt, ccp->in.opt.len);
|
|
|
|
dec->nakend += ccp->in.opt.len;
|
1998-01-29 00:44:16 +00:00
|
|
|
break;
|
|
|
|
case MODE_ACK:
|
1998-03-13 21:08:05 +00:00
|
|
|
memcpy(dec->ackend, cp, length);
|
|
|
|
dec->ackend += length;
|
1998-02-06 02:24:29 +00:00
|
|
|
ccp->his_proto = type;
|
1998-03-17 22:29:12 +00:00
|
|
|
ccp->in.algorithm = f; /* This one'll do :-) */
|
1998-01-29 00:44:16 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else {
|
1998-03-13 21:08:05 +00:00
|
|
|
memcpy(dec->rejend, cp, length);
|
|
|
|
dec->rejend += length;
|
1998-01-29 00:44:16 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case MODE_NAK:
|
1998-03-17 22:29:12 +00:00
|
|
|
for (o = ccp->out.opt; o != NULL; o = o->next)
|
|
|
|
if (o->val.id == cp[0])
|
|
|
|
break;
|
|
|
|
if (o == NULL)
|
|
|
|
LogPrintf(LogCCP, "Warning: Ignoring peer NAK of unsent option\n");
|
1998-01-29 00:44:16 +00:00
|
|
|
else {
|
1998-03-17 22:29:12 +00:00
|
|
|
memcpy(&o->val, cp, length);
|
|
|
|
if ((*algorithm[f]->o.Set)(&o->val) == MODE_ACK)
|
|
|
|
ccp->my_proto = algorithm[f]->id;
|
|
|
|
else {
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-03-17 22:29:12 +00:00
|
|
|
plen -= cp[1];
|
|
|
|
cp += cp[1];
|
1998-01-29 00:44:16 +00:00
|
|
|
}
|
|
|
|
|
1998-04-16 00:26:21 +00:00
|
|
|
if (mode_type != MODE_NOP)
|
|
|
|
if (dec->rejend != dec->rej) {
|
|
|
|
/* rejects are preferred */
|
|
|
|
dec->ackend = dec->ack;
|
|
|
|
dec->nakend = dec->nak;
|
|
|
|
if (ccp->in.state == NULL) {
|
|
|
|
ccp->his_proto = -1;
|
|
|
|
ccp->in.algorithm = -1;
|
|
|
|
}
|
|
|
|
} else if (dec->nakend != dec->nak) {
|
|
|
|
/* then NAKs */
|
|
|
|
dec->ackend = dec->ack;
|
|
|
|
if (ccp->in.state == NULL) {
|
|
|
|
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-23 00:38:44 +00:00
|
|
|
CcpInput(struct ccp *ccp, 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-02-23 00:38:44 +00:00
|
|
|
FsmInput(&ccp->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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-02-21 01:45:26 +00:00
|
|
|
static void
|
|
|
|
CcpRecvResetAck(struct fsm *fp, u_char id)
|
1998-01-29 00:44:16 +00:00
|
|
|
{
|
1998-01-31 02:48:30 +00:00
|
|
|
/* Got a reset ACK, reset incoming dictionary */
|
1998-02-23 00:38:44 +00:00
|
|
|
struct ccp *ccp = fsm2ccp(fp);
|
|
|
|
|
|
|
|
if (ccp->reset_sent != -1) {
|
|
|
|
if (id != ccp->reset_sent) {
|
1998-01-29 00:44:16 +00:00
|
|
|
LogPrintf(LogWARN, "CCP: Incorrect ResetAck (id %d, not %d) ignored\n",
|
1998-02-23 00:38:44 +00:00
|
|
|
id, ccp->reset_sent);
|
1998-01-29 00:44:16 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
/* Whaddaya know - a correct reset ack */
|
1998-02-23 00:38:44 +00:00
|
|
|
} else if (id == ccp->last_reset)
|
1998-01-29 00:44:16 +00:00
|
|
|
LogPrintf(LogCCP, "Duplicate ResetAck (resetting again)\n");
|
|
|
|
else {
|
|
|
|
LogPrintf(LogWARN, "CCP: Unexpected ResetAck (id %d) ignored\n", id);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
1998-02-23 00:38:44 +00:00
|
|
|
ccp->last_reset = ccp->reset_sent;
|
|
|
|
ccp->reset_sent = -1;
|
1998-03-17 22:29:12 +00:00
|
|
|
if (ccp->in.state != NULL)
|
|
|
|
(*algorithm[ccp->in.algorithm]->i.Reset)(ccp->in.state);
|
1998-01-29 00:44:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
1998-04-03 19:21:56 +00:00
|
|
|
ccp_Compress(struct ccp *ccp, struct link *l, int pri, u_short proto,
|
|
|
|
struct mbuf *m)
|
1998-01-29 00:44:16 +00:00
|
|
|
{
|
1998-02-21 01:45:26 +00:00
|
|
|
/* Compress outgoing Network Layer data */
|
1998-03-17 22:29:12 +00:00
|
|
|
if ((proto & 0xfff1) == 0x21 && ccp->fsm.state == ST_OPENED &&
|
|
|
|
ccp->out.state != NULL)
|
|
|
|
return (*algorithm[ccp->out.algorithm]->o.Write)
|
|
|
|
(ccp->out.state, ccp, l, pri, proto, m);
|
1998-01-29 00:44:16 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct mbuf *
|
1998-02-21 01:45:26 +00:00
|
|
|
ccp_Decompress(struct ccp *ccp, u_short *proto, struct mbuf *bp)
|
1998-01-29 00:44:16 +00:00
|
|
|
{
|
1998-02-18 19:36:13 +00:00
|
|
|
/*
|
|
|
|
* If proto isn't PROTO_COMPD, we still want to pass it to the
|
|
|
|
* decompression routines so that the dictionary's updated
|
|
|
|
*/
|
1998-02-21 01:45:26 +00:00
|
|
|
if (ccp->fsm.state == ST_OPENED)
|
1998-02-18 19:36:13 +00:00
|
|
|
if (*proto == PROTO_COMPD) {
|
|
|
|
/* Decompress incoming data */
|
1998-03-20 19:47:10 +00:00
|
|
|
if (ccp->reset_sent != -1)
|
1998-02-18 19:36:13 +00:00
|
|
|
/* Send another REQ and put the packet in the bit bucket */
|
1998-02-21 01:45:26 +00:00
|
|
|
FsmOutput(&ccp->fsm, CODE_RESETREQ, ccp->reset_sent, NULL, 0);
|
1998-03-20 19:47:10 +00:00
|
|
|
else if (ccp->in.state != NULL)
|
1998-03-17 22:29:12 +00:00
|
|
|
return (*algorithm[ccp->in.algorithm]->i.Read)
|
|
|
|
(ccp->in.state, ccp, proto, bp);
|
1998-02-18 19:36:13 +00:00
|
|
|
pfree(bp);
|
|
|
|
bp = NULL;
|
1998-03-17 22:29:12 +00:00
|
|
|
} else if ((*proto & 0xfff1) == 0x21 && ccp->in.state != NULL)
|
1998-02-18 19:36:13 +00:00
|
|
|
/* Add incoming Network Layer traffic to our dictionary */
|
1998-03-17 22:29:12 +00:00
|
|
|
(*algorithm[ccp->in.algorithm]->i.DictSetup)
|
|
|
|
(ccp->in.state, ccp, *proto, bp);
|
1998-02-18 19:36:13 +00:00
|
|
|
|
|
|
|
return bp;
|
1998-01-29 00:44:16 +00:00
|
|
|
}
|