1998-01-29 00:44:16 +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.
|
|
|
|
*
|
1998-04-24 19:16:15 +00:00
|
|
|
* $Id: lqr.c,v 1.22.2.26 1998/04/19 23:08:40 brian Exp $
|
1998-01-29 00:44:16 +00:00
|
|
|
*
|
|
|
|
* o LQR based on RFC1333
|
|
|
|
*
|
|
|
|
* TODO:
|
|
|
|
* o LQM policy
|
|
|
|
* o Allow user to configure LQM method and interval.
|
|
|
|
*/
|
1998-03-13 00:44:26 +00:00
|
|
|
|
1998-04-07 00:54:26 +00:00
|
|
|
#include <sys/types.h>
|
1998-01-29 00:44:16 +00:00
|
|
|
|
1998-03-13 00:44:26 +00:00
|
|
|
#include <string.h>
|
1998-02-02 19:33:40 +00:00
|
|
|
#include <termios.h>
|
1998-01-29 00:44:16 +00:00
|
|
|
|
|
|
|
#include "mbuf.h"
|
|
|
|
#include "log.h"
|
|
|
|
#include "defs.h"
|
|
|
|
#include "timer.h"
|
|
|
|
#include "fsm.h"
|
|
|
|
#include "lcpproto.h"
|
1998-02-02 19:33:40 +00:00
|
|
|
#include "lcp.h"
|
1998-03-13 00:44:26 +00:00
|
|
|
#include "lqr.h"
|
1998-02-02 19:33:40 +00:00
|
|
|
#include "hdlc.h"
|
|
|
|
#include "async.h"
|
|
|
|
#include "throughput.h"
|
1998-04-03 19:21:56 +00:00
|
|
|
#include "ccp.h"
|
1998-02-02 19:33:40 +00:00
|
|
|
#include "link.h"
|
1998-02-09 19:21:11 +00:00
|
|
|
#include "descriptor.h"
|
1998-01-30 19:46:07 +00:00
|
|
|
#include "physical.h"
|
1998-04-03 19:21:56 +00:00
|
|
|
#include "mp.h"
|
1998-04-14 07:25:37 +00:00
|
|
|
#include "chat.h"
|
|
|
|
#include "auth.h"
|
|
|
|
#include "chap.h"
|
1998-04-16 00:26:21 +00:00
|
|
|
#include "command.h"
|
1998-04-14 07:25:37 +00:00
|
|
|
#include "datalink.h"
|
1998-01-29 00:44:16 +00:00
|
|
|
|
|
|
|
struct echolqr {
|
|
|
|
u_int32_t magic;
|
|
|
|
u_int32_t signature;
|
|
|
|
u_int32_t sequence;
|
|
|
|
};
|
|
|
|
|
|
|
|
#define SIGNATURE 0x594e4f54
|
|
|
|
|
|
|
|
static void
|
1998-03-13 00:44:26 +00:00
|
|
|
SendEchoReq(struct lcp *lcp)
|
1998-01-29 00:44:16 +00:00
|
|
|
{
|
1998-03-13 00:44:26 +00:00
|
|
|
struct hdlc *hdlc = &link2physical(lcp->fsm.link)->hdlc;
|
|
|
|
struct echolqr echo;
|
1998-01-29 00:44:16 +00:00
|
|
|
|
1998-03-13 00:44:26 +00:00
|
|
|
echo.magic = htonl(lcp->want_magic);
|
|
|
|
echo.signature = htonl(SIGNATURE);
|
1998-03-20 19:47:10 +00:00
|
|
|
echo.sequence = htonl(hdlc->lqm.echo.seq_sent);
|
|
|
|
FsmOutput(&lcp->fsm, CODE_ECHOREQ, hdlc->lqm.echo.seq_sent++,
|
1998-03-13 00:44:26 +00:00
|
|
|
(u_char *)&echo, sizeof echo);
|
1998-01-29 00:44:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1998-03-13 00:44:26 +00:00
|
|
|
RecvEchoLqr(struct fsm *fp, struct mbuf * bp)
|
1998-01-29 00:44:16 +00:00
|
|
|
{
|
1998-03-13 00:44:26 +00:00
|
|
|
struct hdlc *hdlc = &link2physical(fp->link)->hdlc;
|
1998-01-29 00:44:16 +00:00
|
|
|
struct echolqr *lqr;
|
|
|
|
u_int32_t seq;
|
|
|
|
|
|
|
|
if (plength(bp) == sizeof(struct echolqr)) {
|
|
|
|
lqr = (struct echolqr *) MBUF_CTOP(bp);
|
1998-03-13 00:44:26 +00:00
|
|
|
if (ntohl(lqr->signature) == SIGNATURE) {
|
1998-01-29 00:44:16 +00:00
|
|
|
seq = ntohl(lqr->sequence);
|
1998-03-13 00:44:26 +00:00
|
|
|
/* careful not to update lqm.echo.seq_recv with older values */
|
|
|
|
if ((hdlc->lqm.echo.seq_recv > (u_int32_t)0 - 5 && seq < 5) ||
|
|
|
|
(hdlc->lqm.echo.seq_recv <= (u_int32_t)0 - 5 &&
|
|
|
|
seq > hdlc->lqm.echo.seq_recv))
|
|
|
|
hdlc->lqm.echo.seq_recv = seq;
|
|
|
|
} else
|
|
|
|
LogPrintf(LogERROR, "RecvEchoLqr: Got sig 0x%08x, expecting 0x%08x !\n",
|
1998-04-19 23:09:03 +00:00
|
|
|
(unsigned)ntohl(lqr->signature), (unsigned)SIGNATURE);
|
1998-03-13 00:44:26 +00:00
|
|
|
} else
|
|
|
|
LogPrintf(LogERROR, "RecvEchoLqr: Got packet size %d, expecting %d !\n",
|
|
|
|
plength(bp), sizeof(struct echolqr));
|
1998-01-29 00:44:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
LqrChangeOrder(struct lqrdata * src, struct lqrdata * dst)
|
|
|
|
{
|
|
|
|
u_long *sp, *dp;
|
|
|
|
int n;
|
|
|
|
|
|
|
|
sp = (u_long *) src;
|
|
|
|
dp = (u_long *) dst;
|
1998-03-13 00:44:26 +00:00
|
|
|
for (n = 0; n < sizeof(struct lqrdata) / sizeof(u_int32_t); n++)
|
1998-01-29 00:44:16 +00:00
|
|
|
*dp++ = ntohl(*sp++);
|
|
|
|
}
|
|
|
|
|
1998-04-18 01:01:28 +00:00
|
|
|
static void
|
1998-04-03 19:26:35 +00:00
|
|
|
SendLqrData(struct lcp *lcp)
|
|
|
|
{
|
|
|
|
struct mbuf *bp;
|
|
|
|
|
|
|
|
bp = mballoc(sizeof(struct lqrdata), MB_LQR);
|
|
|
|
HdlcOutput(lcp->fsm.link, PRI_LINK, PROTO_LQR, bp);
|
|
|
|
}
|
|
|
|
|
1998-01-29 00:44:16 +00:00
|
|
|
static void
|
|
|
|
SendLqrReport(void *v)
|
|
|
|
{
|
1998-03-13 00:44:26 +00:00
|
|
|
struct lcp *lcp = (struct lcp *)v;
|
1998-04-14 07:25:37 +00:00
|
|
|
struct physical *p = link2physical(lcp->fsm.link);
|
1998-01-29 00:44:16 +00:00
|
|
|
|
1998-04-14 07:25:37 +00:00
|
|
|
StopTimer(&p->hdlc.lqm.timer);
|
1998-01-29 00:44:16 +00:00
|
|
|
|
1998-04-14 07:25:37 +00:00
|
|
|
if (p->hdlc.lqm.method & LQM_LQR) {
|
|
|
|
if (p->hdlc.lqm.lqr.resent > 5) {
|
1998-03-13 00:44:26 +00:00
|
|
|
/* XXX: Should implement LQM strategy */
|
1998-04-24 19:16:15 +00:00
|
|
|
LogPrintf(LogPHASE, "%s: ** Too many LQR packets lost **\n",
|
|
|
|
lcp->fsm.link->name);
|
|
|
|
LogPrintf(LogLQM, "%s: Too many LQR packets lost\n",
|
|
|
|
lcp->fsm.link->name);
|
1998-04-14 07:25:37 +00:00
|
|
|
p->hdlc.lqm.method = 0;
|
|
|
|
datalink_Down(p->dl, 0);
|
1998-01-29 00:44:16 +00:00
|
|
|
} else {
|
1998-04-03 19:26:35 +00:00
|
|
|
SendLqrData(lcp);
|
1998-04-14 07:25:37 +00:00
|
|
|
p->hdlc.lqm.lqr.resent++;
|
1998-01-29 00:44:16 +00:00
|
|
|
}
|
1998-04-14 07:25:37 +00:00
|
|
|
} else if (p->hdlc.lqm.method & LQM_ECHO) {
|
|
|
|
if ((p->hdlc.lqm.echo.seq_sent > 5 &&
|
|
|
|
p->hdlc.lqm.echo.seq_sent - 5 > p->hdlc.lqm.echo.seq_recv) ||
|
|
|
|
(p->hdlc.lqm.echo.seq_sent <= 5 &&
|
|
|
|
p->hdlc.lqm.echo.seq_sent > p->hdlc.lqm.echo.seq_recv + 5)) {
|
1998-04-24 19:16:15 +00:00
|
|
|
LogPrintf(LogPHASE, "%s: ** Too many ECHO LQR packets lost **\n",
|
|
|
|
lcp->fsm.link->name);
|
|
|
|
LogPrintf(LogLQM, "%s: Too many ECHO LQR packets lost\n",
|
|
|
|
lcp->fsm.link->name);
|
1998-04-14 07:25:37 +00:00
|
|
|
p->hdlc.lqm.method = 0;
|
|
|
|
datalink_Down(p->dl, 0);
|
1998-01-29 00:44:16 +00:00
|
|
|
} else
|
1998-03-13 00:44:26 +00:00
|
|
|
SendEchoReq(lcp);
|
1998-01-29 00:44:16 +00:00
|
|
|
}
|
1998-04-14 07:25:37 +00:00
|
|
|
if (p->hdlc.lqm.method && p->hdlc.lqm.timer.load)
|
|
|
|
StartTimer(&p->hdlc.lqm.timer);
|
1998-01-29 00:44:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1998-03-13 00:44:26 +00:00
|
|
|
LqrInput(struct physical *physical, struct mbuf *bp)
|
1998-01-29 00:44:16 +00:00
|
|
|
{
|
|
|
|
int len;
|
|
|
|
|
|
|
|
len = plength(bp);
|
1998-03-13 00:44:26 +00:00
|
|
|
if (len != sizeof(struct lqrdata))
|
|
|
|
LogPrintf(LogERROR, "LqrInput: Got packet size %d, expecting %d !\n",
|
|
|
|
len, sizeof(struct lqrdata));
|
1998-04-16 00:26:21 +00:00
|
|
|
else if (!IsAccepted(physical->link.lcp.cfg.lqr) &&
|
|
|
|
!(physical->hdlc.lqm.method & LQM_LQR)) {
|
1998-01-29 00:44:16 +00:00
|
|
|
bp->offset -= 2;
|
|
|
|
bp->cnt += 2;
|
1998-03-13 21:07:14 +00:00
|
|
|
lcp_SendProtoRej(physical->hdlc.lqm.owner, MBUF_CTOP(bp), bp->cnt);
|
1998-01-29 00:44:16 +00:00
|
|
|
} else {
|
1998-03-13 00:44:26 +00:00
|
|
|
struct lqrdata *lqr;
|
1998-03-13 21:07:14 +00:00
|
|
|
struct lcp *lcp;
|
1998-03-13 00:44:26 +00:00
|
|
|
u_int32_t lastLQR;
|
|
|
|
|
|
|
|
lqr = (struct lqrdata *)MBUF_CTOP(bp);
|
1998-03-13 21:07:14 +00:00
|
|
|
lcp = physical->hdlc.lqm.owner;
|
|
|
|
if (ntohl(lqr->MagicNumber) != physical->hdlc.lqm.owner->his_magic)
|
1998-01-29 00:44:16 +00:00
|
|
|
LogPrintf(LogERROR, "LqrInput: magic %x != expecting %x\n",
|
1998-04-19 23:09:03 +00:00
|
|
|
(unsigned)ntohl(lqr->MagicNumber),
|
|
|
|
physical->hdlc.lqm.owner->his_magic);
|
1998-03-13 00:44:26 +00:00
|
|
|
else {
|
|
|
|
/*
|
|
|
|
* Remember our PeerInLQRs, then convert byte order and save
|
|
|
|
*/
|
|
|
|
lastLQR = physical->hdlc.lqm.lqr.peer.PeerInLQRs;
|
1998-01-29 00:44:16 +00:00
|
|
|
|
1998-03-13 00:44:26 +00:00
|
|
|
LqrChangeOrder(lqr, &physical->hdlc.lqm.lqr.peer);
|
1998-04-24 19:16:15 +00:00
|
|
|
LqrDump(physical->link.name, "Input", &physical->hdlc.lqm.lqr.peer);
|
1998-03-13 00:44:26 +00:00
|
|
|
/* we have received an LQR from peer */
|
|
|
|
physical->hdlc.lqm.lqr.resent = 0;
|
1998-01-29 00:44:16 +00:00
|
|
|
|
1998-03-13 00:44:26 +00:00
|
|
|
/*
|
|
|
|
* Generate an LQR response if we're not running an LQR timer OR
|
|
|
|
* two successive LQR's PeerInLQRs are the same OR we're not going to
|
|
|
|
* send our next one before the peers max timeout.
|
|
|
|
*/
|
|
|
|
if (physical->hdlc.lqm.timer.load == 0 ||
|
1998-04-03 19:26:35 +00:00
|
|
|
!(physical->hdlc.lqm.method & LQM_LQR) ||
|
1998-03-13 21:07:14 +00:00
|
|
|
(lastLQR && lastLQR == physical->hdlc.lqm.lqr.peer.PeerInLQRs) ||
|
1998-03-13 00:44:26 +00:00
|
|
|
(physical->hdlc.lqm.lqr.peer_timeout &&
|
|
|
|
physical->hdlc.lqm.timer.rest * 100 / SECTICKS >
|
|
|
|
physical->hdlc.lqm.lqr.peer_timeout))
|
1998-04-03 19:26:35 +00:00
|
|
|
SendLqrData(physical->hdlc.lqm.owner);
|
1998-01-29 00:44:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
pfree(bp);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* When LCP is reached to opened state, We'll start LQM activity.
|
|
|
|
*/
|
|
|
|
void
|
1998-03-13 00:44:26 +00:00
|
|
|
StartLqm(struct lcp *lcp)
|
1998-01-29 00:44:16 +00:00
|
|
|
{
|
1998-03-13 00:44:26 +00:00
|
|
|
struct physical *physical = link2physical(lcp->fsm.link);
|
1998-01-29 00:44:16 +00:00
|
|
|
|
1998-03-13 00:44:26 +00:00
|
|
|
physical->hdlc.lqm.lqr.resent = 0;
|
|
|
|
physical->hdlc.lqm.echo.seq_sent = 0;
|
|
|
|
physical->hdlc.lqm.echo.seq_recv = 0;
|
|
|
|
memset(&physical->hdlc.lqm.lqr.peer, '\0',
|
|
|
|
sizeof physical->hdlc.lqm.lqr.peer);
|
1998-01-29 00:44:16 +00:00
|
|
|
|
1998-03-13 00:44:26 +00:00
|
|
|
physical->hdlc.lqm.method = LQM_ECHO;
|
1998-04-16 00:26:21 +00:00
|
|
|
if (IsEnabled(physical->link.lcp.cfg.lqr) && !REJECTED(lcp, TY_QUALPROTO))
|
1998-03-13 00:44:26 +00:00
|
|
|
physical->hdlc.lqm.method |= LQM_LQR;
|
|
|
|
StopTimer(&physical->hdlc.lqm.timer);
|
|
|
|
|
|
|
|
physical->hdlc.lqm.lqr.peer_timeout = lcp->his_lqrperiod;
|
|
|
|
if (lcp->his_lqrperiod)
|
|
|
|
LogPrintf(LogLQM, "Expecting LQR every %d.%02d secs\n",
|
|
|
|
lcp->his_lqrperiod / 100, lcp->his_lqrperiod % 100);
|
|
|
|
|
|
|
|
if (lcp->want_lqrperiod) {
|
|
|
|
LogPrintf(LogLQM, "Will send %s every %d.%02d secs\n",
|
|
|
|
physical->hdlc.lqm.method & LQM_LQR ? "LQR" : "ECHO LQR",
|
|
|
|
lcp->want_lqrperiod / 100, lcp->want_lqrperiod % 100);
|
|
|
|
physical->hdlc.lqm.timer.load = lcp->want_lqrperiod * SECTICKS / 100;
|
|
|
|
physical->hdlc.lqm.timer.func = SendLqrReport;
|
1998-04-03 19:21:56 +00:00
|
|
|
physical->hdlc.lqm.timer.name = "lqm";
|
1998-03-13 00:44:26 +00:00
|
|
|
physical->hdlc.lqm.timer.arg = lcp;
|
|
|
|
SendLqrReport(lcp);
|
1998-01-29 00:44:16 +00:00
|
|
|
} else {
|
1998-03-13 00:44:26 +00:00
|
|
|
physical->hdlc.lqm.timer.load = 0;
|
|
|
|
if (!lcp->his_lqrperiod)
|
|
|
|
LogPrintf(LogLQM, "LQR/ECHO LQR not negotiated\n");
|
1998-01-29 00:44:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1998-03-13 00:44:26 +00:00
|
|
|
StopLqrTimer(struct physical *physical)
|
1998-01-29 00:44:16 +00:00
|
|
|
{
|
1998-03-13 00:44:26 +00:00
|
|
|
StopTimer(&physical->hdlc.lqm.timer);
|
1998-01-29 00:44:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1998-01-29 00:49:32 +00:00
|
|
|
StopLqr(struct physical *physical, int method)
|
1998-01-29 00:44:16 +00:00
|
|
|
{
|
|
|
|
LogPrintf(LogLQM, "StopLqr method = %x\n", method);
|
|
|
|
|
|
|
|
if (method == LQM_LQR)
|
|
|
|
LogPrintf(LogLQM, "Stop sending LQR, Use LCP ECHO instead.\n");
|
|
|
|
if (method == LQM_ECHO)
|
|
|
|
LogPrintf(LogLQM, "Stop sending LCP ECHO.\n");
|
1998-03-13 00:44:26 +00:00
|
|
|
physical->hdlc.lqm.method &= ~method;
|
|
|
|
if (physical->hdlc.lqm.method)
|
|
|
|
SendLqrReport(physical->hdlc.lqm.owner);
|
1998-01-29 00:44:16 +00:00
|
|
|
else
|
1998-03-13 00:44:26 +00:00
|
|
|
StopTimer(&physical->hdlc.lqm.timer);
|
1998-01-29 00:44:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1998-04-24 19:16:15 +00:00
|
|
|
LqrDump(const char *link, const char *message, const struct lqrdata * lqr)
|
1998-01-29 00:44:16 +00:00
|
|
|
{
|
|
|
|
if (LogIsKept(LogLQM)) {
|
1998-04-24 19:16:15 +00:00
|
|
|
LogPrintf(LogLQM, "%s: %s:\n", link, message);
|
1998-01-29 00:44:16 +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);
|
|
|
|
}
|
|
|
|
}
|