From 830f705b607b26a9f6d645d7ef2a314b604b13d1 Mon Sep 17 00:00:00 2001 From: David du Colombier <0intro@gmail.com> Date: Sun, 13 Oct 1991 00:00:00 +0000 Subject: [PATCH] Plan 9 from Bell Labs 1991-10-13 --- port/devip.c | 5 +-- port/ipdat.h | 1 + port/stil.c | 115 +++++++++++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 113 insertions(+), 8 deletions(-) diff --git a/port/devip.c b/port/devip.c index 8a9806ccf94107e0549253e4bb107d49082b1fbc..5494dc7cb51904e67613cf9dfc2669394f3533ca 100644 --- a/port/devip.c +++ b/port/devip.c @@ -9,7 +9,6 @@ #include "devtab.h" - enum { Nrprotocol = 3, /* Number of protocols supported by this driver */ @@ -605,7 +604,6 @@ void tcpstopen(Queue *q, Stream *s) { Ipconv *ipc; - static int donekproc; /* Start tcp service processes */ if(!Tcpoutput) { @@ -719,7 +717,7 @@ tcpstclose(Queue *q) /* - * ptcl_csum - protcol cecksum routine + * ptcl_csum - protcol checksum routine */ ushort ptcl_csum(Block *bp, int offset, int len) @@ -858,4 +856,3 @@ ip_conn(Ipconv *ic, Port dst, Port src, Ipaddr dest, char proto) return 0; } - diff --git a/port/ipdat.h b/port/ipdat.h index 3a2ba84f28541407d6e2b0850221713564c94f74..eda2f70fa3f69b7812fe43f3a9360ade232f47da 100644 --- a/port/ipdat.h +++ b/port/ipdat.h @@ -108,6 +108,7 @@ enum Ilack, Ilquerey, Ilstate, + Ilreset, }; #define TCP_PKT (TCP_EHSIZE+TCP_IPLEN+TCP_PHDRSIZE) diff --git a/port/stil.c b/port/stil.c index cf367999bd7dee3a8f8da7e72ec0bcf53fec7e27..32954962dc35d07a8dfcfa053eafb4d64d247e75 100644 --- a/port/stil.c +++ b/port/stil.c @@ -12,14 +12,26 @@ #include "ipdat.h" #define DPRINT if(pip)print +int ilcksum = 1; +Queue *Iloutput; /* Il to lance output channel */ -void ilrcvmsg(Ipconv *, Block *); +void ilrcvmsg(Ipconv*, Block*); +void ilackproc(void*); void ilopen(Queue *q, Stream *s) { Ipconv *ipc; + /* 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); + } + ipc = &ipconv[s->dev][s->id]; ipc->ipinterface = newipifc(IP_ILPROTO, ilrcvmsg, ipconv[s->dev], 1500, 512, ETHER_HDR, "IL"); @@ -43,7 +55,9 @@ iloput(Queue *q, Block *bp) { Ipconv *ipc; Ilhdr *ih; + Ilcb *ic; int dlen; + Block *np; /* Prepend udp header to packet and pass on to ip layer */ ipc = (Ipconv *)(q->ptr); @@ -71,22 +85,115 @@ iloput(Queue *q, Block *bp) bp = padb(bp, IL_EHSIZE+IL_HDRSIZE); ih = (Ilhdr *)(bp->rptr); + ic = &ipc->ilctl; 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); + hnputl(ih->ilid, ic->sent++); + hnputl(ih->ilack, ic->recvd); ih->ilsum[0] = 0; ih->ilsum[1] = 0; + /* 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; + PUTNEXT(q, bp); } - void iliput(Queue *q, Block *bp) +{ + 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) { }