Skip to content

mesh_remote: add external connection support for Unix socket meshes#3124

Open
jstarks wants to merge 4 commits intomicrosoft:mainfrom
jstarks:mesh-reconnect
Open

mesh_remote: add external connection support for Unix socket meshes#3124
jstarks wants to merge 4 commits intomicrosoft:mainfrom
jstarks:mesh-reconnect

Conversation

@jstarks
Copy link
Copy Markdown
Member

@jstarks jstarks commented Mar 24, 2026

Enable external processes to connect to a running mesh over a well-known Unix socket path. This is the transport foundation for allowing a CLI process needs to join an already-running VM's mesh at runtime.

Windows/ALPC support will come in a separate change.

Enable external processes to connect to a running mesh over a
well-known Unix socket path. This is the transport foundation for
allowing a CLI process needs to join an already-running VM's mesh at
runtime.

Windows/ALPC support will come in a separate change.
Copilot AI review requested due to automatic review settings March 24, 2026 23:37
@github-actions github-actions bot added the unsafe Related to unsafe code label Mar 24, 2026
@github-actions
Copy link
Copy Markdown

⚠️ Unsafe Code Detected

This PR modifies files containing unsafe Rust code. Extra scrutiny is required during review.

For more on why we check whole files, instead of just diffs, check out the Rustonomicon

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

Adds Unix-domain socket support to mesh_remote so external processes (e.g., a CLI) can connect to a running mesh via a well-known socket path, establishing a foundation for runtime “join an existing VM mesh” workflows (with Windows/ALPC planned separately).

Changes:

  • Introduces a generic MeshPayload-over-Unix-stream transport with SCM_RIGHTS fd passing (unix_payload).
  • Adds a Unix mesh listener/handshake layer to accept connections by path and hand out invitations (unix_listener).
  • Refactors SCM_RIGHTS send/recv helpers into a shared Unix module and tweaks UnixNode::invite error typing.

Reviewed changes

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

Show a summary per file
File Description
support/mesh/mesh_remote/src/unix_payload.rs New payload framing + fd transfer over Unix stream sockets; listener/connect helpers + tests
support/mesh/mesh_remote/src/unix_node.rs Extracts inviter handle and changes invite() error type; reuses shared SCM_RIGHTS helpers
support/mesh/mesh_remote/src/unix_listener.rs New Unix socket listener + handshake + join_by_path() API and end-to-end test
support/mesh/mesh_remote/src/unix_common.rs New shared unsafe SCM_RIGHTS send/recv implementation + tests
support/mesh/mesh_remote/src/lib.rs Wires new Unix modules and re-exports new Unix listener/join error types
support/mesh/mesh_remote/Cargo.toml Adds tempfile dev-dependency for new Unix tests
Cargo.lock Records tempfile dependency for mesh_remote dev builds

size_of_val(fds) measured OsResource elements (8 bytes each on 64-bit)
but the cmsg payload contains RawFd values (4 bytes each). This over-
reported cmsg_len, potentially causing the kernel to read extra zero-
valued fd entries from the buffer.
@jstarks jstarks marked this pull request as ready for review March 25, 2026 00:15
@jstarks jstarks requested a review from a team as a code owner March 25, 2026 00:15
Copilot AI review requested due to automatic review settings March 25, 2026 00:15
@jstarks jstarks changed the title mesh_remote: add Unix mesh listener and payload transport mesh_remote: add external connection support for Unix socket meshes Mar 25, 2026
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

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

// that was populated by recvmsg.
let raw_fds = unsafe { std::slice::from_raw_parts(data_ptr.cast::<RawFd>(), fd_count) };
fds.extend(raw_fds.iter().map(|&raw_fd| {
// SAFETY: per the kernel contract, this fd is now owned by the process.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

i'm trying to find the docs on this ownership change, where is it?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

doc'd

"control message truncated: sender sent too many file descriptors",
));
}
if hdr.msg_flags & libc::MSG_TRUNC != 0 {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

what error case is this one, that sendmsg the payload was too large?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

doc'd

}

#[cfg(test)]
mod tests {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

did you run these tests thru miri? does that give anything useful?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

miri can't handle scm_rights

- Merge unix_payload into unix_listener (single consumer, no need
  for a separate module)
- Replace manual header parsing with zerocopy PayloadHeader struct
- Replace PortResourceNotSupported error with unreachable!() (internal
  invariant, not a public API boundary)
- Tighten recv limits: 4 KiB data / 4 fds (only Invitation is sent,
  ~100 bytes + 1 fd)
- Improve comments: SCM_RIGHTS ownership docs, MSG_TRUNC explanation,
  module-level docs for unix_common and unix_listener
- Remove redundant test_send_recv_payload_with_fd (covered by
  test_end_to_end)
Copilot AI review requested due to automatic review settings March 27, 2026 00:37
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

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

unsafe Related to unsafe code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants