Skip to contentSkip to conversation

runqemu: add user mode (SLIRP) support to x86 QEMU targets

PATCH In review Todor Minchev 2 participants 2 messages Oct 26, 2016 – Nov 24, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 runqemu: add user mode (SLIRP) support to x86 QEMU targets

Using 'slirp' as a command line option to runqemu will start QEMU with user mode networking instead of creating tun/tap devices. SLIRP does not require root access. By default port 2222 on the host will be mapped to port 22 in the guest. The default port mapping can be overwritten with the QB_SLIRP_OPT variable e.g.

QB_SLIRP_OPT = "-net nic,model=e1000 -net user,hostfwd=tcp::2222-:22"

---
 meta/conf/machine/include/qemuboot-x86.inc | 1 +
 scripts/runqemu                            | 3 ++-
 2 files changed, 3 insertions(+), 1 deletion(-)
meta/conf/machine/include/qemuboot-x86.inc +1 -0
index 06ac983..0870294 100644
@@ -13,3 +13,4 @@ QB_AUDIO_OPT = "-soundhw ac97,es1370"
 QB_KERNEL_CMDLINE_APPEND = "vga=0 uvesafb.mode_option=640x480-32 oprofile.timer=1 uvesafb.task_timeout=-1"
 # Add the 'virtio-rng-pci' device otherwise the guest may run out of entropy
 QB_OPT_APPEND = "-vga vmware -show-cursor -usb -usbdevice tablet -device virtio-rng-pci"
+QB_SLIRP_OPT = "-net nic,model=e1000 -net user,hostfwd=tcp::2222-:22"
scripts/runqemu +2 -1
index dbe17ab..6952f32 100755
@@ -542,7 +542,8 @@ class BaseConfig(object):
     def check_and_set(self):
         """Check configs sanity and set when needed"""
         self.validate_paths()
-        check_tun()
+        if not self.slirp_enabled:
+            check_tun()
         # Check audio
         if self.audio_enabled:
             if not self.get('QB_AUDIO_DRV'):
Signature · 1 line
2.10.1
#1 lore raw

Hi Todor,

Quoted 19 lines · Todor Minchev

Using 'slirp' as a command line option to runqemu will start QEMU with user mode networking instead of creating tun/tap devices. SLIRP does not require root access. By default port 2222 on the host will be mapped to port 22 in the guest. The default port mapping can be overwritten with the QB_SLIRP_OPT variable e.g.

QB_SLIRP_OPT = "-net nic,model=e1000 -net user,hostfwd=tcp::2222-:22"

---
 meta/conf/machine/include/qemuboot-x86.inc | 1 +
 scripts/runqemu                            | 3 ++-
 2 files changed, 3 insertions(+), 1 deletion(-)
meta/conf/machine/include/qemuboot-x86.inc +0 -0
index 06ac983..0870294 100644

meta/conf/machine/include/qemuboot-x86.inc QB_AUDIO_OPT = "-soundhw ac97,es1370" · line 16

Quoted 4 lines
meta/conf/machine/include/qemuboot-x86.inc +1 -0
@@ -13,3 +13,4 @@ QB_AUDIO_OPT = "-soundhw ac97,es1370"
 QB_KERNEL_CMDLINE_APPEND = "vga=0 uvesafb.mode_option=640x480-32 oprofile.timer=1 uvesafb.task_timeout=-1"
 # Add the 'virtio-rng-pci' device otherwise the guest may run out of entropy
 QB_OPT_APPEND = "-vga vmware -show-cursor -usb -usbdevice tablet -device virtio-rng-pci"
+QB_SLIRP_OPT = "-net nic,model=e1000 -net user,hostfwd=tcp::2222-:22"

It will causes errors when multiple qemus are running:

qemu-system-x86_64: -net user,hostfwd=tcp::2222-:22: could not set up host forwarding rule 'tcp::2222-:22'
qemu-system-x86_64: -net user,hostfwd=tcp::2222-:22: Device 'user' could not be initialized

This because the port are used by another qemu. I will move these code into runqemu, and check whether the port is available, add 1 if not until find a usable port. Default to forward 22, and user can add other ports.

// Robert

Quoted 15 lines
scripts/runqemu +2 -1
index dbe17ab..6952f32 100755
@@ -542,7 +542,8 @@ class BaseConfig(object):
     def check_and_set(self):
         """Check configs sanity and set when needed"""
         self.validate_paths()
-        check_tun()
+        if not self.slirp_enabled:
+            check_tun()
         # Check audio
         if self.audio_enabled:
             if not self.get('QB_AUDIO_DRV'):