Description
Proposal
Problem statement
The current unstable support for Unix socket ancillary data (feature unix_socket_ancillary_data
) has several known issues and cannot be stabilized in its current form (see comments by @m-ou-se on rust-lang/rust#76915).
@m-ou-se suggested that there needs to be an RFC for Unix socket API ancillary data, which I've started a draft of at rust-lang/rfcs#3430 (rendered).
On Zulip, @pitaj suggested that filing an ACP might also be appropriate.
Motivating examples or use cases
I would like to be able to transfer file descriptors via SCM_RIGHTS
ancillary data on platforms that support that functionality (Linux, *BSD, most Unix-ish).
I would also like to be able to obtain platform-specific socket metadata such as Linux's high-resolution packet timestamps.
Solution sketch
The linked RFC 3430 (rendered) contains a draft API for representing ancillary data, including file descriptor ownership and extension points so that third-party libraries can provide platform-specific logic.
I have a local branch that implements that RFC's proposed API. Once the RFC seems to be moving towards stability, I'll add docs + tests to my branch and push it to provide better context as we work out the implementation details.
Alternatives
- Do nothing, keep the current perma-unstable API until a better solution can be designed.
- Remove ancillary data support from stdlib and leave it to third-party libraries such as https://github.com/nix-rust/nix.
- Instead of providing a high-level API, expose more of the underlying BSD sockets API (
CMSG_*
macros and friends) and let third-party libraries provide wrappers. - Expose simple functions for
SCM_RIGHTS
only, analogous to Python'ssocket.send_fds()
andsocket.recv_fds()
functions.
None of these are particularly appealing to me, though if anyone does have ideas on an even better API then I'd be happy to see it.
Links and related work
- Tracking Issue for feature(unix_socket_ancillary_data) rust#76915 (tracking issue for
unix_socket_ancillary_data
) - unix: Extend UnixStream and UnixDatagram to send and receive file descriptors rust#69864 (original implementation PR for
unix_socket_ancillary_data
feature) - Tracking Issue for feature(unix_socket_peek) rust#76923 (a related feature
unix_socket_peek
that this API would subsume) - https://blog.cloudflare.com/know-your-scm_rights/ a blog post about
SCM_RIGHTS
in C, Go, and Rust (vialibc
). - https://go.googlesource.com/sys/+/v0.13.0/unix/creds_test.go (tests for ancillary data support in Go stdlib)
What happens now?
This issue contains an API change proposal (or ACP) and is part of the libs-api team feature lifecycle. Once this issue is filed, the libs-api team will review open proposals as capability becomes available. Current response times do not have a clear estimate, but may be up to several months.
Possible responses
The libs team may respond in various different ways. First, the team will consider the problem (this doesn't require any concrete solution or alternatives to have been proposed):
- We think this problem seems worth solving, and the standard library might be the right place to solve it.
- We think that this probably doesn't belong in the standard library.
Second, if there's a concrete solution:
- We think this specific solution looks roughly right, approved, you or someone else should implement this. (Further review will still happen on the subsequent implementation PR.)
- We're not sure this is the right solution, and the alternatives or other materials don't give us enough information to be sure about that. Here are some questions we have that aren't answered, or rough ideas about alternatives we'd want to see discussed.