Create `struct link' - the logical link from which

`struct physical' (and the future `struct logical')
are derived.
This commit is contained in:
Brian Somers 1998-01-30 19:46:07 +00:00
parent c8ee0d78b6
commit 8c07a7b2e0
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/cvs2svn/branches/MP/; revision=32903
35 changed files with 607 additions and 370 deletions

View File

@ -1,9 +1,9 @@
# $Id: Makefile,v 1.36 1998/01/29 00:42:04 brian Exp $
# $Id: Makefile,v 1.36.2.1 1998/01/29 00:49:10 brian Exp $
PROG= ppp
SRCS= arp.c async.c auth.c ccp.c chap.c chat.c command.c deflate.c \
defs.c filter.c fsm.c hdlc.c id.c ip.c ipcp.c iplist.c lcp.c \
log.c lqr.c main.c mbuf.c modem.c os.c pap.c phase.c physical.c \
link.c log.c lqr.c main.c mbuf.c modem.c os.c pap.c phase.c physical.c \
pred.c route.c server.c sig.c slcompress.c systems.c throughput.c \
timer.c tun.c vars.c vjcomp.c
CFLAGS+=-Wall -Wpointer-arith

View File

@ -17,7 +17,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* $Id: async.c,v 1.15 1998/01/21 02:15:08 brian Exp $
* $Id: async.c,v 1.15.2.1 1998/01/29 00:49:10 brian Exp $
*
*/
#include <sys/param.h>
@ -40,6 +40,8 @@
#include "loadalias.h"
#include "vars.h"
#include "async.h"
#include "throughput.h"
#include "link.h"
#include "physical.h"
#define HDLCSIZE (MAX_MRU*2+6)
@ -98,7 +100,7 @@ HdlcPutByte(u_char **cp, u_char c, int proto)
}
void
AsyncOutput(int pri, struct mbuf *bp, int proto, struct physical *physical)
AsyncOutput(int pri, struct mbuf *bp, int proto, struct link *l)
{
struct async_state *hs = &AsyncState;
u_char *cp, *sp, *ep;
@ -128,8 +130,8 @@ AsyncOutput(int pri, struct mbuf *bp, int proto, struct physical *physical)
cnt = cp - hs->xbuff;
LogDumpBuff(LogASYNC, "WriteModem", hs->xbuff, cnt);
WriteModem(physical, pri, (char *) hs->xbuff, cnt);
ModemAddOutOctets(physical, cnt);
link_Write(l, pri, (char *)hs->xbuff, cnt);
link_AddOutOctets(l, cnt);
pfree(bp);
}
@ -181,7 +183,8 @@ AsyncInput(u_char *buff, int cnt, struct physical *physical)
{
struct mbuf *bp;
ModemAddInOctets(physical, cnt);
link_AddInOctets(physical2link(physical), cnt);
if (Physical_IsSync(physical)) {
bp = mballoc(cnt, MB_ASYNC);
memcpy(MBUF_CTOP(bp), buff, cnt);

View File

@ -23,10 +23,10 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: async.h,v 1.2 1997/12/21 12:11:04 brian Exp $
* $Id: async.h,v 1.2.4.1 1998/01/29 00:49:11 brian Exp $
*/
extern void AsyncInit(void);
extern void SetLinkParams(struct lcpstate *);
extern void AsyncOutput(int, struct mbuf *, int, struct physical *);
extern void AsyncOutput(int, struct mbuf *, int, struct link *);
extern void AsyncInput(u_char *, int, struct physical *);

View File

@ -17,7 +17,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* $Id: auth.c,v 1.27.2.1 1998/01/29 00:49:11 brian Exp $
* $Id: auth.c,v 1.27.2.2 1998/01/29 23:11:31 brian Exp $
*
* TODO:
* o Implement check against with registered IP addresses.
@ -43,6 +43,7 @@
#include "auth.h"
#include "chat.h"
#include "systems.h"
#include "physical.h"
void
LocalAuthInit()
@ -128,7 +129,8 @@ AuthValidate(const char *fname, const char *system, const char *key,
CloseSecret(fp);
if (n > 2 && !UseHisaddr(vector[2], 1))
return (0);
IpcpInit(physical);
IpcpInit(physical2link(physical)); /* XXX defer this - we may join an
* existing bundle ! */
if (n > 3)
SetLabel(vector[3]);
return (1); /* Valid */
@ -166,7 +168,8 @@ AuthGetSecret(const char *fname, const char *system, int len, int setaddr,
memset(&IpcpInfo.DefHisAddress, '\0', sizeof IpcpInfo.DefHisAddress);
if (n > 2 && setaddr)
if (UseHisaddr(vector[2], 1))
IpcpInit(physical);
IpcpInit(physical2link(physical)); /* XXX defer this - we may join
* an existing bundle ! */
else
return NULL;
if (n > 3)

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.1 1998/01/29 00:49:13 brian Exp $
* $Id: ccp.c,v 1.30.2.2 1998/01/29 20:45:13 brian Exp $
*
* TODO:
* o Support other compression protocols
@ -149,9 +149,9 @@ ccpstateInit(void)
}
void
CcpInit(struct physical *physical)
CcpInit(struct link *l)
{
FsmInit(&CcpFsm, physical);
FsmInit(&CcpFsm, l);
ccpstateInit();
CcpFsm.maxconfig = 10;
}
@ -417,10 +417,10 @@ CcpResetInput(u_char id)
}
int
CcpOutput(struct physical *physical, int pri, u_short proto, struct mbuf *m)
CcpOutput(struct link *l, int pri, u_short proto, struct mbuf *m)
{
if (CcpInfo.out_init)
return (*algorithm[CcpInfo.out_algorithm]->o.Write)(physical, pri, proto, m);
return (*algorithm[CcpInfo.out_algorithm]->o.Write)(l, pri, proto, m);
return 0;
}

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.1 1998/01/29 00:49:13 brian Exp $
* $Id: ccp.h,v 1.14.2.2 1998/01/29 20:45:14 brian Exp $
*
* TODO:
*/
@ -76,7 +76,7 @@ struct ccp_algorithm {
int (*Init)(void);
void (*Term)(void);
void (*Reset)(void);
int (*Write)(struct physical *, int, u_short, struct mbuf *);
int (*Write)(struct link *, int, u_short, struct mbuf *);
} o;
};
@ -87,9 +87,9 @@ extern void CcpSendResetReq(struct fsm *);
extern void CcpInput(struct mbuf *);
extern void CcpUp(void);
extern void CcpOpen(void);
extern void CcpInit(struct physical *physical);
extern void CcpInit(struct link *);
extern int ReportCcpStatus(struct cmdargs const *);
extern void CcpResetInput(u_char);
extern int CcpOutput(struct physical *, int, u_short, struct mbuf *);
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 *);

View File

