From patchwork Wed May 29 10:00:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Matthieu Baerts (NGI0)" X-Patchwork-Id: 13678594 X-Patchwork-Delegate: matthieu.baerts@tessares.net Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 71F4B15B14A; Wed, 29 May 2024 10:00:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716976832; cv=none; b=aRdz/A11/u9UwJKSuhuFh0IJJ0f46miVtGJuaCx4UxgKY5cz/VEDHXrSRL3GxjQvptBi9blK5CFX+N+fSPBzR4KWxdr7l6+J1WIN6AVk0hdvwNW1aEqXsi4nFtoUQjj0badPhI0v6uv0adUJjZB3w2SH9adyFV4wmTthyogGOA8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716976832; c=relaxed/simple; bh=Rk9gBOSB9qQ7GfZ8l4CL9mV8J2UVvSan3Wcb93C07+s=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=RTlGntRaw3ANuP3DxNBbwlRaSjjGLXK0GM51DhdHmotS91fNjXldJTuUOUNdDMCI2yB/SiqrdXG4Q1IHf/XBsHlw8GCt1PQ/G4M2FuWcWpwRjR288awDLxuryLhMOyIvdCd1WICpBM7HTzXgPOlwNCtYvQmSDCyWWgCItbE88Vk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=jUl7jxpu; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="jUl7jxpu" Received: by smtp.kernel.org (Postfix) with ESMTPSA id E21F0C32786; Wed, 29 May 2024 10:00:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1716976831; bh=Rk9gBOSB9qQ7GfZ8l4CL9mV8J2UVvSan3Wcb93C07+s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jUl7jxpus2u1urqdyquSPSNLUsec8J3hO9FfYaL/wC7zH4qn4Qce8lLlsV45Z2eiu CrA1dJDHPLvzES39fE5Q7kUvu3J4yoz9evCoFwWOdglYIuX4sMVVLYGGKdZrZ+Hn0r ZurWKmsLRPa6X5IygIgherz8x4jFECn+s61DzPS0eV+7HVa1MPSGhzDGuxbua6HvHa nUquTM6tDidMhzCmNLb/4eNezUMSmyHNN+s+eCUaT7w4wp3rmvG2XjrcB1Ub6dsloS cXjS3z2+X63Ldcg1JvCtI9ZNyDeqpmJftgxDwcwYmQ8aFSty4GPV5zDeXhpg65eztR avmxCmWnGSA+g== From: "Matthieu Baerts (NGI0)" To: mptcp@lists.linux.dev, stable@vger.kernel.org, gregkh@linuxfoundation.org, sashal@kernel.org Cc: Paolo Abeni , Mat Martineau , Matthieu Baerts , "David S . Miller" Subject: [PATCH 6.1.y 1/3] mptcp: avoid some duplicate code in socket option handling Date: Wed, 29 May 2024 12:00:24 +0200 Message-ID: <20240529100022.3373664-6-matttbe@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240529100022.3373664-5-matttbe@kernel.org> References: <20240529100022.3373664-5-matttbe@kernel.org> Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1770; i=matttbe@kernel.org; h=from:subject; bh=eIbNr3+rvmmo94rZ8rIGWyjauvCrVEBoRbXK75Y7ADc=; b=owEBbQKS/ZANAwAIAfa3gk9CaaBzAcsmYgBmVvy29kgTEuVqS6b2K88/X8mkkMQCOSihYjVqB yjlQrlMWf6JAjMEAAEIAB0WIQToy4X3aHcFem4n93r2t4JPQmmgcwUCZlb8tgAKCRD2t4JPQmmg c8kBD/0UUbcNuUkBf9a3tsk5WAetXuB6illSqW0ntuHhTUZrWwXGhdtfOlZ7KtCGRXCepGoMsE1 CTcGZo/lzR5zgCf+sCsW2OvjyDYZhe0alLhyC7lizDtYICsy838vQg4yv2u11CXik1gb8gTIUfE 8G1F5L693EZ4BuEewoLT2TET4f7otDul7cRSrjQXbH35MkRXDf/t+ddPNYu6Ggek/VEswafc++e iKW4TZiND2ioeyOfQ+knL+iQSJOAz/H6bz/rMI5w7CMync1Xz8z1KOmuRZU+IvYVc8e2KxwUwfF LYmWhUzZCt0yiM+0/cS6IwZsKgV6lH6Fly4gGCwgjd4l3OI/H4MaPiS8PU8fEGLn136iJ2ICpKA GbpkfuZtPfdoceFkpb+XkkBEVd9ut77A9ycbnXr2qAr0Cj2DiMfsl1gIR3AdBlgVEejeyrYuOex DMfBr7LVHqkN/75YdjjyJCE7Cohmx4K7jjct0gYjgtPIqpGBeAnw41WlZUxfyCooi72XeBCMHh4 2h+tm9Xn3GrPTvYWNAYK8sdfI027tDgSkpesCQGC8Yfpa1zrZ6bUGPTjV07EtkNakpd8GCaTaFZ rjvm4qXcoPI3UKnUTJuR3hjg2He44zb1WtpjxbUM+puSCVu6ewmf4FYIhWfRHap/2ZAS2nm4ALO OVUq/2WACr/+L2Q== X-Developer-Key: i=matttbe@kernel.org; a=openpgp; fpr=E8CB85F76877057A6E27F77AF6B7824F4269A073 From: Paolo Abeni commit a74762675f700a5473ebe54a671a0788a5b23cc9 upstream. The mptcp_get_int_option() helper is needless open-coded in a couple of places, replace the duplicate code with the helper call. Signed-off-by: Paolo Abeni Reviewed-by: Mat Martineau Signed-off-by: Matthieu Baerts (NGI0) Signed-off-by: David S. Miller Stable-dep-of: bd11dc4fb969 ("mptcp: fix full TCP keep-alive support") Signed-off-by: Matthieu Baerts (NGI0) --- net/mptcp/sockopt.c | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/net/mptcp/sockopt.c b/net/mptcp/sockopt.c index e59e46e07b5c..c3967486ce69 100644 --- a/net/mptcp/sockopt.c +++ b/net/mptcp/sockopt.c @@ -621,13 +621,11 @@ static int mptcp_setsockopt_sol_tcp_cork(struct mptcp_sock *msk, sockptr_t optva { struct mptcp_subflow_context *subflow; struct sock *sk = (struct sock *)msk; - int val; + int val, ret; - if (optlen < sizeof(int)) - return -EINVAL; - - if (copy_from_sockptr(&val, optval, sizeof(val))) - return -EFAULT; + ret = mptcp_get_int_option(msk, optval, optlen, &val); + if (ret) + return ret; lock_sock(sk); sockopt_seq_inc(msk); @@ -651,13 +649,11 @@ static int mptcp_setsockopt_sol_tcp_nodelay(struct mptcp_sock *msk, sockptr_t op { struct mptcp_subflow_context *subflow; struct sock *sk = (struct sock *)msk; - int val; + int val, ret; - if (optlen < sizeof(int)) - return -EINVAL; - - if (copy_from_sockptr(&val, optval, sizeof(val))) - return -EFAULT; + ret = mptcp_get_int_option(msk, optval, optlen, &val); + if (ret) + return ret; lock_sock(sk); sockopt_seq_inc(msk); From patchwork Wed May 29 10:00:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Matthieu Baerts (NGI0)" X-Patchwork-Id: 13678595 X-Patchwork-Delegate: matthieu.baerts@tessares.net Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B180C15B14A; Wed, 29 May 2024 10:00:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716976834; cv=none; b=XIQhf6hSHkwKAvUPdvUcr49NVbd1ZGSy3DBMwZX9qW2rsmiIPOFLy7eEZSneQZHjOwPV2VA6ljyHhd8TebJtetfRPSufZAYBJv6Mf9XP+LtkDXd2XsozSumeQIFCvCIuKck1US8/fgaLho2++Q9cSbsFo9t/OTIWVr1N1i0Yqj8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716976834; c=relaxed/simple; bh=P3GGQZ8FeJ9o0UzU++dcb3MV7s7XyEVKCqT6702BOeY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NWyWsulch3QwOPrCUnOHYvaFjkEjDvdFf1WZnhnD/maKe2oeFUzlR2TL5lL+4kMGntiBnT9yBZGImSVIGFWB46y9Pk1c0qCtERbnE6+aY7Q3stP5ussS6DLB7TFxfDzi73xorVRJM1hVd4NFwLR/tmc5jjflH1KmMVh5rMrVdms= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ADXF72qs; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="ADXF72qs" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4FBF5C32789; Wed, 29 May 2024 10:00:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1716976834; bh=P3GGQZ8FeJ9o0UzU++dcb3MV7s7XyEVKCqT6702BOeY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ADXF72qsxr0KEL+qvxYJXBRTSXYnq7zw+6jWKjJ7A48m/e4ZuzAnpIgu3tJJNkdJv M8qimQ3RQDUqjvLkU25gfxawdkuN6DaEo+bGiu7fW6Uw4oEROvLDPgblkrk/J2JV7+ SDo4aBJ1QXH254PbP0fk+GdSaKoArBJ4vhe1BlfU8bFaF048du0NVcCSrl+Al2MMU0 n8FetvVufHh3HGzHC1hLarMR2S+X1T60okA4FG5mApMo78yLSQwuJsOSi2341tEVoF cPHdHLiJ+LomHV2WSwAmZbZi42sgWJxk8edKeCEV87Hc947jh+TosOUV1jxSkDGSYm 8nYVwcNmywrwg== From: "Matthieu Baerts (NGI0)" To: mptcp@lists.linux.dev, stable@vger.kernel.org, gregkh@linuxfoundation.org, sashal@kernel.org Cc: Paolo Abeni , Mat Martineau , Matthieu Baerts , "David S . Miller" Subject: [PATCH 6.1.y 2/3] mptcp: cleanup SOL_TCP handling Date: Wed, 29 May 2024 12:00:25 +0200 Message-ID: <20240529100022.3373664-7-matttbe@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240529100022.3373664-5-matttbe@kernel.org> References: <20240529100022.3373664-5-matttbe@kernel.org> Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=4108; i=matttbe@kernel.org; h=from:subject; bh=F2qBAcWKXtJVyJ4F8TA0qu8O2hTBKFZK1nxG+f37xPA=; b=owEBbQKS/ZANAwAIAfa3gk9CaaBzAcsmYgBmVvy3jOxhk+GvYM1VZp78S2xT64xVfSLRYPwFX brQ5rra16+JAjMEAAEIAB0WIQToy4X3aHcFem4n93r2t4JPQmmgcwUCZlb8twAKCRD2t4JPQmmg c7l2D/9jWJTdkf70hU7fk3dR9hnsymbYAXsA/4FY2KrKFWUdNP5o4jEz6r16OdR3QAWluu9I6kB 0apTj8naA+XINzeRP+tLsKzTLiokyQkoKx88lYmamWSebx5VNwtlxHcrUrViUkRtw7Rzbq7XFDh CsSLIhOfNTclOBYNxulaZ4lmoF8B/gpE98DUwUIuNmddxZuXz4R1QGQhXy0eUX2Eq/XNbSuuGwM nSPiT3VX8hb8L6NcqmO5p3DF/LoET75Gxzhq/ezk/fPLqmdww4j378m/X9M3iYe7L9Z12aKOkSG eP66csEDKbHYg4NCvMzoOfdxQHpvy1QEH5+7lrEm5uXXUJ2HNGbAaao/T3I5eSbo7/ZUTlFny33 W0rzw2Ytamc9RafpOPQgVTqHEKc7D/lkz/qnLCexIeO7vvmKh/9LYRqIMzAIgsnO5IU/kCkorG1 VqmBxriklZbLFS7g6139k1axcLFdixyhUD/cqIWbvDXjSeVdXate0byKqI9ZdqGLYE+i6+6KtrO 0ngoZ8eCyhDYOE+7lk7Z2NzW39l7B15/e16d9hoNo4tRxCGBm/Vk+kHNvM/t5wJ0m9mc5Zrx9Xc I4IfbJmbG9V6ww9ULF+3+pxb0bTbdrv8htDAF0HnZrJ8R/G2EEBRuwBetLb9HMZ2NU4L/FgHLQK HKrjA3h1ZwAVKjA== X-Developer-Key: i=matttbe@kernel.org; a=openpgp; fpr=E8CB85F76877057A6E27F77AF6B7824F4269A073 From: Paolo Abeni commit 7f71a337b5152ea0e7bef408d1af53778a919316 upstream. Most TCP-level socket options get an integer from user space, and set the corresponding field under the msk-level socket lock. Reduce the code duplication moving such operations in the common code. Signed-off-by: Paolo Abeni Reviewed-by: Mat Martineau Signed-off-by: Matthieu Baerts (NGI0) Signed-off-by: David S. Miller Stable-dep-of: bd11dc4fb969 ("mptcp: fix full TCP keep-alive support") [ Without TCP_NOTSENT_LOWAT support, as it is not in this version, see commit 29b5e5ef8739 ("mptcp: implement TCP_NOTSENT_LOWAT support") ] Signed-off-by: Matthieu Baerts (NGI0) --- net/mptcp/sockopt.c | 61 +++++++++++++++++++-------------------------- 1 file changed, 26 insertions(+), 35 deletions(-) diff --git a/net/mptcp/sockopt.c b/net/mptcp/sockopt.c index c3967486ce69..7573bbd15f84 100644 --- a/net/mptcp/sockopt.c +++ b/net/mptcp/sockopt.c @@ -616,18 +616,11 @@ static int mptcp_setsockopt_sol_tcp_congestion(struct mptcp_sock *msk, sockptr_t return ret; } -static int mptcp_setsockopt_sol_tcp_cork(struct mptcp_sock *msk, sockptr_t optval, - unsigned int optlen) +static int __mptcp_setsockopt_sol_tcp_cork(struct mptcp_sock *msk, int val) { struct mptcp_subflow_context *subflow; struct sock *sk = (struct sock *)msk; - int val, ret; - ret = mptcp_get_int_option(msk, optval, optlen, &val); - if (ret) - return ret; - - lock_sock(sk); sockopt_seq_inc(msk); msk->cork = !!val; mptcp_for_each_subflow(msk, subflow) { @@ -639,23 +632,15 @@ static int mptcp_setsockopt_sol_tcp_cork(struct mptcp_sock *msk, sockptr_t optva } if (!val) mptcp_check_and_set_pending(sk); - release_sock(sk); return 0; } -static int mptcp_setsockopt_sol_tcp_nodelay(struct mptcp_sock *msk, sockptr_t optval, - unsigned int optlen) +static int __mptcp_setsockopt_sol_tcp_nodelay(struct mptcp_sock *msk, int val) { struct mptcp_subflow_context *subflow; struct sock *sk = (struct sock *)msk; - int val, ret; - ret = mptcp_get_int_option(msk, optval, optlen, &val); - if (ret) - return ret; - - lock_sock(sk); sockopt_seq_inc(msk); msk->nodelay = !!val; mptcp_for_each_subflow(msk, subflow) { @@ -667,8 +652,6 @@ static int mptcp_setsockopt_sol_tcp_nodelay(struct mptcp_sock *msk, sockptr_t op } if (val) mptcp_check_and_set_pending(sk); - release_sock(sk); - return 0; } @@ -793,25 +776,10 @@ static int mptcp_setsockopt_sol_tcp(struct mptcp_sock *msk, int optname, int ret, val; switch (optname) { - case TCP_INQ: - ret = mptcp_get_int_option(msk, optval, optlen, &val); - if (ret) - return ret; - if (val < 0 || val > 1) - return -EINVAL; - - lock_sock(sk); - msk->recvmsg_inq = !!val; - release_sock(sk); - return 0; case TCP_ULP: return -EOPNOTSUPP; case TCP_CONGESTION: return mptcp_setsockopt_sol_tcp_congestion(msk, optval, optlen); - case TCP_CORK: - return mptcp_setsockopt_sol_tcp_cork(msk, optval, optlen); - case TCP_NODELAY: - return mptcp_setsockopt_sol_tcp_nodelay(msk, optval, optlen); case TCP_DEFER_ACCEPT: return mptcp_setsockopt_sol_tcp_defer(msk, optval, optlen); case TCP_FASTOPEN_CONNECT: @@ -819,7 +787,30 @@ static int mptcp_setsockopt_sol_tcp(struct mptcp_sock *msk, int optname, optval, optlen); } - return -EOPNOTSUPP; + ret = mptcp_get_int_option(msk, optval, optlen, &val); + if (ret) + return ret; + + lock_sock(sk); + switch (optname) { + case TCP_INQ: + if (val < 0 || val > 1) + ret = -EINVAL; + else + msk->recvmsg_inq = !!val; + break; + case TCP_CORK: + ret = __mptcp_setsockopt_sol_tcp_cork(msk, val); + break; + case TCP_NODELAY: + ret = __mptcp_setsockopt_sol_tcp_nodelay(msk, val); + break; + default: + ret = -ENOPROTOOPT; + } + + release_sock(sk); + return ret; } int mptcp_setsockopt(struct sock *sk, int level, int optname, From patchwork Wed May 29 10:00:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Matthieu Baerts (NGI0)" X-Patchwork-Id: 13678596 X-Patchwork-Delegate: matthieu.baerts@tessares.net Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9A94115B14A; Wed, 29 May 2024 10:00:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716976836; cv=none; b=aPNB5VoWpfxKJqJlArU4ex59vNUZhkPX6vJ1bZqu9zoIGzHX76FJ8Bvbr/K8BKTa2+a1Jw+ddWr59/6pkdhY8QrVSFAGqUp+FzIyyXUNQzw54ifcyXi8dpzMcH/x15nNTZGSabvMJ/ofOhumKDwK7gJwiDd7dliT7FLSRA3IImY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716976836; c=relaxed/simple; bh=Bp2lrsd5Pt0fAdnTuT1CMGHP7lrKu32mKn8vsxswefI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=LsEbyU7M7ftHo6wJAUGrCH88kvHGgx3urOv2ok5lnYrKIVFSEcQzAxIrP/ocgnm3fv5QQjjh+AP3zuXpwPbQyYs5tGlXzbhSYK8zlNEVIICeTt6kpEeBx2BB5wFJs9FeucSpxP66TFnsoMjkn0iN7tHmTk3WLP2OnczNyt9oSHU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=mRd/i9/v; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="mRd/i9/v" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9D892C2BD10; Wed, 29 May 2024 10:00:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1716976836; bh=Bp2lrsd5Pt0fAdnTuT1CMGHP7lrKu32mKn8vsxswefI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mRd/i9/vHfrxv6Byj4GZFcXqmnmJxgKFXctE7lvizNtm+/rpliSQp0M8wXwtRboBf g0anuDSMIa31+UauKwDUBLcQaKief4b9wFEdCaVPvvb90I/Q18Xwi9nz3vGMCTsXTz uiXHNgbose1rJ3Swa9S+ZsClo3qOcj+cGLK9hY47bm9y7rd7jHbFSCy2B3XPkk1L14 XaFSWogNEPRCx5l7Teun6gzQ6s8220Lfg6tq3t9+pNWPxAyTZ+OLi1W1m45P9594xu 15sftRi6ZXZxdqDphDJ5ZYVMS5O1Vlh6s19M9O5qPFXzKxN4pz/eSHhuoXr5TH7rtA PDvdIDwBfkmMQ== From: "Matthieu Baerts (NGI0)" To: mptcp@lists.linux.dev, stable@vger.kernel.org, gregkh@linuxfoundation.org, sashal@kernel.org Cc: "Matthieu Baerts (NGI0)" , Paolo Abeni , Mat Martineau , Jakub Kicinski Subject: [PATCH 6.1.y 3/3] mptcp: fix full TCP keep-alive support Date: Wed, 29 May 2024 12:00:26 +0200 Message-ID: <20240529100022.3373664-8-matttbe@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240529100022.3373664-5-matttbe@kernel.org> References: <20240529100022.3373664-5-matttbe@kernel.org> Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=6715; i=matttbe@kernel.org; h=from:subject; bh=Bp2lrsd5Pt0fAdnTuT1CMGHP7lrKu32mKn8vsxswefI=; b=owEBbQKS/ZANAwAIAfa3gk9CaaBzAcsmYgBmVvy3NZAtLp9eF2ZxMu3hKHvWiji+HEB2uZSgE 76Sdm+RZXeJAjMEAAEIAB0WIQToy4X3aHcFem4n93r2t4JPQmmgcwUCZlb8twAKCRD2t4JPQmmg cyGUD/402c2izreF0/J4NFzws5HrYHmtqEqrtCjbO1bhXeW3lHbk8YtWCvBaiJmSAM01QhOXXoq 0hgvHC2l3iB6JcZc27k5ax3uoTn+Vr057IwOqrqiTxvbKdan/ox4nQx9R08+L6LKgOwPVE2akRr Y1mz9ZCXRgwW5Z2pOPQ7yWdBWebeOcyHwLQ9rpayAv/vGSRbSz0/TNje1cOUP+Zuy5M3YDlI1An /EoanZhQ5l2EWKmQXzPLf6tG/sEvgJ3psuSv2OA4VmhqH+MqUGoXeCetDGWkTy5VQbryXNzoqzr 5mIqcyUYRj3xi9hbrPOs9sRCiTlWLFN7Ufms+dv0DAOZGjt3m0uEAEbQtj0ytS6GMFrO7x2AFSv rwefbXMd/OqystGmqP3IliyNv+3kbgGeuDF/zxHbkXSyzN8eK9EZzOPxdsB6P+xohX5h8bjcohX hE7dO8PScgrETxSxndqBK3ZHBmT223XiPEN17VGMFldeW0Dt5FFu7dctx5MjbscP/B4VwWNvgeX wtaHCu22mYtELt//xjB6SKqHLKb+BF2w174ba9/gsiGLBC8yn1umgSZXdGZZTRfi7V8MfcBSczB pfP1DHEztxpbylLPnhghIWkWvdgrSc2uiMWWkI+TEwRsA/JZhQQQxv+TMBMaiglNAe1+rVjJy/M 5oVQb1MqO12Vvpw== X-Developer-Key: i=matttbe@kernel.org; a=openpgp; fpr=E8CB85F76877057A6E27F77AF6B7824F4269A073 commit bd11dc4fb969ec148e50cd87f88a78246dbc4d0b upstream. SO_KEEPALIVE support has been added a while ago, as part of a series "adding SOL_SOCKET" support. To have a full control of this keep-alive feature, it is important to also support TCP_KEEP* socket options at the SOL_TCP level. Supporting them on the setsockopt() part is easy, it is just a matter of remembering each value in the MPTCP sock structure, and calling tcp_sock_set_keep*() helpers on each subflow. If the value is not modified (0), calling these helpers will not do anything. For the getsockopt() part, the corresponding value from the MPTCP sock structure or the default one is simply returned. All of this is very similar to other TCP_* socket options supported by MPTCP. It looks important for kernels supporting SO_KEEPALIVE, to also support TCP_KEEP* options as well: some apps seem to (wrongly) consider that if the former is supported, the latter ones will be supported as well. But also, not having this simple and isolated change is preventing MPTCP support in some apps, and libraries like GoLang [1]. This is why this patch is seen as a fix. Closes: https://github.com/multipath-tcp/mptcp_net-next/issues/383 Fixes: 1b3e7ede1365 ("mptcp: setsockopt: handle SO_KEEPALIVE and SO_PRIORITY") Link: https://github.com/golang/go/issues/56539 [1] Acked-by: Paolo Abeni Signed-off-by: Matthieu Baerts (NGI0) Signed-off-by: Mat Martineau Link: https://lore.kernel.org/r/20240514011335.176158-3-martineau@kernel.org Signed-off-by: Jakub Kicinski [ Conflicts in the same context, because commit 29b5e5ef8739 ("mptcp: implement TCP_NOTSENT_LOWAT support") (new feature) and commit 013e3179dbd2 ("mptcp: fix rcv space initialization") (not backported because of the various conflicts, and because the race fixed by this commit "does not produce ill effects in practice") are not in this version. Also, TCP_KEEPINTVL and TCP_KEEPCNT value had to be set without lock, the same way it was done on TCP side prior commit 6fd70a6b4e6f ("tcp: set TCP_KEEPINTVL locklessly") and commit 84485080cbc1 ("tcp: set TCP_KEEPCNT locklessly"). ] Signed-off-by: Matthieu Baerts (NGI0) --- net/mptcp/protocol.h | 3 ++ net/mptcp/sockopt.c | 79 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 82 insertions(+) diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h index 2bc37773e780..eaed858c0ff9 100644 --- a/net/mptcp/protocol.h +++ b/net/mptcp/protocol.h @@ -288,6 +288,9 @@ struct mptcp_sock { fastopening:1, in_accept_queue:1, free_first:1; + int keepalive_cnt; + int keepalive_idle; + int keepalive_intvl; struct work_struct work; struct sk_buff *ooo_last_skb; struct rb_root out_of_order_queue; diff --git a/net/mptcp/sockopt.c b/net/mptcp/sockopt.c index 7573bbd15f84..ff82fc062ae7 100644 --- a/net/mptcp/sockopt.c +++ b/net/mptcp/sockopt.c @@ -616,6 +616,52 @@ static int mptcp_setsockopt_sol_tcp_congestion(struct mptcp_sock *msk, sockptr_t return ret; } +static int __tcp_sock_set_keepintvl(struct sock *sk, int val) +{ + if (val < 1 || val > MAX_TCP_KEEPINTVL) + return -EINVAL; + + WRITE_ONCE(tcp_sk(sk)->keepalive_intvl, val * HZ); + + return 0; +} + +static int __tcp_sock_set_keepcnt(struct sock *sk, int val) +{ + if (val < 1 || val > MAX_TCP_KEEPCNT) + return -EINVAL; + + /* Paired with READ_ONCE() in keepalive_probes() */ + WRITE_ONCE(tcp_sk(sk)->keepalive_probes, val); + + return 0; +} + +static int __mptcp_setsockopt_set_val(struct mptcp_sock *msk, int max, + int (*set_val)(struct sock *, int), + int *msk_val, int val) +{ + struct mptcp_subflow_context *subflow; + int err = 0; + + mptcp_for_each_subflow(msk, subflow) { + struct sock *ssk = mptcp_subflow_tcp_sock(subflow); + int ret; + + lock_sock(ssk); + ret = set_val(ssk, val); + err = err ? : ret; + release_sock(ssk); + } + + if (!err) { + *msk_val = val; + sockopt_seq_inc(msk); + } + + return err; +} + static int __mptcp_setsockopt_sol_tcp_cork(struct mptcp_sock *msk, int val) { struct mptcp_subflow_context *subflow; @@ -805,6 +851,22 @@ static int mptcp_setsockopt_sol_tcp(struct mptcp_sock *msk, int optname, case TCP_NODELAY: ret = __mptcp_setsockopt_sol_tcp_nodelay(msk, val); break; + case TCP_KEEPIDLE: + ret = __mptcp_setsockopt_set_val(msk, MAX_TCP_KEEPIDLE, + &tcp_sock_set_keepidle_locked, + &msk->keepalive_idle, val); + break; + case TCP_KEEPINTVL: + ret = __mptcp_setsockopt_set_val(msk, MAX_TCP_KEEPINTVL, + &__tcp_sock_set_keepintvl, + &msk->keepalive_intvl, val); + break; + case TCP_KEEPCNT: + ret = __mptcp_setsockopt_set_val(msk, MAX_TCP_KEEPCNT, + &__tcp_sock_set_keepcnt, + &msk->keepalive_cnt, + val); + break; default: ret = -ENOPROTOOPT; } @@ -1163,6 +1225,8 @@ static int mptcp_put_int_option(struct mptcp_sock *msk, char __user *optval, static int mptcp_getsockopt_sol_tcp(struct mptcp_sock *msk, int optname, char __user *optval, int __user *optlen) { + struct sock *sk = (void *)msk; + switch (optname) { case TCP_ULP: case TCP_CONGESTION: @@ -1178,6 +1242,18 @@ static int mptcp_getsockopt_sol_tcp(struct mptcp_sock *msk, int optname, return mptcp_put_int_option(msk, optval, optlen, msk->cork); case TCP_NODELAY: return mptcp_put_int_option(msk, optval, optlen, msk->nodelay); + case TCP_KEEPIDLE: + return mptcp_put_int_option(msk, optval, optlen, + msk->keepalive_idle ? : + READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_keepalive_time) / HZ); + case TCP_KEEPINTVL: + return mptcp_put_int_option(msk, optval, optlen, + msk->keepalive_intvl ? : + READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_keepalive_intvl) / HZ); + case TCP_KEEPCNT: + return mptcp_put_int_option(msk, optval, optlen, + msk->keepalive_cnt ? : + READ_ONCE(sock_net(sk)->ipv4.sysctl_tcp_keepalive_probes)); } return -EOPNOTSUPP; } @@ -1282,6 +1358,9 @@ static void sync_socket_options(struct mptcp_sock *msk, struct sock *ssk) tcp_set_congestion_control(ssk, msk->ca_name, false, true); __tcp_sock_set_cork(ssk, !!msk->cork); __tcp_sock_set_nodelay(ssk, !!msk->nodelay); + tcp_sock_set_keepidle_locked(ssk, msk->keepalive_idle); + __tcp_sock_set_keepintvl(ssk, msk->keepalive_intvl); + __tcp_sock_set_keepcnt(ssk, msk->keepalive_cnt); inet_sk(ssk)->transparent = inet_sk(sk)->transparent; inet_sk(ssk)->freebind = inet_sk(sk)->freebind;