Repository navigation
Conversation
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: the
first pair is socketpair0, the next socketpair1. The counter keeps the
name unique, as before, and changes under the lock of the local
sockets. The names are short and the same in each run for the same
order of socketpair() calls.
The behavior is the same in all build modes.
Assisted-by: Claude Code:claude-opus-5-5
Signed-off-by: Marco Casaroli <marco.casaroli@gmail.com>
local_findconn() finds a local socket by its name for bind(), connect() and sendto() of a datagram socket. It also compared the internal name of a socket pair. So connect() of a datagram socket to the name "socketpairN" succeeded, a sendto() to it found an end of the pair, and bind() of that name failed with EADDRINUSE. A socket pair has no name for the program: getsockname() gives an unnamed address. Now local_findconn() skips the ends of socket pairs: a pair end is found only through its pair. 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, so a socket bound to that name is never taken for the peer of a pair. The behavior is the same in all build modes. Assisted-by: Claude Code:claude-opus-5-5 Signed-off-by: Marco Casaroli <marco.casaroli@gmail.com>
|
|
|
||
| static int local_socketpair(FAR struct socket *psocks[2]) | ||
| { | ||
| static uint32_t g_next_pair_id; |
Contributor
There was a problem hiding this comment.
change to atomic_t
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 inF_GETPATHandFIOC_FILEPATH(local:[name]), in the file list of/proc/<pid>/group/fdand in the FIFO names inCONFIG_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 ofsocketpair()calls.The second commit stops
local_findconn()(the lookup by name ofbind(),connect()andsendto()of a datagram socket) from finding the ends of socket pairs. A pair has no name for the program (getsockname()gives an unnamed address), butconnect()of a datagram socket to the internal name succeeded, asendto()found an end of the pair, andbind()of that name failed withEADDRINUSE. Nowconnect()andsendto()to the name fail withENOENT, as for any name with no socket, andbind()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/fdand 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#4175, needCONFIG_FS_IOCTL_FILEPATH):test_local_dgram_pair_path:F_GETPATHof both ends of a pair giveslocal:[socketpairN]with a decimal N, the same for both ends, and another N for the next pair.test_local_dgram_pair_noname:connect()andsendto()of a datagram socket to that name fail withENOENT,bind()of the name succeeds, and the pair still works. On qemu-armv8a:nsh (flat), Arm GNU 13.2, QEMU TCG:connect()returns 0)Builds with
-Werrorin 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).