From 0b96d38ea5d87ad8b4b90472aff0fa0ba436ee03 Mon Sep 17 00:00:00 2001 From: David du Colombier <0intro@gmail.com> Date: Mon, 14 Oct 1991 00:00:00 +0000 Subject: [PATCH] Plan 9 from Bell Labs 1991-10-14 --- port/devip.c | 11 ++++++++--- port/ipdat.h | 26 ++++++++++++++++++++++---- port/stil.c | 53 +++++++++++++++++++++++++++++++++++++--------------- port/tcpif.c | 2 +- 4 files changed, 69 insertions(+), 23 deletions(-) diff --git a/port/devip.c b/port/devip.c index 5494dc7cb51904e67613cf9dfc2669394f3533ca..ffeb29b1923eed7ab5e21b854458806e6495cc10 100644 --- a/port/devip.c +++ b/port/devip.c @@ -187,8 +187,10 @@ ipopen(Chan *c, int omode) pushq(c->stream, cp->stproto); if(cp->stproto == &tcpinfo) - open_tcp(cp, TCP_PASSIVE, Streamhi, 0); - + tcpstart(cp, TCP_PASSIVE, Streamhi, 0); + else if(cp->stproto == &ilinfo) + ilstart(cp, IL_PASSIVE, 10); + iplisten(c, cp, ipconv[c->dev]); break; case Sdataqid: @@ -197,7 +199,10 @@ ipopen(Chan *c, int omode) pushq(c->stream, cp->stproto); if(cp->stproto == &tcpinfo) - open_tcp(cp, TCP_ACTIVE, Streamhi, 0); + tcpstart(cp, TCP_ACTIVE, Streamhi, 0); + else if(cp->stproto == &ilinfo) + ilstart(cp, IL_ACTIVE, 10); + break; case Sctlqid: streamopen(c, &ipinfo); diff --git a/port/ipdat.h b/port/ipdat.h index eda2f70fa3f69b7812fe43f3a9360ade232f47da..053621b3f26cbb50be7b108406e5464d361b3a02 100644 --- a/port/ipdat.h +++ b/port/ipdat.h @@ -68,7 +68,7 @@ struct Udphdr struct Ilhdr { -#define IL_EHSIZE 22 +#define IL_EHSIZE 34 uchar d[6]; /* Ethernet destination */ uchar s[6]; /* Ethernet source */ uchar type[2]; /* Ethernet packet type */ @@ -77,6 +77,11 @@ struct Ilhdr uchar length[2]; /* packet length */ uchar id[2]; /* Identification */ uchar frag[2]; /* Fragment information */ + uchar ttl; /* Time to live */ + uchar proto; /* Protocol */ + uchar cksum[2]; /* Header checksum */ + uchar src[4]; /* Ip source */ + uchar dst[4]; /* Ip destination */ #define IL_HDRSIZE 16 uchar ilsum[2]; /* Checksum including header */ uchar illen[2]; /* Packet length */ @@ -88,7 +93,7 @@ struct Ilhdr uchar ilack[4]; /* Acked sequence */ }; -struct Ilcb +struct Ilcb /* Control block */ { int state; Block *unacked; @@ -98,9 +103,10 @@ struct Ilcb ulong sent; ulong recvd; ulong lastack; + int window; }; -enum +enum /* Packet types */ { Ilsync, Ildata, @@ -111,6 +117,16 @@ enum Ilreset, }; +enum /* Connection state */ +{ + Ilclosed, + Ilsyncer, + Ilsyncee, + Ilestablished, + Illistening, + Ilclosing, +}; + #define TCP_PKT (TCP_EHSIZE+TCP_IPLEN+TCP_PHDRSIZE) struct Tcphdr @@ -292,6 +308,8 @@ struct Ipconv #define TCP_PASSIVE 0 #define TCP_ACTIVE 1 +#define IL_PASSIVE 0 +#define IL_ACTIVE 1 #define MAXBACKOFF 5 #define FORCE 1 @@ -481,7 +499,7 @@ int backoff(int); int dupb(Block **, Block *, int, int); void tcp_input(Ipconv *, Block *); void tcprcvwin(Ipconv *); -void open_tcp(Ipconv *, int, ushort, char); +void tcpstart(Ipconv *, int, ushort, char); void tcpflow(void*); void tcp_timeout(void *); void tcp_acktimer(void *); diff --git a/port/stil.c b/port/stil.c index 32954962dc35d07a8dfcfa053eafb4d64d247e75..e69b8af30a6803f05d49463c14aab99fe9f0f948 100644 --- a/port/stil.c +++ b/port/stil.c @@ -14,9 +14,11 @@ #define DPRINT if(pip)print int ilcksum = 1; Queue *Iloutput; /* Il to lance output channel */ +static int initseq = 25000; void ilrcvmsg(Ipconv*, Block*); void ilackproc(void*); +void ilsendctl(Ipconv *, Ilhdr *, int); void ilopen(Queue *q, Stream *s) @@ -126,6 +128,8 @@ void ilrcvmsg(Ipconv *ipc, Block *bp) { Ilhdr *ih; + int plen; + Ipconv *s; ih = (Ilhdr *)bp; @@ -138,21 +142,12 @@ ilrcvmsg(Ipconv *ipc, Block *bp) goto drop; } - s = ip_conn(ipc, hngets(ih->ildst), hngets(ih->ilsrc), hngetl(), IP_ILPROTO); + s = ip_conn(ipc, nhgets(ih->ildst), nhgets(ih->ilsrc), nhgetl(ih->src), IP_ILPROTO); if(s == 0) { - ilsentctl(0, ih, Ilreset); + ilsendctl(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); @@ -171,10 +166,10 @@ ilsendctl(Ipconv *ipc, Ilhdr *inih, int type) 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); + hnputs(ih->ilsrc, nhgets(inih->ildst)); + hnputs(ih->ildst, nhgets(inih->ilsrc)); + hnputl(ih->ilid, nhgetl(inih->ilack)); + hnputl(ih->ilack, nhgetl(inih->ilid)); } else { hnputs(ih->ilsrc, ipc->psrc); @@ -197,3 +192,31 @@ void ilackproc(void *junk) { } + +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; + } + +} diff --git a/port/tcpif.c b/port/tcpif.c index ccfd78af786e5b74f0afe631175c53e62fc4b21a..c87314f96a8a34b2020339a2f4aef3d2b3be3766 100644 --- a/port/tcpif.c +++ b/port/tcpif.c @@ -54,7 +54,7 @@ state_upcall(Ipconv *s, char oldstate, char newstate) } void -open_tcp(Ipconv *s, int mode, ushort window, char tos) +tcpstart(Ipconv *s, int mode, ushort window, char tos) { Tcpctl *tcb = &s->tcpctl;