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:
cinap_lenrek 2017-12-15 22:22:29 +01:00
parent 4ad70e6055
commit 9fd8894fec
11 changed files with 37 additions and 9 deletions

View file

@ -107,5 +107,17 @@ The interface remains promiscuous until the control file is
closed.
The extra packets are passed up connections only of types \-1
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
.B /sys/src/9/*/devether.c

View file

@ -281,7 +281,8 @@ etherwrite(Chan* chan, void* buf, long n, vlong)
nexterror();
}
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();
bp->wp += n;

View file

@ -266,7 +266,8 @@ etherwrite(Chan* chan, void* buf, long n, vlong)
nexterror();
}
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();
bp->wp += n;

View file

@ -279,7 +279,8 @@ etherwrite(Chan* chan, void* buf, long n, vlong)
nexterror();
}
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();
bp->wp += n;

View file

@ -286,7 +286,8 @@ etherwrite(Chan* chan, void* buf, long n, vlong)
nexterror();
}
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();
bp->wp += n;

View file

@ -265,7 +265,8 @@ etherwrite(Chan* chan, void* buf, long n, vlong)
nexterror();
}
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();
bp->wp += n;

View file

@ -285,7 +285,8 @@ etherwrite(Chan* chan, void* buf, long n, vlong)
nexterror();
}
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();
bp->wp += n;

View file

@ -277,7 +277,8 @@ etherwrite(Chan* chan, void* buf, long n, vlong)
nexterror();
}
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();
bp->wp += n;

View file

@ -285,7 +285,8 @@ etherwrite(Chan* chan, void* buf, long n, vlong)
nexterror();
}
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();
bp->wp += n;

View file

@ -306,6 +306,11 @@ writeconndata(Req *r)
/* copy in the ethernet packet */
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;
etheriq(b, 0);

View file

@ -655,7 +655,10 @@ mkvionet(char *net)
}else{
fd = dial(netmkaddr("-1", net, nil), nil, nil, &cfd);
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);