diff options
author | brian <brian@FreeBSD.org> | 1998-03-12 02:23:42 +0000 |
---|---|---|
committer | brian <brian@FreeBSD.org> | 1998-03-12 02:23:42 +0000 |
commit | a8479404200bfc50e062e281337d95b91d6a9a75 (patch) | |
tree | 96c444d4e63628df31d0714b1d5172c8979882f4 /usr.sbin/ppp/lqr.c | |
parent | 279390da0fed6c4baa132126919daedde8bcd717 (diff) | |
download | FreeBSD-src-a8479404200bfc50e062e281337d95b91d6a9a75.zip FreeBSD-src-a8479404200bfc50e062e281337d95b91d6a9a75.tar.gz |
o Fix a few comment typos.
o Fix ``set timeout'' usage message and documentation.
o Change ifOutPackets, ifOutOctets and ifOutLQRs to `u_int32_t's
so that they wrap correctly.
o Put the LQR in network byte order using the correct struct size
(sizeof u_int32_t, not sizeof u_long).
o Wrap LQR ECHO counters correctly.
o Don't increment OutLQR count if the last LQR hasn't been replied
to.
o Initialise HisLqrData (last received LQR) in StartLqm.
o Don't start the LQR timer if we're `disabled' and `accepted'.
o Generate LQR responses when both sides are using a timer and
we're not going to send our next LQR before the peers max timeout.
LQR should now be fully functional.
Diffstat (limited to 'usr.sbin/ppp/lqr.c')
-rw-r--r-- | usr.sbin/ppp/lqr.c | 67 |
1 files changed, 38 insertions, 29 deletions
diff --git a/usr.sbin/ppp/lqr.c b/usr.sbin/ppp/lqr.c index 2820f10..6303453 100644 --- a/usr.sbin/ppp/lqr.c +++ b/usr.sbin/ppp/lqr.c @@ -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.21 1998/01/11 17:50:40 brian Exp $ + * $Id: lqr.c,v 1.22 1998/01/21 02:15:19 brian Exp $ * * o LQR based on RFC1333 * @@ -29,6 +29,7 @@ #include <netinet/in.h> #include <stdio.h> +#include <string.h> #include "command.h" #include "mbuf.h" @@ -91,7 +92,10 @@ RecvEchoLqr(struct mbuf * bp) if (htonl(lqr->signature) == SIGNATURE) { seq = ntohl(lqr->sequence); LogPrintf(LogLQM, "Got echo LQR [%d]\n", ntohl(lqr->sequence)); - gotseq = seq; + /* careful not to update gotseq with older values */ + if ((gotseq > (u_int32_t)0 - 5 && seq < 5) || + (gotseq <= (u_int32_t)0 - 5 && seq > gotseq)) + gotseq = seq; } } } @@ -104,7 +108,7 @@ LqrChangeOrder(struct lqrdata * src, struct lqrdata * dst) sp = (u_long *) src; dp = (u_long *) dst; - for (n = 0; n < sizeof(struct lqrdata) / sizeof(u_long); n++) + for (n = 0; n < sizeof(struct lqrdata) / sizeof(u_int32_t); n++) *dp++ = ntohl(*sp++); } @@ -117,12 +121,12 @@ SendLqrReport(void *v) if (lqmmethod & LQM_LQR) { if (lqrsendcnt > 5) { - /* * XXX: Should implement LQM strategy */ - LogPrintf(LogPHASE, "** 1 Too many ECHO packets are lost. **\n"); - lqmmethod = 0; /* Prevent rcursion via LcpClose() */ + LogPrintf(LogPHASE, "** Too many LQR packets lost **\n"); + LogPrintf(LogLQM, "LqrOutput: Too many LQR packets lost\n"); + lqmmethod = 0; /* Prevent recursion via LcpClose() */ reconnect(RECON_TRUE); LcpClose(); } else { @@ -131,15 +135,17 @@ SendLqrReport(void *v) lqrsendcnt++; } } else if (lqmmethod & LQM_ECHO) { - if (echoseq - gotseq > 5) { - LogPrintf(LogPHASE, "** 2 Too many ECHO packets are lost. **\n"); - lqmmethod = 0; /* Prevent rcursion via LcpClose() */ + if ((echoseq > 5 && echoseq - 5 > gotseq) || + (echoseq <= 5 && echoseq > gotseq + 5)) { + LogPrintf(LogPHASE, "** Too many ECHO LQR packets lost **\n"); + LogPrintf(LogLQM, "LqrOutput: Too many ECHO LQR packets lost\n"); + lqmmethod = 0; /* Prevent recursion via LcpClose() */ reconnect(RECON_TRUE); LcpClose(); } else SendEchoReq(); } - if (lqmmethod && Enabled(ConfLqr)) + if (lqmmethod && LqrTimer.load) StartTimer(&LqrTimer); } @@ -179,12 +185,15 @@ LqrInput(struct mbuf * bp) lqrsendcnt = 0; /* we have received LQR from peer */ /* - * Generate LQR responce to peer, if i) We are not running LQR timer. ii) - * Two successive LQR's PeerInLQRs are same. + * Generate an LQR response to peer we're not running LQR timer OR + * two successive LQR's PeerInLQRs are same OR we're not going to + * send our next one before the peers max timeout. */ - if (LqrTimer.load == 0 || lastpeerin == HisLqrData.PeerInLQRs) { + if (LqrTimer.load == 0 || lastpeerin == HisLqrData.PeerInLQRs || + (LqrTimer.arg && + LqrTimer.rest * 100 / SECTICKS > (u_int32_t)LqrTimer.arg)) { lqmmethod |= LQM_LQR; - SendLqrReport(0); + SendLqrReport(LqrTimer.arg); } lastpeerin = HisLqrData.PeerInLQRs; } @@ -198,34 +207,34 @@ void StartLqm() { struct lcpstate *lcp = &LcpInfo; - int period; lqrsendcnt = 0; /* start waiting all over for ECHOs */ echoseq = 0; gotseq = 0; + memset(&HisLqrData, '\0', sizeof HisLqrData); lqmmethod = LQM_ECHO; if (Enabled(ConfLqr)) lqmmethod |= LQM_LQR; StopTimer(&LqrTimer); - LogPrintf(LogLQM, "LQM method = %d\n", lqmmethod); - if (lcp->his_lqrperiod || lcp->want_lqrperiod) { + if (lcp->his_lqrperiod) + LogPrintf(LogLQM, "Expecting LQR every %d.%02d secs\n", + lcp->his_lqrperiod / 100, lcp->his_lqrperiod % 100); - /* - * We need to run timer. Let's figure out period. - */ - period = lcp->his_lqrperiod ? lcp->his_lqrperiod : lcp->want_lqrperiod; - StopTimer(&LqrTimer); + if (lcp->want_lqrperiod) { + LogPrintf(LogLQM, "Will send %s every %d.%02d secs\n", + lqmmethod & LQM_LQR ? "LQR" : "ECHO LQR", + lcp->want_lqrperiod / 100, lcp->want_lqrperiod % 100); LqrTimer.state = TIMER_STOPPED; - LqrTimer.load = period * SECTICKS / 100; + LqrTimer.load = lcp->want_lqrperiod * SECTICKS / 100; LqrTimer.func = SendLqrReport; - SendLqrReport(0); - StartTimer(&LqrTimer); - LogPrintf(LogLQM, "Will send LQR every %d.%d secs\n", - period / 100, period % 100); + LqrTimer.arg = (void *)lcp->his_lqrperiod; + SendLqrReport(LqrTimer.arg); } else { - LogPrintf(LogLQM, "LQR is not activated.\n"); + LqrTimer.load = 0; + if (!lcp->his_lqrperiod) + LogPrintf(LogLQM, "LQR/ECHO LQR not negotiated\n"); } } @@ -246,7 +255,7 @@ StopLqr(int method) LogPrintf(LogLQM, "Stop sending LCP ECHO.\n"); lqmmethod &= ~method; if (lqmmethod) - SendLqrReport(0); + SendLqrReport(LqrTimer.arg); else StopTimer(&LqrTimer); } |