Bug 7887

Summary: Add support for user networking to runqemu
Product: [Build System, Metadata & Runtime] OE-Core Reporter: Randy Witt <randy.e.witt>
Component: Scripts and ToolsAssignee: Robert Yang <liezhi.yang>
Status: RESOLVED FIXED QA Contact:
Severity: enhancement    
Priority: High CC: adrian.freihofer, alex.kanavin, brian.avery, liezhi.yang, richard.purdie, ross.burton, sgw
Version: 1.8   
Target Milestone: 2.3 M2   
Hardware: x86   
OS: Multiple   
Whiteboard:
OS type for building Yocto: --- Type of Regression: ---
Verified: Documentation change: Yes (doc changes required)
Bug Depends on: 4827    
Bug Blocks: 10713    
Attachments:
Description Flags
qemu user mode networking iperf benchmark none

Description Randy Witt 2015-06-12 20:16:20 UTC
By default runqemu assumes that the user has a tap device set up, or that it will be able to create a tap device for networking. In some cases however, it would be useful to instead use the "-net user" mode of qemu, pick the ports to forward, and not specify an ip address(so the internal qemu dhcp server will be used).

An example that demonstrates this is that dns name resolution using the default 8.8.8.8 will not work in the typical tap setup due to a lack of route to that address.

The argument to qemu could be something like "runqemu -net user[,hostporttoforward:guestport]..."

Then instead of using a tap device the arguments to qemu for networking would use -net user with the "hostfwd" option forwarding both tcp and udp.
Comment 1 Alexander Kanavin 2015-06-15 09:14:17 UTC
Yes,please. For example in intranet environemnts the 8.8.8.8 DNS is not reachable, so IP works, but no names get resolved - which is quite baffling experience.
Comment 2 Richard Purdie 2015-06-18 15:04:41 UTC
Whilst there are some use cases which would improve, I'm not sure user mode networking is going to give a good experience overall, having to manually specify ports for example will not improve the user experience.

Having this as a commandline option is probably fine but I don't think its a high priority or should be the default. Cristi believes there are other networking solutions which may be better and will discuss those in a separate bug which may then better determine this one.
Comment 3 Ross Burton 2015-06-19 12:44:04 UTC
Personally speaking if user-mode networking gave me flawless connectivity (ie proper routing the external networks, working DNS, etc), I'm happy to pay the cost of a performance hit (performance isn't critical), non-working ICMP (a minor problem) and the need to open ports explicitly (runqemu can open SSH by default).

I guess others may feel differently so choice is good.
Comment 4 Cristian Iorga 2015-07-20 17:58:49 UTC
Created attachment 2597 [details]
qemu user mode networking iperf benchmark

Qemu user mode networking iperf benchmark
Comment 5 Cristian Iorga 2015-07-20 17:59:38 UTC
Tested qemu user mode networking using iperf:
Comment 6 Cristian Iorga 2015-07-20 18:00:22 UTC
iperf -s
------------------------------------------------------------
Server listening on TCP port 5001
TCP window size: 85.3 KByte (default)
------------------------------------------------------------
[  4] local 10.237.105.63 port 5001 connected with 10.237.105.63 port 56186
[ ID] Interval       Transfer     Bandwidth
[  4]  0.0-10.0 sec   923 MBytes   774 Mbits/sec


See attachment for details.
Comment 7 Cristian Iorga 2015-07-20 18:19:09 UTC
The networking that are of interest to our project are:

1. TUN/TAP
2. Bridge
3. user mode networking

Let's discuss them a little bit:

1. TUN/TAP is now the mode in use by default with runqemu. However, due to the use of TUN/TAP, it does not easily offer: proper DHCP setup, pre-provisioned DNS server setup, access to internet (only qemu host can be accessed via network). It also requires sudo access.

2. Bridge mode is similar with TUN/TAP, however, a proper bonding between a physical Ethernet interface and qemu VM network interface is used (a network bridge). Setup is more complex, and it exposes the VM to the entire network, which may nor desirable and, in some intranets, not even allowed.  It also requires sudo access. This mode should be the most transparent one.

