diff options
Diffstat (limited to 'scripts/runqemu-ifdown')
-rwxr-xr-x | scripts/runqemu-ifdown | 54 |
1 files changed, 25 insertions, 29 deletions
diff --git a/scripts/runqemu-ifdown b/scripts/runqemu-ifdown index 2486968588..822a2a39b9 100755 --- a/scripts/runqemu-ifdown +++ b/scripts/runqemu-ifdown @@ -1,8 +1,7 @@ #!/bin/bash # # QEMU network configuration script to bring down tap devices. This -# utility needs to be run as root, and will use the tunctl binary -# from the native sysroot. +# utility needs to be run as root, and will use the ip utility # # If you find yourself calling this script a lot, you can add the # the following to your /etc/sudoers file to be able to run this @@ -13,21 +12,11 @@ # # Copyright (c) 2006-2011 Linux Foundation # -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License version 2 as -# published by the Free Software Foundation. +# SPDX-License-Identifier: GPL-2.0-only # -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License along -# with this program; if not, write to the Free Software Foundation, Inc., -# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. usage() { - echo "sudo $(basename $0) <tap-dev> <native-sysroot-basedir>" + echo "sudo $(basename $0) <tap-dev>" } if [ $EUID -ne 0 ]; then @@ -35,30 +24,31 @@ if [ $EUID -ne 0 ]; then exit 1 fi -if [ $# -ne 2 ]; then +if [ $# -gt 2 ] || [ $# -lt 1 ]; then usage exit 1 fi +# backward compatibility +if [ $# -eq 2 ] ; then + echo "Warning: native-sysroot-basedir parameter is ignored. It is no longer needed." >&2 +fi + TAP=$1 -STAGING_BINDIR_NATIVE=$2 -TUNCTL=$STAGING_BINDIR_NATIVE/tunctl -if [ ! -e "$TUNCTL" ]; then - echo "Error: Unable to find tunctl binary in '$STAGING_BINDIR_NATIVE', please bitbake qemu-helper-native" +if ! ip tuntap del $TAP mode tap 2>/dev/null; then + echo "Error: Unable to run up tuntap del" exit 1 fi -$TUNCTL -d $TAP - -IFCONFIG=`which ip 2> /dev/null` -if [ "x$IFCONFIG" = "x" ]; then +IPTOOL=`which ip 2> /dev/null` +if [ "x$IPTOOL" = "x" ]; then # better than nothing... - IFCONFIG=/sbin/ip + IPTOOL=/sbin/ip fi -if [ -x "$IFCONFIG" ]; then - if `$IFCONFIG link show $TAP > /dev/null 2>&1`; then - $IFCONFIG link del $TAP +if [ -x "$IPTOOL" ]; then + if `$IPTOOL link show $TAP > /dev/null 2>&1`; then + $IPTOOL link del $TAP fi fi # cleanup the remaining iptables rules @@ -70,7 +60,13 @@ if [ ! -x "$IPTABLES" ]; then echo "$IPTABLES cannot be executed" exit 1 fi -n=$[ (`echo $TAP | sed 's/tap//'` * 2) + 1 ] -dest=$[ (`echo $TAP | sed 's/tap//'` * 2) + 2 ] + +if [ -z "$OE_TAP_NAME" ]; then + OE_TAP_NAME=tap +fi + +n=$[ (`echo $TAP | sed "s/$OE_TAP_NAME//"` * 2) + 1 ] +dest=$[ (`echo $TAP | sed "s/$OE_TAP_NAME//"` * 2) + 2 ] $IPTABLES -D POSTROUTING -t nat -j MASQUERADE -s 192.168.7.$n/32 $IPTABLES -D POSTROUTING -t nat -j MASQUERADE -s 192.168.7.$dest/32 +true |