Commit Graph

100 Commits

Author SHA1 Message Date
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
Alan Somers
2d796eba38 Collapse Error into Errno
Now that Nix's weird error types are eliminated, there's no reason not
to simply use Errno as the Error type.
2021-07-07 20:49:29 -06:00
Alan Somers
6511d02414 Overhaul Nix's error types
For many of Nix's consumers it be convenient to easily convert a Nix
error into a std::io::Error.  That's currently not possible because of
the InvalidPath, InvalidUtf8, and UnsupportedOperation types that have
no equivalent in std::io::Error.

However, very few of Nix's public APIs actually return those unusual
errors.  So a more useful API would be for Nix's standard error type to
implement Into<std::io::Error>.

This commit makes Error a simple NewType around Errno.  For most
functions it's a drop-in replacement.  There are only three exceptions:

* clearenv now returns a bespoke error type.  It was the only Nix
  function whose error couldn't be cleanly mapped onto an Errno.

* sys::signal::signal now returns Error(Errno::ENOTSUP) instead of
  Error::UnsupportedOperation when the user passes an incompatible
  argument to `handler`.

* When a NixPath exceeds PATH_MAX, it will now return
  Error(Errno::ENAMETOOLONG) instead of Error::InvalidPath.

In the latter two cases there is now some abiguity about whether the
error code was generated by Nix or by the OS.  But I think the ambiguity
is worth it for the sake of being able to implement Into<io::Error>.

This commit also introduces Error::Sys() as a migration aid.  Previously
that as an enum variant.  Now it's a function, but it will work in many
of the same contexts as the original.

Fixes #1155
2021-07-07 20:49:28 -06:00
Alan Somers
7b7d954005 misc Clippy cleanup
* Fix race conditions in the tests.  Two tests were grabbing a mutex but
  immediately dropping it.  Thank you, Clippy.

* Remove vestigial Windows support.  Remove some code added to support
  Windows in 2015.  Nix is no longer intended to ever run on Windows.

* Various other minor Clippy lints.
2021-05-30 20:12:41 -06:00
bors[bot]
68d01f0426
Merge #1402
1402: Support TIMESTAMPNS r=asomers a=WiSaGaN

This adds support of linux TIMESTAMPNS.
The code is mostly copied paste from https://github.com/nix-rust/nix/pull/663

Co-authored-by: Lu, Wangshan <wisagan@gmail.com>
2021-04-08 03:53:56 +00:00
Lu, Wangshan
830bab64a8
Support TIMESTAMPNS for linux 2021-04-08 10:41:38 +08:00
Alan Somers
2ba6999e2e Check all tests in CI
Travis didn't compile check tests on platforms that couldn't run tests
in CI, so they bitrotted.  Let's see how bad they are.

Most annoyingly, 32-bit Android defines mode_t as 16 bits, but
stat.st_mode as 32-bits.
2021-04-04 19:32:54 -06:00
Stefano Garzarella
5d17a60aa0 Revert "Temporarily disable test_vsock on QEMU arches"
This reverts commit c0783e7f8d.

Now the test should work correctly, so we can re-enable it.

Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
2021-03-22 09:53:14 +01:00
Stefano Garzarella
532e238d5e Fix test_vsock failure on VMADDR_CID_LOCAL testing
Starting from Linux 5.6, VMADDR_CID_LOCAL is supported to do local
communication (loopback device).

Before Linux 5.6 it was called VMADDR_CID_RESERVED and was not
supported, so we could expect an EADDRNOTAVAIL, but now this address
is supported and handled by the 'vsock_loopback' kernel module loaded
automatically if no other vsock transports are loaded.

Issue #1310
Issue #1403

Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
2021-03-22 09:51:50 +01:00
Alan Somers
c0783e7f8d Temporarily disable test_vsock on QEMU arches
Issue #1403
2021-03-21 16:17:49 -06:00
Amanda Tait
5846ae2afd
Add fuchsia support
Allow nix to compile on Fuchsia by conditionally avoiding libc
functionality that does not exist for Fuchsia.
2020-12-19 14:17:42 -05:00
Alan Somers
bf7a5fd606 Switch all builds from Travis to Cirrus
Travis has been super-slow lately (> 6 hours per build).  Cirrus is much
faster: about 20 minutes.  Cirrus also has slightly better test
coverage, mainly because it doesn't use SECCOMP.

Also,

* Fix the Redox CI build.  The old Travis configuration didn't actually
  build for Redox, so we never noticed that Redox can't be built with a
  stable compiler.  Thanks to @coolreader18 for finding this.

* Disable the udp_offload tests on cross-tested platforms.  These tests
  are failing with ENOPROTOOPT in Cirrus-CI.  I suspect it's due to a
  lack of support in QEMU.  These tests were skipped on Travis because
  its kernel was too old.

