o Create `struct hdlc' - a part of struct physical.

o Move our LCP report timer into struct hdlc - it's really
  a hdlc timer (fcs errors etc).
o Make `show hdlc' require context and make the output more
  friendly.
o Remove all non-const globals from hdlc.c
o Output peer-rejected protocols by name - not just ones
  that we reject.
This commit is contained in:
Brian Somers 1998-02-18 19:35:59 +00:00
parent 9991562d36
commit 63258dccc5
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/cvs2svn/branches/MP/; revision=33582
10 changed files with 116 additions and 95 deletions

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.25 1998/02/17 19:28:42 brian Exp $
* $Id: command.c,v 1.131.2.26 1998/02/18 19:35:14 brian Exp $
*
*/
#include <sys/param.h>
@ -582,7 +582,7 @@ static struct cmdtab const ShowCommands[] = {
"Show Demand filters", "show dfilteroption .."},
{"escape", NULL, ShowEscape, LOCAL_AUTH | LOCAL_CX,
"Show escape characters", "show escape"},
{"hdlc", NULL, ReportHdlcStatus, LOCAL_AUTH,
{"hdlc", NULL, hdlc_ReportStatus, LOCAL_AUTH | LOCAL_CX,
"Show HDLC errors", "show hdlc"},
{"ifilter", NULL, ShowIfilter, LOCAL_AUTH,
"Show Input filters", "show ifilter option .."},

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.3 1998/01/30 19:45:33 brian Exp $
* $Id: deflate.c,v 1.6.4.4 1998/01/31 02:48:17 brian Exp $
*/
#include <sys/param.h>
@ -39,8 +39,8 @@
#include "defs.h"
#include "loadalias.h"
#include "vars.h"
#include "hdlc.h"
#include "timer.h"
#include "hdlc.h"
#include "fsm.h"
#include "lcp.h"
#include "ccp.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.2.9 1998/02/09 19:20:45 brian Exp $
* $Id: fsm.c,v 1.27.2.10 1998/02/16 00:00:07 brian Exp $
*
* TODO:
* o Refer loglevel for log output
@ -689,7 +689,8 @@ FsmRecvProtoRej(struct fsm *fp, struct fsmheader *lhp, struct mbuf *bp)
sp = (u_short *) MBUF_CTOP(bp);
proto = ntohs(*sp);
LogPrintf(fp->LogLevel, "-- Protocol (%04x) was rejected.\n", proto);
LogPrintf(fp->LogLevel, "-- Protocol 0x%04x (%s) was rejected.\n",
proto, hdlc_Protocol2Nam(proto));
switch (proto) {
case PROTO_LQR:

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.9 1998/02/10 03:23:19 brian Exp $
* $Id: hdlc.c,v 1.28.2.10 1998/02/18 19:35:17 brian Exp $
*
* TODO:
*/
@ -54,17 +54,8 @@
#include "descriptor.h"
#include "physical.h"
#include "prompt.h"
static struct hdlcstat {
int badfcs;
int badaddr;
int badcommand;
int unknownproto;
} HdlcStat;
static int ifOutPackets;
static int ifOutOctets;
static int ifOutLQRs;
#include "chat.h"
#include "datalink.h"
static u_short const fcstab[256] = {
/* 00 */ 0x0000, 0x1189, 0x2312, 0x329b, 0x4624, 0x57ad, 0x6536, 0x74bf,
@ -102,11 +93,9 @@ static u_short const fcstab[256] = {
};
void
HdlcInit()
hdlc_Init(struct hdlc *hdlc)
{
ifOutOctets = 0;
ifOutPackets = 0;
ifOutLQRs = 0;
memset(hdlc, '\0', sizeof(struct hdlc));
}
/*
@ -200,9 +189,9 @@ HdlcOutput(struct link *l, int pri, u_short proto, struct mbuf *bp)
bp = mhp->next;
lqr = &MyLqrData;
lqr->PeerOutPackets = ifOutPackets++;
ifOutOctets += plength(mhp) + 1;
lqr->PeerOutOctets = ifOutOctets;
lqr->PeerOutPackets = p->hdlc.lqr.OutPackets++;
p->hdlc.lqr.OutOctets += plength(mhp) + 1;
lqr->PeerOutOctets = p->hdlc.lqr.OutOctets;
if (proto == PROTO_LQR) {
lqr->MagicNumber = LcpInfo.want_magic;
@ -214,7 +203,7 @@ HdlcOutput(struct link *l, int pri, u_short proto, struct mbuf *bp)
lqr->PeerInDiscards = HisLqrSave.SaveInDiscards;
lqr->PeerInErrors = HisLqrSave.SaveInErrors;
lqr->PeerInOctets = HisLqrSave.SaveInOctets;
lqr->PeerOutLQRs = ++ifOutLQRs;
lqr->PeerOutLQRs = ++p->hdlc.lqr.OutLQRs;
LqrDump("LqrOutput", lqr);
LqrChangeOrder(lqr, (struct lqrdata *) (MBUF_CTOP(bp)));
}
@ -353,8 +342,8 @@ static struct {
#define NPROTOCOLS (sizeof protocols/sizeof protocols[0])
static const char *
Protocol2Nam(u_short proto)
const char *
hdlc_Protocol2Nam(u_short proto)
{
int f;
@ -432,43 +421,18 @@ DecodePacket(struct bundle *bundle, u_short proto, struct mbuf * bp,
break;
default:
LogPrintf(LogPHASE, "Unknown protocol 0x%04x (%s)\n",
proto, Protocol2Nam(proto));
proto, hdlc_Protocol2Nam(proto));
bp->offset -= 2;
bp->cnt += 2;
cp = MBUF_CTOP(bp);
LcpSendProtoRej(cp, bp->cnt);
HisLqrSave.SaveInDiscards++;
HdlcStat.unknownproto++;
p->hdlc.stats.unknownproto++;
pfree(bp);
break;
}
}
int
ReportHdlcStatus(struct cmdargs const *arg)
{
prompt_Printf(&prompt, "HDLC level errors\n\n");
prompt_Printf(&prompt, "FCS: %u ADDR: %u COMMAND: %u PROTO: %u\n",
HdlcStat.badfcs, HdlcStat.badaddr,
HdlcStat.badcommand, HdlcStat.unknownproto);
return 0;
}
static struct hdlcstat laststat;
void
HdlcErrorCheck()
{
if (memcmp(&HdlcStat, &laststat, sizeof laststat)) {
LogPrintf(LogPHASE, "HDLC errors -> FCS: %u ADDR: %u COMD: %u PROTO: %u\n",
HdlcStat.badfcs - laststat.badfcs,
HdlcStat.badaddr - laststat.badaddr,
HdlcStat.badcommand - laststat.badcommand,
HdlcStat.unknownproto - laststat.unknownproto);
laststat = HdlcStat;
}
}
void
HdlcInput(struct bundle *bundle, struct mbuf * bp, struct physical *physical)
{
@ -487,7 +451,7 @@ HdlcInput(struct bundle *bundle, struct mbuf * bp, struct physical *physical)
if (fcs != GOODFCS) {
HisLqrSave.SaveInErrors++;
LogPrintf(LogDEBUG, "HdlcInput: Bad FCS\n");
HdlcStat.badfcs++;
physical->hdlc.stats.badfcs++;
pfree(bp);
return;
}
@ -508,7 +472,7 @@ HdlcInput(struct bundle *bundle, struct mbuf * bp, struct physical *physical)
addr = *cp++;
if (addr != HDLC_ADDR) {
HisLqrSave.SaveInErrors++;
HdlcStat.badaddr++;
physical->hdlc.stats.badaddr++;
LogPrintf(LogDEBUG, "HdlcInput: addr %02x\n", *cp);
pfree(bp);
return;
@ -516,7 +480,7 @@ HdlcInput(struct bundle *bundle, struct mbuf * bp, struct physical *physical)
ctrl = *cp++;
if (ctrl != HDLC_UI) {
HisLqrSave.SaveInErrors++;
HdlcStat.badcommand++;
physical->hdlc.stats.badcommand++;
LogPrintf(LogDEBUG, "HdlcInput: %02x\n", *cp);
pfree(bp);
return;
@ -586,3 +550,57 @@ HdlcDetect(struct physical *physical, u_char *cp, int n)
}
return (u_char *)ptr;
}
int
hdlc_ReportStatus(struct cmdargs const *arg)
{
prompt_Printf(&prompt, "HDLC level errors:\n");
prompt_Printf(&prompt, " Bad Frame Check Sequence fields: %u\n",
arg->cx->physical->hdlc.stats.badfcs);
prompt_Printf(&prompt, " Bad address (!= 0x%02x) fields: %u\n",
HDLC_ADDR, arg->cx->physical->hdlc.stats.badaddr);
prompt_Printf(&prompt, " Bad command (!= 0x%02x) fields: %u\n",
HDLC_UI, arg->cx->physical->hdlc.stats.badcommand);
prompt_Printf(&prompt, " Unrecognised protocol fields: %u\n",
arg->cx->physical->hdlc.stats.unknownproto);
return 0;
}
static void
hdlc_ReportTime(void *v)
{
/* Moan about HDLC errors */
struct hdlc *hdlc = (struct hdlc *)v;
StopTimer(&hdlc->ReportTimer);
hdlc->ReportTimer.state = TIMER_STOPPED;
if (memcmp(&hdlc->laststats, &hdlc->stats, sizeof hdlc->stats)) {
LogPrintf(LogPHASE,
"HDLC errors -> FCS: %u, ADDR: %u, COMD: %u, PROTO: %u\n",
hdlc->stats.badfcs - hdlc->laststats.badfcs,
hdlc->stats.badaddr - hdlc->laststats.badaddr,
hdlc->stats.badcommand - hdlc->laststats.badcommand,
hdlc->stats.unknownproto - hdlc->laststats.unknownproto);
hdlc->laststats = hdlc->stats;
}
StartTimer(&hdlc->ReportTimer);
}
void
hdlc_StartTimer(struct hdlc *hdlc)
{
StopTimer(&hdlc->ReportTimer);
hdlc->ReportTimer.state = TIMER_STOPPED;
hdlc->ReportTimer.load = 60 * SECTICKS;
hdlc->ReportTimer.arg = hdlc;
hdlc->ReportTimer.func = hdlc_ReportTime;
StartTimer(&hdlc->ReportTimer);
}
void
hdlc_StopTimer(struct hdlc *hdlc)
{
StopTimer(&hdlc->ReportTimer);
}

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.2.4 1998/02/09 19:20:49 brian Exp $
* $Id: hdlc.h,v 1.14.2.5 1998/02/18 19:35:20 brian Exp $
*
* TODO:
*/
@ -59,11 +59,32 @@
struct physical;
struct link;
extern void HdlcInit(void);
extern void HdlcErrorCheck(void);
struct hdlc {
struct pppTimer ReportTimer;
struct {
int badfcs;
int badaddr;
int badcommand;
int unknownproto;
} laststats, stats;
struct {
int OutPackets;
int OutOctets;
int OutLQRs;
} lqr;
};
extern void hdlc_Init(struct hdlc *);
extern void hdlc_StartTimer(struct hdlc *);
extern void hdlc_StopTimer(struct hdlc *);
extern int hdlc_ReportStatus(struct cmdargs const *);
extern const char *hdlc_Protocol2Nam(u_short);
extern void HdlcInput(struct bundle *, struct mbuf *, struct physical *);
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 *);
extern u_char *HdlcDetect(struct physical *, u_char *, 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.15 1998/02/16 00:00:15 brian Exp $
* $Id: lcp.c,v 1.55.2.16 1998/02/17 19:29:11 brian Exp $
*
* TODO:
* o Limit data field length by MRU
@ -147,22 +147,6 @@ static const char *cftypes[] = {
#define NCFTYPES (sizeof cftypes/sizeof cftypes[0])
static void
LcpReportTime(void *v)
{
/* Moan about HDLC errors */
struct pppTimer *ReportTimer = (struct pppTimer *)v;
if (LogIsKept(LogDEBUG)) {
time_t t = time(NULL);
LogPrintf(LogDEBUG, "LcpReportTime: %s\n", ctime(&t));
}
StopTimer(ReportTimer);
ReportTimer->state = TIMER_STOPPED;
StartTimer(ReportTimer);
HdlcErrorCheck();
}
int
ReportLcpStatus(struct cmdargs const *arg)
{
@ -203,7 +187,7 @@ LcpInit(struct bundle *bundle, struct physical *physical)
{
/* Initialise ourselves */
FsmInit(&LcpInfo.fsm, bundle, physical2link(physical));
HdlcInit();
hdlc_Init(&physical->hdlc);
async_Init(&physical->async);
LcpInfo.his_mru = DEF_MRU;
@ -225,7 +209,6 @@ LcpInit(struct bundle *bundle, struct physical *physical)
LcpInfo.his_reject = LcpInfo.my_reject = 0;
LcpInfo.auth_iwait = LcpInfo.auth_ineed = 0;
memset(&LcpInfo.ReportTimer, '\0', sizeof LcpInfo.ReportTimer);
LcpInfo.fsm.maxconfig = 10;
}
@ -401,7 +384,6 @@ LcpLayerStart(struct fsm *fp)
static void
StopAllTimers(void)
{
StopTimer(&LcpInfo.ReportTimer);
StopIdleTimer();
StopTimer(&AuthPapInfo.authtimer);
StopTimer(&AuthChapInfo.authtimer);
@ -429,22 +411,19 @@ LcpLayerUp(struct fsm *fp)
if (p) {
async_SetLinkParams(&p->async, lcp);
StartLqm(p);
hdlc_StartTimer(&p->hdlc);
} else
LogPrintf(LogERROR, "LcpLayerUp: Not a physical link !\n");
StopTimer(&lcp->ReportTimer);
lcp->ReportTimer.state = TIMER_STOPPED;
lcp->ReportTimer.load = 60 * SECTICKS;
lcp->ReportTimer.arg = &lcp->ReportTimer;
lcp->ReportTimer.func = LcpReportTime;
StartTimer(&lcp->ReportTimer);
}
static void
LcpLayerDown(struct fsm *fp)
{
/* About to come down */
struct physical *p = link2physical(fp->link);
LogPrintf(LogLCP, "LcpLayerDown\n");
hdlc_StopTimer(&p->hdlc);
}
static void

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.5 1998/02/10 03:23:24 brian Exp $
* $Id: link.c,v 1.1.2.6 1998/02/16 00:00:22 brian Exp $
*
*/
@ -37,8 +37,8 @@
#include "mbuf.h"
#include "log.h"
#include "defs.h"
#include "hdlc.h"
#include "timer.h"
#include "hdlc.h"
#include "throughput.h"
#include "lcpproto.h"
#include "loadalias.h"

View File

@ -16,7 +16,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* $Id: physical.c,v 1.1.2.9 1998/02/16 00:00:56 brian Exp $
* $Id: physical.c,v 1.1.2.10 1998/02/17 19:29:02 brian Exp $
*
*/
@ -41,8 +41,8 @@
#include "mbuf.h"
/* Name space pollution for physical.h */
#include "hdlc.h"
#include "timer.h"
#include "hdlc.h"
#include "throughput.h"
#include "fsm.h"
#include "lcp.h"

View File

@ -16,7 +16,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
* $Id: physical.h,v 1.1.2.8 1998/02/13 05:10:22 brian Exp $
* $Id: physical.h,v 1.1.2.9 1998/02/17 19:29:03 brian Exp $
*
*/
@ -24,6 +24,7 @@ struct physical {
struct link link;
struct descriptor desc;
struct async async; /* Our async state */
struct hdlc hdlc; /* Our hdlc state */
int fd; /* File descriptor for this device */
int mbits; /* Current DCD status */
unsigned abort : 1; /* Something's gone horribly wrong */

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 1998/01/21 02:15:30 brian Exp $
* $Id: tun.c,v 1.6.4.1 1998/02/02 19:32:16 brian Exp $
*/
#include <sys/param.h>
@ -41,6 +41,7 @@
#include "command.h"
#include "mbuf.h"
#include "log.h"
#include "timer.h"
#include "hdlc.h"
#include "defs.h"
#include "loadalias.h"