Linux RDMA and InfiniBand development
 help / color / mirror / Atom feed
* [PATCH net v2] net/rds: include the scope id in the sendmsg connection cache check
@ 2026-09-27  6:23 Allison Henderson
  2026-09-27  6:32 ` sashiko-bot
  2026-10-01 15:26 ` netdev-bot+sashiko
  0 siblings, 2 replies; 4+ messages in thread
From: Allison Henderson @ 2026-09-27  6:23 UTC (permalink / raw)
  To: netdev, linux-rdma, pabeni, edumazet, kuba, horms; +Cc: achender

rds_sendmsg() reuses the connection cached in rs->rs_conn when its
peer address and ToS match the request.  The interface index is part
of a connection's identity as well: rds_conn_create_outgoing() passes
the request's scope_id down as dev_if, and rds_conn_lookup() compares
c_dev_if, so sends to the same link-local address through two
interfaces are two different connections.  The cache-hit test never
looked at it.

A socket bound to a non-link-local address has rs_bound_scope_id 0,
and the scope check at the top of rds_sendmsg() accepts any non-zero
destination scope for such a socket.  So after a send to fe80::x%ifA,
a send to fe80::x%ifB hits the cached ifA connection and the datagram
leaves through ifA, to whichever peer answers to that address there.

Compare c_dev_if with the request's scope_id in the cache test, so
that such a send takes the lookup path and finds, or creates, the ifB
connection.

A request without a scope keeps matching the cached connection.  A
send with a destination always carries one for a link-local peer, but
a send without a destination takes rs_bound_scope_id, and a bind() to
a non-link-local address after connect() to a link-local peer resets
that to 0.  Such a send never named an interface, so the connection
the socket last used is the one it means; making it miss the cache
would send it to look up a connection with no interface, which cannot
be established.

Fixes: 1e2b44e78eea ("rds: Enable RDS IPv6 support")
Assisted-by: Claude-Code:claude-fable-5
Signed-off-by: Allison Henderson <achender@kernel.org>
---
 net/rds/send.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/net/rds/send.c b/net/rds/send.c
index 1afa981e5c06..393898a079c1 100644
--- a/net/rds/send.c
+++ b/net/rds/send.c
@@ -1342,7 +1342,8 @@ int rds_sendmsg(struct socket *sock, struct msghdr *msg, size_t payload_len)
 	/* rds_conn_create has a spinlock that runs with IRQ off.
 	 * Caching the conn in the socket helps a lot. */
 	if (rs->rs_conn && ipv6_addr_equal(&rs->rs_conn->c_faddr, &daddr) &&
-	    rs->rs_tos == rs->rs_conn->c_tos) {
+	    rs->rs_tos == rs->rs_conn->c_tos &&
+	    (!scope_id || rs->rs_conn->c_dev_if == scope_id)) {
 		conn = rs->rs_conn;
 	} else {
 		conn = rds_conn_create_outgoing(sock_net(sock->sk),
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-10-03 16:44 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-27  6:23 [PATCH net v2] net/rds: include the scope id in the sendmsg connection cache check Allison Henderson
2026-09-27  6:32 ` sashiko-bot
2026-10-01 15:26 ` netdev-bot+sashiko
2026-10-03 16:44   ` Allison Henderson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox