Create struct fsm_parent. FSMs are created with one of these,

and the FSM passes subsequent events to them.

The datalink now hides its CCP from the bundle layer.
This commit is contained in:
Brian Somers 1998-02-27 01:22:39 +00:00
parent 486f40c95c
commit 6d6667755e
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/cvs2svn/branches/MP/; revision=33858
17 changed files with 231 additions and 242 deletions

View File

@ -17,7 +17,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* $Id: arp.c,v 1.27.2.3 1998/02/08 11:04:37 brian Exp $
* $Id: arp.c,v 1.27.2.4 1998/02/21 01:44:55 brian Exp $
*
*/
@ -51,9 +51,9 @@
#include "log.h"
#include "id.h"
#include "route.h"
#include "bundle.h"
#include "timer.h"
#include "fsm.h"
#include "bundle.h"
#include "throughput.h"
#include "defs.h"
#include "iplist.h"

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.15 1998/02/21 01:44:58 brian Exp $
* $Id: bundle.c,v 1.1.2.16 1998/02/23 00:38:16 brian Exp $
*/
#include <sys/param.h>
@ -92,8 +92,6 @@ bundle_PhaseName(struct bundle *bundle)
void
bundle_NewPhase(struct bundle *bundle, struct physical *physical, u_int new)
{
struct datalink *dl;
if (new == bundle->phase)
return;
@ -129,14 +127,8 @@ bundle_NewPhase(struct bundle *bundle, struct physical *physical, u_int new)
case PHASE_NETWORK:
tun_configure(bundle, LcpInfo.his_mru, modem_Speed(physical));
ipcp_Setup(&IpcpInfo);
IpcpUp();
IpcpOpen();
/* XXX: The datalink should be doing this ... */
for (dl = bundle->links; dl; dl = dl->next)
if (dl->state == DATALINK_OPEN) {
CcpUp(&dl->ccp);
CcpOpen(&dl->ccp);
}
FsmUp(&IpcpInfo.fsm);
FsmOpen(&IpcpInfo.fsm);
/* Fall through */
case PHASE_TERMINATE:
@ -188,23 +180,27 @@ bundle_CleanInterface(const struct bundle *bundle)
return 1;
}
void
bundle_LayerStart(struct bundle *bundle, struct fsm *fp)
static void
bundle_LayerStart(void *v, struct fsm *fp)
{
/* The given FSM is about to start up ! */
struct bundle *bundle = (struct bundle *)v;
if (fp == &LcpInfo.fsm)
bundle_NewPhase(bundle, link2physical(fp->link), PHASE_ESTABLISH);
}
void
bundle_LayerUp(struct bundle *bundle, struct fsm *fp)
static void
bundle_LayerUp(void *v, struct fsm *fp)
{
/*
* The given fsm is now up
* If it's an lcp, tell the datalink
* If it's the first datalink, bring all NCPs up.
* If it's a datalink, authenticate.
* If it's an NCP, tell our background mode parent to go away.
*/
struct bundle *bundle = (struct bundle *)v;
if (fp == &LcpInfo.fsm)
bundle_NewPhase(bundle, link2physical(fp->link), PHASE_AUTHENTICATE);
@ -221,6 +217,40 @@ bundle_LayerUp(struct bundle *bundle, struct fsm *fp)
}
}
static void
bundle_LayerDown(void *v, struct fsm *fp)
{
/*
* The given FSM has been told to come down.
* We don't do anything here, as the FSM will eventually
* come up or down and will call LayerUp or LayerFinish.
*/
}
static void
bundle_LayerFinish(void *v, struct fsm *fp)
{
/* The given fsm is now down (fp cannot be NULL)
*
* If it's the last LCP, FsmDown all NCPs
* If it's the last NCP, FsmClose all LCPs and enter TERMINATE phase.
*/
struct bundle *bundle = (struct bundle *)v;
if (fp == &LcpInfo.fsm) {
FsmDown(&IpcpInfo.fsm); /* You've lost your underlings */
FsmClose(&IpcpInfo.fsm); /* ST_INITIAL please */
} else if (fp == &IpcpInfo.fsm) {
struct datalink *dl;
bundle_NewPhase(bundle, NULL, PHASE_TERMINATE);
for (dl = bundle->links; dl; dl = dl->next)
datalink_Close(dl, 1);
}
}
int
bundle_LinkIsUp(const struct bundle *bundle)
{
@ -355,15 +385,25 @@ bundle_Create(const char *prefix)
bundle.routing_seq = 0;
bundle.phase = 0;
/* Clean out any leftover crud */
bundle_CleanInterface(&bundle);
bundle.fsm.LayerStart = bundle_LayerStart;
bundle.fsm.LayerUp = bundle_LayerUp;
bundle.fsm.LayerDown = bundle_LayerDown;
bundle.fsm.LayerFinish = bundle_LayerFinish;
bundle.fsm.object = &bundle;
bundle.links = datalink_Create("Modem", &bundle);
bundle.links = datalink_Create("Modem", &bundle, &bundle.fsm);
if (bundle.links == NULL) {
LogPrintf(LogERROR, "Cannot create data link: %s\n", strerror(errno));
close(bundle.tun_fd);
bundle.ifname = NULL;
return NULL;
}
ipcp_Init(&IpcpInfo, &bundle, &bundle.links->physical->link, &bundle.fsm);
/* Clean out any leftover crud */
bundle_CleanInterface(&bundle);
return &bundle;
}
@ -577,55 +617,6 @@ bundle_LinkClosed(struct bundle *bundle, struct datalink *dl)
}
void
bundle_LayerDown(struct bundle *bundle, struct fsm *fp)
{
/*
* The given FSM has been told to come down.
* We don't do anything here, as the FSM will eventually
* come up or down and will call LayerUp or LayerFinish.
*/
}
void
bundle_LayerFinish(struct bundle *bundle, struct fsm *fp)
{
/* The given fsm is now down (fp cannot be NULL)
*
* If it's a CCP, just bring it back to STARTING in case we get more REQs
*
* If it's an LCP, FsmDown the corresponding CCP and Close the link if
* it's open. The link_Close causes the LCP to be FsmDown()d,
* via bundle_LinkLost() causing re-entry.
*
* If it's the last LCP, FsmDown all NCPs
*
* If it's the last NCP, FsmClose all LCPs and enter TERMINATE phase.
*/
if (fp->proto == PROTO_CCP) {
FsmDown(fp);
FsmOpen(fp);
} else if (fp == &LcpInfo.fsm) {
/* XXX fix me */
FsmDown(&bundle->links->ccp.fsm);
FsmDown(&IpcpInfo.fsm); /* You've lost your underlings */
FsmClose(&IpcpInfo.fsm); /* ST_INITIAL please */
if (link_IsActive(fp->link))
link_Close(fp->link, bundle, 0, 0); /* clean shutdown */
/* And wait for the LinkLost() */
} else if (fp == &IpcpInfo.fsm) {
struct datalink *dl;
bundle_NewPhase(bundle, NULL, PHASE_TERMINATE);
for (dl = bundle->links; dl; dl = dl->next)
datalink_Close(dl, 1);
}
}
void
bundle_Open(struct bundle *bundle, const char *name)
{

View File

@ -23,7 +23,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: bundle.h,v 1.1.2.9 1998/02/17 19:27:49 brian Exp $
* $Id: bundle.h,v 1.1.2.10 1998/02/21 01:44:59 brian Exp $
*/
#define PHASE_DEAD 0 /* Link is dead */
@ -35,7 +35,6 @@
struct datalink;
struct physical;
struct link;
struct fsm;
struct bundle {
int unit; /* The tun number */
@ -46,6 +45,7 @@ struct bundle {
int routing_seq; /* The current routing sequence number */
u_int phase; /* Curent phase */
struct fsm_parent fsm; /* Our callback functions */
struct datalink *links; /* Our data links */
};
@ -54,16 +54,12 @@ extern void bundle_Destroy(struct bundle *);
extern const char *bundle_PhaseName(struct bundle *);
#define bundle_Phase(b) ((b)->phase)
extern void bundle_NewPhase(struct bundle *, struct physical *, u_int);
extern void bundle_LayerStart(struct bundle *, struct fsm *);
extern void bundle_LayerUp(struct bundle *, struct fsm *);
extern int bundle_LinkIsUp(const struct bundle *);
extern void bundle_SetRoute(struct bundle *, int, struct in_addr,
struct in_addr, struct in_addr, int);
extern void bundle_LinkLost(struct bundle *, struct link *, int);
extern void bundle_Close(struct bundle *, const char *, int);
extern void bundle_Open(struct bundle *, const char *name);
extern void bundle_LayerDown(struct bundle *, struct fsm *);
extern void bundle_LayerFinish(struct bundle *, struct fsm *);
extern void bundle_LinkClosed(struct bundle *, struct datalink *);
extern int bundle_UpdateSet(struct bundle *, fd_set *, fd_set *, fd_set *,

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.13 1998/02/23 00:38:17 brian Exp $
* $Id: ccp.c,v 1.30.2.14 1998/02/24 03:36:45 brian Exp $
*
* TODO:
* o Support other compression protocols
@ -64,12 +64,10 @@ static void CcpRecvResetReq(struct fsm *);
static void CcpRecvResetAck(struct fsm *, u_char);
static struct fsm_callbacks ccp_Callbacks = {
{
CcpLayerUp,
CcpLayerDown,
CcpLayerStart,
CcpLayerFinish
},
CcpLayerUp,
CcpLayerDown,
CcpLayerStart,
CcpLayerFinish,
CcpInitRestartCounter,
CcpSendConfigReq,
CcpSendTerminateReq,
@ -136,11 +134,12 @@ ccp_ReportStatus(struct cmdargs const *arg)
}
void
ccp_Init(struct ccp *ccp, struct bundle *bundle, struct link *l)
ccp_Init(struct ccp *ccp, struct bundle *bundle, struct link *l,
const struct fsm_parent *parent)
{
/* Initialise ourselves */
fsm_Init(&ccp->fsm, "CCP", PROTO_CCP, CCP_MAXCODE, 10, LogCCP,
bundle, l, &ccp_Callbacks);
bundle, l, parent, &ccp_Callbacks);
ccp_Setup(ccp);
}
@ -289,36 +288,6 @@ CcpLayerUp(struct fsm *fp)
protoname(ccp->his_proto), ccp->his_proto);
}
void
CcpUp(struct ccp *ccp)
{
/* Lower layers are ready.... go */
LogPrintf(LogCCP, "CCP Up event!!\n");
FsmUp(&ccp->fsm);
}
void
CcpOpen(struct ccp *ccp)
{
/* Start CCP please */
int f;
for (f = 0; f < NALGORITHMS; f++)
if (Enabled(algorithm[f]->Conf)) {
ccp->fsm.open_mode = 0;
FsmOpen(&ccp->fsm);
break;
}
if (f == NALGORITHMS)
for (f = 0; f < NALGORITHMS; f++)
if (Acceptable(algorithm[f]->Conf)) {
ccp->fsm.open_mode = OPEN_PASSIVE;
FsmOpen(&ccp->fsm);
break;
}
}
static void
CcpDecodeConfig(struct fsm *fp, u_char *cp, int plen, int mode_type)
{

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.10 1998/02/21 01:45:03 brian Exp $
* $Id: ccp.h,v 1.14.2.11 1998/02/23 00:38:19 brian Exp $
*
* TODO:
*/
@ -82,13 +82,12 @@ struct ccp_algorithm {
} o;
};
extern void ccp_Init(struct ccp *, struct bundle *, struct link *);
extern void ccp_Init(struct ccp *, struct bundle *, struct link *,
const struct fsm_parent *);
extern void ccp_Setup(struct ccp *);
extern void CcpSendResetReq(struct fsm *);
extern void CcpInput(struct ccp *, struct bundle *, struct mbuf *);
extern void CcpUp(struct ccp *);
extern void CcpOpen(struct ccp *);
extern int ccp_ReportStatus(struct cmdargs const *);
extern int ccp_Output(struct ccp *, struct link *, int, u_short, struct mbuf *);
extern struct mbuf *ccp_Decompress(struct ccp *, u_short *, struct mbuf *);

