mbox series

[0/9] fixes for runqemu-gen-tapdevs

Message ID 20230622170946.10082-1-adrian.freihofer@siemens.com
Headers show
Series fixes for runqemu-gen-tapdevs | expand

Message

Adrian Freihofer June 22, 2023, 5:01 p.m. UTC
At least on my machine recent the changes related to the tap interface
setup for Qemu broke even more than already discussed e.g. here:
https://lists.openembedded.org/g/openembedded-core/message/183176
These patches should fix and improve the related scripts:
- First interface is now tap1 with IP address 192.168.7.3. Go back to
  tap0 with IP 192.168.7.1.
- Rather than looping over all tap interfaces which are available on a
  machine, handle only interfaces with a name like tap*. (I need my VPN.)
- New feature: Make the tap interface names configurable at least for
  the basic runqemu use case.
- Cleanup unused parameters and variables. Scripts are supposed to be
  backward compatible. They print warnings for deprecated parameters.

I did not yet run the self tests, but I tested it like that:

Without these patches:
The tap interfaces get created with index 1 instead of 0. Also the ip starts at 3 instead of 1.
This breaks probably several things which use the well known 7.2 IP.

$ sudo -E ./scripts/runqemu-gen-tapdevs 1000 1000 0 $BUILDDIR/tmp/sysroots-components/x86_64/qemu-helper-native/usr/bin
$ ip l
#OK no tap interfaces
$ sudo -E ./scripts/runqemu-gen-tapdevs 1000 1000 2 $BUILDDIR/tmp/sysroots-components/x86_64/qemu-helper-native/usr/bin
Creating 2 tap devices for UID: 1000 GID: 1000...
Creating tap0
Creating tap1

$ ip l
80: tap1: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc fq_codel state DOWN mode DEFAULT group default qlen 1000
    link/ether 36:74:1b:fa:be:df brd ff:ff:ff:ff:ff:ff
81: tap2: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc fq_codel state DOWN mode DEFAULT group default qlen 1000
    link/ether e2:49:ac:ff:cf:0f brd ff:ff:ff:ff:ff:ff
$ ip address show dev tap1
80: tap1: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc fq_codel state DOWN group default qlen 1000
    link/ether 36:74:1b:fa:be:df brd ff:ff:ff:ff:ff:ff
    inet 192.168.7.3/32 brd 192.168.7.255 scope global tap1
       valid_lft forever preferred_lft forever
# Bug: Why not tap0? Also the first IP is now 192.168.7.3 instead of 192.168.7.1

With these patches:

$ sudo -E ./scripts/runqemu-gen-tapdevs 1000 1000 0 $BUILDDIR/tmp/sysroots-components/x86_64/qemu-helper-native/usr/bin
Warning: Ignoring the <native-sysroot-basedir> parameter. It is no longer needed.
Warning: Ignoring the <uid> parameter. It is no longer needed.
Note: Destroying pre-existing tap interface tap0...
Note: Destroying pre-existing tap interface tap1...
$ ip l
#OK no tap interfaces

$ sudo -E ./scripts/runqemu-gen-tapdevs 1000 1000 2 $BUILDDIR/tmp/sysroots-components/x86_64/qemu-helper-native/usr/bin
Warning: Ignoring the <native-sysroot-basedir> parameter. It is no longer needed.
Warning: Ignoring the <uid> parameter. It is no longer needed.
Creating 2 tap devices for GID: 1000...
Creating tap0
Creating tap1
$ ip a
84: tap0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc fq_codel state DOWN group default qlen 1000
    link/ether 1e:d7:db:93:1d:dc brd ff:ff:ff:ff:ff:ff
    inet 192.168.7.1/32 brd 192.168.7.255 scope global tap0
       valid_lft forever preferred_lft forever
85: tap1: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc fq_codel state DOWN group default qlen 1000
    link/ether 36:74:1b:fa:be:df brd ff:ff:ff:ff:ff:ff
    inet 192.168.7.3/32 brd 192.168.7.255 scope global tap1
       valid_lft forever preferred_lft forever
#OK: fixed start index of tap


Without these patches the scripts try to delete other tap interfaces asa well:

$ sudo ip tuntap add foo-tap mode tap group 1000
sudo -E ./scripts/runqemu-gen-tapdevs 1000 1000 0 $BUILDDIR/tmp/sysroots-components/x86_64/qemu-helper-native/usr/bin
Note: Destroying pre-existing tap interface tap0...
Note: Destroying pre-existing tap interface tap1...
--> Note: Destroying pre-existing tap interface foo-tap...

With these patches this is fixed:

