Commit Graph

386 Commits

Author SHA1 Message Date
Alan Somers
5102376164
Add the ListenQLimit sockopt (SO_LISTENQLIMIT) (#2263) 2023-12-16 03:59:07 +00:00
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
26b070a058
test: enable test_aio_suspend on both Linux and macOS (#2262) 2023-12-11 17:45:33 +00:00
sgasse
a09971fd10
Fix setting sockopt::IpMulticastTtl (#2072)
* Fix the value of optlen as passed to libc::setsockopt

Ever since the sockopt macro was written in
979faf0976 we've been passing the wrong
size for u8 and usize sockopts.

* Add tests for sockopt::IpMulticastTtl #2073

On Linux and Android, sockopt::IpMulticastTtl can be set for both IPv4
and IPv6 sockets, but not on FreeBSD.

---------

Co-authored-by: Alan Somers <asomers@gmail.com>
Co-authored-by: Simon B. Gasse <sgasse@users.noreply.github.com>
2023-12-09 16:18: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
David CARLIER
2ab5558e08
fix, mostly, solaris build. (#2248)
With few exceptions as newer interfaces like preadv/pwritev unsupported
only on solaris.
2023-12-08 19:29:11 +00:00
Samuel Thibault
a90b4b215f
Add GNU/Hurd support (#2131) 2023-12-08 18:51:35 +00:00
sgasse
75bddf255a
Add Ipv6MulticastHops as socket option (#2234) (#2234)
Co-authored-by: Simon B. Gasse <sgasse@users.noreply.github.com>
2023-12-04 02:43:07 +00:00
Alan Somers
cb56e89aab
Ensure all tests use unique IP ports (#2196) 2023-12-03 23:02:26 +00:00
Daniil Bondarev
db5353cae0
Added TcpFastOpenConnect sockopt (#2247)
From [tcp](https://man7.org/linux/man-pages/man7/tcp.7.html) man page:
```
TCP_FASTOPEN_CONNECT (since Linux 4.11)
       This option enables an alternative way to perform Fast
       Open on the active side (client).  When this option is
       enabled, connect(2) would behave differently depending on
       if a Fast Open cookie is available for the destination.

       If a cookie is not available (i.e. first contact to the
       destination), connect(2) behaves as usual by sending a SYN
       immediately, except the SYN would include an empty Fast
       Open cookie option to solicit a cookie.

       If a cookie is available, connect(2) would return 0
       immediately but the SYN transmission is deferred.  A
       subsequent write(2) or sendmsg(2) would trigger a SYN with
       data plus cookie in the Fast Open option.  In other words,
       the actual connect operation is deferred until data is
       supplied.

       Note: While this option is designed for convenience,
       enabling it does change the behaviors and certain system
       calls might set different errno values.  With cookie
       present, write(2) or sendmsg(2) must be called right after
       connect(2) in order to send out SYN+data to complete 3WHS
       and establish connection.  Calling read(2) right after
       connect(2) without write(2) will cause the blocking socket
       to be blocked forever.

       The application should either set TCP_FASTOPEN_CONNECT
       socket option before write(2) or sendmsg(2), or call
       write(2) or sendmsg(2) with MSG_FASTOPEN flag directly,
       instead of both on the same connection.

       Here is the typical call flow with this new option:

           s = socket();
           setsockopt(s, IPPROTO_TCP, TCP_FASTOPEN_CONNECT, 1, ...);
           connect(s);
           write(s); /* write() should always follow connect()
                      * in order to trigger SYN to go out. */
           read(s)/write(s);
           /* ... */
           close(s);
```
2023-12-03 23:01:28 +00:00
Daniil Bondarev
3b1ae36c26
Added IpBindAddressNoPort sockopt (#2244)
From [man page](https://man7.org/linux/man-pages/man7/ip.7.html):
```
IP_BIND_ADDRESS_NO_PORT (since Linux 4.2)
       Inform the kernel to not reserve an ephemeral port when
       using bind(2) with a port number of 0.  The port will
       later be automatically chosen at connect(2) time, in a way
       that allows sharing a source port as long as the 4-tuple
       is unique.
```
2023-12-02 22:01:43 +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
Aurélien Deharbe
755c66d275
Add fanotify API wrappers (#2194)
* Add fanotify API wrappers

* Review/fix enum comments

* Rename has_compile_version to check_version

* Fix lint unsafe_block_in_unsafe_fn

* Rename fanotify OFlags to EventFFlags

* Use existing function at_rawfd from fcntl

* Add missing feature guard for docs

* Change FanotifyEvent struct to a simple wrapper over libc structure

* Change FanotifyResponse struct to a simple wrapper over libc structure

* Cast pointer with function 'cast' instead of 'as'

* Add FAN_REPORT_PIDFD and FAN_REPORT_TID fanotify init flags
2023-11-23 02:49:57 +00:00
Jonathan Woollett-Light
1ea59c7d7b
feat: mman NonNull (#2000)
* feat: mmap `NonNull`

* feat: munmap `NonNull`

* feat: mremap `NonNull`

* feat: madvise `NonNull`

* feat: msync `NonNull`

* feat: mprotect `NonNull`

* feat: munlock `NonNull`

* feat mlock `NonNull`
2023-11-13 20:40:59 +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
Artyom Pavlov
a388118870
Add mmap_anonymous function (#2127)
* Add `mmap_anonymous` function

* Add changelog note

* Add changelog note for mmap change
2023-11-05 13:34:57 +00:00
Alan Somers
591e2ed4f5
Fix SignalFd::set_mask (#2141)
In 0.27.0 it inadvertently closed the file descriptor, leaving the
SignalFd object accessing a stale file descriptor.

Fixes #2116
2023-10-02 02:28:34 +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
c4ba877820
Relax lifetime requirements for FdSet::{insert, remove, contains} (#2136)
* Relax lifetime requirements for FdSet::{insert, remove, contains}

Fixes #2130

* Take BorrowedFd as the argument for FdSet::{insert, remove, contains}

&AsFd doesn't work because there are 'static types, like std::fs::File,
which implement AsFd.

* fix changelog & remove unused entries

* fix wrong PR number

---------

Co-authored-by: Steve Lau <stevelauc@outlook.com>
2023-10-01 10:51:07 +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
Daniel Ohlsson
3a4037c8b9
Added support for prctl in Linux (#1550) 2023-08-27 21:34:43 +00:00
Alan Somers
d59d2353e4
Eliminate the lazy_static dev dependency (#2107)
It's no longer needed, because for several versions now AtomicBool::new
and parking_lot::Mutex::new are const functions.

Fixes #1791
2023-08-27 21:34:26 +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
6fb3a8fcaa
Merge pull request #2094 from asomers/clippy-aug-11-2023
Clippy cleanup: noop_method_call
2023-08-11 15:43:32 +00:00
Alan Somers
18cbec28a8 Clippy cleanup: noop_method_call 2023-08-11 09:24:01 -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
Armin Ronacher
960199daf9 Try enabling LocalPeerPid for ios 2023-01-15 22:41:33 +01:00
Armin Ronacher
34788b179b Added changelog entry and test for LocalPeerPid 2023-01-14 19:51:00 +01:00
bors[bot]
99ea907d7d
Merge #1944
1944: Rework vsock test r=asomers a=stefano-garzarella

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>

Co-authored-by: Stefano Garzarella <sgarzare@redhat.com>
2022-12-14 14:37:34 +00: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
Steve Lau
2be852de8e feat: I/O safety for 'sys/select' 2022-12-12 14:18:49 +08:00
bors[bot]
3d3e6b9fa0
Merge #1913 #1926 #1927 #1931 #1933
1913: feat: I/O safety for 'sys/inotify' r=asomers a=SteveLauC

#### What this PR does:

1. Changes the `fd` field of `struct Inotify` from `RawFd` to `OwnedFd`
2. Changes the interfaces of functions in the `impl Inotify {}`
   
    > The type of `self` changes from `Self` to `&mut Self`. 
    
    From:

   ```rust
   pub fn add_watch<P: ?Sized + NixPath>(
         self,
         path: &P,
         mask: AddWatchFlags,
   ) -> Result<WatchDescriptor> 

   pub fn rm_watch(self, wd: WatchDescriptor) -> Result<()>

   pub fn read_events(self) -> Result<Vec<InotifyEvent>>
   ```

   To:

   ```rust
   pub fn add_watch<P: ?Sized + NixPath>(
        &mut self,
        path: &P,
        mask: AddWatchFlags,
    ) -> Result<WatchDescriptor>

   pub fn rm_watch(&mut self, wd: WatchDescriptor) -> Result<()>

   pub fn read_events(&mut self) -> Result<Vec<InotifyEvent>>
   ```
  

   In the previous implementation, these functions can take `self` by value as `struct Inotify` [was `Copy`](https://docs.rs/nix/latest/nix/sys/inotify/struct.Inotify.html#impl-Copy-for-Inotify). With the changes in `1` applied, `struct Inotify` is no longer `Copy`, so we have to take `self` by reference.

-------

Blocks until the merge of #1863 as this PR needs `read(2)` to be I/O-safe.


1926: feat: I/O safety for 'sys/sendfile' r=asomers a=SteveLauC

#### What this PR does:
1. Adds I/O safety for module `sys/sendfile`.

1927: feat: I/O safety for 'sys/statvfs' r=asomers a=SteveLauC

#### What this PR does:
1. Adds I/O safety for module `sys/statvfs`.

1931: feat: I/O safety for 'sys/uid' & 'sched' r=asomers a=SteveLauC

#### What this PR does:
Adds I/O safety for modules:

1. `sys/uio`
2. `sched`

1933: feat: I/O safety for 'sys/timerfd' r=asomers a=SteveLauC

#### What this PR does:
1. Adds I/O safety  for module `sys/timerfd`.

Co-authored-by: Steve Lau <stevelauc@outlook.com>
2022-12-09 16:43:33 +00:00
Steve Lau
8772cde9b8 feat: I/O safety for 'sys/uid' & 'sched' 2022-12-09 11:33:35 +08:00
Steve Lau
f5dffcc7f0 refactor: take AsFd by value 2022-12-09 11:02:30 +08:00
Steve Lau
8f52bc97c9 feat: I/O safety for 'sys/termios' & 'pty' 2022-12-08 14:04:22 +08:00
bors[bot]
67f7d46c6e
Merge #1916
1916: Use I/O safety in sys::mman r=rtzoeller a=asomers



Co-authored-by: Alan Somers <asomers@gmail.com>
2022-12-06 22:07:42 +00:00
Alan Somers
16a8c02983 Use I/O safety in sys::mman 2022-12-05 11:43:17 -07:00
Jonathan
4f61d12009 Epoll 2022-12-04 22:50:13 +00:00