devbridge: simplify etherwrite() as we dont deal with block lists
This commit is contained in:
parent
99cc56f2e9
commit
58fe71b2f5
1 changed files with 16 additions and 27 deletions
|
@ -848,7 +848,7 @@ ethermultiwrite(Bridge *b, Block *bp, Port *port)
|
||||||
// delay one so that the last write does not copy
|
// delay one so that the last write does not copy
|
||||||
if(oport != nil) {
|
if(oport != nil) {
|
||||||
b->copy++;
|
b->copy++;
|
||||||
etherwrite(oport, copyblock(bp, blocklen(bp)));
|
etherwrite(oport, copyblock(bp, BLEN(bp)));
|
||||||
}
|
}
|
||||||
oport = b->port[i];
|
oport = b->port[i];
|
||||||
}
|
}
|
||||||
|
@ -972,7 +972,7 @@ etherread(void *a)
|
||||||
qlock(b);
|
qlock(b);
|
||||||
if(bp == nil)
|
if(bp == nil)
|
||||||
break;
|
break;
|
||||||
n = blocklen(bp);
|
n = BLEN(bp);
|
||||||
if(port->closed || n < ETHERMINTU){
|
if(port->closed || n < ETHERMINTU){
|
||||||
freeb(bp);
|
freeb(bp);
|
||||||
continue;
|
continue;
|
||||||
|
@ -1055,13 +1055,13 @@ etherwrite(Port *port, Block *bp)
|
||||||
{
|
{
|
||||||
Iphdr *eh, *feh;
|
Iphdr *eh, *feh;
|
||||||
Etherpkt *epkt;
|
Etherpkt *epkt;
|
||||||
int n, lid, len, seglen, chunk, dlen, blklen, offset, mf;
|
int n, lid, len, seglen, dlen, blklen, mf;
|
||||||
Block *xp, *nb;
|
Block *nb;
|
||||||
ushort fragoff, frag;
|
ushort fragoff, frag;
|
||||||
|
|
||||||
port->out++;
|
port->out++;
|
||||||
|
n = BLEN(bp);
|
||||||
epkt = (Etherpkt*)bp->rp;
|
epkt = (Etherpkt*)bp->rp;
|
||||||
n = blocklen(bp);
|
|
||||||
if(port->type != Ttun || !fragment(epkt, n)) {
|
if(port->type != Ttun || !fragment(epkt, n)) {
|
||||||
if(!waserror()){
|
if(!waserror()){
|
||||||
devtab[port->data[1]->type]->bwrite(port->data[1], bp, 0);
|
devtab[port->data[1]->type]->bwrite(port->data[1], bp, 0);
|
||||||
|
@ -1071,7 +1071,7 @@ etherwrite(Port *port, Block *bp)
|
||||||
}
|
}
|
||||||
port->outfrag++;
|
port->outfrag++;
|
||||||
if(waserror()){
|
if(waserror()){
|
||||||
freeblist(bp);
|
freeb(bp);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1082,14 +1082,8 @@ etherwrite(Port *port, Block *bp)
|
||||||
mf = frag & IP_MF;
|
mf = frag & IP_MF;
|
||||||
frag <<= 3;
|
frag <<= 3;
|
||||||
dlen = len - IPHDR;
|
dlen = len - IPHDR;
|
||||||
xp = bp;
|
|
||||||
lid = nhgets(eh->id);
|
lid = nhgets(eh->id);
|
||||||
offset = ETHERHDRSIZE+IPHDR;
|
bp->rp += ETHERHDRSIZE+IPHDR;
|
||||||
while(xp != nil && offset && offset >= BLEN(xp)) {
|
|
||||||
offset -= BLEN(xp);
|
|
||||||
xp = xp->next;
|
|
||||||
}
|
|
||||||
xp->rp += offset;
|
|
||||||
|
|
||||||
if(0)
|
if(0)
|
||||||
print("seglen=%d, dlen=%d, mf=%x, frag=%d\n",
|
print("seglen=%d, dlen=%d, mf=%x, frag=%d\n",
|
||||||
|
@ -1112,18 +1106,13 @@ etherwrite(Port *port, Block *bp)
|
||||||
hnputs(feh->length, seglen + IPHDR);
|
hnputs(feh->length, seglen + IPHDR);
|
||||||
hnputs(feh->id, lid);
|
hnputs(feh->id, lid);
|
||||||
|
|
||||||
/* Copy up the data area */
|
if(seglen){
|
||||||
chunk = seglen;
|
blklen = BLEN(bp);
|
||||||
while(chunk) {
|
if(seglen < blklen)
|
||||||
blklen = chunk;
|
blklen = seglen;
|
||||||
if(BLEN(xp) < chunk)
|
memmove(nb->wp, bp->rp, blklen);
|
||||||
blklen = BLEN(xp);
|
|
||||||
memmove(nb->wp, xp->rp, blklen);
|
|
||||||
nb->wp += blklen;
|
nb->wp += blklen;
|
||||||
xp->rp += blklen;
|
bp->rp += blklen;
|
||||||
chunk -= blklen;
|
|
||||||
if(xp->rp == xp->wp)
|
|
||||||
xp = xp->next;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
feh->cksum[0] = 0;
|
feh->cksum[0] = 0;
|
||||||
|
@ -1132,11 +1121,11 @@ etherwrite(Port *port, Block *bp)
|
||||||
|
|
||||||
/* don't generate small packets */
|
/* don't generate small packets */
|
||||||
if(BLEN(nb) < ETHERMINTU)
|
if(BLEN(nb) < ETHERMINTU)
|
||||||
nb->wp = nb->rp + ETHERMINTU;
|
nb = adjustblock(nb, ETHERMINTU);
|
||||||
devtab[port->data[1]->type]->bwrite(port->data[1], nb, 0);
|
devtab[port->data[1]->type]->bwrite(port->data[1], nb, 0);
|
||||||
}
|
}
|
||||||
poperror();
|
poperror();
|
||||||
freeblist(bp);
|
freeb(bp);
|
||||||
}
|
}
|
||||||
|
|
||||||
// hold b lock
|
// hold b lock
|
||||||
|
|
Loading…
Reference in a new issue