]> gitweb.fluxo.info Git - kvmx.git/commitdiff
Initial bridge support thanks to kvm-manager
authorSilvio Rhatto <rhatto@riseup.net>
Sat, 30 Dec 2017 20:13:28 +0000 (18:13 -0200)
committerSilvio Rhatto <rhatto@riseup.net>
Sat, 30 Dec 2017 20:13:28 +0000 (18:13 -0200)
kvmx

diff --git a/kvmx b/kvmx
index 81b62e53a7a754c965231c7905d3b6f2d0ee6bc6..3e718029bdc596043128ea1c6a9f20e4f8b4cd3e 100755 (executable)
--- a/kvmx
+++ b/kvmx
@@ -371,9 +371,21 @@ function kvmx_up {
     shared_folders_cache="none"
   fi
 
+  if [ -z "$net" ] || [ "$net" == "user" ]; then
+    net_opts="user,hostfwd=tcp:127.0.0.1:$SSH-:22,hostfwd=udp:127.0.0.1:$XDMCP_PORT-:177$hostfwd"
+  elif [ "$net" == "tap" ]; then
+    # Thanks kvm-manager
+    tap="${VM}0"
+    # MAC address is derived from a hash of the host's name and the guest's name:
+    mac_address="$(printf "02:%s" "$(printf "%s\0%s" "$(hostname)" "${VM}" | sha256sum | sed 's/\(..\)/\1:/g' | cut -f1-5 -d:)")"
+    bridge="br0"
+    net_opts="tap,ifname=$tap,script=no,downscript=no,vlan=0,name=hostnet0"
+  fi
+
   # Run virtual machine
   # See https://en.wikipedia.org/wiki/Nohup#Overcoming_hanging
-  nohup kvm -m $memory -name $VM -drive file=$image,if=$drive_interface $graphics $shared \
+  nohup kvm -m $memory -name $VM \
+      -drive file=$image,if=$drive_interface $graphics $shared \
       -spice port=$PORT,addr=127.0.0.1,disable-ticketing,streaming-video=off,jpeg-wan-compression=never,playback-compression=off,zlib-glz-wan-compression=never,image-compression=off \
       -device virtio-serial-pci \
       -device virtserialport,chardev=spicechannel0,name=com.redhat.spice.0 \
@@ -382,7 +394,8 @@ function kvmx_up {
       -chardev "socket,id=serial0,path=$CONSOLEFILE,server" -device isa-serial,chardev=serial0 \
       -smp $smp -soundhw ac97 -cpu host -balloon virtio \
       -net nic,model=$nic_model \
-      -net user,hostfwd=tcp:127.0.0.1:$SSH-:22,hostfwd=udp:127.0.0.1:$XDMCP_PORT-:177$hostfwd $qemu_opts &> $LOGFILE < /dev/null &
+      -net $net_opts \
+      $qemu_opts &> $LOGFILE < /dev/null &
 
   PID="$!"
 
@@ -1384,8 +1397,7 @@ function kvmx_mv {
   kvmx_rename $*
 }
 
-# Interface to QEMU monitor
-# Thanks kvm-manager for the idea
+# Interface to QEMU monitor (thanks kvm-manager)
 function kvmx_monitor {
   if ! kvmx_running; then
     echo "$BASENAME: guest $VM is not running"