M port/devip.c => port/devip.c +8 -3
@@ 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);
M port/ipdat.h => port/ipdat.h +22 -4
@@ 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 *);
M port/stil.c => port/stil.c +38 -15
@@ 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;
+ }
+
+}
M port/tcpif.c => port/tcpif.c +1 -1
@@ 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;