From d43c41fcaf061eaf8bff7bc03de19cdc80226796 Mon Sep 17 00:00:00 2001 From: Jörg Sommer Date: Fri, 9 Jun 2023 10:51:06 +0200 Subject: runqemu-ifupdown/get-tapdevs: Add support for ip tuntap MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The *ip* command supports the creation and destruction of TAP devices since 2009 and might be more likely installed on systems then *tunctl*. Therefore it should be tried to setup or teardown the TAP interface with *ip* before falling back to *tunctl*. https://git.kernel.org/pub/scm/network/iproute2/iproute2.git/commit/?id=580fbd88f75cc9eea0d28a48c025b090eb9419a7 (From OE-Core rev: 424ede206baae1c228583aab1df6c18513ac104f) Signed-off-by: Jörg Sommer Signed-off-by: Alexandre Belloni Signed-off-by: Richard Purdie --- scripts/runqemu-ifup | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) (limited to 'scripts/runqemu-ifup') diff --git a/scripts/runqemu-ifup b/scripts/runqemu-ifup index bb661740c5..5fdcddeeda 100755 --- a/scripts/runqemu-ifup +++ b/scripts/runqemu-ifup @@ -41,22 +41,29 @@ USERID="-u $1" GROUP="-g $2" STAGING_BINDIR_NATIVE=$3 -TUNCTL=$STAGING_BINDIR_NATIVE/tunctl -if [ ! -x "$TUNCTL" ]; then - echo "Error: Unable to find tunctl binary in '$STAGING_BINDIR_NATIVE', please bitbake qemu-helper-native" - exit 1 +if taps=$(ip tuntap list 2>/dev/null); then + tap_no=$(( $(echo "$taps" |sort -r |sed 's/^tap//; s/:.*//; q') + 1 )) + ip tuntap add tap$tap_no mode tap group $2 && TAP=tap$tap_no fi -TAP=`$TUNCTL -b $GROUP 2>&1` -STATUS=$? -if [ $STATUS -ne 0 ]; then -# If tunctl -g fails, try using tunctl -u, for older host kernels -# which do not support the TUNSETGROUP ioctl - TAP=`$TUNCTL -b $USERID 2>&1` +if [ -z $TAP ]; then + TUNCTL=$STAGING_BINDIR_NATIVE/tunctl + if [ ! -x "$TUNCTL" ]; then + echo "Error: Unable to find tunctl binary in '$STAGING_BINDIR_NATIVE', please bitbake qemu-helper-native" + exit 1 + fi + + TAP=`$TUNCTL -b $GROUP 2>&1` STATUS=$? if [ $STATUS -ne 0 ]; then - echo "tunctl failed:" - exit 1 + # If tunctl -g fails, try using tunctl -u, for older host kernels + # which do not support the TUNSETGROUP ioctl + TAP=`$TUNCTL -b $USERID 2>&1` + STATUS=$? + if [ $STATUS -ne 0 ]; then + echo "tunctl failed:" + exit 1 + fi fi fi -- cgit v1.2.3-54-g00ecf