Plan 9 from Bell Labs’s /usr/web/sources/extra/9hist/port/stil.c

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


## diffname port/stil.c 1991/1012
## diff -e /dev/null /n/bootesdump/1991/1012/sys/src/9/port/stil.c
0a
/*
 * stil - Internet link protocol
 */
#include	"u.h"
#include	"lib.h"
#include	"mem.h"
#include	"dat.h"
#include	"fns.h"
#include	"io.h"
#include	"errno.h"
#include	"arp.h"
#include 	"ipdat.h"

#define DPRINT if(pip)print

void	ilrcvmsg(Ipconv *, Block *);

void
ilopen(Queue *q, Stream *s)
{
	Ipconv *ipc;

	ipc = &ipconv[s->dev][s->id];
	ipc->ipinterface = newipifc(IP_ILPROTO, ilrcvmsg, ipconv[s->dev],
			            1500, 512, ETHER_HDR, "IL");

	qlock(ipc);
	ipc->ref++;
	qunlock(ipc);
	ipc->readq = RD(q);	
	RD(q)->ptr = (void *)ipc;
	WR(q)->next->ptr = (void *)ipc->ipinterface;
	WR(q)->ptr = (void *)ipc;
}

void
ilclose(Queue *q)
{
}

void
iloput(Queue *q, Block *bp)
{
	Ipconv *ipc;
	Ilhdr *ih;
	int dlen;

	/* Prepend udp header to packet and pass on to ip layer */
	ipc = (Ipconv *)(q->ptr);
	if(ipc->psrc == 0)
		error(Enoport);

	if(bp->type != M_DATA) {
		freeb(bp);
		error(Ebadctl);
	}

	/* Only allow atomic Il writes to form datagrams */
	if(!(bp->flags & S_DELIM)) {
		freeb(bp);
		error(Emsgsize);
	}

	dlen = blen(bp);
	if(dlen > IL_DATMAX) {
		freeb(bp);
		error(Emsgsize);
	}

	/* Make space to fit il & ip & ethernet header */
	bp = padb(bp, IL_EHSIZE+IL_HDRSIZE);

	ih = (Ilhdr *)(bp->rptr);

	hnputs(ih->illen, dlen+IL_EHSIZE+IL_HDRSIZE);
	hnputs(ih->ilsrc, ipc->psrc);
	hnputs(ih->ildst, ipc->pdst);
	ih->iltype = Ildata;
	ih->ilspec = 0;
	hnputl(ih->ilid, ipc->ilctl.sent++);
	hnputl(ih->ilack, ipc->ilctl.recvd);
	ih->ilsum[0] = 0;
	ih->ilsum[1] = 0;

	PUTNEXT(q, bp);
}


void
iliput(Queue *q, Block *bp)
{
}
.
## diffname port/stil.c 1991/1013
## diff -e /n/bootesdump/1991/1012/sys/src/9/port/stil.c /n/bootesdump/1991/1013/sys/src/9/port/stil.c
90a
{
	PUTNEXT(q, bp);
}

void
ilrcvmsg(Ipconv *ipc, Block *bp)
{
	Ilhdr *ih;

	ih = (Ilhdr *)bp;

	plen = blen(bp);
	if(plen < IL_EHSIZE+IL_HDRSIZE)
		goto drop;

	if(ilcksum && ptcl_csum(bp, IL_EHSIZE, plen) != 0) {
		print("il: cksum error\n");
		goto drop;
	}

	s = ip_conn(ipc, hngets(ih->ildst), hngets(ih->ilsrc), hngetl(), IP_ILPROTO);
	if(s == 0) {
		ilsentctl(0, ih, Ilreset);
		goto drop;
	}

	switch(s->state) {
	case Closed:
		ilsentctl(0, ih, Ilreset);
		goto drop;
	case Syncee:
	case Syncer:
	case Established:
	case Closing:
	}	
	
drop:
	freeb(bp);
}

void
ilsendctl(Ipconv *ipc, Ilhdr *inih, int type)
{
	Ilhdr *ih;
	Ilcb *ic;
	Block *bp;

	bp = allocb(IL_EHSIZE+IL_HDRSIZE);
	ih = (Ilhdr *)(bp->rptr);
	ic = &ipc->ilctl;

	hnputs(ih->illen, IL_EHSIZE+IL_HDRSIZE);
	if(inih) {
		hnputs(ih->ilsrc, inih->ildst);
		hnputs(ih->ildst, inih->ilsrc);
		hnputl(ih->ilid, inih->recvd);
		hnputl(ih->ilack, inih->sent);
	}
	else {
		hnputs(ih->ilsrc, ipc->psrc);
		hnputs(ih->ildst, ipc->pdst);
		hnputl(ih->ilid, ic->sent);
		hnputl(ih->ilack, ic->recvd);
	}
	ih->iltype = type;
	ih->ilspec = 0;
	ih->ilsum[0] = 0;
	ih->ilsum[1] = 0;

	if(ilcksum)
		hnputs(ih->ilsum, ptcl_csum(bp, IL_EHSIZE, IL_HDRSIZE));

	PUTNEXT(Iloutput, bp);
}

void
ilackproc(void *junk)
.
88d
84a
	/* Checksum of ilheader plus data (not ip & no pseudo header) */
	if(ilcksum)
		hnputs(ih->ilsum, ptcl_csum(bp, IL_EHSIZE, dlen+IL_HDRSIZE));

	/* Enqueue a copy on the unacked queue in case this one gets lost */
	np = copyb(bp, blen(bp));
	if(ic->unacked) {
		ic->unackedtail->next = np;
		ic->unackedtail = np;
	}
	else {
		ic->unacked = np;
		ic->unackedtail = np;
	}
	np->next = 0;

.
80,81c
	hnputl(ih->ilid, ic->sent++);
	hnputl(ih->ilack, ic->recvd);
.
73a
	ic = &ipc->ilctl;
.
46a
	Block *np;
.
45a
	Ilcb *ic;
.
22a
	/* Start il service processes */
	if(!Iloutput) {
		Iloutput = WR(q);
		/* This never goes away - we use this queue to send acks/rejects */
		s->opens++;
		s->inuse++;
		kproc("ilack", ilackproc, 0);
	}

.
16c
void	ilrcvmsg(Ipconv*, Block*);
void	ilackproc(void*);
.
14a
int ilcksum = 1;
Queue	*Iloutput;		/* Il to lance output channel */
.
## diffname port/stil.c 1991/1014
## diff -e /n/bootesdump/1991/1013/sys/src/9/port/stil.c /n/bootesdump/1991/1014/sys/src/9/port/stil.c
198a
}

void
ilstart(Ipconv *ipc, int type, int window)
{
	Ilcb *ic = &ipc->ilctl;

	if(ic->state != Ilclosed)
		return;

	ic->unacked = 0;
	ic->outoforder = 0;
	initseq += TK2MS(MACHP(0)->ticks);
	ic->sent = initseq;
	ic->recvd = ic->sent;
	ic->lastack = ic->sent;
	ic->window = window;

	switch(type) {
	case IL_PASSIVE:
		ic->state = Illistening;
		break;
	case IL_ACTIVE:
		ic->state = Ilsyncer;
		ilsendctl(ipc, 0, Ilsync);
		break;
	}

.
174,177c
		hnputs(ih->ilsrc, nhgets(inih->ildst));
		hnputs(ih->ildst, nhgets(inih->ilsrc));
		hnputl(ih->ilid, nhgetl(inih->ilack));
		hnputl(ih->ilack, nhgetl(inih->ilid));
.
147,155d
143c
		ilsendctl(0, ih, Ilreset);
.
141c
	s = ip_conn(ipc, nhgets(ih->ildst), nhgets(ih->ilsrc), nhgetl(ih->src), IP_ILPROTO);
.
128a
	int plen;
	Ipconv *s;
.
19a
void	ilsendctl(Ipconv *, Ilhdr *, int);
.
16a
static int initseq = 25000;
.
## diffname port/stil.c 1991/1015
## diff -e /n/bootesdump/1991/1014/sys/src/9/port/stil.c /n/bootesdump/1991/1015/sys/src/9/port/stil.c
17a
char *ilstate[] = { "Closed", "Syncer", "Syncee", "Established", "Listening", "Closing" };
.
## diffname port/stil.c 1991/1019
## diff -e /n/bootesdump/1991/1015/sys/src/9/port/stil.c /n/bootesdump/1991/1019/sys/src/9/port/stil.c
189c
	if(!ack) {
		ic->sent++;			/* Maybe needs locking */
		ilackq(&ipc->ilctl, bp);
	}
	PUTNEXT(Ipoutput, bp);
.
168c
	/* Ip fields */
	hnputl(ih->src, Myip);
	hnputl(ih->dst, ipc->dst);
	ih->proto = IP_ILPROTO;
	hnputs(ih->illen, IL_HDRSIZE);
.
164a
	bp->wptr += IL_EHSIZE+IL_HDRSIZE;

.
159a
	switch(s->ilctl.state) {
	case Ilclosed:
	case Ilclosing:
	case Illistener:
		error(Ehungup);
	}

	switch(h->type) {
	case Ilsync:
		if(s->ilctl.state == Ilsync)
			s->ilctl.state = Ilestablished;
		freeb(bp);
		break;
	case Ilack:
		ilackto(&s->ilctl, hngetl(g->ilack));
		freeb(bp);
		break;
	case Ilquerey:
		ilsendctl(s, 0, Ilack, 1);
		freeb(bp);
		break;
	case Ildataquery:
	case Ildata:
		ilackto(&s->ilctl, hngetl(h->ilack));
		bp->rptr += IL_EHSIZE+IL_HDRSIZE;
		PUTNEXT(s->readq, bp);
		break;
	case Ilreset:
		s->ilctl.state = Closed;
		freeb(bp);
	}
}

