-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Tracking Issue for abstract namespaces in Unix domain sockets #85410
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
Comments
Add abstract namespace support for Unix domain sockets Hello! The other day I wanted to mess around with UDS in Rust and found that abstract namespaces ([unix(7)](https://man7.org/linux/man-pages/man7/unix.7.html)) on Linux still needed development. I took the approach of adding `_addr` specific public functions to reduce conflicts. Feature name: `unix_socket_abstract` Tracking issue: rust-lang#85410 Further context: rust-lang#42048 ## Non-platform specific additions `UnixListener::bind_addr(&SocketAddr) -> Result<UnixListener>` `UnixStream::connect_addr(&SocketAddr) -> Result<()>` `UnixDatagram::bind_addr(&SocketAddr) -> Result<UnixDatagram>` `UnixDatagram::connect_addr(&SocketAddr) -> Result<()>` `UnixDatagram::send_to_addr(&self, &[u8], &SocketAddr) -> Result<usize>` ## Platform-specific (Linux) additions `SocketAddr::from_abstract_namespace(&[u8]) -> SocketAddr` `SockerAddr::as_abstract_namespace() -> Option<&[u8]>` ## Example ```rust #![feature(unix_socket_abstract)] use std::os::unix::net::{UnixListener, SocketAddr}; fn main() -> std::io::Result<()> { let addr = SocketAddr::from_abstract_namespace(b"namespace")?; // Linux only let listener = match UnixListener::bind_addr(&addr) { Ok(sock) => sock, Err(err) => { println!("Couldn't bind: {:?}", err); return Err(err); } }; Ok(()) } ``` ## Further Details The main inspiration for the implementation came from the [nix-rust](https://github.com/nix-rust/nix/blob/master/src/sys/socket/addr.rs#L558) crate but there are also other [historical](rust-lang@c4db068) [attempts](https://github.com/tormol/uds/blob/master/src/addr.rs#L324) with similar approaches. A comment I did have was with this change, we now allow a `SocketAddr` to be constructed explicitly rather than just used almost as a handle for the return of `peer_addr` and `local_addr`. We could consider adding other explicit constructors (e.g. `SocketAddr::from_pathname`, `SockerAddr::from_unnamed`). Cheers!
…tt,GuillaumeGomez Add abstract namespace support for Unix domain sockets Hello! The other day I wanted to mess around with UDS in Rust and found that abstract namespaces ([unix(7)](https://man7.org/linux/man-pages/man7/unix.7.html)) on Linux still needed development. I took the approach of adding `_addr` specific public functions to reduce conflicts. Feature name: `unix_socket_abstract` Tracking issue: rust-lang#85410 Further context: rust-lang#42048 ## Non-platform specific additions `UnixListener::bind_addr(&SocketAddr) -> Result<UnixListener>` `UnixStream::connect_addr(&SocketAddr) -> Result<()>` `UnixDatagram::bind_addr(&SocketAddr) -> Result<UnixDatagram>` `UnixDatagram::connect_addr(&SocketAddr) -> Result<()>` `UnixDatagram::send_to_addr(&self, &[u8], &SocketAddr) -> Result<usize>` ## Platform-specific (Linux) additions `SocketAddr::from_abstract_namespace(&[u8]) -> SocketAddr` `SockerAddr::as_abstract_namespace() -> Option<&[u8]>` ## Example ```rust #![feature(unix_socket_abstract)] use std::os::unix::net::{UnixListener, SocketAddr}; fn main() -> std::io::Result<()> { let addr = SocketAddr::from_abstract_namespace(b"namespace")?; // Linux only let listener = match UnixListener::bind_addr(&addr) { Ok(sock) => sock, Err(err) => { println!("Couldn't bind: {:?}", err); return Err(err); } }; Ok(()) } ``` ## Further Details The main inspiration for the implementation came from the [nix-rust](https://github.com/nix-rust/nix/blob/master/src/sys/socket/addr.rs#L558) crate but there are also other [historical](rust-lang@c4db068) [attempts](https://github.com/tormol/uds/blob/master/src/addr.rs#L324) with similar approaches. A comment I did have was with this change, we now allow a `SocketAddr` to be constructed explicitly rather than just used almost as a handle for the return of `peer_addr` and `local_addr`. We could consider adding other explicit constructors (e.g. `SocketAddr::from_pathname`, `SockerAddr::from_unnamed`). Cheers!
Add abstract namespace support for Unix domain sockets Hello! The other day I wanted to mess around with UDS in Rust and found that abstract namespaces ([unix(7)](https://man7.org/linux/man-pages/man7/unix.7.html)) on Linux still needed development. I took the approach of adding `_addr` specific public functions to reduce conflicts. Feature name: `unix_socket_abstract` Tracking issue: rust-lang#85410 Further context: rust-lang#42048 ## Non-platform specific additions `UnixListener::bind_addr(&SocketAddr) -> Result<UnixListener>` `UnixStream::connect_addr(&SocketAddr) -> Result<()>` `UnixDatagram::bind_addr(&SocketAddr) -> Result<UnixDatagram>` `UnixDatagram::connect_addr(&SocketAddr) -> Result<()>` `UnixDatagram::send_to_addr(&self, &[u8], &SocketAddr) -> Result<usize>` ## Platform-specific (Linux) additions `SocketAddr::from_abstract_namespace(&[u8]) -> SocketAddr` `SockerAddr::as_abstract_namespace() -> Option<&[u8]>` ## Example ```rust #![feature(unix_socket_abstract)] use std::os::unix::net::{UnixListener, SocketAddr}; fn main() -> std::io::Result<()> { let addr = SocketAddr::from_abstract_namespace(b"namespace")?; // Linux only let listener = match UnixListener::bind_addr(&addr) { Ok(sock) => sock, Err(err) => { println!("Couldn't bind: {:?}", err); return Err(err); } }; Ok(()) } ``` ## Further Details The main inspiration for the implementation came from the [nix-rust](https://github.com/nix-rust/nix/blob/master/src/sys/socket/addr.rs#L558) crate but there are also other [historical](rust-lang@c4db068) [attempts](https://github.com/tormol/uds/blob/master/src/addr.rs#L324) with similar approaches. A comment I did have was with this change, we now allow a `SocketAddr` to be constructed explicitly rather than just used almost as a handle for the return of `peer_addr` and `local_addr`. We could consider adding other explicit constructors (e.g. `SocketAddr::from_pathname`, `SockerAddr::from_unnamed`). Cheers!
Is there anything else that needs to be done? 🤔 Seems like the PR from the first message has been already merged, so isn't it time for the FCP? :) Also it seems kinda strange that there's no assignees in this issue. |
Hi @mdaverde , Thank you so much for taking care of this. I am already using the API added on #85379 for AccessKit and I haven't encountered any issue so far. @joshtriplett you were the one reviewing the PR. Isn't it time for the FCP now? |
If I understand #76915 (comment) correctly then the methods on |
Following up on this and this is my first time engaging with the Rust community so forgive me if I make any careless mistakes. If I understand correctly this proposal needs to move to a final commenting period (FCP) until the feature reaches stabilization. Is there anything I can do to contribute and help carry this feature forward? This is a feature is important to myself as well as most folks coming to Rust looking for support for Linux userspace feature implementation in a language other than C. Thank you for your consideration. |
A remaining issue is that the methods are in the wrong place, they need to be moved to the os::linux module since they're linux specific and not available on other unixes. |
Thank you for the context. I'll see if I can't make a contribution to move them to the Linux specific module. Do you know if there are any other outstanding items that would need to be addressed before this can move to FCP? |
I'm also interested in seeing this feature stabilized, and made an attempt at moving the API into |
Team member @joshtriplett has proposed to merge this. The next step is review by the rest of the tagged team members: Concerns:
Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! See this document for info about what commands tagged team members can give me. |
…dr, r=joshtriplett Move `unix_socket_abstract` feature API to `SocketAddrExt`. The pre-stabilized API for abstract socket addresses exposes methods on `SocketAddr` that are only enabled for `cfg(any(target_os = "android", target_os = "linux"))`. Per discussion in <rust-lang#85410>, moving these methods to an OS-specific extension trait is required before stabilization can be considered. This PR makes four changes: 1. The internal module `std::os::net` contains logic for the unstable feature `tcp_quickack` (rust-lang#96256). I moved that code into `linux_ext/tcp.rs` and tried to adjust the module tree so it could accommodate a second unstable feature there. 2. Moves the public API out of `impl SocketAddr`, into `impl SocketAddrExt for SocketAddr` (the headline change). 3. The existing function names and docs for `unix_socket_abstract` refer to addresses as being created from abstract namespaces, but a more accurate description is that they create sockets in *the* abstract namespace. I adjusted the function signatures correspondingly and tried to update the docs to be clearer. 4. I also tweaked `from_abstract_name` so it takes an `AsRef<[u8]>` instead of `&[u8]`, allowing `b""` literals to be passed directly. Issues: 1. The public module `std::os::linux::net` is marked as part of `tcp_quickack`. I couldn't figure out how to mark a module as being part of two unstable features, so I just left the existing attributes in place. My hope is that this will be fixed as a side-effect of stabilizing either feature.
Sorry for the late comment. The current signature of from_abstract_name in nightly is: fn from_abstract_name<N>(name: &N) -> Result<SocketAddr>
where
N: AsRef<[u8]>; but, I think it should be: fn from_abstract_name<N>(name: N) -> Result<SocketAddr>
where
N: AsRef<[u8]>; The latter allows me to easily pass in a &str or &[u8] directly, without encountering Sized errors |
@rfcbot concern wait-for-106441 |
…shtriplett relax reference requirement on SocketAddrExt::from_abstract_name Reference: rust-lang#85410 (comment)
…shtriplett relax reference requirement on SocketAddrExt::from_abstract_name Reference: rust-lang#85410 (comment)
relax reference requirement on SocketAddrExt::from_abstract_name Reference: rust-lang/rust#85410 (comment)
…htriplett Move `unix_socket_abstract` feature API to `SocketAddrExt`. The pre-stabilized API for abstract socket addresses exposes methods on `SocketAddr` that are only enabled for `cfg(any(target_os = "android", target_os = "linux"))`. Per discussion in <rust-lang/rust#85410>, moving these methods to an OS-specific extension trait is required before stabilization can be considered. This PR makes four changes: 1. The internal module `std::os::net` contains logic for the unstable feature `tcp_quickack` (rust-lang/rust#96256). I moved that code into `linux_ext/tcp.rs` and tried to adjust the module tree so it could accommodate a second unstable feature there. 2. Moves the public API out of `impl SocketAddr`, into `impl SocketAddrExt for SocketAddr` (the headline change). 3. The existing function names and docs for `unix_socket_abstract` refer to addresses as being created from abstract namespaces, but a more accurate description is that they create sockets in *the* abstract namespace. I adjusted the function signatures correspondingly and tried to update the docs to be clearer. 4. I also tweaked `from_abstract_name` so it takes an `AsRef<[u8]>` instead of `&[u8]`, allowing `b""` literals to be passed directly. Issues: 1. The public module `std::os::linux::net` is marked as part of `tcp_quickack`. I couldn't figure out how to mark a module as being part of two unstable features, so I just left the existing attributes in place. My hope is that this will be fixed as a side-effect of stabilizing either feature.
Triage: #106441 has been merged, the concern can be resolved now. |
@joshtriplett @JohnTitor Are there any remaining approvals required for this, or should I put together a stabilization PR? |
I think this is ready for a stabilization PR. |
Dropped the "proposed" label to reflect the status, FCP was done here. |
Thanks! Stabilization PR is #109288 |
@rfcbot resolved wait-for-106441 |
🔔 This is now entering its final comment period, as per the review above. 🔔 |
…dr, r=joshtriplett Stabilise `unix_socket_abstract` Fixes rust-lang#85410
…htriplett Stabilise `unix_socket_abstract` Fixes rust-lang/rust#85410
relax reference requirement on SocketAddrExt::from_abstract_name Reference: rust-lang/rust#85410 (comment)
…htriplett Stabilise `unix_socket_abstract` Fixes rust-lang/rust#85410
Feature gate:
#![feature(unix_socket_abstract)]
This is a tracking issue for adding abstract namespace support for Unix domain sockets on Linux.
Traditionally, Unix domain sockets (UDS) use a file to coordinate socket binding and connecting. On Linux, though, a specific extension exists to allow domain sockets to be created from a namespace which does not use the filesystem. With these changes, we extend Rust's UDS support to create sockets directly from a
SocketAddr
which can be itself used to create an abstract namespace.More information
Previous discussion: #42048
Linux man page: unix(7)
Public API
Non-platform specific additions
UnixListener::bind_addr(&SocketAddr) -> Result<UnixListener>
UnixStream::connect_addr(&SocketAddr) -> Result<()>
UnixDatagram::bind_addr(&SocketAddr) -> Result<UnixDatagram>
UnixDatagram::connect_addr(&SocketAddr) -> Result<()>
UnixDatagram::send_to_addr(&self, &[u8], &SocketAddr) -> Result<usize>
Platform-specific (Linux) additions
SocketAddrExt::from_abstract_name(&[u8]) -> Result<SocketAddr>
SockerAddrExt::as_abstract_name(&self) -> Option<&[u8]>
Example
Steps / History
unix_socket_abstract
feature API toSocketAddrExt
. #101967Unresolved Questions
The text was updated successfully, but these errors were encountered: