Configuring the development host's QEMU network

To get local connectivity with redirection, no networking changes on the host are needed. However, people usually want to use TAP-based networking, which does require changes. For one thing, TAP interfaces can be inspected with tools like wireshark, which makes for much easier debugging of network code.

In order to get QEMU networking to function, it is necessary to create TAP interfaces, and, optionally, to bridge them to real networks. A development machine typically will have several TAP interfaces, and more can be created. Generally, each developer should have a TAP interface of his or her own. Here we use newskysaw as an example.

To set up a TAP interface on newskysaw, the following command is used:

/root/util/tap_create tapX

When QEMU runs with a tap interface, it will use /etc/qemu-ifup to bring up the interface. /etc/qemu-ifup looks like this:

#!/bin/bash
echo "Executing /etc/qemu-ifup - no external bridging"
echo "Bringing up $1 for bridged mode..."
NET=`echo $1 | cut -dp -f2` 
sudo /sbin/ifconfig $1 172.2${NET}.0.1 up
sleep 2

The interface tap$N$ is brought up with the IP address 172.2$N$.0.1. ifconfig will also create a routing rule that sends 172.2$N$.0.1/16 traffic to tap$N$. The upshot is that if the code running in QEMU uses an IP address in this network (for example: 172.2$N$.0.2), you will be able to talk to it from newskysaw. For example, from newskysaw, if you ping 172.21.0.2, the packet (and ARP) will go out via tap1. The source address will appear to be 172.21.0.1. The QEMU machine will see these packets on its interface, and the software controlling its interface can respond to 172.21.0.1.

This form of networking is local to the machine. You can also bridge a TAP interface with a physical interface. The result of this is that a packet sent on it will be sent on the physical interface. To do this requires more effort (and is not set up by default on newskysaw). As an example, consider that on newskysaw, the physical interface eth1 is connected to a private network switch to which the lab test computers (v-test-amd, v-test-amd2, etc.) are connected. To bridge, for example, tap10, to this interface, you would do the following (with root's help):

  1. You need to bring up eth1 (ifconfig eth1 up address netmask mask). It is important that the address and mask you choose are appropriate for the network eth1 is connected to.
  2. You would bring up tap10 without an address: /sbin/ifconfig tap10 up
  3. You would bridge tap10 and eth1: /usr/sbin/brctl addif br0 tap10; /usr/sbin/brctl addif eth1. This assumes that br0 was previously created.

Bridging tap$N$ with eth1 will only work (where ``work'' means sending a packet on the network and making the packet visible on localhost) if the IP address in the code running in QEMU is set correctly. This means that it needs to be set to correspond to the network of eth1). For the newskysaw configuration, this is a 10-net address.



Subsections
Jack Lange 2010-04-13