* Fix require_kernel_version on Cirrus-CI.  Cirrus reports the Linux
  kernel version as 4.19.112+, which the semver crate can't handle.

* Fix test_setfsuid on Cirrus.  When run on Cirrus, it seems like the
  file in /tmp gets deleted as soon as it's closed.  Probably an
  overzealous temporary file cleaner.  Use /var/tmp, because no
  temporary file cleaner should run in there.

* Skip mount tests on Cirrus.  They fail for an unknown reason.
Issue #1351

* Skip the AF_ALG tests on Cirrus-CI
Issue #1352
2020-12-06 22:35:30 -07:00
Toby DiPasquale
aef3068c1d Fix recvmmsg(2) implementation
There were two problems discovered with the `recvmmsg(2)` implementation
that this changeset attempts to fix:

1. As mentioned in nix-rust/issues/1325, `recvmmsg(2)` can return fewer
   messages than requested, and
2. Passing the return value of `recvmmsg(2)` as the number of bytes in
   the messages received is incorrect.

This changeset incorporates the proposed fix from nix-rust/issues/1325,
as well as passing the correct value (`mmsghdr.msg_len`) for the number
of bytes in a given message.
2020-11-27 21:49:41 -05:00
Ritesh Khadgaray
e03e400953 test_af_alg_aead waits indefinitely
Starting with 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.
2020-10-17 19:28:22 -07:00
Andrew Walbran
c5739567a3 Support vsock on Android as well as Linux.
Fix deprecation warning from libc update.
2020-10-04 20:29:03 +01:00
Perry Lorier
78347d1618 Add Ipv{4,6}PacketInfo support to ControlMessage for send{m,}msg
This adds Ipv4PacketInfo and Ipv6PacketInfo to ControlMessage,
allowing these to be used with sendmsg/sendmmsg.

This change contains the following squashed commits:

Add Ipv{4,6}PacketInfo to ControlMessage.

Add documentation links to Ipv{4,6}PacketInfo

Add changelog entry for Ipv{4,6}PacketInfo

Add link to PR in the Changelog.

Add extra build environments.

Add tests for Ipv{4,6}PacketInfo.

Swap #[test] and #[cfg]

The CI appears to be running the test, even though it's not cfg'd for
that platform.  I _think_ this might be due to these being in the wrong
order.  So lets try swapping them.

s/freebsd/netbsd/ for Ipv4PacketInfo

netbsd supports in_pktinfo, not freebsd.

Fix the cfg for Ipv{4,6}PacketInfo usage.

Ah, I see what I did wrong.  I had fixed the definitions, but I had the
wrong cfg() in the usage.  This has the usage match the definitions.

Change SOL_IPV6 to IPPROTO_IPV6.

FreeBSD doesn't have SOL_IPV6, but does have IPPROTO_IPV6, and the two
constants are defined as being equal.  So change to use IPPROTO_IPV6.

Skip Ipv6PacketInfo test if v6 is not available.

If IPv6 is not available, then when we try and bind to ip6-localhost,
we'll get a EADDRNOTAVAIL, so skip the test.

This should mean that the test will run on any machine that has a v6
loopback address.

More architecture cfg() fixes.

These all need to be the same, and they were not.  Make them them all
the same.  Attempt III.

Fix up mismatched cfg's again.

Take IV.  Make sure the cfg's that use a enum variant match the enum
definition.
2020-06-26 18:13:51 +01:00
Nick Pelone
dd0a99001e Fix build on OpenBSD caused by erroneous inclusion in allowed OS list for sendmmsg() / recvmmsg() in #1208.
In #1208, sendmmsg() / recvmmsg() were added, but OpenBSD(who doesn't support these)
was included on the list of allowed operating systems for sendmmsg() related things.
This broke the build on OpenBSD.

For more Rust-world examples, see: 6f6297301d
2020-05-26 15:20:39 -04:00
Alan Somers
a937988d7c Fix an "unused import" warning on FreeBSD in test_scm_credentials 2020-05-03 09:56:41 -06:00
Greg V
b2a9c4f18c Add UnixCredentials support on FreeBSD/DragonFly (cmsgcred/SCM_CREDS) 2020-05-02 20:20:35 +03:00
Gleb Pomykalov
833369b241 Support sendmmsg/recvmmsg 2020-04-26 03:07:03 +03:00
Gleb Pomykalov
b1b64ee4a7 Support UDP GSO and GRO on linux 2020-04-25 23:45:50 +03:00
Alan Somers
6cc90b31e2 ScmCredentials now wraps UnixCredentials instead of libc::ucred 2019-12-01 17:26:23 -07:00
Alan Somers
e10e5373e8 Fix sys::socket::recvfrom for TCP sockets
recvfrom(2) only returns the sender's address for protocols that provide
it.  Usually, that means it returns the sender's address for datagram
sockets but not for stream sockets.

Fixes #1144
2019-10-28 20:57:52 -06:00