diff options
Diffstat (limited to 'scripts/runqemu-ifdown')
| -rwxr-xr-x | scripts/runqemu-ifdown | 42 |
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 | ||
| 19 | usage() { | 18 | usage() { |
| 20 | echo "sudo $(basename $0) <tap-dev> <native-sysroot-basedir>" | 19 | echo "sudo $(basename $0) <tap-dev>" |
| 21 | } | 20 | } |
| 22 | 21 | ||
| 23 | if [ $EUID -ne 0 ]; then | 22 | if [ $EUID -ne 0 ]; then |
| @@ -25,30 +24,31 @@ if [ $EUID -ne 0 ]; then | |||
| 25 | exit 1 | 24 | exit 1 |
| 26 | fi | 25 | fi |
| 27 | 26 | ||
| 28 | if [ $# -ne 2 ]; then | 27 | if [ $# -gt 2 ] || [ $# -lt 1 ]; then |
| 29 | usage | 28 | usage |
| 30 | exit 1 | 29 | exit 1 |
| 31 | fi | 30 | fi |
| 32 | 31 | ||
| 32 | # backward compatibility | ||
| 33 | if [ $# -eq 2 ] ; then | ||
| 34 | echo "Warning: native-sysroot-basedir parameter is ignored. It is no longer needed." >&2 | ||
| 35 | fi | ||
| 36 | |||
| 33 | TAP=$1 | 37 | TAP=$1 |
| 34 | STAGING_BINDIR_NATIVE=$2 | ||
| 35 | 38 | ||
| 36 | TUNCTL=$STAGING_BINDIR_NATIVE/tunctl | 39 | if ! ip tuntap del $TAP mode tap 2>/dev/null; then |
| 37 | if [ ! -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 |
| 40 | fi | 42 | fi |
| 41 | 43 | ||
| 42 | $TUNCTL -d $TAP | 44 | IPTOOL=`which ip 2> /dev/null` |
| 43 | 45 | if [ "x$IPTOOL" = "x" ]; then | |
| 44 | IFCONFIG=`which ip 2> /dev/null` | ||
| 45 | if [ "x$IFCONFIG" = "x" ]; then | ||
| 46 | # better than nothing... | 46 | # better than nothing... |
| 47 | IFCONFIG=/sbin/ip | 47 | IPTOOL=/sbin/ip |
| 48 | fi | 48 | fi |
| 49 | if [ -x "$IFCONFIG" ]; then | 49 | if [ -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 |
| 53 | fi | 53 | fi |
| 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 |
| 62 | fi | 62 | fi |
| 63 | n=$[ (`echo $TAP | sed 's/tap//'` * 2) + 1 ] | 63 | |
| 64 | dest=$[ (`echo $TAP | sed 's/tap//'` * 2) + 2 ] | 64 | if [ -z "$OE_TAP_NAME" ]; then |
| 65 | OE_TAP_NAME=tap | ||
| 66 | fi | ||
| 67 | |||
| 68 | n=$[ (`echo $TAP | sed "s/$OE_TAP_NAME//"` * 2) + 1 ] | ||
| 69 | dest=$[ (`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 |
| 72 | true | ||
