summaryrefslogtreecommitdiff
path: root/src/sys/socket
AgeCommit message (Collapse)Author
2023-07-17Merge #2041masterbors[bot]
2041: Set the length of a socket address when calling `recvmsg` on Linux r=asomers a=JarredAllen # Background I think I've found a bug with `recvmsg` on Linux where it doesn't set the length of a received socket address. I found this while working with unix datagram sockets with path `struct sockaddr_un` addresses, but I think this applies to any variable-length socket address type. At present, the `sun_len` field of `UnixAddr` on Linux shows up as 0 whenever I call `recvmsg`. I think it's reading uninitialized memory (afaict the `recvmsg` function never initializes it before we call `MaybeUninit::assume_init`), though it's possible that it's being zero-initialized somewhere that I missed. Either way, this isn't the correct behavior, which should set it to the length of the `struct sockaddr_un` contents (or whatever other type of socket). # Changes I changed the `recvmsg` function to construct the returned socket address from the `struct sockaddr` and length returned by the libc `recvmsg` call (using the `from_raw` function the trait provides). Since the trait is sealed so downstream crates can't implement it, I believe this shouldn't be a breaking change. # Validation I've tested that my code (which failed due to this bug) now works. I also added a new test case which tests that we construct `UnixAddr`s correctly in the `recvmsg` function, which passes locally for me and fails if I cherry-pick it onto the current `master`. I've also checked that `cargo test` and `cargo clippy` both still pass on `aarch64-apple-darwin` and on `aarch64-unknown-linux-musl` targets (the two targets I develop for/have access to). Hopefully your CI will confirm that everything else still works. Co-authored-by: Jarred Allen <jarred@moveparallel.com> Co-authored-by: Jarred Allen <jarredallen73@gmail.com>
2023-07-17Fix lintJarred Allen
2023-07-17Correctly let the kernel set the length on BSDsJarred Allen
Co-authored-by: Alan Somers <asomers@gmail.com>
2023-07-17Merge branch 'master' into set-sockaddr-length-linuxJarred Allen
2023-07-17More PR feedbackJarred Allen
2023-07-17Enable socket timestamping options on AndroidChris Spencer
2023-07-15Merge #2048bors[bot]
2048: Enable additional socket timestamping flags r=asomers a=spencercw Co-authored-by: Chris Spencer <spencercw@gmail.com>
2023-07-15Clippy cleanupAlan Somers
2023-06-27For invalid IP address conversions with future Rust versionsAlan Somers
Rust's standard library no longer guarantees that Ipv4Addr and Ipv6Addr are wrappers around the C types (though for now at least, they are identical on all platforms I'm aware of). So do the conversions explicitly instead of transmuting. Fixes #2053
2023-06-02Enable additional socket timestamping flagsChris Spencer
2023-06-02Fix typo in commentChris Spencer
2023-05-22Merge branch 'master' into set-sockaddr-length-linuxJarred Allen
2023-05-22Remove redundant `unsafe` blockJarred Allen
2023-05-22Fixup accidentally-introduced changesJarred Allen
2023-05-22PR suggestion: Set the length later instead of using `from_raw`Jarred Allen
2023-05-21Clippy cleanup:Alan Somers
fix the new clippy::non_minimal_cfg lint
2023-05-19Set the length of a sockaddr received on LinuxJarred Allen
2023-05-09remove unused mut from two variable declarations in sys/socket/mod.rsBob Haarman
This addresses diagnostics like: error: variable does not need to be mutable --> src/sys/socket/mod.rs:1537:13 | 1537 | let mut p = &mut mmsghdr.msg_hdr;
2023-04-05Merge #2012bors[bot]
2012: Enable socket and select on redox r=asomers a=coolreader18 Co-authored-by: Noa <coolreader18@gmail.com>
2023-03-20fix: send ETH_P_ALL in htons formatTodd Neal
2023-03-13Enable socket on redoxNoa
2023-01-15Try enabling LocalPeerPid for iosArmin Ronacher
2023-01-14Added LOCAL_PEERPID/LocalPeerPid sockopt for macosArmin Ronacher
2023-01-13Fix endian swap on SocketAddrV6.Aaron Drew
flowinfo and scope_id should not be byte swapped.
2022-12-31fix: clippy::size_of_refJonathan
2022-12-13Added CANbus socket family protocol constants.fpagliughi
2022-12-04Cleanup old Clippy directives.Alan Somers
2022-12-04Fix clippy lintsAlex Saveau
Signed-off-by: Alex Saveau <saveau.alexandre@gmail.com>
2022-12-04Merge #1909bors[bot]
1909: More annoying formatting changes r=asomers a=SUPERCILEX Extracted from https://github.com/nix-rust/nix/pull/1862 Co-authored-by: Alex Saveau <saveau.alexandre@gmail.com>
2022-12-04More annoying formatting changesAlex Saveau
Signed-off-by: Alex Saveau <saveau.alexandre@gmail.com>
2022-12-04Move some pure formatting changes out of #1863Alex Saveau
Signed-off-by: Alex Saveau <saveau.alexandre@gmail.com>
2022-12-03Nuke deprecated net APIsAlex Saveau
Signed-off-by: Alex Saveau <saveau.alexandre@gmail.com>
2022-11-29Add routing socket typeEmils
2022-11-28Fix UB in the SO_TYPE sockoptAlan Somers
When reading a value into an enum from getsockopt, we must validate it. Failing to do so can lead to UB for example with SOCK_PACKET on Linux. Perform the validation in GetSockOpt::get. Currently SockType is the only type that requires validation. Fixes #1819
2022-11-25Merge #1865bors[bot]
1865: Add IpMtu sockopt r=asomers a=ShadowJonathan Resolves https://github.com/nix-rust/nix/issues/1864 Co-authored-by: Jonathan de Jong <jonathandejong02@gmail.com>
2022-11-25Clippy cleanup with the latest nightly.Alan Somers
2022-11-23add IpMtu sockoptJonathan de Jong
2022-11-21Merge #1848bors[bot]
1848: SockProtocol::Raw = libc::IPPROTO_RAW for raw sockets r=asomers a=StackOverflowExcept1on Hey, I wanna to make call like `socket(af_type, SOCK_RAW, IPPROTO_RAW)` but currently there is no way to do it with rust https://github.com/rickettm/SendIP/blob/aad12a001157489ab9053c8665e09aec24a2ff6d/sendip.c#L143 Update: Feel free to add `#[cfg]` attribute if I made mistakes that might cause errors on some platforms Co-authored-by: StackOverflowExcept1on <109800286+StackOverflowExcept1on@users.noreply.github.com>
2022-11-21Use the new UnixAddr::new_unnamed in the unit testsAlan Somers
Use it in the from_sockaddr_un_abstract_unnamed test. That test and this method were introduced by PRs #1871 and #1857, which crossed each other.
2022-11-21Added `SockProtocol::Raw = libc::IPPROTO_RAW` for raw socketsStackOverflowExcept1on
2022-11-21Merge #1857bors[bot]
1857: Add better support for unnamed unix socket addrs r=asomers a=stevenengler This adds the following 2 functions/methods: `UnixAddr::new_unnamed` and `UnixAddr::is_unnamed`. Closes #1585 unix(7) on Linux: > unnamed: A stream socket that has not been bound to a pathname using bind(2) has no name. Likewise, the two sockets created by socketpair(2) are unnamed. When the address of an unnamed socket is returned, its length is `sizeof(sa_family_t)`, and `sun_path` should not be inspected. **Edit:** This currently isn't working on BSD, but I see why. Will fix it shortly. Co-authored-by: Steven Engler <opara@cs.georgetown.edu>
2022-11-21Merge #1871bors[bot]
1871: Fix using SockaddrStorage to store Unix domain addresses on Linux r=rtzoeller a=asomers Since it has variable length, the user of a sockaddr_un must keep track of its true length. On the BSDs, this is handled by the builtin sun_len field. But on Linux-like operating systems it isn't. Fix this bug by explicitly tracking it for SockaddrStorage just like we already do for UnixAddr. Fixes #1866 Co-authored-by: Alan Somers <asomers@gmail.com>
2022-11-21fixup! Added better support for unnamed unix socket addrsSteven Engler
Make Linux-only
2022-11-21Added better support for unnamed unix socket addrsSteven Engler
2022-11-20Adds IP_TOS, IPV6_TCLASS and SO_PRIORITY sockopt wrappersmzachar
2022-11-19Misc internal optimizationsAlan Somers
* Make ipv4addr_to_libc const * Use mem::transmute in ipv4addr_to_libc and ipv6addr_to_libc Fixes #1687 Fixes #1688
2022-11-19Fix using SockaddrStorage to store Unix domain addresses on LinuxAlan Somers
Since it has variable length, the user of a sockaddr_un must keep track of its true length. On the BSDs, this is handled by the builtin sun_len field. But on Linux-like operating systems it isn't. Fix this bug by explicitly tracking it for SockaddrStorage just like we already do for UnixAddr. Fixes #1866
2022-11-06Reformat everythingAlex Saveau
Signed-off-by: Alex Saveau <saveau.alexandre@gmail.com>
2022-10-23Suppress deprecation warnings from the latest libcAlan Somers
https://github.com/rust-lang/libc/pull/2963
2022-10-14include docsMichael Baikov