Message ID | cc9a474aa35bc29c00dc7ed216f697a8ccbb0f6e.1686229638.git.joerg.sommer@navimatix.de (mailing list archive) |
---|---|
State | New |
Headers | show |
Series | runqemu-ifupdown: Add support for ip tuntap | expand |
On Thu, 2023-06-08 at 15:07 +0200, Jörg Sommer via lists.yoctoproject.org wrote: > 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(-) This does make me wonder if we could just drop tunctl now? We originally had this as ifconfig couldn't do what we needed and ip was comparatively rare on systems. Things have changed and moved on! Did the gen-tap-devs script also need updating? Also, this patch does need to go to the openembedded-core list as it is changing that repository which poky is built from. Cheers, Richard
@openembedded: I have proposed a patch to runqemu-ifup/down to use `ip tuntap` as an alternative to tunctl for setting up the tap interface. Now the question came up if tunctl could be fully dropped. On 8 June 2023 22:18, Richard Purdie wrote: > On Thu, 2023-06-08 at 15:07 +0200, Jörg Sommer via > lists.yoctoproject.org wrote: > > 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(-) > > This does make me wonder if we could just drop tunctl now? I think so. But do all systems support ip, now? If so, the part for ifconfig could be dropped. > We originally had this as ifconfig couldn't do what we needed and ip > was comparatively rare on systems. Things have changed and moved on! > > Did the gen-tap-devs script also need updating? Yeah, you're right. I forgot about it. > Also, this patch does need to go to the openembedded-core list as it is > changing that repository which poky is built from. Thanks for the pointing. Mit freundlichen Grüßen Jörg Sommer Software Developer / Programmierer -- Navimatix GmbH Tatzendpromenade 2 07745 Jena T: 03641 - 327 99 0 F: 03641 - 526 306 M: joerg.sommer@navimatix.de www.navimatix.de Geschäftsführer: Steffen Späthe, Jan Rommeley Registergericht: Amtsgericht Jena, HRB 501480
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
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(-)