Open
Description
Tracking issue for feature(unix_socket_ancillary_data)
to extend UnixStream
and UnixDatagram
to send and receive ancillary data. For example file descriptors.
Unresolved Questions
- Review the
SocketAncillary
struct before stabilization to ensure it is compatible with all OSes. fuchsia
,haiku
,illumos
,ios
,macos
andsolaris
does not haveMSG_CMSG_CLOEXEC
constant inlibc
fuchsia
anduclibc
(x86_64
) does not havecmsghdr
struct inlibc
- The current version of rust
libc
does not haveucred
struct for the target OSemscripten
, butemscripten
has this struct in the standard C library
Known bugs/issues
Implementation history
- unix: Extend UnixStream and UnixDatagram to send and receive file descriptors #69864
- unix: Non-mutable bufs in send_vectored_with_ancillary_to #82589
- unix: Fix feature(unix_socket_ancillary_data) on macos and other BSDs #83374
- Add types for inspecting control messages in Unix socket ancillary data #117196
Metadata
Metadata
Assignees
Labels
Area: `std::io`, `std::fs`, `std::net` and `std::path`Category: An issue tracking the progress of sth. like the implementation of an RFC`#![feature(unix_socket_ancillary_data)]`Libs issues that are tracked on the team's project board.Operating system: Unix-likeRelevant to the library API team, which will review and decide on the PR/issue.
Type
Projects
Milestone
Relationships
Development
No branches or pull requests
Activity
tadeokondrak commentedon Feb 25, 2021
send_vectored_with_ancillary
should switch to non-mutable references for its parameters, sincesendmsg
doesn't write through them.#79753 changes just the
bufs
parameter, but it was closed for inactivity.(Edit: Hmm, actually changing the ancillary data too would require both a SocketAncillary and SocketAncillaryMut, like IoSlice. Probably not worth it there)
LinkTed commentedon Feb 27, 2021
@tadeokondrak I open a new PR #82589.
LinkTed commentedon Mar 7, 2021
I create a new PR to send and receive TTL for UdpSocket from the ancillary interface. #82858
reyk commentedon Mar 26, 2021
Hi @LinkTed, I posted a fix in #83374 for macOS, OpenBSD, and possibly other BSDs.
Rollup merge of rust-lang#83374 - reyk:fix/bsd-ancillary, r=joshtriplett
LinkTed commentedon Apr 4, 2021
What has to be done to stabilize this API?
the8472 commentedon Apr 15, 2021
I think the API still needs polish. All those niche socket features are tricky and right now it's probably not extensible enough for 3rd party libraries to fill platform-specific gaps such as flags or cmsgs only supported on one particular OS. These basically are wrappers for the
recvmsg
andsndmsg
syscalls, we should expose them in a way that's forwards-compatible so we don't have to addrecv_vectored_with_ancillary_from_with_flags
or something like that in the future.Before stabilizing we should consider whether
recv_vectored_with_ancillary_from
should gain another argument. I would recommend adding aReceiveOptions
argument that allows one to specify flags, similar toOpenOptions
. The options could then be used to set linux'MSG_DONTWAIT
,MSG_PEEK
orMSG_ERRQUEUE
for example, maybe viacustom_flags()
similar toOpenOptions
. That way we don't have to support all OS-specific peculiarities.Or we could put the flags into
SocketAncillary
or at least reserve the right to do that in the future, but in that case the struct would need to be renamed because it would serve several purposes at once.Similar could be done for sending.
Additionally the
AncillaryData
enum should be marked as#[non_exhaustive]
and maybe gain aUnknown
variant for things that the standard library doesn't support. And a way to get the raw ancillary message. That way one could for example decodestruct sock_extended_err
in a 3rd party crate without waiting for std to implement it.LinkTed commentedon Apr 17, 2021
@the8472 Thank you for your feedback. If this PR request is #82858 merged I will start implementing your suggestions.
93 remaining items
jmillikin commentedon Oct 26, 2023
The RFC looks like it's moving now (tagged
libs-api-nominated
) so I've started work on the implementation of non-contentious parts.Unix{Datagram,Stream}::{set_}passcred()
to per-OS traits #117156 is a change that needs to happen anyway, moving OS-specific socket methods to extension traits.ControlMessage{s,Iter,Buf}
for constructing and inspecting the control messages buffer used by ancillary data.purplesyringa commentedon Jan 3, 2024
As far as I can see, the current implementation is unsound: it takes a user-provided buffer and performs unaligned reads and writes. Is this a known issue?
Rewrite suspicious code around ancillary data
GrahamBarnett commentedon Apr 26, 2024
this allows us to work on an existing ancillary buffer or re-use a SocketAncillary on different read buffers if we want, and as a by-product makes testing a lot easier
and:
this allows us to println!("{:?}", ancillary.messages()) which makes logging/ debugging a lot easier.
It also means that you can debug the SocketAncillary struct itself (and get buffer status), or can show messages themselves as needed.
Many thanks
andrewbaxter commentedon May 4, 2024
My use case is I don't know exactly where in a stream ancillary data will appear - I'd like to use several reads to parse a message and aggregate ancillary data across them (in a single buffer) to be used at the end. It doesn't appear trivially possible with the current design.
GrahamBarnett commentedon May 4, 2024
MaxVerevkin commentedon Sep 16, 2024
Wouldn't it be better for
SocketAncillary
'sadd_creds
andadd_fds
to return aResult<(), NotEnoughSpaceErrror>
instead of a bool?jonleivent commentedon Sep 17, 2024
Would it be better for
SocketAncillary::new
to take aMaybeUninit
buffer? I assume that the original buffer should not be read from after callingSocketAncillary::new
. Also, this saves the initialization expense.the8472 commentedon Sep 17, 2024
at least sending it requires zero-initialization anyway.
jonleivent commentedon Sep 17, 2024
Is that the responsibility of the caller of, or of
SocketAncillary::new
itself? Because if this is a safety concern, how do you enforce it on the caller? Wouldn't a common mistake be to re-use the buffer for subsequentSocketAncillary::new
calls without resetting its contents?septatrix commentedon Sep 28, 2024
I see that it currently only includes
SO_PASSCRED
. What is the reason for that, is support for the other socket options also planned? It seems a bit arbitrary to only support one option but not the others (which are also frequently used)