casaroli opened a new pull request, #22469: URL: https://github.com/apache/nuttx/pull/22469
## Summary `socketpair()` gives both ends an internal name, and the FIFOs of the pair get their names from it. The name was "socketpair" and a hexadecimal number that was different in each build and each run. The name shows in `F_GETPATH` and `FIOC_FILEPATH` (`local:[name]`), in the file list of `/proc/<pid>/group/fd` and in the FIFO names in `CONFIG_NET_LOCAL_VFS_PATH`, so these outputs were long and changed from run to run. Now the name is "socketpair" and a decimal number from a counter (`socketpair0`, `socketpair1`, ...). The counter changes under the lock of the local sockets and keeps the name unique, as before. The names are short and the same in each run for the same order of `socketpair()` calls. The second commit stops `local_findconn()` (the lookup by name of `bind()`, `connect()` and `sendto()` of a datagram socket) from finding the ends of socket pairs. A pair has no name for the program (`getsockname()` gives an unnamed address), but `connect()` of a datagram socket to the internal name succeeded, a `sendto()` found an end of the pair, and `bind()` of that name failed with `EADDRINUSE`. Now `connect()` and `sendto()` to the name fail with `ENOENT`, as for any name with no socket, and `bind()` of the name succeeds. `local_peerconn()` matches a pair end only with a pair end. ## Impact The internal name of a socket pair changes (the output of `F_GETPATH`, `/proc/<pid>/group/fd` and the FIFO names), and a lookup by name no longer finds a socket pair. No API, ABI or Kconfig change. The same in all build modes and on all architectures. ## Testing New cases in `cmocka_net_local_dgram` (apache/nuttx-apps#NNNN, need `CONFIG_FS_IOCTL_FILEPATH`): `test_local_dgram_pair_path`: `F_GETPATH` of both ends of a pair gives `local:[socketpairN]` with a decimal N, the same for both ends, and another N for the next pair. `test_local_dgram_pair_noname`: `connect()` and `sendto()` of a datagram socket to that name fail with `ENOENT`, `bind()` of the name succeeds, and the pair still works. On qemu-armv8a:nsh (flat), Arm GNU 13.2, QEMU TCG: | | master | this PR | |---|---|---| | test_local_dgram_pair_path | FAILED (the number is not decimal) | PASSED | | test_local_dgram_pair_noname | FAILED (the name check; with commit 1 only: the `connect()` returns 0) | PASSED | | the other cases of cmocka_net_local_dgram | 91 PASSED | 91 PASSED | Builds with `-Werror` in the CI image, with local stream and datagram sockets: qemu-armv8a:nsh (flat), qemu-armv8a:knsh (kernel, with the apps), rv-virt:netnsh64 (flat), rv-virt:knetnsh64 (kernel, with the apps). -- 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]
