From patchwork Fri May 2 12:29:21 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthieu Baerts X-Patchwork-Id: 887329 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 0036425486C; Fri, 2 May 2025 12:29:39 +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=1746188982; cv=none; b=MIVUP9tNNv+EdU0jI/2tqSD7EDQOtRb6ebZYmHQR9l8teRExcfLvAEV+JoOFK6zWPVP7f+czDUrYpIX7qq0/Rkw6yYFegnINfHUwwP/31U4mYz5SMypcwS50t4n5sSCz8cn6tp2OKjn775R930NgLO1cFsORODtNPXLNK25/o3M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746188982; c=relaxed/simple; bh=7UMUwVfeSCKCbHTkA47Yw4k/uIlln51ZfD1HEo3PtXs=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=l54HuEASu6AuN4ogB41zK22hln1LyKaJSMd3OtXSgPisc+BDHxkLC8VgegOrvGt4VpFTDb6lYzz0AU7qviB+tfz0pu4STTUkaiKE5w7t1+2QKyiUdq2mFCZ1topiahIMdOy7gbBfsmQfzrpHXCNwu1S8eYBpPdVYBp2BtvRf+q8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=RzzBfZVR; 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="RzzBfZVR" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3C07FC4CEF0; Fri, 2 May 2025 12:29:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1746188979; bh=7UMUwVfeSCKCbHTkA47Yw4k/uIlln51ZfD1HEo3PtXs=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=RzzBfZVRAPH6XVBJarfLSHC2JJ0cf8qExjN7XCcyKM+DkXIKbVsM3bhaL8SGZ/udN PSQSB+fRTkRUJLLK7buVH5mHq5WHEpqkmAyZ9ECEEUTyumWbDoAm+0t4d/gaDl38mj 71TCB8R/TZcmmNA/T2WUZJxAnA7zQD2+MBW9ITHYGG9KVZmmLB8KKIWhzNST0fw30X +5OvJ5PmVbURXDwdZjwTKn621X8Mmi2JGlbON2VkcSiE3BlJRGrZ7RAvw4GRdaiIUf fkPh7w2AzKxQsk79yMKzKYPaTlI/xF326F1UzfaUFg2C/oPyO30FhDMZ1hk15jOufk Lcg2+8Z6XKvhg== From: "Matthieu Baerts (NGI0)" Date: Fri, 02 May 2025 14:29:21 +0200 Subject: [PATCH net-next 1/7] selftests: mptcp: info: hide 'grep: write error' warnings Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250502-net-next-mptcp-sft-inc-cover-v1-1-68eec95898fb@kernel.org> References: <20250502-net-next-mptcp-sft-inc-cover-v1-0-68eec95898fb@kernel.org> In-Reply-To: <20250502-net-next-mptcp-sft-inc-cover-v1-0-68eec95898fb@kernel.org> To: mptcp@lists.linux.dev, Mat Martineau , Geliang Tang , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , Shuah Khan Cc: netdev@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, "Matthieu Baerts (NGI0)" X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=1730; i=matttbe@kernel.org; h=from:subject:message-id; bh=7UMUwVfeSCKCbHTkA47Yw4k/uIlln51ZfD1HEo3PtXs=; b=owGbwMvMwCVWo/Th0Gd3rumMp9WSGDJEdi0T3N9c9U2koObk/9py6SMeQgWTZLOyfh/TVRJ/7 PH1CJd8RykLgxgXg6yYIot0W2T+zOdVvCVefhYwc1iZQIYwcHEKwERKDjIynHAOlrxwMb3x+bbd DStnGJlm7plkODVRcd8n0ZorD6fpejEyXNvArZ+1ujgrYuJB7jmvTyxY9a5FULTBuTlaK2/yR+s yRgA= X-Developer-Key: i=matttbe@kernel.org; a=openpgp; fpr=E8CB85F76877057A6E27F77AF6B7824F4269A073 mptcp_lib_get_info_value() will only print the first entry that match the filter because of the ';q' at the end. As a consequence, the 'sed' command could finish before the previous 'grep' one and print a 'write error' warning because it is trying to write data to the closed pipe. Such warnings are not interesting, they can be hidden by muting stderr here for grep. While at it, clearly indicate that mptcp_lib_get_info_value() will only print the first matched entry to avoid confusions later on. Reviewed-by: Mat Martineau Signed-off-by: Matthieu Baerts (NGI0) --- tools/testing/selftests/net/mptcp/mptcp_lib.sh | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/net/mptcp/mptcp_lib.sh b/tools/testing/selftests/net/mptcp/mptcp_lib.sh index 051e289d79676c5feb9f46da67a08116548f4b47..99c87cd6e25563e220263c813223206ef6f4b311 100644 --- a/tools/testing/selftests/net/mptcp/mptcp_lib.sh +++ b/tools/testing/selftests/net/mptcp/mptcp_lib.sh @@ -331,12 +331,15 @@ mptcp_lib_result_print_all_tap() { # get the value of keyword $1 in the line marked by keyword $2 mptcp_lib_get_info_value() { - grep "${2}" | sed -n 's/.*\('"${1}"':\)\([0-9a-f:.]*\).*$/\2/p;q' + grep "${2}" 2>/dev/null | + sed -n 's/.*\('"${1}"':\)\([0-9a-f:.]*\).*$/\2/p;q' + # the ';q' at the end limits to the first matched entry. } # $1: info name ; $2: evts_ns ; [$3: event type; [$4: addr]] mptcp_lib_evts_get_info() { - grep "${4:-}" "${2}" | mptcp_lib_get_info_value "${1}" "^type:${3:-1}," + grep "${4:-}" "${2}" 2>/dev/null | + mptcp_lib_get_info_value "${1}" "^type:${3:-1}," } # $1: PID From patchwork Fri May 2 12:29:22 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthieu Baerts X-Patchwork-Id: 886782 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 A19C3254B1B; Fri, 2 May 2025 12:29:42 +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=1746188983; cv=none; b=ZYDw/frC4EukSxkMUnjMY2klbxrznP30eNjVdcOQEGRoQE7jyQs4zMBOz4nb1XBqMU8WQuX4jutialllOQDnFbxRfUeUBKWx13WCbMGoJLkB38WcwHIeTwQM10eq4ozZ2Ancu3Fe2kUruj16b1fTPYCtlcofm46KdzKQAJ496hA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746188983; c=relaxed/simple; bh=+8h2bBaXFvBYeApUD14GhuhytbONYgeQNFr6X5ImztQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=mNwKIfKVemp9OQFTnlNcvPJKE+Wof8ADgXKfWbe13lFvQqBxL5II7nPup7LTNjqs5nCvyI34Xvv+ceydJ3hPIdgm+MNTHVwZXmcs6h0DdjgK4yEa0nwxp5B1n1Nh5BLnR5aLQFARLzNPRbfahGou+dO7w77rXyCLMtzeqhoiYYA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ku/nlL6d; 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="ku/nlL6d" Received: by smtp.kernel.org (Postfix) with ESMTPSA id DB9D3C4CEE4; Fri, 2 May 2025 12:29:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1746188982; bh=+8h2bBaXFvBYeApUD14GhuhytbONYgeQNFr6X5ImztQ=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=ku/nlL6dneEz7IDa6Juf+mJ7IXYE/PgG5+2opOEGtkVs0z5ayHTEjFm/j1T8vpn8Y NOV3wbOeOkTz3KeERLvkoVHHfavIngFzd9+7picPhipmiK793rjQlC+BP4rdu38Vn6 tx5CazxgqdwwRsA1i1ZfkRIavyJlqj9aey7cVymyN5uYWtGDze6/32WDYoqc0WMGaN +GwL46Yd+eir38qNLYD0C0DKKKLkCx/gDWDfe87tbEe+mWZnZgqRsSRYuXCMAXy0V6 Yx8O6gRcOkOXO9d5JteLmjIvBPMKrjawwQuValSY9dlD2NrhBOSM3p5grIGs9E79Lt Sql5wHtgt68lw== From: "Matthieu Baerts (NGI0)" Date: Fri, 02 May 2025 14:29:22 +0200 Subject: [PATCH net-next 2/7] selftests: mptcp: sockopt: use IPPROTO_MPTCP for getaddrinfo Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250502-net-next-mptcp-sft-inc-cover-v1-2-68eec95898fb@kernel.org> References: <20250502-net-next-mptcp-sft-inc-cover-v1-0-68eec95898fb@kernel.org> In-Reply-To: <20250502-net-next-mptcp-sft-inc-cover-v1-0-68eec95898fb@kernel.org> To: mptcp@lists.linux.dev, Mat Martineau , Geliang Tang , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , Shuah Khan Cc: netdev@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, "Matthieu Baerts (NGI0)" , Geliang Tang X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=3683; i=matttbe@kernel.org; h=from:subject:message-id; bh=sduBQPtFEpZUQE4iqnz88Fv2x9sSGoedrY37aNpWYUA=; b=owGbwMvMwCVWo/Th0Gd3rumMp9WSGDJEdi33vjv39J/pMyZPD5j95JzJ0mtHdBNLPlb0dDlNn NG49qpUXEcpC4MYF4OsmCKLdFtk/sznVbwlXn4WMHNYmUCGMHBxCsBEHh5hZPhe/aQ3+uO9IMmj CXfXrGUybJmvyNr6NVD84pldvouk37ow/GY7x58wdZH55dV9J5vaV2/d8VDuSV9rZe7klIWL86N tL7MAAA== X-Developer-Key: i=matttbe@kernel.org; a=openpgp; fpr=E8CB85F76877057A6E27F77AF6B7824F4269A073 From: Geliang Tang getaddrinfo MPTCP is recently supported in glibc and IPPROTO_MPTCP for getaddrinfo is used in mptcp_connect.c. But in mptcp_sockopt.c and mptcp_inq.c, IPPROTO_TCP are still used for getaddrinfo, So this patch updates them. Signed-off-by: Geliang Tang Reviewed-by: Matthieu Baerts (NGI0) Signed-off-by: Matthieu Baerts (NGI0) --- tools/testing/selftests/net/mptcp/mptcp_inq.c | 16 ++++++++++++---- tools/testing/selftests/net/mptcp/mptcp_sockopt.c | 16 ++++++++++++---- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/tools/testing/selftests/net/mptcp/mptcp_inq.c b/tools/testing/selftests/net/mptcp/mptcp_inq.c index 218aac46732125c005212d0d561ae3bce8f91a74..3cf1e2a612cef911028f46569563d16dd5d32129 100644 --- a/tools/testing/selftests/net/mptcp/mptcp_inq.c +++ b/tools/testing/selftests/net/mptcp/mptcp_inq.c @@ -72,13 +72,21 @@ static const char *getxinfo_strerr(int err) } static void xgetaddrinfo(const char *node, const char *service, - const struct addrinfo *hints, + struct addrinfo *hints, struct addrinfo **res) { +again: int err = getaddrinfo(node, service, hints, res); if (err) { - const char *errstr = getxinfo_strerr(err); + const char *errstr; + + if (err == EAI_SOCKTYPE) { + hints->ai_protocol = IPPROTO_TCP; + goto again; + } + + errstr = getxinfo_strerr(err); fprintf(stderr, "Fatal: getaddrinfo(%s:%s): %s\n", node ? node : "", service ? service : "", errstr); @@ -91,7 +99,7 @@ static int sock_listen_mptcp(const char * const listenaddr, { int sock = -1; struct addrinfo hints = { - .ai_protocol = IPPROTO_TCP, + .ai_protocol = IPPROTO_MPTCP, .ai_socktype = SOCK_STREAM, .ai_flags = AI_PASSIVE | AI_NUMERICHOST }; @@ -136,7 +144,7 @@ static int sock_connect_mptcp(const char * const remoteaddr, const char * const port, int proto) { struct addrinfo hints = { - .ai_protocol = IPPROTO_TCP, + .ai_protocol = IPPROTO_MPTCP, .ai_socktype = SOCK_STREAM, }; struct addrinfo *a, *addr; diff --git a/tools/testing/selftests/net/mptcp/mptcp_sockopt.c b/tools/testing/selftests/net/mptcp/mptcp_sockopt.c index 926b0be87c9905e763cfb5ba6df974d3518f0b49..9934a68df23708ecb413c4ab26523989e3b9f158 100644 --- a/tools/testing/selftests/net/mptcp/mptcp_sockopt.c +++ b/tools/testing/selftests/net/mptcp/mptcp_sockopt.c @@ -159,13 +159,21 @@ static const char *getxinfo_strerr(int err) } static void xgetaddrinfo(const char *node, const char *service, - const struct addrinfo *hints, + struct addrinfo *hints, struct addrinfo **res) { +again: int err = getaddrinfo(node, service, hints, res); if (err) { - const char *errstr = getxinfo_strerr(err); + const char *errstr; + + if (err == EAI_SOCKTYPE) { + hints->ai_protocol = IPPROTO_TCP; + goto again; + } + + errstr = getxinfo_strerr(err); fprintf(stderr, "Fatal: getaddrinfo(%s:%s): %s\n", node ? node : "", service ? service : "", errstr); @@ -178,7 +186,7 @@ static int sock_listen_mptcp(const char * const listenaddr, { int sock = -1; struct addrinfo hints = { - .ai_protocol = IPPROTO_TCP, + .ai_protocol = IPPROTO_MPTCP, .ai_socktype = SOCK_STREAM, .ai_flags = AI_PASSIVE | AI_NUMERICHOST }; @@ -223,7 +231,7 @@ static int sock_connect_mptcp(const char * const remoteaddr, const char * const port, int proto) { struct addrinfo hints = { - .ai_protocol = IPPROTO_TCP, + .ai_protocol = IPPROTO_MPTCP, .ai_socktype = SOCK_STREAM, }; struct addrinfo *a, *addr; From patchwork Fri May 2 12:29:23 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthieu Baerts X-Patchwork-Id: 887328 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 714F1255232; Fri, 2 May 2025 12:29:45 +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=1746188986; cv=none; b=LqP/d5ZyRyspW7ZGQ7oriZTpRlCoVK5t4TS26wO4c7hBLACyOMclMF7G3GNE1RqQ/jGtWweYRnjSy5Ouro3mzzrPqpsmD/H6yQYlzgE9v4AE2BpWDwo1+4yyuOQ8FvyfmWVX46r4pljefq0mTFk6DJbpl4dtRcCOI0/BTkQQQqk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746188986; c=relaxed/simple; bh=Ib1TqcrHx6htyMHOJudLtaj/PP66OW6d82PiRhdb0l4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=GIR35j8gmlqF2gbXqd+ixRQzrLNj+4mBgoH2CXKfwQnm8sjcYz/RFO7A5FKM236Ois2cQulKhx2zlQPXdKiF2SBR5KvjoYyFQ7vkVUCUDBnZvUnuAdFcT0mhZNE5rYXsc5GMzuwAbTKorXKem8Z0ZTuQMxiWDTNeoPH7gdGpkko= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=V/GqyulW; 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="V/GqyulW" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 86F6BC4CEF3; Fri, 2 May 2025 12:29:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1746188984; bh=Ib1TqcrHx6htyMHOJudLtaj/PP66OW6d82PiRhdb0l4=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=V/GqyulW1RSCehdxqbo+J52NDT7Q2egM2+OLpvsDHlN6YOHskeO+eZ1JOPwLkCZ0P vP/NNMFTENEUHEv2fceinIUUCP8nMMaPit/nsXPRBcW3GfIW+mSE6e4F0srVkaybFn QG3FLDVhblZoUojVT2KT6PIj0OKAqfZhm6Ked25m7zX6Qws7KwM9fcgpLMiWqvJsmh svqoKIN5j117XdIlGvK9kIfkhgW0/lGZs0PBbgDDEGYAyBPACvvyU8zQJbQoP+/HA4 I/ngJqfR2Oa9qKSBa/LheXZvxCNEiYEEeIMYoltps6WjyZRcmwt2sKHVnXHPerSYMb JILPLok3yYSKQ== From: "Matthieu Baerts (NGI0)" Date: Fri, 02 May 2025 14:29:23 +0200 Subject: [PATCH net-next 3/7] selftests: mptcp: add struct params in mptcp_diag Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250502-net-next-mptcp-sft-inc-cover-v1-3-68eec95898fb@kernel.org> References: <20250502-net-next-mptcp-sft-inc-cover-v1-0-68eec95898fb@kernel.org> In-Reply-To: <20250502-net-next-mptcp-sft-inc-cover-v1-0-68eec95898fb@kernel.org> To: mptcp@lists.linux.dev, Mat Martineau , Geliang Tang , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , Shuah Khan Cc: netdev@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, "Matthieu Baerts (NGI0)" , Gang Yan X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=1932; i=matttbe@kernel.org; h=from:subject:message-id; bh=JV5KRwJz/0wGNszA8+h6v2IEAspsGHzn0JdEiVMYgzU=; b=owGbwMvMwCVWo/Th0Gd3rumMp9WSGDJEdq1Ii+rZVH7X9OdyzgVPW2ZMT9NufPjeW+iB4poNj YWPzT6u6ChlYRDjYpAVU2SRbovMn/m8irfEy88CZg4rE8gQBi5OAZhIXTUjw6pmHr39s9ovT730 voy5Rrjumnp3lkXWWyae1Y/DC55GvGL4yXjY4e7/q85LQ9/tOKnFnphve9X3HseOmHO/6g1PWqQ dYQYA X-Developer-Key: i=matttbe@kernel.org; a=openpgp; fpr=E8CB85F76877057A6E27F77AF6B7824F4269A073 From: Gang Yan This patch adds a struct named 'params' to save 'target_token' and other future parameters. This structure facilitates future function expansions. Co-developed-by: Geliang Tang Signed-off-by: Geliang Tang Signed-off-by: Gang Yan Reviewed-by: Matthieu Baerts (NGI0) Signed-off-by: Matthieu Baerts (NGI0) --- tools/testing/selftests/net/mptcp/mptcp_diag.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/tools/testing/selftests/net/mptcp/mptcp_diag.c b/tools/testing/selftests/net/mptcp/mptcp_diag.c index 37d5015ad08c44485f1964593ecb1a7b25d95934..ea7cb1128044ab7f9bad50cb29856c2e290f385f 100644 --- a/tools/testing/selftests/net/mptcp/mptcp_diag.c +++ b/tools/testing/selftests/net/mptcp/mptcp_diag.c @@ -19,6 +19,10 @@ #define IPPROTO_MPTCP 262 #endif +struct params { + __u32 target_token; +}; + struct mptcp_info { __u8 mptcpi_subflows; __u8 mptcpi_add_addr_signal; @@ -237,7 +241,7 @@ static void get_mptcpinfo(__u32 token) close(fd); } -static void parse_opts(int argc, char **argv, __u32 *target_token) +static void parse_opts(int argc, char **argv, struct params *p) { int c; @@ -250,7 +254,7 @@ static void parse_opts(int argc, char **argv, __u32 *target_token) die_usage(0); break; case 't': - sscanf(optarg, "%x", target_token); + sscanf(optarg, "%x", &p->target_token); break; default: die_usage(1); @@ -261,10 +265,12 @@ static void parse_opts(int argc, char **argv, __u32 *target_token) int main(int argc, char *argv[]) { - __u32 target_token; + struct params p = { 0 }; - parse_opts(argc, argv, &target_token); - get_mptcpinfo(target_token); + parse_opts(argc, argv, &p); + + if (p.target_token) + get_mptcpinfo(p.target_token); return 0; } From patchwork Fri May 2 12:29:24 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthieu Baerts X-Patchwork-Id: 886781 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 3EE30255E34; Fri, 2 May 2025 12:29:47 +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=1746188988; cv=none; b=ofM+ewGVq3e7JU0bKzlgzjjGW226MYiSibD7iZ9imNLUZ/AnyXc0LOMD9OVbaUNt1R3QsjfSFYy96CItD6knFXqsY5VUegVK2hrXT6/VOG7yp/qHU9o3d5ypCFS710xsUiwByJl6zeDlrOfMzt3PRBNhdiFEPySS3fl/0PjLROM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746188988; c=relaxed/simple; bh=Ya2+jFEI7mJuT3ncP/RsKk1LdroKEiKCPg02KaA8Zbg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=KlT39L42BWqZwLXZAqiHkz4PX0NfqFHtHj2Ath8y621r/x6ngvQ2vWvjBRFDiR/9FWrnOidlBkWmyAxWFGGTR/POKiDAs7APOTSseqzr5rpu93n4nBJrtDq0hRN89thkd41Xubh6YsW9tREujFMIQlBgr6mtJU0CRsnPp2S+168= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=a0Bxm6ku; 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="a0Bxm6ku" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 599D7C4CEEB; Fri, 2 May 2025 12:29:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1746188987; bh=Ya2+jFEI7mJuT3ncP/RsKk1LdroKEiKCPg02KaA8Zbg=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=a0Bxm6kud/b3GtZpAvBrjnOqkSBYN5DcTHB2Mf4RDaC3mvM+sOEb79YztFv3Xf2dK 2yC0avJkx5m4tDNpt/FlN8IFZt4+Z3ayw0WQiSN26ibbOQd6IMGhHQP3DrcbySUkLu Pr3lQUoGul4Yee+L3SzhfZR4ITNpt3kPb4mupkgrGS9iIks5EJ44Id7RhSNUKy+O7H QvHQkneMn6Fo0oSRw1eI/45ksvZHf8qaT0EJqp04qCex0qKTDT2SVQT1N9JahYB9Tu cfjWaenrzEwNx8nllLudxsunBVNREU2Pp4V6imL0cy6All3yKfyYEMQzSNacdJZ8uW Zi5AfqYiSBx4Q== From: "Matthieu Baerts (NGI0)" Date: Fri, 02 May 2025 14:29:24 +0200 Subject: [PATCH net-next 4/7] selftests: mptcp: refactor send_query parameters for code clarity Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250502-net-next-mptcp-sft-inc-cover-v1-4-68eec95898fb@kernel.org> References: <20250502-net-next-mptcp-sft-inc-cover-v1-0-68eec95898fb@kernel.org> In-Reply-To: <20250502-net-next-mptcp-sft-inc-cover-v1-0-68eec95898fb@kernel.org> To: mptcp@lists.linux.dev, Mat Martineau , Geliang Tang , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , Shuah Khan Cc: netdev@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, "Matthieu Baerts (NGI0)" , Gang Yan X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=2372; i=matttbe@kernel.org; h=from:subject:message-id; bh=tTuaDYFXrdjZ2f7/7lgt2gZN6EWhTltwwGFKgN6cy80=; b=owGbwMvMwCVWo/Th0Gd3rumMp9WSGDJEdq3KZJsWOH3axp97Jvr08S/SXCV80Vji5Hlh9tSHc V8ndQWs7ihlYRDjYpAVU2SRbovMn/m8irfEy88CZg4rE8gQBi5OAZhI9FyGfwYK/l1xgjfXf/f9 8qL2rsKekzwb11tb9YR7PlqV3X0+hJ+R4SNH4EWDRT8SeJe8zLmz/Nw50bJGA/0/qx5bfMlZcYi XhxUA X-Developer-Key: i=matttbe@kernel.org; a=openpgp; fpr=E8CB85F76877057A6E27F77AF6B7824F4269A073 From: Gang Yan This patch use 'inet_diag_req_v2' instead of 'token' as parameters of send_query, and construct the req in 'get_mptcpinfo'. This modification enhances the clarity of the code, and prepare for the dump_subflow_info. Co-developed-by: Geliang Tang Signed-off-by: Geliang Tang Signed-off-by: Gang Yan Reviewed-by: Matthieu Baerts (NGI0) Signed-off-by: Matthieu Baerts (NGI0) --- tools/testing/selftests/net/mptcp/mptcp_diag.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/tools/testing/selftests/net/mptcp/mptcp_diag.c b/tools/testing/selftests/net/mptcp/mptcp_diag.c index ea7cb1128044ab7f9bad50cb29856c2e290f385f..76135aba71ad24c25c7babb6875e8a6dd7636b21 100644 --- a/tools/testing/selftests/net/mptcp/mptcp_diag.c +++ b/tools/testing/selftests/net/mptcp/mptcp_diag.c @@ -62,7 +62,7 @@ static void die_usage(int r) exit(r); } -static void send_query(int fd, __u32 token) +static void send_query(int fd, struct inet_diag_req_v2 *r) { struct sockaddr_nl nladdr = { .nl_family = AF_NETLINK @@ -76,19 +76,13 @@ static void send_query(int fd, __u32 token) .nlmsg_type = SOCK_DIAG_BY_FAMILY, .nlmsg_flags = NLM_F_REQUEST }, - .r = { - .sdiag_family = AF_INET, - /* Real proto is set via INET_DIAG_REQ_PROTOCOL */ - .sdiag_protocol = IPPROTO_TCP, - .id.idiag_cookie[0] = token, - } + .r = *r }; struct rtattr rta_proto; struct iovec iov[6]; int iovlen = 1; __u32 proto; - req.r.idiag_ext |= (1 << (INET_DIAG_INFO - 1)); proto = IPPROTO_MPTCP; rta_proto.rta_type = INET_DIAG_REQ_PROTOCOL; rta_proto.rta_len = RTA_LENGTH(sizeof(proto)); @@ -229,13 +223,20 @@ static void recv_nlmsg(int fd) static void get_mptcpinfo(__u32 token) { + struct inet_diag_req_v2 r = { + .sdiag_family = AF_INET, + /* Real proto is set via INET_DIAG_REQ_PROTOCOL */ + .sdiag_protocol = IPPROTO_TCP, + .idiag_ext = 1 << (INET_DIAG_INFO - 1), + .id.idiag_cookie[0] = token, + }; int fd; fd = socket(AF_NETLINK, SOCK_RAW, NETLINK_SOCK_DIAG); if (fd < 0) die_perror("Netlink socket"); - send_query(fd, token); + send_query(fd, &r); recv_nlmsg(fd); close(fd); From patchwork Fri May 2 12:29:25 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthieu Baerts X-Patchwork-Id: 887327 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 32A88255F43; Fri, 2 May 2025 12:29:50 +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=1746188991; cv=none; b=NH5V82ROpTUAQdzATSF4COFHa8JdqXQbf8jzG7XiwGyvKnpGv+2dnu4/qVghCoys8YEP+PNeAGMIiU+dDcwxrUXKw6VgRaUkTve3kknEdSCRWa+zEEqXTLX5KzhV47qgk0XBcL6HvqaMzUkZmNPyBYH9qw4aUdCDvnf8195jScg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746188991; c=relaxed/simple; bh=cqB9dz1yBk4G81aoXsuf6a8tTtHU627jMvKTo5XIkLs=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=nOZclRrm2XwZBUD6d23dKDh2pYBRH/2AmgC9fI9/g3Rwg8bBVdjgFl4eN90ZnliaZfpjyJK1B0kJTu0Al83ojyaYqZwZtCpCsezVZ3cRR7gOCJ2dkbHTKisro0Cj1nY+NAz/zhPQrhjdXaTvFGKb4donXhOGboVhTunzbwIUcaw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ixSHneR+; 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="ixSHneR+" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2C3ECC4CEEE; Fri, 2 May 2025 12:29:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1746188990; bh=cqB9dz1yBk4G81aoXsuf6a8tTtHU627jMvKTo5XIkLs=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=ixSHneR+uCbN151wtIhGEfQvIRIBRAy/F1cvPUbHvkZLSpUia09upwXhD+liBdJSK 5di+7MFiySJRbh7I1J3JitTSskBAZGQM2EGiu+hsEBBRHAhKNEgVzIXrzXsJ89BapW Mi1GvDJKzqw9MxHcBF8U8UKjAWovPFvFbSJ6js9hxGifJfmzm8TywHZyHcl5QSe1Qy NAko+pvaJtoAyiDHzLeef8I5KCCxjz+snXN5zAwyVUVdxoz5pHWYzJcBdsadSzOwJA 0shlt5t/RIG+vYy8KbrtRmw2aSekQBsxJOs9HYUxtS6cbSWAOXOMOeBp6GeEieUGkL Tsy5/sXewGUSA== From: "Matthieu Baerts (NGI0)" Date: Fri, 02 May 2025 14:29:25 +0200 Subject: [PATCH net-next 5/7] selftests: mptcp: refactor NLMSG handling with 'proto' Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250502-net-next-mptcp-sft-inc-cover-v1-5-68eec95898fb@kernel.org> References: <20250502-net-next-mptcp-sft-inc-cover-v1-0-68eec95898fb@kernel.org> In-Reply-To: <20250502-net-next-mptcp-sft-inc-cover-v1-0-68eec95898fb@kernel.org> To: mptcp@lists.linux.dev, Mat Martineau , Geliang Tang , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , Shuah Khan Cc: netdev@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, "Matthieu Baerts (NGI0)" , Gang Yan X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=4189; i=matttbe@kernel.org; h=from:subject:message-id; bh=6gMy9j0i075KIh14EymklHuMxOQb1xA+ZLGrQ9vl9ZE=; b=owGbwMvMwCVWo/Th0Gd3rumMp9WSGDJEdq1e2dpqejnUjSPg78pNEim3Gfbttlv4e5J/9u2qw HNW2nZzO0pZGMS4GGTFFFmk2yLzZz6v4i3x8rOAmcPKBDKEgYtTACYSPJ+R4fTbl46NDrUNiS6m pnF7PpyftZ/z3EJ545IVfm7a53XXuzEyXHJ/Gt25ZWX+nlsfd3QmvflsdLYnwPZqrlH1evPtEn8 42AA= X-Developer-Key: i=matttbe@kernel.org; a=openpgp; fpr=E8CB85F76877057A6E27F77AF6B7824F4269A073 From: Gang Yan This patch introduces the '__u32 proto' variable to the 'send_query' and 'recv_nlmsg' functions for further extending function. In the 'send_query' function, the inclusion of this variable makes the structure clearer and more readable. In the 'recv_nlmsg' function, the '__u32 proto' variable ensures that the 'diag_info' field remains unmodified when processing IPPROTO_TCP data, thereby preventing unintended transformation into 'mptcp_info' format. While at it, increment iovlen directly when an item is added to simplify this portion of the code and improve its readaility. Co-developed-by: Geliang Tang Signed-off-by: Geliang Tang Signed-off-by: Gang Yan Reviewed-by: Matthieu Baerts (NGI0) Signed-off-by: Matthieu Baerts (NGI0) --- tools/testing/selftests/net/mptcp/mptcp_diag.c | 38 ++++++++++++++------------ 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/tools/testing/selftests/net/mptcp/mptcp_diag.c b/tools/testing/selftests/net/mptcp/mptcp_diag.c index 76135aba71ad24c25c7babb6875e8a6dd7636b21..cc0326548e4ec44060da83f1f77e498bcedc82a9 100644 --- a/tools/testing/selftests/net/mptcp/mptcp_diag.c +++ b/tools/testing/selftests/net/mptcp/mptcp_diag.c @@ -62,7 +62,7 @@ static void die_usage(int r) exit(r); } -static void send_query(int fd, struct inet_diag_req_v2 *r) +static void send_query(int fd, struct inet_diag_req_v2 *r, __u32 proto) { struct sockaddr_nl nladdr = { .nl_family = AF_NETLINK @@ -80,21 +80,22 @@ static void send_query(int fd, struct inet_diag_req_v2 *r) }; struct rtattr rta_proto; struct iovec iov[6]; - int iovlen = 1; - __u32 proto; + int iovlen = 0; - proto = IPPROTO_MPTCP; - rta_proto.rta_type = INET_DIAG_REQ_PROTOCOL; - rta_proto.rta_len = RTA_LENGTH(sizeof(proto)); - - iov[0] = (struct iovec) { + iov[iovlen++] = (struct iovec) { .iov_base = &req, .iov_len = sizeof(req) }; - iov[iovlen] = (struct iovec){ &rta_proto, sizeof(rta_proto)}; - iov[iovlen + 1] = (struct iovec){ &proto, sizeof(proto)}; - req.nlh.nlmsg_len += RTA_LENGTH(sizeof(proto)); - iovlen += 2; + + if (proto == IPPROTO_MPTCP) { + rta_proto.rta_type = INET_DIAG_REQ_PROTOCOL; + rta_proto.rta_len = RTA_LENGTH(sizeof(proto)); + + iov[iovlen++] = (struct iovec){ &rta_proto, sizeof(rta_proto)}; + iov[iovlen++] = (struct iovec){ &proto, sizeof(proto)}; + req.nlh.nlmsg_len += RTA_LENGTH(sizeof(proto)); + } + struct msghdr msg = { .msg_name = &nladdr, .msg_namelen = sizeof(nladdr), @@ -158,7 +159,7 @@ static void print_info_msg(struct mptcp_info *info) printf("bytes_acked: %llu\n", info->mptcpi_bytes_acked); } -static void parse_nlmsg(struct nlmsghdr *nlh) +static void parse_nlmsg(struct nlmsghdr *nlh, __u32 proto) { struct inet_diag_msg *r = NLMSG_DATA(nlh); struct rtattr *tb[INET_DIAG_MAX + 1]; @@ -167,7 +168,7 @@ static void parse_nlmsg(struct nlmsghdr *nlh) nlh->nlmsg_len - NLMSG_LENGTH(sizeof(*r)), NLA_F_NESTED); - if (tb[INET_DIAG_INFO]) { + if (proto == IPPROTO_MPTCP && tb[INET_DIAG_INFO]) { int len = RTA_PAYLOAD(tb[INET_DIAG_INFO]); struct mptcp_info *info; @@ -183,7 +184,7 @@ static void parse_nlmsg(struct nlmsghdr *nlh) } } -static void recv_nlmsg(int fd) +static void recv_nlmsg(int fd, __u32 proto) { char rcv_buff[8192]; struct nlmsghdr *nlh = (struct nlmsghdr *)rcv_buff; @@ -216,7 +217,7 @@ static void recv_nlmsg(int fd) -(err->error), strerror(-(err->error))); break; } - parse_nlmsg(nlh); + parse_nlmsg(nlh, proto); nlh = NLMSG_NEXT(nlh, len); } } @@ -230,14 +231,15 @@ static void get_mptcpinfo(__u32 token) .idiag_ext = 1 << (INET_DIAG_INFO - 1), .id.idiag_cookie[0] = token, }; + __u32 proto = IPPROTO_MPTCP; int fd; fd = socket(AF_NETLINK, SOCK_RAW, NETLINK_SOCK_DIAG); if (fd < 0) die_perror("Netlink socket"); - send_query(fd, &r); - recv_nlmsg(fd); + send_query(fd, &r, proto); + recv_nlmsg(fd, proto); close(fd); } From patchwork Fri May 2 12:29:26 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthieu Baerts X-Patchwork-Id: 886780 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 8349F2561B4; Fri, 2 May 2025 12:29:53 +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=1746188993; cv=none; b=Efr+Sj/gpc0tEqOHjrhLgQQ1gnkUpq9/v9FMeVDPzS4Dn/H2V5XUF1vSGD5SetpSdwr3+KD07uYAk1LFp8EcI2oXJyt2+jLw/kx/kd6Gz8MZ7S2RMEpdMvSy0RHtNdgHI9U04rd0S+cWckwAhVhuJyG94cSqnxf+bpQ45nJLVR8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746188993; c=relaxed/simple; bh=HrsUHH/qcXk1q2H9+8cPQnJZjPaeJV60k2cbn77FiW4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=VCzG6q5cqQAorQJEDmdBF5NvU3Pf+Kl0etTUxqd0oxO5NeGCHwff4ergvOFZZFmxtqTb3pA3qRo1NIUVGa5+7lg8GnZwsedTJp5yXkufdwYnJZ+e0dzNhw7W+UtXzZUbZnGAedu886qeueYNDttr28J79Aa4qdhfFo809SN3NKo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=n6MhFhMR; 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="n6MhFhMR" Received: by smtp.kernel.org (Postfix) with ESMTPSA id F3140C4CEEF; Fri, 2 May 2025 12:29:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1746188993; bh=HrsUHH/qcXk1q2H9+8cPQnJZjPaeJV60k2cbn77FiW4=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=n6MhFhMRALlVlVlt/huLjvKonv68JMMSW4ipemc/u0gBn14MugCigjIpky7JhU3Bm m4JW5Qx6XmWg33tImH+XiF4hBLLb+x6qoKlplnI975yo43+GJoHJDCZ5cUodcGGfzl Eczt/rWvh8q61Jb3aCPLABPefcM680J3EvDnlYweNcoeI94h8yXy/T7ZhOyUrwOZtm m9Y+5LBvx08fpe69G8xXgcxn+XLGL9T3rNTsrEeOVKlMQ1uZVu83CUqYj54M9SVRJ0 812m3Tp6eEOZE6DrZAzcbGRHkZ0uwJc+b/goGu2A4v4WpulovL6A8W3B6yWkLeVqUn G2JIvzivzwSwg== From: "Matthieu Baerts (NGI0)" Date: Fri, 02 May 2025 14:29:26 +0200 Subject: [PATCH net-next 6/7] selftests: mptcp: add helpers to get subflow_info Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250502-net-next-mptcp-sft-inc-cover-v1-6-68eec95898fb@kernel.org> References: <20250502-net-next-mptcp-sft-inc-cover-v1-0-68eec95898fb@kernel.org> In-Reply-To: <20250502-net-next-mptcp-sft-inc-cover-v1-0-68eec95898fb@kernel.org> To: mptcp@lists.linux.dev, Mat Martineau , Geliang Tang , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , Shuah Khan Cc: netdev@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, "Matthieu Baerts (NGI0)" , Gang Yan X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=8228; i=matttbe@kernel.org; h=from:subject:message-id; bh=7miyWEw+OpSZsSyngjOj789UMezB1kb5Lfuy5ZvWtt4=; b=owGbwMvMwCVWo/Th0Gd3rumMp9WSGDJEdq3p9+dT2CxdWnnR8te3+efWKGUm69+t3PP6CCvbm 7m+fzOqO0pZGMS4GGTFFFmk2yLzZz6v4i3x8rOAmcPKBDKEgYtTACayWJeR4ajqz09t1/7easxY e9vIRz37dajmveDVB09VMUrouSmFn2RkuO/0nmNGw9wniyy5P3+Rnfz00f9D5x137d4lWjuNm/l vBBsA X-Developer-Key: i=matttbe@kernel.org; a=openpgp; fpr=E8CB85F76877057A6E27F77AF6B7824F4269A073 From: Gang Yan This patch adds 'get_subflow_info' in 'mptcp_diag', which can check whether a TCP connection is an MPTCP subflow based on the "INET_ULP_INFO_MPTCP" with tcp_diag method. The helper 'print_subflow_info' in 'mptcp_diag' can print the subflow_filed of an MPTCP subflow for further checking the 'subflow_info' through inet_diag method. The example of the whole output should be: $ ./mptcp_diag -s "127.0.0.1:10000 127.0.0.1:38984" 127.0.0.1:10000 -> 127.0.0.1:38984 It's a mptcp subflow, the subflow info: flags:Mec token:0000(id:0)/4278e77e(id:0) seq:9288466187236176036 \ sfseq:1 ssnoff:2317083055 maplen:215 Co-developed-by: Geliang Tang Signed-off-by: Geliang Tang Signed-off-by: Gang Yan Reviewed-by: Matthieu Baerts (NGI0) Signed-off-by: Matthieu Baerts (NGI0) --- tools/testing/selftests/net/mptcp/mptcp_diag.c | 159 ++++++++++++++++++++++++- 1 file changed, 157 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/net/mptcp/mptcp_diag.c b/tools/testing/selftests/net/mptcp/mptcp_diag.c index cc0326548e4ec44060da83f1f77e498bcedc82a9..e084796e804d28e93d04c30cca937fe21be43388 100644 --- a/tools/testing/selftests/net/mptcp/mptcp_diag.c +++ b/tools/testing/selftests/net/mptcp/mptcp_diag.c @@ -8,6 +8,7 @@ #include #include #include +#include #include #include @@ -19,8 +20,13 @@ #define IPPROTO_MPTCP 262 #endif +#define parse_rtattr_nested(tb, max, rta) \ + (parse_rtattr_flags((tb), (max), RTA_DATA(rta), RTA_PAYLOAD(rta), \ + NLA_F_NESTED)) + struct params { __u32 target_token; + char subflow_addrs[1024]; }; struct mptcp_info { @@ -50,6 +56,37 @@ struct mptcp_info { __u32 mptcpi_last_ack_recv; }; +enum { + MPTCP_SUBFLOW_ATTR_UNSPEC, + MPTCP_SUBFLOW_ATTR_TOKEN_REM, + MPTCP_SUBFLOW_ATTR_TOKEN_LOC, + MPTCP_SUBFLOW_ATTR_RELWRITE_SEQ, + MPTCP_SUBFLOW_ATTR_MAP_SEQ, + MPTCP_SUBFLOW_ATTR_MAP_SFSEQ, + MPTCP_SUBFLOW_ATTR_SSN_OFFSET, + MPTCP_SUBFLOW_ATTR_MAP_DATALEN, + MPTCP_SUBFLOW_ATTR_FLAGS, + MPTCP_SUBFLOW_ATTR_ID_REM, + MPTCP_SUBFLOW_ATTR_ID_LOC, + MPTCP_SUBFLOW_ATTR_PAD, + + __MPTCP_SUBFLOW_ATTR_MAX +}; + +#define MPTCP_SUBFLOW_ATTR_MAX (__MPTCP_SUBFLOW_ATTR_MAX - 1) + +#define MPTCP_SUBFLOW_FLAG_MCAP_REM _BITUL(0) +#define MPTCP_SUBFLOW_FLAG_MCAP_LOC _BITUL(1) +#define MPTCP_SUBFLOW_FLAG_JOIN_REM _BITUL(2) +#define MPTCP_SUBFLOW_FLAG_JOIN_LOC _BITUL(3) +#define MPTCP_SUBFLOW_FLAG_BKUP_REM _BITUL(4) +#define MPTCP_SUBFLOW_FLAG_BKUP_LOC _BITUL(5) +#define MPTCP_SUBFLOW_FLAG_FULLY_ESTABLISHED _BITUL(6) +#define MPTCP_SUBFLOW_FLAG_CONNECTED _BITUL(7) +#define MPTCP_SUBFLOW_FLAG_MAPVALID _BITUL(8) + +#define rta_getattr(type, value) (*(type *)RTA_DATA(value)) + static void die_perror(const char *msg) { perror(msg); @@ -58,7 +95,9 @@ static void die_perror(const char *msg) static void die_usage(int r) { - fprintf(stderr, "Usage: mptcp_diag -t\n"); + fprintf(stderr, "Usage:\n" + "mptcp_diag -t \n" + "mptcp_diag -s \": :\"\n"); exit(r); } @@ -159,6 +198,66 @@ static void print_info_msg(struct mptcp_info *info) printf("bytes_acked: %llu\n", info->mptcpi_bytes_acked); } +/* + * 'print_subflow_info' is from 'mptcp_subflow_info' + * which is a function in 'misc/ss.c' of iproute2. + */ +static void print_subflow_info(struct rtattr *tb[]) +{ + u_int32_t flags = 0; + + printf("It's a mptcp subflow, the subflow info:\n"); + if (tb[MPTCP_SUBFLOW_ATTR_FLAGS]) { + char caps[32 + 1] = { 0 }, *cap = &caps[0]; + + flags = rta_getattr(__u32, tb[MPTCP_SUBFLOW_ATTR_FLAGS]); + + if (flags & MPTCP_SUBFLOW_FLAG_MCAP_REM) + *cap++ = 'M'; + if (flags & MPTCP_SUBFLOW_FLAG_MCAP_LOC) + *cap++ = 'm'; + if (flags & MPTCP_SUBFLOW_FLAG_JOIN_REM) + *cap++ = 'J'; + if (flags & MPTCP_SUBFLOW_FLAG_JOIN_LOC) + *cap++ = 'j'; + if (flags & MPTCP_SUBFLOW_FLAG_BKUP_REM) + *cap++ = 'B'; + if (flags & MPTCP_SUBFLOW_FLAG_BKUP_LOC) + *cap++ = 'b'; + if (flags & MPTCP_SUBFLOW_FLAG_FULLY_ESTABLISHED) + *cap++ = 'e'; + if (flags & MPTCP_SUBFLOW_FLAG_CONNECTED) + *cap++ = 'c'; + if (flags & MPTCP_SUBFLOW_FLAG_MAPVALID) + *cap++ = 'v'; + + if (flags) + printf(" flags:%s", caps); + } + if (tb[MPTCP_SUBFLOW_ATTR_TOKEN_REM] && + tb[MPTCP_SUBFLOW_ATTR_TOKEN_LOC] && + tb[MPTCP_SUBFLOW_ATTR_ID_REM] && + tb[MPTCP_SUBFLOW_ATTR_ID_LOC]) + printf(" token:%04x(id:%u)/%04x(id:%u)", + rta_getattr(__u32, tb[MPTCP_SUBFLOW_ATTR_TOKEN_REM]), + rta_getattr(__u8, tb[MPTCP_SUBFLOW_ATTR_ID_REM]), + rta_getattr(__u32, tb[MPTCP_SUBFLOW_ATTR_TOKEN_LOC]), + rta_getattr(__u8, tb[MPTCP_SUBFLOW_ATTR_ID_LOC])); + if (tb[MPTCP_SUBFLOW_ATTR_MAP_SEQ]) + printf(" seq:%llu", + rta_getattr(__u64, tb[MPTCP_SUBFLOW_ATTR_MAP_SEQ])); + if (tb[MPTCP_SUBFLOW_ATTR_MAP_SFSEQ]) + printf(" sfseq:%u", + rta_getattr(__u32, tb[MPTCP_SUBFLOW_ATTR_MAP_SFSEQ])); + if (tb[MPTCP_SUBFLOW_ATTR_SSN_OFFSET]) + printf(" ssnoff:%u", + rta_getattr(__u32, tb[MPTCP_SUBFLOW_ATTR_SSN_OFFSET])); + if (tb[MPTCP_SUBFLOW_ATTR_MAP_DATALEN]) + printf(" maplen:%u", + rta_getattr(__u32, tb[MPTCP_SUBFLOW_ATTR_MAP_DATALEN])); + printf("\n"); +} + static void parse_nlmsg(struct nlmsghdr *nlh, __u32 proto) { struct inet_diag_msg *r = NLMSG_DATA(nlh); @@ -182,6 +281,22 @@ static void parse_nlmsg(struct nlmsghdr *nlh, __u32 proto) } print_info_msg(info); } + if (proto == IPPROTO_TCP && tb[INET_DIAG_ULP_INFO]) { + struct rtattr *ulpinfo[INET_ULP_INFO_MAX + 1] = { 0 }; + + parse_rtattr_nested(ulpinfo, INET_ULP_INFO_MAX, + tb[INET_DIAG_ULP_INFO]); + + if (ulpinfo[INET_ULP_INFO_MPTCP]) { + struct rtattr *sfinfo[MPTCP_SUBFLOW_ATTR_MAX + 1] = { 0 }; + + parse_rtattr_nested(sfinfo, MPTCP_SUBFLOW_ATTR_MAX, + ulpinfo[INET_ULP_INFO_MPTCP]); + print_subflow_info(sfinfo); + } else { + printf("It's a normal TCP!\n"); + } + } } static void recv_nlmsg(int fd, __u32 proto) @@ -244,6 +359,39 @@ static void get_mptcpinfo(__u32 token) close(fd); } +static void get_subflow_info(char *subflow_addrs) +{ + struct inet_diag_req_v2 r = { + .sdiag_family = AF_INET, + .sdiag_protocol = IPPROTO_TCP, + .idiag_ext = 1 << (INET_DIAG_INFO - 1), + .id.idiag_cookie[0] = INET_DIAG_NOCOOKIE, + .id.idiag_cookie[1] = INET_DIAG_NOCOOKIE, + }; + char saddr[64], daddr[64]; + int sport, dport; + int ret; + int fd; + + ret = sscanf(subflow_addrs, "%[^:]:%d %[^:]:%d", saddr, &sport, daddr, &dport); + if (ret != 4) + die_perror("IP PORT Pairs has style problems!"); + + printf("%s:%d -> %s:%d\n", saddr, sport, daddr, dport); + + fd = socket(AF_NETLINK, SOCK_RAW, NETLINK_SOCK_DIAG); + if (fd < 0) + die_perror("Netlink socket"); + + r.id.idiag_sport = htons(sport); + r.id.idiag_dport = htons(dport); + + inet_pton(AF_INET, saddr, &r.id.idiag_src); + inet_pton(AF_INET, daddr, &r.id.idiag_dst); + send_query(fd, &r, IPPROTO_TCP); + recv_nlmsg(fd, IPPROTO_TCP); +} + static void parse_opts(int argc, char **argv, struct params *p) { int c; @@ -251,7 +399,7 @@ static void parse_opts(int argc, char **argv, struct params *p) if (argc < 2) die_usage(1); - while ((c = getopt(argc, argv, "ht:")) != -1) { + while ((c = getopt(argc, argv, "ht:s:")) != -1) { switch (c) { case 'h': die_usage(0); @@ -259,6 +407,10 @@ static void parse_opts(int argc, char **argv, struct params *p) case 't': sscanf(optarg, "%x", &p->target_token); break; + case 's': + strncpy(p->subflow_addrs, optarg, + sizeof(p->subflow_addrs) - 1); + break; default: die_usage(1); break; @@ -275,6 +427,9 @@ int main(int argc, char *argv[]) if (p.target_token) get_mptcpinfo(p.target_token); + if (p.subflow_addrs[0] != '\0') + get_subflow_info(p.subflow_addrs); + return 0; } From patchwork Fri May 2 12:29:27 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthieu Baerts X-Patchwork-Id: 887326 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 AC37D2566D4; Fri, 2 May 2025 12:29:56 +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=1746188996; cv=none; b=l/HY/LNeAVoNnYuUdXD3tio0+7m3fO9rA1qPrgMcrymPJfRsFslm1oKqfMp/R3btnE+2MGTGpPgbin5dErECcK5IILhXJBiFtiRYq9MqQI7GbJrZfa3lp7TmwjvC0UnqIce3icpX1Bf5Vs3CcIqBfHFN7ORO1J5RxFwV9tlkZwE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746188996; c=relaxed/simple; bh=DGcYu+3DqZNwUOU60M33ZGmzLjkivOhGbY2ClBN8f/4=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=jphPvsfU8ZX9qR/bvHcCwtb4BLo+AsAyh4nUyaetN2AMuOOOGNManzlQ6KU54SDOXAWnlcahHrKNiTHLq+CIoqTHmsnxJlnI31yuZfZ3Zoz/+3uFxToOa9hVcA8BhArzubnYzTiUFuEDsGVJpXUguHYkaTyIDmXbs4SgtTImgjY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=A5Aq20Um; 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="A5Aq20Um" Received: by smtp.kernel.org (Postfix) with ESMTPSA id C5614C4CEEF; Fri, 2 May 2025 12:29:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1746188996; bh=DGcYu+3DqZNwUOU60M33ZGmzLjkivOhGbY2ClBN8f/4=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=A5Aq20UmZw/n8JuSJthdNPcL2VufHRnX86P9N5/lDJDQ1Nl3rYcA59uYY/tHf7Eqy 20yeBrxIabqqt93vElvDVvAyQqY2N8wWbX79hyCq3b9e4N4zjzMy3/byNpHlAL5yAh DQpMs3dacjTe84NqvpFxzc8NxHhycI5HaqJVDtMWKS1N/sy1JScmUWxCCZuxrBRpps DlT2947AWIfX/T6O1edUogJ4erzQ2TyPagA/1ITxwpg/XR/CsmxdK26jGoi/IozjK0 1CpV15GX7WDp3Yu8vk9AHPsAH7cRgry4JOTIw+o07lj+rQeZY4PE+9Dyh9jSJuMae0 3mYLlaeqq09VA== From: "Matthieu Baerts (NGI0)" Date: Fri, 02 May 2025 14:29:27 +0200 Subject: [PATCH net-next 7/7] selftests: mptcp: add chk_sublfow in diag.sh Precedence: bulk X-Mailing-List: linux-kselftest@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20250502-net-next-mptcp-sft-inc-cover-v1-7-68eec95898fb@kernel.org> References: <20250502-net-next-mptcp-sft-inc-cover-v1-0-68eec95898fb@kernel.org> In-Reply-To: <20250502-net-next-mptcp-sft-inc-cover-v1-0-68eec95898fb@kernel.org> To: mptcp@lists.linux.dev, Mat Martineau , Geliang Tang , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Simon Horman , Shuah Khan Cc: netdev@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, "Matthieu Baerts (NGI0)" , Gang Yan X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=1984; i=matttbe@kernel.org; h=from:subject:message-id; bh=JQOWlruNPp9QEkq2WeaRRQQFmYLUfEbcF8gyDviCmTk=; b=owGbwMvMwCVWo/Th0Gd3rumMp9WSGDJEdq2Naprr8HbH2oIpBw1DDmc9O66+ZMbL2eW/Sxarx gi4XdFO7ChlYRDjYpAVU2SRbovMn/m8irfEy88CZg4rE8gQBi5OAZjIknqGv2KBIuqsYbM0713X SJbXXm3n7VzL17fv+tTJn/mv3Yk9fYSR4X4Qg6TNhiwRyXtMXcYbb8xYXnR256/ZaZP4e3mEjWZ t4wEA X-Developer-Key: i=matttbe@kernel.org; a=openpgp; fpr=E8CB85F76877057A6E27F77AF6B7824F4269A073 From: Gang Yan This patch aims to add chk_dump_subflow in diag.sh. The subflow's info can be obtained through "ss -tin", then use the 'mptcp_diag' to verify the token in subflow_info. Closes: https://github.com/multipath-tcp/mptcp_net-next/issues/524 Co-developed-by: Geliang Tang Signed-off-by: Geliang Tang Signed-off-by: Gang Yan Reviewed-by: Matthieu Baerts (NGI0) Signed-off-by: Matthieu Baerts (NGI0) --- tools/testing/selftests/net/mptcp/diag.sh | 32 +++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/tools/testing/selftests/net/mptcp/diag.sh b/tools/testing/selftests/net/mptcp/diag.sh index e7a75341f0f32304ff4e58c9b2500d405124dc74..7a3cb4c09e450f0ae570015c4724ec268c6dc19f 100755 --- a/tools/testing/selftests/net/mptcp/diag.sh +++ b/tools/testing/selftests/net/mptcp/diag.sh @@ -225,6 +225,37 @@ chk_dump_one() fi } +chk_dump_subflow() +{ + local inet_diag_token + local subflow_line + local ss_output + local ss_token + local msg + + ss_output=$(ss -tniN $ns) + + subflow_line=$(echo "$ss_output" | \ + grep -m1 -Eo '[0-9.]+:[0-9].+ +[0-9.]+:[0-9.]+') + + ss_token=$(echo "$ss_output" | grep -m1 -Eo 'token:[^ ]+') + + inet_diag_token=$(ip netns exec $ns ./mptcp_diag -s "$subflow_line" | \ + grep -Eo 'token:[^ ]+') + + msg="....chk dump_subflow" + + mptcp_lib_print_title "$msg" + if [ -n "$ss_token" ] && [ "$ss_token" = "$inet_diag_token" ]; then + mptcp_lib_pr_ok + mptcp_lib_result_pass "${msg}" + else + mptcp_lib_pr_fail "expected $ss_token found $inet_diag_token" + mptcp_lib_result_fail "${msg}" + ret=${KSFT_FAIL} + fi +} + msk_info_get_value() { local port="${1}" @@ -316,6 +347,7 @@ chk_msk_fallback_nr 0 "....chk no fallback" chk_msk_inuse 2 chk_msk_cestab 2 chk_dump_one +chk_dump_subflow flush_pids chk_msk_inuse 0 "2->0"