From d6433056607ba01af94df996822d900b3b31abe7 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: e448f9b292aba2bf344a69f32d62b107c18993e9) Signed-off-by: Jörg Sommer Signed-off-by: Alexandre Belloni (cherry picked from commit 424ede206baae1c228583aab1df6c18513ac104f) Signed-off-by: Steve Sakoman --- scripts/runqemu-gen-tapdevs | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) (limited to 'scripts/runqemu-gen-tapdevs') diff --git a/scripts/runqemu-gen-tapdevs b/scripts/runqemu-gen-tapdevs index f2d6cc39c2..ffb82adce6 100755 --- a/scripts/runqemu-gen-tapdevs +++ b/scripts/runqemu-gen-tapdevs @@ -50,12 +50,6 @@ if ! [ $COUNT -ge 0 ]; then exit 1 fi -TUNCTL=$STAGING_BINDIR_NATIVE/tunctl -if [[ ! -x "$TUNCTL" || -d "$TUNCTL" ]]; then - echo "Error: $TUNCTL is not an executable" - usage -fi - if [ $EUID -ne 0 ]; then echo "Error: This script must be run with root privileges" exit @@ -68,15 +62,29 @@ if [ ! -x "$RUNQEMU_IFUP" ]; then exit 1 fi -if ! interfaces=`ip link` 2>/dev/null; then +TUNCTL=$STAGING_BINDIR_NATIVE/tunctl +ip_supports_tuntap=false +if interfaces=`ip tuntap list` 2>/dev/null; then + ip_supports_tuntap=true + interfaces=`echo "$interfaces |cut -f1 -d:` +elif [[ ! -x "$TUNCTL" || -d "$TUNCTL" ]]; then + echo "Error: $TUNCTL is not an executable" + usage +elif interfaces=`ip link` 2>/dev/null; then + interfaces=`echo "$interfaces" | sed '/^[0-9]\+: \(docker[0-9]\+\):.*/!d; s//\1/'` +else echo "Failed to call 'ip link'" >&2 exit 1 fi # Ensure we start with a clean slate -for tap in `echo "$interfaces" | sed '/^[0-9]\+: \(docker[0-9]\+\):.*/!d; s//\1/'`; do +for tap in $interfaces; do echo "Note: Destroying pre-existing tap interface $tap..." - $TUNCTL -d $tap + if $ip_supports_tuntap; then + ip tuntap del $tap mode tap + else + $TUNCTL -d $tap + fi done rm -f /etc/runqemu-nosudo -- cgit v1.2.3-54-g00ecf