Skip to content

Commit

Permalink
mptcp: sockopt: info: stop early if no buffer
Browse files Browse the repository at this point in the history
Up to recently, it has been recommended to use getsockopt(MPTCP_INFO) to
check if a fallback to TCP happened, or 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 length, 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.

Reviewed-by: Mat Martineau <martineau@kernel.org>
Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
Signed-off-by: Mat Martineau <martineau@kernel.org>
Link: https://lore.kernel.org/r/20240514011335.176158-4-martineau@kernel.org
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
  • Loading branch information
Matthieu Baerts (NGI0) authored and Jakub Kicinski committed May 14, 2024
1 parent bd11dc4 commit ce5f6f7
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions net/mptcp/sockopt.c
Original file line number Diff line number Diff line change
Expand Up @@ -999,6 +999,10 @@ static int mptcp_getsockopt_info(struct mptcp_sock *msk, char __user *optval, in
if (get_user(len, optlen))
return -EFAULT;

/* When used only to check if a fallback to TCP happened. */
if (len == 0)
return 0;

len = min_t(unsigned int, len, sizeof(struct mptcp_info));

mptcp_diag_fill_info(msk, &m_info);
Expand Down

0 comments on commit ce5f6f7

Please sign in to comment.