From 0f0dee3f1021eeaf794a657df226c35d96efbc84 Mon Sep 17 00:00:00 2001 From: David du Colombier <0intro@gmail.com> Date: Sun, 5 Jan 1992 00:00:00 +0000 Subject: [PATCH] Plan 9 from Bell Labs 1992-01-05 --- port/ipdat.h | 1 - port/stil.c | 16 ++++++++-------- port/tcpinput.c | 50 +++++++++++++++++++++++++++---------------------- 3 files changed, 36 insertions(+), 31 deletions(-) diff --git a/port/ipdat.h b/port/ipdat.h index 9c45a080b0e13e336da9900a4d43f5df78434419..68b6f6916daad45f4911b74bc14952ac92bcf8f9 100644 --- a/port/ipdat.h +++ b/port/ipdat.h @@ -104,7 +104,6 @@ struct Ilcb /* Control block */ QLock outo; /* Out of order packet queue */ Block *outoforder; - int oblks; /* Number of blocks in queue */ Lock nxl; ulong next; /* Id of next to send */ diff --git a/port/stil.c b/port/stil.c index cf97e1a9353949d25afec2319e82a67901964c67..1848811ff36a923f4ae69bd7ee396565adb76f94 100644 --- a/port/stil.c +++ b/port/stil.c @@ -114,6 +114,7 @@ iloput(Queue *q, Block *bp) Ilcb *ic; int dlen; Block *np, *f; + ulong id; ipc = (Ipconv *)(q->ptr); if(ipc->psrc == 0) @@ -158,9 +159,12 @@ iloput(Queue *q, Block *bp) hnputs(ih->illen, dlen+IL_HDRSIZE); hnputs(ih->ilsrc, ipc->psrc); hnputs(ih->ildst, ipc->pdst); + lock(&ic->nxl); - hnputl(ih->ilid, ic->next++); + id = ic->next++; unlock(&ic->nxl); + hnputl(ih->ilid, id); + hnputl(ih->ilack, ic->recvd); ih->iltype = Ildata; ih->ilspec = 0; @@ -250,7 +254,7 @@ ilrcvmsg(Ipconv *ipc, Block *bp) if(ilcksum && ptcl_csum(bp, IL_EHSIZE, illen) != 0) { st = (ih->iltype < 0 || ih->iltype > Ilclose) ? "?" : iltype[ih->iltype]; - print("il: cksum error, pkt(%s id %d ack %d %d.%d.%d.%d/%d->%d)\n", + print("il: cksum error, pkt(%s id %lud ack %lud %d.%d.%d.%d/%d->%d)\n", st, nhgetl(ih->ilid), nhgetl(ih->ilack), fmtaddr(dst), sp, dp); goto drop; } @@ -314,8 +318,7 @@ void _ilprocess(Ipconv *s, Ilhdr *h, Block *bp) { Ilcb *ic; - Block *nb, *next; - ulong id, ack, dlen; + ulong id, ack; id = nhgetl(h->ilid); ack = nhgetl(h->ilack); @@ -561,7 +564,6 @@ ilpullup(Ipconv *s) ic->recvd = oid; ic->outoforder = bp->list; - ic->oblks--; qunlock(&ic->outo); bp->list = 0; @@ -587,14 +589,13 @@ iloutoforder(Ipconv *s, Ilhdr *h, Block *bp) id = nhgetl(h->ilid); /* Window checks */ - if(id <= ic->recvd || ic->oblks > ic->window) { + if(id <= ic->recvd || id > ic->recvd+ic->window) { freeb(bp); return; } /* Packet is acceptable so sort onto receive queue for pullup */ qlock(&ic->outo); - ic->oblks++; if(ic->outoforder == 0) ic->outoforder = bp; else { @@ -753,7 +754,6 @@ ilstart(Ipconv *ipc, int type, int window) ic->next = ic->start+1; ic->recvd = 0; ic->window = window; - ic->oblks = 0; switch(type) { case IL_PASSIVE: diff --git a/port/tcpinput.c b/port/tcpinput.c index 0b846bd84dc3eb65c12aaec5a39c9395d13fe8e1..313e5f2350efabca60e7fb4a7bdb875c53c5d187 100644 --- a/port/tcpinput.c +++ b/port/tcpinput.c @@ -784,31 +784,37 @@ dupb(Block **hp, Block *bp, int offset, int count) Block * copyb(Block *bp, int count) { - Block *nbp, *head, *tail; - int i; - - head = tail = 0; - while(bp && count) { - i = BLEN(bp); - nbp = allocb(i); - if(i > nbp->lim-nbp->wptr) { - if(head) - freeb(head); - return 0; - } - memmove(nbp->wptr, bp->rptr, i); - nbp->wptr += i; - count -= i; - if(head == 0) - head = nbp; - else - tail->next = nbp; + Block *nb, *head, **p; + int l; - tail = nbp; + p = &head; + while(count) { + l = BLEN(bp); + if(count < l) + l = count; + nb = allocb(l); + if(nb == 0) + panic("copyb.1"); + memmove(nb->wptr, bp->rptr, l); + nb->wptr += l; + count -= l; + *p = nb; + p = &nb->next; bp = bp->next; + if(bp == 0) + break; } - - return head; + if(count) { + nb = allocb(count); + if(nb == 0) + panic("copyb.2"); + memset(nb->wptr, 0, count); + nb->wptr += count; + *p = nb; + } + if(blen(head) == 0) + print("copyb: zero length\n"); + return head; } ushort tcp_mss = DEF_MSS; /* Maximum segment size to be sent with SYN */