1995-01-31 06:29:58 +00:00
|
|
|
/*
|
|
|
|
* PPP Line Quality Monitoring (LQM) Module
|
|
|
|
*
|
|
|
|
* Written by Toshiharu OHNO (tony-o@iij.ad.jp)
|
|
|
|
*
|
|
|
|
* Copyright (C) 1993, Internet Initiative Japan, Inc. All rights reserverd.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms are permitted
|
|
|
|
* provided that the above copyright notice and this paragraph are
|
|
|
|
* duplicated in all such forms and that any documentation,
|
|
|
|
* advertising materials, and other materials related to such
|
|
|
|
* distribution and use acknowledge that the software was developed
|
|
|
|
* by the Internet Initiative Japan, Inc. The name of the
|
|
|
|
* IIJ may not be used to endorse or promote products derived
|
|
|
|
* from this software without specific prior written permission.
|
|
|
|
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
|
|
|
|
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
|
|
|
|
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
*
|
1997-11-22 03:37:54 +00:00
|
|
|
* $Id: lqr.c,v 1.19 1997/10/26 01:03:08 brian Exp $
|
1995-05-30 03:57:47 +00:00
|
|
|
*
|
1995-02-26 12:18:08 +00:00
|
|
|
* o LQR based on RFC1333
|
1995-01-31 06:29:58 +00:00
|
|
|
*
|
|
|
|
* TODO:
|
|
|
|
* o LQM policy
|
|
|
|
* o Allow user to configure LQM method and interval.
|
|
|
|
*/
|
1997-10-26 01:04:02 +00:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <netinet/in.h>
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
1997-11-22 03:37:54 +00:00
|
|
|
#include "command.h"
|
1997-10-26 01:04:02 +00:00
|
|
|
#include "mbuf.h"
|
|
|
|
#include "log.h"
|
|
|
|
#include "defs.h"
|
|
|
|
#include "timer.h"
|
1995-01-31 06:29:58 +00:00
|
|
|
#include "fsm.h"
|
|
|
|
#include "lcpproto.h"
|
|
|
|
#include "lqr.h"
|
|
|
|
#include "hdlc.h"
|
|
|
|
#include "lcp.h"
|
1997-05-26 00:44:10 +00:00
|
|
|
#include "loadalias.h"
|
1995-01-31 06:29:58 +00:00
|
|
|
#include "vars.h"
|
1996-01-11 17:48:59 +00:00
|
|
|
#include "main.h"
|
1995-01-31 06:29:58 +00:00
|
|
|
|
|
|
|
struct pppTimer LqrTimer;
|
|
|
|
|
1997-08-25 00:29:32 +00:00
|
|
|
static u_long lastpeerin = (u_long) - 1;
|
1995-01-31 06:29:58 +00:00
|
|
|
|
|
|
|
static int lqmmethod;
|
|
|
|
static int echoseq;
|
|
|
|
static int gotseq;
|
|
|
|
static int lqrsendcnt;
|
|
|
|
|
|
|
|
struct echolqr {
|
|
|
|
u_long magic;
|
|
|
|
u_long signature;
|
|
|
|
u_long sequence;
|
|
|
|
};
|
|
|
|
|
|
|
|
#define SIGNATURE 0x594e4f54
|
|
|
|
|
|
|
|
static void
|
1997-11-22 03:37:54 +00:00
|
|
|
SendEchoReq(void)
|
1995-01-31 06:29:58 +00:00
|
|
|
{
|
|
|
|
struct fsm *fp = &LcpFsm;
|
|
|
|
struct echolqr *lqr, lqrdata;
|
|
|
|
|
|
|
|
if (fp->state == ST_OPENED) {
|
|
|
|
lqr = &lqrdata;
|
|
|
|
lqr->magic = htonl(LcpInfo.want_magic);
|
|
|
|
lqr->signature = htonl(SIGNATURE);
|
1997-06-09 03:27:43 +00:00
|
|
|
LogPrintf(LogLQM, "Send echo LQR [%d]\n", echoseq);
|
1995-01-31 06:29:58 +00:00
|
|
|
lqr->sequence = htonl(echoseq++);
|
|
|
|
FsmOutput(fp, CODE_ECHOREQ, fp->reqid++,
|
1997-08-25 00:29:32 +00:00
|
|
|
(u_char *) lqr, sizeof(struct echolqr));
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1997-08-25 00:29:32 +00:00
|
|
|
RecvEchoLqr(struct mbuf * bp)
|
1995-01-31 06:29:58 +00:00
|
|
|
{
|
|
|
|
struct echolqr *lqr;
|
|
|
|
u_long seq;
|
|
|
|
|
|
|
|
if (plength(bp) == sizeof(struct echolqr)) {
|
1997-08-25 00:29:32 +00:00
|
|
|
lqr = (struct echolqr *) MBUF_CTOP(bp);
|
1995-01-31 06:29:58 +00:00
|
|
|
if (htonl(lqr->signature) == SIGNATURE) {
|
|
|
|
seq = ntohl(lqr->sequence);
|
1997-06-09 03:27:43 +00:00
|
|
|
LogPrintf(LogLQM, "Got echo LQR [%d]\n", ntohl(lqr->sequence));
|
1995-01-31 06:29:58 +00:00
|
|
|
gotseq = seq;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1997-08-25 00:29:32 +00:00
|
|
|
LqrChangeOrder(struct lqrdata * src, struct lqrdata * dst)
|
1995-01-31 06:29:58 +00:00
|
|
|
{
|
|
|
|
u_long *sp, *dp;
|
|
|
|
int n;
|
|
|
|
|
1997-08-25 00:29:32 +00:00
|
|
|
sp = (u_long *) src;
|
|
|
|
dp = (u_long *) dst;
|
|
|
|
for (n = 0; n < sizeof(struct lqrdata) / sizeof(u_long); n++)
|
1995-01-31 06:29:58 +00:00
|
|
|
*dp++ = ntohl(*sp++);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
1997-11-22 03:37:54 +00:00
|
|
|
SendLqrReport(void *v)
|
1995-01-31 06:29:58 +00:00
|
|
|
{
|
|
|
|
struct mbuf *bp;
|
|
|
|
|
|
|
|
StopTimer(&LqrTimer);
|
|
|
|
|
|
|
|
if (lqmmethod & LQM_LQR) {
|
|
|
|
if (lqrsendcnt > 5) {
|
1997-08-25 00:29:32 +00:00
|
|
|
|
1995-01-31 06:29:58 +00:00
|
|
|
/*
|
|
|
|
* XXX: Should implement LQM strategy
|
|
|
|
*/
|
1997-06-09 03:27:43 +00:00
|
|
|
LogPrintf(LogPHASE, "** 1 Too many ECHO packets are lost. **\n");
|
1997-08-25 00:29:32 +00:00
|
|
|
lqmmethod = 0; /* Prevent rcursion via LcpClose() */
|
1997-05-24 17:32:42 +00:00
|
|
|
reconnect(RECON_TRUE);
|
1995-01-31 06:29:58 +00:00
|
|
|
LcpClose();
|
|
|
|
} else {
|
|
|
|
bp = mballoc(sizeof(struct lqrdata), MB_LQR);
|
1996-01-30 11:08:50 +00:00
|
|
|
HdlcOutput(PRI_LINK, PROTO_LQR, bp);
|
1995-01-31 06:29:58 +00:00
|
|
|
lqrsendcnt++;
|
|
|
|
}
|
|
|
|
} else if (lqmmethod & LQM_ECHO) {
|
|
|
|
if (echoseq - gotseq > 5) {
|
1997-06-09 03:27:43 +00:00
|
|
|
LogPrintf(LogPHASE, "** 2 Too many ECHO packets are lost. **\n");
|
1997-08-25 00:29:32 +00:00
|
|
|
lqmmethod = 0; /* Prevent rcursion via LcpClose() */
|
1997-05-24 17:32:42 +00:00
|
|
|
reconnect(RECON_TRUE);
|
1995-01-31 06:29:58 +00:00
|
|
|
LcpClose();
|
|
|
|
} else
|
|
|
|
SendEchoReq();
|
|
|
|
}
|
|
|
|
if (lqmmethod && Enabled(ConfLqr))
|
|
|
|
StartTimer(&LqrTimer);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1997-08-25 00:29:32 +00:00
|
|
|
LqrInput(struct mbuf * bp)
|
1995-01-31 06:29:58 +00:00
|
|
|
{
|
|
|
|
int len;
|
|
|
|
u_char *cp;
|
|
|
|
struct lqrdata *lqr;
|
|
|
|
|
|
|
|
len = plength(bp);
|
|
|
|
if (len != sizeof(struct lqrdata)) {
|
|
|
|
pfree(bp);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!Acceptable(ConfLqr)) {
|
|
|
|
bp->offset -= 2;
|
|
|
|
bp->cnt += 2;
|
|
|
|
|
|
|
|
cp = MBUF_CTOP(bp);
|
|
|
|
LcpSendProtoRej(cp, bp->cnt);
|
|
|
|
} else {
|
|
|
|
cp = MBUF_CTOP(bp);
|
1997-08-25 00:29:32 +00:00
|
|
|
lqr = (struct lqrdata *) cp;
|
1995-01-31 06:29:58 +00:00
|
|
|
if (ntohl(lqr->MagicNumber) != LcpInfo.his_magic) {
|
1997-06-09 03:27:43 +00:00
|
|
|
LogPrintf(LogERROR, "LqrInput: magic %x != expecting %x\n",
|
1997-08-25 00:29:32 +00:00
|
|
|
ntohl(lqr->MagicNumber), LcpInfo.his_magic);
|
1995-01-31 06:29:58 +00:00
|
|
|
pfree(bp);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Convert byte order and save into our strage
|
|
|
|
*/
|
|
|
|
LqrChangeOrder(lqr, &HisLqrData);
|
|
|
|
LqrDump("LqrInput", &HisLqrData);
|
1997-08-25 00:29:32 +00:00
|
|
|
lqrsendcnt = 0; /* we have received LQR from peer */
|
1995-01-31 06:29:58 +00:00
|
|
|
|
|
|
|
/*
|
1997-08-25 00:29:32 +00:00
|
|
|
* Generate LQR responce to peer, if i) We are not running LQR timer. ii)
|
|
|
|
* Two successive LQR's PeerInLQRs are same.
|
1995-01-31 06:29:58 +00:00
|
|
|
*/
|
|
|
|
if (LqrTimer.load == 0 || lastpeerin == HisLqrData.PeerInLQRs) {
|
|
|
|
lqmmethod |= LQM_LQR;
|
1997-11-22 03:37:54 +00:00
|
|
|
SendLqrReport(0);
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
lastpeerin = HisLqrData.PeerInLQRs;
|
|
|
|
}
|
|
|
|
pfree(bp);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* When LCP is reached to opened state, We'll start LQM activity.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
StartLqm()
|
|
|
|
{
|
|
|
|
struct lcpstate *lcp = &LcpInfo;
|
|
|
|
int period;
|
|
|
|
|
1997-08-25 00:29:32 +00:00
|
|
|
lqrsendcnt = 0; /* start waiting all over for ECHOs */
|
1997-07-02 19:18:42 +00:00
|
|
|
echoseq = 0;
|
|
|
|
gotseq = 0;
|
1997-08-25 00:29:32 +00:00
|
|
|
|
1995-01-31 06:29:58 +00:00
|
|
|
lqmmethod = LQM_ECHO;
|
|
|
|
if (Enabled(ConfLqr))
|
|
|
|
lqmmethod |= LQM_LQR;
|
|
|
|
StopTimer(&LqrTimer);
|
1997-06-09 03:27:43 +00:00
|
|
|
LogPrintf(LogLQM, "LQM method = %d\n", lqmmethod);
|
1995-01-31 06:29:58 +00:00
|
|
|
|
|
|
|
if (lcp->his_lqrperiod || lcp->want_lqrperiod) {
|
1997-08-25 00:29:32 +00:00
|
|
|
|
1995-01-31 06:29:58 +00:00
|
|
|
/*
|
1997-08-25 00:29:32 +00:00
|
|
|
* We need to run timer. Let's figure out period.
|
1995-01-31 06:29:58 +00:00
|
|
|
*/
|
|
|
|
period = lcp->his_lqrperiod ? lcp->his_lqrperiod : lcp->want_lqrperiod;
|
|
|
|
StopTimer(&LqrTimer);
|
|
|
|
LqrTimer.state = TIMER_STOPPED;
|
|
|
|
LqrTimer.load = period * SECTICKS / 100;
|
|
|
|
LqrTimer.func = SendLqrReport;
|
1997-11-22 03:37:54 +00:00
|
|
|
SendLqrReport(0);
|
1995-01-31 06:29:58 +00:00
|
|
|
StartTimer(&LqrTimer);
|
1997-06-09 03:27:43 +00:00
|
|
|
LogPrintf(LogLQM, "Will send LQR every %d.%d secs\n",
|
1997-08-25 00:29:32 +00:00
|
|
|
period / 100, period % 100);
|
1995-01-31 06:29:58 +00:00
|
|
|
} else {
|
1997-06-09 03:27:43 +00:00
|
|
|
LogPrintf(LogLQM, "LQR is not activated.\n");
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1996-01-30 11:08:50 +00:00
|
|
|
void
|
1997-08-25 00:29:32 +00:00
|
|
|
StopLqrTimer()
|
1996-01-30 11:08:50 +00:00
|
|
|
{
|
1997-08-25 00:29:32 +00:00
|
|
|
StopTimer(&LqrTimer);
|
1996-01-30 11:08:50 +00:00
|
|
|
}
|
|
|
|
|
1995-01-31 06:29:58 +00:00
|
|
|
void
|
1997-08-25 00:29:32 +00:00
|
|
|
StopLqr(int method)
|
1995-01-31 06:29:58 +00:00
|
|
|
{
|
1997-06-09 03:27:43 +00:00
|
|
|
LogPrintf(LogLQM, "StopLqr method = %x\n", method);
|
1995-01-31 06:29:58 +00:00
|
|
|
|
|
|
|
if (method == LQM_LQR)
|
1997-06-09 03:27:43 +00:00
|
|
|
LogPrintf(LogLQM, "Stop sending LQR, Use LCP ECHO instead.\n");
|
1995-01-31 06:29:58 +00:00
|
|
|
if (method == LQM_ECHO)
|
1997-06-09 03:27:43 +00:00
|
|
|
LogPrintf(LogLQM, "Stop sending LCP ECHO.\n");
|
1995-01-31 06:29:58 +00:00
|
|
|
lqmmethod &= ~method;
|
|
|
|
if (lqmmethod)
|
1997-11-22 03:37:54 +00:00
|
|
|
SendLqrReport(0);
|
1995-01-31 06:29:58 +00:00
|
|
|
else
|
|
|
|
StopTimer(&LqrTimer);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1997-11-22 03:37:54 +00:00
|
|
|
LqrDump(const char *message, const struct lqrdata * lqr)
|
1995-01-31 06:29:58 +00:00
|
|
|
{
|
1997-06-09 03:27:43 +00:00
|
|
|
if (LogIsKept(LogLQM)) {
|
1997-08-31 22:59:49 +00:00
|
|
|
LogPrintf(LogLQM, "%s:\n", message);
|
1997-06-09 03:27:43 +00:00
|
|
|
LogPrintf(LogLQM, " Magic: %08x LastOutLQRs: %08x\n",
|
|
|
|
lqr->MagicNumber, lqr->LastOutLQRs);
|
|
|
|
LogPrintf(LogLQM, " LastOutPackets: %08x LastOutOctets: %08x\n",
|
|
|
|
lqr->LastOutPackets, lqr->LastOutOctets);
|
|
|
|
LogPrintf(LogLQM, " PeerInLQRs: %08x PeerInPackets: %08x\n",
|
|
|
|
lqr->PeerInLQRs, lqr->PeerInPackets);
|
|
|
|
LogPrintf(LogLQM, " PeerInDiscards: %08x PeerInErrors: %08x\n",
|
|
|
|
lqr->PeerInDiscards, lqr->PeerInErrors);
|
|
|
|
LogPrintf(LogLQM, " PeerInOctets: %08x PeerOutLQRs: %08x\n",
|
|
|
|
lqr->PeerInOctets, lqr->PeerOutLQRs);
|
|
|
|
LogPrintf(LogLQM, " PeerOutPackets: %08x PeerOutOctets: %08x\n",
|
|
|
|
lqr->PeerOutPackets, lqr->PeerOutOctets);
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
}
|