View File

@ -23,7 +23,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: datalink.c,v 1.1.2.13 1998/02/23 00:38:26 brian Exp $
* $Id: datalink.c,v 1.1.2.14 1998/02/26 17:53:15 brian Exp $
*/
#include <sys/param.h>
@ -313,8 +313,57 @@ datalink_Write(struct descriptor *d, struct bundle *bundle, const fd_set *fdset)
}
}
static void
datalink_LayerStart(void *v, struct fsm *fp)
{
/* The given FSM is about to start up ! */
struct datalink *dl = (struct datalink *)v;
return (*dl->parent->LayerStart)(dl->parent->object, fp);
}
static void
datalink_LayerUp(void *v, struct fsm *fp)
{
/* The given fsm is now up */
struct datalink *dl = (struct datalink *)v;
if (fp == &LcpInfo.fsm) {
(*dl->parent->LayerUp)(dl->parent->object, fp);
FsmUp(&dl->ccp.fsm);
FsmOpen(&dl->ccp.fsm);
}
}
static void
datalink_LayerDown(void *v, struct fsm *fp)
{
/* The given FSM has been told to come down */
struct datalink *dl = (struct datalink *)v;
if (fp == &LcpInfo.fsm) {
FsmDown(fp);
FsmClose(fp);
}
return (*dl->parent->LayerDown)(dl->parent->object, fp);
}
static void
datalink_LayerFinish(void *v, struct fsm *fp)
{
/* The given fsm is now down */
struct datalink *dl = (struct datalink *)v;
if (fp == &LcpInfo.fsm) {
(*dl->parent->LayerFinish)(dl->parent->object, fp);
if (link_IsActive(fp->link))
link_Close(fp->link, dl->bundle, 0, 0); /* clean shutdown */
/* And wait for the LinkLost() */
}
}
struct datalink *
datalink_Create(const char *name, struct bundle *bundle)
datalink_Create(const char *name, struct bundle *bundle,
const struct fsm_parent *parent)
{
struct datalink *dl;
@ -359,9 +408,15 @@ datalink_Create(const char *name, struct bundle *bundle)
}
chat_Init(&dl->chat, dl->physical, NULL, 1);
ipcp_Init(&IpcpInfo, dl->bundle, &dl->physical->link);
lcp_Init(&LcpInfo, dl->bundle, dl->physical);
ccp_Init(&dl->ccp, dl->bundle, &dl->physical->link);
dl->parent = parent;
dl->fsm.LayerStart = datalink_LayerStart;
dl->fsm.LayerUp = datalink_LayerUp;
dl->fsm.LayerDown = datalink_LayerDown;
dl->fsm.LayerFinish = datalink_LayerFinish;
dl->fsm.object = dl;
lcp_Init(&LcpInfo, dl->bundle, dl->physical, &dl->fsm);
ccp_Init(&dl->ccp, dl->bundle, &dl->physical->link, &dl->fsm);
LogPrintf(LogPHASE, "%s: Created in CLOSED state\n", dl->name);

