@@ 28,6 28,7 @@ struct
Envval *free[EVFREE+1];
char *block; /* the free page we are allocating from */
char *lim; /* end of block */
+ int npage; /* total pages gotten from newpage() */
}envalloc;
QLock evlock;
@@ 366,9 367,10 @@ evalloc(ulong n)
b += ALIGN + sizeof *ev;
}
b = (char*)VA(kmap(newpage(0, 0, 0)));
+ envalloc.npage++;
envalloc.lim = b + BY2PG;
}
-
+
ev = (Envval*)b;
ev->val = b + sizeof *ev;
ev->ref = 1;
@@ 400,6 402,43 @@ evfree(Envval *ev)
envalloc.free[n] = ev;
}
+void
+envdump(void)
+{
+ Envval *ev;
+ int i, j;
+
+ qlock(&evlock);
+ print("pages allocated: %d\n", envalloc.npage);
+ print("bytes left in page: %d\n", envalloc.lim - envalloc.block);
+ for(i = 0; i < EVFREE + 1; i++){
+ j = 0;
+ if(i == EVFREE)
+ print("big blocks:\n");
+ else
+ print("%d byte blocks:\n", (i + 1) * ALIGN);
+ for(ev = envalloc.free[i]; ev; ev = ev->next){
+ if(j++ == 1000){
+ print("circular\n");
+ break;
+ }
+ if(j < 10)
+ print("\tenv %d %lux n%lux p%lux r%d\n",
+ ev->len, ev, ev->next, ev->prev, ev->ref);
+ }
+ }
+ for(i = 0; i < EVHASH; i++){
+ j = 0;
+ for(ev = evhash[i].next; ev; ev = ev->next){
+ if(j++ == 1000){
+ print("hash bucket %d circular\n", i);
+ break;
+ }
+ }
+ }
+ qunlock(&evlock);
+}
+
/*
* to let the kernel set environment variables
*/
@@ 19,7 19,9 @@ char *ilstate[] = { "Closed", "Syncer", "Syncee", "Established", "Listening", "C
void ilrcvmsg(Ipconv*, Block*);
void ilackproc(void*);
-void ilsendctl(Ipconv *, Ilhdr *, int);
+void ilsendctl(Ipconv*, Ilhdr*, int, int);
+void ilackq(Ilcb*, Block*);
+void ilprocess(Ipconv*, Ilhdr*, Block*);
void
ilopen(Queue *q, Stream *s)
@@ 127,7 129,7 @@ iloput(Queue *q, Block *bp)
}
void
-ilackq(Ilctl *ic, Block *bp)
+ilackq(Ilcb *ic, Block *bp)
{
Block *np;
@@ 148,7 150,7 @@ ilackq(Ilctl *ic, Block *bp)
}
void
-ilackto(Ilctl *ic, ulong ackto)
+ilackto(Ilcb *ic, ulong ackto)
{
Ilhdr *h;
Block *bp;
@@ 157,7 159,7 @@ ilackto(Ilctl *ic, ulong ackto)
lock(ic);
if(ic->unacked) {
h = (Ilhdr *)ic->unacked->rptr;
- if(ackto < hngetl(h->ilack)) {
+ if(ackto < nhgetl(h->ilack)) {
unlock(ic);
break;
}
@@ 184,7 186,8 @@ ilrcvmsg(Ipconv *ipc, Block *bp)
{
Ilhdr *ih;
int plen;
- Ipconv *s;
+ Ipconv *s, *etab;
+ short sp, dp;
ih = (Ilhdr *)bp;
@@ 197,43 200,46 @@ ilrcvmsg(Ipconv *ipc, Block *bp)
goto drop;
}
+ sp = nhgets(ih->ildst);
+ dp = nhgets(ih->ilsrc);
etab = &ipc[conf.ip];
for(s = ipc; s < etab; s++) {
- if(s->sport == ih->ildst && s->dport == ih->ilsrc) {
+ if(s->psrc == sp && s->pdst == dp) {
ilprocess(s, ih, bp);
return;
}
}
for(s = ipc; s < etab; s++) {
- if(s->state == Illistening && s->sport == 0) {
+ if(s->ilctl.state == Illistening && s->psrc == 0) {
/* Do the listener stuff */
ilprocess(s, ih, bp);
return;
}
}
- ilsendctl(0, ih, Ilreset);
+ ilsendctl(0, ih, Ilreset, 0);
+drop:
freeb(bp);
}
void
-ilprocess(Ipconv *s, Ihdr *h, Block *bp)
+ilprocess(Ipconv *s, Ilhdr *h, Block *bp)
{
switch(s->ilctl.state) {
case Ilclosed:
case Ilclosing:
- case Illistener:
+ case Illistening:
error(Ehungup);
}
- switch(h->type) {
+ switch(h->iltype) {
case Ilsync:
if(s->ilctl.state == Ilsync)
s->ilctl.state = Ilestablished;
freeb(bp);
break;
case Ilack:
- ilackto(&s->ilctl, hngetl(g->ilack));
+ ilackto(&s->ilctl, nhgetl(h->ilack));
freeb(bp);
break;
case Ilquerey:
@@ 242,12 248,12 @@ ilprocess(Ipconv *s, Ihdr *h, Block *bp)
break;
case Ildataquery:
case Ildata:
- ilackto(&s->ilctl, hngetl(h->ilack));
+ ilackto(&s->ilctl, nhgetl(h->ilack));
bp->rptr += IL_EHSIZE+IL_HDRSIZE;
PUTNEXT(s->readq, bp);
break;
case Ilreset:
- s->ilctl.state = Closed;
+ s->ilctl.state = Ilclosed;
freeb(bp);
}
}
@@ 324,7 330,7 @@ ilstart(Ipconv *ipc, int type, int window)
break;
case IL_ACTIVE:
ic->state = Ilsyncer;
- ilsendctl(ipc, 0, Ilsync);
+ ilsendctl(ipc, 0, Ilsync, 1);
break;
}