add vbridge.sh script
authorColin Patrick Mccabe <cmccabe@alumni.cmu.edu>
Fri, 1 Jun 2012 18:14:14 +0000 (11:14 -0700)
committerColin Patrick Mccabe <cmccabe@alumni.cmu.edu>
Fri, 1 Jun 2012 18:14:14 +0000 (11:14 -0700)
Signed-off-by: Colin McCabe <cmccabe@alumni.cmu.edu>

vbridge.sh [new file with mode: 0755]

diff --git a/vbridge.sh b/vbridge.sh
new file mode 100755 (executable)
index 0000000..f59ee33
--- /dev/null
@@ -0,0 +1,38 @@
+#!/bin/bash -xe
+
+#
+# Create tun and bridge interfaces for qemu.
+#
+
+TAP=tap0
+BR=br0
+
+die() {
+    echo $@
+    exit 1
+}
+
+up() {
+    /sbin/tunctl -b -t $TAP
+    /sbin/ifconfig $TAP up
+    /sbin/brctl addbr $BR
+    /sbin/brctl addif $BR $TAP
+    /sbin/ifconfig $BR 192.168.123.1 netmask 255.255.255.0
+    /sbin/ifconfig $BR up
+}
+
+down() {
+    /sbin/ifconfig $BR down
+    /sbin/ifconfig $TAP down
+    /sbin/brctl delbr $BR
+    /sbin/tunctl -d $TAP
+}
+
+ARG="x$1"
+if [ $ARG == "xup" ]; then
+    up
+elif [ $ARG == "xdown" ]; then
+    down
+else
+    die "must specify either up or down."
+fi