From 46b0c67fbbcbc663a834fd325958a1fd4e425bc2 Mon Sep 17 00:00:00 2001 From: David du Colombier <0intro@gmail.com> Date: Mon, 25 Nov 1991 00:00:00 +0000 Subject: [PATCH] Plan 9 from Bell Labs 1991-11-25 --- port/devip.c | 15 ++++++++++++--- port/segment.c | 8 ++++---- port/stil.c | 32 +++++++++++++++++++++++--------- port/stip.c | 4 +++- 4 files changed, 42 insertions(+), 17 deletions(-) diff --git a/port/devip.c b/port/devip.c index 33171cbff3a2ae860b1065dd984cb70e8fa3d1d8..e065e93c95dd8423a1a274916677c0fb019983b7 100644 --- a/port/devip.c +++ b/port/devip.c @@ -271,6 +271,13 @@ ipwrite(Chan *c, char *a, long n, ulong offset) ilstart(cp, IL_ACTIVE, 20); } + else if(strcmp(field[0], "disconnect") == 0) { + if(cp->stproto != &udpinfo) + error(Eperm); + + cp->dst = 0; + cp->pdst = 0; + } else if(strcmp(field[0], "announce") == 0) { if((cp->stproto == &tcpinfo && cp->tcpctl.state != CLOSED) || (cp->stproto == &ilinfo && cp->ilctl.state != Ilclosed)) @@ -328,7 +335,7 @@ udprcvmsg(Ipconv *muxed, Block *bp) { Ipconv *ifc, *etab; Udphdr *uh; - Port dport; + Port dport, sport; ushort sum, len; Ipaddr addr; @@ -352,11 +359,13 @@ udprcvmsg(Ipconv *muxed, Block *bp) } dport = nhgets(uh->udpdport); + sport = nhgets(uh->udpsport); /* Look for a conversation structure for this port */ etab = &muxed[conf.ip]; for(ifc = muxed; ifc < etab; ifc++) { - if(ifc->psrc == dport && ifc->ref) { + if(ifc->psrc == dport && ifc->ref && + (ifc->pdst == 0 || ifc->pdst == sport)) { /* Trim the packet down to data size */ len = len - (UDP_HDRSIZE-UDP_PHDRSIZE); bp = btrim(bp, UDP_EHSIZE+UDP_HDRSIZE, len); @@ -365,7 +374,7 @@ udprcvmsg(Ipconv *muxed, Block *bp) /* Stuff the src address into the remote file */ ifc->dst = addr; - ifc->pdst = nhgets(uh->udpsport); + ifc->pdst = sport; PUTNEXT(ifc->readq, bp); return; } diff --git a/port/segment.c b/port/segment.c index e72908bb8ca4359a01a456791718d7e57b953df1..80c874b9cfd44d6739031d134493716518a8ab7b 100644 --- a/port/segment.c +++ b/port/segment.c @@ -339,17 +339,17 @@ ibrk(ulong addr, int seg) if(s == 0) errors("no segment"); - qlock(&s->lk); - if(addr == 0) return s->base; + qlock(&s->lk); + if(addr < s->base) { /* We may start with the bss overlapping the data */ if(seg != BSEG || u->p->seg[DSEG] == 0 || addr < u->p->seg[DSEG]->base) { qunlock(&s->lk); - pprint("addr below segment\n"); - } + errors("addr below segment"); + } addr = s->base; } diff --git a/port/stil.c b/port/stil.c index 0c89ab2f2f51d60f881a8c0f5ff8846fa4b14dcc..ad46eacd19de4659053b1788d4bac84fa504a4b0 100644 --- a/port/stil.c +++ b/port/stil.c @@ -24,15 +24,16 @@ static char *etime = "connection timed out"; enum { Iltickms = 100, - Slowtime = 20*Iltickms, - Fasttime = 5*Iltickms, - Acktime = 3*Iltickms, - Ackkeepalive = 1000*Iltickms, + Slowtime = 200*Iltickms, + Fasttime = 4*Iltickms, + Acktime = 2*Iltickms, + Ackkeepalive = 6000*Iltickms, Defaultwin = 20, }; -#define Backoff(s) (s)*=2 #define Starttimer(s) {(s)->timeout = 0; (s)->fasttime = Fasttime;} +/* Packet dropping putnext for testing */ +#define DPUTNEXT(q, b) if((MACHP(0)->ticks&7) != 3)PUTNEXT(q, b);else{freeb(b);print(".");} void ilrcvmsg(Ipconv*, Block*); void ilackproc(void*); @@ -43,6 +44,7 @@ void ilpullup(Ipconv*); void ilhangup(Ipconv*, char *); void ilfreeq(Ilcb*); void ilrexmit(Ilcb*); +void ilbackoff(Ilcb*); void ilopen(Queue *q, Stream *s) @@ -183,8 +185,11 @@ ilackq(Ilcb *ic, Block *bp) qlock(&ic->ackq); if(ic->unacked) ic->unackedtail->list = np; - else + else { + /* Start timer since we may have been idle for some time */ + Starttimer(ic); ic->unacked = np; + } ic->unackedtail = np; qunlock(&ic->ackq); np->list = 0; @@ -673,7 +678,7 @@ ilackproc(void *a) case Ilclosing: if(ic->timeout >= ic->fasttime) { ilsendctl(s, 0, Ilclose, ic->next, ic->recvd); - Backoff(ic->fasttime); + ilbackoff(ic); } if(ic->timeout >= ic->slowtime) { ic->state = Ilclosed; @@ -684,7 +689,7 @@ ilackproc(void *a) case Ilsyncer: if(ic->timeout >= ic->fasttime) { ilsendctl(s, 0, Ilsync, ic->start, ic->recvd); - Backoff(ic->fasttime); + ilbackoff(ic); } if(ic->timeout >= ic->slowtime) { ic->state = Ilclosed; @@ -701,7 +706,7 @@ ilackproc(void *a) } if(ic->timeout >= ic->fasttime) { ilrexmit(ic); - Backoff(ic->fasttime); + ilbackoff(ic); } if(ic->timeout >= ic->slowtime) { ic->state = Ilclosed; @@ -714,6 +719,15 @@ ilackproc(void *a) } } +void +ilbackoff(Ilcb *ic) +{ + if(ic->fasttime < Slowtime/2) + ic->fasttime += Fasttime; + else + ic->fasttime = (ic->fasttime)*3/2; +} + void ilstart(Ipconv *ipc, int type, int window) { diff --git a/port/stip.c b/port/stip.c index 01d2f55cda0751d0d956443b5a28cd441501110f..63da113f98ff1f781a068d9020ac050836d08bc8 100644 --- a/port/stip.c +++ b/port/stip.c @@ -29,6 +29,7 @@ Queue *Etherq; Ipaddr Myip; Ipaddr Mymask; uchar Netmyip[4]; /* In Network byte order */ +uchar bcast[4] = { 0xff, 0xff, 0xff, 0xff }; /* Predeclaration */ static void ipetherclose(Queue*); @@ -309,7 +310,8 @@ ipetheriput(Queue *q, Block *bp) } /* Look to see if its for me before we waste time checksuming it */ - if(memcmp(h->dst, Netmyip, sizeof(Netmyip)) != 0) + if(memcmp(h->dst, Netmyip, sizeof(Netmyip)) != 0 && + memcmp(h->dst, bcast, sizeof(bcast)) != 0) goto drop; if(ipcksum && ip_csum(&h->vihl)) {