* Add more cfg aliases
Add cfg aliases for linux_android, bsd, and freebsdlike. Use them in
many places, though not everywhere they could theoretically be used.
Fixes#2188
* Use apple_targets in build.rs
Co-authored-by: SteveLauC <stevelauc@outlook.com>
* whitespace
Co-authored-by: SteveLauC <stevelauc@outlook.com>
* Define a "solarish" target alias.
* Describe cfg aliases in CONVENTIONS.md
* solarish in line 803
* solarish in line 845
* fix fmt
---------
Co-authored-by: SteveLauC <stevelauc@outlook.com>
* Added FreeBSD's SCM_REALTIME and SCM_MONOTONIC into sys::socket::ControlMessageOwned.
* Creating a SocketTimestamp enum for the SO_TS_CLOCK setsockopt for FreeBSD.
* Fixing whitespace
* Fixing CI error on cfg attributes
* Removing legacy doc attributes
* Formatting cleanup
* Updating changelog
* Adding tests for new TsClock setsockopt enum and the two new packet timestamp control messages for FreeBSD
* Replacing an assert_eq with an assert in new tests.
* Removing qemu ignore for new FreeBSD tests
* Giving new FreeBSD timestamping tests each a unique socket
* Updating monotonic packet timestamp test to account for monotonicity
* Moving test ports again to line up with changes in #2196
* Attempting checks again
* Wrapping ptr::read_unaligned calls in unsafe blocks
* Cast pointers more carefully
Prefer ptr::{cast, cast_const, cast_mut} over `as`. The latter makes it
too easy to accidentally change both the type and mutability when
changing only one was intended.
This exercise caught an unintended mutability cast in one function, the
BSD version of sendfile. In this case there's no UB because it isn't
possible for anything else to get a reference to the data that was
incorrectly cast.
There was also a type cast that wasn't guaranteed to be correct (but
probably was) due to memory layout guarantees in if_nametoindex.
* Remove unnecessary cast in UnixCredentials::groups
We mainly provide VsockAddr, so let's try to test well that VsockAddr
mapping to libc::sockaddr_vm is correct.
Let's remove all interactions with the socket, since vsock may or may
not be available in the environment.
Testing socket(), bind(), listen(), connect(), etc. caused unexpected
failures, and it's out of scope of this crate.
So let's simplify the vsock test focussing on VsockAddr.
This should work also on graviton, so let's try to re-enable it.
Fixes#1934
Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
New implementation performs no allocations after all the necessary
structures are created, removes potentially unsound code that
was used by the old version (see below) and adds a bit more
documentation about bugs in how timeout is actually handled
```
let timeout = if let Some(mut t) = timeout {
t.as_mut() as *mut libc::timespec
} else {
ptr::null_mut()
};
```
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.
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 #1504Fixes#1544
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>
1317: test_af_alg_aead waits indefinitely r=asomers a=ritzk
Starting with linux kernel 4.9, the crypto interface changed slightly such that the authentication tag memory is only needed in the output buffer for encryption and in the input buffer for decryption. Thus, we have fewer bytes to read than the buffer size. Do not block on read.
alternatively, we can adjust the decrypted buffer size based on kernel version ( ">= 4.9") to not include auth_size .
```
if kernel_version >= "4.9":
let mut decrypted = vec![0u8; payload_len + (assoc_size as usize) ];
```
before
```
test sys::test_socket::test_af_alg_aead ... test sys::test_socket::test_af_alg_aead has been running for over 60 seconds
```
after
```
test sys::test_socket::test_af_alg_aead ... ok
```
Co-authored-by: Ritesh Khadgaray <khadgaray@gmail.com>
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>.
Apparently AWS Graviton containers don't support it. socket() retunrs
EAFNOSUPPORT in that environment.
Also, be more selective about skipping tests under QEMU
Instead of skipping them on architectures where we happen to use QEMU,
only skip them when QEMU is actually being used.