Commit Graph

122 Commits

Author SHA1 Message Date
SteveLauC
c0d8ad4df4
refactor: move tests to the test dir (#2257)
* refactor: move tests to the test dir

* try fixing it

* try fixing it

* fix Redox and FreeBSD

* document it
2023-12-11 22:29:22 +00:00
SteveLauC
6961f0fabd
refactor: cfg for test/* (#2230)
* refactor: cfg for test/*

* one more netbsdlike

* more cfg
2023-12-09 16:15:41 +00:00
Alan Somers
cb56e89aab
Ensure all tests use unique IP ports (#2196) 2023-12-03 23:02:26 +00:00
SteveLauC
a4e0c9544c
feat: ControlMessageOwned::{Ipv4RecvIf,Ipv4RecvDstAddr} for DragonFlyBSD (#2240)
* feat: Enable ControlMessageOwned::{Ipv4RecvIf,Ipv4RecvDstAddr} for DragonFlyBSD

* fix DrafonFlyBSD

* fix Linux

* fix cfg
2023-12-02 17:10:19 +00:00
SteveLauC
e95162f288
refactor: enable most macOS funcs for apple_targets (#2241)
* refactor: enable most macOS funcs for apple_targets

* respond to review

* respond to review
2023-12-02 17:10:04 +00:00
Alan Somers
2afff8194c
Add more cfg aliases (#2205)
* 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>
2023-11-25 06:32:06 +00:00
recatek
3541bdd9b1
Added FreeBSD's SCM_REALTIME and SCM_MONOTONIC into sys::socket::ControlMessageOwned (#2187)
* 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
2023-11-25 03:07:34 +00:00
Henry Chen
7c1045e5c7
sys: add MIPS R6 support (#2138)
Currently R6 targets are almost identical to their R2/R5
counterparts.
2023-11-13 05:29:51 +00:00
Luís Cruz
49283c9031
Add apple tvos support (#2169) 2023-11-09 01:00:20 +00:00
Gilad Naaman
173bde107a
Add SockProtocol variants for ICMP{,v6} (#2103) 2023-10-01 18:59:54 +00:00
Jan Adä
9f4e87764f
fixes UB for recvmmsg, simplifies function signature of recvmmsg and sendmmsg (#2120) 2023-10-01 18:59:36 +00:00
Alan Somers
e5b2df67bc
Cast pointers more carefully (#2140)
* 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
2023-10-01 00:29:52 +00:00
Jonathan Woollett-Light
8ad064d7b9
feat: I/O safety pipe, pipe2 & write (#2100) 2023-09-30 07:52:11 +00:00
Alan Somers
154a8a4a00
Clippy cleanup: endless_loop (#2135) 2023-09-23 16:14:59 +00:00
Alan Somers
c98b13e529 Fix an incorrect lifetime in the return value of recvmsg
Fixes #2083
2023-08-11 10:47:27 -06:00
Alan Somers
c1317e477f Add I/O safety to sockopt and some socket functions
* socket
* socketpair
* listen
* setsockopt
* getsockopt
2023-08-06 20:18:09 -06:00
Todd Neal
7a9826273f add vsock support for macOS 2023-07-18 07:31:29 -05:00
Jarred Allen
23125cbb1b Merge branch 'master' into set-sockaddr-length-linux 2023-07-17 11:34:00 -07:00
Ben Kimock
57cdbed0ab Clippy cleanup:
fix the new clippy::non-minimal-cfg lint
2023-06-05 18:11:07 -06:00
Jarred Allen
72a2f567ee PR suggestions: use skip macro 2023-05-22 11:47:24 -07:00
Jarred Allen
96fa5a898c Add test coverage for bug with unset socket address length 2023-05-19 17:00:13 -07:00
Stefano Garzarella
4d31ecf06b Rework vsock test
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>
2022-12-14 09:54:43 +01:00
Alex Saveau
fb802462a6
Fix clippy lints
Signed-off-by: Alex Saveau <saveau.alexandre@gmail.com>
2022-12-04 13:44:50 -08:00
Alex Saveau
f3aa1affb0
Nuke deprecated net APIs
Signed-off-by: Alex Saveau <saveau.alexandre@gmail.com>
2022-12-03 11:40:05 -08:00
Steven Engler
f6a22198a4 fixup! Added better support for unnamed unix socket addrs
Removed test assertion
2022-11-21 12:11:50 -05:00
Steven Engler
49bab984ee fixup! Added better support for unnamed unix socket addrs
Make Linux-only
2022-11-21 12:03:11 -05:00
Steven Engler
8884ea38ec Added better support for unnamed unix socket addrs 2022-11-21 12:03:11 -05:00
Michael Baikov
19c83afbbf reimplement recvmsg/sendmmsg
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()
    };
```
2022-10-14 08:57:41 -04:00
Matthew Ingwersen
6bf07fdbb9 Add support for the IP_SENDSRCADDR control message
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-08-05 12:35:57 -04:00
Michael Baikov
a6ee63ac32 fix clippy assertions_on_result_states
https://rust-lang.github.io/rust-clippy/master/index.html#assertions_on_result_states
2022-08-04 09:44:40 +08:00
Brian May
c45cd74f42 Add support for RecvOrigDstAddr on Linux
Fixes #1767
2022-07-26 07:39:00 +10:00
Alan Somers
e0e768e7b9 Fix a buffer overflow in sys::socket::recvfrom
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-14 11:37:56 -06:00
Alan Somers
dc1a34b864 Clippy cleanup in the tests.
* Remove a redundant closure.
* Comparison with null
* Manual implementation of find
* Suppress a false positive
2022-07-10 08:43:04 -06:00
Costin-Robert Sin
3e6cb639f0 Fix all formating problems to pass CI formating test
Signed-off-by: Costin-Robert Sin <sin.costinrobert@gmail.com>
2022-06-24 00:35:52 +03:00
Kyle Huey
024c0d7dde Restore conversions from ip v4/6 Sockaddr types to std::net equivalents.
Fixes #1710
2022-05-02 08:53:08 -07:00
not_a_seagull
0b58f29772 Replace the IoVec type with IoSlice and IoSliceMut 2022-04-08 12:39:16 -07:00
Alan Somers
fbeabf3730 Deprecate IpAddr, Ipv4Addr, and Ipv6Addr
Because they're redundant with types in the standard library.

Fixes #1681
2022-03-22 21:09:52 -06:00
Alan Somers
76d70b4b25 Replace the Sockaddr enum with a union
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-21 20:50:24 -06:00
Ryan Zoeller
ebd4acebc0 Change port used by test_txtime to avoid conflict 2022-01-10 21:57:55 -06:00
Alessandro Ghedini
a9829853df Add support for the SO_TXTIME sockopt and SCM_TXTIME control message 2021-12-29 14:15:54 +00:00
Michael Baikov
9aa61ef975 feat: Add glibc::SOF_TIMESTAMPING_* support 2021-12-23 06:41:30 +08:00
Alan Somers
a09b1c8ac6 Clippy cleanup
And this time, start running Clippy in CI
2021-09-19 07:58:15 -06:00
bors[bot]
4f58c8c8e3
Merge #1496
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-19 02:04:04 +00:00
bors[bot]
630700eb7c
Merge #1317
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>
2021-09-07 23:37:26 +00:00
Conrad Meyer
d23e7c7575 Add support for IP_RECVERR and IPV6_RECVERR
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-06 16:59:35 -07:00
Noa
8e963a093f
Rework UnixAddr to fix soundness issues 2021-08-29 17:25:41 -05:00
Alan Somers
18c095b367 Ignore vsock tests on Linux aarch64
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.
2021-08-27 22:31:20 -06:00
Noah
c96141d423
Deprecate SockAddr/InetAddr::to_str 2021-08-21 16:59:35 -05:00
Kyle Huey
d133d3db76 Relax assertions in sockaddr_storage_to_addr to match the documentation.
Fixes #1479
2021-08-17 19:26:12 -07:00
Junho Choi
0b596a11e0 Support SO_RXQ_OVFL socket option (android/fuchsia/linux)
This PR implements support of RXQ_OVFL flag and parsing ControlMessage
to get the packet drop counter of UDP socket.
2021-07-08 16:00:39 -07:00