ether: allow spoofing of source mac address for bridges; used by vmx
to implement layer 2 bridges in userspace, we disable to auto filling of the source mac address when bridge mode is enabled on the connection.
This commit is contained in:
parent
4ad70e6055
commit
9fd8894fec
11 changed files with 37 additions and 9 deletions
|
@ -107,5 +107,17 @@ The interface remains promiscuous until the control file is
|
||||||
closed.
|
closed.
|
||||||
The extra packets are passed up connections only of types \-1
|
The extra packets are passed up connections only of types \-1
|
||||||
and \-2.
|
and \-2.
|
||||||
|
.PP
|
||||||
|
Writing packets to the
|
||||||
|
.B data
|
||||||
|
file automatically fills the
|
||||||
|
source address before sending. To allow implementations of
|
||||||
|
layer 2 bridges like
|
||||||
|
.IR bridge (3),
|
||||||
|
connections can be set to bridge mode by writing
|
||||||
|
.B bridge
|
||||||
|
to the
|
||||||
|
.B ctl
|
||||||
|
file.
|
||||||
.SH SOURCE
|
.SH SOURCE
|
||||||
.B /sys/src/9/*/devether.c
|
.B /sys/src/9/*/devether.c
|
||||||
|
|
|
@ -281,7 +281,8 @@ etherwrite(Chan* chan, void* buf, long n, vlong)
|
||||||
nexterror();
|
nexterror();
|
||||||
}
|
}
|
||||||
memmove(bp->rp, buf, n);
|
memmove(bp->rp, buf, n);
|
||||||
memmove(bp->rp+Eaddrlen, ether->ea, Eaddrlen);
|
if(!ether->f[NETID(chan->qid.path)]->bridge)
|
||||||
|
memmove(bp->rp+Eaddrlen, ether->ea, Eaddrlen);
|
||||||
poperror();
|
poperror();
|
||||||
bp->wp += n;
|
bp->wp += n;
|
||||||
|
|
||||||
|
|
|
@ -266,7 +266,8 @@ etherwrite(Chan* chan, void* buf, long n, vlong)
|
||||||
nexterror();
|
nexterror();
|
||||||
}
|
}
|
||||||
memmove(bp->rp, buf, n);
|
memmove(bp->rp, buf, n);
|
||||||
memmove(bp->rp+Eaddrlen, ether->ea, Eaddrlen);
|
if(!ether->f[NETID(chan->qid.path)]->bridge)
|
||||||
|
memmove(bp->rp+Eaddrlen, ether->ea, Eaddrlen);
|
||||||
poperror();
|
poperror();
|
||||||
bp->wp += n;
|
bp->wp += n;
|
||||||
|
|
||||||
|
|
|
@ -279,7 +279,8 @@ etherwrite(Chan* chan, void* buf, long n, vlong)
|
||||||
nexterror();
|
nexterror();
|
||||||
}
|
}
|
||||||
memmove(bp->rp, buf, n);
|
memmove(bp->rp, buf, n);
|
||||||
memmove(bp->rp+Eaddrlen, ether->ea, Eaddrlen);
|
if(!ether->f[NETID(chan->qid.path)]->bridge)
|
||||||
|
memmove(bp->rp+Eaddrlen, ether->ea, Eaddrlen);
|
||||||
poperror();
|
poperror();
|
||||||
bp->wp += n;
|
bp->wp += n;
|
||||||
|
|
||||||
|
|
|
@ -286,7 +286,8 @@ etherwrite(Chan* chan, void* buf, long n, vlong)
|
||||||
nexterror();
|
nexterror();
|
||||||
}
|
}
|
||||||
memmove(bp->rp, buf, n);
|
memmove(bp->rp, buf, n);
|
||||||
memmove(bp->rp+Eaddrlen, ether->ea, Eaddrlen);
|
if(!ether->f[NETID(chan->qid.path)]->bridge)
|
||||||
|
memmove(bp->rp+Eaddrlen, ether->ea, Eaddrlen);
|
||||||
poperror();
|
poperror();
|
||||||
bp->wp += n;
|
bp->wp += n;
|
||||||
|
|
||||||
|
|
|
@ -265,7 +265,8 @@ etherwrite(Chan* chan, void* buf, long n, vlong)
|
||||||
nexterror();
|
nexterror();
|
||||||
}
|
}
|
||||||
memmove(bp->rp, buf, n);
|
memmove(bp->rp, buf, n);
|
||||||
memmove(bp->rp+Eaddrlen, ether->ea, Eaddrlen);
|
if(!ether->f[NETID(chan->qid.path)]->bridge)
|
||||||
|
memmove(bp->rp+Eaddrlen, ether->ea, Eaddrlen);
|
||||||
poperror();
|
poperror();
|
||||||
bp->wp += n;
|
bp->wp += n;
|
||||||
|
|
||||||
|
|
|
@ -285,7 +285,8 @@ etherwrite(Chan* chan, void* buf, long n, vlong)
|
||||||
nexterror();
|
nexterror();
|
||||||
}
|
}
|
||||||
memmove(bp->rp, buf, n);
|
memmove(bp->rp, buf, n);
|
||||||
memmove(bp->rp+Eaddrlen, ether->ea, Eaddrlen);
|
if(!ether->f[NETID(chan->qid.path)]->bridge)
|
||||||
|
memmove(bp->rp+Eaddrlen, ether->ea, Eaddrlen);
|
||||||
poperror();
|
poperror();
|
||||||
bp->wp += n;
|
bp->wp += n;
|
||||||
|
|
||||||
|
|
|
@ -277,7 +277,8 @@ etherwrite(Chan* chan, void* buf, long n, vlong)
|
||||||
nexterror();
|
nexterror();
|
||||||
}
|
}
|
||||||
memmove(bp->rp, buf, n);
|
memmove(bp->rp, buf, n);
|
||||||
memmove(bp->rp+Eaddrlen, ether->ea, Eaddrlen);
|
if(!ether->f[NETID(chan->qid.path)]->bridge)
|
||||||
|
memmove(bp->rp+Eaddrlen, ether->ea, Eaddrlen);
|
||||||
poperror();
|
poperror();
|
||||||
bp->wp += n;
|
bp->wp += n;
|
||||||
|
|
||||||
|
|
|
@ -285,7 +285,8 @@ etherwrite(Chan* chan, void* buf, long n, vlong)
|
||||||
nexterror();
|
nexterror();
|
||||||
}
|
}
|
||||||
memmove(bp->rp, buf, n);
|
memmove(bp->rp, buf, n);
|
||||||
memmove(bp->rp+Eaddrlen, ether->ea, Eaddrlen);
|
if(!ether->f[NETID(chan->qid.path)]->bridge)
|
||||||
|
memmove(bp->rp+Eaddrlen, ether->ea, Eaddrlen);
|
||||||
poperror();
|
poperror();
|
||||||
bp->wp += n;
|
bp->wp += n;
|
||||||
|
|
||||||
|
|
|
@ -306,6 +306,11 @@ writeconndata(Req *r)
|
||||||
|
|
||||||
/* copy in the ethernet packet */
|
/* copy in the ethernet packet */
|
||||||
memmove(b->wp, p, r->ifcall.count);
|
memmove(b->wp, p, r->ifcall.count);
|
||||||
|
|
||||||
|
/* fill source mac address if not bridged */
|
||||||
|
if(!conn[NUM(r->fid->qid.path)].bridge)
|
||||||
|
memmove(b->wp+6, macaddr, 6);
|
||||||
|
|
||||||
b->wp += r->ifcall.count;
|
b->wp += r->ifcall.count;
|
||||||
|
|
||||||
etheriq(b, 0);
|
etheriq(b, 0);
|
||||||
|
|
|
@ -655,7 +655,10 @@ mkvionet(char *net)
|
||||||
}else{
|
}else{
|
||||||
fd = dial(netmkaddr("-1", net, nil), nil, nil, &cfd);
|
fd = dial(netmkaddr("-1", net, nil), nil, nil, &cfd);
|
||||||
if(fd < 0) return -1;
|
if(fd < 0) return -1;
|
||||||
if(cfd >= 0) fprint(cfd, "promiscuous");
|
if(cfd >= 0) {
|
||||||
|
write(cfd, "promiscuous", 11);
|
||||||
|
write(cfd, "bridge", 6);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
d = mkviodev(0x1000, 0x020000, 1, 3);
|
d = mkviodev(0x1000, 0x020000, 1, 3);
|
||||||
|
|
Loading…
Reference in a new issue