void
ilsendctl(Ipconv *ipc, Ilhdr *inih, int type, int ack)
{
.
158c
ilprocess(Ipconv *s, Ihdr *h, Block *bp)
.
151,153c
	for(s = ipc; s < etab; s++) {
		if(s->state == 	Illistening && s->sport == 0) {
			/* Do the listener stuff */
			ilprocess(s, ih, bp);
			return;
		}
	}
	ilsendctl(0, ih, Ilreset);
.
146,149c
	etab = &ipc[conf.ip];
	for(s = ipc; s < etab; s++) {
		if(s->sport == ih->ildst && s->dport == ih->ilsrc) {
			ilprocess(s, ih, bp);
			return;
		}
			
.
119c
void
ilackto(Ilctl *ic, ulong ackto)
{
	Ilhdr *h;
	Block *bp;

	for(;;) {
		lock(ic);
		if(ic->unacked) {
			h = (Ilhdr *)ic->unacked->rptr;
			if(ackto < hngetl(h->ilack)) {
				unlock(ic);
				break;	
			}
			bp = ic->unacked;
			ic->unacked = bp->next;
			unlock(ic);
			freeb(bp);
		}
		else {
			unlock(ic);
			break;
		}
	}
.
117a
	unlock(ic);
}
.
108a

	lock(ic);
.
106a
	ilackq(ic, bp);

	PUTNEXT(q, bp);
}

void
ilackq(Ilctl *ic, Block *bp)
{
	Block *np;

.
93c
	/* Ip fields */
	hnputl(ih->src, Myip);
	hnputl(ih->dst, ipc->dst);
	ih->proto = IP_ILPROTO;
	/* Il fields */
	hnputs(ih->illen, dlen+IL_HDRSIZE);
.
69a
	switch(ipc->ilctl.state) {
	case Ilclosed:
	case Ilsyncee:
	case Illistening:
	case Ilclosing:
		error(Ehungup);
	}

.
65d
34a
	}

	if(ilkproc == 0) {
		ilkproc = 1;
.
30,31c
	if(!Ipoutput) {
		Ipoutput = WR(q);
.
27a
	static int ilkproc;
.
16c

.
## diffname port/stil.c 1991/1022
## diff -e /n/bootesdump/1991/1019/sys/src/9/port/stil.c /n/bootesdump/1991/1022/sys/src/9/port/stil.c
327c
		ilsendctl(ipc, 0, Ilsync, 1);
.
250c
		s->ilctl.state = Ilclosed;
.
245c
		ilackto(&s->ilctl, nhgetl(h->ilack));
.
236c
		ilackto(&s->ilctl, nhgetl(h->ilack));
.
229c
	switch(h->iltype) {
.
225c
	case Illistening:
.
220c
ilprocess(Ipconv *s, Ilhdr *h, Block *bp)
.
215c
	ilsendctl(0, ih, Ilreset, 0);
drop:
.
209c
		if(s->ilctl.state == Illistening && s->psrc == 0) {
.
202c
		if(s->psrc == sp && s->pdst == dp) {
.
199a
	sp = nhgets(ih->ildst);
	dp = nhgets(ih->ilsrc);
.
187c
	Ipconv *s, *etab;
	short sp, dp;
.
160c
			if(ackto < nhgetl(h->ilack)) {
.
151c
ilackto(Ilcb *ic, ulong ackto)
.
130c
ilackq(Ilcb *ic, Block *bp)
.
22c
void	ilsendctl(Ipconv*, Ilhdr*, int, int);
void	ilackq(Ilcb*, Block*);
void	ilprocess(Ipconv*, Ilhdr*, Block*);
.
## diffname port/stil.c 1991/1023
## diff -e /n/bootesdump/1991/1022/sys/src/9/port/stil.c /n/bootesdump/1991/1023/sys/src/9/port/stil.c
336d
219a
reset:
.
216c
			new = ipincoming(ipc);
			if(new == 0) 
				goto reset;
			if(ih->type != Ilsync)
				goto reset;

			new->newcon = 1;
			new->ipinterface = s->ipinterface;
			s->ipinterface->ref++;
			new->psrc = sp;
			new->pdst = dp;
			new->dst = nhgetl(ih->src);
			ilprocess(new, ih, bp);

			wakeup(&s->listenr);
.
212a

.
189c
	Ipconv *s, *etab, *new;
.
17,19d
15c
int 	ilcksum = 1;
static 	int initseq = 25000;
char	*ilstate[] = { "Closed", "Syncer", "Syncee", "Established", "Listening", "Closing" };
.
## diffname port/stil.c 1991/1024
## diff -e /n/bootesdump/1991/1023/sys/src/9/port/stil.c /n/bootesdump/1991/1024/sys/src/9/port/stil.c
314c
	if(!ack && ipc) {
.
300a
		hnputl(ih->dst, ipc->dst);
.
294a
		hnputl(ih->dst, nhgetl(inih->src));
.
292a
	hnputl(ih->src, Myip);
.
290,291d
271a
		nb = allocb(0);
		nb->type = M_HANGUP;
		PUTNEXT(s->readq, nb);
.
267a
/* Check and trim to length */
.
242a
	Block *nb;

.
224a
			s->curlog++;
.
214c
		if(s->ilctl.state == Illistening && s->pdst == 0) {
.
212a
	if(s->curlog > s->backlog) {
print("Backlog\n");
		goto reset;
	}

.
206c
		if(s->psrc == sp && s->pdst == dp && s->dst == dst) {
.
203a
	dst = nhgetl(ih->src);

print("got packet from %d.%d.%d.%d %d %d\n", fmtaddr(dst), sp, dp);

.
191c
	ih = (Ilhdr *)bp->rptr;
.
189a
	Ipaddr dst;
.
## diffname port/stil.c 1991/1025
## diff -e /n/bootesdump/1991/1024/sys/src/9/port/stil.c /n/bootesdump/1991/1025/sys/src/9/port/stil.c
290a
}

void
iloutoforder(Ipconv *s, Ilhdr *h, Block *bp)
{
	Block *f, **l;
	Ilcb *ic;
	ulong id;
	uchar *lid;

	ic = &s->ilctl;

	if(ic->outoforder == 0) {
		ic->outoforder = bp;
		bp->next = 0;
		return;
	}

	id = nhgetl(h->id);
	l = &ic->outoforder;
	for(f = *l; f; f = f->next) {
		lid = ((Ilhdr*)(bp->rptr))->ilid;
		if(id < nhgetl(lid))
			break;
		l = &f->next;
	}
	bp->next = *l;
	*l = bp;
.
286,288c
	hungup:
		if(s->readq) {
			nb = allocb(0);
			nb->type = M_HANGUP;
			PUTNEXT(s->readq, nb);
		}
.
280,282c
		switch(s->ilctl.state) {
		default:
			iloutoforder(s, h, bp);
			break;
		case Ilestablished:
			id = nhgetl(h->ilid);
			if(id < s->ilctl.recvd)
				freeb(bp);
			else if(id > s->ilctl.recvd)
				iloutoforder(s, h, bp);
			else {
				bp->rptr += IL_EHSIZE+IL_HDRSIZE;
				PUTNEXT(s->readq, bp);
			}
		}
.
270c
		ack = nhgetl(h->ilack);
		if(s->ilctl.recvd+1 == ack)
			s->ilctl.recvd = ack;
		ilackto(&s->ilctl, ack);
.
264,268d
262a
	/* Passive actions based on packet type */
.
259,260c
		goto hungup;
.
256a
	case Ilsyncee:	
		switch(h->iltype) {
		case Ilsync:
			ilsendctl(s, 0, Ilsync, 0);
			break;
		case Ilack:
			s->ilctl.state = Ilestablished;
			break;
		}
		break;
.
255a
	/* Active transition machine - this tracks connection state */
.
254a
	ulong id, ack;
.
240a
			s->ipinterface->ref++;
			s->curlog++;
.
237a
			new->ilctl.state = Ilsyncee;
.
234,235d
229c
			if(ih->iltype != Ilsync)
.
227c
			if(new == 0)
.
224c
		if(s->ilctl.state == Illistening && s->pdst == 0 && s->dst == 0) {
.
221d
218,219c
	if(s->curlog > s->backlog)
.
157,173c
	while(ic->unacked) {
		h = (Ilhdr *)ic->unacked->rptr;
		if(ackto < nhgetl(h->ilack))
			break;	
		bp = ic->unacked;
		ic->unacked = bp->next;
		freeb(bp);
.
148d
138d
## diffname port/stil.c 1991/1026
## diff -e /n/bootesdump/1991/1025/sys/src/9/port/stil.c /n/bootesdump/1991/1026/sys/src/9/port/stil.c
396c
	ic->start = ic->sent;
	ic->recvd = 0;
.
362a
		print("sendctl: id %d ack %d\n", ic->sent, ic->recvd);
.
341a
	bp->flags |= S_DELIM;
.
304a

.
302a

	/* Process out of order packets */
	if(ic->state == Ilestablished) {
		while(ic->outoforder) {
			bp = ic->outoforder;
			oh = (Ilhdr*)bp->rptr;
			oid = nhgetl(oh->ilid);
print("recvd = %d outoforder = %d\n", ic->recvd, oid);
			if(oid < ic->recvd) {
				ic->outoforder = bp->next;
				freeb(bp);
			}
			if(oid == ic->recvd) {
print("outoforder %d\n", oid);
				ic->recvd++;
				ic->outoforder = bp->next;
				bp->rptr += IL_EHSIZE+IL_HDRSIZE;
				PUTNEXT(s->readq, bp);
			}
		}
	}
.
298a
			nb->flags |= S_DELIM;
.
287a
				s->ilctl.recvd++;
.
282d
276c
		ilackto(&s->ilctl, ack);
.
264,266d
262a
	default:
		freeb(bp);
		break;
.
255a
	case Ilsyncer:
		if(h->iltype == Ilsync && ic->start == ack) {
			ic->recvd = id;
			ilsendctl(s, 0, Ilack, 0);
			ic->state = Ilestablished;
		}
		break;
.
252c
			ic->state = Ilestablished;
.
248a
			ic->recvd = id;
.
245c
	switch(ic->state) {
.
243a
	id = nhgetl(h->ilid);
	ack = nhgetl(h->ilack);
	ic = &s->ilctl;

.
242c
	Ilcb *ic;
	Ilhdr *oh;
	ulong id, ack, oid;
.
222a
			initseq += TK2MS(MACHP(0)->ticks);
			new->ilctl.sent = initseq;
.
## diffname port/stil.c 1991/1028
## diff -e /n/bootesdump/1991/1026/sys/src/9/port/stil.c /n/bootesdump/1991/1028/sys/src/9/port/stil.c
327a
			if(oid > ic->recvd)
				break;
.
## diffname port/stil.c 1991/1030
## diff -e /n/bootesdump/1991/1028/sys/src/9/port/stil.c /n/bootesdump/1991/1030/sys/src/9/port/stil.c
370,371d
361,368c
	else {
		id = nhgetl(h->id);
		l = &ic->outoforder;
		for(f = *l; f; f = f->next) {
			lid = ((Ilhdr*)(bp->rptr))->ilid;
			if(id > nhgetl(lid))
				break;
			l = &f->next;
		}
		bp->next = *l;
		*l = bp;
.
359d
355d
342a

	if(sendack)
		ilsendctl(s, 0, Ilack, 1);

	print("revd = %d sent = %d\n", ic->recvd, ic->sent);
.
338c
				bp->next = 0;
				dlen = nhgets(oh->illen)-IL_HDRSIZE;
				bp = btrim(bp, IL_EHSIZE+IL_HDRSIZE, dlen);
.
322c
	if(ic->state == Ilestablished && s->readq) {
.
304c
				dlen = nhgets(h->illen)-IL_HDRSIZE;
				bp = btrim(bp, IL_EHSIZE+IL_HDRSIZE, dlen);
.
290a
		sendack = 1;
.
267,268c
			ic->recvd = id+1;
			sendack = 1;
.
246c
	ulong id, ack, oid, dlen;
	int sendack = 0;
.
215,216d
211d
208a
	/* Look for a listener */
.
205a
	if(ih->iltype != Ilsync)
		goto drop;

.
203d
195,196d
186c
	illen = nhgets(ih->illen);
	if(illen+IL_EHSIZE > plen)
		goto drop;

	if(ilcksum && ptcl_csum(bp, IL_EHSIZE, illen) != 0) {
.
175c
	int plen, illen;
.
160a
		bp->next = 0;
.
144,145c
	ic->unackedtail = np;
.
140,142c
	else 
.
138c
	if(ic->unacked)
.
126d
77d
59a
	Ipconv *s;

	s = (Ipconv *)(q->ptr);
	qlock(s);
	s->ref--;
	qunlock(s);
	s->readq = 0;
.
34d
31d
## diffname port/stil.c 1991/10302
## diff -e /n/bootesdump/1991/1030/sys/src/9/port/stil.c /n/bootesdump/1991/10302/sys/src/9/port/stil.c
436a
	Rendez wait;
	Ipconv *base, *end, *s;

	base = (Ipconv*)a;
	end = &base[conf.ip];

	for(;;) {
		tsleep(&wait, return0, 0, 250);
		for(s = base; s < end; s++) {
			if(s->ilctl.state == Ilclosed)
				continue;
		}
	}
.
435c
ilackproc(void *a)
.
381c
		bp->list = *l;
.
379c
			l = &f->list;
.
375c
		for(f = *l; f; f = f->list) {
.
370c
		bp->list = 0;
.
343,344c
				ic->outoforder = bp->list;
				bp->list = 0;
.
337c
				ic->outoforder = bp->list;
.
316c
		ic->state = Ilclosed;
.
305c
			else if(s->readq == 0 || id > ic->recvd)
.
297,298c
		ilackto(ic, ack);
		switch(ic->state) {
.
287c
		ilackto(ic, ack);
.
163a
	if(ic->unacked == 0) print("ack empty: %d\n", ackto);
.
160,161c
		ic->unacked = bp->list;
		bp->list = 0;
.
146c
	np->list = 0;
.
142c
		ic->unackedtail->list = np;
.
93c
	for(f = bp; f && (f->flags&S_DELIM) == 0; f = f->next)
		;
	if(f ==0 || (f->flags & S_DELIM) == 0) {
.
74c
	Block *np, *f;
.
39c
		kproc("ilack", ilackproc, ipconv[s->dev]);
.
## diffname port/stil.c 1991/1101
## diff -e /n/bootesdump/1991/10302/sys/src/9/port/stil.c /n/bootesdump/1991/1101/sys/src/9/port/stil.c
449,450c
/* Decide if we have to do the action !! */
			switch(s->ilctl.state) {
			case Ilclosed:
			case Illistening:
				break;
			case Ilclosing:
				bp = s->ilctl.unacked;
				if(bp) {
					np = copyb(bp, blen(bp));
					PUTNEXT(Ipoutput, np);
				}
				break;
			case Ilsyncer:
			case Ilsyncee:
			case Ilestablished:
				break;
			}
.
447c
		tsleep(&ilackr, return0, 0, 100);
.
441a
	Block *bp, *np;
.
440d
430c
	if(ack == 0 && ipc) {
.
420d
354,358d
344d
336d
330c
	/* Since recvd may have changed we can process out of order packets */
.
318c
	case Ilclose:
.
312,313c
				bp->rptr += IL_EHSIZE+IL_HDRSIZE;
.
310c
			else if(s->readq) {
.
308c
			else if(id > s->ilctl.recvd)
.
300,301c
		ilackto(&s->ilctl, ack);
		switch(s->ilctl.state) {
.
298c
		ilsendctl(s, 0, Ilack, 1);
		/* NO break */
.
275c
			ilsendctl(s, 0, Ilack, 1);
.
253d
241c
	ilsendctl(0, ih, Ilclose, 0);
.
219c
		if(s->ilctl.state == Illistening)
		if(s->pdst == 0)
		if(s->dst == 0) {
.
209d
204,205c
	for(s = ipc; s < etab; s++)
		if(s->psrc == sp)
		if(s->pdst == dp)
		if(s->dst == dst) {
.
166d
123a
	ih->iltype = Ildata;
	ih->ilspec = 0;
.
120,121d
95c
	if((f->flags & S_DELIM) == 0) {
.
93c
	for(f = bp; f->next; f = f->next)
.
64a
	qunlock(s);

	switch(ic->state) {
	case Ilclosed:
		break;
	case Ilsyncer:
	case Ilsyncee:
	case Ilestablished:
		for(bp = ic->outoforder; bp; bp = next) {
			next = bp->list;
			freeb(bp);
		}
		ic->outoforder = 0;
		ic->state = Ilclosing;
		ilsendctl(s, 0, Ilclose, 0);
		break;
	Illistening:
		ic->state = Ilclosed;
		break;
	Ilclosing:
		/* ?? */
		break;
	}
.
63d
60a
	ic = &s->ilctl;
.
58a
	Ilcb *ic;
	Block *bp, *next;
.
15,16c
int 		ilcksum = 1;
static 	int 	initseq = 25000;
static	Rendez	ilackr;
.
## diffname port/stil.c 1991/1102
## diff -e /n/bootesdump/1991/1101/sys/src/9/port/stil.c /n/bootesdump/1991/1102/sys/src/9/port/stil.c
474,479d
472d
346c
		ic->state = Ilclosing;
.
326c
		/* No break */
.
307a
		ilsendctl(s, 0, Ilclose, 0);
		ic->state = Ilclosed;
		/* No break */
	case Ilclosed:
.
306d
279a
	int sendack = 0;
.
270d
267a
drop:
	freeb(bp);
	return;
.
87,89d
70a
	case Ilclosing:
.
## diffname port/stil.c 1991/1104
## diff -e /n/bootesdump/1991/1102/sys/src/9/port/stil.c /n/bootesdump/1991/1104/sys/src/9/port/stil.c
280d
## diffname port/stil.c 1991/1105
## diff -e /n/bootesdump/1991/1104/sys/src/9/port/stil.c /n/bootesdump/1991/1105/sys/src/9/port/stil.c
492a
	ic->timeout = 0;
.
478a
				if(++ic->timeout == Fasttime) {
					if(ic->lastack < ic->recvd)
						ilsendctl(s, 0, Ilstate, 1);
					ic->timeout = 0;
				}
.
477a
			case Ilsyncer:
				ilsendctl(s, 0, Ilsync, 1);
				if(++ic->timeout == Slowtime) {
					ilhangup(s);
					ic->state = Ilclosed;
					s->dst = 0;
					s->pdst = 0;
					ic->timeout = 0;
				}
				break;
.
476c
				break;
.
474a
				break;
.
471,472c
			ic = &s->ilctl;
			switch(ic->state) {
.
462a
	Ilcb *ic;
.
409a
	bp->list = *l;
	*l = bp;
.
398,408c

	id = nhgetl(h->id);
	l = &ic->outoforder;
	for(f = *l; f; f = f->list) {
		lid = ((Ilhdr*)(bp->rptr))->ilid;
		if(id > nhgetl(lid))
			break;
		l = &f->list;
.
396c
		return;
.
393a
	bp->list = 0;
.
384a
	if(s->readq == 0)
		return;

	ic = &s->ilctl;
	if(ic->state != Ilestablished)
		return;

	while(ic->outoforder) {
		bp = ic->outoforder;
		oh = (Ilhdr*)bp->rptr;
		oid = nhgetl(oh->ilid);
		if(oid > ic->recvd)
			break;
		if(oid < ic->recvd) {
			ic->outoforder = bp->list;
			freeb(bp);
		}
		if(oid == ic->recvd) {
			ic->recvd++;
			ic->outoforder = bp->list;
			bp->list = 0;
			dlen = nhgets(oh->illen)-IL_HDRSIZE;
			bp = btrim(bp, IL_EHSIZE+IL_HDRSIZE, dlen);
			PUTNEXT(s->readq, bp);
		}
	}
}

.
383a
void
ilpullup(Ipconv *s)
{
	Ilcb *ic;
	Ilhdr *oh;
	ulong oid, dlen;
	Block *bp;
.
360,380c
void
ilhangup(Ipconv *s)
{
	Block *nb;

	if(s->readq) {
		nb = allocb(0);
		nb->type = M_HANGUP;
		nb->flags |= S_DELIM;
		PUTNEXT(s->readq, nb);
.
358a
}
.
357a
		break;
.
350,356c
		ilhangup(s);
		/* No break */
	default:
.
344a
				ilpullup(s);
.
316c
	case Ilstate:
		if(ic->unacked) {
			nb = copyb(ic->unacked, blen(ic->unacked));
			PUTNEXT(Ipoutput, nb);	
		}
		else
			ilsendctl(s, 0, Ilack, 1);
.
311c
		ilhangup(s);
		freeb(bp);
		return;
.
303a
			ilpullup(s);
.
285a
	ic->timeout = 0;
.
279,280c
	ulong id, ack, dlen;
.
184c
			break;
.
24a
void	ilpullup(Ipconv*);
void	ilhangup(Ipconv*);
.
19a
enum
{
	Slowtime = 20,
	Fasttime = 1,
};

.
## diffname port/stil.c 1991/1106
## diff -e /n/bootesdump/1991/1105/sys/src/9/port/stil.c /n/bootesdump/1991/1106/sys/src/9/port/stil.c
566c
		ilsendctl(ipc, 0, Ilsync);
.
531,535d
521,528d
519a
				break;
.
510c
		tsleep(&ilackr, return0, 0, 250);
.
492,495d
481c
		id = ic->sent;
		if(type == Ilsync)
			id = ic->start;
		hnputl(ih->ilid, id);
.
457a
	ulong id;
.
453c
ilsendctl(Ipconv *ipc, Ilhdr *inih, int type)
.
376a
ilprocess(Ipconv *s, Ilhdr *h, Block *bp)
{
	Ilcb *ic = &s->ilctl;

	print("%s start %d rstart %d recvd %d sent %d\n",
		ilstate[ic->state], ic->start, ic->rstart, ic->recvd, ic->sent);
	print("pkt(%s id %d ack %d)\n", iltype[h->iltype], nhgetl(h->ilid), nhgetl(h->ilack));

	_ilprocess(s, h, bp);

	print("%s start %d rstart %d recvd %d sent %d\n",
		ilstate[ic->state], ic->start, ic->rstart, ic->recvd, ic->sent);
}

void
.
375a
/* DEBUG */
.
365,370d
353,363d
351c
			ic->state = Ilclosed;
			ilsendctl(s, 0, Ilclose);
			ilhangup(s);
.
336,349c
	case Ilclosing:
		switch(h->iltype) {
		case Ilclose:
			if(ack == ic->sent) {
				ic->state = Ilclosed;
				ilhangup(s);
			}
			ic->recvd = id;
			ilsendctl(s, 0, Ilclose);
			break;
.
322,334d
315,320c
	case Illistening:
.
312a
			if(h->iltype == Ildataquery)
				ilsendctl(s, 0, Ilstate);
			break;
		case Ilack:
			ilackto(ic, ack);
			freeb(bp);
			break;
		case Ilquerey:
			ilackto(ic, ack);
			ilsendctl(s, 0, Ilstate);
			freeb(bp);
			break;
		case Ilstate:
			ilackto(ic, ack);
			if(ic->unacked) {
				nb = copyb(ic->unacked, blen(ic->unacked));
				h = (Ilhdr*)nb;
				h->iltype = Ildataquery;
				hnputl(h->ilack, ic->recvd);
				PUTNEXT(Ipoutput, nb);
			}
			freeb(bp);
			break;
		case Ilclose:
			freeb(bp);
			if(ic->start >= ack || ack < ic->sent)
				break;
			ic->sent++;
			ic->recvd = ack;
			ilsendctl(s, 0, Ilclose);
			ic->state = Ilclosing;
			for(nb = ic->unacked; nb; nb = next) {
				next = nb->list;
				freeb(nb);
			}
			for(nb = ic->outoforder; nb; nb = next) {
				next = nb->list;
				freeb(nb);
			}
			ic->unacked = 0;
			ic->outoforder = 0;
			break;
.
307,311c
	case Ilestablished:
		switch(h->iltype) {
		case Ilsync:
			if(id != ic->start) {
				ic->state = Ilclosed;
				ilhangup(s);
			}
			else 
				ilsendctl(s, 0, Ilack);
			freeb(bp);	
			break;
		case Ildata:
		case Ildataquery:
			if(id < ic->recvd) {
				freeb(bp);
				break;
			}
			if(ack >= ic->recvd)
				ilackto(ic, ack);
			iloutoforder(s, h, bp);
.
305a
		freeb(bp);
.
304a
		case Ilclose:
			if(ack == ic->start) {
				ic->state = Ilclosed;
				ilhangup(s);
			}
			break;
.
303c
			if(ack == ic->start) {
				ic->state = Ilestablished;
				ilpullup(s);
			}
.
301a
		case Ilclose:
			if(ack == ic->start) {
				ic->state = Ilclosed;
				ilhangup(s);
			}
			break;
		}
		freeb(bp);
		break;
	case Ilsyncee:
		switch(h->iltype) {
		default:
			break;
		case Ilsync:
			if(id != ic->rstart || ack != 0)
				ic->state = Ilclosed;
			else {
				ic->recvd = id;
				ilsendctl(s, 0, Ilsync);
			}
			break;
.
299,300c
			if(ack != ic->start) {
				ilhangup(s);
				ic->state = Ilclosed;
			}
			else {
				ic->recvd = id;
				ic->rstart = id;
				ilsendctl(s, 0, Ilack);
				ic->state = Ilestablished;
				ilpullup(s);
			}
.
297a
		default:
			break;
.
296c
	default:
		panic("il unknown state");
	case Ilclosed:
		freeb(bp);
		break;
	case Ilsyncer:
.
293,294d
286a
	Block *nb, *next;
.
285d
283c
_ilprocess(Ipconv *s, Ilhdr *h, Block *bp)
.
278c
	print("reset\n");
	ilsendctl(0, ih, Ilclose);
.
274a
	print("drop\n");
.
265a

			ic = &new->ilctl;
			ic->state = Ilsyncee;
			initseq += TK2MS(MACHP(0)->ticks);
			ic->sent = initseq;
			ic->start = ic->sent;
			ic->recvd = 0;
			ic->rstart = nhgetl(ih->ilid);
.
262,264d
209a
	Ilcb *ic;
.
192a
		ic->lastack = ackto;
.
191c
		ack = nhgetl(h->ilack);
		if(ackto < ack)
.
187a
	ulong ack;
.
174d
163a
	delay(100);
.
91c
		ic->sent++;
		ilsendctl(s, 0, Ilclose);
.
88a
		ic->unacked = 0;
.
84a
		for(bp = ic->unacked; bp; bp = next) {
			next = bp->list;
			freeb(bp);
		}
.
28c
void	ilsendctl(Ipconv*, Ilhdr*, int);
.
18a
char	*iltype[] =  { "sync", "data", "dataquerey", "ack", "querey", "state", "close" };
.
17a
Rendez poor;	/* DEBUG */
.
14d
## diffname port/stil.c 1991/1107
## diff -e /n/bootesdump/1991/1106/sys/src/9/port/stil.c /n/bootesdump/1991/1107/sys/src/9/port/stil.c
655a
}

void
ilfreeq(Ilcb *ic)
{
	Block *bp, *next;

	for(bp = ic->unacked; bp; bp = next) {
		next = bp->list;
		freeb(bp);
	}
	for(bp = ic->outoforder; bp; bp = next) {
		next = bp->list;
		freeb(bp);
	}
	ic->unacked = 0;
	ic->outoforder = 0;
.
644c
	ic->lastack = ic->next;
.
641,642c
	ic->next = initseq;
	ic->start = ic->next;
.
594a
	print("ctl(%s id %d ack %d %d->%d) ",
		iltype[ih->iltype], nhgetl(ih->ilid), nhgetl(ih->ilack), 
		nhgets(ih->ilsrc), nhgets(ih->ildst));

.
581c
		id = ic->next;
.
471,472c
	print("%s rcv %d snt %d\n", ilstate[ic->state], ic->recvd, ic->next);
.
465,467c
	print("%s rcv %d/%d snt %d/%d pkt(%s id %d ack %d %d->%d) ",
		ilstate[ic->state],  ic->rstart, ic->recvd, ic->start, ic->next,
		iltype[h->iltype], nhgetl(h->ilid), nhgetl(h->ilack), 
		nhgets(h->ilsrc), nhgets(h->ildst));
.
449d
445,446c
			else {
				ic->recvd = id;
				ilsendctl(s, 0, Ilclose);
			}
.
441c
			if(ack == ic->next) {
.
422,431c
			ilfreeq(ic);
.
418,419d
416c
			if(id != ic->recvd)
.
278,279c
			ic->next = initseq;
			ic->start = ic->next;
.
159c
	hnputl(ih->ilid, ic->next++);
.
97d
86,95c
		ilfreeq(ic);
.
33a
void	ilfreeq(Ilcb*);
.
## diffname port/stil.c 1991/1108
## diff -e /n/bootesdump/1991/1107/sys/src/9/port/stil.c /n/bootesdump/1991/1108/sys/src/9/port/stil.c
576c
	DBG("\nctl(%s id %d ack %d %d->%d)\n",
.
453c
	DBG("%s rcv %d snt %d\n", ilstate[ic->state], ic->recvd, ic->next);
.
446c
	USED(ic);
	DBG("%s rcv %d/%d snt %d/%d pkt(%s id %d ack %d %d->%d) ",
.
431,432d
425,428c
			ilsendctl(s, 0, Ilclose);
.
420a
			ic->recvd = id;
.
407c
			if(id != ic->recvd) 
.
400a
				h->ilsum[0] = 0;
				h->ilsum[1] = 0;
				if(ilcksum)
					hnputs(h->ilsum, ptcl_csum(nb, IL_EHSIZE, IL_HDRSIZE));
.
235a
	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",
			st, nhgetl(ih->ilid), nhgetl(ih->ilack), fmtaddr(dst), sp, dp);
		goto drop;
	}

.
227,231d
215a
	char *st;
.
140d
138d
110c
	ic = &ipc->ilctl;
	switch(ic->state) {
.
13a
#define	 DBG	if(0)print
.
## diffname port/stil.c 1991/1115
## diff -e /n/bootesdump/1991/1108/sys/src/9/port/stil.c /n/bootesdump/1991/1115/sys/src/9/port/stil.c
259c
			new = ipincoming(ipc, s);
.
95a
	netdisown(&s->ipinterface->net, s->index);
.
1c

/*
.
## diffname port/stil.c 1991/1119
## diff -e /n/bootesdump/1991/1115/sys/src/9/port/stil.c /n/bootesdump/1991/1119/sys/src/9/port/stil.c
18c

.
1c
/*
.
## diffname port/stil.c 1991/1120
## diff -e /n/bootesdump/1991/1119/sys/src/9/port/stil.c /n/bootesdump/1991/1120/sys/src/9/port/stil.c
630a
*/
initseq = 1;
.
629a
/*
.
273c
*/
initseq	=1;		ic->next = initseq;
.
271a
/*
.
233a
print("len = %d BLEN = %d IL %d\n", blen(bp), BLEN(bp), illen);
.
163a
	print("TX len = %d BLEN = %d IL %d\n", blen(bp), BLEN(bp), dlen+IL_HDRSIZE);
.
77d
58,60d
14c
#define	 DBG	if(1)print
.
## diffname port/stil.c 1991/1121
## diff -e /n/bootesdump/1991/1120/sys/src/9/port/stil.c /n/bootesdump/1991/1121/sys/src/9/port/stil.c
584c
*/
.
581c
/*	DBG("\nctl(%s id %d ack %d %d->%d)\n",
.
458c
	DBG("%11s rcv %d snt %d\n", ilstate[ic->state], ic->recvd, ic->next);
.
451c
	DBG("%11s rcv %d/%d snt %d/%d pkt(%s id %d ack %d %d->%d) ",
.
408c
					hnputs(h->ilsum, ptcl_csum(nb, IL_EHSIZE, nhgets(h->illen)));
.
319a
				ilhangup(s);
.
318d
240,242c
		if(s->psrc == sp && s->pdst == dp && s->dst == dst) {
.
231d
217d
160d
157d
## diffname port/stil.c 1991/1122
## diff -e /n/bootesdump/1991/1121/sys/src/9/port/stil.c /n/bootesdump/1991/1122/sys/src/9/port/stil.c
606a
				ic->timeout++;
				if(ic->unacked == 0)
					break;
				if(ic->timeout >= Slowtime) {
					ic->state = Ilclosed;
					ilhangup(s, Ctimedout);
					break;
				}
print("Rxmit %d/%d %s", s->psrc, s->pdst, ilstate[ic->state]);
				ilsendctl(s, 0, Ilstate);
.
604a
				ic->timeout++;
				if(ic->timeout >= Slowtime) {
					ic->state = Ilclosed;
					ilhangup(s, Ctimedout);
					break;
				}
print("Rxmit %d/%d %s", s->psrc, s->pdst, ilstate[ic->state]);
				ilsendctl(s, 0, Ilsync);
.
602a
				ic->timeout++;
				if(ic->timeout >= Slowtime) {
					ic->state = Ilclosed;
					ilhangup(s, Ctimedout);
					break;
				}
print("Rxmit %d/%d %s", s->psrc, s->pdst, ilstate[ic->state]);
				ilsendctl(s, 0, Ilsync);
.
600a
				ic->timeout++;
				if(ic->timeout >= Slowtime) {
					ic->state = Ilclosed;
					ilhangup(s, 0);
				}
.
597,598c
			default:
.
593c
		tsleep(&ilackr, return0, 0, Mstime);
.
591d
461c
		if(msg) {
			l = strlen(msg);
			nb = allocb(l);
			strcpy((char*)nb->wptr, msg);
			nb->wptr += l;
		}
		else
			nb = allocb(0);
.
458a
	ulong l;
.
456c
ilhangup(Ipconv *s, char *msg)
.
452c
	DBG("%-11s rcv %d snt %d\n", ilstate[ic->state], ic->recvd, ic->next);
.
445c
	DBG("%-11s rcv %d/%d snt %d/%d pkt(%-6s id %d ack %d %d->%d) ",
.
426c
				ilhangup(s, 0);
.
364c
				ilhangup(s, Creset);
.
353c
				ilhangup(s, Crefused);
.
326c
				ilhangup(s, Crefused);
.
313c
				ilhangup(s, Crefused);
.
299a
	ic->timeout = 0;
.
254a
			}
.
253c
			if(new == 0) {
				print("incoming\n");
.
251a
			if(s->curlog > s->backlog)
				goto reset;
.
244,246d
236c
		if(s->ilctl.state != Ilclosed)
		if(s->psrc == sp)
		if(s->pdst == dp)
		if(s->dst == dst) {
.
158d
156a

.
89a
		s->psrc = 0;
.
88c
	case Illistening:
.
36a
char Crefused[] = "connection refused";
char Ctimedout[] = "connection timed out";
char Creset[] = "connection reset by peer";

.
34c
void	ilhangup(Ipconv*, char*);
.
24,25c
	Mstime	  = 200,
	Slowtime  = Mstime*20,
	Fasttime  = Mstime,
.
14c
#define	 DBG	if(0)print
.
## diffname port/stil.c 1991/1124
## diff -e /n/bootesdump/1991/1122/sys/src/9/port/stil.c /n/bootesdump/1991/1124/sys/src/9/port/stil.c
707a
	qunlock(&ic->outo);
.
706d
701a
	ic->unacked = 0;
	qunlock(&ic->ackq);

	qlock(&ic->outo);
.
697a
	qlock(&ic->ackq);
.
688c
		ilsendctl(ipc, 0, Ilsync, ic->start, ic->recvd);
.
679d
674,677c
	ic->start = initseq;
	ic->next = ic->start+1;
.
672c
	ic->slowtime = Slowtime;


.
653,654d
650c
					ilhangup(s, etime);
.
648c
				}
				if(ic->timeout >= ic->fasttime) {
					ilrexmit(ic);
					Backoff(ic->fasttime);
				}
				if(ic->timeout >= ic->slowtime) {
.
645,646c
				ic->acktime -= Iltickms;
				if(ic->acktime <= 0)
					ilsendctl(s, 0, Ilack, ic->next, ic->recvd);
				if(ic->unacked == 0) {
					ic->timeout = 0;
.
641,642d
638,639c
					ilhangup(s, etime);
.
635,636c
				if(ic->timeout >= ic->fasttime) {
					ilsendctl(s, 0, Ilsync, ic->start, ic->recvd);
					Backoff(ic->fasttime);
				}
				if(ic->timeout >= ic->slowtime) {
.
625,633d
618,619c
				if(ic->timeout >= ic->fasttime) {
					ilsendctl(s, 0, Ilclose, ic->next, ic->recvd);
					Backoff(ic->fasttime);
				}
				if(ic->timeout >= ic->slowtime) {
.
615c
			case Ilclosed:
			case Illistening:
.
613a
			ic->timeout += Iltickms;
.
611c
		tsleep(&ilackr, return0, 0, Iltickms);
.
609a

.
584c
		hnputl(ih->ilack, ack);
		ic->acktime = Ackkeepalive;
.
580,582d
556d
551c
ilsendctl(Ipconv *ipc, Ilhdr *inih, int type, ulong id, ulong ack)
.
546,547c
	qunlock(&ic->outo);
.
538,544c
	/* Packet is acceptable so sort onto receive queue for pullup */
	qlock(&ic->outo);
	ic->oblks++;
	if(ic->outoforder == 0)
		ic->outoforder = bp;
	else {
		l = &ic->outoforder;
		for(f = *l; f; f = f->list) {
			lid = ((Ilhdr*)(f->rptr))->ilid;
			if(id < nhgetl(lid)) {
				bp->list = f;
				*l = bp;
				qunlock(&ic->outo);
				return;
			}
			l = &f->list;
		}
		*l = bp;
.
533,534c


	id = nhgetl(h->ilid);
	/* Window checks */
	if(id <= ic->recvd || ic->oblks > ic->window) {
		freeb(bp);
.
520a
	qunlock(&ic->outo);
.
512,519c
		if(oid != ic->recvd+1)
			break;

		ic->recvd = oid;
		ic->outoforder = bp->list;
		ic->oblks--;

		qunlock(&ic->outo);
		bp->list = 0;
		dlen = nhgets(oh->illen)-IL_HDRSIZE;
		bp = btrim(bp, IL_EHSIZE+IL_HDRSIZE, dlen);
		PUTNEXT(s->readq, bp);
		qlock(&ic->outo);
.
510a
			continue;
.
506,508c
		if(oid <= ic->recvd) {
.
501a
	qlock(&ic->outo);
.
484a
	s->psrc = 0;
	s->pdst = 0;
	s->dst = 0;
.
471a
	DBG("hangup! %s %d/%d\n", msg ? msg : "??", s->psrc, s->pdst);
.
470c
	int l;
.
463c
	DBG("%11s rcv %d snt %d\n", ilstate[ic->state], ic->recvd, ic->next);
.
456c
	DBG("%11s rcv %d/%d snt %d/%d pkt(%s id %d ack %d %d->%d) ",
.
448a
void
ilrexmit(Ilcb *ic)
{
	Block *nb;
	Ilhdr *h;

	if(ic->unacked == 0)
		return;

	nb = copyb(ic->unacked, blen(ic->unacked));
	h = (Ilhdr*)nb->rptr;
	DBG("rxmit %d.", nhgetl(h->ilid));

	h->iltype = Ildataquery;
	hnputl(h->ilack, ic->recvd);
	h->ilsum[0] = 0;
	h->ilsum[1] = 0;
	if(ilcksum)
		hnputs(h->ilsum, ptcl_csum(nb, IL_EHSIZE, nhgets(h->illen)));

	PUTNEXT(Ipoutput, nb);
}

.
439c
			Starttimer(ic);
.
434a
			ilsendctl(s, 0, Ilclose, ic->next, ic->recvd);
.
424a
			Starttimer(ic);
.
422c
			ilsendctl(s, 0, Ilclose, ic->next, ic->recvd);
.
420c
			if(ack < ic->start || ack > ic->next) 
.
405,415c
			ilrexmit(ic);
			Starttimer(ic);
.
400c
			ilsendctl(s, 0, Ilstate, ic->next, ic->recvd);
			Starttimer(ic);
.
395a
			Starttimer(ic);
.
391,392c
			ilsendctl(s, 0, Ilstate, ic->next, ic->recvd);
.
383,388c
			Starttimer(ic);
			ilackto(ic, ack);
			ic->acktime = Acktime;
.
381a
			Starttimer(ic);
			ilackto(ic, ack);
			ic->acktime = Acktime;
			iloutoforder(s, h, bp);
			ilpullup(s);
			break;
.
377,378c
			else {
				ilsendctl(s, 0, Ilack, ic->next, ic->rstart);
				Starttimer(ic);
			}
.
375c
				ilhangup(s, "remote close");
.
364c
				ilhangup(s, "remote close");
.
362c
			if(id == ic->next) {
.
358a
				Starttimer(ic);
.
352c
				ilsendctl(s, 0, Ilsync, ic->start, ic->recvd);
				Starttimer(ic);
.
337c
				ilhangup(s, "remote close");
.
331a
				Starttimer(ic);
.
329c
				ilsendctl(s, 0, Ilack, ic->next, ic->recvd);
.
324c
				ilhangup(s, "connection rejected");
.
310d
294,295c
	ilsendctl(0, ih, Ilclose, 0, 0);
.
290d
280a
			ic->slowtime = Slowtime;
			ic->window = Defaultwin;
.
276,278c
			ic->start = initseq;
			ic->next = ic->start+1;
.
274d
264d
261,262c
			if(new == 0)
.
259a

.
242d
200a
	qunlock(&ic->ackq);
.
195c

.
192,193c
		id = nhgetl(h->ilid);
		if(ackto < id)
.
189a
	qlock(&ic->ackq);
.
188c
	ulong id;
.
179a
	qunlock(&ic->ackq);
.
174a
	qlock(&ic->ackq);
.
164a
	ic->acktime = Ackkeepalive;

.
163d
95a
		s->pdst = 0;
		s->dst = 0;
.
91c
		ilsendctl(s, 0, Ilclose, ic->next, ic->recvd);
.
38,41d
36a
void	ilrexmit(Ilcb*);
.
35c
void	ilhangup(Ipconv*, char *);
.
31c
void	ilsendctl(Ipconv*, Ilhdr*, int, ulong, ulong);
.
28a
#define Backoff(s)	(s)*=2
#define Starttimer(s)	{(s)->timeout = 0; (s)->fasttime = Fasttime;}

.
24,26c
	Iltickms 	= 100,
	Slowtime 	= 20*Iltickms,
	Fasttime 	= 5*Iltickms,
	Acktime		= 3*Iltickms,
	Ackkeepalive	= 1000*Iltickms,
	Defaultwin	= 20,
.
21a
/* Always Acktime < Fasttime < Slowtime << Ackkeepalive */
.
20a
static char *etime = "connection timed out";
.
## diffname port/stil.c 1991/1125
## diff -e /n/bootesdump/1991/1124/sys/src/9/port/stil.c /n/bootesdump/1991/1125/sys/src/9/port/stil.c
714a
}

void
ilbackoff(Ilcb *ic)
{
	if(ic->fasttime < Slowtime/2)
		ic->fasttime += Fasttime;
	else
		ic->fasttime = (ic->fasttime)*3/2;
.
704c
					ilbackoff(ic);
.
687c
					ilbackoff(ic);
.
676c
					ilbackoff(ic);
.
187a
	}
.
186c
	else {
		/* Start timer since we may have been idle for some time */
		Starttimer(ic);
.
45a
void	ilbackoff(Ilcb*);
.
35a
/* Packet dropping putnext for testing */
#define DPUTNEXT(q, b)	if((MACHP(0)->ticks&7) != 3)PUTNEXT(q, b);else{freeb(b);print(".");}
.
34d
27,30c
	Slowtime 	= 200*Iltickms,
	Fasttime 	= 4*Iltickms,
	Acktime		= 2*Iltickms,
	Ackkeepalive	= 6000*Iltickms,
.
## diffname port/stil.c 1991/1126
## diff -e /n/bootesdump/1991/1125/sys/src/9/port/stil.c /n/bootesdump/1991/1126/sys/src/9/port/stil.c
107d
## diffname port/stil.c 1991/1214
## diff -e /n/bootesdump/1991/1126/sys/src/9/port/stil.c /n/bootesdump/1991/1214/sys/src/9/port/stil.c
748a
	ic->oblks = 0;
.
## diffname port/stil.c 1991/1219
## diff -e /n/bootesdump/1991/1214/sys/src/9/port/stil.c /n/bootesdump/1991/1219/sys/src/9/port/stil.c
68c
			            1500, 60, ETHER_HDR, "IL");
.
## diffname port/stil.c 1991/1230
## diff -e /n/bootesdump/1991/1219/sys/src/9/port/stil.c /n/bootesdump/1991/1230/sys/src/9/port/stil.c
471a
	qunlock(&ic->ackq);

.
470a
	qlock(&ic->ackq);
.
194a
	qunlock(&ic->ackq);
.
193d
## diffname port/stil.c 1992/0101
## diff -e /n/bootesdump/1991/1230/sys/src/9/port/stil.c /n/bootesdump/1992/0101/sys/src/9/port/stil.c
473a

	if(nb == 0)
		return;
.
472c
	if(ic->unacked)
		nb = copyb(ic->unacked, blen(ic->unacked));
.
468,470c
	nb = 0;
.
## diffname port/stil.c 1992/0103
## diff -e /n/bootesdump/1992/0101/sys/src/9/port/stil.c /n/bootesdump/1992/0103/sys/src/9/port/stil.c
161a
	unlock(&ic->nxl);
.
160a
	lock(&ic->nxl);
.
## diffname port/stil.c 1992/0105
## diff -e /n/bootesdump/1992/0103/sys/src/9/port/stil.c /n/bootesdump/1992/0105/sys/src/9/port/stil.c
756d
597d
590c
	if(id <= ic->recvd || id > ic->recvd+ic->window) {
.
564d
317,318c
	ulong id, ack;
.
253c
		print("il: cksum error, pkt(%s id %lud ack %lud %d.%d.%d.%d/%d->%d)\n",
.
163a
	hnputl(ih->ilid, id);

.
162c
	id = ic->next++;
.
160a

.
116a
	ulong id;
.
## diffname port/stil.c 1992/0106
## diff -e /n/bootesdump/1992/0105/sys/src/9/port/stil.c /n/bootesdump/1992/0106/sys/src/9/port/stil.c
753c
	ic->start = initseq & 0xffffff;
.
470c
	Block *nb, *bp;
.
295c
			ic->start = initseq & 0xffffff;
.
154a
	ih->frag[0] = 0;
	ih->frag[1] = 0;
.
## diffname port/stil.c 1992/0107
## diff -e /n/bootesdump/1992/0106/sys/src/9/port/stil.c /n/bootesdump/1992/0107/sys/src/9/port/stil.c
637a
	ih->frag[0] = 0;
	ih->frag[1] = 0;
.
## diffname port/stil.c 1992/0111
## diff -e /n/bootesdump/1992/0107/sys/src/9/port/stil.c /n/bootesdump/1992/0111/sys/src/9/port/stil.c
10c
#include	"../port/error.h"
.
## diffname port/stil.c 1992/0213
## diff -e /n/bootesdump/1992/0111/sys/src/9/port/stil.c /n/bootesdump/1992/0213/sys/src/9/port/stil.c
636c
	hnputl(ih->src, Myip[Myself]);
.
157c
	hnputl(ih->src, Myip[Myself]);
.
## diffname port/stil.c 1992/0301
## diff -e /n/bootesdump/1992/0213/sys/src/9/port/stil.c /n/bootesdump/1992/0301/sys/src/9/port/stil.c
713a
				ic->querytime -= Iltickms;
				if(ic->querytime <= 0){
					ic->deathtime -= Querytime;
					if(ic->deathtime < 0){
						ic->state = Ilclosed;
						ilhangup(s, etime);
						break;
					}
					ilsendctl(s, 0, Ilquerey, ic->next, ic->recvd);
					ic->querytime = Querytime;
				}
.
328a
	ic->querytime = Keepalivetime;
	ic->deathtime = Keepalivetime;
.
301a
			ic->querytime = Keepalivetime;
			ic->deathtime = Keepalivetime;
.
34c
#define Starttimer(s)	{(s)->timeout = 0; (s)->fasttime = Fasttime; }
.
30a
	Querytime	= 60*Iltickms,		/* time between queries */
	Keepalivetime	= 10*Querytime,		/* keep alive time */
.
## diffname port/stil.c 1992/0302
## diff -e /n/bootesdump/1992/0301/sys/src/9/port/stil.c /n/bootesdump/1992/0302/sys/src/9/port/stil.c
261,262c
/*		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); /**/
.
## diffname port/stil.c 1992/0303
## diff -e /n/bootesdump/1992/0302/sys/src/9/port/stil.c /n/bootesdump/1992/0303/sys/src/9/port/stil.c
785a
		sleep(&ic->syncer, notsyncer, ic);
		if(ic->state == Ilclosed)
			error(Etimedout);
.
758a
static int
notsyncer(void *ic)
{
	return ((Ilcb*)ic)->state != Ilsyncer;
}
.
740d
724d
714d
711,712c
				if(ic->timeout >= ic->slowtime)
.
703d
700,701c
				if(ic->timeout >= ic->slowtime)
.
539a
	if(callout)
		wakeup(&ic->syncer);
.
526a

	ic = &s->ilctl;
	callout = ic->state == Ilsyncer;
	ic->state = Ilclosed;
.
524a
	Ilcb *ic;
	int callout;
.
464d
461,462c
			if(ack == ic->next)
.
403d
400,401c
			if(id != ic->start)
.
392d
389,390c
			if(id == ic->next)
.
363d
360,361c
			if(ack == ic->start)
.
354a
				wakeup(&ic->syncer);
.
349d
346,347c
			if(ack != ic->start)
.
260,261c
/*		st = (ih->iltype < 0 || ih->iltype > Ilclose) ? "?" : iltype[ih->iltype];
		print("il: cksum error, pkt(%s id %lud ack %lud %d.%d.%d.%d/%d->%d)\n",
.
## diffname port/stil.c 1992/0307
## diff -e /n/bootesdump/1992/0303/sys/src/9/port/stil.c /n/bootesdump/1992/0307/sys/src/9/port/stil.c
714a

.
259a
		ipc->ipinterface->chkerrs++;
.
## diffname port/stil.c 1992/0310
## diff -e /n/bootesdump/1992/0307/sys/src/9/port/stil.c /n/bootesdump/1992/0310/sys/src/9/port/stil.c
767c
	Starttimer(ic);
.
## diffname port/stil.c 1992/0321
## diff -e /n/bootesdump/1992/0310/sys/src/9/port/stil.c /n/bootesdump/1992/0321/sys/src/9/port/stil.c
19,20c
char	*ilstate[] = 
{ 
	"Closed", "Syncer", "Syncee", "Established", "Listening", "Closing" 
};
char	*iltype[] = 
{	
	"sync", "data", "dataquerey", "ack", "querey", "state", "close" 
};
.
5c
#include	"../port/lib.h"
.
## diffname port/stil.c 1992/0414
## diff -e /n/bootesdump/1992/0321/sys/src/9/port/stil.c /n/bootesdump/1992/0414/sys/src/9/port/stil.c
297c
			new->newcon = s;
.
## diffname port/stil.c 1992/0614
## diff -e /n/bootesdump/1992/0414/sys/src/9/port/stil.c /n/bootesdump/1992/0614/sys/src/9/port/stil.c
777c
	ic->rtt = Iltickms;
	Starttimer(ic);
.
773d
310a
			ic->rtt = Iltickms;
.
219a
	if(ic->rttack == ackto) {
		t = TK2MS(MACHP(0)->ticks - ic->ackms);
		/* Guard against the ulong zero wrap */
		if(t < 100*ic->rtt)
			ic->rtt = (ic->rtt*(ILgain-1)+t)/ILgain;
		if(ic->rtt < Iltickms)
			ic->rtt = Iltickms;
	}

	/* Cancel if we lost the packet we were interested in */
	if(ic->rttack <= ackto)
		ic->rttack = 0;

.
218c
	ulong id, t;
.
187a

	/* Start the round trip timer for this packet if the timer is free */
	if(ic->rttack == 0) {
		ic->rttack = id;
		ic->ackms = MACHP(0)->ticks;
	}
.
42,44c
#define Starttimer(s)	{(s)->timeout = 0; (s)->fasttime = (Fasttime*(s)->rtt)/Iltickms; (s)->slowtime = (Slowtime*(s)->rtt)/Iltickms; }
.
39a
	ILgain		= 8,
.
## diffname port/stil.c 1992/0615
## diff -e /n/bootesdump/1992/0614/sys/src/9/port/stil.c /n/bootesdump/1992/0615/sys/src/9/port/stil.c
227c
		/* Guard against the ulong zero wrap if MACP->ticks */
.
43c
#define Starttimer(s)	{(s)->timeout = 0; \
			 (s)->fasttime = (Fasttime*(s)->rtt)/Iltickms; \
			 (s)->slowtime = (Slowtime*(s)->rtt)/Iltickms; }
.
## diffname port/stil.c 1992/0626
## diff -e /n/bootesdump/1992/0615/sys/src/9/port/stil.c /n/bootesdump/1992/0626/sys/src/9/port/stil.c
715c
		for(p = base; p < end && *p; p++) {
			s = *p;
.
710,711c
	ifc = (Ipifc*)a;
	base = ifc->conv;
	end = &base[Nipconv];
.
706c
	Ipifc *ifc;
	Ipconv **base, **p, **end, *s;
.
564a
	qunlock(s);
.
551a
	qlock(s);
.
337d
318c
			new->ifc = s->ifc;
.
313c
			new = ipincoming(ifc, s);
.
306c
	for(p = ifc->conv; p < etab; p++) {
		s = *p;
		if(s == 0)
			break;
.
300a
	}
.
293,294c
	etab = &ifc->conv[Nipconv];
	for(p = ifc->conv; p < etab; p++) {
		s = *p;
		if(s == 0)
			break;
.
286c
		ifc->chkerrs++;
.
267c
	Ipconv *s, **p, **etab, *new;
.
262c
ilrcvmsg(Ipifc *ifc, Block *bp)
.
81c
	WR(q)->next->ptr = (void *)ipc->ifc;
.
75,77c
	ipc = ipcreateconv(ipifc[s->dev], s->id);
	initipifc(ipc->ifc, IP_ILPROTO, ilrcvmsg, 1500, 60, ETHER_HDR, "IL");
.
72c
		kproc("ilack", ilackproc, ipifc[s->dev]);
.
47c
void	ilrcvmsg(Ipifc*, Block*);
.
## diffname port/stil.c 1992/0711
## diff -e /n/bootesdump/1992/0626/sys/src/9/port/stil.c /n/bootesdump/1992/0711/sys/src/9/port/stil.c
716d
502c
	Block *nb;
.
269d
124c
	Block *f;
.
89d
76c
	initipifc(ipc->ifc, IP_ILPROTO, ilrcvmsg, 1500, 60, ETHER_HDR);
.
## diffname port/stil.c 1992/0904
## diff -e /n/bootesdump/1992/0711/sys/src/9/port/stil.c /n/bootesdump/1992/0904/sys/src/9/port/stil.c
791c
	Ilcb *i;

	i = ic;
	return i->state != Ilsyncer;
.
## diffname port/stil.c 1992/0907
## diff -e /n/bootesdump/1992/0904/sys/src/9/port/stil.c /n/bootesdump/1992/0907/sys/src/9/port/stil.c
795a

.
583a
	ulong oid, dlen;
.
582d
25c
	"sync",
	"data",
	"dataquerey",
	"ack",
	"querey",
	"state",
	"close" 
.
22a

.
21c
	"Closed",
	"Syncer",
	"Syncee",
	"Established",
	"Listening",
	"Closing" 
.
## diffname port/stil.c 1992/1017
## diff -e /n/bootesdump/1992/0907/sys/src/9/port/stil.c /n/bootesdump/1992/1017/sys/src/9/port/stil.c
353,357c
	new->newcon = s;
	new->ifc = s->ifc;
	new->psrc = sp;
	new->pdst = dp;
	new->dst = nhgetl(ih->src);

	ic = &new->ilctl;
	ic->state = Ilsyncee;
	initseq += TK2MS(MACHP(0)->ticks);
	ic->start = initseq & 0xffffff;
	ic->next = ic->start+1;
	ic->recvd = 0;
	ic->rstart = nhgetl(ih->ilid);
	ic->slowtime = Slowtime;
	ic->rtt = Iltickms;
	ic->querytime = Keepalivetime;
	ic->deathtime = Keepalivetime;
	ic->window = Defaultwin;
	ilprocess(new, ih, bp);

	s->curlog++;
	wakeup(&s->listenr);
	return;

.
339,351c
	new = ipincoming(ifc, s);
	if(new == 0)
		goto reset;
.
333,337c
	if(s->curlog > s->backlog)
		goto reset;
.
329,331c
	if(spec)
		s = spec;
	else if(gen)
		s = gen;
	else
		goto drop;
.
326,327c
			if(s->psrc == sp){
				spec = s;
				break;
			}
			if(s->psrc == 0)
				gen = s;
		}
	}
.
321,322d
318,319c
	gen = 0;
	spec = 0;
	etab = &ifc->conv[Nipconv];
	for(p = ifc->conv; p < etab && *p; p++) {
.
277c
	Ipconv *s, **p, **etab, *new, *spec, *gen;
.
## diffname port/stil.c 1993/0123
## diff -e /n/bootesdump/1992/1017/sys/src/9/port/stil.c /n/bootesdump/1993/0123/sys/src/9/port/stil.c
748c
		for(p = base; p < last && *p; p++) {
.
744c
	last = &base[Nipconv];
.
739c
	Ipconv **base, **p, **last, *s;
.
## diffname port/stil.c 1993/0328
## diff -e /n/bootesdump/1993/0123/sys/src/9/port/stil.c /n/bootesdump/1993/0328/sys/src/9/port/stil.c
453c
			if(id != ic->rstart)
.
## diffname port/stil.c 1993/0401
## diff -e /n/bootesdump/1993/0328/sys/src/9/port/stil.c /n/bootesdump/1993/0401/sys/src/9/port/stil.c
16c
static 	int 	initseq = 25001;
.
## diffname port/stil.c 1993/0501
## diff -e /n/bootesdump/1993/0401/sys/src/9/port/stil.c /n/fornaxdump/1993/0501/sys/src/brazil/port/stil.c
748c
		for(p = base; p < end && *p; p++) {
.
744c
	end = &base[Nipconv];
.
739c
	Ipconv **base, **p, **end, *s;
.
600,601d
598a

.
16c
static 	int 	initseq = 26000;
.
## diffname port/stil.c 1993/0804 # deleted
## diff -e /n/fornaxdump/1993/0501/sys/src/brazil/port/stil.c /n/fornaxdump/1993/0804/sys/src/brazil/port/stil.c
1,877d

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to [email protected].