From: Allison Henderson <achender@kernel.org>
To: netdev@vger.kernel.org
Cc: linux-kselftest@vger.kernel.org, pabeni@redhat.com,
edumazet@google.com, rds-devel@oss.oracle.com, kuba@kernel.org,
horms@kernel.org, linux-rdma@vger.kernel.org,
allison.henderson@oracle.com
Subject: [PATCH net-next v2 3/4] net/rds: Use proper peer port number even when not connected
Date: Sat, 7 Feb 2026 22:37:15 -0700 [thread overview]
Message-ID: <20260208053716.1617809-4-achender@kernel.org> (raw)
In-Reply-To: <20260208053716.1617809-1-achender@kernel.org>
From: Greg Jumper <greg.jumper@oracle.com>
The function rds_tcp_get_peer_sport() should return the peer port of a
socket, even when the socket is not currently connected, so that RDS
can reliably determine the MPRDS "lane" corresponding to the port.
rds_tcp_get_peer_sport() calls kernel_getpeername() to get the port
number; however, when paths between endpoints frequently drop and
reconnect, kernel_getpeername() can return -ENOTCONN, causing
rds_tcp_get_peer_sport() to return an error, and ultimately causing
RDS to use the wrong lane for a port when reconnecting to a peer.
This patch modifies rds_tcp_get_peer_sport() to directly call the
socket-specific get-name function (inet_getname() in this case) that
kernel_getpeername() also calls. The socket-specific function offers
an additional argument which, when set to a value greater than 1,
causes the function to return the socket's peer name even when the
socket is not connected, which in turn allows rds_tcp_get_peer_sport()
to return the correct port number.
Signed-off-by: Greg Jumper <greg.jumper@oracle.com>
Signed-off-by: Allison Henderson <achender@kernel.org>
---
net/rds/tcp_listen.c | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/net/rds/tcp_listen.c b/net/rds/tcp_listen.c
index 8fb8f7d26683..db4938fd1672 100644
--- a/net/rds/tcp_listen.c
+++ b/net/rds/tcp_listen.c
@@ -67,7 +67,14 @@ rds_tcp_get_peer_sport(struct socket *sock)
} saddr;
int sport;
- if (kernel_getpeername(sock, &saddr.addr) >= 0) {
+ /* Call the socket's getname() function (inet_getname() in this case)
+ * with a final argument greater than 1 to get the peer's port
+ * regardless of whether the socket is currently connected.
+ * Using peer=2 will get the peer port even during reconnection states
+ * (TCPF_CLOSE, TCPF_SYN_SENT). This avoids -ENOTCONN while
+ * inet_dport still contains the correct peer port.
+ */
+ if (sock->ops->getname(sock, &saddr.addr, 2) >= 0) {
switch (saddr.addr.sa_family) {
case AF_INET:
sport = ntohs(saddr.sin.sin_port);
--
2.43.0
next prev parent reply other threads:[~2026-02-08 5:37 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-08 5:37 [PATCH net-next v2 0/4] net/rds: RDS-TCP reconnect and fanout improvements Allison Henderson
2026-02-08 5:37 ` [PATCH net-next v2 1/4] net/rds: Refactor __rds_conn_create for blocking transport cleanup Allison Henderson
2026-02-08 5:37 ` [PATCH net-next v2 2/4] net/rds: Delegate fan-out to a background worker Allison Henderson
2026-02-08 5:37 ` Allison Henderson [this message]
2026-02-08 5:37 ` [PATCH net-next v2 4/4] net/rds: rds_sendmsg should not discard payload_len Allison Henderson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260208053716.1617809-4-achender@kernel.org \
--to=achender@kernel.org \
--cc=allison.henderson@oracle.com \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux-rdma@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=rds-devel@oss.oracle.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.