Skip to content

Add support for missing TUN/TAP parameters from Linux kernel #1066

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 28, 2025

Conversation

vanytsvetkov
Copy link
Contributor

Hey folks! This PR fixes TUN/TAP implementation to handle several kernel parameters we've been missing. No rocket science – just closing gaps with well-known features.

What's changed

  1. New field in Tuntap struct

    • Added DisabledQueues to track inactive multiqueue slots (critical for live migration in VMs).
  2. Now parsing kernel flags

    • IFLA_TUN_PI → sets TUNTAP_NO_PI (for "raw" packet mode)
    • IFLA_TUN_VNET_HDR → sets TUNTAP_VNET_HDR (QEMU/virtio needs this)
    • IFLA_TUN_MULTI_QUEUE support
    • Reads actual queue counts from IFLA_TUN_NUM_QUEUES/DISABLED_QUEUES

Why this is needed

  • We were dropping important settings: Before this, flags like VNET_HDR or multiqueue configs got silently ignored.
  • Kernel compatibility: These parameters exist since Linux 3.8 (2012!) but our code never acknowledged them.
  • Real-world impact:
    • Cloud setups need DisabledQueues for VM migrations
    • MULTI_QUEUE matters for anyone using DPDK/VPP for fast packet processing

How I tested

  • Ran on real 5.10+ kernels with:
    ✓ 4 active + 2 disabled queues
    VNET_HDR flag (matching QEMU's requirements)
    ✓ Legacy configs (verified old behavior stays intact)

Notes for review

  • Zero breakage:
    • New fields start as 0 (backward-safe)
    • Older kernels without these attributes work normally
  • Matches Linux tooling: Logic aligns with iproute2's implementation (see here) – we're not inventing wheels.

Signed-off-by: Ivan Tsvetkov ivanfromearth@gmail.com

@aboch
Copy link
Collaborator

aboch commented Mar 26, 2025

Is it possible to test this in an existing or a new UT function?

Signed-off-by: Ivan Tsvetkov <ivanfromearth@gmail.com>
Introduce AddQueues and RemoveQueues methods for attaching and detaching
queue file descriptors to an existing TUN/TAP interface in multi-queue mode.
This enables controlled testing of disabled queues and fine-grained queue
management without relying on interface recreation.

Signed-off-by: Ivan Tsvetkov <ivanfromearth@gmail.com>
@vanytsvetkov
Copy link
Contributor Author

Hi @aboch,

Yes — the changes are now covered by both extended and new unit tests.

Specifically:

  • The TestLinkAddDelTuntapMq test was extended to verify correct parsing and round-tripping of the new fields (Flags, Queues, DisabledQueues).
  • A new unit test, TestTuntapPartialQueues, was added to demonstrate that we can correctly observe the actual runtime state of TAP queues by manually attaching and closing queue file descriptors. This validates that the updated parsing logic reflects the live kernel-reported values.

That said, due to time constraints I didn't implement a native test that programmatically triggers non-zero DisabledQueues. However, I can confirm that in our production system, the patch correctly reflects the number of disabled queues — for instance, when connecting a TAP interface with 20 queues to a VM with 16 vCPUs, we consistently observe DisabledQueues == 4.

Let me know if any adjustments are needed — happy to follow up.

Best regards,
Ivan

@aboch
Copy link
Collaborator

aboch commented Mar 28, 2025

The two commits are more or less independent.

LGTM

@aboch aboch merged commit 14e2f0a into vishvananda:main Mar 28, 2025
4 of 6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants