summaryrefslogtreecommitdiffstats
path: root/scripts/runqemu-ifdown
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/runqemu-ifdown')
-rwxr-xr-xscripts/runqemu-ifdown42
1 files changed, 24 insertions, 18 deletions
diff --git a/scripts/runqemu-ifdown b/scripts/runqemu-ifdown
index a104c37bf8..822a2a39b9 100755
--- a/scripts/runqemu-ifdown
+++ b/scripts/runqemu-ifdown
@@ -1,8 +1,7 @@
1#!/bin/bash 1#!/bin/bash
2# 2#
3# QEMU network configuration script to bring down tap devices. This 3# QEMU network configuration script to bring down tap devices. This
4# utility needs to be run as root, and will use the tunctl binary 4# utility needs to be run as root, and will use the ip utility
5# from the native sysroot.
6# 5#
7# If you find yourself calling this script a lot, you can add the 6# If you find yourself calling this script a lot, you can add the
8# the following to your /etc/sudoers file to be able to run this 7# the following to your /etc/sudoers file to be able to run this
@@ -17,7 +16,7 @@
17# 16#
18 17
19usage() { 18usage() {
20 echo "sudo $(basename $0) <tap-dev> <native-sysroot-basedir>" 19 echo "sudo $(basename $0) <tap-dev>"
21} 20}
22 21
23if [ $EUID -ne 0 ]; then 22if [ $EUID -ne 0 ]; then
@@ -25,30 +24,31 @@ if [ $EUID -ne 0 ]; then
25 exit 1 24 exit 1
26fi 25fi
27 26
28if [ $# -ne 2 ]; then 27if [ $# -gt 2 ] || [ $# -lt 1 ]; then
29 usage 28 usage
30 exit 1 29 exit 1
31fi 30fi
32 31
32# backward compatibility
33if [ $# -eq 2 ] ; then
34 echo "Warning: native-sysroot-basedir parameter is ignored. It is no longer needed." >&2
35fi
36
33TAP=$1 37TAP=$1
34STAGING_BINDIR_NATIVE=$2
35 38
36TUNCTL=$STAGING_BINDIR_NATIVE/tunctl 39if ! ip tuntap del $TAP mode tap 2>/dev/null; then
37if [ ! -e "$TUNCTL" ]; then 40 echo "Error: Unable to run up tuntap del"
38 echo "Error: Unable to find tunctl binary in '$STAGING_BINDIR_NATIVE', please bitbake qemu-helper-native"
39 exit 1 41 exit 1
40fi 42fi
41 43
42$TUNCTL -d $TAP 44IPTOOL=`which ip 2> /dev/null`
43 45if [ "x$IPTOOL" = "x" ]; then
44IFCONFIG=`which ip 2> /dev/null`
45if [ "x$IFCONFIG" = "x" ]; then
46 # better than nothing... 46 # better than nothing...
47 IFCONFIG=/sbin/ip 47 IPTOOL=/sbin/ip
48fi 48fi
49if [ -x "$IFCONFIG" ]; then 49if [ -x "$IPTOOL" ]; then
50 if `$IFCONFIG link show $TAP > /dev/null 2>&1`; then 50 if `$IPTOOL link show $TAP > /dev/null 2>&1`; then
51 $IFCONFIG link del $TAP 51 $IPTOOL link del $TAP
52 fi 52 fi
53fi 53fi
54# cleanup the remaining iptables rules 54# cleanup the remaining iptables rules
@@ -60,7 +60,13 @@ if [ ! -x "$IPTABLES" ]; then
60 echo "$IPTABLES cannot be executed" 60 echo "$IPTABLES cannot be executed"
61 exit 1 61 exit 1
62fi 62fi
63n=$[ (`echo $TAP | sed 's/tap//'` * 2) + 1 ] 63
64dest=$[ (`echo $TAP | sed 's/tap//'` * 2) + 2 ] 64if [ -z "$OE_TAP_NAME" ]; then
65 OE_TAP_NAME=tap
66fi
67
68n=$[ (`echo $TAP | sed "s/$OE_TAP_NAME//"` * 2) + 1 ]
69dest=$[ (`echo $TAP | sed "s/$OE_TAP_NAME//"` * 2) + 2 ]
65$IPTABLES -D POSTROUTING -t nat -j MASQUERADE -s 192.168.7.$n/32 70$IPTABLES -D POSTROUTING -t nat -j MASQUERADE -s 192.168.7.$n/32
66$IPTABLES -D POSTROUTING -t nat -j MASQUERADE -s 192.168.7.$dest/32 71$IPTABLES -D POSTROUTING -t nat -j MASQUERADE -s 192.168.7.$dest/32
72true