-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Add abstract namespace support for Unix domain sockets #85379
Conversation
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.
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. |
Updated the stability attributes to a new tracking issue! Although, I think I need maintainer approval to rerun the build? |
@bors try |
⌛ Trying commit a4d0489 with merge 1c03bdf6c40e17f64fa452dd50a3e41fcd70fb69... |
☀️ Try build successful - checks-actions |
@bors r+ |
📌 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!
Failed in CI:
@bors: r- |
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 *mut u8,
namespace.len(),
); |
Is it behind a cfg by any chance? Worst case, simply replace |
Ah yes, that was it. Went ahead and moved the use declaration within the fn block. Thank you! |
@bors: r=joshtriplett,GuillaumeGomez |
📌 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!
⌛ Testing commit 3b441c8 with merge 1aa771d03efaa4bcb086adbf0e9e38fb98a6f428... |
💔 Test failed - checks-actions |
This comment has been minimized.
This comment has been minimized.
3b441c8
to
15b1198
Compare
Integrated the I/O safety changes and did a rebase 🙏 |
@bors r+ |
📌 Commit 15b1198 has been approved by |
☀️ Test successful - checks-actions |
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
_addr
specific public functions to reduce conflicts.Feature name:
unix_socket_abstract
Tracking 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]) -> SocketAddr
SockerAddr::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 historical attempts 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 ofpeer_addr
andlocal_addr
. We could consider adding other explicit constructors (e.g.SocketAddr::from_pathname
,SockerAddr::from_unnamed
).Cheers!