2001-06-13 21:52:19 +00:00
|
|
|
/*-
|
|
|
|
* Copyright (c) 1996 - 2001 Brian Somers <brian@Awfulhak.org>
|
|
|
|
* based on work by Toshiharu OHNO <tony-o@iij.ad.jp>
|
|
|
|
* Internet Initiative Japan, Inc (IIJ)
|
|
|
|
* All rights reserved.
|
1995-01-31 06:29:58 +00:00
|
|
|
*
|
2001-06-13 21:52:19 +00:00
|
|
|
* 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.
|
1995-01-31 06:29:58 +00:00
|
|
|
*
|
2001-06-13 21:52:19 +00:00
|
|
|
* 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.
|
1995-01-31 06:29:58 +00:00
|
|
|
*
|
1999-08-28 01:35:59 +00:00
|
|
|
* $FreeBSD$
|
1995-01-31 06:29:58 +00:00
|
|
|
*/
|
1997-10-26 01:04:02 +00:00
|
|
|
|
1999-01-28 01:56:34 +00:00
|
|
|
#include <sys/param.h>
|
2002-05-14 12:55:39 +00:00
|
|
|
|
|
|
|
#ifdef __FreeBSD__
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#endif
|
1998-04-28 01:25:46 +00:00
|
|
|
#include <sys/un.h>
|
1998-01-29 00:44:16 +00:00
|
|
|
|
1998-03-12 02:23:42 +00:00
|
|
|
#include <string.h>
|
1998-02-02 19:33:40 +00:00
|
|
|
#include <termios.h>
|
1997-10-26 01:04:02 +00:00
|
|
|
|
1999-05-08 11:07:56 +00:00
|
|
|
#include "layer.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"
|
1999-05-08 11:07:56 +00:00
|
|
|
#include "acf.h"
|
|
|
|
#include "proto.h"
|
1995-01-31 06:29:58 +00:00
|
|
|
#include "lqr.h"
|
|
|
|
#include "hdlc.h"
|
2000-07-19 02:10:35 +00:00
|
|
|
#include "lcp.h"
|
1998-02-02 19:33:40 +00:00
|
|
|
#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-08-07 18:42:51 +00:00
|
|
|
#include "cbcp.h"
|
1998-04-14 07:25:37 +00:00
|
|
|
#include "datalink.h"
|
1995-01-31 06:29:58 +00:00
|
|
|
|
|
|
|
struct echolqr {
|
1998-01-11 17:50:49 +00:00
|
|
|
u_int32_t magic;
|
|
|
|
u_int32_t signature;
|
|
|
|
u_int32_t sequence;
|
1995-01-31 06:29:58 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#define SIGNATURE 0x594e4f54
|
|
|
|
|
|
|
|
static void
|
1998-03-13 00:44:26 +00:00
|
|
|
SendEchoReq(struct lcp *lcp)
|
1995-01-31 06:29:58 +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);
|
1998-05-01 19:26:12 +00:00
|
|
|
fsm_Output(&lcp->fsm, CODE_ECHOREQ, hdlc->lqm.echo.seq_sent++,
|
1999-06-02 15:59:09 +00:00
|
|
|
(u_char *)&echo, sizeof echo, MB_ECHOOUT);
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
|
1999-05-09 20:02:29 +00:00
|
|
|
struct mbuf *
|
|
|
|
lqr_RecvEcho(struct fsm *fp, struct mbuf *bp)
|
1995-01-31 06:29:58 +00:00
|
|
|
{
|
1998-03-13 00:44:26 +00:00
|
|
|
struct hdlc *hdlc = &link2physical(fp->link)->hdlc;
|
1999-05-14 09:36:06 +00:00
|
|
|
struct lcp *lcp = fsm2lcp(fp);
|
1999-05-09 20:02:29 +00:00
|
|
|
struct echolqr lqr;
|
1995-01-31 06:29:58 +00:00
|
|
|
|
2000-06-20 09:13:25 +00:00
|
|
|
if (m_length(bp) >= sizeof lqr) {
|
|
|
|
m_freem(mbuf_Read(bp, &lqr, sizeof lqr));
|
|
|
|
bp = NULL;
|
1999-05-14 09:36:06 +00:00
|
|
|
lqr.magic = ntohl(lqr.magic);
|
|
|
|
lqr.signature = ntohl(lqr.signature);
|
|
|
|
lqr.sequence = ntohl(lqr.sequence);
|
|
|
|
|
|
|
|
/* Tolerate echo replies with either magic number */
|
|
|
|
if (lqr.magic != 0 && lqr.magic != lcp->his_magic &&
|
|
|
|
lqr.magic != lcp->want_magic) {
|
|
|
|
log_Printf(LogWARN, "%s: lqr_RecvEcho: Bad magic: expected 0x%08x,"
|
|
|
|
" got 0x%08x\n", fp->link->name, lcp->his_magic, lqr.magic);
|
|
|
|
/*
|
|
|
|
* XXX: We should send a terminate request. But poor implementations may
|
|
|
|
* die as a result.
|
|
|
|
*/
|
|
|
|
}
|
2012-10-12 22:48:33 +00:00
|
|
|
if (lqr.signature == SIGNATURE
|
|
|
|
|| lqr.signature == lcp->want_magic) { /* some implementations return the wrong magic */
|
1998-03-13 00:44:26 +00:00
|
|
|
/* careful not to update lqm.echo.seq_recv with older values */
|
1999-05-14 09:36:06 +00:00
|
|
|
if ((hdlc->lqm.echo.seq_recv > (u_int32_t)0 - 5 && lqr.sequence < 5) ||
|
1998-03-13 00:44:26 +00:00
|
|
|
(hdlc->lqm.echo.seq_recv <= (u_int32_t)0 - 5 &&
|
1999-05-14 09:36:06 +00:00
|
|
|
lqr.sequence > hdlc->lqm.echo.seq_recv))
|
|
|
|
hdlc->lqm.echo.seq_recv = lqr.sequence;
|
1998-03-13 00:44:26 +00:00
|
|
|
} else
|
1998-06-27 23:48:54 +00:00
|
|
|
log_Printf(LogWARN, "lqr_RecvEcho: Got sig 0x%08lx, not 0x%08lx !\n",
|
1999-10-16 09:18:15 +00:00
|
|
|
(u_long)lqr.signature, (u_long)SIGNATURE);
|
1998-03-13 00:44:26 +00:00
|
|
|
} else
|
2004-09-06 00:07:58 +00:00
|
|
|
log_Printf(LogWARN, "lqr_RecvEcho: Got packet size %zd, expecting %ld !\n",
|
1999-12-20 20:29:47 +00:00
|
|
|
m_length(bp), (long)sizeof(struct echolqr));
|
1999-05-09 20:02:29 +00:00
|
|
|
return bp;
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1999-05-09 20:02:29 +00:00
|
|
|
lqr_ChangeOrder(struct lqrdata *src, struct lqrdata *dst)
|
1995-01-31 06:29:58 +00:00
|
|
|
{
|
1998-06-26 19:02:40 +00:00
|
|
|
u_int32_t *sp, *dp;
|
2004-09-05 01:46:52 +00:00
|
|
|
unsigned n;
|
1995-01-31 06:29:58 +00:00
|
|
|
|
1998-06-26 19:02:40 +00:00
|
|
|
sp = (u_int32_t *) src;
|
|
|
|
dp = (u_int32_t *) dst;
|
1999-05-08 11:07:56 +00:00
|
|
|
for (n = 0; n < sizeof(struct lqrdata) / sizeof(u_int32_t); n++, sp++, dp++)
|
|
|
|
*dp = ntohl(*sp);
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
1998-04-03 19:26:35 +00:00
|
|
|
SendLqrData(struct lcp *lcp)
|
1995-01-31 06:29:58 +00:00
|
|
|
{
|
|
|
|
struct mbuf *bp;
|
1999-06-02 15:59:09 +00:00
|
|
|
int extra;
|
1995-01-31 06:29:58 +00:00
|
|
|
|
1999-06-02 15:59:09 +00:00
|
|
|
extra = proto_WrapperOctets(lcp, PROTO_LQR) +
|
|
|
|
acf_WrapperOctets(lcp, PROTO_LQR);
|
1999-12-20 20:29:47 +00:00
|
|
|
bp = m_get(sizeof(struct lqrdata) + extra, MB_LQROUT);
|
|
|
|
bp->m_len -= extra;
|
|
|
|
bp->m_offset += extra;
|
2004-06-30 12:24:56 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Send on the highest priority queue. We send garbage - the real data
|
|
|
|
* is written by lqr_LayerPush() where we know how to fill in all the
|
|
|
|
* fields. Note, lqr_LayerPush() ``knows'' that we're pushing onto the
|
|
|
|
* highest priority queue, and factors out packet & octet values from
|
|
|
|
* other queues!
|
|
|
|
*/
|
1999-09-04 00:00:21 +00:00
|
|
|
link_PushPacket(lcp->fsm.link, bp, lcp->fsm.bundle,
|
|
|
|
LINK_QUEUES(lcp->fsm.link) - 1, PROTO_LQR);
|
1998-04-03 19:26:35 +00:00
|
|
|
}
|
1995-01-31 06:29:58 +00:00
|
|
|
|
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-05-01 19:26:12 +00:00
|
|
|
timer_Stop(&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-05-01 19:26:12 +00:00
|
|
|
log_Printf(LogPHASE, "%s: ** Too many LQR packets lost **\n",
|
1998-04-24 19:16:15 +00:00
|
|
|
lcp->fsm.link->name);
|
1998-05-01 19:26:12 +00:00
|
|
|
log_Printf(LogLQM, "%s: Too many LQR packets lost\n",
|
1998-04-24 19:16:15 +00:00
|
|
|
lcp->fsm.link->name);
|
1998-04-14 07:25:37 +00:00
|
|
|
p->hdlc.lqm.method = 0;
|
1998-06-15 19:05:27 +00:00
|
|
|
datalink_Down(p->dl, CLOSE_NORMAL);
|
1995-01-31 06:29:58 +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++;
|
1995-01-31 06:29:58 +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)) {
|
2004-12-13 12:51:19 +00:00
|
|
|
log_Printf(LogPHASE, "%s: ** Too many LCP ECHO packets lost **\n",
|
1998-04-24 19:16:15 +00:00
|
|
|
lcp->fsm.link->name);
|
2004-12-13 12:51:19 +00:00
|
|
|
log_Printf(LogLQM, "%s: Too many LCP ECHO packets lost\n",
|
1998-04-24 19:16:15 +00:00
|
|
|
lcp->fsm.link->name);
|
1998-04-14 07:25:37 +00:00
|
|
|
p->hdlc.lqm.method = 0;
|
1998-06-15 19:05:27 +00:00
|
|
|
datalink_Down(p->dl, CLOSE_NORMAL);
|
1995-01-31 06:29:58 +00:00
|
|
|
} else
|
1998-03-13 00:44:26 +00:00
|
|
|
SendEchoReq(lcp);
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
1998-04-14 07:25:37 +00:00
|
|
|
if (p->hdlc.lqm.method && p->hdlc.lqm.timer.load)
|
1998-05-01 19:26:12 +00:00
|
|
|
timer_Start(&p->hdlc.lqm.timer);
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
|
1999-05-08 11:07:56 +00:00
|
|
|
struct mbuf *
|
2004-09-05 01:46:52 +00:00
|
|
|
lqr_Input(struct bundle *bundle __unused, struct link *l, struct mbuf *bp)
|
1995-01-31 06:29:58 +00:00
|
|
|
{
|
1999-05-08 11:07:56 +00:00
|
|
|
struct physical *p = link2physical(l);
|
|
|
|
struct lcp *lcp = p->hdlc.lqm.owner;
|
1995-01-31 06:29:58 +00:00
|
|
|
int len;
|
|
|
|
|
1999-05-08 11:07:56 +00:00
|
|
|
if (p == NULL) {
|
|
|
|
log_Printf(LogERROR, "lqr_Input: Not a physical link - dropped\n");
|
1999-12-20 20:29:47 +00:00
|
|
|
m_freem(bp);
|
1999-05-08 11:07:56 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
1999-12-20 20:29:47 +00:00
|
|
|
len = m_length(bp);
|
1998-03-13 00:44:26 +00:00
|
|
|
if (len != sizeof(struct lqrdata))
|
1998-06-27 23:48:54 +00:00
|
|
|
log_Printf(LogWARN, "lqr_Input: Got packet size %d, expecting %ld !\n",
|
|
|
|
len, (long)sizeof(struct lqrdata));
|
1999-05-08 11:07:56 +00:00
|
|
|
else if (!IsAccepted(l->lcp.cfg.lqr) && !(p->hdlc.lqm.method & LQM_LQR)) {
|
1999-12-20 20:29:47 +00:00
|
|
|
bp = m_pullup(proto_Prepend(bp, PROTO_LQR, 0, 0));
|
|
|
|
lcp_SendProtoRej(lcp, MBUF_CTOP(bp), bp->m_len);
|
1995-01-31 06:29:58 +00:00
|
|
|
} else {
|
1998-03-13 00:44:26 +00:00
|
|
|
struct lqrdata *lqr;
|
1995-01-31 06:29:58 +00:00
|
|
|
|
1999-12-20 20:29:47 +00:00
|
|
|
bp = m_pullup(bp);
|
1998-03-13 00:44:26 +00:00
|
|
|
lqr = (struct lqrdata *)MBUF_CTOP(bp);
|
1999-05-08 11:07:56 +00:00
|
|
|
if (ntohl(lqr->MagicNumber) != lcp->his_magic)
|
1998-06-27 23:48:54 +00:00
|
|
|
log_Printf(LogWARN, "lqr_Input: magic 0x%08lx is wrong,"
|
|
|
|
" expecting 0x%08lx\n",
|
1999-05-08 11:07:56 +00:00
|
|
|
(u_long)ntohl(lqr->MagicNumber), (u_long)lcp->his_magic);
|
1998-03-13 00:44:26 +00:00
|
|
|
else {
|
2004-06-30 12:24:56 +00:00
|
|
|
struct lqrdata lastlqr;
|
1998-01-29 00:44:16 +00:00
|
|
|
|
2004-06-30 12:24:56 +00:00
|
|
|
memcpy(&lastlqr, &p->hdlc.lqm.lqr.peer, sizeof lastlqr);
|
1999-05-08 11:07:56 +00:00
|
|
|
lqr_ChangeOrder(lqr, &p->hdlc.lqm.lqr.peer);
|
|
|
|
lqr_Dump(l->name, "Input", &p->hdlc.lqm.lqr.peer);
|
2004-06-30 12:24:56 +00:00
|
|
|
/* we have received an LQR from our peer */
|
1999-05-08 11:07:56 +00:00
|
|
|
p->hdlc.lqm.lqr.resent = 0;
|
1998-01-29 00:44:16 +00:00
|
|
|
|
2004-06-30 12:24:56 +00:00
|
|
|
/* Snapshot our state when the LQR packet was received */
|
|
|
|
memcpy(&p->hdlc.lqm.lqr.prevSave, &p->hdlc.lqm.lqr.Save,
|
|
|
|
sizeof p->hdlc.lqm.lqr.prevSave);
|
|
|
|
p->hdlc.lqm.lqr.Save.InLQRs = ++p->hdlc.lqm.lqr.InLQRs;
|
|
|
|
p->hdlc.lqm.lqr.Save.InPackets = p->hdlc.lqm.ifInUniPackets;
|
|
|
|
p->hdlc.lqm.lqr.Save.InDiscards = p->hdlc.lqm.ifInDiscards;
|
|
|
|
p->hdlc.lqm.lqr.Save.InErrors = p->hdlc.lqm.ifInErrors;
|
|
|
|
p->hdlc.lqm.lqr.Save.InOctets = p->hdlc.lqm.lqr.InGoodOctets;
|
|
|
|
|
|
|
|
lqr_Analyse(&p->hdlc, &lastlqr, &p->hdlc.lqm.lqr.peer);
|
|
|
|
|
1998-03-13 00:44:26 +00:00
|
|
|
/*
|
|
|
|
* Generate an LQR response if we're not running an LQR timer OR
|
2004-06-30 12:24:56 +00:00
|
|
|
* two successive LQR's PeerInLQRs are the same.
|
1998-03-13 00:44:26 +00:00
|
|
|
*/
|
2004-06-30 12:24:56 +00:00
|
|
|
if (p->hdlc.lqm.timer.load == 0 || !(p->hdlc.lqm.method & LQM_LQR) ||
|
|
|
|
(lastlqr.PeerInLQRs &&
|
|
|
|
lastlqr.PeerInLQRs == p->hdlc.lqm.lqr.peer.PeerInLQRs))
|
1999-05-08 11:07:56 +00:00
|
|
|
SendLqrData(lcp);
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
}
|
1999-12-20 20:29:47 +00:00
|
|
|
m_freem(bp);
|
1999-05-08 11:07:56 +00:00
|
|
|
return NULL;
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* When LCP is reached to opened state, We'll start LQM activity.
|
|
|
|
*/
|
1998-05-08 01:15:19 +00:00
|
|
|
static void
|
|
|
|
lqr_Setup(struct lcp *lcp)
|
1995-01-31 06:29:58 +00:00
|
|
|
{
|
1998-03-13 00:44:26 +00:00
|
|
|
struct physical *physical = link2physical(lcp->fsm.link);
|
2004-12-13 12:51:19 +00:00
|
|
|
int period;
|
1995-01-31 06:29:58 +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);
|
1997-08-25 00:29:32 +00:00
|
|
|
|
2004-12-13 12:51:19 +00:00
|
|
|
physical->hdlc.lqm.method = lcp->cfg.echo ? LQM_ECHO : 0;
|
1998-05-08 01:15:19 +00:00
|
|
|
if (IsEnabled(lcp->cfg.lqr) && !REJECTED(lcp, TY_QUALPROTO))
|
1998-03-13 00:44:26 +00:00
|
|
|
physical->hdlc.lqm.method |= LQM_LQR;
|
1998-05-01 19:26:12 +00:00
|
|
|
timer_Stop(&physical->hdlc.lqm.timer);
|
1995-01-31 06:29:58 +00:00
|
|
|
|
1998-03-13 00:44:26 +00:00
|
|
|
physical->hdlc.lqm.lqr.peer_timeout = lcp->his_lqrperiod;
|
1998-03-12 02:23:42 +00:00
|
|
|
if (lcp->his_lqrperiod)
|
1998-05-08 01:15:19 +00:00
|
|
|
log_Printf(LogLQM, "%s: Expecting LQR every %d.%02d secs\n",
|
|
|
|
physical->link.name, lcp->his_lqrperiod / 100,
|
|
|
|
lcp->his_lqrperiod % 100);
|
1997-08-25 00:29:32 +00:00
|
|
|
|
2004-12-13 12:51:19 +00:00
|
|
|
period = lcp->want_lqrperiod ?
|
|
|
|
lcp->want_lqrperiod : lcp->cfg.lqrperiod * 100;
|
|
|
|
physical->hdlc.lqm.timer.func = SendLqrReport;
|
|
|
|
physical->hdlc.lqm.timer.name = "lqm";
|
|
|
|
physical->hdlc.lqm.timer.arg = lcp;
|
|
|
|
|
|
|
|
if (lcp->want_lqrperiod || physical->hdlc.lqm.method & LQM_ECHO) {
|
1998-05-08 01:15:19 +00:00
|
|
|
log_Printf(LogLQM, "%s: Will send %s every %d.%02d secs\n",
|
2004-12-13 12:51:19 +00:00
|
|
|
physical->link.name, lcp->want_lqrperiod ? "LQR" : "LCP ECHO",
|
|
|
|
period / 100, period % 100);
|
|
|
|
physical->hdlc.lqm.timer.load = period * SECTICKS / 100;
|
1995-01-31 06:29:58 +00:00
|
|
|
} else {
|
1998-03-13 00:44:26 +00:00
|
|
|
physical->hdlc.lqm.timer.load = 0;
|
1998-03-12 02:23:42 +00:00
|
|
|
if (!lcp->his_lqrperiod)
|
2004-12-13 12:51:19 +00:00
|
|
|
log_Printf(LogLQM, "%s: LQR/LCP ECHO not negotiated\n",
|
1998-05-08 01:15:19 +00:00
|
|
|
physical->link.name);
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1996-01-30 11:08:50 +00:00
|
|
|
void
|
1998-05-08 01:15:19 +00:00
|
|
|
lqr_Start(struct lcp *lcp)
|
1996-01-30 11:08:50 +00:00
|
|
|
{
|
1998-05-08 01:15:19 +00:00
|
|
|
struct physical *p = link2physical(lcp->fsm.link);
|
|
|
|
|
|
|
|
lqr_Setup(lcp);
|
|
|
|
if (p->hdlc.lqm.timer.load)
|
|
|
|
SendLqrReport(lcp);
|
1996-01-30 11:08:50 +00:00
|
|
|
}
|
|
|
|
|
1995-01-31 06:29:58 +00:00
|
|
|
void
|
1998-05-08 01:15:19 +00:00
|
|
|
lqr_reStart(struct lcp *lcp)
|
1995-01-31 06:29:58 +00:00
|
|
|
{
|
1998-05-08 01:15:19 +00:00
|
|
|
struct physical *p = link2physical(lcp->fsm.link);
|
1995-01-31 06:29:58 +00:00
|
|
|
|
1998-05-08 01:15:19 +00:00
|
|
|
lqr_Setup(lcp);
|
|
|
|
if (p->hdlc.lqm.timer.load)
|
|
|
|
timer_Start(&p->hdlc.lqm.timer);
|
|
|
|
}
|
|
|
|
|
1998-01-29 00:44:16 +00:00
|
|
|
void
|
1998-05-01 19:26:12 +00:00
|
|
|
lqr_StopTimer(struct physical *physical)
|
1998-01-29 00:44:16 +00:00
|
|
|
{
|
1998-05-01 19:26:12 +00:00
|
|
|
timer_Stop(&physical->hdlc.lqm.timer);
|
1998-01-29 00:44:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1998-05-01 19:26:12 +00:00
|
|
|
lqr_Stop(struct physical *physical, int method)
|
1998-01-29 00:44:16 +00:00
|
|
|
{
|
1995-01-31 06:29:58 +00:00
|
|
|
if (method == LQM_LQR)
|
1998-05-08 01:15:19 +00:00
|
|
|
log_Printf(LogLQM, "%s: Stop sending LQR, Use LCP ECHO instead.\n",
|
|
|
|
physical->link.name);
|
1995-01-31 06:29:58 +00:00
|
|
|
if (method == LQM_ECHO)
|
1998-05-08 01:15:19 +00:00
|
|
|
log_Printf(LogLQM, "%s: Stop sending LCP ECHO.\n",
|
|
|
|
physical->link.name);
|
1998-03-13 00:44:26 +00:00
|
|
|
physical->hdlc.lqm.method &= ~method;
|
|
|
|
if (physical->hdlc.lqm.method)
|
|
|
|
SendLqrReport(physical->hdlc.lqm.owner);
|
1995-01-31 06:29:58 +00:00
|
|
|
else
|
1998-05-01 19:26:12 +00:00
|
|
|
timer_Stop(&physical->hdlc.lqm.timer);
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1998-05-08 01:15:19 +00:00
|
|
|
lqr_Dump(const char *link, const char *message, const struct lqrdata *lqr)
|
1995-01-31 06:29:58 +00:00
|
|
|
{
|
1998-05-01 19:26:12 +00:00
|
|
|
if (log_IsKept(LogLQM)) {
|
|
|
|
log_Printf(LogLQM, "%s: %s:\n", link, message);
|
|
|
|
log_Printf(LogLQM, " Magic: %08x LastOutLQRs: %08x\n",
|
1997-06-09 03:27:43 +00:00
|
|
|
lqr->MagicNumber, lqr->LastOutLQRs);
|
1998-05-01 19:26:12 +00:00
|
|
|
log_Printf(LogLQM, " LastOutPackets: %08x LastOutOctets: %08x\n",
|
1997-06-09 03:27:43 +00:00
|
|
|
lqr->LastOutPackets, lqr->LastOutOctets);
|
1998-05-01 19:26:12 +00:00
|
|
|
log_Printf(LogLQM, " PeerInLQRs: %08x PeerInPackets: %08x\n",
|
1997-06-09 03:27:43 +00:00
|
|
|
lqr->PeerInLQRs, lqr->PeerInPackets);
|
1998-05-01 19:26:12 +00:00
|
|
|
log_Printf(LogLQM, " PeerInDiscards: %08x PeerInErrors: %08x\n",
|
1997-06-09 03:27:43 +00:00
|
|
|
lqr->PeerInDiscards, lqr->PeerInErrors);
|
1998-05-01 19:26:12 +00:00
|
|
|
log_Printf(LogLQM, " PeerInOctets: %08x PeerOutLQRs: %08x\n",
|
1997-06-09 03:27:43 +00:00
|
|
|
lqr->PeerInOctets, lqr->PeerOutLQRs);
|
1998-05-01 19:26:12 +00:00
|
|
|
log_Printf(LogLQM, " PeerOutPackets: %08x PeerOutOctets: %08x\n",
|
1997-06-09 03:27:43 +00:00
|
|
|
lqr->PeerOutPackets, lqr->PeerOutOctets);
|
1995-01-31 06:29:58 +00:00
|
|
|
}
|
|
|
|
}
|
1999-05-08 11:07:56 +00:00
|
|
|
|
2004-06-30 12:24:56 +00:00
|
|
|
void
|
|
|
|
lqr_Analyse(const struct hdlc *hdlc, const struct lqrdata *oldlqr,
|
|
|
|
const struct lqrdata *newlqr)
|
|
|
|
{
|
|
|
|
u_int32_t LQRs, transitLQRs, pkts, octets, disc, err;
|
|
|
|
|
|
|
|
if (!newlqr->PeerInLQRs) /* No analysis possible yet! */
|
|
|
|
return;
|
|
|
|
|
|
|
|
log_Printf(LogLQM, "Analysis:\n");
|
|
|
|
|
|
|
|
LQRs = (newlqr->LastOutLQRs - oldlqr->LastOutLQRs) -
|
|
|
|
(newlqr->PeerInLQRs - oldlqr->PeerInLQRs);
|
|
|
|
transitLQRs = hdlc->lqm.lqr.OutLQRs - newlqr->LastOutLQRs;
|
|
|
|
pkts = (newlqr->LastOutPackets - oldlqr->LastOutPackets) -
|
|
|
|
(newlqr->PeerInPackets - oldlqr->PeerInPackets);
|
|
|
|
octets = (newlqr->LastOutOctets - oldlqr->LastOutOctets) -
|
|
|
|
(newlqr->PeerInOctets - oldlqr->PeerInOctets);
|
|
|
|
log_Printf(LogLQM, " Outbound lossage: %d LQR%s (%d en route), %d packet%s,"
|
|
|
|
" %d octet%s\n", (int)LQRs, LQRs == 1 ? "" : "s", (int)transitLQRs,
|
|
|
|
(int)pkts, pkts == 1 ? "" : "s",
|
|
|
|
(int)octets, octets == 1 ? "" : "s");
|
|
|
|
|
|
|
|
pkts = (newlqr->PeerOutPackets - oldlqr->PeerOutPackets) -
|
|
|
|
(hdlc->lqm.lqr.Save.InPackets - hdlc->lqm.lqr.prevSave.InPackets);
|
|
|
|
octets = (newlqr->PeerOutOctets - oldlqr->PeerOutOctets) -
|
|
|
|
(hdlc->lqm.lqr.Save.InOctets - hdlc->lqm.lqr.prevSave.InOctets);
|
|
|
|
log_Printf(LogLQM, " Inbound lossage: %d packet%s, %d octet%s\n",
|
|
|
|
(int)pkts, pkts == 1 ? "" : "s",
|
|
|
|
(int)octets, octets == 1 ? "" : "s");
|
|
|
|
|
|
|
|
disc = newlqr->PeerInDiscards - oldlqr->PeerInDiscards;
|
|
|
|
err = newlqr->PeerInErrors - oldlqr->PeerInErrors;
|
|
|
|
if (disc && err)
|
|
|
|
log_Printf(LogLQM, " Likely due to both peer congestion"
|
|
|
|
" and physical errors\n");
|
|
|
|
else if (disc)
|
|
|
|
log_Printf(LogLQM, " Likely due to peer congestion\n");
|
|
|
|
else if (err)
|
|
|
|
log_Printf(LogLQM, " Likely due to physical errors\n");
|
|
|
|
else if (pkts)
|
|
|
|
log_Printf(LogLQM, " Likely due to transport "
|
|
|
|
"congestion\n");
|
|
|
|
}
|
|
|
|
|
1999-05-08 11:07:56 +00:00
|
|
|
static struct mbuf *
|
2004-09-05 01:46:52 +00:00
|
|
|
lqr_LayerPush(struct bundle *b __unused, struct link *l, struct mbuf *bp,
|
|
|
|
int pri __unused, u_short *proto)
|
1999-05-08 11:07:56 +00:00
|
|
|
{
|
|
|
|
struct physical *p = link2physical(l);
|
2012-01-20 01:37:39 +00:00
|
|
|
int len, layer;
|
1999-05-08 11:07:56 +00:00
|
|
|
|
|
|
|
if (!p) {
|
|
|
|
/* Oops - can't happen :-] */
|
1999-12-20 20:29:47 +00:00
|
|
|
m_freem(bp);
|
1999-05-08 11:07:56 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2004-06-30 12:24:56 +00:00
|
|
|
bp = m_pullup(bp);
|
|
|
|
len = m_length(bp);
|
|
|
|
|
|
|
|
/*-
|
1999-05-08 11:07:56 +00:00
|
|
|
* From rfc1989:
|
|
|
|
*
|
|
|
|
* All octets which are included in the FCS calculation MUST be counted,
|
|
|
|
* including the packet header, the information field, and any padding.
|
|
|
|
* The FCS octets MUST also be counted, and one flag octet per frame
|
|
|
|
* MUST be counted. All other octets (such as additional flag
|
|
|
|
* sequences, and escape bits or octets) MUST NOT be counted.
|
|
|
|
*
|
2004-06-30 12:24:56 +00:00
|
|
|
* As we're stacked higher than the HDLC layer (otherwise HDLC wouldn't be
|
1999-05-08 11:07:56 +00:00
|
|
|
* able to calculate the FCS), we must not forget about these additional
|
|
|
|
* bytes when we're asynchronous.
|
|
|
|
*
|
2004-06-30 12:24:56 +00:00
|
|
|
* We're also expecting to be stacked *before* the likes of the proto and
|
|
|
|
* acf layers (to avoid alignment issues), so deal with this too.
|
1999-05-08 11:07:56 +00:00
|
|
|
*/
|
|
|
|
|
2004-06-30 12:24:56 +00:00
|
|
|
p->hdlc.lqm.ifOutUniPackets++;
|
|
|
|
p->hdlc.lqm.ifOutOctets += len + 1; /* plus 1 flag octet! */
|
|
|
|
for (layer = 0; layer < l->nlayers; layer++)
|
|
|
|
switch (l->layer[layer]->type) {
|
|
|
|
case LAYER_ACF:
|
|
|
|
p->hdlc.lqm.ifOutOctets += acf_WrapperOctets(&l->lcp, *proto);
|
|
|
|
break;
|
|
|
|
case LAYER_ASYNC:
|
|
|
|
/* Not included - see rfc1989 */
|
|
|
|
break;
|
|
|
|
case LAYER_HDLC:
|
2004-09-05 01:46:52 +00:00
|
|
|
p->hdlc.lqm.ifOutOctets += hdlc_WrapperOctets();
|
2004-06-30 12:24:56 +00:00
|
|
|
break;
|
|
|
|
case LAYER_LQR:
|
|
|
|
layer = l->nlayers;
|
|
|
|
break;
|
|
|
|
case LAYER_PROTO:
|
|
|
|
p->hdlc.lqm.ifOutOctets += proto_WrapperOctets(&l->lcp, *proto);
|
|
|
|
break;
|
|
|
|
case LAYER_SYNC:
|
|
|
|
/* Nothing to add on */
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
log_Printf(LogWARN, "Oops, don't know how to do octets for %s layer\n",
|
|
|
|
l->layer[layer]->name);
|
|
|
|
break;
|
|
|
|
}
|
1999-05-08 11:07:56 +00:00
|
|
|
|
|
|
|
if (*proto == PROTO_LQR) {
|
1999-06-02 15:59:09 +00:00
|
|
|
/* Overwrite the entire packet (created in SendLqrData()) */
|
1999-05-08 11:07:56 +00:00
|
|
|
struct lqrdata lqr;
|
2004-06-30 12:24:56 +00:00
|
|
|
size_t pending_pkts, pending_octets;
|
1999-05-08 11:07:56 +00:00
|
|
|
|
2004-06-30 12:24:56 +00:00
|
|
|
p->hdlc.lqm.lqr.OutLQRs++;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We need to compensate for the fact that we're pushing our data
|
|
|
|
* onto the highest priority queue by factoring out packet & octet
|
|
|
|
* values from other queues!
|
|
|
|
*/
|
|
|
|
link_PendingLowPriorityData(l, &pending_pkts, &pending_octets);
|
|
|
|
|
|
|
|
memset(&lqr, '\0', sizeof lqr);
|
1999-05-08 11:07:56 +00:00
|
|
|
lqr.MagicNumber = p->link.lcp.want_magic;
|
|
|
|
lqr.LastOutLQRs = p->hdlc.lqm.lqr.peer.PeerOutLQRs;
|
|
|
|
lqr.LastOutPackets = p->hdlc.lqm.lqr.peer.PeerOutPackets;
|
|
|
|
lqr.LastOutOctets = p->hdlc.lqm.lqr.peer.PeerOutOctets;
|
2004-06-30 12:24:56 +00:00
|
|
|
lqr.PeerInLQRs = p->hdlc.lqm.lqr.Save.InLQRs;
|
|
|
|
lqr.PeerInPackets = p->hdlc.lqm.lqr.Save.InPackets;
|
|
|
|
lqr.PeerInDiscards = p->hdlc.lqm.lqr.Save.InDiscards;
|
|
|
|
lqr.PeerInErrors = p->hdlc.lqm.lqr.Save.InErrors;
|
|
|
|
lqr.PeerInOctets = p->hdlc.lqm.lqr.Save.InOctets;
|
|
|
|
lqr.PeerOutLQRs = p->hdlc.lqm.lqr.OutLQRs;
|
|
|
|
lqr.PeerOutPackets = p->hdlc.lqm.ifOutUniPackets - pending_pkts;
|
|
|
|
/* Don't forget our ``flag'' octets.... */
|
|
|
|
lqr.PeerOutOctets = p->hdlc.lqm.ifOutOctets - pending_octets - pending_pkts;
|
|
|
|
lqr_Dump(l->name, "Output", &lqr);
|
1999-05-08 11:07:56 +00:00
|
|
|
lqr_ChangeOrder(&lqr, (struct lqrdata *)MBUF_CTOP(bp));
|
|
|
|
}
|
|
|
|
|
|
|
|
return bp;
|
|
|
|
}
|
|
|
|
|
1999-06-02 15:59:09 +00:00
|
|
|
static struct mbuf *
|
2004-09-05 01:46:52 +00:00
|
|
|
lqr_LayerPull(struct bundle *b __unused, struct link *l __unused,
|
|
|
|
struct mbuf *bp, u_short *proto)
|
1999-06-02 15:59:09 +00:00
|
|
|
{
|
|
|
|
/*
|
2004-06-30 12:24:56 +00:00
|
|
|
* This is the ``Rx'' process from rfc1989, although a part of it is
|
|
|
|
* actually performed by sync_LayerPull() & hdlc_LayerPull() so that
|
|
|
|
* our octet counts are correct.
|
1999-06-02 15:59:09 +00:00
|
|
|
*/
|
2004-06-30 12:24:56 +00:00
|
|
|
|
1999-06-02 15:59:09 +00:00
|
|
|
if (*proto == PROTO_LQR)
|
1999-12-20 20:29:47 +00:00
|
|
|
m_settype(bp, MB_LQRIN);
|
1999-06-02 15:59:09 +00:00
|
|
|
return bp;
|
|
|
|
}
|
|
|
|
|
1999-05-08 11:07:56 +00:00
|
|
|
/*
|
|
|
|
* Statistics for pulled packets are recorded either in hdlc_PullPacket()
|
|
|
|
* or sync_PullPacket()
|
|
|
|
*/
|
|
|
|
|
1999-06-02 15:59:09 +00:00
|
|
|
struct layer lqrlayer = { LAYER_LQR, "lqr", lqr_LayerPush, lqr_LayerPull };
|