1995-01-31 06:29:58 +00:00
|
|
|
/*
|
|
|
|
* PPP Finite State Machine for LCP/IPCP
|
|
|
|
*
|
|
|
|
* 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
|
|
|
*
|
1998-06-15 19:06:58 +00:00
|
|
|
* $Id: fsm.c,v 1.28 1998/05/21 21:45:20 brian Exp $
|
1995-05-30 03:57:47 +00:00
|
|
|
*
|
1995-01-31 06:29:58 +00:00
|
|
|
* TODO:
|
|
|
|
*/
|
1998-05-21 21:49:08 +00:00
|
|
|
|
|
|
|
#include <sys/types.h>
|
1997-10-26 01:04:02 +00:00
|
|
|
#include <netinet/in.h>
|
1998-05-21 21:49:08 +00:00
|
|
|
#include <netinet/in_systm.h>
|
|
|
|
#include <netinet/ip.h>
|
|
|
|
#include <sys/un.h>
|
1997-10-26 01:04:02 +00:00
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
#include <termios.h>
|
|
|
|
|
|
|
|
#include "mbuf.h"
|
|
|
|
#include "log.h"
|
|
|
|
#include "defs.h"
|
|
|
|
#include "timer.h"
|
1995-01-31 06:29:58 +00:00
|
|
|
#include "fsm.h"
|
1998-05-21 21:49:08 +00:00
|
|
|
#include "iplist.h"
|
1995-01-31 06:29:58 +00:00
|
|
|
#include "lqr.h"
|
1998-05-21 21:49:08 +00:00
|
|
|
#include "hdlc.h"
|
|
|
|
#include "throughput.h"
|
|
|
|
#include "slcompress.h"
|
|
|
|
#include "ipcp.h"
|
|
|
|
#include "filter.h"
|
|
|
|
#include "descriptor.h"
|
1995-01-31 06:29:58 +00:00
|
|
|
#include "lcp.h"
|
1996-01-11 17:48:59 +00:00
|
|
|
#include "ccp.h"
|
1998-05-21 21:49:08 +00:00
|
|
|
#include "link.h"
|
|
|
|
#include "mp.h"
|
|
|
|
#include "bundle.h"
|
|
|
|
#include "async.h"
|
|
|
|
#include "physical.h"
|
|
|
|
#include "lcpproto.h"
|
1997-10-26 01:04:02 +00:00
|
|
|
|
|
|
|
static void FsmSendConfigReq(struct fsm *);
|
|
|
|
static void FsmSendTerminateReq(struct fsm *);
|
|
|
|
static void FsmInitRestartCounter(struct fsm *);
|
1995-01-31 06:29:58 +00:00
|
|
|
|
1998-05-21 21:49:08 +00:00
|
|
|
typedef void (recvfn)(struct fsm *, struct fsmheader *, struct mbuf *);
|
|
|
|
static recvfn FsmRecvConfigReq, FsmRecvConfigAck, FsmRecvConfigNak,
|
|
|
|
FsmRecvConfigRej, FsmRecvTermReq, FsmRecvTermAck,
|
|
|
|
FsmRecvCodeRej, FsmRecvProtoRej, FsmRecvEchoReq,
|
|
|
|
FsmRecvEchoRep, FsmRecvDiscReq, FsmRecvIdent,
|
|
|
|
FsmRecvTimeRemain, FsmRecvResetReq, FsmRecvResetAck;
|
|
|
|
|
|
|
|
static const struct fsmcodedesc {
|
|
|
|
recvfn *recv;
|
|
|
|
unsigned check_reqid : 1;
|
|
|
|
unsigned inc_reqid : 1;
|
|
|
|
const char *name;
|
|
|
|
} FsmCodes[] = {
|
|
|
|
{ FsmRecvConfigReq, 0, 0, "ConfigReq" },
|
|
|
|
{ FsmRecvConfigAck, 1, 1, "ConfigAck" },
|
|
|
|
{ FsmRecvConfigNak, 1, 1, "ConfigNak" },
|
|
|
|
{ FsmRecvConfigRej, 1, 1, "ConfigRej" },
|
|
|
|
{ FsmRecvTermReq, 0, 0, "TerminateReq" },
|
|
|
|
{ FsmRecvTermAck, 1, 1, "TerminateAck" },
|
|
|
|
{ FsmRecvCodeRej, 0, 0, "CodeRej" },
|
|
|
|
{ FsmRecvProtoRej, 0, 0, "ProtocolRej" },
|
|
|
|
{ FsmRecvEchoReq, 0, 0, "EchoRequest" },
|
|
|
|
{ FsmRecvEchoRep, 0, 0, "EchoReply" },
|
|
|
|
{ FsmRecvDiscReq, 0, 0, "DiscardReq" },
|
|
|
|
{ FsmRecvIdent, 0, 0, "Ident" },
|
|
|
|
{ FsmRecvTimeRemain,0, 0, "TimeRemain" },
|
|
|
|
{ FsmRecvResetReq, 0, 0, "ResetReqt" },
|
|
|
|
{ FsmRecvResetAck, 0, 1, "ResetAck" }
|
1995-01-31 06:29:58 +00:00
|
|
|
};
|
|
|
|
|
1998-05-21 21:49:08 +00:00
|
|
|
static const char *
|
|
|
|
Code2Nam(u_int code)
|
|
|
|
{
|
|
|
|
if (code == 0 || code > sizeof FsmCodes / sizeof FsmCodes[0])
|
|
|
|
return "Unknown";
|
|
|
|
return FsmCodes[code-1].name;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *
|
|
|
|
State2Nam(u_int state)
|
|
|
|
{
|
|
|
|
static const char *StateNames[] = {
|
|
|
|
"Initial", "Starting", "Closed", "Stopped", "Closing", "Stopping",
|
|
|
|
"Req-Sent", "Ack-Rcvd", "Ack-Sent", "Opened",
|
|
|
|
};
|
|
|
|
|
|
|
|
if (state >= sizeof StateNames / sizeof StateNames[0])
|
|
|
|
return "unknown";
|
|
|
|
return StateNames[state];
|
|
|
|
}
|
|
|
|
|
1997-08-17 20:45:50 +00:00
|
|
|
static void
|
1997-11-22 03:37:54 +00:00
|
|
|
StoppedTimeout(void *v)
|
1997-08-17 20:45:50 +00:00
|
|
|
{
|
1997-11-22 03:37:54 +00:00
|
|
|
struct fsm *fp = (struct fsm *)v;
|
|
|
|
|
1998-05-21 21:49:08 +00:00
|
|
|
log_Printf(fp->LogLevel, "%s: Stopped timer expired\n", fp->link->name);
|
1998-01-20 22:47:48 +00:00
|
|
|
if (fp->OpenTimer.state == TIMER_RUNNING) {
|
1998-05-21 21:49:08 +00:00
|
|
|
log_Printf(LogWARN, "%s: %s: aborting open delay due to stopped timer\n",
|
|
|
|
fp->link->name, fp->name);
|
|
|
|
timer_Stop(&fp->OpenTimer);
|
|
|
|
}
|
|
|
|
if (fp->state == ST_STOPPED) {
|
|
|
|
/* Force ourselves back to initial */
|
|
|
|
fsm_Down(fp);
|
|
|
|
fsm_Close(fp);
|
1998-01-20 22:47:48 +00:00
|
|
|
}
|
1997-08-17 20:45:50 +00:00
|
|
|
}
|
|
|
|
|
1995-01-31 06:29:58 +00:00
|
|
|
void
|
1998-05-21 21:49:08 +00:00
|
|
|
fsm_Init(struct fsm *fp, const char *name, u_short proto, int mincode,
|
|
|
|
int maxcode, int maxcfg, int LogLevel, struct bundle *bundle,
|
|
|
|
struct link *l, const struct fsm_parent *parent,
|
|
|
|
struct fsm_callbacks *fn, const char *timer_names[3])
|
|
|
|
{
|
|
|
|
fp->name = name;
|
|
|
|
fp->proto = proto;
|
|
|
|
fp->min_code = mincode;
|
|
|
|
fp->max_code = maxcode;
|
|
|
|
fp->state = fp->min_code > CODE_TERMACK ? ST_OPENED : ST_INITIAL;
|
1995-01-31 06:29:58 +00:00
|
|
|
fp->reqid = 1;
|
|
|
|
fp->restart = 1;
|
1998-05-21 21:49:08 +00:00
|
|
|
fp->maxconfig = maxcfg;
|
|
|
|
memset(&fp->FsmTimer, '\0', sizeof fp->FsmTimer);
|
|
|
|
memset(&fp->OpenTimer, '\0', sizeof fp->OpenTimer);
|
|
|
|
memset(&fp->StoppedTimer, '\0', sizeof fp->StoppedTimer);
|
|
|
|
fp->LogLevel = LogLevel;
|
|
|
|
fp->link = l;
|
|
|
|
fp->bundle = bundle;
|
|
|
|
fp->parent = parent;
|
|
|
|
fp->fn = fn;
|
|
|
|
fp->FsmTimer.name = timer_names[0];
|
|
|
|
fp->OpenTimer.name = timer_names[1];
|
|
|
|
fp->StoppedTimer.name = timer_names[2];
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
|
1997-10-26 01:04:02 +00:00
|
|
|
static void
|
1997-08-25 00:29:32 +00:00
|
|
|
NewState(struct fsm * fp, int new)
|
1995-01-31 06:29:58 +00:00
|
|
|
{
|
1998-05-21 21:49:08 +00:00
|
|
|
log_Printf(fp->LogLevel, "%s: State change %s --> %s\n",
|
|
|
|
fp->link->name, State2Nam(fp->state), State2Nam(new));
|
1997-08-20 23:47:53 +00:00
|
|
|
if (fp->state == ST_STOPPED && fp->StoppedTimer.state == TIMER_RUNNING)
|
1998-05-21 21:49:08 +00:00
|
|
|
timer_Stop(&fp->StoppedTimer);
|
1995-01-31 06:29:58 +00:00
|
|
|
fp->state = new;
|
1997-08-17 20:45:50 +00:00
|
|
|
if ((new >= ST_INITIAL && new <= ST_STOPPED) || (new == ST_OPENED)) {
|
1998-05-21 21:49:08 +00:00
|
|
|
timer_Stop(&fp->FsmTimer);
|
1997-08-20 23:47:53 +00:00
|
|
|
if (new == ST_STOPPED && fp->StoppedTimer.load) {
|
1998-05-21 21:49:08 +00:00
|
|
|
timer_Stop(&fp->StoppedTimer);
|
1997-08-20 23:47:53 +00:00
|
|
|
fp->StoppedTimer.func = StoppedTimeout;
|
1997-08-25 00:29:32 +00:00
|
|
|
fp->StoppedTimer.arg = (void *) fp;
|
1998-05-21 21:49:08 +00:00
|
|
|
timer_Start(&fp->StoppedTimer);
|
1997-08-17 20:45:50 +00:00
|
|
|
}
|
|
|
|
}
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1998-05-21 21:49:08 +00:00
|
|
|
fsm_Output(struct fsm *fp, u_int code, u_int id, u_char *ptr, int count)
|
1995-01-31 06:29:58 +00:00
|
|
|
{
|
|
|
|
int plen;
|
|
|
|
struct fsmheader lh;
|
|
|
|
struct mbuf *bp;
|
|
|
|
|
1998-05-21 21:49:08 +00:00
|
|
|
if (log_IsKept(fp->LogLevel)) {
|
|
|
|
log_Printf(fp->LogLevel, "%s: Send%s(%d) state = %s\n",
|
|
|
|
fp->link->name, Code2Nam(code), id, State2Nam(fp->state));
|
|
|
|
switch (code) {
|
|
|
|
case CODE_CONFIGREQ:
|
|
|
|
case CODE_CONFIGACK:
|
|
|
|
case CODE_CONFIGREJ:
|
|
|
|
case CODE_CONFIGNAK:
|
|
|
|
(*fp->fn->DecodeConfig)(fp, ptr, count, MODE_NOP, NULL);
|
|
|
|
if (count < sizeof(struct fsmconfig))
|
|
|
|
log_Printf(fp->LogLevel, " [EMPTY]\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1997-08-25 00:29:32 +00:00
|
|
|
plen = sizeof(struct fsmheader) + count;
|
1995-01-31 06:29:58 +00:00
|
|
|
lh.code = code;
|
|
|
|
lh.id = id;
|
|
|
|
lh.length = htons(plen);
|
1998-05-21 21:49:08 +00:00
|
|
|
bp = mbuf_Alloc(plen, MB_FSM);
|
1997-10-26 01:04:02 +00:00
|
|
|
memcpy(MBUF_CTOP(bp), &lh, sizeof(struct fsmheader));
|
1995-01-31 06:29:58 +00:00
|
|
|
if (count)
|
1997-10-26 01:04:02 +00:00
|
|
|
memcpy(MBUF_CTOP(bp) + sizeof(struct fsmheader), ptr, count);
|
1998-05-21 21:49:08 +00:00
|
|
|
log_DumpBp(LogDEBUG, "fsm_Output", bp);
|
|
|
|
hdlc_Output(fp->link, PRI_LINK, fp->proto, bp);
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
|
1998-01-20 22:47:48 +00:00
|
|
|
static void
|
|
|
|
FsmOpenNow(void *v)
|
|
|
|
{
|
|
|
|
struct fsm *fp = (struct fsm *)v;
|
|
|
|
|
1998-05-21 21:49:08 +00:00
|
|
|
timer_Stop(&fp->OpenTimer);
|
1998-01-20 22:47:48 +00:00
|
|
|
if (fp->state <= ST_STOPPED) {
|
|
|
|
FsmInitRestartCounter(fp);
|
|
|
|
FsmSendConfigReq(fp);
|
|
|
|
NewState(fp, ST_REQSENT);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1995-01-31 06:29:58 +00:00
|
|
|
void
|
1998-05-21 21:49:08 +00:00
|
|
|
fsm_Open(struct fsm * fp)
|
1995-01-31 06:29:58 +00:00
|
|
|
{
|
|
|
|
switch (fp->state) {
|
1998-05-21 21:49:08 +00:00
|
|
|
case ST_INITIAL:
|
1995-01-31 06:29:58 +00:00
|
|
|
NewState(fp, ST_STARTING);
|
1998-05-21 21:49:08 +00:00
|
|
|
(*fp->fn->LayerStart)(fp);
|
|
|
|
(*fp->parent->LayerStart)(fp->parent->object, fp);
|
1995-01-31 06:29:58 +00:00
|
|
|
break;
|
|
|
|
case ST_CLOSED:
|
|
|
|
if (fp->open_mode == OPEN_PASSIVE) {
|
|
|
|
NewState(fp, ST_STOPPED);
|
1998-01-20 22:47:48 +00:00
|
|
|
} else if (fp->open_mode > 0) {
|
|
|
|
if (fp->open_mode > 1)
|
1998-05-21 21:49:08 +00:00
|
|
|
log_Printf(LogPHASE, "%s: Entering STOPPED state for %d seconds\n",
|
|
|
|
fp->link->name, fp->open_mode);
|
1998-01-20 22:47:48 +00:00
|
|
|
NewState(fp, ST_STOPPED);
|
1998-05-21 21:49:08 +00:00
|
|
|
timer_Stop(&fp->OpenTimer);
|
1998-01-20 22:47:48 +00:00
|
|
|
fp->OpenTimer.load = fp->open_mode * SECTICKS;
|
|
|
|
fp->OpenTimer.func = FsmOpenNow;
|
|
|
|
fp->OpenTimer.arg = (void *)fp;
|
1998-05-21 21:49:08 +00:00
|
|
|
timer_Start(&fp->OpenTimer);
|
1998-01-20 22:47:48 +00:00
|
|
|
} else
|
|
|
|
FsmOpenNow(fp);
|
1995-01-31 06:29:58 +00:00
|
|
|
break;
|
1997-08-25 00:29:32 +00:00
|
|
|
case ST_STOPPED: /* XXX: restart option */
|
1995-01-31 06:29:58 +00:00
|
|
|
case ST_REQSENT:
|
|
|
|
case ST_ACKRCVD:
|
|
|
|
case ST_ACKSENT:
|
1997-08-25 00:29:32 +00:00
|
|
|
case ST_OPENED: /* XXX: restart option */
|
1995-01-31 06:29:58 +00:00
|
|
|
break;
|
1997-08-25 00:29:32 +00:00
|
|
|
case ST_CLOSING: /* XXX: restart option */
|
|
|
|
case ST_STOPPING: /* XXX: restart option */
|
1995-01-31 06:29:58 +00:00
|
|
|
NewState(fp, ST_STOPPING);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1998-05-21 21:49:08 +00:00
|
|
|
fsm_Up(struct fsm * fp)
|
1995-01-31 06:29:58 +00:00
|
|
|
{
|
|
|
|
switch (fp->state) {
|
1997-08-25 00:29:32 +00:00
|
|
|
case ST_INITIAL:
|
1998-05-21 21:49:08 +00:00
|
|
|
log_Printf(fp->LogLevel, "FSM: Using \"%s\" as a transport\n",
|
|
|
|
fp->link->name);
|
1995-01-31 06:29:58 +00:00
|
|
|
NewState(fp, ST_CLOSED);
|
|
|
|
break;
|
|
|
|
case ST_STARTING:
|
|
|
|
FsmInitRestartCounter(fp);
|
|
|
|
FsmSendConfigReq(fp);
|
|
|
|
NewState(fp, ST_REQSENT);
|
|
|
|
break;
|
|
|
|
default:
|
1998-05-21 21:49:08 +00:00
|
|
|
log_Printf(fp->LogLevel, "%s: Oops, Up at %s\n",
|
|
|
|
fp->link->name, State2Nam(fp->state));
|
1995-01-31 06:29:58 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1998-05-21 21:49:08 +00:00
|
|
|
fsm_Down(struct fsm *fp)
|
1995-01-31 06:29:58 +00:00
|
|
|
{
|
|
|
|
switch (fp->state) {
|
1998-05-21 21:49:08 +00:00
|
|
|
case ST_CLOSED:
|
|
|
|
NewState(fp, ST_INITIAL);
|
|
|
|
break;
|
|
|
|
case ST_CLOSING:
|
|
|
|
(*fp->fn->LayerFinish)(fp);
|
1995-01-31 06:29:58 +00:00
|
|
|
NewState(fp, ST_INITIAL);
|
1998-05-21 21:49:08 +00:00
|
|
|
(*fp->parent->LayerFinish)(fp->parent->object, fp);
|
1995-01-31 06:29:58 +00:00
|
|
|
break;
|
|
|
|
case ST_STOPPED:
|
1998-05-21 21:49:08 +00:00
|
|
|
NewState(fp, ST_STARTING);
|
|
|
|
(*fp->fn->LayerStart)(fp);
|
|
|
|
(*fp->parent->LayerStart)(fp->parent->object, fp);
|
|
|
|
break;
|
1995-01-31 06:29:58 +00:00
|
|
|
case ST_STOPPING:
|
|
|
|
case ST_REQSENT:
|
|
|
|
case ST_ACKRCVD:
|
|
|
|
case ST_ACKSENT:
|
|
|
|
NewState(fp, ST_STARTING);
|
|
|
|
break;
|
|
|
|
case ST_OPENED:
|
1998-05-21 21:49:08 +00:00
|
|
|
(*fp->fn->LayerDown)(fp);
|
1995-01-31 06:29:58 +00:00
|
|
|
NewState(fp, ST_STARTING);
|
1998-05-21 21:49:08 +00:00
|
|
|
(*fp->parent->LayerDown)(fp->parent->object, fp);
|
1995-01-31 06:29:58 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1998-05-21 21:49:08 +00:00
|
|
|
fsm_Close(struct fsm *fp)
|
1995-01-31 06:29:58 +00:00
|
|
|
{
|
|
|
|
switch (fp->state) {
|
1998-05-21 21:49:08 +00:00
|
|
|
case ST_STARTING:
|
|
|
|
(*fp->fn->LayerFinish)(fp);
|
1995-01-31 06:29:58 +00:00
|
|
|
NewState(fp, ST_INITIAL);
|
1998-05-21 21:49:08 +00:00
|
|
|
(*fp->parent->LayerFinish)(fp->parent->object, fp);
|
1995-01-31 06:29:58 +00:00
|
|
|
break;
|
|
|
|
case ST_STOPPED:
|
|
|
|
NewState(fp, ST_CLOSED);
|
|
|
|
break;
|
|
|
|
case ST_STOPPING:
|
|
|
|
NewState(fp, ST_CLOSING);
|
|
|
|
break;
|
|
|
|
case ST_OPENED:
|
1998-05-21 21:49:08 +00:00
|
|
|
(*fp->fn->LayerDown)(fp);
|
|
|
|
FsmInitRestartCounter(fp);
|
|
|
|
FsmSendTerminateReq(fp);
|
|
|
|
NewState(fp, ST_CLOSING);
|
|
|
|
(*fp->parent->LayerDown)(fp->parent->object, fp);
|
|
|
|
break;
|
1995-01-31 06:29:58 +00:00
|
|
|
case ST_REQSENT:
|
|
|
|
case ST_ACKRCVD:
|
|
|
|
case ST_ACKSENT:
|
|
|
|
FsmInitRestartCounter(fp);
|
|
|
|
FsmSendTerminateReq(fp);
|
|
|
|
NewState(fp, ST_CLOSING);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Send functions
|
|
|
|
*/
|
1997-10-26 01:04:02 +00:00
|
|
|
static void
|
1997-08-25 00:29:32 +00:00
|
|
|
FsmSendConfigReq(struct fsm * fp)
|
1995-01-31 06:29:58 +00:00
|
|
|
{
|
|
|
|
if (--fp->maxconfig > 0) {
|
1998-05-21 21:49:08 +00:00
|
|
|
(*fp->fn->SendConfigReq)(fp);
|
|
|
|
timer_Start(&fp->FsmTimer); /* Start restart timer */
|
1995-01-31 06:29:58 +00:00
|
|
|
fp->restart--; /* Decrement restart counter */
|
|
|
|
} else {
|
1998-05-21 21:49:08 +00:00
|
|
|
fsm_Close(fp);
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1997-10-26 01:04:02 +00:00
|
|
|
static void
|
1998-05-21 21:49:08 +00:00
|
|
|
FsmSendTerminateReq(struct fsm *fp)
|
1995-01-31 06:29:58 +00:00
|
|
|
{
|
1998-05-21 21:49:08 +00:00
|
|
|
fsm_Output(fp, CODE_TERMREQ, fp->reqid, NULL, 0);
|
|
|
|
(*fp->fn->SentTerminateReq)(fp);
|
|
|
|
timer_Start(&fp->FsmTimer); /* Start restart timer */
|
1995-01-31 06:29:58 +00:00
|
|
|
fp->restart--; /* Decrement restart counter */
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Timeout actions
|
|
|
|
*/
|
1997-10-26 01:04:02 +00:00
|
|
|
static void
|
1997-11-22 03:37:54 +00:00
|
|
|
FsmTimeout(void *v)
|
1995-01-31 06:29:58 +00:00
|
|
|
{
|
1997-11-22 03:37:54 +00:00
|
|
|
struct fsm *fp = (struct fsm *)v;
|
|
|
|
|
1995-01-31 06:29:58 +00:00
|
|
|
if (fp->restart) {
|
|
|
|
switch (fp->state) {
|
1998-05-21 21:49:08 +00:00
|
|
|
case ST_CLOSING:
|
|
|
|
case ST_STOPPING:
|
1995-01-31 06:29:58 +00:00
|
|
|
FsmSendTerminateReq(fp);
|
|
|
|
break;
|
|
|
|
case ST_REQSENT:
|
|
|
|
case ST_ACKSENT:
|
|
|
|
FsmSendConfigReq(fp);
|
|
|
|
break;
|
|
|
|
case ST_ACKRCVD:
|
|
|
|
FsmSendConfigReq(fp);
|
|
|
|
NewState(fp, ST_REQSENT);
|
|
|
|
break;
|
|
|
|
}
|
1998-05-21 21:49:08 +00:00
|
|
|
timer_Start(&fp->FsmTimer);
|
1995-01-31 06:29:58 +00:00
|
|
|
} else {
|
|
|
|
switch (fp->state) {
|
|
|
|
case ST_CLOSING:
|
1998-05-21 21:49:08 +00:00
|
|
|
(*fp->fn->LayerFinish)(fp);
|
1995-01-31 06:29:58 +00:00
|
|
|
NewState(fp, ST_CLOSED);
|
1998-05-21 21:49:08 +00:00
|
|
|
(*fp->parent->LayerFinish)(fp->parent->object, fp);
|
1995-01-31 06:29:58 +00:00
|
|
|
break;
|
|
|
|
case ST_STOPPING:
|
1998-05-21 21:49:08 +00:00
|
|
|
(*fp->fn->LayerFinish)(fp);
|
1995-01-31 06:29:58 +00:00
|
|
|
NewState(fp, ST_STOPPED);
|
1998-05-21 21:49:08 +00:00
|
|
|
(*fp->parent->LayerFinish)(fp->parent->object, fp);
|
1995-01-31 06:29:58 +00:00
|
|
|
break;
|
|
|
|
case ST_REQSENT: /* XXX: 3p */
|
|
|
|
case ST_ACKSENT:
|
|
|
|
case ST_ACKRCVD:
|
1998-05-21 21:49:08 +00:00
|
|
|
(*fp->fn->LayerFinish)(fp);
|
1995-01-31 06:29:58 +00:00
|
|
|
NewState(fp, ST_STOPPED);
|
1998-05-21 21:49:08 +00:00
|
|
|
(*fp->parent->LayerFinish)(fp->parent->object, fp);
|
1995-01-31 06:29:58 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1997-10-26 01:04:02 +00:00
|
|
|
static void
|
1997-08-25 00:29:32 +00:00
|
|
|
FsmInitRestartCounter(struct fsm * fp)
|
1995-01-31 06:29:58 +00:00
|
|
|
{
|
1998-05-21 21:49:08 +00:00
|
|
|
timer_Stop(&fp->FsmTimer);
|
1995-01-31 06:29:58 +00:00
|
|
|
fp->FsmTimer.func = FsmTimeout;
|
1997-08-25 00:29:32 +00:00
|
|
|
fp->FsmTimer.arg = (void *) fp;
|
1998-05-21 21:49:08 +00:00
|
|
|
(*fp->fn->InitRestartCounter)(fp);
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Actions when receive packets
|
|
|
|
*/
|
1997-10-26 01:04:02 +00:00
|
|
|
static void
|
1998-05-21 21:49:08 +00:00
|
|
|
FsmRecvConfigReq(struct fsm *fp, struct fsmheader *lhp, struct mbuf *bp)
|
1997-08-25 00:29:32 +00:00
|
|
|
/* RCR */
|
1995-01-31 06:29:58 +00:00
|
|
|
{
|
1998-05-21 21:49:08 +00:00
|
|
|
struct fsm_decode dec;
|
1995-02-26 12:18:08 +00:00
|
|
|
int plen, flen;
|
1995-01-31 06:29:58 +00:00
|
|
|
int ackaction = 0;
|
1995-05-30 03:57:47 +00:00
|
|
|
|
1998-05-21 21:49:08 +00:00
|
|
|
plen = mbuf_Length(bp);
|
1997-12-24 09:29:17 +00:00
|
|
|
flen = ntohs(lhp->length) - sizeof *lhp;
|
1995-02-26 12:18:08 +00:00
|
|
|
if (plen < flen) {
|
1998-05-21 21:49:08 +00:00
|
|
|
log_Printf(LogERROR, "%s: FsmRecvConfigReq: plen (%d) < flen (%d)\n",
|
|
|
|
fp->link->name, plen, flen);
|
|
|
|
mbuf_Free(bp);
|
1995-01-31 06:29:58 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
1997-08-25 00:29:32 +00:00
|
|
|
* Check and process easy case
|
1995-01-31 06:29:58 +00:00
|
|
|
*/
|
|
|
|
switch (fp->state) {
|
|
|
|
case ST_INITIAL:
|
|
|
|
case ST_STARTING:
|
1998-05-21 21:49:08 +00:00
|
|
|
log_Printf(fp->LogLevel, "%s: Oops, RCR in %s.\n",
|
|
|
|
fp->link->name, State2Nam(fp->state));
|
|
|
|
mbuf_Free(bp);
|
1995-01-31 06:29:58 +00:00
|
|
|
return;
|
|
|
|
case ST_CLOSED:
|
1998-05-21 21:49:08 +00:00
|
|
|
(*fp->fn->SendTerminateAck)(fp, lhp->id);
|
|
|
|
mbuf_Free(bp);
|
1995-01-31 06:29:58 +00:00
|
|
|
return;
|
|
|
|
case ST_CLOSING:
|
1998-05-21 21:49:08 +00:00
|
|
|
log_Printf(fp->LogLevel, "%s: Error: Got ConfigReq while state = %s\n",
|
|
|
|
fp->link->name, State2Nam(fp->state));
|
1997-11-11 23:23:11 +00:00
|
|
|
case ST_STOPPING:
|
1998-05-21 21:49:08 +00:00
|
|
|
mbuf_Free(bp);
|
1995-01-31 06:29:58 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
1998-05-21 21:49:08 +00:00
|
|
|
dec.ackend = dec.ack;
|
|
|
|
dec.nakend = dec.nak;
|
|
|
|
dec.rejend = dec.rej;
|
|
|
|
(*fp->fn->DecodeConfig)(fp, MBUF_CTOP(bp), flen, MODE_REQ, &dec);
|
|
|
|
if (flen < sizeof(struct fsmconfig))
|
|
|
|
log_Printf(fp->LogLevel, " [EMPTY]\n");
|
1995-01-31 06:29:58 +00:00
|
|
|
|
1998-05-21 21:49:08 +00:00
|
|
|
if (dec.nakend == dec.nak && dec.rejend == dec.rej)
|
1995-01-31 06:29:58 +00:00
|
|
|
ackaction = 1;
|
|
|
|
|
|
|
|
switch (fp->state) {
|
|
|
|
case ST_OPENED:
|
1998-05-21 21:49:08 +00:00
|
|
|
(*fp->fn->LayerDown)(fp);
|
1995-01-31 06:29:58 +00:00
|
|
|
FsmSendConfigReq(fp);
|
1998-05-21 21:49:08 +00:00
|
|
|
(*fp->parent->LayerDown)(fp->parent->object, fp);
|
1995-01-31 06:29:58 +00:00
|
|
|
break;
|
|
|
|
case ST_STOPPED:
|
|
|
|
FsmInitRestartCounter(fp);
|
|
|
|
FsmSendConfigReq(fp);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
1998-05-21 21:49:08 +00:00
|
|
|
if (dec.rejend != dec.rej)
|
|
|
|
fsm_Output(fp, CODE_CONFIGREJ, lhp->id, dec.rej, dec.rejend - dec.rej);
|
|
|
|
if (dec.nakend != dec.nak)
|
|
|
|
fsm_Output(fp, CODE_CONFIGNAK, lhp->id, dec.nak, dec.nakend - dec.nak);
|
1995-01-31 06:29:58 +00:00
|
|
|
if (ackaction)
|
1998-05-21 21:49:08 +00:00
|
|
|
fsm_Output(fp, CODE_CONFIGACK, lhp->id, dec.ack, dec.ackend - dec.ack);
|
1995-01-31 06:29:58 +00:00
|
|
|
|
|
|
|
switch (fp->state) {
|
|
|
|
case ST_OPENED:
|
1998-05-21 21:49:08 +00:00
|
|
|
case ST_STOPPED:
|
1995-01-31 06:29:58 +00:00
|
|
|
if (ackaction)
|
|
|
|
NewState(fp, ST_ACKSENT);
|
|
|
|
else
|
|
|
|
NewState(fp, ST_REQSENT);
|
|
|
|
break;
|
|
|
|
case ST_REQSENT:
|
|
|
|
if (ackaction)
|
|
|
|
NewState(fp, ST_ACKSENT);
|
|
|
|
break;
|
|
|
|
case ST_ACKRCVD:
|
|
|
|
if (ackaction) {
|
|
|
|
NewState(fp, ST_OPENED);
|
1998-05-21 21:49:08 +00:00
|
|
|
if ((*fp->fn->LayerUp)(fp))
|
|
|
|
(*fp->parent->LayerUp)(fp->parent->object, fp);
|
|
|
|
else {
|
|
|
|
(*fp->fn->LayerDown)(fp);
|
|
|
|
FsmInitRestartCounter(fp);
|
|
|
|
FsmSendTerminateReq(fp);
|
|
|
|
NewState(fp, ST_CLOSING);
|
|
|
|
}
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ST_ACKSENT:
|
|
|
|
if (!ackaction)
|
|
|
|
NewState(fp, ST_REQSENT);
|
|
|
|
break;
|
|
|
|
}
|
1998-05-21 21:49:08 +00:00
|
|
|
mbuf_Free(bp);
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
|
1997-10-26 01:04:02 +00:00
|
|
|
static void
|
1998-05-21 21:49:08 +00:00
|
|
|
FsmRecvConfigAck(struct fsm *fp, struct fsmheader *lhp, struct mbuf *bp)
|
1997-08-25 00:29:32 +00:00
|
|
|
/* RCA */
|
1995-01-31 06:29:58 +00:00
|
|
|
{
|
|
|
|
switch (fp->state) {
|
1997-08-25 00:29:32 +00:00
|
|
|
case ST_CLOSED:
|
|
|
|
case ST_STOPPED:
|
1998-05-21 21:49:08 +00:00
|
|
|
(*fp->fn->SendTerminateAck)(fp, lhp->id);
|
1995-01-31 06:29:58 +00:00
|
|
|
break;
|
|
|
|
case ST_CLOSING:
|
|
|
|
case ST_STOPPING:
|
|
|
|
break;
|
|
|
|
case ST_REQSENT:
|
|
|
|
FsmInitRestartCounter(fp);
|
|
|
|
NewState(fp, ST_ACKRCVD);
|
|
|
|
break;
|
|
|
|
case ST_ACKRCVD:
|
|
|
|
FsmSendConfigReq(fp);
|
|
|
|
NewState(fp, ST_REQSENT);
|
|
|
|
break;
|
|
|
|
case ST_ACKSENT:
|
|
|
|
FsmInitRestartCounter(fp);
|
|
|
|
NewState(fp, ST_OPENED);
|
1998-05-21 21:49:08 +00:00
|
|
|
if ((*fp->fn->LayerUp)(fp))
|
|
|
|
(*fp->parent->LayerUp)(fp->parent->object, fp);
|
|
|
|
else {
|
|
|
|
(*fp->fn->LayerDown)(fp);
|
|
|
|
FsmInitRestartCounter(fp);
|
|
|
|
FsmSendTerminateReq(fp);
|
|
|
|
NewState(fp, ST_CLOSING);
|
|
|
|
}
|
1995-01-31 06:29:58 +00:00
|
|
|
break;
|
|
|
|
case ST_OPENED:
|
1998-05-21 21:49:08 +00:00
|
|
|
(*fp->fn->LayerDown)(fp);
|
1995-01-31 06:29:58 +00:00
|
|
|
FsmSendConfigReq(fp);
|
|
|
|
NewState(fp, ST_REQSENT);
|
1998-05-21 21:49:08 +00:00
|
|
|
(*fp->parent->LayerDown)(fp->parent->object, fp);
|
1995-01-31 06:29:58 +00:00
|
|
|
break;
|
|
|
|
}
|
1998-05-21 21:49:08 +00:00
|
|
|
mbuf_Free(bp);
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
|
1997-10-26 01:04:02 +00:00
|
|
|
static void
|
1998-05-21 21:49:08 +00:00
|
|
|
FsmRecvConfigNak(struct fsm *fp, struct fsmheader *lhp, struct mbuf *bp)
|
1997-08-25 00:29:32 +00:00
|
|
|
/* RCN */
|
1995-01-31 06:29:58 +00:00
|
|
|
{
|
1998-05-21 21:49:08 +00:00
|
|
|
struct fsm_decode dec;
|
1995-02-26 12:18:08 +00:00
|
|
|
int plen, flen;
|
1995-05-30 03:57:47 +00:00
|
|
|
|
1998-05-21 21:49:08 +00:00
|
|
|
plen = mbuf_Length(bp);
|
1997-12-24 09:29:17 +00:00
|
|
|
flen = ntohs(lhp->length) - sizeof *lhp;
|
1995-02-26 12:18:08 +00:00
|
|
|
if (plen < flen) {
|
1998-05-21 21:49:08 +00:00
|
|
|
mbuf_Free(bp);
|
1995-01-31 06:29:58 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
1997-08-25 00:29:32 +00:00
|
|
|
* Check and process easy case
|
1995-01-31 06:29:58 +00:00
|
|
|
*/
|
|
|
|
switch (fp->state) {
|
|
|
|
case ST_INITIAL:
|
|
|
|
case ST_STARTING:
|
1998-05-21 21:49:08 +00:00
|
|
|
log_Printf(fp->LogLevel, "%s: Oops, RCN in %s.\n",
|
|
|
|
fp->link->name, State2Nam(fp->state));
|
|
|
|
mbuf_Free(bp);
|
1995-01-31 06:29:58 +00:00
|
|
|
return;
|
|
|
|
case ST_CLOSED:
|
|
|
|
case ST_STOPPED:
|
1998-05-21 21:49:08 +00:00
|
|
|
(*fp->fn->SendTerminateAck)(fp, lhp->id);
|
|
|
|
mbuf_Free(bp);
|
1995-01-31 06:29:58 +00:00
|
|
|
return;
|
|
|
|
case ST_CLOSING:
|
|
|
|
case ST_STOPPING:
|
1998-05-21 21:49:08 +00:00
|
|
|
mbuf_Free(bp);
|
1995-01-31 06:29:58 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
1998-05-21 21:49:08 +00:00
|
|
|
dec.ackend = dec.ack;
|
|
|
|
dec.nakend = dec.nak;
|
|
|
|
dec.rejend = dec.rej;
|
|
|
|
(*fp->fn->DecodeConfig)(fp, MBUF_CTOP(bp), flen, MODE_NAK, &dec);
|
|
|
|
if (flen < sizeof(struct fsmconfig))
|
|
|
|
log_Printf(fp->LogLevel, " [EMPTY]\n");
|
1995-01-31 06:29:58 +00:00
|
|
|
|
|
|
|
switch (fp->state) {
|
|
|
|
case ST_REQSENT:
|
|
|
|
case ST_ACKSENT:
|
|
|
|
FsmInitRestartCounter(fp);
|
|
|
|
FsmSendConfigReq(fp);
|
|
|
|
break;
|
|
|
|
case ST_OPENED:
|
1998-05-21 21:49:08 +00:00
|
|
|
(*fp->fn->LayerDown)(fp);
|
|
|
|
FsmSendConfigReq(fp);
|
|
|
|
NewState(fp, ST_REQSENT);
|
|
|
|
(*fp->parent->LayerDown)(fp->parent->object, fp);
|
|
|
|
break;
|
1995-01-31 06:29:58 +00:00
|
|
|
case ST_ACKRCVD:
|
|
|
|
FsmSendConfigReq(fp);
|
|
|
|
NewState(fp, ST_REQSENT);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
1998-05-21 21:49:08 +00:00
|
|
|
mbuf_Free(bp);
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
|
1997-10-26 01:04:02 +00:00
|
|
|
static void
|
1998-05-21 21:49:08 +00:00
|
|
|
FsmRecvTermReq(struct fsm *fp, struct fsmheader *lhp, struct mbuf *bp)
|
1997-08-25 00:29:32 +00:00
|
|
|
/* RTR */
|
1995-01-31 06:29:58 +00:00
|
|
|
{
|
|
|
|
switch (fp->state) {
|
1998-05-21 21:49:08 +00:00
|
|
|
case ST_INITIAL:
|
|
|
|
case ST_STARTING:
|
|
|
|
log_Printf(fp->LogLevel, "%s: Oops, RTR in %s\n",
|
|
|
|
fp->link->name, State2Nam(fp->state));
|
1995-01-31 06:29:58 +00:00
|
|
|
break;
|
|
|
|
case ST_CLOSED:
|
|
|
|
case ST_STOPPED:
|
|
|
|
case ST_CLOSING:
|
|
|
|
case ST_STOPPING:
|
|
|
|
case ST_REQSENT:
|
1998-05-21 21:49:08 +00:00
|
|
|
(*fp->fn->SendTerminateAck)(fp, lhp->id);
|
1995-01-31 06:29:58 +00:00
|
|
|
break;
|
|
|
|
case ST_ACKRCVD:
|
|
|
|
case ST_ACKSENT:
|
1998-05-21 21:49:08 +00:00
|
|
|
(*fp->fn->SendTerminateAck)(fp, lhp->id);
|
1995-01-31 06:29:58 +00:00
|
|
|
NewState(fp, ST_REQSENT);
|
|
|
|
break;
|
|
|
|
case ST_OPENED:
|
1998-05-21 21:49:08 +00:00
|
|
|
(*fp->fn->LayerDown)(fp);
|
|
|
|
(*fp->fn->SendTerminateAck)(fp, lhp->id);
|
|
|
|
timer_Start(&fp->FsmTimer); /* Start restart timer */
|
1997-06-02 00:04:40 +00:00
|
|
|
fp->restart = 0;
|
|
|
|
NewState(fp, ST_STOPPING);
|
1998-05-21 21:49:08 +00:00
|
|
|
(*fp->parent->LayerDown)(fp->parent->object, fp);
|
1995-01-31 06:29:58 +00:00
|
|
|
break;
|
|
|
|
}
|
1998-05-21 21:49:08 +00:00
|
|
|
mbuf_Free(bp);
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
|
1997-10-26 01:04:02 +00:00
|
|
|
static void
|
1997-08-25 00:29:32 +00:00
|
|
|
FsmRecvTermAck(struct fsm * fp, struct fsmheader * lhp, struct mbuf * bp)
|
|
|
|
/* RTA */
|
1995-01-31 06:29:58 +00:00
|
|
|
{
|
|
|
|
switch (fp->state) {
|
1998-05-21 21:49:08 +00:00
|
|
|
case ST_CLOSING:
|
|
|
|
(*fp->fn->LayerFinish)(fp);
|
1995-01-31 06:29:58 +00:00
|
|
|
NewState(fp, ST_CLOSED);
|
1998-05-21 21:49:08 +00:00
|
|
|
(*fp->parent->LayerFinish)(fp->parent->object, fp);
|
1995-01-31 06:29:58 +00:00
|
|
|
break;
|
|
|
|
case ST_STOPPING:
|
1998-05-21 21:49:08 +00:00
|
|
|
(*fp->fn->LayerFinish)(fp);
|
1995-01-31 06:29:58 +00:00
|
|
|
NewState(fp, ST_STOPPED);
|
1998-05-21 21:49:08 +00:00
|
|
|
(*fp->parent->LayerFinish)(fp->parent->object, fp);
|
1995-01-31 06:29:58 +00:00
|
|
|
break;
|
|
|
|
case ST_ACKRCVD:
|
|
|
|
NewState(fp, ST_REQSENT);
|
|
|
|
break;
|
|
|
|
case ST_OPENED:
|
1998-05-21 21:49:08 +00:00
|
|
|
(*fp->fn->LayerDown)(fp);
|
1995-01-31 06:29:58 +00:00
|
|
|
FsmSendConfigReq(fp);
|
|
|
|
NewState(fp, ST_REQSENT);
|
1998-05-21 21:49:08 +00:00
|
|
|
(*fp->parent->LayerDown)(fp->parent->object, fp);
|
1995-01-31 06:29:58 +00:00
|
|
|
break;
|
|
|
|
}
|
1998-05-21 21:49:08 +00:00
|
|
|
mbuf_Free(bp);
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
|
1997-10-26 01:04:02 +00:00
|
|
|
static void
|
1998-05-21 21:49:08 +00:00
|
|
|
FsmRecvConfigRej(struct fsm *fp, struct fsmheader *lhp, struct mbuf *bp)
|
1997-08-25 00:29:32 +00:00
|
|
|
/* RCJ */
|
1995-01-31 06:29:58 +00:00
|
|
|
{
|
1998-05-21 21:49:08 +00:00
|
|
|
struct fsm_decode dec;
|
1995-02-26 12:18:08 +00:00
|
|
|
int plen, flen;
|
1995-05-30 03:57:47 +00:00
|
|
|
|
1998-05-21 21:49:08 +00:00
|
|
|
plen = mbuf_Length(bp);
|
1997-12-24 09:29:17 +00:00
|
|
|
flen = ntohs(lhp->length) - sizeof *lhp;
|
1995-02-26 12:18:08 +00:00
|
|
|
if (plen < flen) {
|
1998-05-21 21:49:08 +00:00
|
|
|
mbuf_Free(bp);
|
1995-01-31 06:29:58 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
1997-08-25 00:29:32 +00:00
|
|
|
* Check and process easy case
|
1995-01-31 06:29:58 +00:00
|
|
|
*/
|
|
|
|
switch (fp->state) {
|
|
|
|
case ST_INITIAL:
|
|
|
|
case ST_STARTING:
|
1998-05-21 21:49:08 +00:00
|
|
|
log_Printf(fp->LogLevel, "%s: Oops, RCJ in %s.\n",
|
|
|
|
fp->link->name, State2Nam(fp->state));
|
|
|
|
mbuf_Free(bp);
|
1995-01-31 06:29:58 +00:00
|
|
|
return;
|
|
|
|
case ST_CLOSED:
|
|
|
|
case ST_STOPPED:
|
1998-05-21 21:49:08 +00:00
|
|
|
(*fp->fn->SendTerminateAck)(fp, lhp->id);
|
|
|
|
mbuf_Free(bp);
|
1995-01-31 06:29:58 +00:00
|
|
|
return;
|
|
|
|
case ST_CLOSING:
|
|
|
|
case ST_STOPPING:
|
1998-05-21 21:49:08 +00:00
|
|
|
mbuf_Free(bp);
|
1995-01-31 06:29:58 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
1998-05-21 21:49:08 +00:00
|
|
|
dec.ackend = dec.ack;
|
|
|
|
dec.nakend = dec.nak;
|
|
|
|
dec.rejend = dec.rej;
|
|
|
|
(*fp->fn->DecodeConfig)(fp, MBUF_CTOP(bp), flen, MODE_REJ, &dec);
|
|
|
|
if (flen < sizeof(struct fsmconfig))
|
|
|
|
log_Printf(fp->LogLevel, " [EMPTY]\n");
|
1995-01-31 06:29:58 +00:00
|
|
|
|
|
|
|
switch (fp->state) {
|
|
|
|
case ST_REQSENT:
|
|
|
|
case ST_ACKSENT:
|
|
|
|
FsmInitRestartCounter(fp);
|
|
|
|
FsmSendConfigReq(fp);
|
|
|
|
break;
|
|
|
|
case ST_OPENED:
|
1998-05-21 21:49:08 +00:00
|
|
|
(*fp->fn->LayerDown)(fp);
|
|
|
|
FsmSendConfigReq(fp);
|
|
|
|
NewState(fp, ST_REQSENT);
|
|
|
|
(*fp->parent->LayerDown)(fp->parent->object, fp);
|
|
|
|
break;
|
1995-01-31 06:29:58 +00:00
|
|
|
case ST_ACKRCVD:
|
|
|
|
FsmSendConfigReq(fp);
|
|
|
|
NewState(fp, ST_REQSENT);
|
|
|
|
break;
|
|
|
|
}
|
1998-05-21 21:49:08 +00:00
|
|
|
mbuf_Free(bp);
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
|
1997-10-26 01:04:02 +00:00
|
|
|
static void
|
1998-05-21 21:49:08 +00:00
|
|
|
FsmRecvCodeRej(struct fsm *fp, struct fsmheader *lhp, struct mbuf *bp)
|
1995-01-31 06:29:58 +00:00
|
|
|
{
|
1998-05-21 21:49:08 +00:00
|
|
|
mbuf_Free(bp);
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
|
1997-10-26 01:04:02 +00:00
|
|
|
static void
|
1998-05-21 21:49:08 +00:00
|
|
|
FsmRecvProtoRej(struct fsm *fp, struct fsmheader *lhp, struct mbuf *bp)
|
1995-01-31 06:29:58 +00:00
|
|
|
{
|
1998-05-21 21:49:08 +00:00
|
|
|
struct physical *p = link2physical(fp->link);
|
1995-01-31 06:29:58 +00:00
|
|
|
u_short *sp, proto;
|
|
|
|
|
1997-08-25 00:29:32 +00:00
|
|
|
sp = (u_short *) MBUF_CTOP(bp);
|
1995-01-31 06:29:58 +00:00
|
|
|
proto = ntohs(*sp);
|
1998-05-21 21:49:08 +00:00
|
|
|
log_Printf(fp->LogLevel, "%s: -- Protocol 0x%04x (%s) was rejected!\n",
|
|
|
|
fp->link->name, proto, hdlc_Protocol2Nam(proto));
|
1995-01-31 06:29:58 +00:00
|
|
|
|
|
|
|
switch (proto) {
|
|
|
|
case PROTO_LQR:
|
1998-05-21 21:49:08 +00:00
|
|
|
if (p)
|
|
|
|
lqr_Stop(p, LQM_LQR);
|
|
|
|
else
|
|
|
|
log_Printf(LogERROR, "%s: FsmRecvProtoRej: Not a physical link !\n",
|
|
|
|
fp->link->name);
|
1995-01-31 06:29:58 +00:00
|
|
|
break;
|
|
|
|
case PROTO_CCP:
|
1998-05-21 21:49:08 +00:00
|
|
|
if (fp->proto == PROTO_LCP) {
|
|
|
|
fp = &fp->link->ccp.fsm;
|
|
|
|
(*fp->fn->LayerFinish)(fp);
|
|
|
|
switch (fp->state) {
|
|
|
|
case ST_CLOSED:
|
|
|
|
case ST_CLOSING:
|
|
|
|
NewState(fp, ST_CLOSED);
|
|
|
|
default:
|
|
|
|
NewState(fp, ST_STOPPED);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
(*fp->parent->LayerFinish)(fp->parent->object, fp);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case PROTO_MP:
|
|
|
|
if (fp->proto == PROTO_LCP) {
|
|
|
|
struct lcp *lcp = fsm2lcp(fp);
|
|
|
|
|
|
|
|
if (lcp->want_mrru && lcp->his_mrru) {
|
|
|
|
log_Printf(LogPHASE, "%s: MP protocol reject is fatal !\n",
|
|
|
|
fp->link->name);
|
|
|
|
fsm_Close(fp);
|
|
|
|
}
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
1998-05-21 21:49:08 +00:00
|
|
|
mbuf_Free(bp);
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
|
1997-10-26 01:04:02 +00:00
|
|
|
static void
|
1998-05-21 21:49:08 +00:00
|
|
|
FsmRecvEchoReq(struct fsm *fp, struct fsmheader *lhp, struct mbuf *bp)
|
1995-01-31 06:29:58 +00:00
|
|
|
{
|
1998-05-21 21:49:08 +00:00
|
|
|
struct lcp *lcp = fsm2lcp(fp);
|
1995-01-31 06:29:58 +00:00
|
|
|
u_char *cp;
|
1998-05-21 21:49:08 +00:00
|
|
|
u_int32_t magic;
|
|
|
|
|
|
|
|
if (lcp) {
|
|
|
|
cp = MBUF_CTOP(bp);
|
|
|
|
magic = ntohl(*(u_int32_t *)cp);
|
|
|
|
if (magic != lcp->his_magic) {
|
|
|
|
log_Printf(fp->LogLevel, "%s: RecvEchoReq: Error: His magic is bad!!\n",
|
|
|
|
fp->link->name);
|
|
|
|
/* XXX: We should send terminate request */
|
|
|
|
}
|
|
|
|
if (fp->state == ST_OPENED) {
|
|
|
|
*(u_int32_t *)cp = htonl(lcp->want_magic); /* local magic */
|
|
|
|
fsm_Output(fp, CODE_ECHOREP, lhp->id, cp, mbuf_Length(bp));
|
|
|
|
}
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
1998-05-21 21:49:08 +00:00
|
|
|
mbuf_Free(bp);
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
|
1997-10-26 01:04:02 +00:00
|
|
|
static void
|
1998-05-21 21:49:08 +00:00
|
|
|
FsmRecvEchoRep(struct fsm *fp, struct fsmheader *lhp, struct mbuf *bp)
|
|
|
|
{
|
|
|
|
struct lcp *lcp = fsm2lcp(fp);
|
|
|
|
u_int32_t magic;
|
|
|
|
|
|
|
|
if (lcp) {
|
|
|
|
magic = ntohl(*(u_int32_t *)MBUF_CTOP(bp));
|
|
|
|
/* Tolerate echo replies with either magic number */
|
|
|
|
if (magic != 0 && magic != lcp->his_magic && magic != lcp->want_magic) {
|
|
|
|
log_Printf(LogWARN,
|
|
|
|
"%s: RecvEchoRep: Bad magic: expected 0x%08x, got: 0x%08x\n",
|
|
|
|
fp->link->name, lcp->his_magic, magic);
|
|
|
|
/*
|
|
|
|
* XXX: We should send terminate request. But poor implementations may
|
|
|
|
* die as a result.
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
lqr_RecvEcho(fp, bp);
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
1998-05-21 21:49:08 +00:00
|
|
|
mbuf_Free(bp);
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
|
1997-10-26 01:04:02 +00:00
|
|
|
static void
|
1997-08-25 00:29:32 +00:00
|
|
|
FsmRecvDiscReq(struct fsm * fp, struct fsmheader * lhp, struct mbuf * bp)
|
1995-01-31 06:29:58 +00:00
|
|
|
{
|
1998-05-21 21:49:08 +00:00
|
|
|
mbuf_Free(bp);
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
|
1997-10-26 01:04:02 +00:00
|
|
|
static void
|
1997-08-25 00:29:32 +00:00
|
|
|
FsmRecvIdent(struct fsm * fp, struct fsmheader * lhp, struct mbuf * bp)
|
1995-01-31 06:29:58 +00:00
|
|
|
{
|
1998-05-21 21:49:08 +00:00
|
|
|
mbuf_Free(bp);
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
|
1997-10-26 01:04:02 +00:00
|
|
|
static void
|
1997-08-25 00:29:32 +00:00
|
|
|
FsmRecvTimeRemain(struct fsm * fp, struct fsmheader * lhp, struct mbuf * bp)
|
1995-01-31 06:29:58 +00:00
|
|
|
{
|
1998-05-21 21:49:08 +00:00
|
|
|
mbuf_Free(bp);
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
|
1997-10-26 01:04:02 +00:00
|
|
|
static void
|
1998-05-21 21:49:08 +00:00
|
|
|
FsmRecvResetReq(struct fsm *fp, struct fsmheader *lhp, struct mbuf *bp)
|
1995-01-31 06:29:58 +00:00
|
|
|
{
|
1998-05-21 21:49:08 +00:00
|
|
|
(*fp->fn->RecvResetReq)(fp);
|
Implement Reset{Req,Ack} properly, as per rfc 1962.
(I completely mis-read the rfc last time 'round!)
This means:
o Better CCP/WARN Reset diagnostics.
o After we've sent a REQ and before we've received an ACK, we drop
incoming compressed data and send another REQ.
o Before sending an ACK, re-sequence all pending PRI_NORMAL data in
the modem queue so that pending packets won't get to the peer
*after* the ResetAck.
o Send ACKs with the `identifier' from the REQ frame.
o After we've received a correct ACK, duplicate ACKs are ok (and will
reset our history).
o Incorrect ACKs (not matching the last REQ) are moaned about and dropped.
Also,
o Calculate the correct FCS after compressing a packet. DEFLATE
*may* produce an mbuf with more than a single link in the chain,
but HdlcOutput didn't know how to calculate the FCS :-(
o Make `struct fsm'::reqid a u_char, not an int.
This fix will prevent us from sending id `255' 2,000,000,000 times
before wrapping to `0' for another 2,000,000,000 sends :-/
o Bump the version number a little.
The end result: DEFLATE now works over an unreliable link layer.
I can txfr a 1.5Mb kernel over a (rather bad) null-modem
cable at an average of 21679 bytes per second using rcp.
Repeat after me: Don't test compression using a loopback ppp/tcp setup as
we never lose packets and therefore never have to reset!
1998-01-10 01:55:11 +00:00
|
|
|
/*
|
|
|
|
* All sendable compressed packets are queued in the PRI_NORMAL modem
|
|
|
|
* output queue.... dump 'em to the priority queue so that they arrive
|
|
|
|
* at the peer before our ResetAck.
|
|
|
|
*/
|
1998-05-21 21:49:08 +00:00
|
|
|
link_SequenceQueue(fp->link);
|
|
|
|
fsm_Output(fp, CODE_RESETACK, lhp->id, NULL, 0);
|
|
|
|
mbuf_Free(bp);
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
|
1997-10-26 01:04:02 +00:00
|
|
|
static void
|
1998-05-21 21:49:08 +00:00
|
|
|
FsmRecvResetAck(struct fsm *fp, struct fsmheader *lhp, struct mbuf *bp)
|
|
|
|
{
|
|
|
|
(*fp->fn->RecvResetAck)(fp, lhp->id);
|
|
|
|
mbuf_Free(bp);
|
|
|
|
}
|
1995-01-31 06:29:58 +00:00
|
|
|
|
|
|
|
void
|
1998-05-21 21:49:08 +00:00
|
|
|
fsm_Input(struct fsm *fp, struct mbuf *bp)
|
1995-01-31 06:29:58 +00:00
|
|
|
{
|
|
|
|
int len;
|
|
|
|
struct fsmheader *lhp;
|
1997-12-03 10:23:54 +00:00
|
|
|
const struct fsmcodedesc *codep;
|
1995-01-31 06:29:58 +00:00
|
|
|
|
1998-05-21 21:49:08 +00:00
|
|
|
len = mbuf_Length(bp);
|
1995-01-31 06:29:58 +00:00
|
|
|
if (len < sizeof(struct fsmheader)) {
|
1998-05-21 21:49:08 +00:00
|
|
|
mbuf_Free(bp);
|
1995-01-31 06:29:58 +00:00
|
|
|
return;
|
|
|
|
}
|
1997-08-25 00:29:32 +00:00
|
|
|
lhp = (struct fsmheader *) MBUF_CTOP(bp);
|
1998-05-21 21:49:08 +00:00
|
|
|
if (lhp->code < fp->min_code || lhp->code > fp->max_code ||
|
|
|
|
lhp->code > sizeof FsmCodes / sizeof *FsmCodes) {
|
|
|
|
/*
|
|
|
|
* Use a private id. This is really a response-type packet, but we
|
|
|
|
* MUST send a unique id for each REQ....
|
|
|
|
*/
|
|
|
|
static u_char id;
|
1998-06-15 19:06:58 +00:00
|
|
|
|
1998-05-21 21:49:08 +00:00
|
|
|
fsm_Output(fp, CODE_CODEREJ, id++, MBUF_CTOP(bp), bp->cnt);
|
|
|
|
mbuf_Free(bp);
|
1995-01-31 06:29:58 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
bp->offset += sizeof(struct fsmheader);
|
|
|
|
bp->cnt -= sizeof(struct fsmheader);
|
|
|
|
|
|
|
|
codep = FsmCodes + lhp->code - 1;
|
1998-05-21 21:49:08 +00:00
|
|
|
if (lhp->id != fp->reqid && codep->check_reqid &&
|
|
|
|
Enabled(fp->bundle, OPT_IDCHECK)) {
|
|
|
|
log_Printf(fp->LogLevel, "%s: Recv%s(%d), dropped (expected %d)\n",
|
|
|
|
fp->link->name, codep->name, lhp->id, fp->reqid);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
log_Printf(fp->LogLevel, "%s: Recv%s(%d) state = %s\n",
|
|
|
|
fp->link->name, codep->name, lhp->id, State2Nam(fp->state));
|
|
|
|
|
|
|
|
if (log_IsKept(LogDEBUG))
|
|
|
|
mbuf_Log();
|
|
|
|
|
|
|
|
if (codep->inc_reqid && (lhp->id == fp->reqid ||
|
|
|
|
(!Enabled(fp->bundle, OPT_IDCHECK) && codep->check_reqid)))
|
|
|
|
fp->reqid++; /* That's the end of that ``exchange''.... */
|
|
|
|
|
|
|
|
(*codep->recv)(fp, lhp, bp);
|
|
|
|
|
|
|
|
if (log_IsKept(LogDEBUG))
|
|
|
|
mbuf_Log();
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
fsm_NullRecvResetReq(struct fsm *fp)
|
|
|
|
{
|
|
|
|
log_Printf(fp->LogLevel, "%s: Oops - received unexpected reset req\n",
|
|
|
|
fp->link->name);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
fsm_NullRecvResetAck(struct fsm *fp, u_char id)
|
|
|
|
{
|
|
|
|
log_Printf(fp->LogLevel, "%s: Oops - received unexpected reset ack\n",
|
|
|
|
fp->link->name);
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|