shithub: riscv

Download patch

ref: 9fd8894fec87ccd326997b84a2be431af8764cce
parent: 4ad70e6055093123f0611269ca7e8e201257e5db
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Fri Dec 15 17:22:29 EST 2017

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.

--- a/sys/man/3/ether
+++ b/sys/man/3/ether
@@ -107,5 +107,17 @@
 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
--- a/sys/src/9/kw/devether.c
+++ b/sys/src/9/kw/devether.c
@@ -281,7 +281,8 @@
 		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;
 
--- a/sys/src/9/mtx/devether.c
+++ b/sys/src/9/mtx/devether.c
@@ -266,7 +266,8 @@
 		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;
 
--- a/sys/src/9/omap/devether.c
+++ b/sys/src/9/omap/devether.c
@@ -279,7 +279,8 @@
 		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;
 
--- a/sys/src/9/pc/devether.c
+++ b/sys/src/9/pc/devether.c
@@ -286,7 +286,8 @@
 		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;
 
--- a/sys/src/9/ppc/devether.c
+++ b/sys/src/9/ppc/devether.c
@@ -265,7 +265,8 @@
 		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;
 
--- a/sys/src/9/sgi/devether.c
+++ b/sys/src/9/sgi/devether.c
@@ -285,7 +285,8 @@
 		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;
 
--- a/sys/src/9/teg2/devether.c
+++ b/sys/src/9/teg2/devether.c
@@ -277,7 +277,8 @@
 		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;
 
--- a/sys/src/9/zynq/devether.c
+++ b/sys/src/9/zynq/devether.c
@@ -285,7 +285,8 @@
 		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;
 
--- a/sys/src/cmd/nusb/ether/ether.c
+++ b/sys/src/cmd/nusb/ether/ether.c
@@ -306,6 +306,11 @@
 
 	/* 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);
--- a/sys/src/cmd/vmx/virtio.c
+++ b/sys/src/cmd/vmx/virtio.c
@@ -655,7 +655,10 @@
 	}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);