@ -17,7 +17,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* $Id: chap.c,v 1.28.2.1 1998/01/29 00:49:13 brian Exp $
* $Id: chap.c,v 1.28.2.2 1998/01/30 01:33:44 brian Exp $
*
* TODO:
*/
@ -80,7 +80,7 @@ ChapOutput(struct physical *physical, u_int code, u_int id,
memcpy(MBUF_CTOP(bp) + sizeof(struct fsmheader), ptr, count);
LogDumpBp(LogDEBUG, "ChapOutput", bp);
LogPrintf(LogLCP, "ChapOutput: %s\n", chapcodes[code]);
HdlcOutput(physical, PRI_LINK, PROTO_CHAP, bp);
HdlcOutput(physical2link(physical), PRI_LINK, PROTO_CHAP, bp);
}

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.1 1998/01/29 00:49:15 brian Exp $
* $Id: command.c,v 1.131.2.2 1998/01/29 23:11:33 brian Exp $
*
*/
#include <sys/param.h>
@ -74,6 +74,7 @@
#include "ip.h"
#include "slcompress.h"
#include "auth.h"
#include "link.h"
#include "physical.h"
struct in_addr ifnetmask;
@ -640,7 +641,7 @@ static struct cmdtab const ShowCommands[] = {
"Show Preferred MTU", "show mtu"},
{"ofilter", NULL, ShowOfilter, LOCAL_AUTH,
"Show Output filters", "show ofilter option .."},
{"proto", NULL, ReportProtStatus, LOCAL_AUTH,
{"proto", NULL, ReportProtocolStatus, LOCAL_AUTH,
"Show protocol summary", "show proto"},
{"reconnect", NULL, ShowReconnect, LOCAL_AUTH,
"Show reconnect timer", "show reconnect"},
@ -1372,8 +1373,8 @@ SetVariable(struct cmdargs const *arg)
break;
case VAR_DEVICE:
if (mode & MODE_INTER)
HangupModem(pppVars.physical, 0);
if (Physical_IsActive(pppVars.physical))
link_Close(physical2link(pppVars.physical), 0);
if (link_IsActive(physical2link(pppVars.physical)))
LogPrintf(LogWARN,
"Cannot change device to \"%s\" when \"%s\" is open\n",
argp, Physical_GetDevice(pppVars.physical));

View File

@ -23,7 +23,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: deflate.c,v 1.6.4.1 1998/01/29 00:49:16 brian Exp $
* $Id: deflate.c,v 1.6.4.2 1998/01/30 01:33:45 brian Exp $
*/
#include <sys/param.h>
@ -45,6 +45,8 @@
#include "ccp.h"
#include "lcpproto.h"
#include "fsm.h"
#include "throughput.h"
#include "link.h"
#include "deflate.h"
/* Our state */
@ -72,8 +74,7 @@ DeflateResetOutput(void)
}
static int
DeflateOutput(struct physical *physical, int pri, u_short proto,
struct mbuf *mp)
DeflateOutput(struct link *l, int pri, u_short proto, struct mbuf *mp)
{
u_char *wp, *rp;
int olen, ilen, len, res, flush;
@ -185,7 +186,7 @@ DeflateOutput(struct physical *physical, int pri, u_short proto,
LogPrintf(LogDEBUG, "DeflateOutput: %d => %d bytes, proto 0x%04x\n",
ilen, olen, proto);
HdlcOutput(physical, PRI_NORMAL, PROTO_COMPD, mo_head);
HdlcOutput(l, PRI_NORMAL, PROTO_COMPD, mo_head);
return 1;
}

View File

@ -17,7 +17,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* $Id: filter.c,v 1.22 1998/01/21 02:15:14 brian Exp $
* $Id: filter.c,v 1.22.2.1 1998/01/29 23:11:33 brian Exp $
*
* TODO: Shoud send ICMP error message when we discard packets.
*/
@ -40,6 +40,8 @@
#include "iplist.h"
#include "timer.h"
#include "throughput.h"
#include "hdlc.h"
#include "link.h"
#include "ipcp.h"
#include "filter.h"

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 1998/01/20 22:47:36 brian Exp $
* $Id: fsm.c,v 1.27.2.1 1998/01/29 00:49:19 brian Exp $
*
* TODO:
* o Refer loglevel for log output
@ -44,6 +44,8 @@
#include "modem.h"
#include "loadalias.h"
#include "vars.h"
#include "throughput.h"
#include "link.h"
#include "physical.h"
u_char AckBuff[200];
@ -74,21 +76,21 @@ StoppedTimeout(void *v)
fp->name);
StopTimer(&fp->OpenTimer);
}
if (Physical_IsActive(fp->physical))
if (link_IsActive(fp->link))
DownConnection();
else
FsmDown(fp);
}
void
FsmInit(struct fsm * fp, struct physical *physical)
FsmInit(struct fsm * fp, struct link *l)
{
LogPrintf(LogDEBUG, "FsmInit\n");
fp->state = ST_INITIAL;
fp->reqid = 1;
fp->restart = 1;
fp->maxconfig = 3;
fp->physical = physical;
fp->link = l;
}
static void
@ -126,7 +128,7 @@ FsmOutput(struct fsm * fp, u_int code, u_int id, u_char * ptr, int count)
if (count)
memcpy(MBUF_CTOP(bp) + sizeof(struct fsmheader), ptr, count);
LogDumpBp(LogDEBUG, "FsmOutput", bp);
HdlcOutput(fp->physical, PRI_LINK, fp->proto, bp);
HdlcOutput(fp->link, PRI_LINK, fp->proto, bp);
}
static void
@ -655,8 +657,9 @@ FsmRecvCodeRej(struct fsm * fp, struct fsmheader * lhp, struct mbuf * bp)
}
static void
FsmRecvProtoRej(struct fsm * fp, struct fsmheader * lhp, struct mbuf * bp)
FsmRecvProtoRej(struct fsm *fp, struct fsmheader *lhp, struct mbuf *bp)
{
struct physical *p = link2physical(fp->link);
u_short *sp, proto;
sp = (u_short *) MBUF_CTOP(bp);
@ -665,7 +668,10 @@ FsmRecvProtoRej(struct fsm * fp, struct fsmheader * lhp, struct mbuf * bp)
switch (proto) {
case PROTO_LQR:
StopLqr(fp->physical, LQM_LQR);
if (p)
StopLqr(p, LQM_LQR);
else
LogPrintf(LogERROR, "FsmRecvProtoRej: Not a physical link !\n");
break;
case PROTO_CCP:
fp = &CcpFsm;
@ -758,7 +764,7 @@ FsmRecvResetReq(struct fsm * fp, struct fsmheader * lhp, struct mbuf * bp)
* output queue.... dump 'em to the priority queue so that they arrive
* at the peer before our ResetAck.
*/
SequenceQueues(fp->physical);
link_SequenceQueue(fp->link);
LogPrintf(fp->LogLevel, "SendResetAck(%d)\n", lhp->id);
FsmOutput(fp, CODE_RESETACK, lhp->id, NULL, 0);
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 1998/01/21 02:15:15 brian Exp $
* $Id: fsm.h,v 1.16.2.1 1998/01/29 00:49:21 brian Exp $
*
* TODO:
*/
@ -70,8 +70,8 @@ struct fsm {
struct pppTimer StoppedTimer;
int LogLevel;
/* The physical layer active with this FSM. */
struct physical *physical;
/* The link layer active with this FSM. */
struct link *link;
void (*LayerUp) (struct fsm *);
void (*LayerDown) (struct fsm *);
@ -126,7 +126,7 @@ extern u_char *rejp;
extern char const *StateNames[];
extern void FsmInit(struct fsm *, struct physical *);
extern void FsmInit(struct fsm *, struct link *);
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: hdlc.c,v 1.28.2.1 1998/01/29 00:49:21 brian Exp $
* $Id: hdlc.c,v 1.28.2.2 1998/01/29 23:11:34 brian Exp $
*
* TODO:
*/
@ -50,6 +50,7 @@
#include "vars.h"
#include "modem.h"
#include "ccp.h"
#include "link.h"
#include "physical.h"
static struct hdlcstat {
@ -63,25 +64,6 @@ static int ifOutPackets;
static int ifOutOctets;
static int ifOutLQRs;
static struct protostat {
u_short number;
const char *name;
u_long in_count;
u_long out_count;
} ProtocolStat[] = {
{ PROTO_IP, "IP" },
{ PROTO_VJUNCOMP, "VJ_UNCOMP" },
{ PROTO_VJCOMP, "VJ_COMP" },
{ PROTO_COMPD, "COMPD" },
{ PROTO_LCP, "LCP" },
{ PROTO_IPCP, "IPCP" },
{ PROTO_CCP, "CCP" },
{ PROTO_PAP, "PAP" },
{ PROTO_LQR, "LQR" },
{ PROTO_CHAP, "CHAP" },
{ 0, "Others" }
};
static u_short const fcstab[256] = {
/* 00 */ 0x0000, 0x1189, 0x2312, 0x329b, 0x4624, 0x57ad, 0x6536, 0x74bf,
/* 08 */ 0x8c48, 0x9dc1, 0xaf5a, 0xbed3, 0xca6c, 0xdbe5, 0xe97e, 0xf8f7,
@ -160,21 +142,32 @@ HdlcFcsBuf(u_short fcs, struct mbuf *m)
}
void
HdlcOutput(struct physical *physical,
int pri, u_short proto, struct mbuf * bp)
HdlcOutput(struct link *l, int pri, u_short proto, struct mbuf *bp)
{
struct physical *p = link2physical(l);
struct mbuf *mhp, *mfcs;
struct protostat *statp;
struct lqrdata *lqr;
u_char *cp;
u_short fcs;
if ((proto & 0xfff1) == 0x21) /* Network Layer protocol */
if (CcpFsm.state == ST_OPENED)
if (CcpOutput(physical, pri, proto, bp))
if (CcpOutput(l, pri, proto, bp))
return;
if (Physical_IsSync(physical))
if (!p) {
/*
* This is where we multiplex the data over our available physical
* links. We don't frame our logical link data. Instead we wait
* for the logical link implementation to chop our data up and pile
* it into the physical links by re-calling this function with the
* encapsulated fragments.
*/
link_Output(l, pri, bp);
return;
}
if (Physical_IsSync(p))
mfcs = NULL;
else
mfcs = mballoc(2, MB_HDLCOUT);
@ -199,6 +192,7 @@ HdlcOutput(struct physical *physical,
*cp = proto & 0377;
mhp->cnt += 2;
}
mhp->next = bp;
while (bp->next != NULL)
bp = bp->next;
@ -224,7 +218,8 @@ HdlcOutput(struct physical *physical,
LqrDump("LqrOutput", lqr);
LqrChangeOrder(lqr, (struct lqrdata *) (MBUF_CTOP(bp)));
}
if (!Physical_IsSync(physical)) {
if (mfcs) {
mfcs->cnt = 0;
fcs = HdlcFcsBuf(INITFCS, mhp);
fcs = ~fcs;
@ -233,18 +228,16 @@ HdlcOutput(struct physical *physical,
*cp++ = fcs >> 8;
mfcs->cnt = 2;
}
LogDumpBp(LogHDLC, "HdlcOutput", mhp);
for (statp = ProtocolStat; statp->number; statp++)
if (statp->number == proto)
break;
statp->out_count++;
LogDumpBp(LogHDLC, "HdlcOutput", mhp);
link_ProtocolRecord(l, proto, PROTO_OUT);
LogPrintf(LogDEBUG, "HdlcOutput: proto = 0x%04x\n", proto);
if (Physical_IsSync(physical))
ModemOutput(physical, pri, mhp);
if (Physical_IsSync(p))
link_Output(l, pri, mhp); /* Send it raw */
else
AsyncOutput(pri, mhp, proto, physical);
AsyncOutput(pri, mhp, proto, l);
}
/* Check out the latest ``Assigned numbers'' rfc (rfc1700.txt) */
@ -374,8 +367,9 @@ Protocol2Nam(u_short proto)
}
static void
DecodePacket(u_short proto, struct mbuf * bp, struct physical *physical)
DecodePacket(u_short proto, struct mbuf * bp, struct link *l)
{
struct physical *p = link2physical(l);
u_char *cp;
LogPrintf(LogDEBUG, "DecodePacket: proto = 0x%04x\n", proto);
@ -396,21 +390,35 @@ DecodePacket(u_short proto, struct mbuf * bp, struct physical *physical)
LcpInput(bp);
break;
case PROTO_PAP:
PapInput(bp, physical);
if (p)
PapInput(bp, p);
else {
LogPrintf(LogERROR, "DecodePacket: PAP: Not a physical link !\n");
pfree(bp);
}
break;
case PROTO_LQR:
HisLqrSave.SaveInLQRs++;
LqrInput(physical, bp);
if (p)
LqrInput(p, bp);
else {
LogPrintf(LogERROR, "DecodePacket: LQR: Not a physical link !\n");
pfree(bp);
}
break;
case PROTO_CHAP:
ChapInput(bp, physical);
if (p)
ChapInput(bp, p);
else {
LogPrintf(LogERROR, "DecodePacket: CHAP: Not a physical link !\n");
pfree(bp);
}
break;
case PROTO_VJUNCOMP:
case PROTO_VJCOMP:
bp = VjCompInput(bp, proto);
if (bp == NULL) {
if (bp == NULL)
break;
}
/* fall down */
case PROTO_IP:
IpInput(bp);
@ -435,30 +443,6 @@ DecodePacket(u_short proto, struct mbuf * bp, struct physical *physical)
}
}
int
ReportProtStatus(struct cmdargs const *arg)
{
struct protostat *statp;
int cnt;
statp = ProtocolStat;
statp--;
cnt = 0;
fprintf(VarTerm, " Protocol in out Protocol in out\n");
do {
statp++;
fprintf(VarTerm, " %-9s: %8lu, %8lu",
statp->name, statp->in_count, statp->out_count);
if (++cnt == 2) {
fprintf(VarTerm, "\n");
cnt = 0;
}
} while (statp->number);
if (cnt)
fprintf(VarTerm, "\n");
return (0);
}
int
ReportHdlcStatus(struct cmdargs const *arg)
{
@ -493,7 +477,6 @@ HdlcInput(struct mbuf * bp, struct physical *physical)
{
u_short fcs, proto;
u_char *cp, addr, ctrl;
struct protostat *statp;
LogDumpBp(LogHDLC, "HdlcInput:", bp);
if (Physical_IsSync(physical))
@ -570,11 +553,8 @@ HdlcInput(struct mbuf * bp, struct physical *physical)
bp->cnt -= 2;
}
for (statp = ProtocolStat; statp->number; statp++)
if (statp->number == proto)
break;
statp->in_count++;
link_ProtocolRecord(physical2link(physical), proto, PROTO_IN);
HisLqrSave.SaveInPackets++;
DecodePacket(proto, bp, physical);
DecodePacket(proto, bp, physical2link(physical));
}

View File

@ -15,7 +15,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* $Id: hdlc.h,v 1.14 1998/01/21 02:15:15 brian Exp $
* $Id: hdlc.h,v 1.14.2.1 1998/01/29 00:49:22 brian Exp $
*
* TODO:
*/
@ -54,15 +54,17 @@
#define PRI_NORMAL 0 /* Normal priority */
#define PRI_FAST 1 /* Fast (interractive) */
#define PRI_LINK 1 /* Urgent (LQR packets) */
#define PRI_MAX 1
extern u_char EscMap[33];
struct physical;
struct link;
extern void HdlcInit(void);
extern void HdlcErrorCheck(void);
extern void HdlcInput(struct mbuf *, struct physical *);
extern void HdlcOutput(struct physical *, int, u_short, struct mbuf *bp);
extern void HdlcOutput(struct link *, int, u_short, struct mbuf *bp);
extern u_short HdlcFcs(u_short, u_char *, int);
extern int ReportHdlcStatus(struct cmdargs const *);
extern int ReportProtStatus(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: ip.c,v 1.38.2.1 1998/01/29 00:49:22 brian Exp $
* $Id: ip.c,v 1.38.2.2 1998/01/29 23:11:35 brian Exp $
*
* TODO:
* o Return ICMP message for filterd packet
@ -516,7 +516,7 @@ IsIpEnqueued()
#endif
void
IpStartOutput(struct physical *physical)
IpStartOutput(struct link *l)
{
struct mqueue *queue;
struct mbuf *bp;
@ -529,7 +529,7 @@ IpStartOutput(struct physical *physical)
bp = Dequeue(queue);
if (bp) {
cnt = plength(bp);
SendPppFrame(physical, bp);
SendPppFrame(l, bp);
RestartIdleTimer();
IpcpAddOutOctets(cnt);
break;

View File

@ -17,13 +17,11 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* $Id: ip.h,v 1.8 1997/12/29 22:23:11 brian Exp $
* $Id: ip.h,v 1.8.2.1 1998/01/29 00:49:23 brian Exp $
*
*/
struct physical;
extern void IpStartOutput(struct physical *);
extern void IpStartOutput(struct link *);
extern int PacketCheck(char *, int, int);
extern void IpEnqueue(int, char *, int);
extern void IpInput(struct mbuf *);

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.1 1998/01/29 00:49:23 brian Exp $
* $Id: ipcp.c,v 1.50.2.2 1998/01/29 23:11:36 brian Exp $
*
* TODO:
* o More RFC1772 backwoard compatibility
@ -55,6 +55,8 @@
#include "ip.h"
#include "route.h"
#include "filter.h"
#include "hdlc.h"
#include "link.h"
#include "physical.h"
struct compreq {
@ -223,11 +225,11 @@ ShowInitVJ(struct cmdargs const *args)
}
void
IpcpInit(struct physical *physical)
IpcpInit(struct link *l)
{
if (iplist_isvalid(&IpcpInfo.DefHisChoice))
iplist_setrandpos(&IpcpInfo.DefHisChoice);
FsmInit(&IpcpFsm, physical);
FsmInit(&IpcpFsm, l);
IpcpInfo.his_compproto = 0;
IpcpInfo.his_reject = IpcpInfo.my_reject = 0;
@ -270,14 +272,15 @@ IpcpInitRestartCounter(struct fsm * fp)
}
static void
IpcpSendConfigReq(struct fsm * fp)
IpcpSendConfigReq(struct fsm *fp)
{
struct physical *p = link2physical(fp->link);
u_char *cp;
struct lcp_opt o;
cp = ReqBuff;
LogPrintf(LogIPCP, "IpcpSendConfigReq\n");
if (!Physical_IsSync(fp->physical) || !REJECTED(&IpcpInfo, TY_IPADDR)) {
if ((p && !Physical_IsSync(p)) || !REJECTED(&IpcpInfo, TY_IPADDR)) {
o.id = TY_IPADDR;
o.len = 6;
*(u_long *)o.data = IpcpInfo.want_ipaddr.s_addr;
@ -327,7 +330,6 @@ IpcpLayerFinish(struct fsm * fp)
LogPrintf(LogIPCP, "IpcpLayerFinish.\n");
reconnect(RECON_FALSE);
LcpClose(&LcpFsm);
NewPhase(fp->physical, PHASE_TERMINATE);
}
static void

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.3 1998/01/30 01:28:35 brian Exp $
* $Id: ipcp.h,v 1.18.2.4 1998/01/30 01:32:55 brian Exp $
*
* TODO:
*/
@ -73,7 +73,7 @@ struct ipcpstate {
extern struct ipcpstate IpcpInfo;
extern struct fsm IpcpFsm;
extern void IpcpInit(struct physical *physical);
extern void IpcpInit(struct link *l);
extern void IpcpDefAddress(void);
extern void IpcpUp(void);
extern void IpcpOpen(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.2 1998/01/29 23:11:38 brian Exp $
* $Id: lcp.c,v 1.55.2.3 1998/01/30 01:33:45 brian Exp $
*
* TODO:
* o Limit data field length by MRU
@ -65,6 +65,7 @@
#include "ip.h"
#include "modem.h"
#include "tun.h"
#include "link.h"
#include "physical.h"
/* for received LQRs */
@ -202,7 +203,7 @@ GenerateMagic(void)
void
LcpInit(struct physical *physical)
{
FsmInit(&LcpFsm, physical);
FsmInit(&LcpFsm, physical2link(physical));
HdlcInit();
memset(&LcpInfo, '\0', sizeof LcpInfo);
LcpInfo.want_mru = VarMRU;
@ -310,14 +311,20 @@ do { \
#define PUTMSCHAP() PUTCHAP(0x80)
static void
LcpSendConfigReq(struct fsm * fp)
LcpSendConfigReq(struct fsm *fp)
{
struct physical *p = link2physical(fp->link);
u_char *cp;
struct lcp_opt o;
if (!p) {
LogPrintf(LogERROR, "LcpSendConfigReq: Not a physical link !\n");
return;
}
LogPrintf(LogLCP, "LcpSendConfigReq\n");
cp = ReqBuff;
if (!Physical_IsSync(fp->physical)) {
if (!Physical_IsSync(p)) {
if (LcpInfo.want_acfcomp && !REJECTED(&LcpInfo, TY_ACFCOMP))
PUTN(TY_ACFCOMP);
@ -377,10 +384,15 @@ LcpSendTerminateAck(struct fsm * fp)
}
static void
LcpLayerStart(struct fsm * fp)
LcpLayerStart(struct fsm *fp)
{
struct physical *p = link2physical(fp->link);
LogPrintf(LogLCP, "LcpLayerStart\n");
NewPhase(fp->physical, PHASE_ESTABLISH);
if (p)
NewPhase(p, PHASE_ESTABLISH);
else
LogPrintf(LogERROR, "LcpLayerStart: Not a physical link !\n");
}
static void
@ -394,29 +406,38 @@ StopAllTimers(void)
}
static void
LcpLayerFinish(struct fsm * fp)
LcpLayerFinish(struct fsm *fp)
{
struct physical *p = link2physical(fp->link);
LogPrintf(LogLCP, "LcpLayerFinish\n");
HangupModem(fp->physical, 0);
link_Close(fp->link, 0);
StopAllTimers();
/* We're down at last. Lets tell background and direct mode to get out */
NewPhase(fp->physical, PHASE_DEAD);
LcpInit(fp->physical);
IpcpInit(fp->physical);
CcpInit(fp->physical);
if (p) {
NewPhase(p, PHASE_DEAD);
LcpInit(p);
} else
LogPrintf(LogERROR, "LcpLayerFinish: Not a physical link !\n");
IpcpInit(fp->link);
CcpInit(fp->link);
Prompt();
}
static void
LcpLayerUp(struct fsm * fp)
LcpLayerUp(struct fsm *fp)
{
struct physical *p = link2physical(fp->link);
LogPrintf(LogLCP, "LcpLayerUp\n");
tun_configure(LcpInfo.his_mru, ModemSpeed(fp->physical));
SetLinkParams(&LcpInfo);
NewPhase(fp->physical, PHASE_AUTHENTICATE);
if (p) {
NewPhase(p, PHASE_AUTHENTICATE);
StartLqm(p);
} else
LogPrintf(LogERROR, "LcpLayerUp: Not a physical link !\n");
StartLqm(fp->physical);
StopTimer(&LcpInfo.ReportTimer);
LcpInfo.ReportTimer.state = TIMER_STOPPED;
LcpInfo.ReportTimer.load = 60 * SECTICKS;
@ -464,7 +485,13 @@ LcpOpen(int open_mode)
void
LcpClose(struct fsm *fp)
{
NewPhase(fp->physical, PHASE_TERMINATE);
struct physical *p = link2physical(fp->link);
if (p)
NewPhase(p, PHASE_TERMINATE);
else
LogPrintf(LogERROR, "LcpClose: Not a physical link !\n");
OsInterfaceDown(0);
FsmClose(fp);
LcpInfo.LcpFailedMagic = 0;

196
usr.sbin/ppp/link.c Normal file
View File

@ -0,0 +1,196 @@
/*-
* Copyright (c) 1998 Brian Somers <brian@Awfulhak.org>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id$
*
*/
#include <sys/param.h>
#include <netinet/in.h>
#include <stdio.h>
#include "command.h"
#include "mbuf.h"
#include "log.h"
#include "defs.h"
#include "hdlc.h"
#include "timer.h"
#include "throughput.h"
#include "lcpproto.h"
#include "loadalias.h"
#include "vars.h"
#include "link.h"
void
link_AddInOctets(struct link *l, int n)
{
throughput_addin(&l->throughput, n);
}
void
link_AddOutOctets(struct link *l, int n)
{
throughput_addout(&l->throughput, n);
}
void
link_SequenceQueue(struct link *l)
{
LogPrintf(LogDEBUG, "link_SequenceQueue\n");
while (l->Queue[PRI_NORMAL].qlen)
Enqueue(l->Queue + PRI_LINK, Dequeue(l->Queue + PRI_NORMAL));
}
int
link_QueueLen(struct link *l)
{
int i, len;
for (i = 0, len = 0; i < LINK_QUEUES; i++)
len += l->Queue[i].qlen;
return len;
}
struct mbuf *
link_Dequeue(struct link *l)
{
int pri;
struct mbuf *bp;
for (bp = (struct mbuf *)0, pri = LINK_QUEUES - 1; pri >= 0; pri--)
if (l->Queue[pri].qlen) {
bp = Dequeue(l->Queue + pri);
if (pri > PRI_NORMAL)
LogPrintf(LogDEBUG, "link_Dequeue: Output from queue %d,"
" containing %d packets\n", pri, l->Queue[pri].qlen);
LogPrintf(LogDEBUG, "link_Dequeue: Dequeued from %d\n", pri);
break;
}
return bp;
}
/*
* Write to the link. Actualy, requested packets are queued, and go out
* at some later time depending on the physical link implementation.
*/
void
link_Write(struct link *l, int pri, const char *ptr, int count)
{
struct mbuf *bp;
if(pri < 0 || pri >= LINK_QUEUES)
pri = 0;
bp = mballoc(count, MB_LINK);
memcpy(MBUF_CTOP(bp), ptr, count);
Enqueue(l->Queue + pri, bp);
}
void
link_StartOutput(struct link *l)
{
(*l->StartOutput)(l);
}
void
link_Output(struct link *l, int pri, struct mbuf *bp)
{
struct mbuf *wp;
int len;
if(pri < 0 || pri >= LINK_QUEUES)
pri = 0;
len = plength(bp);
wp = mballoc(len, MB_LINK);
mbread(bp, MBUF_CTOP(wp), len);
Enqueue(l->Queue + pri, wp);
link_StartOutput(l);
}
int
link_IsActive(struct link *l)
{
return (*l->IsActive)(l);
}
void
link_Close(struct link *l, int dedicated_force)
{
(*l->Close)(l, dedicated_force);
}
static struct protostatheader {
u_short number;
const char *name;
} ProtocolStat[NPROTOSTAT] = {
{ PROTO_IP, "IP" },
{ PROTO_VJUNCOMP, "VJ_UNCOMP" },
{ PROTO_VJCOMP, "VJ_COMP" },
{ PROTO_COMPD, "COMPD" },
{ PROTO_LCP, "LCP" },
{ PROTO_IPCP, "IPCP" },
{ PROTO_CCP, "CCP" },
{ PROTO_PAP, "PAP" },
{ PROTO_LQR, "LQR" },
{ PROTO_CHAP, "CHAP" },
{ 0, "Others" }
};
void
link_ProtocolRecord(struct link *l, u_short proto, int type)
{
int i;
for (i = 0; i < NPROTOSTAT; i++)
if (ProtocolStat[i].number == proto)
break;
if (type == PROTO_IN)
l->proto_in[i]++;
else
l->proto_out[i]++;
}
void
link_ReportProtocolStatus(struct link *l)
{
int i;
fprintf(VarTerm,
" Protocol in out Protocol in out\n");
for (i = 0; i < NPROTOSTAT; i++) {
fprintf(VarTerm, " %-9s: %8lu, %8lu",
ProtocolStat[i].name, l->proto_in[i], l->proto_out[i]);
if ((i % 2) == 0)
fprintf(VarTerm, "\n");
}
if (i % 2)
fprintf(VarTerm, "\n");
}

70
usr.sbin/ppp/link.h Normal file
View File

@ -0,0 +1,70 @@
/*-
* Copyright (c) 1998 Brian Somers <brian@Awfulhak.org>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id$
*
*/
#define PHYSICAL_LINK 1
#define MP_LINK 2
#define LINK_QUEUES (PRI_MAX + 1)
#define NPROTOSTAT 11
struct link {
int type; /* _LINK type */
const char *name; /* unique id per link type */
int len; /* full size of parent struct */
struct pppThroughput throughput; /* Link throughput statistics */
struct pppTimer Timer; /* inactivity timeout */
struct mqueue Queue[LINK_QUEUES]; /* Our output queue of mbufs */
u_long proto_in[NPROTOSTAT]; /* outgoing protocol stats */
u_long proto_out[NPROTOSTAT]; /* incoming protocol stats */
/* Implementation routines for use by link_ routines */
void (*StartOutput)(struct link *); /* send the queued data */
int (*IsActive)(struct link *); /* Are we active ? */
void (*Close)(struct link *, int); /* Close the link */
};
extern void link_AddInOctets(struct link *, int);
extern void link_AddOutOctets(struct link *, int);
extern void link_SequenceQueue(struct link *);
extern int link_QueueLen(struct link *);
extern struct mbuf *link_Dequeue(struct link *);
extern void link_Write(struct link *, int, const char *, int);
extern void link_StartOutput(struct link *);
extern void link_Output(struct link *, int, struct mbuf *);
#define PROTO_IN 1 /* third arg to link_ProtocolRecord */
#define PROTO_OUT 2
extern void link_ProtocolRecord(struct link *, u_short, int);
extern void link_ReportProtocolStatus(struct link *);
extern int link_IsActive(struct link *);
extern void link_Close(struct link *, int);

View File

@ -17,7 +17,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* $Id: lqr.c,v 1.22.2.1 1998/01/29 00:49:25 brian Exp $
* $Id: lqr.c,v 1.22.2.2 1998/01/30 01:33:46 brian Exp $
*
* o LQR based on RFC1333
*
@ -37,6 +37,7 @@
#include "timer.h"
#include "fsm.h"
#include "lcpproto.h"
#include "physical.h"
#include "lqr.h"
#include "hdlc.h"
#include "lcp.h"
@ -128,7 +129,7 @@ SendLqrReport(void *v)
LcpClose(&LcpFsm);
} else {
bp = mballoc(sizeof(struct lqrdata), MB_LQR);
HdlcOutput(physical, PRI_LINK, PROTO_LQR, bp);
HdlcOutput(physical2link(physical), PRI_LINK, PROTO_LQR, bp);
lqrsendcnt++;
}
} else if (lqmmethod & LQM_ECHO) {
@ -221,7 +222,7 @@ StartLqm(struct physical *physical)
LqrTimer.state = TIMER_STOPPED;
LqrTimer.load = period * SECTICKS / 100;
LqrTimer.func = SendLqrReport;
LqrTimer.arg = physical;
LqrTimer.arg = physical;
SendLqrReport(physical);
StartTimer(&LqrTimer);
LogPrintf(LogLQM, "Will send LQR every %d.%d secs\n",

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.1 1998/01/29 00:49:26 brian Exp $
* $Id: main.c,v 1.121.2.2 1998/01/29 23:11:39 brian Exp $
*
* TODO:
* o Add commands for traffic summary, version display, etc.
@ -75,6 +75,7 @@
#include "pathnames.h"
#include "tun.h"
#include "route.h"
#include "link.h"
#include "physical.h"
#ifndef O_NONBLOCK
@ -183,8 +184,8 @@ Cleanup(int excode)
DropClient(1);
ServerClose();
OsInterfaceDown(1);
HangupModem(pppVars.physical, 1); /* XXX must be expanded to
take all modems */
link_Close(physical2link(pppVars.physical), 1); /* XXX gotta get a handle on
* the logical link */
nointr_sleep(1);
DeleteIfRoutes(1);
ID0unlink(pid_filename);
@ -575,8 +576,8 @@ PacketMode(int delay)
AsyncInit();
VjInit(15);
LcpInit(pppVars.physical);
IpcpInit(pppVars.physical);
CcpInit(pppVars.physical);
IpcpInit(physical2link(pppVars.physical));
CcpInit(physical2link(pppVars.physical));
LcpUp();
LcpOpen(delay);
@ -773,7 +774,7 @@ DoLoop(void)
LogPrintf(LogPHASE, "Packet mode enabled\n");
PacketMode(VarOpenMode);
} else if (mode & MODE_DEDICATED) {
if (!Physical_IsActive(pppVars.physical))
if (!link_IsActive(physical2link(pppVars.physical)))
while (OpenModem(pppVars.physical) < 0)
nointr_sleep(VarReconnectTimer);
}
@ -885,13 +886,14 @@ DoLoop(void)
}
}
}
qlen = ModemQlen(pppVars.physical);
qlen = link_QueueLen(physical2link(pppVars.physical));
if (qlen == 0) {
IpStartOutput(pppVars.physical);
qlen = ModemQlen(pppVars.physical);
IpStartOutput(physical2link(pppVars.physical));
qlen = link_QueueLen(physical2link(pppVars.physical));
}
if (Physical_IsActive(pppVars.physical)) {
if (link_IsActive(physical2link(pppVars.physical))) {
/* XXX-ML this should probably be abstracted */
if (Physical_GetFD(pppVars.physical) + 1 > nfds)
nfds = Physical_GetFD(pppVars.physical) + 1;
@ -1011,8 +1013,8 @@ DoLoop(void)
ReadTty();
if (Physical_FD_ISSET(pppVars.physical, &wfds)) {
/* ready to write into modem */
ModemStartOutput(pppVars.physical);
if (!Physical_IsActive(pppVars.physical))
link_StartOutput(physical2link(pppVars.physical));
if (!link_IsActive(physical2link(pppVars.physical)))
dial_up = 1;
}
if (Physical_FD_ISSET(pppVars.physical, &rfds)) {

View File

@ -17,7 +17,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* $Id: mbuf.c,v 1.12 1997/12/28 02:56:42 brian Exp $
* $Id: mbuf.c,v 1.13 1998/01/21 02:15:21 brian Exp $
*
*/
#include <sys/param.h>
@ -173,3 +173,35 @@ LogMemory()
LogPrintf(LogDEBUG, "LogMemory: 5: %d 6: %d 7: %d 8: %d\n",
MemMap[5].count, MemMap[6].count, MemMap[7].count, MemMap[8].count);
}
struct mbuf *
Dequeue(struct mqueue *q)
{
struct mbuf *bp;
LogPrintf(LogDEBUG, "Dequeue: len = %d\n", q->qlen);
bp = q->top;
if (bp) {
q->top = q->top->pnext;
q->qlen--;
if (q->top == NULL) {
q->last = q->top;
if (q->qlen)
LogPrintf(LogERROR, "Dequeue: Not zero (%d)!!!\n", q->qlen);
}
}
return bp;
}
void
Enqueue(struct mqueue *queue, struct mbuf *bp)
{
if (queue->last) {
queue->last->pnext = bp;
queue->last = bp;
} else
queue->last = queue->top = bp;
queue->qlen++;
LogPrintf(LogDEBUG, "Enqueue: len = %d\n", queue->qlen);
}

View File

@ -15,7 +15,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* $Id: mbuf.h,v 1.10 1997/12/03 10:23:50 brian Exp $
* $Id: mbuf.h,v 1.11 1998/01/21 02:15:21 brian Exp $
*
* TODO:
*/
@ -44,7 +44,7 @@ struct mqueue {
#define MB_IPIN 4
#define MB_ECHO 5
#define MB_LQR 6
#define MB_MODEM 7
#define MB_LINK 7
#define MB_VJCOMP 8
#define MB_LOG 9
#define MB_IPQ 10
@ -58,3 +58,5 @@ extern void mbwrite(struct mbuf *, u_char *, int);
extern struct mbuf *mbread(struct mbuf *, u_char *, int);
extern void LogMemory(void);
extern int ShowMemMap(struct cmdargs const *);
extern void Enqueue(struct mqueue *, struct mbuf *);
extern struct mbuf *Dequeue(struct mqueue *);

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 1998/01/29 00:42:05 brian Exp $
* $Id: modem.c,v 1.77.2.1 1998/01/29 00:49:26 brian Exp $
*
* TODO:
*/
@ -27,7 +27,6 @@
#include <arpa/inet.h>
#include <netdb.h>
#include <assert.h>
#include <errno.h>
#include <fcntl.h>
#include <paths.h>
@ -66,6 +65,7 @@
/* We're defining a physical device, and thus need the real
headers. */
#define PHYSICAL_DEVICE
#include "link.h"
#include "physical.h"
@ -75,8 +75,25 @@
#endif
#endif
static void ModemStartOutput(struct link *);
static int ModemIsActive(struct link *);
static void ModemHangup(struct link *, int);
struct physical phys_modem = {
-1
{
PHYSICAL_LINK,
"modem",
sizeof(struct physical),
{ 0 }, /* throughput */
{ 0 }, /* timer */
{ { 0 } }, /* queues */
{ 0 }, /* proto_in */
{ 0 }, /* proto_out */
ModemStartOutput,
ModemIsActive,
ModemHangup
},
-1
};
/* XXX-ML this should probably change when we add support for other
@ -85,45 +102,6 @@ struct physical phys_modem = {
static void CloseLogicalModem(struct physical *);
void
Enqueue(struct mqueue * queue, struct mbuf * bp)
{
if (queue->last) {
queue->last->pnext = bp;
queue->last = bp;
} else
queue->last = queue->top = bp;
queue->qlen++;
LogPrintf(LogDEBUG, "Enqueue: len = %d\n", queue->qlen);
}
struct mbuf *
Dequeue(struct mqueue *queue)
{
struct mbuf *bp;
LogPrintf(LogDEBUG, "Dequeue: len = %d\n", queue->qlen);
bp = queue->top;
if (bp) {
queue->top = queue->top->pnext;
queue->qlen--;
if (queue->top == NULL) {
queue->last = queue->top;
if (queue->qlen)
LogPrintf(LogERROR, "Dequeue: Not zero (%d)!!!\n", queue->qlen);
}
}
return (bp);
}
void
SequenceQueues(struct physical *phys)
{
LogPrintf(LogDEBUG, "SequenceQueues\n");
while (phys->OutputQueues[PRI_NORMAL].qlen)
Enqueue(&phys->OutputQueues[PRI_LINK], Dequeue(&phys->OutputQueues[PRI_NORMAL]));
}
static struct speeds {
int nspeed;
speed_t speed;
@ -250,8 +228,8 @@ ModemTimeout(void *data)
int ombits = modem->mbits;
int change;
StopTimer(&modem->DeviceTimer);
StartTimer(&modem->DeviceTimer);
StopTimer(&modem->link.Timer);
StartTimer(&modem->link.Timer);
if (modem->dev_is_modem) {
if (modem->fd >= 0) {
@ -297,7 +275,7 @@ StartModemTimer(struct physical *modem)
{
struct pppTimer *ModemTimer;
ModemTimer = &modem->DeviceTimer;
ModemTimer = &modem->link.Timer;
StopTimer(ModemTimer);
ModemTimer->state = TIMER_STOPPED;
@ -463,7 +441,7 @@ UnlockModem(struct physical *modem)
static void
HaveModem(struct physical *modem)
{
throughput_start(&modem->throughput);
throughput_start(&modem->link.throughput);
modem->connect_count++;
LogPrintf(LogPHASE, "Connected!\n");
}
@ -721,42 +699,32 @@ UnrawModem(struct physical *modem)
}
}
void
ModemAddInOctets(struct physical *modem, int n)
{
throughput_addin(&modem->throughput, n);
}
void
ModemAddOutOctets(struct physical *modem, int n)
{
throughput_addout(&modem->throughput, n);
}
static void
ClosePhysicalModem(struct physical *modem)
{
LogPrintf(LogDEBUG, "ClosePhysicalModem\n");
close(modem->fd);
modem->fd = -1;
throughput_log(&modem->throughput, LogPHASE, "Modem");
throughput_log(&modem->link.throughput, LogPHASE, "Modem");
}
void
HangupModem(struct physical *modem, int flag)
static void
ModemHangup(struct link *l, int dedicated_force)
{
struct termios tio;
struct physical *modem = (struct physical *)l;
LogPrintf(LogDEBUG, "Hangup modem (%s)\n", modem >= 0 ? "open" : "closed");
LogPrintf(LogDEBUG, "Hangup modem (%s)\n",
modem->fd >= 0 ? "open" : "closed");
if (modem->fd < 0)
return;
StopTimer(&modem->DeviceTimer);
throughput_stop(&modem->throughput);
StopTimer(&modem->link.Timer);
throughput_stop(&modem->link.throughput);
if (TermMode) {
LogPrintf(LogDEBUG, "HangupModem: Not in 'term' mode\n");
LogPrintf(LogDEBUG, "ModemHangup: Not in 'term' mode\n");
return;
}
@ -781,8 +749,8 @@ HangupModem(struct physical *modem, int flag)
strncpy(ScriptBuffer, VarHangupScript, sizeof ScriptBuffer - 1);
ScriptBuffer[sizeof ScriptBuffer - 1] = '\0';
LogPrintf(LogDEBUG, "HangupModem: Script: %s\n", ScriptBuffer);
if (flag ||
LogPrintf(LogDEBUG, "ModemHangup: Script: %s\n", ScriptBuffer);
if (dedicated_force ||
#ifdef notyet
!modem->is_dedicated
#else
@ -826,89 +794,25 @@ CloseLogicalModem(struct physical *modem)
}
}
/*
* Write to modem. Actualy, requested packets are queued, and goes out
* to the line when ModemStartOutput() is called.
*/
void
WriteModem(struct physical *modem, int pri, const char *ptr, int count)
static void
ModemStartOutput(struct link *l)
{
struct mbuf *bp;
assert(pri == PRI_NORMAL || pri == PRI_LINK);
bp = mballoc(count, MB_MODEM);
memcpy(MBUF_CTOP(bp), ptr, count);
/*
* Should be NORMAL and LINK only. All IP frames get here marked NORMAL.
*/
Enqueue(&modem->OutputQueues[pri], bp);
}
void
ModemOutput(struct physical *modem, int pri, struct mbuf * bp)
{
struct mbuf *wp;
int len;
assert(pri == PRI_NORMAL || pri == PRI_LINK);
len = plength(bp);
wp = mballoc(len, MB_MODEM);
mbread(bp, MBUF_CTOP(wp), len);
Enqueue(&modem->OutputQueues[pri], wp);
ModemStartOutput(modem);
}
int
ModemQlen(struct physical *phys)
{
struct mqueue *queue;
int len = 0;
int i;
for (i = PRI_NORMAL; i <= PRI_LINK; i++) {
queue = &phys->OutputQueues[i];
len += queue->qlen;
}
return (len);
}
void
ModemStartOutput(struct physical *modem)
{
struct mqueue *queue;
struct physical *modem = (struct physical *)l;
int nb, nw;
int i;
if (modem->out == NULL) {
if (ModemQlen(modem) == 0)
IpStartOutput(modem);
i = PRI_LINK;
for (queue = &modem->OutputQueues[PRI_LINK]; queue >= &modem->OutputQueues[0]; queue--) {
if (queue->top) {
modem->out = Dequeue(queue);
if (LogIsKept(LogDEBUG)) {
if (i > PRI_NORMAL) {
struct mqueue *q;
if (link_QueueLen(l) == 0)
IpStartOutput(l);
q = &modem->OutputQueues[0];
LogPrintf(LogDEBUG, "ModemStartOutput: Output from queue %d,"
" normal has %d\n", i, q->qlen);
}
LogPrintf(LogDEBUG, "ModemStartOutput: Dequeued %d\n", i);
}
break;
}
i--;
}
modem->out = link_Dequeue(l);
}
if (modem->out) {
nb = modem->out->cnt;
/* Eh ? Removed 980130
if (nb > 1600)
nb = 1600;
*/
nw = write(modem->fd, MBUF_CTOP(modem->out), nb);
LogPrintf(LogDEBUG, "ModemStartOutput: wrote: %d(%d)\n", nw, nb);
LogDumpBuff(LogDEBUG, "ModemStartOutput: modem write",
@ -931,6 +835,12 @@ ModemStartOutput(struct physical *modem)
}
}
static int
ModemIsActive(struct link *l)
{
return ((struct physical *)l)->fd >= 0;
}
int
DialModem(struct physical *modem)
{
@ -961,7 +871,7 @@ DialModem(struct physical *modem)
LogPrintf(LogWARN, "DialModem: dial failed.\n");
excode = EX_NODIAL;
}
HangupModem(modem, 0);
ModemHangup(&modem->link, 0);
return (excode);
}
@ -1013,17 +923,24 @@ ShowModemStatus(struct cmdargs const *arg)
else
fprintf(VarTerm, "outq: ioctl probe failed: %s\n", strerror(errno));
#endif
fprintf(VarTerm, "outqlen: %d\n", ModemQlen(modem));
fprintf(VarTerm, "outqlen: %d\n", link_QueueLen(&modem->link));
fprintf(VarTerm, "DialScript = %s\n", VarDialScript);
fprintf(VarTerm, "LoginScript = %s\n", VarLoginScript);
fprintf(VarTerm, "PhoneNumber(s) = %s\n", VarPhoneList);
fprintf(VarTerm, "\n");
throughput_disp(&modem->throughput, VarTerm);
throughput_disp(&modem->link.throughput, VarTerm);
return 0;
}
int
ReportProtocolStatus(struct cmdargs const *arg)
{
link_ReportProtocolStatus(&phys_modem.link);
return 0;
}
/* Dummy linker functions, to keep this quiet. Might end up a full
regression test later, right now it is just to be able to track

View File

@ -15,7 +15,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* $Id: modem.h,v 1.16 1998/01/21 02:15:23 brian Exp $
* $Id: modem.h,v 1.16.2.1 1998/01/29 00:49:27 brian Exp $
*
* TODO:
*/
@ -23,22 +23,12 @@
struct physical;
extern int RawModem(struct physical *);
extern void WriteModem(struct physical *, int, const char *, int);
extern void ModemStartOutput(struct physical *);
extern int OpenModem(struct physical *);
extern int ModemSpeed(struct physical *);
extern int ModemQlen(struct physical *);
extern int DialModem(struct physical *);
extern speed_t IntToSpeed(int);
extern void ModemTimeout(void *);
extern void DownConnection(void);
extern void ModemOutput(struct physical *modem, int, struct mbuf *);
extern int ChangeParity(struct physical *, const char *);
extern void HangupModem(struct physical *, int);
extern int ShowModemStatus(struct cmdargs const *);
extern void Enqueue(struct mqueue *, struct mbuf *);
extern struct mbuf *Dequeue(struct mqueue *);
extern void SequenceQueues(struct physical *physical);
extern void ModemAddInOctets(struct physical *modem, int);
extern void ModemAddOutOctets(struct physical *modem, int);
extern int ReportProtocolStatus(struct cmdargs const *arg);

View File

@ -18,7 +18,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* $Id: pap.c,v 1.20.2.1 1998/01/29 00:49:27 brian Exp $
* $Id: pap.c,v 1.20.2.2 1998/01/30 01:33:46 brian Exp $
*
* TODO:
*/
@ -84,7 +84,7 @@ SendPapChallenge(int papid, struct physical *physical)
*cp++ = keylen;
memcpy(cp, VarAuthKey, keylen);
HdlcOutput(physical, PRI_LINK, PROTO_PAP, bp);
HdlcOutput(physical2link(physical), PRI_LINK, PROTO_PAP, bp);
}
struct authinfo AuthPapInfo = {
@ -110,7 +110,7 @@ SendPapCode(int id, int code, const char *message, struct physical *physical)
*cp++ = mlen;
memcpy(cp, message, mlen);
LogPrintf(LogPHASE, "PapOutput: %s\n", papcodes[code]);
HdlcOutput(physical, PRI_LINK, PROTO_PAP, bp);
HdlcOutput(physical2link(physical), PRI_LINK, PROTO_PAP, bp);
}
/*

View File

@ -23,13 +23,14 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: phase.c,v 1.6.4.2 1998/01/29 23:11:41 brian Exp $
* $Id: phase.c,v 1.6.4.3 1998/01/30 01:33:46 brian Exp $
*/
#include <sys/param.h>
#include <netinet/in.h>
#include <stdio.h>
#include <termios.h>
#include "command.h"
#include "mbuf.h"
@ -43,11 +44,15 @@
#include "defs.h"
#include "iplist.h"
#include "throughput.h"
#include "hdlc.h"
#include "link.h"
#include "ipcp.h"
#include "ccp.h"
#include "main.h"
#include "loadalias.h"
#include "vars.h"
#include "modem.h"
#include "tun.h"
#include "phase.h"
int phase = 0; /* Curent phase */
@ -90,12 +95,15 @@ NewPhase(struct physical *physical, int new)
} else
NewPhase(physical, PHASE_NETWORK);
break;
case PHASE_NETWORK:
tun_configure(LcpInfo.his_mru, ModemSpeed(physical));
IpcpUp();
IpcpOpen();
CcpUp();
CcpOpen();
break;
case PHASE_DEAD:
if (mode & MODE_DIRECT)
Cleanup(EX_DEAD);

View File

@ -16,7 +16,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* $Id$
* $Id: physical.c,v 1.1.2.1 1998/01/29 00:49:29 brian Exp $
*
*/
@ -44,6 +44,7 @@
#include "hdlc.h"
#include "timer.h"
#include "throughput.h"
#include "link.h"
#define PHYSICAL_DEVICE
#include "physical.h"
@ -65,11 +66,6 @@ Physical_IsATTY(struct physical *phys) {
return isatty(phys->fd);
}
int
Physical_IsActive(struct physical *phys) {
return phys->fd >= 0;
}
int
Physical_IsSync(struct physical *phys) {
return phys->speed == 0;

View File

@ -16,44 +16,41 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* $Id$
* $Id: physical.h,v 1.1.2.1 1998/01/29 00:49:30 brian Exp $
*
*/
struct physical;
#ifdef PHYSICAL_DEVICE
struct physical {
int fd; /* File descriptor for this device */
int mbits; /* Current DCD status */
unsigned dev_is_modem : 1; /* Is the device an actual modem?
Faked for sync devices, though...
(Possibly this should be
dev_is_not_tcp?) XXX-ML */
struct link link;
int fd; /* File descriptor for this device */
int mbits; /* Current DCD status */
unsigned dev_is_modem : 1; /* Is the device an actual modem?
Faked for sync devices, though...
(Possibly this should be
dev_is_not_tcp?) XXX-ML */
unsigned is_dedicated : 1; /* Dedicated mode? XXX-ML - not yet initialized */
unsigned is_direct : 1; /* Direct mode? XXX-ML - not yet initialized */
struct pppThroughput throughput;
struct mbuf *out;
int connect_count;
struct pppTimer DeviceTimer; /* Was ModemTimer */
unsigned is_dedicated : 1; /* Dedicated mode? XXX-ML - not yet initialized */
unsigned is_direct : 1; /* Direct mode? XXX-ML - not yet initialized */
struct mbuf *out;
int connect_count;
/* XXX Shouldn't be tied up to a specific number like this. -EE. */
struct mqueue OutputQueues[PRI_LINK + 1];
/* XXX-ML Most of the below is device specific, and probably do not
/* XXX-ML Most of the below is device specific, and probably do not
belong in the generic physical struct. It comes from modem.c. */
unsigned rts_cts : 1; /* Is rts/cts enabled? */
unsigned int parity; /* What parity is enabled? (TTY flags) */
unsigned int speed; /* Modem speed */
struct termios ios; /* To be able to reset from raw mode */
unsigned rts_cts : 1; /* Is rts/cts enabled? */
unsigned int parity; /* What parity is enabled? (TTY flags) */
unsigned int speed; /* Modem speed */
struct termios ios; /* To be able to reset from raw mode */
};
#else
struct physical;
#endif
#define physical2link(p) ((struct link *)p)
#define link2physical(l) (l->type == PHYSICAL_LINK ? (struct physical *)l : 0)
int Physical_GetFD(struct physical *);
int Physical_IsATTY(struct physical *);
int Physical_IsActive(struct physical *);
int Physical_IsSync(struct physical *);
int Physical_IsDedicated(struct physical *phys);
int Physical_IsDirect(struct physical *phys);
@ -68,8 +65,8 @@ Physical_SetSpeed(struct physical *phys, int speed);
can solve that later. */
void Physical_SetSync(struct physical *phys);
int /* Can this be set? (Might not be a relevant attribute for this
device, for instance) */
int /* Can this be set? (Might not be a relevant attribute for this
device, for instance) */
Physical_SetRtsCts(struct physical *phys, int enable);
void Physical_SetDedicated(struct physical *phys, int enable);

View File

@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: pred.c,v 1.20 1998/01/14 01:47:50 brian Exp $
* $Id: pred.c,v 1.20.2.1 1998/01/29 00:49:30 brian Exp $
*/
#include <sys/param.h>
@ -48,6 +48,8 @@
#include "lcpproto.h"
#include "lcp.h"
#include "ccp.h"
#include "throughput.h"
#include "link.h"
#include "pred.h"
/* The following hash code is the heart of the algorithm:
@ -182,8 +184,7 @@ Pred1InitOutput(void)
}
static int
Pred1Output(struct physical *physical, int pri, u_short proto,
struct mbuf * bp)
Pred1Output(struct link *l, int pri, u_short proto, struct mbuf * bp)
{
struct mbuf *mwp;
u_char *cp, *wp, *hp;
@ -219,7 +220,7 @@ Pred1Output(struct physical *physical, int pri, u_short proto,
*wp++ = fcs & 0377;
*wp++ = fcs >> 8;
mwp->cnt = wp - MBUF_CTOP(mwp);
HdlcOutput(physical, PRI_NORMAL, PROTO_COMPD, mwp);
HdlcOutput(l, PRI_NORMAL, PROTO_COMPD, mwp);
return 1;
}

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 1998/01/21 02:15:26 brian Exp $
* $Id: route.c,v 1.42.2.1 1998/01/29 23:11:42 brian Exp $
*
*/
@ -51,6 +51,8 @@
#include "iplist.h"
#include "timer.h"
#include "throughput.h"
#include "hdlc.h"
#include "link.h"
#include "ipcp.h"
#include "route.h"

View File

@ -17,7 +17,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* $Id: vjcomp.c,v 1.16.2.1 1998/01/29 00:49:32 brian Exp $
* $Id: vjcomp.c,v 1.16.2.2 1998/01/29 23:11:44 brian Exp $
*
* TODO:
*/
@ -54,7 +54,7 @@ VjInit(int max_state)
}
void
SendPppFrame(struct physical *physical, struct mbuf * bp)
SendPppFrame(struct link *l, struct mbuf * bp)
{
int type;
u_short proto;
@ -83,7 +83,7 @@ SendPppFrame(struct physical *physical, struct mbuf * bp)
}
} else
proto = PROTO_IP;
HdlcOutput(physical, PRI_NORMAL, proto, bp);
HdlcOutput(l, PRI_NORMAL, proto, bp);
}
static struct mbuf *

View File

@ -23,12 +23,10 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* $Id: vjcomp.h,v 1.5 1998/01/11 17:50:49 brian Exp $
* $Id: vjcomp.h,v 1.5.4.1 1998/01/29 00:49:32 brian Exp $
*/
struct physical;
extern void VjInit(int);
extern void SendPppFrame(struct physical *physical, struct mbuf *);
extern void SendPppFrame(struct link *, struct mbuf *);
extern struct mbuf *VjCompInput(struct mbuf *, int);
extern const char *vj2asc(u_int32_t);