Skip to content

net_tap: change TapHandle from device name to pre-opened fd#3181

Open
jstarks wants to merge 3 commits intomicrosoft:mainfrom
jstarks:tap_handle_fd
Open

net_tap: change TapHandle from device name to pre-opened fd#3181
jstarks wants to merge 3 commits intomicrosoft:mainfrom
jstarks:tap_handle_fd

Conversation

@jstarks
Copy link
Copy Markdown
Member

@jstarks jstarks commented Apr 2, 2026

TapHandle in net_backend_resources carried a device name string and the resolver opened the TAP device. Change it to carry a pre-opened OwnedFd so the opener (openvmm_entry or a test harness) controls namespace and permission details. This resolves a long-standing TODO and enables fd passing from Kata and similar environments.

Also tighten both TapHandle and net_tap from cfg(unix) to cfg(target_os = "linux") since TAP uses Linux-specific /dev/net/tun ioctls.

@jstarks jstarks requested a review from a team as a code owner April 2, 2026 17:46
Copilot AI review requested due to automatic review settings April 2, 2026 17:46
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Moves TAP device opening out of the net_tap resolver and into the caller by changing TapHandle (in net_backend_resources) to carry a pre-opened OwnedFd, enabling more control over namespaces/permissions and supporting fd passing scenarios. It also tightens TAP-related code from cfg(unix) to Linux-only since TAP relies on Linux /dev/net/tun ioctls.

Changes:

  • Change TapHandle from device name (String) to a pre-opened OwnedFd, and update the TAP resolver to use it directly.
  • Move TAP opening to openvmm_entry (CLI and ttrpc/grpc paths) so the entrypoint controls how the fd is obtained.
  • Restrict net_tap and TAP resources to target_os = "linux" and update dependencies accordingly.

Reviewed changes

Copilot reviewed 7 out of 8 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
vm/devices/net/net_tap/src/resolver.rs Stop opening TAP by name; construct Tap from the fd in TapHandle.
vm/devices/net/net_tap/src/lib.rs Make the crate Linux-only (cfg(target_os = "linux")).
vm/devices/net/net_tap/Cargo.toml Switch target-specific deps/dev-deps from cfg(unix) to Linux-only.
vm/devices/net/net_backend_resources/src/lib.rs Change TapHandle to carry OwnedFd; gate the tap module to Linux.
openvmm/openvmm_entry/src/ttrpc/mod.rs Open TAP in the entrypoint for ttrpc/grpc NIC configs and pass fd via TapHandle.
openvmm/openvmm_entry/src/lib.rs Open TAP in CLI parsing on Linux; produce a clear error on non-Linux.
openvmm/openvmm_entry/Cargo.toml Add net_tap dependency only on Linux.
Cargo.lock Lockfile updated to include net_tap as a dependency of openvmm_entry.

Copy link
Copy Markdown
Member

@chris-oo chris-oo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks reasonable to me, but do we need the tap filename as part of the context, or is it part of the upper chained context?

jstarks added 3 commits April 3, 2026 16:06
TapHandle in net_backend_resources carried a device name string and
the resolver opened the TAP device. Change it to carry a pre-opened
OwnedFd so the opener (openvmm_entry or a test harness) controls
namespace and permission details. This resolves a long-standing TODO
and enables fd passing from Kata and similar environments.

Also tighten both TapHandle and net_tap from cfg(unix) to
cfg(target_os = "linux") since TAP uses Linux-specific /dev/net/tun
ioctls.
@jstarks
Copy link
Copy Markdown
Member Author

jstarks commented Apr 3, 2026

Added the context to the errors.

@jstarks jstarks enabled auto-merge (squash) April 3, 2026 16:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants