aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorToni Uhlig <matzeton@googlemail.com>2020-10-01 18:10:11 +0200
committerToni Uhlig <matzeton@googlemail.com>2020-10-01 18:14:12 +0200
commitd77e45bd8fc6b85c7ee1b1dcc9f12d366e523742 (patch)
tree7f7b2ab469aedcb7f87dbc3217f5f6173bedb266
parent1cfb3174cf8b66185223846fc8a3ee104bcbf296 (diff)
Improved QEMU network interface mgmt.
* Removed C&P QEMU ifup script * Removed deprecated brctl usage * Set TAP device ifname, required to run multiple QEMU VMs Signed-off-by: Toni Uhlig <matzeton@googlemail.com>
-rw-r--r--Makefile17
-rwxr-xr-xscripts/qemu-ifup44
2 files changed, 10 insertions, 51 deletions
diff --git a/Makefile b/Makefile
index ee1fc43..a1a265e 100644
--- a/Makefile
+++ b/Makefile
@@ -1,5 +1,6 @@
ARCH=$(shell uname -m)
MEMORY ?= 128
+NET_QEMU_TAP ?= linux-qemu-test
NET_BRIDGE ?= br0
NET_HWADDR ?= 66:66:66:66:66:66
KEYMAP ?= i386/qwertz/de-latin1
@@ -167,9 +168,12 @@ image-repack:
$(DO_BUILD)
net:
- -sudo ip tuntap add linux-qemu-test mode tap
- -test -x /etc/qemu-ifup && sudo /etc/qemu-ifup linux-qemu-test
- -test -x /etc/qemu-ifup || sudo scripts/qemu-ifup linux-qemu-test
+ sudo ip tuntap add $(NET_QEMU_TAP) mode tap
+ sudo ip link set dev $(NET_QEMU_TAP) up
+ sudo ip link set dev $(NET_QEMU_TAP) master $(NET_BRIDGE)
+
+net-clean:
+ sudo ip link delete $(NET_QEMU_TAP)
qemu: image
qemu-system-$(ARCH) -kernel '$(LINUX_BUILD_DIR)/arch/$(ARCH)/boot/bzImage' -initrd '$(INITRD_TARGET)' -enable-kvm -m $(MEMORY) -vga qxl -display sdl -append 'keymap=$(KEYMAP)'
@@ -181,14 +185,12 @@ qemu-serial: image
qemu-system-$(ARCH) -kernel '$(LINUX_BUILD_DIR)/arch/$(ARCH)/boot/bzImage' -initrd '$(INITRD_TARGET)' -enable-kvm -m $(MEMORY) -nographic -append 'console=ttyS0 keymap=$(KEYMAP)'
qemu-serial-net: image
- brctl show $(NET_BRIDGE)
qemu-system-$(ARCH) -kernel '$(LINUX_BUILD_DIR)/arch/$(ARCH)/boot/bzImage' -initrd '$(INITRD_TARGET)' -enable-kvm -m $(MEMORY) -nographic \
- -net nic,macaddr=$(NET_HWADDR) -net tap,ifname=linux-qemu-test,br=$(NET_BRIDGE),script=no,downscript=no -append 'net console=ttyS0 keymap=$(KEYMAP)'
+ -net nic,macaddr=$(NET_HWADDR) -net tap,ifname=$(NET_QEMU_TAP),br=$(NET_BRIDGE),script=no,downscript=no -append 'net console=ttyS0 keymap=$(KEYMAP)'
qemu-net: image
- brctl show $(NET_BRIDGE)
qemu-system-$(ARCH) -kernel '$(LINUX_BUILD_DIR)/arch/$(ARCH)/boot/bzImage' -initrd '$(INITRD_TARGET)' -enable-kvm -m $(MEMORY) -vga qxl -display sdl \
- -net nic,macaddr=$(NET_HWADDR) -net tap,ifname=linux-qemu-test,br=$(NET_BRIDGE),script=no,downscript=no -append 'net keymap=$(KEYMAP)'
+ -net nic,macaddr=$(NET_HWADDR) -net tap,ifname=$(NET_QEMU_TAP),br=$(NET_BRIDGE),script=no,downscript=no -append 'net keymap=$(KEYMAP)'
define HELP_PREFIX
@printf '%*s%-10s - %s\n' '20' '$1' '' '$2'
@@ -219,6 +221,7 @@ help:
@echo -e '\tAdditional make options:'
$(call HELP_PREFIX_OPTS,NO_MODULES=$(NO_MODULES),neither build nor install kernel modules)
$(call HELP_PREFIX_OPTS,MEMORY=$(MEMORY),set the RAM size for QEMU in MBytes)
+ $(call HELP_PREFIX_OPTS,NET_QEMU_TAP=$(NET_QEMU_TAP),set the ifname which QEMU will use as TAP device (run `make net` before))
$(call HELP_PREFIX_OPTS,NET_BRIDGE=$(NET_BRIDGE),set your host network bridge interface)
$(call HELP_PREFIX_OPTS,NET_HWADDR=$(NET_HWADDR),set mac address for the qemu guest)
$(call HELP_PREFIX_OPTS,KEYMAP=$(KEYMAP),set a keymap which the init script tries to load)
diff --git a/scripts/qemu-ifup b/scripts/qemu-ifup
deleted file mode 100755
index e5e3858..0000000
--- a/scripts/qemu-ifup
+++ /dev/null
@@ -1,44 +0,0 @@
-#! /bin/sh
-# Script to bring a network (tap) device for qemu up.
-# The idea is to add the tap device to the same bridge
-# as we have default routing to.
-
-set -x
-
-# in order to be able to find brctl
-PATH=$PATH:/sbin:/usr/sbin
-ip=$(which ip)
-
-if [ -n "$ip" ]; then
- ip link set "$1" up
-else
- brctl=$(which brctl)
- if [ ! "$ip" -o ! "$brctl" ]; then
- echo "W: $0: not doing any bridge processing: neither ip nor brctl utility not found" >&2
- exit 0
- fi
- ifconfig "$1" 0.0.0.0 up
-fi
-
-switch=$(ip route ls | \
- awk '/^default / {
- for(i=0;i<NF;i++) { if ($i == "dev") { print $(i+1); next; } }
- }'
- )
-
-# only add the interface to default-route bridge if we
-# have such interface (with default route) and if that
-# interface is actually a bridge.
-# It is possible to have several default routes too
-for br in $switch; do
- if [ -d /sys/class/net/$br/bridge/. ]; then
- if [ -n "$ip" ]; then
- ip link set "$1" master "$br"
- else
- brctl addif $br "$1"
- fi
- exit # exit with status of the previous command
- fi
-done
-
-echo "W: $0: no bridge for guest interface found" >&2