@@ 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 */
@@ 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:
@@ 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 */