3. User mode networking is similar to what a home router does: NAT, routing to the outside world (Internet), DNS setup, DHCP server provided. Similar to a router, it does not offer access from the outside world (in this case, qemu host) to the qemu VM directly, but via port redirects (from the qemu host to qemu VM), but same sane defaults can be configured (SSH access, web server, Samba, FTP) and documented accordingly.
User mode networking is actually SLIRP networking that is provided by runqemu.
Only the port redirect is not implemented at this point, but that should be fairly easy and easily controllable from a test setup. Performance is good, as proven by my test. Another advantage is that it does not need sudo rights. The setup is almost non-existent (only port redirects). It's not clear to me at this point if network virtio acceleration is available, but performance is quite good even without virtio acceleration.
Comment 8 Richard Purdie 2015-07-23 09:01:17 UTC
(In reply to comment #7)
> The networking that are of interest to our project are:
> 
> 1. TUN/TAP
> 2. Bridge
> 3. user mode networking
> 
> Let's discuss them a little bit:
> 
> 1. TUN/TAP is now the mode in use by default with runqemu. However, due to
> the use of TUN/TAP, it does not easily offer: proper DHCP setup,
> pre-provisioned DNS server setup, access to internet (only qemu host can be
> accessed via network). It also requires sudo access.

To be clear, on a network without proxies, this setup does offer access to the internet. It only fails in a proxy environment as we don't have a good way of pushing the right DNS servers and proxy setup into the guest.

On possible way of mitigating this may be to have a command which ssh's into the guest and pushes the right proxy config and DNS setup into it for use in network constrained environments. Ugly but would resolve some of the current issues.

> 2. Bridge mode is similar with TUN/TAP, however, a proper bonding between a
> physical Ethernet interface and qemu VM network interface is used (a network
> bridge). Setup is more complex, and it exposes the VM to the entire network,
> which may nor desirable and, in some intranets, not even allowed.  It also
> requires sudo access. This mode should be the most transparent one.

This one is probably the least preferred from a security standpoint and also its requires the most invasive root privileges.

> 3. User mode networking is similar to what a home router does: NAT, routing
> to the outside world (Internet), DNS setup, DHCP server provided. Similar to
> a router, it does not offer access from the outside world (in this case,
> qemu host) to the qemu VM directly, but via port redirects (from the qemu
> host to qemu VM), but same sane defaults can be configured (SSH access, web
> server, Samba, FTP) and documented accordingly.
> User mode networking is actually SLIRP networking that is provided by
> runqemu.
> Only the port redirect is not implemented at this point, but that should be
> fairly easy and easily controllable from a test setup. Performance is good,
> as proven by my test. Another advantage is that it does not need sudo
> rights. The setup is almost non-existent (only port redirects). It's not
> clear to me at this point if network virtio acceleration is available, but
> performance is quite good even without virtio acceleration.

Cristi mentioned that DNS is also not working in SLIRP mode. I can see some value in improving that mode as you mention and documenting the setup. Exactly how you support multiple qemus running and know which set of ports to connect to to get to which guest could be a challenge, or this mode will only support one qemu at a time.

I believe WR originally added this mode so it may also be worth talking to the people who added it originally and see if they have any plans or thoughts on how they'd like to see it extended?
Comment 9 Cristian Iorga 2015-07-23 09:08:17 UTC
In SLIRP (user) mode, the network in qemu machine is setup up by activating the IP PNP part of the Linux kernel (via ip=dhcp kernel parameter). While this will setup the network interface via DHCP, it will not setup proper DNS resolving (kernel not allowed to write to files). The above will happen for images that don't rely on connman for network setup (core-image-minimal and others).
Comment 10 Cristian Iorga 2015-07-23 09:25:38 UTC
At this moment, the state of qemu user mode networking is ok, so this will be re-analysed in time for M3.
Comment 11 Cristian Iorga 2015-07-23 09:27:12 UTC
qemu user mode can be activated via slirp option of runqemu.
Comment 12 Cristian Iorga 2015-07-23 09:27:36 UTC
Port redirection is not yet implemented.
Comment 13 Adrian 2015-11-17 22:17:58 UTC
Support for bridged mode would be beneficial as well. I sent a patchset which adds support for hostonly networking mode. hostonly mode can be considered as a first step towards bridged mode. It can be considered as an enabler to implement bridged mode without any need to change files in the poky folder.
The patchset provides all the changes which have to be applied on the poky folder (runqemu scripts). Further improvements like setting up a bridge on the host, running a DHCP/DNS server on the bridge or whatever users need can be implemented in a script located outside of the poky folder. The script might be implemented as a wrapper for runqemu-gen-tapdevs.

Here is the thread on the mailing list:
http://lists.openembedded.org/pipermail/openembedded-core/2015-November/112823.html
Comment 14 Cristian Iorga 2015-11-18 17:02:42 UTC
Postponed due to technical limitations of the SLIRP mode.
Comment 15 Ross Burton 2016-02-11 11:59:03 UTC
*** Bug 8762 has been marked as a duplicate of this bug. ***
Comment 16 Robert Yang 2016-09-15 04:19:31 UTC
runqemu slirp works well now, also add help info for slirp mode.

Merged into master:
http://git.yoctoproject.org/cgit/cgit.cgi/poky/commit/?id=b405712414de98cba3a645601419aceb32d52f02
Comment 17 Randy Witt 2016-11-23 23:13:12 UTC
Although you can specify QB_SLIRP_OPT in the configuration, most of the machines do not have the device in the configuration. So specify slirp on runqemu, ends up with no network device other than lo.

The other issue is that there is no way to specify the ports that are forwarded when using slirp from what I can tell.
Comment 18 Randy Witt 2016-11-28 20:13:23 UTC
I submitted a patch to add slirp support to all qemu machines available in oe-core. https://patchwork.openembedded.org/patch/134399/
Comment 19 brian avery 2017-01-19 21:37:23 UTC
M2 looms. Patch 2 no longer applies cleanly due to some lines moving a bit.  Robert, can you redo/resend and I'll try to stay on top of getting it in?
Comment 20 Ross Burton 2017-01-19 23:40:05 UTC
I think all of this is now in ross/mut2.  Someone doublechecking would be appreciated!
Comment 21 brian avery 2017-01-26 16:33:24 UTC
merged into master
commit be60ae52f2871b84db8cdc96f8ac18c09892104a
+2 previous and 
commit dcaeaf2df160163319a05f5ae23e4ada6b64ca4e
+1 previous and 
commit 28ef841440bbd27fcf89b1f73a8c5f8e5591d30a