fix the following: 1. echo>/net/ether?/clone would crash machine 2. allow for attach failure -- clean up channel. sorry about the extra jumbo-frame related noise. - erik Reference: /n/sources/patch/applied/devether Date: Thu Nov 29 16:57:26 CET 2007 Signed-off-by: quanstro@quanstro.net --- /sys/src/9/pc/devether.c Thu Nov 29 16:55:40 2007 +++ /sys/src/9/pc/devether.c Thu Nov 29 16:55:37 2007 @@ -4,7 +4,6 @@ #include "dat.h" #include "fns.h" #include "io.h" -#include "pool.h" #include "ureg.h" #include "../port/error.h" #include "../port/netif.h" @@ -30,9 +29,14 @@ error(Enodev); chan = devattach('l', spec); + if(waserror()){ + chanfree(chan); + nexterror(); + } chan->dev = ctlrno; if(etherxx[ctlrno]->attach) etherxx[ctlrno]->attach(etherxx[ctlrno]); + poperror(); return chan; } @@ -251,7 +255,7 @@ if(nn >= 0) return nn; cb = parsecmd(buf, n); - if(strcmp(cb->f[0], "nonblocking") == 0){ + if(cb->f[0] && strcmp(cb->f[0], "nonblocking") == 0){ if(cb->nf <= 1) onoff = 1; else @@ -263,11 +267,11 @@ free(cb); if(ether->ctl!=nil) return ether->ctl(ether,buf,n); - + error(Ebadctl); } - if(n > ether->maxmtu) + if(n > ether->mtu) error(Etoobig); if(n < ether->minmtu) error(Etoosmall); @@ -304,7 +308,7 @@ } ether = etherxx[chan->dev]; - if(n > ether->maxmtu){ + if(n > ether->mtu){ freeb(bp); error(Etoobig); } @@ -359,8 +363,7 @@ static Ether* etherprobe(int cardno, int ctlrno) { - int i, lg; - ulong mb, bsz; + int i, j; Ether *ether; char buf[128], name[32]; @@ -370,6 +373,7 @@ ether->tbdf = BUSUNKNOWN; ether->mbps = 10; ether->minmtu = ETHERMINTU; + ether->mtu = ETHERMAXTU; ether->maxmtu = ETHERMAXTU; if(cardno < 0){ @@ -415,8 +419,8 @@ if(ether->irq >= 0) intrenable(ether->irq, ether->interrupt, ether, ether->tbdf, name); - i = sprint(buf, "#l%d: %s: %dMbps port 0x%luX irq %d", - ctlrno, cards[cardno].type, ether->mbps, ether->port, ether->irq); + i = sprint(buf, "#l%d: %s: %dMbps port 0x%luX irq %d tu %d", + ctlrno, cards[cardno].type, ether->mbps, ether->port, ether->irq, ether->mtu); if(ether->mem) i += sprint(buf+i, " addr 0x%luX", ether->mem); if(ether->size) @@ -427,25 +431,16 @@ sprint(buf+i, "\n"); print(buf); - /* compute log10(ether->mbps) into lg */ - for(lg = 0, mb = ether->mbps; mb >= 10; lg++) - mb /= 10; - if (lg > 0) - lg--; - if (lg > 14) /* 2^(14+17) = 2⁳ⁱ */ - lg = 14; - /* allocate larger output queues for higher-speed interfaces */ - bsz = 1UL << (lg + 17); /* 2ⁱ⁷ = 128K, bsz = 2ⁿ × 128K */ - while (bsz > mainmem->maxsize && bsz >= 128*1024) - bsz /= 2; - - netifinit(ether, name, Ntypes, bsz); - while (ether->oq == nil && bsz >= 128*1024) { - bsz /= 2; - ether->oq = qopen(bsz, Qmsg, 0, 0); - ether->limit = bsz; - } - if(ether->oq == nil) + j = ether->mbps; + if(j > 1000) + j *= 10; + for(i = 0; j >= 100; i++) + j /= 10; + i = (128<oq == 0) + ether->oq = qopen(i, Qmsg, 0, 0); + if(ether->oq == 0) panic("etherreset %s", name); ether->alen = Eaddrlen; memmove(ether->addr, ether->ea, Eaddrlen);