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

   ## Summary
   
   `tun_read()` and `tun_write()` ignored the result of `nxsem_wait()` and 
waited again. A signal did not end a `read()` of the TUN device that waits for 
a packet, or a `write()` that waits until the reader takes the reply of the 
stack, and `pthread_cancel()` did not end the thread there. Linux returns 
`EINTR` (or restarts the call with `SA_RESTART`).
   
   Now both return the error of `nxsem_wait()` (`-EINTR`, `-ECANCELED`). 
Nothing was read or written at that point. The wait flag stays set: it is 
shared by all waiters of the device, and a later notification only wakes the 
next `read()` or `write()` once, which checks the buffers and waits again.
   
   The test cases will follow in a separate apps PR.
   
   ## Impact
   
   A signal ends a blocked `read()` / `write()` of `/dev/tun` with `EINTR`. No 
API, ABI or Kconfig change. Only `CONFIG_NET_TUN`. The same in all build modes 
and on all architectures.
   
   ## Testing
   
   `cmocka_net_tun` with the new cases `test_tun_signal_read` and 
`test_tun_signal_write` (SIGUSR1 handler without `SA_RESTART`, the signal after 
200 ms; if the call does not end, the case takes the interface down after 2 s), 
qemu-armv8a:nsh (flat, CI image gcc 12.3, QEMU TCG):
   
   | | master | this PR |
   |---|---|---|
   | test_tun_signal_read | FAIL: the read() went on waiting until the 
interface went down | pass |
   | test_tun_signal_write | FAIL | pass |
   | test_tun_tcp_lossy | pass | pass |
   
   Builds with `-Werror`: qemu-armv8a:netnsh and rv-virt:netnsh with 
`cmocka_net_tun`, rv-virt:knetnsh64 (kernel) and qemu-armv8a:knsh (kernel) with 
`CONFIG_NET_TUN`, qemu-armv8a:nsh.
   


-- 
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] drivers/net/tun.c: Let a... casaroli (via GitHub) via commits

Reply via email to