qemu: Use a TAP device instead of slirp for networking
With this patch, a persistent TAP device is set up by poky-qemu-ifup, which is now run before qemu. The qemu command line now uses the device that was constructed (rather than the hard-coded tap0) and it is told not to run any networking scripts. When qemu shuts down, poky-qemu-ifdown removes the TAP device. sudo use - sudo is used to run poky-qemu-ifup. sudo is no longer used to run qemu, as qemu no longer needs privileges to set up networking. poky-qemu-ifdown is run without privileges, as you can remove a TAP device which you own. Signed-off-by: Jeff Dike <jdike@linux.intel.com>
This commit is contained in:
parent
b5b3825ce6
commit
c791544bb0
|
@ -17,11 +17,9 @@
|
||||||
# with this program; if not, write to the Free Software Foundation, Inc.,
|
# with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
|
||||||
|
TAP=$1
|
||||||
|
|
||||||
IFCONFIG=`which ifconfig`
|
TUNCTL=`which tunctl`
|
||||||
if [ "x$IFCONFIG" = "x" ]; then
|
[ "$TUNCTL" = "" ] && TUNCTL=/usr/sbin/tunctl
|
||||||
# better than nothing...
|
|
||||||
IFCONFIG=/sbin/ifconfig
|
|
||||||
fi
|
|
||||||
|
|
||||||
$IFCONFIG tap0 down
|
$TUNCTL -d $TAP
|
||||||
|
|
|
@ -17,6 +17,12 @@
|
||||||
# with this program; if not, write to the Free Software Foundation, Inc.,
|
# with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
|
||||||
|
USER=$1
|
||||||
|
|
||||||
|
TUNCTL=`which tunctl`
|
||||||
|
[ "$TUNCTL" = "" ] && TUNCTL=/usr/sbin/tunctl
|
||||||
|
|
||||||
|
TAP=`$TUNCTL -b -u $USER`
|
||||||
|
|
||||||
IFCONFIG=`which ifconfig`
|
IFCONFIG=`which ifconfig`
|
||||||
if [ "x$IFCONFIG" = "x" ]; then
|
if [ "x$IFCONFIG" = "x" ]; then
|
||||||
|
@ -24,7 +30,7 @@ if [ "x$IFCONFIG" = "x" ]; then
|
||||||
IFCONFIG=/sbin/ifconfig
|
IFCONFIG=/sbin/ifconfig
|
||||||
fi
|
fi
|
||||||
|
|
||||||
$IFCONFIG tap0 192.168.7.1
|
$IFCONFIG $TAP 192.168.7.1
|
||||||
|
|
||||||
# setup NAT for tap0 interface to have internet access in QEMU
|
# setup NAT for tap0 interface to have internet access in QEMU
|
||||||
IPTABLES=`which iptables`
|
IPTABLES=`which iptables`
|
||||||
|
@ -35,3 +41,5 @@ fi
|
||||||
$IPTABLES -A POSTROUTING -t nat -j MASQUERADE -s 192.168.7.0/24
|
$IPTABLES -A POSTROUTING -t nat -j MASQUERADE -s 192.168.7.0/24
|
||||||
echo 1 > /proc/sys/net/ipv4/ip_forward
|
echo 1 > /proc/sys/net/ipv4/ip_forward
|
||||||
$IPTABLES -P FORWARD ACCEPT
|
$IPTABLES -P FORWARD ACCEPT
|
||||||
|
|
||||||
|
echo $TAP
|
||||||
|
|
|
@ -53,8 +53,13 @@ fi
|
||||||
|
|
||||||
QEMUIFUP=`which poky-qemu-ifup`
|
QEMUIFUP=`which poky-qemu-ifup`
|
||||||
QEMUIFDOWN=`which poky-qemu-ifdown`
|
QEMUIFDOWN=`which poky-qemu-ifdown`
|
||||||
|
|
||||||
|
USER=`id -u`
|
||||||
|
echo 'Setting up tap interface under sudo'
|
||||||
|
TAP=`sudo $QEMUIFUP $USER`
|
||||||
|
|
||||||
KERNEL_NETWORK_CMD="ip=192.168.7.2::192.168.7.1:255.255.255.0"
|
KERNEL_NETWORK_CMD="ip=192.168.7.2::192.168.7.1:255.255.255.0"
|
||||||
QEMU_TAP_CMD="-net tap,vlan=0,ifname=tap0,script=$QEMUIFUP,downscript=$QEMUIFDOWN"
|
QEMU_TAP_CMD="-net tap,vlan=0,ifname=$TAP,script=no,downscript=no"
|
||||||
QEMU_NETWORK_CMD="-net nic,vlan=0 $QEMU_TAP_CMD"
|
QEMU_NETWORK_CMD="-net nic,vlan=0 $QEMU_TAP_CMD"
|
||||||
KERNCMDLINE="mem=$QEMU_MEMORY"
|
KERNCMDLINE="mem=$QEMU_MEMORY"
|
||||||
QEMU_UI_OPTIONS="-show-cursor -usb -usbdevice wacom-tablet"
|
QEMU_UI_OPTIONS="-show-cursor -usb -usbdevice wacom-tablet"
|
||||||
|
@ -298,9 +303,13 @@ else
|
||||||
echo "Warning: distccd not present, no distcc support loaded."
|
echo "Warning: distccd not present, no distcc support loaded."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "Running $QEMU using sudo..."
|
|
||||||
|
|
||||||
|
echo "Running $QEMU..."
|
||||||
echo $QEMUBIN -kernel $ZIMAGE $QEMUOPTIONS $SERIALOPTS $* --append "$KERNCMDLINE"
|
echo $QEMUBIN -kernel $ZIMAGE $QEMUOPTIONS $SERIALOPTS $* --append "$KERNCMDLINE"
|
||||||
sudo $QEMUBIN -kernel $ZIMAGE $QEMUOPTIONS $SERIALOPTS $* --append "$KERNCMDLINE" || /bin/true
|
$QEMUBIN -kernel $ZIMAGE $QEMUOPTIONS $SERIALOPTS $* --append "$KERNCMDLINE" || /bin/true
|
||||||
|
|
||||||
|
$QEMUIFDOWN $TAP
|
||||||
|
|
||||||
trap - INT TERM QUIT
|
trap - INT TERM QUIT
|
||||||
return
|
return
|
||||||
|
|
Loading…
Reference in New Issue