Commit Graph

673 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
SteveLauC
1c189d99bc
feat: Add associated constants UTIME_OMIT UTIME_NOW to TimeSpec (#1879)
* feat: support UTIME_NOW & UTIME_OMIT

* fmt

* fmt

* linux x32 type cast

* fmt
2023-12-10 00:27:36 +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
SteveLauC
8708d5b3b7
refactor: some clippy warnings (#2250) 2023-12-08 18:51:50 +00:00
Samuel Thibault
a90b4b215f
Add GNU/Hurd support (#2131) 2023-12-08 18:51:35 +00:00
David CARLIER
da451400ea
sys::sendfile adding solaris' sendfilev wrapper proposal. (#2207) 2023-12-04 06:28:48 +00:00
David CARLIER
3a20eef318
FreeBSD's rfork wrapper proposal (#2121) 2023-12-04 06:24:21 +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
Chris
9b39cf9f0e
Added Flock object for automatic unlock on drop. (#2170)
* Added  object for automatic unlock on drop.

* Added appropriate changelog file.

* Fixed doc error on `Flock`.

* Requested changes to make `fcntl::flock` private and OwnedFd instead of RawFd.

* Indent fix.

* Removed doc links to private item, updated imports.

* More import fixes.

* Format changes.

* Remove unused import for redox.

* Added `Flockable` trait per discussions, added tests for `Flock`.

* Simplified flock error conditionals.

* Added missing cfg flags for `Flockable`.

* Added missing cfg flags for impl of `Flockable` on `File`.

* Update src/fcntl.rs

Co-authored-by: SteveLauC <stevelauc@outlook.com>

* Updated `Flockable` comment per suggestion.

* Finalized `FlockArg` as enum and removed TODO accordingly, removed flock wrapper entirely.

* Implemented `Flockable` for `OwnedFd` as well.

* Fixed linting error.

* Updated changelog accordingly.

* Corrected errno logic in `Flock::lock`.

* Properly dropped inner type for `Flock`.

* Replaced `ManuallyDrop` with `Option` as inner `Flock` type to avoid double-free.

* Fixed linting errors.

* Removed unnecessary cfg condition, updated documentation.

* Modified Flock behavior for drop() and unlock().

* Reverted changes to original `flock()` and `FlockArg` for deprecation period, added EINVAL case if the unlock operation is given to `Flock::lock()`.

* Refactored `Flock` to wrap T directly and avoid a double-free after `unlock()` is used.

* Fixed linting errors.

* More linting fixes.

* Fixed example code for `Flock::unlock()`.

* Made requested changes.

* Removed duplicate import.

* Format change.

---------

Co-authored-by: SteveLauC <stevelauc@outlook.com>
2023-12-03 03:06:23 +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
7e16e32c93
feat: Safer poll timeout (#1876) 2023-11-23 01:15:30 +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
David CARLIER
b5e1a76e22
fcntl adding few apple extensions (#2155) 2023-11-06 06:15:35 +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
SteveLauC
e5cc5cea46
refactor: change dirfd arg of xxxat() to Option<fd> (#2157)
* refactor: change dirfd arg of xxxat() to Option<fd>

* changelog

* gate at_rawfd() with features fs or process

* fix import

* fix test on Android

* simplify at_rawfd()

* update changelog
2023-11-05 06:02:40 +00:00
David CARLIER
ed3ed6ba4f
fcntl update following up with F_GETPATH but with FreeBSD's F_KINFO flag support instead (#2152) 2023-10-06 00:47:14 +00:00
David CARLIER
68c230b37e
fcntl add F_GETPATH support for apple/netbsd/dragonfly (#2142)
* fcntl add F_GETPATH support for apple/netbsd

* changes from review

* CHANGELOG entry

---------

Co-authored-by: SteveLauC <stevelauc@outlook.com>
2023-10-03 09:16:32 +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
ea888247b7
Relax lifetime requirements for PollFd::new (#2134)
* Relax lifetime requirements for PollFd::new

Fixes #2118

* Take BorrowedFd as the argument for PollFd::new

&AsFd didn't work because there are 'static types, like std::fs::File,
which implement AsFd.  The created BorrowedFd type within the
PollFd::new method would have a very brief lifetime, but the PhantomData
would capture the lifetime of the std::fs::File.  Taking BorrowFd<'fd>
argument makes the lifetime explicit.

* fix legacy comment

---------

Co-authored-by: Steve Lau <stevelauc@outlook.com>
2023-10-01 11:30:52 +00:00
Carlos B
489621e86a
Changed signature for openat function (#2139)
* Changed signature for openat function

Signed-off-by: carlosb1 <mcflurry0@gmail.com>

* Fixed tests for openat to apply Options

Signed-off-by: carlosb1 <mcflurry0@gmail.com>

* Updated changelog

Signed-off-by: carlosb1 <mcflurry0@gmail.com>

* Fixed num PR

Signed-off-by: carlosb1 <mcflurry0@gmail.com>

---------

Signed-off-by: carlosb1 <mcflurry0@gmail.com>
2023-10-01 11:20:45 +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
William Woodruff
90e3c3a1ef
unistd: make getpeereid take AsFd rather than a raw FD (#2137)
* unistd: make getpeereid take AsFd rather than a raw FD

`AsFd` returns a `BorrowedFd` that is correct by construction,
meaning that this API rejects more error states at the type
level (such as passing in `fd = -1`).

* CHANGELOG: record changes

* unistd: pass AsFd impl by value

* unistd: more AsFd usage

* CHANGELOG: update changes
2023-09-30 04:00:37 +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
Chris
a0613ba0e6
Changed name parameter of mqueue functions to be generic over NixPath. (#2102)
* Changed `name` parameter of `mq_open` and `mq_unlink` to be generic over `NixPath`.

* Updated with PR link.

* Fixed docs example code.

* Fixed docs example code for real this time.
2023-08-26 18:30:36 +00:00
Alan Somers
b4836ead0a
Merge pull request #2095 from asomers/recvmsg-lifetime
Fix an incorrect lifetime in the return value of recvmsg
2023-08-19 02:57:36 +00:00
Alan Somers
9304788f22
Merge pull request #1906 from asomers/copy_file_range
Expose copy_file_range on FreeBSD and use I/O Safety
2023-08-11 16:48:18 +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
5d55d8f12f Use AsFd in copy_file_range
And expose it on FreeBSD
2023-08-11 09:21:38 -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