$ sudo -E ./scripts/runqemu-gen-tapdevs 1000 2
Creating 2 tap devices for GID: 1000...
Creating tap0
Creating tap1
$ sudo ip tuntap add foo-tap mode tap group 1000
$ ip l
89: foo-tap: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN mode DEFAULT group default qlen 1000
    link/ether 8a:93:d3:4f:0d:ae brd ff:ff:ff:ff:ff:ff
90: tap0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc fq_codel state DOWN mode DEFAULT group default qlen 1000
    link/ether 1e:d7:db:93:1d:dc brd ff:ff:ff:ff:ff:ff
91: tap1: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc fq_codel state DOWN mode DEFAULT group default qlen 1000
    link/ether 36:74:1b:fa:be:df brd ff:ff:ff:ff:ff:ff
$ sudo -E ./scripts/runqemu-gen-tapdevs 1000 0
Note: Destroying pre-existing tap interface tap0...
Note: Destroying pre-existing tap interface tap1...

ip l
89: foo-tap: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN mode DEFAULT group default qlen 1000
    link/ether 8a:93:d3:4f:0d:ae brd ff:ff:ff:ff:ff:ff


New feature: OE_TAP_NAME variable allows to rename the tap

export OE_TAP_NAME=tap-yocto-
$ sudo -E ./scripts/runqemu-gen-tapdevs 1000 2
Creating 2 tap devices for GID: 1000...
Creating tap-yocto-0
Creating tap-yocto-1
Note: For systems running NetworkManager, it's recommended
Note: that the tap devices be set as unmanaged in the
Note: NetworkManager.conf file. Add the following lines to
Note: /etc/NetworkManager/NetworkManager.conf
[keyfile]
unmanaged-devices=interface-name:tap-yocto-*
$ ip a
92: tap-yocto-0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc fq_codel state DOWN group default qlen 1000
    link/ether f2:9c:14:41:b1:e3 brd ff:ff:ff:ff:ff:ff
    inet 192.168.7.1/32 brd 192.168.7.255 scope global tap-yocto-0
       valid_lft forever preferred_lft forever
93: tap-yocto-1: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc fq_codel state DOWN group default qlen 1000
    link/ether 06:08:16:73:be:48 brd ff:ff:ff:ff:ff:ff
    inet 192.168.7.3/32 brd 192.168.7.255 scope global tap-yocto-1
       valid_lft forever preferred_lft forever

runqemu serialstdio
...
runqemu - INFO - Using preconfigured tap device tap-yocto-0
runqemu - INFO - If this is not intended, touch /tmp/qemu-tap-locks/tap-yocto-0.skip to make runqemu skip tap-yocto-0.
runqemu - INFO - Network configuration: ip=192.168.7.2::192.168.7.1:255.255.255.0::eth0:off:8.8.8.8
...



Adrian Freihofer (9):
  runqemu-ifup: remove uid parameter
  runqemu-ifup: configurable tap names
  runqemu-ifup: fix tap index
  runqemu-ifup: remove only our taps
  runqemu-gen-tapdevs: remove staging dir parameter
  runqemu-gen-tapdevs: remove uid parameter
  runqemu-gen-tapdevs: configurable tap names
  runqemu-gen-tapdevs: remove only our taps
  runqemu: configurable tap names

 scripts/runqemu             |  8 +++++--
 scripts/runqemu-gen-tapdevs | 45 ++++++++++++++++++++++---------------
 scripts/runqemu-ifup        | 30 +++++++++++++++++--------
 3 files changed, 54 insertions(+), 29 deletions(-)

Comments

Richard Purdie June 24, 2023, 11:25 a.m. UTC | #1
On Thu, 2023-06-22 at 19:01 +0200, Adrian Freihofer wrote:
> At least on my machine recent the changes related to the tap interface
> setup for Qemu broke even more than already discussed e.g. here:
> https://lists.openembedded.org/g/openembedded-core/message/183176
> These patches should fix and improve the related scripts:
> - First interface is now tap1 with IP address 192.168.7.3. Go back to
>   tap0 with IP 192.168.7.1.
> - Rather than looping over all tap interfaces which are available on a
>   machine, handle only interfaces with a name like tap*. (I need my VPN.)
> - New feature: Make the tap interface names configurable at least for
>   the basic runqemu use case.
> - Cleanup unused parameters and variables. Scripts are supposed to be
>   backward compatible. They print warnings for deprecated parameters.

I had the right intentions with the direction of these improvements but
not my best patches, thanks for fixing up a few things and taking the
cleanups further! I'd wondered what had happened to tap0.

Cheers,

Richard