diff options
| author | Jörg Sommer <joerg.sommer@navimatix.de> | 2023-06-09 10:51:06 +0200 |
|---|---|---|
| committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2023-06-13 22:10:32 +0100 |
| commit | d43c41fcaf061eaf8bff7bc03de19cdc80226796 (patch) | |
| tree | 9ec2ccdcd0232adb6b4b055571f43dbc773822b3 /scripts | |
| parent | 177886950ea29fcc0496ebcfd7478d694dd72704 (diff) | |
| download | poky-d43c41fcaf061eaf8bff7bc03de19cdc80226796.tar.gz | |
runqemu-ifupdown/get-tapdevs: Add support for ip tuntap
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 <joerg.sommer@navimatix.de>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'scripts')
| -rwxr-xr-x | scripts/runqemu-gen-tapdevs | 26 | ||||
| -rwxr-xr-x | scripts/runqemu-ifdown | 14 | ||||
| -rwxr-xr-x | scripts/runqemu-ifup | 31 |
3 files changed, 44 insertions, 27 deletions
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 | |||
| 50 | exit 1 | 50 | exit 1 |
| 51 | fi | 51 | fi |
| 52 | 52 | ||
| 53 | TUNCTL=$STAGING_BINDIR_NATIVE/tunctl | ||
| 54 | if [[ ! -x "$TUNCTL" || -d "$TUNCTL" ]]; then | ||
| 55 | echo "Error: $TUNCTL is not an executable" | ||
| 56 | usage | ||
| 57 | fi | ||
| 58 | |||
| 59 | if [ $EUID -ne 0 ]; then | 53 | if [ $EUID -ne 0 ]; then |
| 60 | echo "Error: This script must be run with root privileges" | 54 | echo "Error: This script must be run with root privileges" |
| 61 | exit | 55 | exit |
| @@ -68,15 +62,29 @@ if [ ! -x "$RUNQEMU_IFUP" ]; then | |||
| 68 | exit 1 | 62 | exit 1 |
| 69 | fi | 63 | fi |
| 70 | 64 | ||
| 71 | if ! interfaces=`ip link` 2>/dev/null; then | 65 | TUNCTL=$STAGING_BINDIR_NATIVE/tunctl |
| 66 | ip_supports_tuntap=false | ||
| 67 | if interfaces=`ip tuntap list` 2>/dev/null; then | ||
| 68 | ip_supports_tuntap=true | ||
| 69 | interfaces=`echo "$interfaces |cut -f1 -d:` | ||
| 70 | elif [[ ! -x "$TUNCTL" || -d "$TUNCTL" ]]; then | ||
| 71 | echo "Error: $TUNCTL is not an executable" | ||
| 72 | usage | ||
| 73 | elif interfaces=`ip link` 2>/dev/null; then | ||
| 74 | interfaces=`echo "$interfaces" | sed '/^[0-9]\+: \(docker[0-9]\+\):.*/!d; s//\1/'` | ||
| 75 | else | ||
| 72 | echo "Failed to call 'ip link'" >&2 | 76 | echo "Failed to call 'ip link'" >&2 |
| 73 | exit 1 | 77 | exit 1 |
| 74 | fi | 78 | fi |
| 75 | 79 | ||
| 76 | # Ensure we start with a clean slate | 80 | # Ensure we start with a clean slate |
| 77 | for tap in `echo "$interfaces" | sed '/^[0-9]\+: \(docker[0-9]\+\):.*/!d; s//\1/'`; do | 81 | for tap in $interfaces; do |
| 78 | echo "Note: Destroying pre-existing tap interface $tap..." | 82 | echo "Note: Destroying pre-existing tap interface $tap..." |
| 79 | $TUNCTL -d $tap | 83 | if $ip_supports_tuntap; then |
| 84 | ip tuntap del $tap mode tap | ||
| 85 | else | ||
| 86 | $TUNCTL -d $tap | ||
| 87 | fi | ||
| 80 | done | 88 | done |
| 81 | rm -f /etc/runqemu-nosudo | 89 | rm -f /etc/runqemu-nosudo |
| 82 | 90 | ||
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 | |||
| 33 | TAP=$1 | 33 | TAP=$1 |
| 34 | STAGING_BINDIR_NATIVE=$2 | 34 | STAGING_BINDIR_NATIVE=$2 |
| 35 | 35 | ||
| 36 | TUNCTL=$STAGING_BINDIR_NATIVE/tunctl | 36 | if !ip tuntap del $TAP mode tap 2>/dev/null; then |
| 37 | if [ ! -e "$TUNCTL" ]; then | 37 | TUNCTL=$STAGING_BINDIR_NATIVE/tunctl |
| 38 | echo "Error: Unable to find tunctl binary in '$STAGING_BINDIR_NATIVE', please bitbake qemu-helper-native" | 38 | if [ ! -e "$TUNCTL" ]; then |
| 39 | exit 1 | 39 | echo "Error: Unable to find tunctl binary in '$STAGING_BINDIR_NATIVE', please bitbake qemu-helper-native" |
| 40 | fi | 40 | exit 1 |
| 41 | fi | ||
| 41 | 42 | ||
| 42 | $TUNCTL -d $TAP | 43 | $TUNCTL -d $TAP |
| 44 | fi | ||
| 43 | 45 | ||
| 44 | IFCONFIG=`which ip 2> /dev/null` | 46 | IFCONFIG=`which ip 2> /dev/null` |
| 45 | if [ "x$IFCONFIG" = "x" ]; then | 47 | 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" | |||
| 41 | GROUP="-g $2" | 41 | GROUP="-g $2" |
| 42 | STAGING_BINDIR_NATIVE=$3 | 42 | STAGING_BINDIR_NATIVE=$3 |
| 43 | 43 | ||
| 44 | TUNCTL=$STAGING_BINDIR_NATIVE/tunctl | 44 | if taps=$(ip tuntap list 2>/dev/null); then |
| 45 | if [ ! -x "$TUNCTL" ]; then | 45 | tap_no=$(( $(echo "$taps" |sort -r |sed 's/^tap//; s/:.*//; q') + 1 )) |
| 46 | echo "Error: Unable to find tunctl binary in '$STAGING_BINDIR_NATIVE', please bitbake qemu-helper-native" | 46 | ip tuntap add tap$tap_no mode tap group $2 && TAP=tap$tap_no |
| 47 | exit 1 | ||
| 48 | fi | 47 | fi |
| 49 | 48 | ||
| 50 | TAP=`$TUNCTL -b $GROUP 2>&1` | 49 | if [ -z $TAP ]; then |
| 51 | STATUS=$? | 50 | TUNCTL=$STAGING_BINDIR_NATIVE/tunctl |
| 52 | if [ $STATUS -ne 0 ]; then | 51 | if [ ! -x "$TUNCTL" ]; then |
| 53 | # If tunctl -g fails, try using tunctl -u, for older host kernels | 52 | echo "Error: Unable to find tunctl binary in '$STAGING_BINDIR_NATIVE', please bitbake qemu-helper-native" |
| 54 | # which do not support the TUNSETGROUP ioctl | 53 | exit 1 |
| 55 | TAP=`$TUNCTL -b $USERID 2>&1` | 54 | fi |
| 55 | |||
| 56 | TAP=`$TUNCTL -b $GROUP 2>&1` | ||
| 56 | STATUS=$? | 57 | STATUS=$? |
| 57 | if [ $STATUS -ne 0 ]; then | 58 | if [ $STATUS -ne 0 ]; then |
| 58 | echo "tunctl failed:" | 59 | # If tunctl -g fails, try using tunctl -u, for older host kernels |
| 59 | exit 1 | 60 | # which do not support the TUNSETGROUP ioctl |
| 61 | TAP=`$TUNCTL -b $USERID 2>&1` | ||
| 62 | STATUS=$? | ||
| 63 | if [ $STATUS -ne 0 ]; then | ||
| 64 | echo "tunctl failed:" | ||
| 65 | exit 1 | ||
| 66 | fi | ||
| 60 | fi | 67 | fi |
| 61 | fi | 68 | fi |
| 62 | 69 | ||
