Isolate fsm callback functions

Derive {lcp,ipcp,ccp}state structures from struct fsm
where convenient.
Create bundle_Down() and remove LcpDown()
This commit is contained in:
Brian Somers 1998-02-06 02:24:29 +00:00
parent 2289f24698
commit 83d1af558c
14 changed files with 318 additions and 295 deletions

View File

@ -23,7 +23,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: bundle.c,v 1.1.2.2 1998/02/02 19:33:00 brian Exp $
* $Id: bundle.c,v 1.1.2.3 1998/02/06 02:23:28 brian Exp $
*/
#include <sys/param.h>
@ -555,3 +555,14 @@ bundle_SetRoute(struct bundle *bundle, int cmd, struct in_addr dst,
wb, cmdstr, dst.s_addr, gateway.s_addr);
close(s);
}
void
bundle_Down(struct bundle *bundle, struct link *link)
{
/* If link is NULL slam everything down, otherwise `link' is dead */
LogPrintf(LogPHASE, "Disconnected!\n");
FsmDown(&LcpInfo.fsm);
FsmDown(&IpcpInfo.fsm);
FsmDown(&CcpInfo.fsm);
}

View File

@ -23,10 +23,11 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: bundle.h,v 1.1.2.3 1998/02/04 01:03:19 brian Exp $
* $Id: bundle.h,v 1.1.2.4 1998/02/06 02:23:29 brian Exp $
*/
struct physical;
struct link;
struct bundle {
int unit; /* The tun number */
@ -55,3 +56,4 @@ extern int bundle_LinkIsUp(const struct bundle *);
extern void bundle_Linkdown(struct bundle *);
extern void bundle_SetRoute(struct bundle *, int, struct in_addr,
struct in_addr, struct in_addr, int);
extern void bundle_Down(struct bundle *, struct link *);

View File

@ -17,7 +17,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* $Id: ccp.c,v 1.30.2.4 1998/01/31 02:48:14 brian Exp $
* $Id: ccp.c,v 1.30.2.5 1998/02/02 19:32:02 brian Exp $
*
* TODO:
* o Support other compression protocols
@ -46,13 +46,25 @@
static void CcpSendConfigReq(struct fsm *);
static void CcpSendTerminateReq(struct fsm *);
static void CcpSendTerminateAck(struct fsm *);
static void CcpDecodeConfig(struct bundle *, u_char *, int, int);
static void CcpDecodeConfig(struct fsm *, u_char *, int, int);
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 *);
static struct fsm_callbacks ccp_Callbacks = {
CcpLayerUp,
CcpLayerDown,
CcpLayerStart,
CcpLayerFinish,
CcpInitRestartCounter,
CcpSendConfigReq,
CcpSendTerminateReq,
CcpSendTerminateAck,
CcpDecodeConfig
};
struct ccpstate CcpInfo = {
{
"CCP",
@ -67,15 +79,7 @@ struct ccpstate CcpInfo = {
LogCCP,
NULL, /* link */
NULL, /* bundle */
CcpLayerUp,
CcpLayerDown,
CcpLayerStart,
CcpLayerFinish,
CcpInitRestartCounter,
CcpSendConfigReq,
CcpSendTerminateReq,
CcpSendTerminateAck,
CcpDecodeConfig,
&ccp_Callbacks
},
-1, -1, -1, -1, -1, -1
};
@ -163,22 +167,23 @@ static void
CcpSendConfigReq(struct fsm *fp)
{
/* Send config REQ please */
struct ccpstate *ccp = fsm2ccp(fp);
u_char *cp;
int f;
LogPrintf(LogCCP, "CcpSendConfigReq\n");
cp = ReqBuff;
CcpInfo.my_proto = -1;
CcpInfo.out_algorithm = -1;
ccp->my_proto = -1;
ccp->out_algorithm = -1;
for (f = 0; f < NALGORITHMS; f++)
if (Enabled(algorithm[f]->Conf) && !REJECTED(&CcpInfo, algorithm[f]->id)) {
if (Enabled(algorithm[f]->Conf) && !REJECTED(ccp, algorithm[f]->id)) {
struct lcp_opt o;
(*algorithm[f]->o.Get)(&o);
cp += LcpPutConf(LogCCP, cp, &o, cftypes[o.id],
(*algorithm[f]->Disp)(&o));
CcpInfo.my_proto = o.id;
CcpInfo.out_algorithm = f;
ccp->my_proto = o.id;
ccp->out_algorithm = f;
}
FsmOutput(fp, CODE_CONFIGREQ, fp->reqid++, ReqBuff, cp - ReqBuff);
}
@ -187,9 +192,10 @@ void
CcpSendResetReq(struct fsm *fp)
{
/* We can't read our input - ask peer to reset */
struct ccpstate *ccp = fsm2ccp(fp);
LogPrintf(LogCCP, "SendResetReq(%d)\n", fp->reqid);
CcpInfo.reset_sent = fp->reqid;
CcpInfo.last_reset = -1;
ccp->reset_sent = fp->reqid;
ccp->last_reset = -1;
FsmOutput(fp, CODE_RESETREQ, fp->reqid, NULL, 0);
}
@ -211,8 +217,9 @@ void
CcpRecvResetReq(struct fsm *fp)
{
/* Got a reset REQ, reset outgoing dictionary */
if (CcpInfo.out_init)
(*algorithm[CcpInfo.out_algorithm]->o.Reset)();
struct ccpstate *ccp = fsm2ccp(fp);
if (ccp->out_init)
(*algorithm[ccp->out_algorithm]->o.Reset)();
}
static void
@ -226,14 +233,15 @@ static void
CcpLayerFinish(struct fsm *fp)
{
/* We're now down */
struct ccpstate *ccp = fsm2ccp(fp);
LogPrintf(LogCCP, "CcpLayerFinish.\n");
if (CcpInfo.in_init) {
(*algorithm[CcpInfo.in_algorithm]->i.Term)();
CcpInfo.in_init = 0;
if (ccp->in_init) {
(*algorithm[ccp->in_algorithm]->i.Term)();
ccp->in_init = 0;
}
if (CcpInfo.out_init) {
(*algorithm[CcpInfo.out_algorithm]->o.Term)();
CcpInfo.out_init = 0;
if (ccp->out_init) {
(*algorithm[ccp->out_algorithm]->o.Term)();
ccp->out_init = 0;
}
}
@ -251,30 +259,31 @@ static void
CcpLayerUp(struct fsm *fp)
{
/* We're now up */
struct ccpstate *ccp = fsm2ccp(fp);
LogPrintf(LogCCP, "CcpLayerUp(%d).\n", fp->state);
if (!CcpInfo.in_init && CcpInfo.in_algorithm >= 0 &&
CcpInfo.in_algorithm < NALGORITHMS)
if ((*algorithm[CcpInfo.in_algorithm]->i.Init)())
CcpInfo.in_init = 1;
if (!ccp->in_init && ccp->in_algorithm >= 0 &&
ccp->in_algorithm < NALGORITHMS)
if ((*algorithm[ccp->in_algorithm]->i.Init)())
ccp->in_init = 1;
else {
LogPrintf(LogERROR, "%s (in) initialisation failure\n",
protoname(CcpInfo.his_proto));
CcpInfo.his_proto = CcpInfo.my_proto = -1;
protoname(ccp->his_proto));
ccp->his_proto = ccp->my_proto = -1;
FsmClose(fp);
}
if (!CcpInfo.out_init && CcpInfo.out_algorithm >= 0 &&
CcpInfo.out_algorithm < NALGORITHMS)
if ((*algorithm[CcpInfo.out_algorithm]->o.Init)())
CcpInfo.out_init = 1;
if (!ccp->out_init && ccp->out_algorithm >= 0 &&
ccp->out_algorithm < NALGORITHMS)
if ((*algorithm[ccp->out_algorithm]->o.Init)())
ccp->out_init = 1;
else {
LogPrintf(LogERROR, "%s (out) initialisation failure\n",
protoname(CcpInfo.my_proto));
CcpInfo.his_proto = CcpInfo.my_proto = -1;
protoname(ccp->my_proto));
ccp->his_proto = ccp->my_proto = -1;
FsmClose(fp);
}
LogPrintf(LogCCP, "Out = %s[%d], In = %s[%d]\n",
protoname(CcpInfo.my_proto), CcpInfo.my_proto,
protoname(CcpInfo.his_proto), CcpInfo.his_proto);
protoname(ccp->my_proto), ccp->my_proto,
protoname(ccp->his_proto), ccp->his_proto);
}
void
@ -285,17 +294,6 @@ CcpUp()
LogPrintf(LogCCP, "CCP Up event!!\n");
}
void
CcpDown()
{
/* Physical link is gone - sudden death */
if (CcpInfo.fsm.state >= ST_CLOSED) {
FsmDown(&CcpInfo.fsm);
/* FsmDown() results in a CcpLayerDown() if we're currently open. */
CcpLayerFinish(&CcpInfo.fsm);
}
}
void
CcpOpen()
{
@ -319,9 +317,10 @@ CcpOpen()
}
static void
CcpDecodeConfig(struct bundle *bundle, u_char *cp, int plen, int mode_type)
CcpDecodeConfig(struct fsm *fp, u_char *cp, int plen, int mode_type)
{
/* Deal with incoming data */
struct ccpstate *ccp = fsm2ccp(fp);
int type, length;
int f;
@ -344,7 +343,7 @@ CcpDecodeConfig(struct bundle *bundle, u_char *cp, int plen, int mode_type)
if (f == -1) {
/* Don't understand that :-( */
if (mode_type == MODE_REQ) {
CcpInfo.my_reject |= (1 << type);
ccp->my_reject |= (1 << type);
memcpy(rejp, cp, length);
rejp += length;
}
@ -353,7 +352,7 @@ CcpDecodeConfig(struct bundle *bundle, u_char *cp, int plen, int mode_type)
switch (mode_type) {
case MODE_REQ:
if (Acceptable(algorithm[f]->Conf) && CcpInfo.in_algorithm == -1) {
if (Acceptable(algorithm[f]->Conf) && ccp->in_algorithm == -1) {
memcpy(&o, cp, length);
switch ((*algorithm[f]->i.Set)(&o)) {
case MODE_REJ:
@ -367,8 +366,8 @@ CcpDecodeConfig(struct bundle *bundle, u_char *cp, int plen, int mode_type)
case MODE_ACK:
memcpy(ackp, cp, length);
ackp += length;
CcpInfo.his_proto = type;
CcpInfo.in_algorithm = f; /* This one'll do ! */
ccp->his_proto = type;
ccp->in_algorithm = f; /* This one'll do ! */
break;
}
} else {
@ -379,15 +378,15 @@ CcpDecodeConfig(struct bundle *bundle, u_char *cp, int plen, int mode_type)
case MODE_NAK:
memcpy(&o, cp, length);
if ((*algorithm[f]->o.Set)(&o) == MODE_ACK)
CcpInfo.my_proto = algorithm[f]->id;
ccp->my_proto = algorithm[f]->id;
else {
CcpInfo.his_reject |= (1 << type);
CcpInfo.my_proto = -1;
ccp->his_reject |= (1 << type);
ccp->my_proto = -1;
}
break;
case MODE_REJ:
CcpInfo.his_reject |= (1 << type);
CcpInfo.my_proto = -1;
ccp->his_reject |= (1 << type);
ccp->my_proto = -1;
break;
}
}
@ -398,9 +397,9 @@ CcpDecodeConfig(struct bundle *bundle, u_char *cp, int plen, int mode_type)
if (rejp != RejBuff) {
ackp = AckBuff; /* let's not send both ! */
if (!CcpInfo.in_init) {
CcpInfo.his_proto = -1;
CcpInfo.in_algorithm = -1;
if (!ccp->in_init) {
ccp->his_proto = -1;
ccp->in_algorithm = -1;
}
}
}

View File

@ -15,7 +15,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* $Id: ccp.h,v 1.14.2.4 1998/01/31 02:48:15 brian Exp $
* $Id: ccp.h,v 1.14.2.5 1998/02/02 19:32:02 brian Exp $
*
* TODO:
*/
@ -59,6 +59,8 @@ struct ccpstate {
extern struct ccpstate CcpInfo;
#define fsm2ccp(fp) (fp->proto == PROTO_CCP ? (struct ccpstate *)fp : NULL)
struct ccp_algorithm {
int id;
int Conf; /* A Conf value from vars.h */
@ -93,4 +95,3 @@ extern void CcpResetInput(u_char);
extern int CcpOutput(struct link *, int, u_short, struct mbuf *);
extern struct mbuf *CompdInput(u_short *, struct mbuf *);
extern void CcpDictSetup(u_short, struct mbuf *);
extern void CcpDown(void);

View File

@ -17,7 +17,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* $Id: command.c,v 1.131.2.8 1998/02/06 02:22:10 brian Exp $
* $Id: command.c,v 1.131.2.9 1998/02/06 02:23:33 brian Exp $
*
*/
#include <sys/param.h>
@ -885,7 +885,7 @@ CloseCommand(struct cmdargs const *arg)
static int
DownCommand(struct cmdargs const *arg)
{
LcpDown();
bundle_Down(arg->bundle, &arg->bundle->physical->link);
return 0;
}

View File

@ -17,7 +17,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* $Id: fsm.c,v 1.27.2.5 1998/02/02 19:33:35 brian Exp $
* $Id: fsm.c,v 1.27.2.6 1998/02/06 02:22:12 brian Exp $
*
* TODO:
* o Refer loglevel for log output
@ -48,6 +48,7 @@
#include "async.h"
#include "link.h"
#include "physical.h"
#include "bundle.h"
u_char AckBuff[200];
u_char NakBuff[200];
@ -80,7 +81,7 @@ StoppedTimeout(void *v)
if (link_IsActive(fp->link))
FsmDown(fp);
else
LcpDown();
bundle_Down(fp->bundle, fp->link);
}
void
@ -151,7 +152,7 @@ FsmOpen(struct fsm * fp)
{
switch (fp->state) {
case ST_INITIAL:
(fp->LayerStart) (fp);
(*fp->fn->LayerStart)(fp);
NewState(fp, ST_STARTING);
break;
case ST_STARTING:
@ -212,7 +213,7 @@ FsmDown(struct fsm *fp)
NewState(fp, ST_INITIAL);
break;
case ST_STOPPED:
(fp->LayerStart) (fp);
(*fp->fn->LayerStart)(fp);
/* Fall into.. */
case ST_STOPPING:
case ST_REQSENT:
@ -221,10 +222,15 @@ FsmDown(struct fsm *fp)
NewState(fp, ST_STARTING);
break;
case ST_OPENED:
(fp->LayerDown) (fp);
(*fp->fn->LayerDown)(fp);
NewState(fp, ST_STARTING);
break;
}
if (fp->state != ST_INITIAL) {
/* XXX: Is this violating the rfc ? */
(*fp->fn->LayerFinish)(fp);
NewState(fp, ST_INITIAL);
}
}
void
@ -241,7 +247,7 @@ FsmClose(struct fsm *fp)
NewState(fp, ST_CLOSING);
break;
case ST_OPENED:
(fp->LayerDown) (fp);
(*fp->fn->LayerDown)(fp);
/* Fall down */
case ST_REQSENT:
case ST_ACKRCVD:
@ -260,7 +266,7 @@ static void
FsmSendConfigReq(struct fsm * fp)
{
if (--fp->maxconfig > 0) {
(fp->SendConfigReq) (fp);
(*fp->fn->SendConfigReq)(fp);
StartTimer(&fp->FsmTimer); /* Start restart timer */
fp->restart--; /* Decrement restart counter */
} else {
@ -273,7 +279,7 @@ FsmSendTerminateReq(struct fsm * fp)
{
LogPrintf(fp->LogLevel, "SendTerminateReq.\n");
FsmOutput(fp, CODE_TERMREQ, fp->reqid++, NULL, 0);
(fp->SendTerminateReq) (fp);
(*fp->fn->SendTerminateReq)(fp);
StartTimer(&fp->FsmTimer); /* Start restart timer */
fp->restart--; /* Decrement restart counter */
}
@ -283,7 +289,7 @@ FsmSendConfigAck(struct fsm *fp, struct fsmheader *lhp,
u_char *option, int count)
{
LogPrintf(fp->LogLevel, "SendConfigAck(%s)\n", StateNames[fp->state]);
(fp->DecodeConfig) (fp->bundle, option, count, MODE_NOP);
(*fp->fn->DecodeConfig)(fp, option, count, MODE_NOP);
FsmOutput(fp, CODE_CONFIGACK, lhp->id, option, count);
}
@ -292,7 +298,7 @@ FsmSendConfigRej(struct fsm *fp, struct fsmheader *lhp,
u_char *option, int count)
{
LogPrintf(fp->LogLevel, "SendConfigRej(%s)\n", StateNames[fp->state]);
(fp->DecodeConfig) (fp->bundle, option, count, MODE_NOP);
(*fp->fn->DecodeConfig)(fp, option, count, MODE_NOP);
FsmOutput(fp, CODE_CONFIGREJ, lhp->id, option, count);
}
@ -301,7 +307,7 @@ FsmSendConfigNak(struct fsm *fp, struct fsmheader *lhp,
u_char *option, int count)
{
LogPrintf(fp->LogLevel, "SendConfigNak(%s)\n", StateNames[fp->state]);
(fp->DecodeConfig) (fp->bundle, option, count, MODE_NOP);
(*fp->fn->DecodeConfig)(fp, option, count, MODE_NOP);
FsmOutput(fp, CODE_CONFIGNAK, lhp->id, option, count);
}
@ -333,17 +339,17 @@ FsmTimeout(void *v)
switch (fp->state) {
case ST_CLOSING:
NewState(fp, ST_CLOSED);
(fp->LayerFinish) (fp);
(*fp->fn->LayerFinish)(fp);
break;
case ST_STOPPING:
NewState(fp, ST_STOPPED);
(fp->LayerFinish) (fp);
(*fp->fn->LayerFinish)(fp);
break;
case ST_REQSENT: /* XXX: 3p */
case ST_ACKSENT:
case ST_ACKRCVD:
NewState(fp, ST_STOPPED);
(fp->LayerFinish) (fp);
(*fp->fn->LayerFinish)(fp);
break;
}
}
@ -356,7 +362,7 @@ FsmInitRestartCounter(struct fsm * fp)
fp->FsmTimer.state = TIMER_STOPPED;
fp->FsmTimer.func = FsmTimeout;
fp->FsmTimer.arg = (void *) fp;
(fp->InitRestartCounter) (fp);
(*fp->fn->InitRestartCounter)(fp);
}
/*
@ -388,7 +394,7 @@ FsmRecvConfigReq(struct fsm *fp, struct fsmheader *lhp, struct mbuf *bp)
pfree(bp);
return;
case ST_CLOSED:
(fp->SendTerminateAck) (fp);
(*fp->fn->SendTerminateAck)(fp);
pfree(bp);
return;
case ST_CLOSING:
@ -399,14 +405,14 @@ FsmRecvConfigReq(struct fsm *fp, struct fsmheader *lhp, struct mbuf *bp)
return;
}
(fp->DecodeConfig) (fp->bundle, MBUF_CTOP(bp), flen, MODE_REQ);
(*fp->fn->DecodeConfig)(fp, MBUF_CTOP(bp), flen, MODE_REQ);
if (nakp == NakBuff && rejp == RejBuff)
ackaction = 1;
switch (fp->state) {
case ST_OPENED:
(fp->LayerDown) (fp);
(*fp->fn->LayerDown)(fp);
FsmSendConfigReq(fp);
break;
case ST_STOPPED:
@ -437,7 +443,7 @@ FsmRecvConfigReq(struct fsm *fp, struct fsmheader *lhp, struct mbuf *bp)
case ST_ACKRCVD:
if (ackaction) {
NewState(fp, ST_OPENED);
(fp->LayerUp) (fp);
(*fp->fn->LayerUp)(fp);
}
break;
case ST_ACKSENT:
@ -455,7 +461,7 @@ FsmRecvConfigAck(struct fsm * fp, struct fsmheader * lhp, struct mbuf * bp)
switch (fp->state) {
case ST_CLOSED:
case ST_STOPPED:
(fp->SendTerminateAck) (fp);
(*fp->fn->SendTerminateAck)(fp);
break;
case ST_CLOSING:
case ST_STOPPING:
@ -471,10 +477,10 @@ FsmRecvConfigAck(struct fsm * fp, struct fsmheader * lhp, struct mbuf * bp)
case ST_ACKSENT:
FsmInitRestartCounter(fp);
NewState(fp, ST_OPENED);
(fp->LayerUp) (fp);
(*fp->fn->LayerUp)(fp);
break;
case ST_OPENED:
(fp->LayerDown) (fp);
(*fp->fn->LayerDown)(fp);
FsmSendConfigReq(fp);
NewState(fp, ST_REQSENT);
break;
@ -506,7 +512,7 @@ FsmRecvConfigNak(struct fsm *fp, struct fsmheader *lhp, struct mbuf *bp)
return;
case ST_CLOSED:
case ST_STOPPED:
(fp->SendTerminateAck) (fp);
(*fp->fn->SendTerminateAck)(fp);
pfree(bp);
return;
case ST_CLOSING:
@ -515,7 +521,7 @@ FsmRecvConfigNak(struct fsm *fp, struct fsmheader *lhp, struct mbuf *bp)
return;
}
(fp->DecodeConfig) (fp->bundle, MBUF_CTOP(bp), flen, MODE_NAK);
(*fp->fn->DecodeConfig)(fp, MBUF_CTOP(bp), flen, MODE_NAK);
switch (fp->state) {
case ST_REQSENT:
@ -524,7 +530,7 @@ FsmRecvConfigNak(struct fsm *fp, struct fsmheader *lhp, struct mbuf *bp)
FsmSendConfigReq(fp);
break;
case ST_OPENED:
(fp->LayerDown) (fp);
(*fp->fn->LayerDown)(fp);
/* Fall down */
case ST_ACKRCVD:
FsmSendConfigReq(fp);
@ -549,16 +555,16 @@ FsmRecvTermReq(struct fsm * fp, struct fsmheader * lhp, struct mbuf * bp)
case ST_CLOSING:
case ST_STOPPING:
case ST_REQSENT:
(fp->SendTerminateAck) (fp);
(*fp->fn->SendTerminateAck)(fp);
break;
case ST_ACKRCVD:
case ST_ACKSENT:
(fp->SendTerminateAck) (fp);
(*fp->fn->SendTerminateAck)(fp);
NewState(fp, ST_REQSENT);
break;
case ST_OPENED:
(fp->LayerDown) (fp);
(fp->SendTerminateAck) (fp);
(*fp->fn->LayerDown)(fp);
(*fp->fn->SendTerminateAck)(fp);
StartTimer(&fp->FsmTimer); /* Start restart timer */
fp->restart = 0;
NewState(fp, ST_STOPPING);
@ -574,17 +580,17 @@ FsmRecvTermAck(struct fsm * fp, struct fsmheader * lhp, struct mbuf * bp)
switch (fp->state) {
case ST_CLOSING:
NewState(fp, ST_CLOSED);
(fp->LayerFinish) (fp);
(*fp->fn->LayerFinish)(fp);
break;
case ST_STOPPING:
NewState(fp, ST_STOPPED);
(fp->LayerFinish) (fp);
(*fp->fn->LayerFinish)(fp);
break;
case ST_ACKRCVD:
NewState(fp, ST_REQSENT);
break;
case ST_OPENED:
(fp->LayerDown) (fp);
(*fp->fn->LayerDown)(fp);
FsmSendConfigReq(fp);
NewState(fp, ST_REQSENT);
break;
@ -617,7 +623,7 @@ FsmRecvConfigRej(struct fsm *fp, struct fsmheader *lhp, struct mbuf *bp)
return;
case ST_CLOSED:
case ST_STOPPED:
(fp->SendTerminateAck) (fp);
(*fp->fn->SendTerminateAck)(fp);
pfree(bp);
return;
case ST_CLOSING:
@ -626,7 +632,7 @@ FsmRecvConfigRej(struct fsm *fp, struct fsmheader *lhp, struct mbuf *bp)
return;
}
(fp->DecodeConfig) (fp->bundle, MBUF_CTOP(bp), flen, MODE_REJ);
(*fp->fn->DecodeConfig)(fp, MBUF_CTOP(bp), flen, MODE_REJ);
switch (fp->state) {
case ST_REQSENT:
@ -635,7 +641,7 @@ FsmRecvConfigRej(struct fsm *fp, struct fsmheader *lhp, struct mbuf *bp)
FsmSendConfigReq(fp);
break;
case ST_OPENED:
(fp->LayerDown) (fp);
(*fp->fn->LayerDown)(fp);
/* Fall down */
case ST_ACKRCVD:
FsmSendConfigReq(fp);
@ -671,7 +677,7 @@ FsmRecvProtoRej(struct fsm *fp, struct fsmheader *lhp, struct mbuf *bp)
break;
case PROTO_CCP:
fp = &CcpInfo.fsm;
(fp->LayerFinish) (fp);
(*fp->fn->LayerFinish)(fp);
switch (fp->state) {
case ST_CLOSED:
case ST_CLOSING:
@ -776,7 +782,7 @@ FsmRecvResetAck(struct fsm * fp, struct fsmheader * lhp, struct mbuf * bp)
}
static const struct fsmcodedesc {
void (*action) (struct fsm *, struct fsmheader *, struct mbuf *);
void (*action)(struct fsm *, struct fsmheader *, struct mbuf *);
const char *name;
} FsmCodes[] = {
{FsmRecvConfigReq, "Configure Request",},
@ -822,7 +828,7 @@ FsmInput(struct fsm * fp, struct mbuf * bp)
codep->name, lhp->id, StateNames[fp->state], fp->state);
if (LogIsKept(LogDEBUG))
LogMemory();
(codep->action) (fp, lhp, bp);
(codep->action)(fp, lhp, bp);
if (LogIsKept(LogDEBUG))
LogMemory();
}

View File

@ -15,7 +15,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* $Id: fsm.h,v 1.16.2.3 1998/01/31 02:48:18 brian Exp $
* $Id: fsm.h,v 1.16.2.4 1998/02/02 19:32:06 brian Exp $
*
* TODO:
*/
@ -45,6 +45,20 @@
#define OPEN_PASSIVE -1
struct fsm;
struct fsm_callbacks {
void (*LayerUp) (struct fsm *); /* Layer is now up (tlu) */
void (*LayerDown) (struct fsm *); /* About to come down (tld) */
void (*LayerStart) (struct fsm *); /* Layer about to start up (tls) */
void (*LayerFinish) (struct fsm *); /* Layer now down (tlf) */
void (*InitRestartCounter) (struct fsm *); /* Set fsm timer load */
void (*SendConfigReq) (struct fsm *); /* Send REQ please */
void (*SendTerminateReq) (struct fsm *); /* Term REQ just sent */
void (*SendTerminateAck) (struct fsm *); /* Send Term ACK please */
void (*DecodeConfig) (struct fsm *, u_char *, int, int);
};
struct fsm {
const char *name; /* Name of protocol */
u_short proto; /* Protocol number */
@ -76,16 +90,7 @@ struct fsm {
/* Our high-level link */
struct bundle *bundle;
void (*LayerUp) (struct fsm *); /* Layer is now up (tlu) */
void (*LayerDown) (struct fsm *); /* About to come down (tld) */
void (*LayerStart) (struct fsm *); /* Layer about to start up (tls) */
void (*LayerFinish) (struct fsm *); /* Layer now down (tlf) */
void (*InitRestartCounter) (struct fsm *); /* Set fsm timer load */
void (*SendConfigReq) (struct fsm *); /* Send REQ please */
void (*SendTerminateReq) (struct fsm *); /* Term REQ just sent */
void (*SendTerminateAck) (struct fsm *); /* Send Term ACK please */
void (*DecodeConfig) (struct bundle *, u_char *, int, int);
/* Deal with incoming data */
const struct fsm_callbacks *fn;
};
struct fsmheader {

View File

@ -17,7 +17,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* $Id: ipcp.c,v 1.50.2.6 1998/02/02 19:32:31 brian Exp $
* $Id: ipcp.c,v 1.50.2.7 1998/02/02 19:33:36 brian Exp $
*
* TODO:
* o More RFC1772 backwoard compatibility
@ -75,7 +75,19 @@ static void IpcpInitRestartCounter(struct fsm *);
static void IpcpSendConfigReq(struct fsm *);
static void IpcpSendTerminateReq(struct fsm *);
static void IpcpSendTerminateAck(struct fsm *);
static void IpcpDecodeConfig(struct bundle *, u_char *, int, int);
static void IpcpDecodeConfig(struct fsm *, u_char *, int, int);
static struct fsm_callbacks ipcp_Callbacks = {
IpcpLayerUp,
IpcpLayerDown,
IpcpLayerStart,
IpcpLayerFinish,
IpcpInitRestartCounter,
IpcpSendConfigReq,
IpcpSendTerminateReq,
IpcpSendTerminateAck,
IpcpDecodeConfig,
};
struct ipcpstate IpcpInfo = {
{
@ -91,15 +103,7 @@ struct ipcpstate IpcpInfo = {
LogIPCP,
NULL, /* link */
NULL, /* bundle */
IpcpLayerUp,
IpcpLayerDown,
IpcpLayerStart,
IpcpLayerFinish,
IpcpInitRestartCounter,
IpcpSendConfigReq,
IpcpSendTerminateReq,
IpcpSendTerminateAck,
IpcpDecodeConfig,
&ipcp_Callbacks,
},
MAX_VJ_STATES,
1
@ -274,30 +278,31 @@ IpcpSendConfigReq(struct fsm *fp)
{
/* Send config REQ please */
struct physical *p = link2physical(fp->link);
struct ipcpstate *ipcp = fsm2ipcp(fp);
u_char *cp;
struct lcp_opt o;
cp = ReqBuff;
LogPrintf(LogIPCP, "IpcpSendConfigReq\n");
if ((p && !Physical_IsSync(p)) || !REJECTED(&IpcpInfo, TY_IPADDR)) {
if ((p && !Physical_IsSync(p)) || !REJECTED(ipcp, TY_IPADDR)) {
o.id = TY_IPADDR;
o.len = 6;
*(u_long *)o.data = IpcpInfo.want_ipaddr.s_addr;
*(u_long *)o.data = ipcp->want_ipaddr.s_addr;
cp += LcpPutConf(LogIPCP, cp, &o, cftypes[o.id],
inet_ntoa(IpcpInfo.want_ipaddr));
inet_ntoa(ipcp->want_ipaddr));
}
if (IpcpInfo.want_compproto && !REJECTED(&IpcpInfo, TY_COMPPROTO)) {
if (ipcp->want_compproto && !REJECTED(ipcp, TY_COMPPROTO)) {
const char *args;
o.id = TY_COMPPROTO;
if (IpcpInfo.heis1172) {
if (ipcp->heis1172) {
o.len = 4;
*(u_short *)o.data = htons(PROTO_VJCOMP);
args = "";
} else {
o.len = 6;
*(u_long *)o.data = htonl(IpcpInfo.want_compproto);
args = vj2asc(IpcpInfo.want_compproto);
*(u_long *)o.data = htonl(ipcp->want_compproto);
args = vj2asc(ipcp->want_compproto);
}
cp += LcpPutConf(LogIPCP, cp, &o, cftypes[o.id], args);
}
@ -336,42 +341,43 @@ IpcpLayerFinish(struct fsm * fp)
}
static void
IpcpLayerDown(struct fsm * fp)
IpcpLayerDown(struct fsm *fp)
{
/* About to come down */
struct ipcpstate *ipcp = fsm2ipcp(fp);
LogPrintf(LogIPCP, "IpcpLayerDown.\n");
throughput_stop(&IpcpInfo.throughput);
throughput_log(&IpcpInfo.throughput, LogIPCP, NULL);
throughput_stop(&ipcp->throughput);
throughput_log(&ipcp->throughput, LogIPCP, NULL);
}
static void
IpcpLayerUp(struct fsm *fp)
{
/* We're now up */
struct ipcpstate *ipcp = fsm2ipcp(fp);
char tbuff[100];
Prompt();
LogPrintf(LogIPCP, "IpcpLayerUp(%d).\n", fp->state);
snprintf(tbuff, sizeof tbuff, "myaddr = %s ",
inet_ntoa(IpcpInfo.want_ipaddr));
snprintf(tbuff, sizeof tbuff, "myaddr = %s ", inet_ntoa(ipcp->want_ipaddr));
if (IpcpInfo.his_compproto >> 16 == PROTO_VJCOMP)
VjInit((IpcpInfo.his_compproto >> 8) & 255);
if (ipcp->his_compproto >> 16 == PROTO_VJCOMP)
VjInit((ipcp->his_compproto >> 8) & 255);
LogPrintf(LogIsKept(LogIPCP) ? LogIPCP : LogLINK, " %s hisaddr = %s\n",
tbuff, inet_ntoa(IpcpInfo.his_ipaddr));
if (bundle_SetIPaddress(fp->bundle, IpcpInfo.want_ipaddr,
IpcpInfo.his_ipaddr) < 0) {
tbuff, inet_ntoa(ipcp->his_ipaddr));
if (bundle_SetIPaddress(fp->bundle, ipcp->want_ipaddr,
ipcp->his_ipaddr) < 0) {
if (VarTerm)
LogPrintf(LogERROR, "IpcpLayerUp: unable to set ip address\n");
return;
}
#ifndef NOALIAS
if (mode & MODE_ALIAS)
VarPacketAliasSetAddress(IpcpInfo.want_ipaddr);
VarPacketAliasSetAddress(ipcp->want_ipaddr);
#endif
bundle_Linkup(fp->bundle);
throughput_start(&IpcpInfo.throughput);
throughput_start(&ipcp->throughput);
StartIdleTimer();
}
@ -383,17 +389,6 @@ IpcpUp()
LogPrintf(LogIPCP, "IPCP Up event!!\n");
}
void
IpcpDown()
{
/* Physical link is gone - sudden death */
if (IpcpInfo.fsm.state >= ST_CLOSED) {
FsmDown(&IpcpInfo.fsm);
/* FsmDown() results in an IpcpLayerDown() if we're currently open. */
IpcpLayerFinish(&IpcpInfo.fsm);
}
}
void
IpcpOpen()
{
@ -415,9 +410,10 @@ AcceptableAddr(struct in_range *prange, struct in_addr ipaddr)
}
static void
IpcpDecodeConfig(struct bundle *bundle, u_char * cp, int plen, int mode_type)
IpcpDecodeConfig(struct fsm *fp, u_char * cp, int plen, int mode_type)
{
/* Deal with incoming PROTO_IPCP */
struct ipcpstate *ipcp = fsm2ipcp(fp);
int type, length;
u_long *lp, compproto;
struct compreq *pcomp;
@ -447,53 +443,53 @@ IpcpDecodeConfig(struct bundle *bundle, u_char * cp, int plen, int mode_type)
switch (mode_type) {
case MODE_REQ:
if (iplist_isvalid(&IpcpInfo.DefHisChoice)) {
if (iplist_isvalid(&ipcp->DefHisChoice)) {
if (ipaddr.s_addr == INADDR_ANY ||
iplist_ip2pos(&IpcpInfo.DefHisChoice, ipaddr) < 0 ||
bundle_TrySetIPaddress(bundle, IpcpInfo.DefMyAddress.ipaddr,
iplist_ip2pos(&ipcp->DefHisChoice, ipaddr) < 0 ||
bundle_TrySetIPaddress(fp->bundle, ipcp->DefMyAddress.ipaddr,
ipaddr)) {
LogPrintf(LogIPCP, "%s: Address invalid or already in use\n",
inet_ntoa(ipaddr));
IpcpInfo.his_ipaddr = ChooseHisAddr
(bundle, IpcpInfo.DefMyAddress.ipaddr);
if (IpcpInfo.his_ipaddr.s_addr == INADDR_ANY) {
ipcp->his_ipaddr = ChooseHisAddr
(fp->bundle, ipcp->DefMyAddress.ipaddr);
if (ipcp->his_ipaddr.s_addr == INADDR_ANY) {
memcpy(rejp, cp, length);
rejp += length;
} else {
memcpy(nakp, cp, 2);
memcpy(nakp+2, &IpcpInfo.his_ipaddr.s_addr, length - 2);
memcpy(nakp+2, &ipcp->his_ipaddr.s_addr, length - 2);
nakp += length;
}
break;
}
} else if (!AcceptableAddr(&IpcpInfo.DefHisAddress, ipaddr)) {
} else if (!AcceptableAddr(&ipcp->DefHisAddress, ipaddr)) {
/*
* If destination address is not acceptable, insist to use what we
* want to use.
*/
memcpy(nakp, cp, 2);
memcpy(nakp+2, &IpcpInfo.his_ipaddr.s_addr, length - 2);
memcpy(nakp+2, &ipcp->his_ipaddr.s_addr, length - 2);
nakp += length;
break;
}
IpcpInfo.his_ipaddr = ipaddr;
ipcp->his_ipaddr = ipaddr;
memcpy(ackp, cp, length);
ackp += length;
break;
case MODE_NAK:
if (AcceptableAddr(&IpcpInfo.DefMyAddress, ipaddr)) {
if (AcceptableAddr(&ipcp->DefMyAddress, ipaddr)) {
/* Use address suggested by peer */
snprintf(tbuff2, sizeof tbuff2, "%s changing address: %s ", tbuff,
inet_ntoa(IpcpInfo.want_ipaddr));
inet_ntoa(ipcp->want_ipaddr));
LogPrintf(LogIPCP, "%s --> %s\n", tbuff2, inet_ntoa(ipaddr));
IpcpInfo.want_ipaddr = ipaddr;
ipcp->want_ipaddr = ipaddr;
} else {
LogPrintf(LogIPCP, "%s: Unacceptable address!\n", inet_ntoa(ipaddr));
FsmClose(&IpcpInfo.fsm);
FsmClose(&ipcp->fsm);
}
break;
case MODE_REJ:
IpcpInfo.his_reject |= (1 << type);
ipcp->his_reject |= (1 << type);
break;
}
break;
@ -513,8 +509,8 @@ IpcpDecodeConfig(struct bundle *bundle, u_char * cp, int plen, int mode_type)
case 4: /* RFC1172 */
if (ntohs(pcomp->proto) == PROTO_VJCOMP) {
LogPrintf(LogWARN, "Peer is speaking RFC1172 compression protocol !\n");
IpcpInfo.heis1172 = 1;
IpcpInfo.his_compproto = compproto;
ipcp->heis1172 = 1;
ipcp->his_compproto = compproto;
memcpy(ackp, cp, length);
ackp += length;
} else {
@ -527,8 +523,8 @@ IpcpDecodeConfig(struct bundle *bundle, u_char * cp, int plen, int mode_type)
case 6: /* RFC1332 */
if (ntohs(pcomp->proto) == PROTO_VJCOMP
&& pcomp->slots < MAX_VJ_STATES && pcomp->slots > 2) {
IpcpInfo.his_compproto = compproto;
IpcpInfo.heis1172 = 0;
ipcp->his_compproto = compproto;
ipcp->heis1172 = 0;
memcpy(ackp, cp, length);
ackp += length;
} else {
@ -549,11 +545,11 @@ IpcpDecodeConfig(struct bundle *bundle, u_char * cp, int plen, int mode_type)
break;
case MODE_NAK:
LogPrintf(LogIPCP, "%s changing compproto: %08x --> %08x\n",
tbuff, IpcpInfo.want_compproto, compproto);
IpcpInfo.want_compproto = compproto;
tbuff, ipcp->want_compproto, compproto);
ipcp->want_compproto = compproto;
break;
case MODE_REJ:
IpcpInfo.his_reject |= (1 << type);
ipcp->his_reject |= (1 << type);
break;
}
break;
@ -567,20 +563,20 @@ IpcpDecodeConfig(struct bundle *bundle, u_char * cp, int plen, int mode_type)
switch (mode_type) {
case MODE_REQ:
IpcpInfo.his_ipaddr = ipaddr;
IpcpInfo.want_ipaddr = dstipaddr;
ipcp->his_ipaddr = ipaddr;
ipcp->want_ipaddr = dstipaddr;
memcpy(ackp, cp, length);
ackp += length;
break;
case MODE_NAK:
snprintf(tbuff2, sizeof tbuff2, "%s changing address: %s", tbuff,
inet_ntoa(IpcpInfo.want_ipaddr));
inet_ntoa(ipcp->want_ipaddr));
LogPrintf(LogIPCP, "%s --> %s\n", tbuff2, inet_ntoa(ipaddr));
IpcpInfo.want_ipaddr = ipaddr;
IpcpInfo.his_ipaddr = dstipaddr;
ipcp->want_ipaddr = ipaddr;
ipcp->his_ipaddr = dstipaddr;
break;
case MODE_REJ:
IpcpInfo.his_reject |= (1 << type);
ipcp->his_reject |= (1 << type);
break;
}
break;
@ -594,7 +590,7 @@ IpcpDecodeConfig(struct bundle *bundle, u_char * cp, int plen, int mode_type)
case TY_SECONDARY_DNS:
if (!Enabled(ConfMSExt)) {
LogPrintf(LogIPCP, "MS NS req - rejected - msext disabled\n");
IpcpInfo.my_reject |= (1 << type);
ipcp->my_reject |= (1 << type);
memcpy(rejp, cp, length);
rejp += length;
break;
@ -603,7 +599,7 @@ IpcpDecodeConfig(struct bundle *bundle, u_char * cp, int plen, int mode_type)
case MODE_REQ:
lp = (u_long *) (cp + 2);
dnsstuff.s_addr = *lp;
ms_info_req.s_addr = IpcpInfo.ns_entries
ms_info_req.s_addr = ipcp->ns_entries
[(type - TY_PRIMARY_DNS) ? 1 : 0].s_addr;
if (dnsstuff.s_addr != ms_info_req.s_addr) {
@ -644,7 +640,7 @@ IpcpDecodeConfig(struct bundle *bundle, u_char * cp, int plen, int mode_type)
case TY_SECONDARY_NBNS:
if (!Enabled(ConfMSExt)) {
LogPrintf(LogIPCP, "MS NBNS req - rejected - msext disabled\n");
IpcpInfo.my_reject |= (1 << type);
ipcp->my_reject |= (1 << type);
memcpy(rejp, cp, length);
rejp += length;
break;
@ -653,7 +649,7 @@ IpcpDecodeConfig(struct bundle *bundle, u_char * cp, int plen, int mode_type)
case MODE_REQ:
lp = (u_long *) (cp + 2);
dnsstuff.s_addr = *lp;
ms_info_req.s_addr = IpcpInfo.nbns_entries
ms_info_req.s_addr = ipcp->nbns_entries
[(type - TY_PRIMARY_NBNS) ? 1 : 0].s_addr;
if (dnsstuff.s_addr != ms_info_req.s_addr) {
memcpy(nakp, cp, 2);
@ -683,7 +679,7 @@ IpcpDecodeConfig(struct bundle *bundle, u_char * cp, int plen, int mode_type)
#endif
default:
IpcpInfo.my_reject |= (1 << type);
ipcp->my_reject |= (1 << type);
memcpy(rejp, cp, length);
rejp += length;
break;

View File

@ -15,7 +15,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* $Id: ipcp.h,v 1.18.2.7 1998/02/02 19:32:08 brian Exp $
* $Id: ipcp.h,v 1.18.2.8 1998/02/02 19:32:31 brian Exp $
*
* TODO:
*/
@ -74,6 +74,8 @@ struct ipcpstate {
extern struct ipcpstate IpcpInfo;
#define fsm2ipcp(fp) (fp->proto == PROTO_IPCP ? (struct ipcpstate *)fp : NULL)
extern void IpcpInit(struct bundle *, struct link *l);
extern void IpcpDefAddress(void);
extern void IpcpUp(void);
@ -84,4 +86,3 @@ extern void IpcpAddInOctets(int);
extern void IpcpAddOutOctets(int);
extern int UseHisaddr(struct bundle *, const char *, int);
extern int SetInitVJ(struct cmdargs const *);
extern void IpcpDown(void);

View File

@ -17,7 +17,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* $Id: lcp.c,v 1.55.2.8 1998/02/04 01:03:51 brian Exp $
* $Id: lcp.c,v 1.55.2.9 1998/02/06 02:22:14 brian Exp $
*
* TODO:
* o Limit data field length by MRU
@ -84,7 +84,19 @@ static void LcpInitRestartCounter(struct fsm *);
static void LcpSendConfigReq(struct fsm *);
static void LcpSendTerminateReq(struct fsm *);
static void LcpSendTerminateAck(struct fsm *);
static void LcpDecodeConfig(struct bundle *, u_char *, int, int);
static void LcpDecodeConfig(struct fsm *, u_char *, int, int);
static struct fsm_callbacks lcp_Callbacks = {
LcpLayerUp,
LcpLayerDown,
LcpLayerStart,
LcpLayerFinish,
LcpInitRestartCounter,
LcpSendConfigReq,
LcpSendTerminateReq,
LcpSendTerminateAck,
LcpDecodeConfig
};
struct lcpstate LcpInfo = {
{
@ -100,15 +112,7 @@ struct lcpstate LcpInfo = {
LogLCP,
NULL, /* link */
NULL, /* bundle */
LcpLayerUp,
LcpLayerDown,
LcpLayerStart,
LcpLayerFinish,
LcpInitRestartCounter,
LcpSendConfigReq,
LcpSendTerminateReq,
LcpSendTerminateAck,
LcpDecodeConfig,
&lcp_Callbacks
}
};
@ -317,6 +321,7 @@ LcpSendConfigReq(struct fsm *fp)
{
/* Send config REQ please */
struct physical *p = link2physical(fp->link);
struct lcpstate *lcp = fsm2lcp(fp);
u_char *cp;
struct lcp_opt o;
@ -328,26 +333,26 @@ LcpSendConfigReq(struct fsm *fp)
LogPrintf(LogLCP, "LcpSendConfigReq\n");
cp = ReqBuff;
if (!Physical_IsSync(p)) {
if (LcpInfo.want_acfcomp && !REJECTED(&LcpInfo, TY_ACFCOMP))
if (lcp->want_acfcomp && !REJECTED(lcp, TY_ACFCOMP))
PUTN(TY_ACFCOMP);
if (LcpInfo.want_protocomp && !REJECTED(&LcpInfo, TY_PROTOCOMP))
if (lcp->want_protocomp && !REJECTED(lcp, TY_PROTOCOMP))
PUTN(TY_PROTOCOMP);
if (!REJECTED(&LcpInfo, TY_ACCMAP))
PUTACCMAP(LcpInfo.want_accmap);
if (!REJECTED(lcp, TY_ACCMAP))
PUTACCMAP(lcp->want_accmap);
}
if (!REJECTED(&LcpInfo, TY_MRU))
PUTMRU(LcpInfo.want_mru);
if (!REJECTED(lcp, TY_MRU))
PUTMRU(lcp->want_mru);
if (LcpInfo.want_magic && !REJECTED(&LcpInfo, TY_MAGICNUM))
PUTMAGIC(LcpInfo.want_magic);
if (lcp->want_magic && !REJECTED(lcp, TY_MAGICNUM))
PUTMAGIC(lcp->want_magic);
if (LcpInfo.want_lqrperiod && !REJECTED(&LcpInfo, TY_QUALPROTO))
PUTLQR(LcpInfo.want_lqrperiod);
if (lcp->want_lqrperiod && !REJECTED(lcp, TY_QUALPROTO))
PUTLQR(lcp->want_lqrperiod);
switch (LcpInfo.want_auth) {
switch (lcp->want_auth) {
case PROTO_PAP:
PUTPAP();
break;
@ -414,9 +419,10 @@ LcpLayerFinish(struct fsm *fp)
{
/* We're now down */
struct physical *p = link2physical(fp->link);
struct lcpstate *lcp = fsm2lcp(fp);
LogPrintf(LogLCP, "LcpLayerFinish\n");
LcpInfo.LcpFailedMagic = 0;
lcp->LcpFailedMagic = 0;
link_Close(fp->link, 0);
StopAllTimers();
CcpInfo.fsm.restart = 0;
@ -435,22 +441,23 @@ LcpLayerUp(struct fsm *fp)
{
/* We're now up */
struct physical *p = link2physical(fp->link);
struct lcpstate *lcp = fsm2lcp(fp);
LogPrintf(LogLCP, "LcpLayerUp\n");
if (p) {
async_SetLinkParams(&p->async, &LcpInfo);
async_SetLinkParams(&p->async, lcp);
NewPhase(fp->bundle, p, PHASE_AUTHENTICATE);
StartLqm(p);
} else
LogPrintf(LogERROR, "LcpLayerUp: Not a physical link !\n");
StopTimer(&LcpInfo.ReportTimer);
LcpInfo.ReportTimer.state = TIMER_STOPPED;
LcpInfo.ReportTimer.load = 60 * SECTICKS;
LcpInfo.ReportTimer.arg = &LcpInfo.ReportTimer;
LcpInfo.ReportTimer.func = LcpReportTime;
StartTimer(&LcpInfo.ReportTimer);
StopTimer(&lcp->ReportTimer);
lcp->ReportTimer.state = TIMER_STOPPED;
lcp->ReportTimer.load = 60 * SECTICKS;
lcp->ReportTimer.arg = &lcp->ReportTimer;
lcp->ReportTimer.func = LcpReportTime;
StartTimer(&lcp->ReportTimer);
}
static void
@ -474,18 +481,6 @@ LcpUp()
FsmUp(&LcpInfo.fsm);
}
void
LcpDown()
{
LogPrintf(LogPHASE, "Disconnected!\n");
/* Physical link is gone - sudden death */
CcpDown(); /* CCP must come down */
IpcpDown(); /* IPCP must come down */
FsmDown(&LcpInfo.fsm);
/* FsmDown() results in a LcpLayerDown() if we're currently open. */
LcpLayerFinish(&LcpInfo.fsm);
}
void
LcpOpen(int open_mode)
{
@ -513,9 +508,10 @@ LcpClose(struct fsm *fp)
}
static void
LcpDecodeConfig(struct bundle *bundle, u_char *cp, int plen, int mode_type)
LcpDecodeConfig(struct fsm *fp, u_char *cp, int plen, int mode_type)
{
/* Deal with incoming PROTO_LCP */
struct lcpstate *lcp = fsm2lcp(fp);
int type, length, sz, pos;
u_int32_t *lp, magic, accmap;
u_short mtu, mru, *sp, proto;
@ -555,17 +551,17 @@ LcpDecodeConfig(struct bundle *bundle, u_char *cp, int plen, int mode_type)
memcpy(nakp, cp, 4);
nakp += 4;
} else {
LcpInfo.his_mru = mru;
lcp->his_mru = mru;
memcpy(ackp, cp, 4);
ackp += 4;
}
break;
case MODE_NAK:
if (mru >= MIN_MRU || mru <= MAX_MRU)
LcpInfo.want_mru = mru;
lcp->want_mru = mru;
break;
case MODE_REJ:
LcpInfo.his_reject |= (1 << type);
lcp->his_reject |= (1 << type);
break;
}
break;
@ -577,15 +573,15 @@ LcpDecodeConfig(struct bundle *bundle, u_char *cp, int plen, int mode_type)
switch (mode_type) {
case MODE_REQ:
LcpInfo.his_accmap = accmap;
lcp->his_accmap = accmap;
memcpy(ackp, cp, 6);
ackp += 6;
break;
case MODE_NAK:
LcpInfo.want_accmap = accmap;
lcp->want_accmap = accmap;
break;
case MODE_REJ:
LcpInfo.his_reject |= (1 << type);
lcp->his_reject |= (1 << type);
break;
}
break;
@ -614,7 +610,7 @@ LcpDecodeConfig(struct bundle *bundle, u_char *cp, int plen, int mode_type)
goto reqreject;
}
if (Acceptable(ConfPap)) {
LcpInfo.his_auth = proto;
lcp->his_auth = proto;
memcpy(ackp, cp, length);
ackp += length;
} else if (Acceptable(ConfChap)) {
@ -643,7 +639,7 @@ LcpDecodeConfig(struct bundle *bundle, u_char *cp, int plen, int mode_type)
if (Acceptable(ConfChap) && cp[4] == 5)
#endif
{
LcpInfo.his_auth = proto;
lcp->his_auth = proto;
memcpy(ackp, cp, length);
ackp += length;
#ifdef HAVE_DES
@ -670,28 +666,28 @@ LcpDecodeConfig(struct bundle *bundle, u_char *cp, int plen, int mode_type)
switch (proto) {
case PROTO_PAP:
if (Enabled(ConfPap))
LcpInfo.want_auth = PROTO_PAP;
lcp->want_auth = PROTO_PAP;
else {
LogPrintf(LogLCP, "Peer will only send PAP (not enabled)\n");
LcpInfo.his_reject |= (1 << type);
lcp->his_reject |= (1 << type);
}
break;
case PROTO_CHAP:
if (Enabled(ConfChap))
LcpInfo.want_auth = PROTO_CHAP;
lcp->want_auth = PROTO_CHAP;
else {
LogPrintf(LogLCP, "Peer will only send CHAP (not enabled)\n");
LcpInfo.his_reject |= (1 << type);
lcp->his_reject |= (1 << type);
}
break;
default:
/* We've been NAK'd with something we don't understand :-( */
LcpInfo.his_reject |= (1 << type);
lcp->his_reject |= (1 << type);
break;
}
break;
case MODE_REJ:
LcpInfo.his_reject |= (1 << type);
lcp->his_reject |= (1 << type);
break;
}
break;
@ -705,10 +701,10 @@ LcpDecodeConfig(struct bundle *bundle, u_char *cp, int plen, int mode_type)
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);
lcp->his_lqrperiod = ntohl(req->period);
if (lcp->his_lqrperiod < 500)
lcp->his_lqrperiod = 500;
req->period = htonl(lcp->his_lqrperiod);
memcpy(ackp, cp, length);
ackp += length;
}
@ -716,7 +712,7 @@ LcpDecodeConfig(struct bundle *bundle, u_char *cp, int plen, int mode_type)
case MODE_NAK:
break;
case MODE_REJ:
LcpInfo.his_reject |= (1 << type);
lcp->his_reject |= (1 << type);
break;
}
break;
@ -728,35 +724,35 @@ LcpDecodeConfig(struct bundle *bundle, u_char *cp, int plen, int mode_type)
switch (mode_type) {
case MODE_REQ:
if (LcpInfo.want_magic) {
if (lcp->want_magic) {
/* Validate magic number */
if (magic == LcpInfo.want_magic) {
if (magic == lcp->want_magic) {
LogPrintf(LogLCP, "Magic is same (%08lx) - %d times\n",
(u_long)magic, ++LcpInfo.LcpFailedMagic);
LcpInfo.want_magic = GenerateMagic();
(u_long)magic, ++lcp->LcpFailedMagic);
lcp->want_magic = GenerateMagic();
memcpy(nakp, cp, 6);
nakp += 6;
ualarm(TICKUNIT * (4 + 4 * LcpInfo.LcpFailedMagic), 0);
ualarm(TICKUNIT * (4 + 4 * lcp->LcpFailedMagic), 0);
sigpause(0);
} else {
LcpInfo.his_magic = magic;
lcp->his_magic = magic;
memcpy(ackp, cp, length);
ackp += length;
LcpInfo.LcpFailedMagic = 0;
lcp->LcpFailedMagic = 0;
}
} else {
LcpInfo.my_reject |= (1 << type);
lcp->my_reject |= (1 << type);
goto reqreject;
}
break;
case MODE_NAK:
LogPrintf(LogLCP, " Magic 0x%08lx is NAKed!\n", (u_long)magic);
LcpInfo.want_magic = GenerateMagic();
lcp->want_magic = GenerateMagic();
break;
case MODE_REJ:
LogPrintf(LogLCP, " Magic 0x%08x is REJected!\n", magic);
LcpInfo.want_magic = 0;
LcpInfo.his_reject |= (1 << type);
lcp->want_magic = 0;
lcp->his_reject |= (1 << type);
break;
}
break;
@ -767,7 +763,7 @@ LcpDecodeConfig(struct bundle *bundle, u_char *cp, int plen, int mode_type)
switch (mode_type) {
case MODE_REQ:
if (Acceptable(ConfProtocomp)) {
LcpInfo.his_protocomp = 1;
lcp->his_protocomp = 1;
memcpy(ackp, cp, 2);
ackp += 2;
} else {
@ -780,14 +776,14 @@ LcpDecodeConfig(struct bundle *bundle, u_char *cp, int plen, int mode_type)
#else
memcpy(rejp, cp, 2);
rejp += 2;
LcpInfo.my_reject |= (1 << type);
lcp->my_reject |= (1 << type);
#endif
}
break;
case MODE_NAK:
case MODE_REJ:
LcpInfo.want_protocomp = 0;
LcpInfo.his_reject |= (1 << type);
lcp->want_protocomp = 0;
lcp->his_reject |= (1 << type);
break;
}
break;
@ -797,7 +793,7 @@ LcpDecodeConfig(struct bundle *bundle, u_char *cp, int plen, int mode_type)
switch (mode_type) {
case MODE_REQ:
if (Acceptable(ConfAcfcomp)) {
LcpInfo.his_acfcomp = 1;
lcp->his_acfcomp = 1;
memcpy(ackp, cp, 2);
ackp += 2;
} else {
@ -810,14 +806,14 @@ LcpDecodeConfig(struct bundle *bundle, u_char *cp, int plen, int mode_type)
#else
memcpy(rejp, cp, 2);
rejp += 2;
LcpInfo.my_reject |= (1 << type);
lcp->my_reject |= (1 << type);
#endif
}
break;
case MODE_NAK:
case MODE_REJ:
LcpInfo.want_acfcomp = 0;
LcpInfo.his_reject |= (1 << type);
lcp->want_acfcomp = 0;
lcp->his_reject |= (1 << type);
break;
}
break;
@ -852,7 +848,7 @@ LcpDecodeConfig(struct bundle *bundle, u_char *cp, int plen, int mode_type)
}
memcpy(rejp, cp, length);
rejp += length;
LcpInfo.my_reject |= (1 << type);
lcp->my_reject |= (1 << type);
if (length != cp[1])
return;
}

View File

@ -15,7 +15,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* $Id: lcp.h,v 1.16.2.3 1998/01/31 02:48:22 brian Exp $
* $Id: lcp.h,v 1.16.2.4 1998/02/02 19:32:09 brian Exp $
*
* TODO:
*/
@ -74,12 +74,13 @@ struct physical;
extern struct lcpstate LcpInfo;
#define fsm2lcp(fp) (fp->proto == PROTO_LCP ? (struct lcpstate *)fp : NULL)
extern void LcpInit(struct bundle *, struct physical *);
extern void LcpUp(void);
extern void LcpSendProtoRej(u_char *, int);
extern void LcpOpen(int);
extern void LcpClose(struct fsm *);
extern void LcpDown(void);
extern int LcpPutConf(int, u_char *, const struct lcp_opt *, const char *,
const char *, ...);
extern int ReportLcpStatus(struct cmdargs const *);

View File

@ -17,7 +17,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* $Id: main.c,v 1.121.2.8 1998/02/06 02:22:45 brian Exp $
* $Id: main.c,v 1.121.2.9 1998/02/06 02:23:37 brian Exp $
*
* TODO:
* o Add commands for traffic summary, version display, etc.
@ -178,17 +178,17 @@ TtyOldMode()
tcsetattr(netfd, TCSADRAIN, &oldtio);
}
static struct bundle *CleanupBundle;
static struct bundle *SignalBundle;
void
Cleanup(int excode)
{
DropClient(1);
ServerClose();
bundle_InterfaceDown(CleanupBundle);
link_Close(physical2link(CleanupBundle->physical), 1);
bundle_InterfaceDown(SignalBundle);
link_Close(physical2link(SignalBundle->physical), 1);
nointr_sleep(1);
DeleteIfRoutes(CleanupBundle, 1);
DeleteIfRoutes(SignalBundle, 1);
ID0unlink(pid_filename);
if (mode & MODE_BACKGROUND && BGFiledes[1] != -1) {
char c = EX_ERRDEAD;
@ -201,7 +201,7 @@ Cleanup(int excode)
}
LogPrintf(LogPHASE, "PPP Terminated (%s).\n", ex_desc(excode));
TtyOldMode();
link_Destroy(physical2link(CleanupBundle->physical));
link_Destroy(physical2link(SignalBundle->physical));
LogClose();
exit(excode);
@ -215,7 +215,7 @@ CloseConnection(int signo)
LogPrintf(LogPHASE, "Caught signal %d, abort connection\n", signo);
reconnectState = RECON_FALSE;
reconnectCount = 0;
LcpDown();
bundle_Down(SignalBundle, NULL);
dial_up = 0;
pending_signal(SIGINT, CloseConnection);
}
@ -419,7 +419,7 @@ main(int argc, char **argv)
IsInteractive(1);
IpcpDefAddress();
CleanupBundle = bundle;
SignalBundle = bundle;
if (SelectSystem(bundle, "default", CONFFILE) < 0 && VarTerm)
fprintf(VarTerm, "Warning: No default entry is given in config file.\n");
@ -1025,7 +1025,7 @@ DoLoop(struct bundle *bundle)
nointr_usleep(10000);
n = Physical_Read(bundle->physical, rbuff, sizeof rbuff);
if ((mode & MODE_DIRECT) && n <= 0) {
LcpDown();
bundle_Down(bundle, &bundle->physical->link);
} else
LogDumpBuff(LogASYNC, "ReadFromModem", rbuff, n);

View File

@ -17,7 +17,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* $Id: modem.c,v 1.77.2.6 1998/02/06 02:22:48 brian Exp $
* $Id: modem.c,v 1.77.2.7 1998/02/06 02:23:46 brian Exp $
*
* TODO:
*/
@ -232,11 +232,15 @@ modem_Timeout(void *data)
StopTimer(&to->modem->link.Timer);
StartTimer(&to->modem->link.Timer);
if (to->modem->dev_is_modem) {
if (to->modem->abort) {
/* Something went horribly wrong */
to->modem->abort = 0;
bundle_Down(to->bundle, &to->modem->link);
} else if (to->modem->dev_is_modem) {
if (to->modem->fd >= 0) {
if (ioctl(to->modem->fd, TIOCMGET, &to->modem->mbits) < 0) {
LogPrintf(LogPHASE, "ioctl error (%s)!\n", strerror(errno));
LcpDown();
bundle_Down(to->bundle, &to->modem->link);
return;
}
} else
@ -259,7 +263,7 @@ modem_Timeout(void *data)
} else {
LogPrintf(LogDEBUG, "modem_Timeout: online -> offline\n");
reconnect(RECON_TRUE);
LcpDown();
bundle_Down(to->bundle, &to->modem->link);
}
}
else
@ -843,7 +847,7 @@ modem_StartOutput(struct link *l)
LogPrintf(LogERROR, "modem write (%d): %s\n", modem->fd,
strerror(errno));
reconnect(RECON_TRUE);
LcpDown();
modem->abort = 1;
}
}
}

View File

@ -16,7 +16,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* $Id: physical.h,v 1.1.2.3 1998/02/02 19:33:39 brian Exp $
* $Id: physical.h,v 1.1.2.4 1998/02/06 02:22:28 brian Exp $
*
*/
@ -25,6 +25,7 @@ struct physical {
struct async async; /* Our async state */
int fd; /* File descriptor for this device */
int mbits; /* Current DCD status */
unsigned abort : 1; /* Something's gone horribly wrong */
unsigned dev_is_modem : 1; /* Is the device an actual modem?
Faked for sync devices, though...
(Possibly this should be