From: "Jörg Sommer" <joerg.sommer@navimatix.de>
To: poky@lists.yoctoproject.org
Cc: "Jörg Sommer" <joerg.sommer@navimatix.de>
Subject: [PATCH] runqemu-ifupdown: Add support for ip tuntap
Date: Thu, 8 Jun 2023 15:07:18 +0200 [thread overview]
Message-ID: <cc9a474aa35bc29c00dc7ed216f697a8ccbb0f6e.1686229638.git.joerg.sommer@navimatix.de> (raw)
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
Signed-off-by: Jörg Sommer <joerg.sommer@navimatix.de>
---
scripts/runqemu-ifdown | 14 ++++++++------
scripts/runqemu-ifup | 31 +++++++++++++++++++------------
2 files changed, 27 insertions(+), 18 deletions(-)
diff --git a/scripts/runqemu-ifdown b/scripts/runqemu-ifdown
index e0eb5344c6..f72166b32b 100755
--- a/scripts/runqemu-ifdown
+++ b/scripts/runqemu-ifdown
@@ -33,13 +33,15 @@ 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"
- exit 1
-fi
+if !ip tuntap del $TAP mode tap 2>/dev/null; then
+ 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"
+ exit 1
+ fi
-$TUNCTL -d $TAP
+ $TUNCTL -d $TAP
+fi
IFCONFIG=`which ip 2> /dev/null`
if [ "x$IFCONFIG" = "x" ]; then
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
--
2.34.1
next reply other threads:[~2023-06-08 13:08 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-06-08 13:07 Jörg Sommer [this message]
2023-06-08 20:18 ` [poky] [PATCH] runqemu-ifupdown: Add support for ip tuntap Richard Purdie
2023-06-09 7:30 ` Jörg Sommer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=cc9a474aa35bc29c00dc7ed216f697a8ccbb0f6e.1686229638.git.joerg.sommer@navimatix.de \
--to=joerg.sommer@navimatix.de \
--cc=poky@lists.yoctoproject.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).