Uh oh!
There was an error while loading. Please reload this page.
Add abstract namespace support for Unix domain sockets - #85379
Conversation
rust-highfive
commented
May 16, 2021
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @kennytm (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
This comment has been minimized.
This comment has been minimized.
joshtriplett
commented
May 17, 2021
This looks reasonable to me! You need to create a tracking issue, and change the issue number in the stability attributes to reference that tracking issue. With that fixed, if CI passes and a try build passes, r=me. |
mdaverde
commented
May 17, 2021
Updated the stability attributes to a new tracking issue! Although, I think I need maintainer approval to rerun the build? |
joshtriplett
commented
May 17, 2021
@bors try |
bors
commented
May 17, 2021
⌛ Trying commit a4d0489 with merge 1c03bdf6c40e17f64fa452dd50a3e41fcd70fb69... |
bors
commented
May 17, 2021
☀️ Try build successful - checks-actions |
joshtriplett
commented
May 18, 2021
@bors r+ |
bors
commented
May 18, 2021
📌 Commit a4d0489 has been approved by |
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!
GuillaumeGomez
commented
May 18, 2021
Failed in CI: @bors: r- |
mdaverde
commented
May 18, 2021
Hmm is that an allowable import? I believe I am using it on line :288 of ptr::copy_nonoverlapping(
namespace.as_ptr(),
addr.sun_path.as_mut_ptr().offset(1)as*mutu8,
namespace.len(),); |
GuillaumeGomez
commented
May 18, 2021
Is it behind a cfg by any chance? Worst case, simply replace |
mdaverde
commented
May 18, 2021
Ah yes, that was it. Went ahead and moved the use declaration within the fn block. Thank you! |
GuillaumeGomez
commented
May 18, 2021
@bors: r=joshtriplett,GuillaumeGomez |
bors
commented
May 18, 2021
📌 Commit b0b0267 has been approved by |
…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!
bors
commented
Oct 6, 2021
⌛ Testing commit 3b441c8 with merge 1aa771d03efaa4bcb086adbf0e9e38fb98a6f428... |
bors
commented
Oct 6, 2021
💔 Test failed - checks-actions |
This comment has been minimized.
This comment has been minimized.
mdaverde
commented
Oct 10, 2021
Integrated the I/O safety changes and did a rebase 🙏 |
joshtriplett
commented
Oct 15, 2021
@bors r+ |
bors
commented
Oct 15, 2021
📌 Commit 15b1198 has been approved by |
bors
commented
Oct 15, 2021
bors
commented
Oct 16, 2021
☀️ Test successful - checks-actions |
rust-timer
commented
Oct 16, 2021
Finished benchmarking commit (6cc0a76): comparison url. Summary: This benchmark run did not return any relevant changes. If you disagree with this performance assessment, please file an issue in rust-lang/rustc-perf. @rustbot label: -perf-regression |
Hello! The other day I wanted to mess around with UDS in Rust and found that abstract namespaces (unix(7)) on Linux still needed development. I took the approach of adding
_addrspecific public functions to reduce conflicts.Feature name:
unix_socket_abstractTracking issue: #85410
Further context: #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]) -> SocketAddrSockerAddr::as_abstract_namespace() -> Option<&[u8]>Example
Further Details
The main inspiration for the implementation came from the nix-rust crate but there are also other historicalattempts with similar approaches.
A comment I did have was with this change, we now allow a
SocketAddrto be constructed explicitly rather than just used almost as a handle for the return ofpeer_addrandlocal_addr. We could consider adding other explicit constructors (e.g.SocketAddr::from_pathname,SockerAddr::from_unnamed).Cheers!