casaroli opened a new pull request, #22430:
URL: https://github.com/apache/nuttx/pull/22430

   ## Summary
   
   - Commit 1 (TCP): a blocking `accept()` ignored the receive timeout 
(`SO_RCVTIMEO`) and waited for ever: `psock_tcp_accept()` waited with 
`UINT_MAX`. It now waits for the receive timeout of the listener and returns 
`EAGAIN` when it expires, as Linux and the usrsock `accept()` of NuttX do. A 
connection that comes after the wait ended (timeout or signal), before 
`accept()` takes the lock of the listener again, is now returned. Before, the 
accept callback had already taken it, `accept()` returned the error, and 
nothing freed the connection.
   - Commit 2 (local stream sockets): the same timeout in `local_waitlisten()`.
   - Commit 3: `accept4()` gave the address family a pointer into the buffer of 
the caller for the address of the peer (with `CONFIG_MM_KMAP` a kernel mapping 
of `sizeof(struct sockaddr)` bytes of it), and a blocking TCP `accept()` writes 
the address from the event handler of the network stack. Now the address family 
writes into a zeroed `struct sockaddr_storage` of `accept4()`, and `accept4()` 
copies the address to the caller when the call returns, in the context of the 
caller: at most `*addrlen` bytes, and `*addrlen` gives the length of the whole 
address. POSIX: "If the actual length of the address is greater than the length 
of the supplied sockaddr structure, the stored address shall be truncated." 
Before, an IPv4 or IPv6 socket returned `EINVAL` for a buffer shorter than its 
address. `addr` without `addrlen` gives `EFAULT`, as on Linux. In a kernel 
build `accept4()` returns `EFAULT` if `addr` or `addrlen` is not user memory, 
as with `CONFIG_MM_KMAP` before.
   - Commit 4: the documentation of `accept()`.
   
   ## Impact
   
   `accept()` with `SO_RCVTIMEO` now returns `EAGAIN` after the timeout instead 
of waiting for ever. `accept()` with a buffer shorter than the address now 
succeeds and truncates the address (POSIX, Linux) instead of failing with 
`EINVAL`. Without `SO_RCVTIMEO`, and with a buffer large enough, nothing 
changes. No API, ABI or Kconfig change; one `struct sockaddr_storage` (128 
bytes) on the stack of `accept4()`. Common code: the same in flat, protected 
and kernel builds and on all architectures.
   
   ## Testing
   
   New cases (apache/nuttx-apps#NNNN): `test_tcp_accept_rcvtimeo` and 
`test_tcp_accept_addrlen` in `cmocka_net_tcp`, `test_local_accept_rcvtimeo` in 
`cmocka_net_local`.
   
   Each boot ran `cmocka_net_local`, `cmocka_net_tun` and `cmocka_net_tcp`, 
with the cases of this PR and of #22429 (the `connect()` PR) in the apps tree 
(CI image, gcc 12.3, 64 devif callbacks):
   
   | Config | master 453cafdc4dd | this PR (flat and x86_64: with #22429 too) |
   |---|---|---|
   | qemu-armv8a:knsh (kernel), QEMU TCG, 3 boots | `test_tcp_accept_rcvtimeo` 
and `test_local_accept_rcvtimeo` FAIL (`accept()` waits until a client connects 
after 3 s), `test_tcp_accept_addrlen` FAIL (`EINVAL` for a buffer of 8 bytes), 
in 3 of 3 | all 3 pass in 3 of 3; `ostest` passes |
   | qemu-armv8a:nsh (flat), TCG, 1 boot | the same 3 FAIL | all 3 pass |
   | qemu-intel64:knsh_romfs (kernel, CMake), KVM, 1 boot | the same 3 FAIL | 
all 3 pass |
   
   The other cases give the same result with and without this PR. 
`test_tcp_close_timewait` fails on both (fixed by apache/nuttx-apps#4143). 
`test_tcp_reset_send` fails on both in the flat build and on x86_64 (`SIGPIPE` 
goes to another thread).
   
   Builds with `-Werror` (CI image): qemu-armv8a:knsh and :nsh, rv-virt:knsh 
and :nsh (32-bit), qemu-intel64:knsh_romfs (CMake), with TCP, TUN, local and 
UDP sockets; the touched files also without `CONFIG_NET_SOCKOPTS` 
(qemu-armv8a:nsh: they compile with no warning). Protected build: not built 
(common code, no build-mode test besides the kernel-build `uaccess_ok()` check).
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

  • [PR] net: Honour SO_RCVTIMEO ... casaroli (via GitHub) via commits

Reply via email to