View File

@ -23,7 +23,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: datalink.h,v 1.1.2.7 1998/02/17 19:28:46 brian Exp $
* $Id: datalink.h,v 1.1.2.8 1998/02/23 00:38:27 brian Exp $
*/
#define DATALINK_CLOSED (0)
@ -66,20 +66,23 @@ struct datalink {
char *name; /* Our name */
struct fsm_parent fsm; /* Our callback functions */
const struct fsm_parent *parent; /* Our parent */
#ifdef soon
struct lcp lcp; /* Our line control FSM */
struct lcp lcp; /* Our line control FSM */
#endif
struct ccp ccp; /* Our compression FSM */
struct ccp ccp; /* Our compression FSM */
struct bundle *bundle; /* for the moment */
struct datalink *next; /* Next in the list */
struct bundle *bundle; /* for the moment */
struct datalink *next; /* Next in the list */
};
#define datalink2descriptor(dl) (&(dl)->desc)
#define descriptor2datalink(d) \
((d)->type == DATALINK_DESCRIPTOR ? (struct datalink *)(d) : NULL)
extern struct datalink *datalink_Create(const char *name, struct bundle *);
extern struct datalink *datalink_Create(const char *name, struct bundle *,
const struct fsm_parent *);
extern struct datalink *datalink_Destroy(struct datalink *);
extern void datalink_Up(struct datalink *, int, int);
extern void datalink_Close(struct datalink *, int);

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.14 1998/02/23 00:38:29 brian Exp $
* $Id: fsm.c,v 1.27.2.15 1998/02/24 03:36:46 brian Exp $
*
* TODO:
* o Refer loglevel for log output
@ -86,7 +86,7 @@ StoppedTimeout(void *v)
void
fsm_Init(struct fsm *fp, const char *name, u_short proto, int maxcode,
int maxcfg, int LogLevel, struct bundle *bundle, struct link *l,
struct fsm_callbacks *fn)
const struct fsm_parent *parent, struct fsm_callbacks *fn)
{
fp->name = name;
fp->proto = proto;
@ -101,6 +101,7 @@ fsm_Init(struct fsm *fp, const char *name, u_short proto, int maxcode,
fp->LogLevel = LogLevel;
fp->link = l;
fp->bundle = bundle;
fp->parent = parent;
fp->fn = fn;
}
@ -161,8 +162,8 @@ FsmOpen(struct fsm * fp)
switch (fp->state) {
case ST_INITIAL:
NewState(fp, ST_STARTING);
(*fp->fn->notify.LayerStart)(fp);
bundle_LayerStart(fp->bundle, fp);
(*fp->fn->LayerStart)(fp);
(*fp->parent->LayerStart)(fp->parent->object, fp);
break;
case ST_CLOSED:
if (fp->open_mode == OPEN_PASSIVE) {
@ -219,14 +220,14 @@ FsmDown(struct fsm *fp)
NewState(fp, ST_INITIAL);
break;
case ST_CLOSING:
(*fp->fn->notify.LayerFinish)(fp);
(*fp->fn->LayerFinish)(fp);
NewState(fp, ST_INITIAL);
bundle_LayerFinish(fp->bundle, fp);
(*fp->parent->LayerFinish)(fp->parent->object, fp);
break;
case ST_STOPPED:
NewState(fp, ST_STARTING);
(*fp->fn->notify.LayerStart)(fp);
bundle_LayerStart(fp->bundle, fp);
(*fp->fn->LayerStart)(fp);
(*fp->parent->LayerStart)(fp->parent->object, fp);
break;
case ST_STOPPING:
case ST_REQSENT:
@ -235,9 +236,9 @@ FsmDown(struct fsm *fp)
NewState(fp, ST_STARTING);
break;
case ST_OPENED:
(*fp->fn->notify.LayerDown)(fp);
(*fp->fn->LayerDown)(fp);
NewState(fp, ST_STARTING);
bundle_LayerDown(fp->bundle, fp);
(*fp->parent->LayerDown)(fp->parent->object, fp);
break;
}
}
@ -247,9 +248,9 @@ FsmClose(struct fsm *fp)
{
switch (fp->state) {
case ST_STARTING:
(*fp->fn->notify.LayerFinish)(fp);
(*fp->fn->LayerFinish)(fp);
NewState(fp, ST_INITIAL);
bundle_LayerFinish(fp->bundle, fp);
(*fp->parent->LayerFinish)(fp->parent->object, fp);
break;
case ST_STOPPED:
NewState(fp, ST_CLOSED);
@ -258,11 +259,11 @@ FsmClose(struct fsm *fp)
NewState(fp, ST_CLOSING);
break;
case ST_OPENED:
(*fp->fn->notify.LayerDown)(fp);
(*fp->fn->LayerDown)(fp);
FsmInitRestartCounter(fp);
FsmSendTerminateReq(fp);
NewState(fp, ST_CLOSING);
bundle_LayerDown(fp->bundle, fp);
(*fp->parent->LayerDown)(fp->parent->object, fp);
break;
case ST_REQSENT:
case ST_ACKRCVD:
@ -353,21 +354,21 @@ FsmTimeout(void *v)
} else {
switch (fp->state) {
case ST_CLOSING:
(*fp->fn->notify.LayerFinish)(fp);
(*fp->fn->LayerFinish)(fp);
NewState(fp, ST_CLOSED);
bundle_LayerFinish(fp->bundle, fp);
(*fp->parent->LayerFinish)(fp->parent->object, fp);
break;
case ST_STOPPING:
(*fp->fn->notify.LayerFinish)(fp);
(*fp->fn->LayerFinish)(fp);
NewState(fp, ST_STOPPED);
bundle_LayerFinish(fp->bundle, fp);
(*fp->parent->LayerFinish)(fp->parent->object, fp);
break;
case ST_REQSENT: /* XXX: 3p */
case ST_ACKSENT:
case ST_ACKRCVD:
(*fp->fn->notify.LayerFinish)(fp);
(*fp->fn->LayerFinish)(fp);
NewState(fp, ST_STOPPED);
bundle_LayerFinish(fp->bundle, fp);
(*fp->parent->LayerFinish)(fp->parent->object, fp);
break;
}
}
@ -430,9 +431,9 @@ FsmRecvConfigReq(struct fsm *fp, struct fsmheader *lhp, struct mbuf *bp)
switch (fp->state) {
case ST_OPENED:
(*fp->fn->notify.LayerDown)(fp);
(*fp->fn->LayerDown)(fp);
FsmSendConfigReq(fp);
bundle_LayerDown(fp->bundle, fp);
(*fp->parent->LayerDown)(fp->parent->object, fp);
break;
case ST_STOPPED:
FsmInitRestartCounter(fp);
@ -462,8 +463,8 @@ FsmRecvConfigReq(struct fsm *fp, struct fsmheader *lhp, struct mbuf *bp)
case ST_ACKRCVD:
if (ackaction) {
NewState(fp, ST_OPENED);
(*fp->fn->notify.LayerUp)(fp);
bundle_LayerUp(fp->bundle, fp);
(*fp->fn->LayerUp)(fp);
(*fp->parent->LayerUp)(fp->parent->object, fp);
}
break;
case ST_ACKSENT:
@ -497,14 +498,14 @@ FsmRecvConfigAck(struct fsm * fp, struct fsmheader * lhp, struct mbuf * bp)
case ST_ACKSENT:
FsmInitRestartCounter(fp);
NewState(fp, ST_OPENED);
(*fp->fn->notify.LayerUp)(fp);
bundle_LayerUp(fp->bundle, fp);
(*fp->fn->LayerUp)(fp);
(*fp->parent->LayerUp)(fp->parent->object, fp);
break;
case ST_OPENED:
(*fp->fn->notify.LayerDown)(fp);
(*fp->fn->LayerDown)(fp);
FsmSendConfigReq(fp);
NewState(fp, ST_REQSENT);
bundle_LayerDown(fp->bundle, fp);
(*fp->parent->LayerDown)(fp->parent->object, fp);
break;
}
pfree(bp);
@ -552,10 +553,10 @@ FsmRecvConfigNak(struct fsm *fp, struct fsmheader *lhp, struct mbuf *bp)
FsmSendConfigReq(fp);
break;
case ST_OPENED:
(*fp->fn->notify.LayerDown)(fp);
(*fp->fn->LayerDown)(fp);
FsmSendConfigReq(fp);
NewState(fp, ST_REQSENT);
bundle_LayerDown(fp->bundle, fp);
(*fp->parent->LayerDown)(fp->parent->object, fp);
break;
case ST_ACKRCVD:
FsmSendConfigReq(fp);
@ -588,12 +589,12 @@ FsmRecvTermReq(struct fsm * fp, struct fsmheader * lhp, struct mbuf * bp)
NewState(fp, ST_REQSENT);
break;
case ST_OPENED:
(*fp->fn->notify.LayerDown)(fp);
(*fp->fn->LayerDown)(fp);
(*fp->fn->SendTerminateAck)(fp);
StartTimer(&fp->FsmTimer); /* Start restart timer */
fp->restart = 0;
NewState(fp, ST_STOPPING);
bundle_LayerDown(fp->bundle, fp);
(*fp->parent->LayerDown)(fp->parent->object, fp);
break;
}
pfree(bp);
@ -605,23 +606,23 @@ FsmRecvTermAck(struct fsm * fp, struct fsmheader * lhp, struct mbuf * bp)
{
switch (fp->state) {
case ST_CLOSING:
(*fp->fn->notify.LayerFinish)(fp);
(*fp->fn->LayerFinish)(fp);
NewState(fp, ST_CLOSED);
bundle_LayerFinish(fp->bundle, fp);
(*fp->parent->LayerFinish)(fp->parent->object, fp);
break;
case ST_STOPPING:
(*fp->fn->notify.LayerFinish)(fp);
(*fp->fn->LayerFinish)(fp);
NewState(fp, ST_STOPPED);
bundle_LayerFinish(fp->bundle, fp);
(*fp->parent->LayerFinish)(fp->parent->object, fp);
break;
case ST_ACKRCVD:
NewState(fp, ST_REQSENT);
break;
case ST_OPENED:
(*fp->fn->notify.LayerDown)(fp);
(*fp->fn->LayerDown)(fp);
FsmSendConfigReq(fp);
NewState(fp, ST_REQSENT);
bundle_LayerDown(fp->bundle, fp);
(*fp->parent->LayerDown)(fp->parent->object, fp);
break;
}
pfree(bp);
@ -670,10 +671,10 @@ FsmRecvConfigRej(struct fsm *fp, struct fsmheader *lhp, struct mbuf *bp)
FsmSendConfigReq(fp);
break;
case ST_OPENED:
(*fp->fn->notify.LayerDown)(fp);
(*fp->fn->LayerDown)(fp);
FsmSendConfigReq(fp);
NewState(fp, ST_REQSENT);
bundle_LayerDown(fp->bundle, fp);
(*fp->parent->LayerDown)(fp->parent->object, fp);
break;
case ST_ACKRCVD:
FsmSendConfigReq(fp);
@ -710,7 +711,7 @@ FsmRecvProtoRej(struct fsm *fp, struct fsmheader *lhp, struct mbuf *bp)
break;
case PROTO_CCP:
fp = &bundle2ccp(fp->bundle, fp->link->name)->fsm;
(*fp->fn->notify.LayerFinish)(fp);
(*fp->fn->LayerFinish)(fp);
switch (fp->state) {
case ST_CLOSED:
case ST_CLOSING:
@ -719,7 +720,7 @@ FsmRecvProtoRej(struct fsm *fp, struct fsmheader *lhp, struct mbuf *bp)
NewState(fp, ST_STOPPED);
break;
}
bundle_LayerFinish(fp->bundle, fp);
(*fp->parent->LayerFinish)(fp->parent->object, fp);
break;
}
pfree(bp);

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.7 1998/02/21 01:45:08 brian Exp $
* $Id: fsm.h,v 1.16.2.8 1998/02/24 03:36:47 brian Exp $
*
* TODO:
*/
@ -47,15 +47,11 @@
struct fsm;
struct fsm_events {
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) */
};
struct fsm_callbacks {
struct fsm_events notify;
void (*InitRestartCounter) (struct fsm *); /* Set fsm timer load */
void (*SendConfigReq) (struct fsm *); /* Send REQ please */
void (*SendTerminateReq) (struct fsm *); /* Term REQ just sent */
@ -66,6 +62,14 @@ struct fsm_callbacks {
void (*RecvResetAck) (struct fsm *fp, u_char); /* Reset input */
};
struct fsm_parent {
void (*LayerStart) (void *, struct fsm *); /* tls */
void (*LayerUp) (void *, struct fsm *); /* tlu */
void (*LayerDown) (void *, struct fsm *); /* tld */
void (*LayerFinish) (void *, struct fsm *); /* tlf */
void *object;
};
struct fsm {
const char *name; /* Name of protocol */
u_short proto; /* Protocol number */
@ -97,6 +101,7 @@ struct fsm {
/* Our high-level link */
struct bundle *bundle;
const struct fsm_parent *parent;
const struct fsm_callbacks *fn;
};
@ -139,7 +144,8 @@ extern u_char *rejp;
extern char const *StateNames[];
extern void fsm_Init(struct fsm *, const char *, u_short, int, int, int,
struct bundle *, struct link *, struct fsm_callbacks *);
struct bundle *, struct link *, const struct fsm_parent *,
struct fsm_callbacks *);
extern void FsmOutput(struct fsm *, u_int, u_int, u_char *, int);
extern void FsmOpen(struct fsm *);
extern void FsmUp(struct fsm *);

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.15 1998/02/21 01:45:11 brian Exp $
* $Id: ipcp.c,v 1.50.2.16 1998/02/24 03:36:49 brian Exp $
*
* TODO:
* o More RFC1772 backwoard compatibility
@ -89,12 +89,10 @@ static void IpcpSendTerminateAck(struct fsm *);
static void IpcpDecodeConfig(struct fsm *, u_char *, int, int);
static struct fsm_callbacks ipcp_Callbacks = {
{
IpcpLayerUp,
IpcpLayerDown,
IpcpLayerStart,
IpcpLayerFinish
},
IpcpLayerUp,
IpcpLayerDown,
IpcpLayerStart,
IpcpLayerFinish,
IpcpInitRestartCounter,
IpcpSendConfigReq,
IpcpSendTerminateReq,
@ -203,13 +201,14 @@ SetInitVJ(struct cmdargs const *args)
}
void
ipcp_Init(struct ipcp *ipcp, struct bundle *bundle, struct link *l)
ipcp_Init(struct ipcp *ipcp, struct bundle *bundle, struct link *l,
const struct fsm_parent *parent)
{
struct hostent *hp;
char name[MAXHOSTNAMELEN];
fsm_Init(&ipcp->fsm, "IPCP", PROTO_IPCP, IPCP_MAXCODE, 10, LogIPCP,
bundle, l, &ipcp_Callbacks);
bundle, l, parent, &ipcp_Callbacks);
ipcp->cfg.VJInitSlots = DEF_VJ_STATES;
ipcp->cfg.VJInitComp = 1;
@ -571,21 +570,6 @@ IpcpLayerUp(struct fsm *fp)
prompt_Display(&prompt, fp->bundle);
}
void
IpcpUp()
{
/* Lower layers are ready.... go */
FsmUp(&IpcpInfo.fsm);
LogPrintf(LogIPCP, "IPCP Up event!!\n");
}
void
IpcpOpen()
{
/* Start IPCP please */
FsmOpen(&IpcpInfo.fsm);
}
static int
AcceptableAddr(struct in_range *prange, struct in_addr ipaddr)
{

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.12 1998/02/08 19:29:44 brian Exp $
* $Id: ipcp.h,v 1.18.2.13 1998/02/21 01:45:12 brian Exp $
*
* TODO:
*/
@ -80,11 +80,10 @@ extern struct ipcp IpcpInfo;
#define fsm2ipcp(fp) (fp->proto == PROTO_IPCP ? (struct ipcp *)fp : NULL)
extern void ipcp_Init(struct ipcp *, struct bundle *, struct link *l);
extern void ipcp_Init(struct ipcp *, struct bundle *, struct link *l,
const struct fsm_parent *);
extern void ipcp_Setup(struct ipcp *);
extern void IpcpUp(void);
extern void IpcpOpen(void);
extern int ReportIpcpStatus(struct cmdargs const *);
extern void IpcpInput(struct mbuf *);
extern void IpcpAddInOctets(int);

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.19 1998/02/21 01:45:14 brian Exp $
* $Id: lcp.c,v 1.55.2.20 1998/02/24 03:36:50 brian Exp $
*
* TODO:
* o Limit data field length by MRU
@ -88,12 +88,10 @@ static void LcpSendTerminateAck(struct fsm *);
static void LcpDecodeConfig(struct fsm *, u_char *, int, int);
static struct fsm_callbacks lcp_Callbacks = {
{
LcpLayerUp,
LcpLayerDown,
LcpLayerStart,
LcpLayerFinish
},
LcpLayerUp,
LcpLayerDown,
LcpLayerStart,
LcpLayerFinish,
LcpInitRestartCounter,
LcpSendConfigReq,
LcpSendTerminateReq,
@ -103,23 +101,7 @@ static struct fsm_callbacks lcp_Callbacks = {
NullRecvResetAck
};
struct lcp LcpInfo = {
{
"LCP", /* Name of protocol */
PROTO_LCP, /* Protocol Number */
LCP_MAXCODE,
1, /* Open mode delay */
ST_INITIAL, /* State of machine */
0, 0, 0,
{0, 0, 0, NULL, NULL, NULL}, /* FSM timer */
{0, 0, 0, NULL, NULL, NULL}, /* Open timer */
{0, 0, 0, NULL, NULL, NULL}, /* Stopped timer */
LogLCP,
NULL, /* link */
NULL, /* bundle */
&lcp_Callbacks
}
};
struct lcp LcpInfo;
static const char *cftypes[] = {
/* Check out the latest ``Assigned numbers'' rfc (rfc1700.txt) */
@ -187,11 +169,12 @@ GenerateMagic(void)
}
void
lcp_Init(struct lcp *lcp, struct bundle *bundle, struct physical *physical)
lcp_Init(struct lcp *lcp, struct bundle *bundle, struct physical *physical,
const struct fsm_parent *parent)
{
/* Initialise ourselves */
fsm_Init(&lcp->fsm, "LCP", PROTO_LCP, LCP_MAXCODE, 10, LogLCP, bundle,
&physical->link, &lcp_Callbacks);
&physical->link, parent, &lcp_Callbacks);
lcp_Setup(lcp, 1);
}

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.10 1998/02/19 19:56:39 brian Exp $
* $Id: lcp.h,v 1.16.2.11 1998/02/21 01:45:17 brian Exp $
*
* TODO:
*/
@ -75,7 +75,8 @@ extern struct lcp LcpInfo;
#define fsm2lcp(fp) (fp->proto == PROTO_LCP ? (struct lcp *)fp : NULL)
extern void lcp_Init(struct lcp *, struct bundle *, struct physical *);
extern void lcp_Init(struct lcp *, struct bundle *, struct physical *,
const struct fsm_parent *);
extern void lcp_Setup(struct lcp *, int);
extern void LcpSendProtoRej(u_char *, int);

View File

@ -23,7 +23,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: link.c,v 1.1.2.7 1998/02/18 19:35:51 brian Exp $
* $Id: link.c,v 1.1.2.8 1998/02/23 00:38:33 brian Exp $
*
*/
@ -44,6 +44,7 @@
#include "loadalias.h"
#include "vars.h"
#include "link.h"
#include "fsm.h"
#include "bundle.h"
#include "descriptor.h"
#include "prompt.h"

View File

@ -23,7 +23,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: prompt.c,v 1.1.2.7 1998/02/17 19:28:35 brian Exp $
* $Id: prompt.c,v 1.1.2.8 1998/02/23 00:38:41 brian Exp $
*/
#include <sys/param.h>
@ -40,10 +40,10 @@
#include "timer.h"
#include "command.h"
#include "log.h"
#include "bundle.h"
#include "descriptor.h"
#include "prompt.h"
#include "fsm.h"
#include "bundle.h"
#include "lcp.h"
#include "auth.h"
#include "loadalias.h"

View File

@ -17,7 +17,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* $Id: route.c,v 1.42.2.6 1998/02/07 20:50:06 brian Exp $
* $Id: route.c,v 1.42.2.7 1998/02/10 03:23:39 brian Exp $
*
*/
@ -48,13 +48,13 @@
#include "defs.h"
#include "vars.h"
#include "id.h"
#include "bundle.h"
#include "iplist.h"
#include "timer.h"
#include "throughput.h"
#include "hdlc.h"
#include "link.h"
#include "fsm.h"
#include "bundle.h"
#include "ipcp.h"
#include "route.h"
#include "descriptor.h"

View File

@ -23,7 +23,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: tun.c,v 1.6.4.1 1998/02/02 19:32:16 brian Exp $
* $Id: tun.c,v 1.6.4.2 1998/02/18 19:35:59 brian Exp $
*/
#include <sys/param.h>
@ -46,6 +46,7 @@
#include "defs.h"
#include "loadalias.h"
#include "vars.h"
#include "fsm.h"
#include "bundle.h"
#include "tun.h"