1995-01-31 06:29:58 +00:00
|
|
|
/*
|
|
|
|
* PPP Link Control Protocol (LCP) Module
|
|
|
|
*
|
|
|
|
* Written by Toshiharu OHNO (tony-o@iij.ad.jp)
|
|
|
|
*
|
|
|
|
* Copyright (C) 1993, 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.
|
1995-05-30 03:57:47 +00:00
|
|
|
*
|
1997-05-11 00:16:00 +00:00
|
|
|
* $Id: lcp.c,v 1.15 1997/05/10 01:22:13 brian Exp $
|
1995-05-30 03:57:47 +00:00
|
|
|
*
|
1995-01-31 06:29:58 +00:00
|
|
|
* TODO:
|
|
|
|
* o Validate magic number received from peer.
|
|
|
|
* o Limit data field length by MRU
|
|
|
|
*/
|
|
|
|
#include <sys/time.h>
|
|
|
|
#include "fsm.h"
|
|
|
|
#include "lcp.h"
|
|
|
|
#include "ipcp.h"
|
|
|
|
#include "lcpproto.h"
|
|
|
|
#include "os.h"
|
|
|
|
#include "hdlc.h"
|
1996-01-11 17:48:59 +00:00
|
|
|
#include "ccp.h"
|
1995-01-31 06:29:58 +00:00
|
|
|
#include "lqr.h"
|
|
|
|
#include "phase.h"
|
|
|
|
#include "vars.h"
|
1995-02-26 12:18:08 +00:00
|
|
|
#include "auth.h"
|
1996-01-11 17:48:59 +00:00
|
|
|
#include <arpa/inet.h>
|
1995-01-31 06:29:58 +00:00
|
|
|
|
|
|
|
extern void IpcpUp();
|
|
|
|
extern void IpcpOpen();
|
1995-02-26 12:18:08 +00:00
|
|
|
extern void StartPapChallenge();
|
|
|
|
extern void StartChapChallenge();
|
1995-01-31 06:29:58 +00:00
|
|
|
extern void SetLinkParams(struct lcpstate *);
|
|
|
|
extern void Prompt();
|
|
|
|
extern void StopIdleTimer();
|
|
|
|
extern void OsLinkdown();
|
|
|
|
extern void Cleanup();
|
1995-03-11 15:18:55 +00:00
|
|
|
extern struct pppTimer IpcpReportTimer;
|
1997-05-11 00:16:00 +00:00
|
|
|
extern int randinit;
|
1995-01-31 06:29:58 +00:00
|
|
|
|
|
|
|
struct lcpstate LcpInfo;
|
|
|
|
|
1995-02-26 12:18:08 +00:00
|
|
|
static void LcpSendConfigReq __P((struct fsm *));
|
|
|
|
static void LcpSendTerminateReq __P((struct fsm *fp));
|
|
|
|
static void LcpSendTerminateAck __P((struct fsm *fp));
|
|
|
|
static void LcpDecodeConfig __P((u_char *cp, int flen,int mode));
|
|
|
|
static void LcpInitRestartCounter __P((struct fsm *));
|
|
|
|
static void LcpLayerUp __P((struct fsm *));
|
|
|
|
static void LcpLayerDown __P((struct fsm *));
|
|
|
|
static void LcpLayerStart __P((struct fsm *));
|
|
|
|
static void LcpLayerFinish __P((struct fsm *));
|
1995-01-31 06:29:58 +00:00
|
|
|
|
|
|
|
extern int ModemSpeed();
|
|
|
|
|
|
|
|
#define REJECTED(p, x) (p->his_reject & (1<<x))
|
|
|
|
|
|
|
|
static char *cftypes[] = {
|
|
|
|
"???", "MRU", "ACCMAP", "AUTHPROTO", "QUALPROTO", "MAGICNUM",
|
|
|
|
"RESERVED", "PROTOCOMP", "ACFCOMP", "FCSALT", "SDP",
|
|
|
|
};
|
|
|
|
|
|
|
|
struct fsm LcpFsm = {
|
|
|
|
"LCP", /* Name of protocol */
|
|
|
|
PROTO_LCP, /* Protocol Number */
|
|
|
|
LCP_MAXCODE,
|
|
|
|
OPEN_ACTIVE,
|
|
|
|
ST_INITIAL, /* State of machine */
|
|
|
|
0, 0, 0,
|
|
|
|
|
|
|
|
0,
|
|
|
|
{ 0, 0, 0, NULL, NULL, NULL },
|
|
|
|
|
|
|
|
LcpLayerUp,
|
|
|
|
LcpLayerDown,
|
|
|
|
LcpLayerStart,
|
|
|
|
LcpLayerFinish,
|
|
|
|
LcpInitRestartCounter,
|
|
|
|
LcpSendConfigReq,
|
|
|
|
LcpSendTerminateReq,
|
|
|
|
LcpSendTerminateAck,
|
|
|
|
LcpDecodeConfig,
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct pppTimer LcpReportTimer;
|
|
|
|
|
|
|
|
char *PhaseNames[] = {
|
|
|
|
"Dead", "Establish", "Authenticate", "Network", "Terminate"
|
|
|
|
};
|
|
|
|
|
|
|
|
void
|
|
|
|
NewPhase(new)
|
|
|
|
int new;
|
|
|
|
{
|
|
|
|
struct lcpstate *lcp = &LcpInfo;
|
|
|
|
|
|
|
|
phase = new;
|
1996-05-11 20:48:42 +00:00
|
|
|
LogPrintf(LOG_PHASE_BIT, "Phase: %s\n", PhaseNames[phase]);
|
1995-01-31 06:29:58 +00:00
|
|
|
switch (phase) {
|
|
|
|
case PHASE_AUTHENTICATE:
|
|
|
|
lcp->auth_ineed = lcp->want_auth;
|
|
|
|
lcp->auth_iwait = lcp->his_auth;
|
|
|
|
if (lcp->his_auth || lcp->want_auth) {
|
1996-05-11 20:48:42 +00:00
|
|
|
LogPrintf(LOG_PHASE_BIT, " his = %x, mine = %x\n", lcp->his_auth, lcp->want_auth);
|
1995-01-31 06:29:58 +00:00
|
|
|
if (lcp->his_auth == PROTO_PAP)
|
1995-02-26 12:18:08 +00:00
|
|
|
StartAuthChallenge(&AuthPapInfo);
|
1995-01-31 06:29:58 +00:00
|
|
|
if (lcp->want_auth == PROTO_CHAP)
|
1995-02-26 12:18:08 +00:00
|
|
|
StartAuthChallenge(&AuthChapInfo);
|
1995-01-31 06:29:58 +00:00
|
|
|
} else
|
|
|
|
NewPhase(PHASE_NETWORK);
|
|
|
|
break;
|
|
|
|
case PHASE_NETWORK:
|
|
|
|
IpcpUp();
|
|
|
|
IpcpOpen();
|
|
|
|
CcpUp();
|
|
|
|
CcpOpen();
|
1997-03-13 21:22:09 +00:00
|
|
|
if (mode & MODE_BACKGROUND && BGFiledes[1] != -1) {
|
|
|
|
char c = EX_NORMAL;
|
|
|
|
if (write(BGFiledes[1],&c,1) == 1)
|
|
|
|
LogPrintf(LOG_PHASE_BIT,"Parent notified of success.\n");
|
|
|
|
else
|
|
|
|
LogPrintf(LOG_PHASE_BIT,"Failed to notify parent of success.\n");
|
|
|
|
close(BGFiledes[1]);
|
|
|
|
BGFiledes[1] = -1;
|
|
|
|
}
|
1995-01-31 06:29:58 +00:00
|
|
|
break;
|
|
|
|
case PHASE_DEAD:
|
1997-05-05 23:45:15 +00:00
|
|
|
if (mode & (MODE_DIRECT|MODE_BACKGROUND))
|
1995-01-31 06:29:58 +00:00
|
|
|
Cleanup(EX_DEAD);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
LcpReportTime()
|
|
|
|
{
|
|
|
|
#ifdef VERBOSE
|
|
|
|
time_t t;
|
|
|
|
|
|
|
|
time(&t);
|
|
|
|
logprintf("%s", ctime(&t));
|
|
|
|
#endif
|
|
|
|
StopTimer(&LcpReportTimer);
|
|
|
|
LcpReportTimer.state = TIMER_STOPPED;
|
|
|
|
StartTimer(&LcpReportTimer);
|
|
|
|
HdlcErrorCheck();
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
ReportLcpStatus()
|
|
|
|
{
|
|
|
|
struct lcpstate *lcp = &LcpInfo;
|
|
|
|
struct fsm *fp = &LcpFsm;
|
|
|
|
|
|
|
|
printf("%s [%s]\n", fp->name, StateNames[fp->state]);
|
|
|
|
printf(
|
1996-01-11 17:48:59 +00:00
|
|
|
" his side: MRU %ld, ACCMAP %08lx, PROTOCOMP %d, ACFCOMP %d MAGIC %08lx\n",
|
1995-01-31 06:29:58 +00:00
|
|
|
lcp->his_mru, lcp->his_accmap, lcp->his_protocomp, lcp->his_acfcomp, lcp->his_magic);
|
|
|
|
printf(
|
1996-01-11 17:48:59 +00:00
|
|
|
" my side: MRU %ld, ACCMAP %08lx, PROTOCOMP %d, ACFCOMP %d MAGIC %08lx\n",
|
1995-01-31 06:29:58 +00:00
|
|
|
lcp->want_mru, lcp->want_accmap, lcp->want_protocomp, lcp->want_acfcomp, lcp->want_magic);
|
1996-01-11 17:48:59 +00:00
|
|
|
printf("\nDefaults: MRU = %ld, ACCMAP = %08x\t", VarMRU, VarAccmap);
|
1995-01-31 06:29:58 +00:00
|
|
|
printf("Open Mode: %s\n", (VarOpenMode == OPEN_ACTIVE)? "active" : "passive");
|
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Generate random number which will be used as magic number.
|
|
|
|
*/
|
|
|
|
u_long
|
|
|
|
GenerateMagic()
|
|
|
|
{
|
1997-05-11 00:16:00 +00:00
|
|
|
if (!randinit) {
|
|
|
|
randinit = 1;
|
|
|
|
if (srandomdev() < 0)
|
|
|
|
srandom((unsigned long)(time(NULL) ^ getpid()));
|
|
|
|
}
|
|
|
|
|
|
|
|
return (random());
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
LcpInit()
|
|
|
|
{
|
|
|
|
struct lcpstate *lcp = &LcpInfo;
|
|
|
|
|
|
|
|
FsmInit(&LcpFsm);
|
|
|
|
HdlcInit();
|
|
|
|
|
|
|
|
bzero(lcp, sizeof(struct lcpstate));
|
|
|
|
lcp->want_mru = VarMRU;
|
|
|
|
lcp->his_mru = DEF_MRU;
|
|
|
|
lcp->his_accmap = 0xffffffff;
|
|
|
|
lcp->want_accmap = VarAccmap;
|
|
|
|
lcp->want_magic = GenerateMagic();
|
|
|
|
lcp->want_auth = lcp->his_auth = 0;
|
|
|
|
if (Enabled(ConfChap))
|
|
|
|
lcp->want_auth = PROTO_CHAP;
|
|
|
|
else if (Enabled(ConfPap))
|
|
|
|
lcp->want_auth = PROTO_PAP;
|
|
|
|
if (Enabled(ConfLqr)) lcp->want_lqrperiod = VarLqrTimeout * 100;
|
|
|
|
if (Enabled(ConfAcfcomp)) lcp->want_acfcomp = 1;
|
|
|
|
if (Enabled(ConfProtocomp)) lcp->want_protocomp = 1;
|
|
|
|
LcpFsm.maxconfig = 10;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
LcpInitRestartCounter(fp)
|
|
|
|
struct fsm *fp;
|
|
|
|
{
|
1995-02-26 12:18:08 +00:00
|
|
|
fp->FsmTimer.load = VarRetryTimeout * SECTICKS;
|
1995-01-31 06:29:58 +00:00
|
|
|
fp->restart = 5;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
PutConfValue(cpp, types, type, len, val)
|
|
|
|
u_char **cpp;
|
|
|
|
char **types;
|
|
|
|
u_char type;
|
|
|
|
int len;
|
|
|
|
u_long val;
|
|
|
|
{
|
|
|
|
u_char *cp;
|
1996-01-11 17:48:59 +00:00
|
|
|
struct in_addr ina;
|
1995-01-31 06:29:58 +00:00
|
|
|
|
|
|
|
cp = *cpp;
|
|
|
|
*cp++ = type; *cp++ = len;
|
|
|
|
if (len == 6) {
|
|
|
|
if (type == TY_IPADDR) {
|
1996-01-11 17:48:59 +00:00
|
|
|
ina.s_addr = htonl(val);
|
1996-05-11 20:48:42 +00:00
|
|
|
LogPrintf(LOG_LCP_BIT, " %s [%d] %s\n",
|
1996-01-11 17:48:59 +00:00
|
|
|
types[type], len, inet_ntoa(ina));
|
1995-01-31 06:29:58 +00:00
|
|
|
} else {
|
1996-05-11 20:48:42 +00:00
|
|
|
LogPrintf(LOG_LCP_BIT, " %s [%d] %08x\n", types[type], len, val);
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
*cp++ = (val >> 24) & 0377;
|
|
|
|
*cp++ = (val >> 16) & 0377;
|
|
|
|
} else
|
1996-05-11 20:48:42 +00:00
|
|
|
LogPrintf(LOG_LCP_BIT, " %s [%d] %d\n", types[type], len, val);
|
1995-01-31 06:29:58 +00:00
|
|
|
*cp++ = (val >> 8) & 0377;
|
|
|
|
*cp++ = val & 0377;
|
|
|
|
*cpp = cp;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
LcpSendConfigReq(fp)
|
|
|
|
struct fsm *fp;
|
|
|
|
{
|
|
|
|
u_char *cp;
|
|
|
|
struct lcpstate *lcp = &LcpInfo;
|
|
|
|
struct lqrreq *req;
|
|
|
|
|
1996-05-11 20:48:42 +00:00
|
|
|
LogPrintf(LOG_LCP_BIT, "%s: SendConfigReq\n", fp->name);
|
1995-01-31 06:29:58 +00:00
|
|
|
cp = ReqBuff;
|
1995-02-26 12:18:08 +00:00
|
|
|
if (!DEV_IS_SYNC) {
|
|
|
|
if (lcp->want_acfcomp && !REJECTED(lcp, TY_ACFCOMP)) {
|
|
|
|
*cp++ = TY_ACFCOMP; *cp++ = 2;
|
1996-05-11 20:48:42 +00:00
|
|
|
LogPrintf(LOG_LCP_BIT, " %s\n", cftypes[TY_ACFCOMP]);
|
1995-02-26 12:18:08 +00:00
|
|
|
}
|
|
|
|
if (lcp->want_protocomp && !REJECTED(lcp, TY_PROTOCOMP)) {
|
|
|
|
*cp++ = TY_PROTOCOMP; *cp++ = 2;
|
1996-05-11 20:48:42 +00:00
|
|
|
LogPrintf(LOG_LCP_BIT, " %s\n", cftypes[TY_PROTOCOMP]);
|
1995-02-26 12:18:08 +00:00
|
|
|
}
|
|
|
|
if (!REJECTED(lcp, TY_ACCMAP))
|
|
|
|
PutConfValue(&cp, cftypes, TY_ACCMAP, 6, lcp->want_accmap);
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
if (!REJECTED(lcp, TY_MRU))
|
|
|
|
PutConfValue(&cp, cftypes, TY_MRU, 4, lcp->want_mru);
|
|
|
|
if (lcp->want_magic && !REJECTED(lcp, TY_MAGICNUM))
|
|
|
|
PutConfValue(&cp, cftypes, TY_MAGICNUM, 6, lcp->want_magic);
|
|
|
|
if (lcp->want_lqrperiod && !REJECTED(lcp, TY_QUALPROTO)) {
|
|
|
|
req = (struct lqrreq *)cp;
|
|
|
|
req->type = TY_QUALPROTO; req->length = sizeof(struct lqrreq);
|
|
|
|
req->proto = htons(PROTO_LQR);
|
|
|
|
req->period = htonl(lcp->want_lqrperiod);
|
|
|
|
cp += sizeof(struct lqrreq);
|
1996-05-11 20:48:42 +00:00
|
|
|
LogPrintf(LOG_LCP_BIT, " %s (%d)\n", cftypes[TY_QUALPROTO], lcp->want_lqrperiod);
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
switch (lcp->want_auth) {
|
|
|
|
case PROTO_PAP:
|
|
|
|
PutConfValue(&cp, cftypes, TY_AUTHPROTO, 4, lcp->want_auth);
|
|
|
|
break;
|
|
|
|
case PROTO_CHAP:
|
|
|
|
PutConfValue(&cp, cftypes, TY_AUTHPROTO, 5, lcp->want_auth);
|
|
|
|
*cp++ = 5; /* Use MD5 */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
FsmOutput(fp, CODE_CONFIGREQ, fp->reqid++, ReqBuff, cp - ReqBuff);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
LcpSendProtoRej(option, count)
|
|
|
|
u_char *option;
|
|
|
|
int count;
|
|
|
|
{
|
|
|
|
struct fsm *fp = &LcpFsm;
|
|
|
|
|
1996-05-11 20:48:42 +00:00
|
|
|
LogPrintf(LOG_LCP_BIT, "%s: SendProtoRej\n", fp->name);
|
1995-01-31 06:29:58 +00:00
|
|
|
FsmOutput(fp, CODE_PROTOREJ, fp->reqid, option, count);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
LcpSendTerminateReq(fp)
|
|
|
|
struct fsm *fp;
|
|
|
|
{
|
|
|
|
/* Most thins are done in fsm layer. Nothing to to. */
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
LcpSendTerminateAck(fp)
|
|
|
|
struct fsm *fp;
|
|
|
|
{
|
1996-05-11 20:48:42 +00:00
|
|
|
LogPrintf(LOG_LCP_BIT, "%s: SendTerminateAck.\n", fp->name);
|
1995-01-31 06:29:58 +00:00
|
|
|
FsmOutput(fp, CODE_TERMACK, fp->reqid++, NULL, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
LcpLayerStart(fp)
|
|
|
|
struct fsm *fp;
|
|
|
|
{
|
1996-05-11 20:48:42 +00:00
|
|
|
LogPrintf(LOG_LCP_BIT, "%s: LayerStart\n", fp->name);
|
1995-01-31 06:29:58 +00:00
|
|
|
NewPhase(PHASE_ESTABLISH);
|
|
|
|
}
|
|
|
|
|
1995-02-26 12:18:08 +00:00
|
|
|
static void
|
|
|
|
StopAllTimers()
|
|
|
|
{
|
|
|
|
StopTimer(&LcpReportTimer);
|
1995-03-11 15:18:55 +00:00
|
|
|
StopTimer(&IpcpReportTimer);
|
1995-02-26 12:18:08 +00:00
|
|
|
StopIdleTimer();
|
|
|
|
StopTimer(&AuthPapInfo.authtimer);
|
|
|
|
StopTimer(&AuthChapInfo.authtimer);
|
1996-01-30 11:08:50 +00:00
|
|
|
StopLqrTimer();
|
1995-02-26 12:18:08 +00:00
|
|
|
}
|
|
|
|
|
1995-01-31 06:29:58 +00:00
|
|
|
static void
|
|
|
|
LcpLayerFinish(fp)
|
|
|
|
struct fsm *fp;
|
|
|
|
{
|
|
|
|
#ifdef VERBOSE
|
|
|
|
fprintf(stderr, "%s: LayerFinish\r\n", fp->name);
|
|
|
|
#endif
|
1997-05-10 01:22:19 +00:00
|
|
|
Prompt();
|
1996-05-11 20:48:42 +00:00
|
|
|
LogPrintf(LOG_LCP_BIT, "%s: LayerFinish\n", fp->name);
|
1995-01-31 06:29:58 +00:00
|
|
|
#ifdef notdef
|
|
|
|
OsCloseLink(0);
|
|
|
|
#else
|
|
|
|
OsCloseLink(1);
|
|
|
|
#endif
|
|
|
|
NewPhase(PHASE_DEAD);
|
1995-02-26 12:18:08 +00:00
|
|
|
StopAllTimers();
|
1997-05-10 01:22:19 +00:00
|
|
|
(void)OsInterfaceDown(0);
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
LcpLayerUp(fp)
|
|
|
|
struct fsm *fp;
|
|
|
|
{
|
1996-05-11 20:48:42 +00:00
|
|
|
LogPrintf(LOG_LCP_BIT, "%s: LayerUp\n", fp->name);
|
1995-01-31 06:29:58 +00:00
|
|
|
OsSetInterfaceParams(23, LcpInfo.his_mru, ModemSpeed());
|
|
|
|
SetLinkParams(&LcpInfo);
|
|
|
|
|
|
|
|
NewPhase(PHASE_AUTHENTICATE);
|
|
|
|
|
|
|
|
StartLqm();
|
|
|
|
StopTimer(&LcpReportTimer);
|
|
|
|
LcpReportTimer.state = TIMER_STOPPED;
|
|
|
|
LcpReportTimer.load = 60 * SECTICKS;
|
|
|
|
LcpReportTimer.func = LcpReportTime;
|
|
|
|
StartTimer(&LcpReportTimer);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
LcpLayerDown(fp)
|
|
|
|
struct fsm *fp;
|
|
|
|
{
|
1996-05-11 20:48:42 +00:00
|
|
|
LogPrintf(LOG_LCP_BIT, "%s: LayerDown\n", fp->name);
|
1995-02-26 12:18:08 +00:00
|
|
|
StopAllTimers();
|
1995-01-31 06:29:58 +00:00
|
|
|
OsLinkdown();
|
|
|
|
NewPhase(PHASE_TERMINATE);
|
1997-05-10 01:22:19 +00:00
|
|
|
Prompt();
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
LcpUp()
|
|
|
|
{
|
|
|
|
FsmUp(&LcpFsm);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1995-02-26 12:18:08 +00:00
|
|
|
LcpDown() /* Sudden death */
|
1995-01-31 06:29:58 +00:00
|
|
|
{
|
|
|
|
NewPhase(PHASE_DEAD);
|
1995-02-26 12:18:08 +00:00
|
|
|
StopAllTimers();
|
1995-01-31 06:29:58 +00:00
|
|
|
FsmDown(&LcpFsm);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
LcpOpen(mode)
|
|
|
|
int mode;
|
|
|
|
{
|
|
|
|
LcpFsm.open_mode = mode;
|
|
|
|
FsmOpen(&LcpFsm);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
LcpClose()
|
|
|
|
{
|
|
|
|
FsmClose(&LcpFsm);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* XXX: Should validate option length
|
|
|
|
*/
|
|
|
|
static void
|
1995-02-26 12:18:08 +00:00
|
|
|
LcpDecodeConfig(cp, plen, mode)
|
|
|
|
u_char *cp;
|
|
|
|
int plen;
|
1995-01-31 06:29:58 +00:00
|
|
|
int mode;
|
|
|
|
{
|
|
|
|
char *request;
|
1995-02-26 12:18:08 +00:00
|
|
|
int type, length, mru;
|
1995-01-31 06:29:58 +00:00
|
|
|
u_long *lp, magic, accmap;
|
|
|
|
u_short *sp, proto;
|
|
|
|
struct lqrreq *req;
|
|
|
|
|
|
|
|
ackp = AckBuff;
|
|
|
|
nakp = NakBuff;
|
|
|
|
rejp = RejBuff;
|
|
|
|
|
|
|
|
while (plen >= sizeof(struct fsmconfig)) {
|
|
|
|
type = *cp;
|
|
|
|
length = cp[1];
|
|
|
|
if (type <= TY_ACFCOMP)
|
|
|
|
request = cftypes[type];
|
|
|
|
else
|
|
|
|
request = "???";
|
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case TY_MRU:
|
|
|
|
sp = (u_short *)(cp + 2);
|
|
|
|
mru = htons(*sp);
|
1996-05-11 20:48:42 +00:00
|
|
|
LogPrintf(LOG_LCP_BIT, " %s %d\n", request, mru);
|
1995-01-31 06:29:58 +00:00
|
|
|
|
|
|
|
switch (mode) {
|
|
|
|
case MODE_REQ:
|
|
|
|
if (mru > MAX_MRU) {
|
|
|
|
*sp = htons(MAX_MRU);
|
|
|
|
bcopy(cp, nakp, 4); nakp += 4;
|
|
|
|
} else if (mru < MIN_MRU) {
|
|
|
|
*sp = htons(MIN_MRU);
|
|
|
|
bcopy(cp, nakp, 4); nakp += 4;
|
|
|
|
} else {
|
|
|
|
LcpInfo.his_mru = mru;
|
|
|
|
bcopy(cp, ackp, 4); ackp += 4;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case MODE_NAK:
|
|
|
|
if (mru >= MIN_MRU || mru <= MAX_MRU)
|
|
|
|
LcpInfo.want_mru = mru;
|
|
|
|
break;
|
|
|
|
case MODE_REJ:
|
|
|
|
LcpInfo.his_reject |= (1 << type);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case TY_ACCMAP:
|
|
|
|
lp = (u_long *)(cp + 2);
|
|
|
|
accmap = htonl(*lp);
|
1996-05-11 20:48:42 +00:00
|
|
|
LogPrintf(LOG_LCP_BIT, " %s %08x\n", request, accmap);
|
1995-01-31 06:29:58 +00:00
|
|
|
|
|
|
|
switch (mode) {
|
|
|
|
case MODE_REQ:
|
|
|
|
LcpInfo.his_accmap = accmap;
|
|
|
|
bcopy(cp, ackp, 6); ackp += 6;
|
|
|
|
break;
|
|
|
|
case MODE_NAK:
|
|
|
|
LcpInfo.want_accmap = accmap;
|
|
|
|
break;
|
|
|
|
case MODE_REJ:
|
|
|
|
LcpInfo.his_reject |= (1 << type);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case TY_AUTHPROTO:
|
|
|
|
sp = (u_short *)(cp + 2);
|
|
|
|
proto = ntohs(*sp);
|
1996-05-11 20:48:42 +00:00
|
|
|
LogPrintf(LOG_LCP_BIT, " %s proto = %04x\n", request, proto);
|
1995-01-31 06:29:58 +00:00
|
|
|
|
|
|
|
switch (mode) {
|
|
|
|
case MODE_REQ:
|
|
|
|
switch (proto) {
|
|
|
|
case PROTO_PAP:
|
|
|
|
if (length != 4) {
|
1996-05-11 20:48:42 +00:00
|
|
|
LogPrintf(LOG_LCP_BIT, " %s bad length (%d)\n", request, length);
|
1995-01-31 06:29:58 +00:00
|
|
|
goto reqreject;
|
|
|
|
}
|
|
|
|
if (Acceptable(ConfPap)) {
|
|
|
|
LcpInfo.his_auth = proto;
|
|
|
|
bcopy(cp, ackp, length); ackp += length;
|
|
|
|
} else if (Acceptable(ConfChap)) {
|
|
|
|
*nakp++ = *cp; *nakp++ = 5;
|
1995-02-26 12:18:08 +00:00
|
|
|
*nakp++ = (unsigned char)(PROTO_CHAP >> 8);
|
1995-01-31 06:29:58 +00:00
|
|
|
*nakp++ = (unsigned char)PROTO_CHAP;
|
|
|
|
*nakp++ = 5;
|
|
|
|
} else
|
|
|
|
goto reqreject;
|
|
|
|
break;
|
|
|
|
case PROTO_CHAP:
|
|
|
|
if (length < 5) {
|
1996-05-11 20:48:42 +00:00
|
|
|
LogPrintf(LOG_LCP_BIT, " %s bad length (%d)\n", request, length);
|
1995-01-31 06:29:58 +00:00
|
|
|
goto reqreject;
|
|
|
|
}
|
|
|
|
if (Acceptable(ConfChap) && cp[4] == 5) {
|
|
|
|
LcpInfo.his_auth = proto;
|
|
|
|
bcopy(cp, ackp, length); ackp += length;
|
|
|
|
} else if (Acceptable(ConfPap)) {
|
|
|
|
*nakp++ = *cp; *nakp++ = 4;
|
1995-02-26 12:18:08 +00:00
|
|
|
*nakp++ = (unsigned char)(PROTO_PAP >> 8);
|
1995-01-31 06:29:58 +00:00
|
|
|
*nakp++ = (unsigned char)PROTO_PAP;
|
|
|
|
} else
|
|
|
|
goto reqreject;
|
|
|
|
break;
|
|
|
|
default:
|
1996-05-11 20:48:42 +00:00
|
|
|
LogPrintf(LOG_LCP_BIT, " %s not implemented, NAK.\n", request);
|
1995-07-08 05:09:57 +00:00
|
|
|
bcopy(cp, nakp, length);
|
|
|
|
nakp += length;
|
|
|
|
break;
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case MODE_NAK:
|
|
|
|
break;
|
|
|
|
case MODE_REJ:
|
|
|
|
LcpInfo.his_reject |= (1 << type);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case TY_QUALPROTO:
|
|
|
|
req = (struct lqrreq *)cp;
|
1996-05-11 20:48:42 +00:00
|
|
|
LogPrintf(LOG_LCP_BIT, " %s proto: %x, interval: %dms\n",
|
1995-01-31 06:29:58 +00:00
|
|
|
request, ntohs(req->proto), ntohl(req->period)*10);
|
|
|
|
switch (mode) {
|
|
|
|
case MODE_REQ:
|
|
|
|
if (ntohs(req->proto) != PROTO_LQR || !Acceptable(ConfLqr))
|
|
|
|
goto reqreject;
|
|
|
|
else {
|
|
|
|
LcpInfo.his_lqrperiod = ntohl(req->period);
|
|
|
|
if (LcpInfo.his_lqrperiod < 500)
|
|
|
|
LcpInfo.his_lqrperiod = 500;
|
|
|
|
req->period = htonl(LcpInfo.his_lqrperiod);
|
|
|
|
bcopy(cp, ackp, length); ackp += length;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case MODE_NAK:
|
|
|
|
break;
|
|
|
|
case MODE_REJ:
|
|
|
|
LcpInfo.his_reject |= (1 << type);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case TY_MAGICNUM:
|
|
|
|
lp = (u_long *)(cp + 2);
|
|
|
|
magic = ntohl(*lp);
|
1996-05-11 20:48:42 +00:00
|
|
|
LogPrintf(LOG_LCP_BIT, " %s %08x\n", request, magic);
|
1995-01-31 06:29:58 +00:00
|
|
|
|
|
|
|
switch (mode) {
|
|
|
|
case MODE_REQ:
|
|
|
|
if (LcpInfo.want_magic) {
|
|
|
|
/* XXX: Shoud validate magic number */
|
|
|
|
if (magic == LcpInfo.want_magic)
|
|
|
|
logprintf("magic is same!! %x, %x, %x\n",
|
|
|
|
magic, LcpInfo.want_magic, LcpInfo.his_magic);
|
|
|
|
LcpInfo.his_magic = magic;
|
|
|
|
bcopy(cp, ackp, length); ackp += length;
|
|
|
|
} else {
|
|
|
|
LcpInfo.my_reject |= (1 << type);
|
|
|
|
goto reqreject;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case MODE_NAK:
|
1996-05-11 20:48:42 +00:00
|
|
|
LogPrintf(LOG_LCP_BIT, " %s magic %08x has NAKed\n", request, magic);
|
1995-01-31 06:29:58 +00:00
|
|
|
LcpInfo.want_magic = GenerateMagic();
|
|
|
|
break;
|
|
|
|
case MODE_REJ:
|
1996-05-11 20:48:42 +00:00
|
|
|
LogPrintf(LOG_LCP_BIT, " %s magic has REJected\n", request);
|
1995-01-31 06:29:58 +00:00
|
|
|
LcpInfo.want_magic = 0;
|
|
|
|
LcpInfo.his_reject |= (1 << type);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case TY_PROTOCOMP:
|
1996-05-11 20:48:42 +00:00
|
|
|
LogPrintf(LOG_LCP_BIT, " %s\n", request);
|
1995-01-31 06:29:58 +00:00
|
|
|
|
|
|
|
switch (mode) {
|
|
|
|
case MODE_REQ:
|
|
|
|
if (Acceptable(ConfProtocomp)) {
|
|
|
|
LcpInfo.his_protocomp = 1;
|
|
|
|
bcopy(cp, ackp, 2); ackp += 2;
|
|
|
|
} else {
|
|
|
|
#ifdef OLDMST
|
|
|
|
/*
|
|
|
|
* MorningStar before v1.3 needs NAK
|
|
|
|
*/
|
|
|
|
bcopy(cp, nakp, 2); nakp += 2;
|
|
|
|
#else
|
|
|
|
bcopy(cp, rejp, 2); rejp += 2;
|
|
|
|
LcpInfo.my_reject |= (1 << type);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case MODE_NAK:
|
|
|
|
case MODE_REJ:
|
|
|
|
LcpInfo.want_protocomp = 0;
|
|
|
|
LcpInfo.his_reject |= (1 << type);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case TY_ACFCOMP:
|
1996-05-11 20:48:42 +00:00
|
|
|
LogPrintf(LOG_LCP_BIT, " %s\n", request);
|
1995-01-31 06:29:58 +00:00
|
|
|
switch (mode) {
|
|
|
|
case MODE_REQ:
|
|
|
|
if (Acceptable(ConfAcfcomp)) {
|
|
|
|
LcpInfo.his_acfcomp = 1;
|
|
|
|
bcopy(cp, ackp, 2);
|
|
|
|
ackp += 2;
|
|
|
|
} else {
|
|
|
|
#ifdef OLDMST
|
|
|
|
/*
|
|
|
|
* MorningStar before v1.3 needs NAK
|
|
|
|
*/
|
|
|
|
bcopy(cp, nakp, 2);
|
|
|
|
nakp += 2;
|
|
|
|
#else
|
|
|
|
bcopy(cp, rejp, 2);
|
|
|
|
rejp += 2;
|
|
|
|
LcpInfo.my_reject |= (1 << type);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case MODE_NAK:
|
|
|
|
case MODE_REJ:
|
|
|
|
LcpInfo.want_acfcomp = 0;
|
|
|
|
LcpInfo.his_reject |= (1 << type);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case TY_SDP:
|
1996-05-11 20:48:42 +00:00
|
|
|
LogPrintf(LOG_LCP_BIT, " %s\n", request);
|
1995-01-31 06:29:58 +00:00
|
|
|
switch (mode) {
|
|
|
|
case MODE_REQ:
|
|
|
|
case MODE_NAK:
|
|
|
|
case MODE_REJ:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
1996-05-11 20:48:42 +00:00
|
|
|
LogPrintf(LOG_LCP_BIT, " ???[%02x]\n", type);
|
1995-02-26 12:18:08 +00:00
|
|
|
if (mode == MODE_REQ) {
|
1995-01-31 06:29:58 +00:00
|
|
|
reqreject:
|
1995-02-26 12:18:08 +00:00
|
|
|
bcopy(cp, rejp, length);
|
|
|
|
rejp += length;
|
|
|
|
LcpInfo.my_reject |= (1 << type);
|
|
|
|
}
|
1995-01-31 06:29:58 +00:00
|
|
|
break;
|
|
|
|
}
|
1996-10-12 16:20:34 +00:00
|
|
|
/* to avoid inf. loop */
|
|
|
|
if (length == 0) {
|
|
|
|
LogPrintf(LOG_LCP, "LCP size zero\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
1995-01-31 06:29:58 +00:00
|
|
|
plen -= length;
|
|
|
|
cp += length;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
LcpInput(struct mbuf *bp)
|
|
|
|
{
|
|
|
|
FsmInput(&LcpFsm, bp);
|
|
|
|
}
|