summaryrefslogtreecommitdiff
path: root/usr.sbin
diff options
context:
space:
mode:
authorbrian <brian@cvs.openbsd.org>1998-01-10 01:55:18 +0000
committerbrian <brian@cvs.openbsd.org>1998-01-10 01:55:18 +0000
commit56909f6cc6f48c5a163fcd09e26c6700017e12f4 (patch)
treeb3fc5e6e070f081a91d217c838c9b719a7fb3585 /usr.sbin
parentb3c9a2210c6e2bdf4e7f0c39c494b60e02457403 (diff)
Implement Reset{Req,Ack} properly, as per rfc 1962.
(I completely mis-read the rfc last time 'round!) This means: o Better CCP/WARN Reset diagnostics. o After we've sent a REQ and before we've received an ACK, we drop incoming compressed data and send another REQ. o Before sending an ACK, re-sequence all pending PRI_NORMAL data in the modem queue so that pending packets won't get to the peer *after* the ResetAck. o Send ACKs with the `identifier' from the REQ frame. o After we've received a correct ACK, duplicate ACKs are ok (and will reset our history). o Incorrect ACKs (not matching the last REQ) are moaned about and dropped. Also, o Calculate the correct FCS after compressing a packet. DEFLATE *may* produce an mbuf with more than a single link in the chain, but HdlcOutput didn't know how to calculate the FCS :-( o Make `struct fsm'::reqid a u_char, not an int. This fix will prevent us from sending id `255' 2,000,000,000 times before wrapping to `0' for another 2,000,000,000 sends :-/ o Bump the version number a little (it should already have been at 1.6). The end result: DEFLATE now works over an unreliable link layer. I can txfr a 1.5Mb kernel over a (rather bad) null-modem cable at an average of 21679 bytes per second using rcp. Repeat after me: Don't test compression using a loopback ppp/tcp setup as we never lose packets and therefore never have to reset!
Diffstat (limited to 'usr.sbin')
-rw-r--r--usr.sbin/ppp/ccp.c34
-rw-r--r--usr.sbin/ppp/ccp.h7
-rw-r--r--usr.sbin/ppp/deflate.c25
-rw-r--r--usr.sbin/ppp/fsm.c18
-rw-r--r--usr.sbin/ppp/fsm.h4
-rw-r--r--usr.sbin/ppp/hdlc.c17
-rw-r--r--usr.sbin/ppp/modem.c12
-rw-r--r--usr.sbin/ppp/modem.h3
-rw-r--r--usr.sbin/ppp/vars.c6
9 files changed, 84 insertions, 42 deletions
diff --git a/usr.sbin/ppp/ccp.c b/usr.sbin/ppp/ccp.c
index c0fb3e236f0..6b6a960858c 100644
--- a/usr.sbin/ppp/ccp.c
+++ b/usr.sbin/ppp/ccp.c
@@ -17,7 +17,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
- * $Id: ccp.c,v 1.7 1998/01/04 20:29:21 brian Exp $
+ * $Id: ccp.c,v 1.8 1998/01/10 01:55:13 brian Exp $
*
* TODO:
* o Support other compression protocols
@@ -43,7 +43,7 @@
#include "pred.h"
#include "deflate.h"
-struct ccpstate CcpInfo = { -1, -1 };
+struct ccpstate CcpInfo = { -1, -1, -1, -1 };
static void CcpSendConfigReq(struct fsm *);
static void CcpSendTerminateReq(struct fsm *);
@@ -146,6 +146,7 @@ ccpstateInit(void)
out_algorithm = -1;
memset(&CcpInfo, '\0', sizeof CcpInfo);
CcpInfo.his_proto = CcpInfo.my_proto = -1;
+ CcpInfo.reset_sent = CcpInfo.last_reset = -1;
}
void
@@ -189,7 +190,9 @@ CcpSendConfigReq(struct fsm *fp)
void
CcpSendResetReq(struct fsm *fp)
{
- LogPrintf(LogCCP, "CcpSendResetReq\n");
+ LogPrintf(LogCCP, "SendResetReq(%d)\n", fp->reqid);
+ CcpInfo.reset_sent = fp->reqid;
+ CcpInfo.last_reset = -1;
FsmOutput(fp, CODE_RESETREQ, fp->reqid, NULL, 0);
}
@@ -378,8 +381,24 @@ CcpInput(struct mbuf *bp)
}
void
-CcpResetInput()
+CcpResetInput(u_char id)
{
+ if (CcpInfo.reset_sent != -1) {
+ if (id != CcpInfo.reset_sent) {
+ LogPrintf(LogWARN, "CCP: Incorrect ResetAck (id %d, not %d) ignored\n",
+ id, CcpInfo.reset_sent);
+ return;
+ }
+ /* Whaddaya know - a correct reset ack */
+ } else if (id == CcpInfo.last_reset)
+ LogPrintf(LogCCP, "Duplicate ResetAck (resetting again)\n");
+ else {
+ LogPrintf(LogWARN, "CCP: Unexpected ResetAck (id %d) ignored\n", id);
+ return;
+ }
+
+ CcpInfo.last_reset = CcpInfo.reset_sent;
+ CcpInfo.reset_sent = -1;
if (in_algorithm >= 0 && in_algorithm < NALGORITHMS)
(*algorithm[in_algorithm]->i.Reset)();
}
@@ -395,7 +414,12 @@ CcpOutput(int pri, u_short proto, struct mbuf *m)
struct mbuf *
CompdInput(u_short *proto, struct mbuf *m)
{
- if (in_algorithm >= 0 && in_algorithm < NALGORITHMS)
+ if (CcpInfo.reset_sent != -1) {
+ /* Send another REQ and put the packet in the bit bucket */
+ LogPrintf(LogCCP, "ReSendResetReq(%d)\n", CcpInfo.reset_sent);
+ FsmOutput(&CcpFsm, CODE_RESETREQ, CcpInfo.reset_sent, NULL, 0);
+ pfree(m);
+ } else if (in_algorithm >= 0 && in_algorithm < NALGORITHMS)
return (*algorithm[in_algorithm]->i.Read)(proto, m);
return NULL;
}
diff --git a/usr.sbin/ppp/ccp.h b/usr.sbin/ppp/ccp.h
index 732ccafc3db..b10ad9e8280 100644
--- a/usr.sbin/ppp/ccp.h
+++ b/usr.sbin/ppp/ccp.h
@@ -15,7 +15,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
- * $Id: ccp.h,v 1.3 1998/01/04 20:29:22 brian Exp $
+ * $Id: ccp.h,v 1.4 1998/01/10 01:55:14 brian Exp $
*
* TODO:
*/
@@ -39,6 +39,9 @@ struct ccpstate {
u_long his_proto; /* peer's compression protocol */
u_long my_proto; /* our compression protocol */
+ int reset_sent; /* If != -1, ignore compressed 'till ack */
+ int last_reset; /* We can receive more (dups) w/ this id */
+
u_long his_reject; /* Request codes rejected by peer */
u_long my_reject; /* Request codes I have rejected */
@@ -83,7 +86,7 @@ extern void CcpUp(void);
extern void CcpOpen(void);
extern void CcpInit(void);
extern int ReportCcpStatus(struct cmdargs const *);
-extern void CcpResetInput(void);
+extern void CcpResetInput(u_char);
extern int CcpOutput(int, u_short, struct mbuf *);
extern struct mbuf *CompdInput(u_short *, struct mbuf *);
extern void CcpDictSetup(u_short, struct mbuf *);
diff --git a/usr.sbin/ppp/deflate.c b/usr.sbin/ppp/deflate.c
index 5ac759d60b3..6973cdbddab 100644
--- a/usr.sbin/ppp/deflate.c
+++ b/usr.sbin/ppp/deflate.c
@@ -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.4 1997/12/28 02:16:34 brian Exp $
+ * $Id: deflate.c,v 1.5 1998/01/10 01:55:14 brian Exp $
*/
#include <sys/param.h>
@@ -50,7 +50,7 @@
/* Our state */
struct deflate_state {
u_short seqno;
- int dodgy_seqno;
+ int uncomp_rec;
z_stream cx;
};
@@ -66,7 +66,7 @@ static void
DeflateResetOutput(void)
{
OutputState.seqno = 0;
- OutputState.dodgy_seqno = 0;
+ OutputState.uncomp_rec = 0;
deflateReset(&OutputState.cx);
LogPrintf(LogCCP, "Deflate: Output channel reset\n");
}
@@ -192,7 +192,7 @@ static void
DeflateResetInput(void)
{
InputState.seqno = 0;
- InputState.dodgy_seqno = 0;
+ InputState.uncomp_rec = 0;
inflateReset(&InputState.cx);
LogPrintf(LogCCP, "Deflate: Input channel reset\n");
}
@@ -214,7 +214,12 @@ DeflateInput(u_short *proto, struct mbuf *mi)
seq = (hdr[0] << 8) + hdr[1];
LogPrintf(LogDEBUG, "DeflateInput: Seq %d\n", seq);
if (seq != InputState.seqno) {
- if (InputState.dodgy_seqno && seq < InputState.seqno)
+ if (seq <= InputState.uncomp_rec)
+ /*
+ * So the peer's started at zero again - fine ! If we're wrong,
+ * inflate() will fail. This is better than getting into a loop
+ * trying to get a ResetReq to a busy sender.
+ */
InputState.seqno = seq;
else {
LogPrintf(LogERROR, "DeflateInput: Seq error: Got %d, expected %d\n",
@@ -225,7 +230,7 @@ DeflateInput(u_short *proto, struct mbuf *mi)
}
}
InputState.seqno++;
- InputState.dodgy_seqno = 0;
+ InputState.uncomp_rec = 0;
/* Allocate an output mbuf */
mo_head = mo = mballoc(DEFLATE_CHUNK_LEN, MB_IPIN);
@@ -420,6 +425,7 @@ DeflateDictSetup(u_short proto, struct mbuf *mi)
CcpInfo.uncompin += len;
InputState.seqno++;
+ InputState.uncomp_rec++;
mbfree(mi_head); /* lose our allocated ``head'' buf */
}
@@ -533,13 +539,6 @@ DeflateInitInput(void)
if (inflateInit2(&InputState.cx, -iWindowSize) != Z_OK)
return 0;
DeflateResetInput();
- /*
- * When we begin, we may start adding to our dictionary before the
- * peer does. If `dodgy_seqno' is set, we'll allow the peer to send
- * us a seqno that's too small and just adjust seqno accordingly -
- * deflate is a sliding window compressor !
- */
- InputState.dodgy_seqno = 1;
return 1;
}
diff --git a/usr.sbin/ppp/fsm.c b/usr.sbin/ppp/fsm.c
index caf4938fc35..32b2c053263 100644
--- a/usr.sbin/ppp/fsm.c
+++ b/usr.sbin/ppp/fsm.c
@@ -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.4 1997/12/24 09:30:31 brian Exp $
+ * $Id: fsm.c,v 1.5 1998/01/10 01:55:15 brian Exp $
*
* TODO:
* o Refer loglevel for log output
@@ -724,18 +724,24 @@ FsmRecvTimeRemain(struct fsm * fp, struct fsmheader * lhp, struct mbuf * bp)
static void
FsmRecvResetReq(struct fsm * fp, struct fsmheader * lhp, struct mbuf * bp)
{
- LogPrintf(fp->LogLevel, "RecvResetReq\n");
+ LogPrintf(fp->LogLevel, "RecvResetReq(%d)\n", lhp->id);
CcpRecvResetReq(fp);
- LogPrintf(fp->LogLevel, "SendResetAck\n");
- FsmOutput(fp, CODE_RESETACK, fp->reqid, NULL, 0);
+ /*
+ * All sendable compressed packets are queued in the PRI_NORMAL modem
+ * output queue.... dump 'em to the priority queue so that they arrive
+ * at the peer before our ResetAck.
+ */
+ SequenceQueues();
+ LogPrintf(fp->LogLevel, "SendResetAck(%d)\n", lhp->id);
+ FsmOutput(fp, CODE_RESETACK, lhp->id, NULL, 0);
pfree(bp);
}
static void
FsmRecvResetAck(struct fsm * fp, struct fsmheader * lhp, struct mbuf * bp)
{
- LogPrintf(fp->LogLevel, "RecvResetAck\n");
- CcpResetInput();
+ LogPrintf(fp->LogLevel, "RecvResetAck(%d)\n", lhp->id);
+ CcpResetInput(lhp->id);
fp->reqid++;
pfree(bp);
}
diff --git a/usr.sbin/ppp/fsm.h b/usr.sbin/ppp/fsm.h
index cd56347f049..8f17c7b588b 100644
--- a/usr.sbin/ppp/fsm.h
+++ b/usr.sbin/ppp/fsm.h
@@ -15,7 +15,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
- * $Id: fsm.h,v 1.2 1997/12/06 12:08:57 brian Exp $
+ * $Id: fsm.h,v 1.3 1998/01/10 01:55:15 brian Exp $
*
* TODO:
*/
@@ -52,7 +52,7 @@ struct fsm {
u_short max_code;
int open_mode;
int state; /* State of the machine */
- int reqid; /* Next request id */
+ u_char reqid; /* Next request id */
int restart; /* Restart counter value */
int maxconfig;
diff --git a/usr.sbin/ppp/hdlc.c b/usr.sbin/ppp/hdlc.c
index e1c5a578df5..3f9b797d28a 100644
--- a/usr.sbin/ppp/hdlc.c
+++ b/usr.sbin/ppp/hdlc.c
@@ -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.5 1998/01/06 01:03:01 brian Exp $
+ * $Id: hdlc.c,v 1.6 1998/01/10 01:55:16 brian Exp $
*
* TODO:
*/
@@ -223,12 +223,13 @@ HdlcOutput(int pri, u_short proto, struct mbuf * bp)
LqrChangeOrder(lqr, (struct lqrdata *) (MBUF_CTOP(bp)));
}
if (!DEV_IS_SYNC) {
- fcs = HdlcFcs(INITFCS, MBUF_CTOP(mhp), mhp->cnt);
- fcs = HdlcFcs(fcs, MBUF_CTOP(bp), bp->cnt);
+ mfcs->cnt = 0;
+ fcs = HdlcFcsBuf(INITFCS, mhp);
fcs = ~fcs;
cp = MBUF_CTOP(mfcs);
*cp++ = fcs & 0377; /* Low byte first!! */
*cp++ = fcs >> 8;
+ mfcs->cnt = 2;
}
LogDumpBp(LogHDLC, "HdlcOutput", mhp);
for (statp = ProtocolStat; statp->number; statp++)
@@ -381,11 +382,11 @@ DecodePacket(u_short proto, struct mbuf * bp)
* If proto isn't PROTO_COMPD, we still want to pass it to the
* decompression routines so that the dictionary's updated
*/
- if (proto == PROTO_COMPD) {
- if ((bp = CompdInput(&proto, bp)) == NULL)
- return;
- } else if ((proto & 0xfff1) == 0x21) /* Network Layer protocol */
- if (CcpFsm.state == ST_OPENED)
+ if (CcpFsm.state == ST_OPENED)
+ if (proto == PROTO_COMPD) {
+ if ((bp = CompdInput(&proto, bp)) == NULL)
+ return;
+ } else if ((proto & 0xfff1) == 0x21) /* Network Layer protocol */
CcpDictSetup(proto, bp);
switch (proto) {
diff --git a/usr.sbin/ppp/modem.c b/usr.sbin/ppp/modem.c
index e4b8d98e95c..b1bb7808b4a 100644
--- a/usr.sbin/ppp/modem.c
+++ b/usr.sbin/ppp/modem.c
@@ -17,7 +17,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
- * $Id: modem.c,v 1.7 1997/12/30 23:22:37 brian Exp $
+ * $Id: modem.c,v 1.8 1998/01/10 01:55:16 brian Exp $
*
* TODO:
*/
@@ -94,7 +94,7 @@ Enqueue(struct mqueue * queue, struct mbuf * bp)
}
struct mbuf *
-Dequeue(struct mqueue * queue)
+Dequeue(struct mqueue *queue)
{
struct mbuf *bp;
@@ -112,6 +112,14 @@ Dequeue(struct mqueue * queue)
return (bp);
}
+void
+SequenceQueues()
+{
+ LogPrintf(LogDEBUG, "SequenceQueues\n");
+ while (OutputQueues[PRI_NORMAL].qlen)
+ Enqueue(OutputQueues + PRI_LINK, Dequeue(OutputQueues + PRI_NORMAL));
+}
+
static struct speeds {
int nspeed;
speed_t speed;
diff --git a/usr.sbin/ppp/modem.h b/usr.sbin/ppp/modem.h
index 0fd81148090..7112096582d 100644
--- a/usr.sbin/ppp/modem.h
+++ b/usr.sbin/ppp/modem.h
@@ -15,7 +15,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
- * $Id: modem.h,v 1.1 1997/11/23 20:27:35 brian Exp $
+ * $Id: modem.h,v 1.2 1998/01/10 01:55:17 brian Exp $
*
* TODO:
*/
@@ -38,5 +38,6 @@ extern void HangupModem(int);
extern int ShowModemStatus(struct cmdargs const *);
extern void Enqueue(struct mqueue *, struct mbuf *);
extern struct mbuf *Dequeue(struct mqueue *);
+extern void SequenceQueues(void);
extern void ModemAddInOctets(int);
extern void ModemAddOutOctets(int);
diff --git a/usr.sbin/ppp/vars.c b/usr.sbin/ppp/vars.c
index ad3ddb5bf65..beb4cf451b5 100644
--- a/usr.sbin/ppp/vars.c
+++ b/usr.sbin/ppp/vars.c
@@ -17,7 +17,7 @@
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
- * $Id: vars.c,v 1.4 1997/12/29 22:23:08 brian Exp $
+ * $Id: vars.c,v 1.5 1998/01/10 01:55:17 brian Exp $
*
*/
#include <sys/param.h>
@@ -38,8 +38,8 @@
#include "vars.h"
#include "auth.h"
-char VarVersion[] = "PPP Version 1.5";
-char VarLocalVersion[] = "$Date: 1997/12/29 22:23:08 $";
+char VarVersion[] = "PPP Version 1.65";
+char VarLocalVersion[] = "$Date: 1998/01/10 01:55:17 $";
int Utmp = 0;
int ipInOctets = 0;
int ipOutOctets = 0;