All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH mptcp-next] mptcp: sockopt: info: stop early if no buffer
@ 2024-04-18 16:12 Matthieu Baerts (NGI0)
  2024-04-18 16:58 ` MPTCP CI
  2024-04-18 17:06 ` Mat Martineau
  0 siblings, 2 replies; 4+ messages in thread
From: Matthieu Baerts (NGI0) @ 2024-04-18 16:12 UTC (permalink / raw)
  To: mptcp; +Cc: Matthieu Baerts (NGI0)

Up to recently, it has been recommended to use getsockopt(MPTCP_INFO) on
an 'accept'ed socket, for a server app to check if the client requested
to use MPTCP.

In this case, the userspace app is only interested by the returned value
of the getsocktop() call, and can then give 0 for the option lenght, and
NULL for the buffer address. An easy optimisation is then to stop early,
and avoid filling a local buffer -- which now requires two different
locks -- if it is not needed.

Note that userspace apps should use getsockopt(SO_PROTOCOL) in such case
instead: it looks less like a workaround, and it works with any kernel
versions, while the MPTCP_INFO method requires kernels >= v5.16.

Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
---
 net/mptcp/sockopt.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/net/mptcp/sockopt.c b/net/mptcp/sockopt.c
index 1fea43f5b6f3..b0d1dc4df0c1 100644
--- a/net/mptcp/sockopt.c
+++ b/net/mptcp/sockopt.c
@@ -960,6 +960,12 @@ static int mptcp_getsockopt_info(struct mptcp_sock *msk, char __user *optval, in
 	if (get_user(len, optlen))
 		return -EFAULT;
 
+	/* Opti when used to check if a fallback to TCP happened on an 'accept'
+	 * socket. Userspace apps should use getsockopt(SO_PROTOCOL) instead.
+	 */
+	if (len == 0)
+		return 0;
+
 	len = min_t(unsigned int, len, sizeof(struct mptcp_info));
 
 	mptcp_diag_fill_info(msk, &m_info);

---
base-commit: 69582b96be671a6d87ab1e96e86c26225f1ec12a
change-id: 20240418-mptcp-getsockopt-info-opti-1232118bb417

Best regards,
-- 
Matthieu Baerts (NGI0) <matttbe@kernel.org>


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

end of thread, other threads:[~2024-04-19 10:01 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-04-18 16:12 [PATCH mptcp-next] mptcp: sockopt: info: stop early if no buffer Matthieu Baerts (NGI0)
2024-04-18 16:58 ` MPTCP CI
2024-04-18 17:06 ` Mat Martineau
2024-04-19 10:01   ` Matthieu Baerts

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.