devether: handle input queue size for bypass mode

when the interface is bypassed, use a fixed large
receive queue (1MB) and ignore speed/link state
changes.

also, zap the mac table when the link state changes.
This commit is contained in:
cinap_lenrek 2025-01-10 22:50:24 +00:00
parent 09b5619466
commit 511cd4dc31
2 changed files with 44 additions and 25 deletions

View file

@ -21,6 +21,9 @@ static Ether *etherprobe(int cardno, int ctlrno, char *conf);
static void dmatproxy(Block*, int, uchar*, DMAT*); static void dmatproxy(Block*, int, uchar*, DMAT*);
static int etheroqsize(Ether*);
static int etheriqsize(Ether*);
Chan* Chan*
etherattach(char* spec) etherattach(char* spec)
{ {
@ -88,10 +91,17 @@ static void
etherclose(Chan* chan) etherclose(Chan* chan)
{ {
Ether *ether = etherxx[chan->dev]; Ether *ether = etherxx[chan->dev];
Netfile *f;
if(NETTYPE(chan->qid.path) == Ndataqid && ether->f[NETID(chan->qid.path)]->bridge) if(NETTYPE(chan->qid.path) == Ndataqid){
f = ether->f[NETID(chan->qid.path)];
if(f->bridge || f->bypass)
memset(ether->mactab, 0, sizeof(ether->mactab)); memset(ether->mactab, 0, sizeof(ether->mactab));
if(f->bypass){
qsetlimit(ether->oq, etheroqsize(ether));
netifsetlimit(ether, etheriqsize(ether));
}
}
netifclose(ether, chan); netifclose(ether, chan);
} }
@ -295,8 +305,14 @@ etherwrite(Chan* chan, void* buf, long n, vlong)
if(NETTYPE(chan->qid.path) != Ndataqid) { if(NETTYPE(chan->qid.path) != Ndataqid) {
nn = netifwrite(ether, chan, buf, n); nn = netifwrite(ether, chan, buf, n);
if(nn >= 0) if(nn >= 0){
/* ignore mbps and use large input queue size when bypassed */
if(ether->f[NETID(chan->qid.path)]->bypass){
qflush(ether->oq);
netifsetlimit(ether, MB);
}
return nn; return nn;
}
cb = parsecmd(buf, n); cb = parsecmd(buf, n);
if(cb->f[0] && strcmp(cb->f[0], "nonblocking") == 0){ if(cb->f[0] && strcmp(cb->f[0], "nonblocking") == 0){
if(cb->nf <= 1) if(cb->nf <= 1)
@ -380,7 +396,7 @@ addethercard(char* t, int (*r)(Ether*))
} }
static int static int
etherqueuesize(Ether *ether) etheroqsize(Ether *ether)
{ {
int b, q; int b, q;
@ -392,6 +408,12 @@ etherqueuesize(Ether *ether)
return q; return q;
} }
static int
etheriqsize(Ether *ether)
{
return etheroqsize(ether) * 2;
}
static Ether* static Ether*
etherprobe(int cardno, int ctlrno, char *conf) etherprobe(int cardno, int ctlrno, char *conf)
{ {
@ -445,7 +467,7 @@ Nope:
print("#l%d: %s: %dMbps port 0x%lluX irq %d ea %E\n", print("#l%d: %s: %dMbps port 0x%lluX irq %d ea %E\n",
ctlrno, ether->type, ether->mbps, (uvlong)ether->port, ether->irq, ether->ea); ctlrno, ether->type, ether->mbps, (uvlong)ether->port, ether->irq, ether->ea);
q = etherqueuesize(ether); q = etheroqsize(ether);
if(ether->oq == nil){ if(ether->oq == nil){
ether->oq = qopen(q, Qmsg, 0, 0); ether->oq = qopen(q, Qmsg, 0, 0);
if(ether->oq == nil) if(ether->oq == nil)
@ -453,7 +475,7 @@ Nope:
} else { } else {
qsetlimit(ether->oq, q); qsetlimit(ether->oq, q);
} }
netifinit(ether, ether->name, Ntypes, q*2); netifinit(ether, ether->name, Ntypes, etheriqsize(ether));
ether->alen = Eaddrlen; ether->alen = Eaddrlen;
memmove(ether->addr, ether->ea, Eaddrlen); memmove(ether->addr, ether->ea, Eaddrlen);
memset(ether->bcast, 0xFF, Eaddrlen); memset(ether->bcast, 0xFF, Eaddrlen);
@ -464,17 +486,13 @@ Nope:
void void
ethersetspeed(Ether *ether, int mbps) ethersetspeed(Ether *ether, int mbps)
{ {
int q;
if(ether->mbps == mbps) if(ether->mbps == mbps)
return; return;
ether->mbps = mbps; ether->mbps = mbps;
if(mbps <= 0 || ether->f == nil || ether->oq == nil || ether->bypass)
if(mbps <= 0 || ether->f == nil || ether->oq == nil)
return; return;
q = etherqueuesize(ether); qsetlimit(ether->oq, etheroqsize(ether));
qsetlimit(ether->oq, q); netifsetlimit(ether, etheriqsize(ether));
netifsetlimit(ether, q*2);
} }
void void
@ -484,10 +502,9 @@ ethersetlink(Ether *ether, int link)
if(!!ether->link == link) if(!!ether->link == link)
return; return;
ether->link = link; ether->link = link;
if(ether->f == nil || ether->bypass)
if(ether->f == nil)
return; return;
memset(ether->mactab, 0, sizeof(ether->mactab));
if(link) if(link)
print("#l%d: %s: link up: %dMbps\n", print("#l%d: %s: link up: %dMbps\n",
ether->ctlrno, ether->type, ether->mbps); ether->ctlrno, ether->type, ether->mbps);

View file

@ -39,6 +39,7 @@ netifsetlimit(Netif *nif, int limit)
int i; int i;
qlock(nif); qlock(nif);
if(nif->limit != limit){
nif->limit = limit; nif->limit = limit;
for(i = 0; i < nif->nfile; i++){ for(i = 0; i < nif->nfile; i++){
f = nif->f[i]; f = nif->f[i];
@ -48,6 +49,7 @@ netifsetlimit(Netif *nif, int limit)
qsetlimit(f->in, nif->limit); qsetlimit(f->in, nif->limit);
qunlock(f); qunlock(f);
} }
}
qunlock(nif); qunlock(nif);
} }