summaryrefslogtreecommitdiff
path: root/src/sys/socket
AgeCommit message (Collapse)Author
2022-08-05Add support for the IP_SENDSRCADDR control messageMatthew Ingwersen
This control message (actually just an alias for IP_RECVDSTADDR) sets the IPv4 source address when used with sendmsg. It is available on FreeBSD, NetBSD, OpenBSD, and DragonFlyBSD.
2022-07-26Merge #1772bors[bot]
1772: Add support for RecvOrigDstAddr on Linux r=asomers a=brianmay Fixes #1767 Co-authored-by: Brian May <brian@linuxpenguins.xyz>
2022-07-26Add support for RecvOrigDstAddr on LinuxBrian May
Fixes #1767
2022-07-24Add ETH_P_ALL protocol number to SockProtocolvaldaarhun
Add note to Changelog.md Make changes in comments Co-authored-by: Alan Somers <asomers@gmail.com> Add Android as target os for ETH_P_ALL
2022-07-23Fix SockaddrLike::from_raw with unaligned inputsAlan Somers
The major users of this function are functions like gethostname, which will always properly align their buffers. But out-of-crate consumers could manually construct an unaligned buffer. Handle that correctly. Enable Clippy's cast_ptr_alignment lint. It's disabled by default as it reports many false positives, but it would've caught this problem. Reported-by: Miri Fixes: 1769
2022-07-14Fix a buffer overflow in sys::socket::recvfromAlan Somers
IPv4 and stream sockets are unaffected, but for datagram sockets of other address types libc::recvfrom might overwrite part of the stack. Fixes #1762
2022-07-11Add DontRoute SockOptLeo Lu
2022-06-09Merge #1736bors[bot]
1736: Fix socket address family checks r=rtzoeller a=qwandor The `SockaddrLike::from_raw` implementations for `VsockAddr` and `SysControlAddr` were checking against the wrong address family constant. This PR makes them consistent with the values matched against in `SockaddrStorage::from_raw`. Co-authored-by: Andrew Walbran <qwandor@google.com>
2022-06-07Fix socket address family check for SysControlAddr::from_raw.Andrew Walbran
2022-06-07Fix socket address family check for VsockAddr::from_raw.Andrew Walbran
2022-06-06Cleanup cfg blocksRyan Zoeller
Remove obsolete references to target_env = wasi, target_os = nacl, target_os = osx, and a typo'd target_os = fushsia that didn't compile when fixed. - target_env = wasi is dead: https://github.com/rust-lang/rust/pull/60117 - target_os = nacl is dead: https://github.com/rust-lang/rust/pull/45041 - target_os = osx is dead, but I can't find a link.
2022-05-31Enable SockaddrStorage::{as_link_addr, as_link_addr_mut} on Linux.Alan Somers
This was an oversight from #1684. Fixes #1728
2022-05-14add haiku supportAl Hoang
* enabled as much functionality and defines that match updated libc definitions for haiku
2022-05-13Fix "unused_macro_rules" warnings with the latest nightly compiler.Alan Somers
It just so happens that Redox, OpenBSD, Dragonfly, and uclibc don't use some of the rules for two internal macros.
2022-05-02Restore conversions from ip v4/6 Sockaddr types to std::net equivalents.Kyle Huey
Fixes #1710
2022-04-22Fix UnixAddr::size on Linux and AndroidAlan Somers
SockaddrLike::size() is meant to return the amount of space that can be used to store the sockaddr. But on Linux-based OSes, UnixAddr contains an extra field to store the address's length. This field is not part of the address, and should not contribute to the value of size(). This bug can't cause an out-of-bounds write, and every OS that we test on can tolerate the greater-than-expected length, but it might confuse applications that implement functions similar to getsockname in userland.
2022-04-08Merge #1643bors[bot]
1643: Replace the IoVec struct with IoSlice and IoSliceMut from the standard library r=asomers a=notgull As per discussion in #1637, the `IoVec<&[u8]>` and `IoVec<&mut [u8]>` types have been replaced with `std::io::IoSlice` and `IoSliceMut`, respectively. Notable changes made in this pull request include: - The complete replacement of `IoVec` with `IoSlice*` types in both public API, private API, and tests. - Replacing `IoVec` with `IoSlice` in docs. - Replacing `&[IoVec<&mut [u8]>]` with `&mut [IoSliceMut]`, note that the slice requires a mutable reference now. This is how it's done in the standard library, and there might be a soundness issue in doing it the other way. Resolves #1637 Co-authored-by: not_a_seagull <notaseagull048@gmail.com>
2022-04-08Replace the IoVec type with IoSlice and IoSliceMutnot_a_seagull
2022-04-07Add IP_DONTFRAG and IPV6_DONTFRAG SockOptsJunho Choi
IP_DONTFRAG: iOS, macOS IPV6_DONTFRAG: android, iOS, linux and macOS Test: `cargo test --test test dontfrag_opts` Some CI tests running ENOPROTOOPT are disabled (qemu-based).
2022-03-24Merge #1686bors[bot]
1686: [skip ci] better docs for SockaddrLike::from_raw r=asomers a=asomers Fixes #1680 Co-authored-by: Alan Somers <asomers@gmail.com>
2022-03-22[skip ci] better docs for SockaddrLike::from_rawAlan Somers
Fixes #1680
2022-03-22Deprecate IpAddr, Ipv4Addr, and Ipv6AddrAlan Somers
Because they're redundant with types in the standard library. Fixes #1681
2022-03-21Replace the Sockaddr enum with a unionAlan Somers
The SockAddr enum is quite large, and the user must allocate space for the whole thing even though he usually knows what type he needs. Furthermore, thanks to the sa_family field, the sockaddr types are basically an enum even in C. So replace the ungainly enum with a SockaddrLike trait implemented by all sockaddr types and a SockaddrStorage union that has safe accessors. Also, deprecate InetAddr, which only existed to support SockAddr. Supplants #1504 Fixes #1544
2022-03-13Use the same signature for LinkAddr::addr on all platformsAlan Somers
This should've been done as part of #1675
2022-03-13Fix a panic in Linkaddr::addrAlan Somers
The function assumed something about the values of the sockaddr_dl's fields. But because the inner type is public, we musn't do that. The only solution is to change the function's signature to return an Option.
2022-03-09docs: fix link in doc for cmsg_space in sys/socketbin liu
Link to cmsg_space macro for recvmmsg and recvmsg should be the doc's root of crate as macro is an exported macro. Signed-off-by: bin liu <liubin0329@gmail.com>
2022-03-06Add MsgFlag::MSG_NOSIGNALi509VCB
2022-02-04Add accept4 on supported platformsRyan Zoeller
2022-01-24uclibc supportJonah Petri
2022-01-23InetAddr::from_std should set sin_len/sin6_len on the BSDsRyan Zoeller
2021-12-31Merge #1618bors[bot]
1618: Refactor UnixAddr r=asomers a=asomers * Within UnixAddr, replace the path_len variable (length of the sun_path field) with sun_len (length of the whole structure). This is more similar to how other sockaddr types work, and it's the same way that the BSDs use the sun_len field. Also, don't require that sun_path be nul-terminated. The OS doesn't require it. * On BSD-derived operating systems, struct sockaddr has a sa_len field that holds the length of the structure. UnixAddr's path_len field is redundant. Remove path_len on BSD-derived OSes, retaining it only for Illumos and Linux-based OSes. Co-authored-by: Alan Somers <asomers@gmail.com>
2021-12-30Optimize UnixAddr for the BSDsAlan Somers
On BSD-derived operating systems, struct sockaddr has a sa_len field that holds the length of the structure. UnixAddr's path_len field is redundant. Remove path_len on BSD-derived OSes, retaining it only for Illumos and Linux-based OSes. Also, ensure that two UnixAddrs compare equal if they differ only by the presence of a trailing NUL. On Linux, syscalls like getsockname add a trailing NUL to the sockaddr they return, even if no NUL was present on the sockaddr originally passed to the kernel via a syscall like bind, and even though the docs explicitly say that any NUL passed to bind is not considered to be part of the address. Work around this bug by stripping it in UnixAddrKind::get(), so that at least two UnixAddrs will compare identical even if they differ in the presence of a trailing NUL.
2021-12-29Add support for the SO_TXTIME sockopt and SCM_TXTIME control messageAlessandro Ghedini
2021-12-24Merge #1547bors[bot]
1547: feat: Add glibc::SOF_TIMESTAMPING_* support r=asomers a=pacak Support for kernel and hardware receive timestamps Co-authored-by: Michael Baikov <manpacket@gmail.com>
2021-12-23feat: Add glibc::SOF_TIMESTAMPING_* supportMichael Baikov
2021-12-21UnixAddr: replace path_len with sun_lenAlan Somers
Within UnixAddr, replace the path_len variable (length of the sun_path field) with sun_len (length of the whole structure). This is more similar to how other sockaddr types work, and it's the same way that the BSDs use the sun_len field. Also, don't require that sun_path be nul-terminated. The OS doesn't require it.
2021-12-21Improve the sockaddr interface:Alan Somers
* All sockaddr newtypes should be repr(transparent) * All sockaddr newtypes should be opaque, so the user can't do something like change the sa_family field in a way that violates invariants. This is a prerequisite for #1544.
2021-12-20feature-gate most Nix functionsVincent Dagonneau
Using features reduces build time and size for consumer crates. By default all features are enabled.
2021-10-09sockopt's Set and Get traits are not unsafeAlan Somers
They were properly marked as unsafe as originally written. However, when the internal mem::zeroed() was replaced by mem::uninitialized(), these traits actually became safe. Only Get::assume_init() is actually unsafe. Fixes a warning with the latest Clippy.
2021-09-28Revert "Expose SockAddr::from_raw_sockaddr"Alan Somers
This reverts commit ed43d2c65e65dd68c9cf2dcf06f5ec45a44aaccd. As discussed in #1544 the API of this function needs to change. For now, revert the PR that made it public, because it has not yet been included in any release.
2021-09-19Clippy cleanupAlan Somers
And this time, start running Clippy in CI
2021-09-19Merge #1496bors[bot]
1496: Rework UnixAddr to fix soundness issues r=asomers a=coolreader18 Fixes #1494 I went with making `sun_path` always nul-terminated since that just seems to make things easier, since (at least according to linux man pages) `sockaddr_un`s returned by the kernel will always be nul-terminated. Co-authored-by: Noa <33094578+coolreader18@users.noreply.github.com>
2021-09-12Add docs for all sockopts that are documented by their respective OSesAlan Somers
2021-09-12Add the ability to set doc strings in sockopts' definitionsAlan Somers
2021-09-12Switch the argument order of sockopt_impl!Alan Somers
This macro is not exported outside of the crate, so there's no danger.
2021-09-07Add IP_TTL/IPV6_UNICAST_HOPS SockOptsConrad Meyer
Test: `cargo test --test test test_ttl_opts`
2021-09-07Merge branch 'master' into socket-mssAlan Somers
2021-09-06Add support for IP_RECVERR and IPV6_RECVERRConrad Meyer
Setting these options enables receiving errors, such as ICMP errors from the network, via `recvmsg()` with `MSG_ERRQUEUE`. Adds new `Ipv{4,6}RecvErr` variants to `ControlMessageOwned`. These control messages are produced when `Ipv4RecvErr` or `Ipv6RecvErr` options are enabled on a raw or datagram socket. New tests for the functionality can be run with `cargo test --test test test_recverr`. This commit builds on an earlier draft of the functionality authored by Matthew McPherrin <git@mcpherrin.ca>.
2021-09-04Merge branch 'master' into socket-msseaon
2021-09-04Support for `TCP_MAXSEG` TCP MSS socket optioneaon