From patchwork Sat Jul 29 09:57:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13333068 X-Patchwork-Delegate: bpf@iogearbox.net Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (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 E80D211C8B; Sat, 29 Jul 2023 09:57:30 +0000 (UTC) Received: from EUR04-DB3-obe.outbound.protection.outlook.com (mail-db3eur04on2088.outbound.protection.outlook.com [40.107.6.88]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 86E07129; Sat, 29 Jul 2023 02:57:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=hCaIbJWy2f4BNsjwBDYXnfXFMs09wZhsf1421Iw+3EbfN5C5qgVbw7gpL75l5LVp9YCbtEsKOfMNAnT2ZfPQYu1/XpxWFzrRQLg7YUmPWI7LjPVp85rHrOfzzDqEa1KWOh1/tDEAVeaJQI5k2OU45/5irrp4zsjpbq+ApRpxjgmf1O5JGINCakp8e+A5ZuYPbwHCzZJGu5NriDKw055XCUoHqrillewkQ3FOfWqurLtCCXs19oi0qkgbuT/CbFsX4z9oiLgh7iqjRFx35u/l6Eo5JHiAwQl3D7RoXVvB6HPNWHV1t8jORYUXeN4orKg19nkkJaTJ8zKv4UD5mpeAnA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=Uc3rWPqpo9AJ3vXV8zv6TYKhLBzpJxCa6nqvVpw+HO4=; b=gvgSY2J3O9IFAar+WHEsbUfCy53A20a+UDiPvXVq1IDJ9vHgbo2vZ9p7vFg+ogJ9Iv+V4mmgMjPDEdOaGn7l2DKiIePXc4BbDLdcSrgAmHvqBWOX3TTAjEtl0rJ9c48wKozDvJy/x6PmPzu0WHcIRpIPGvGXurrhrCHicZo52VVCPiA+L34/AXhzBYl8REyWi/CPuYthsdmrFxjGNWojlOGTLURFBESrPM99+YED7FbVc0uH5U8YzCn2MmOSBvbnu+rPMG7ZlWYdYo0oyRRrWLvm/szy1goBFoNXf1A2/TYDHrraO2Lz/3YfeiBFpo4DSEDn/ZEsx6I9RLOpByY0lg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Uc3rWPqpo9AJ3vXV8zv6TYKhLBzpJxCa6nqvVpw+HO4=; b=HgQuFWPhcWnEDFqewQmnKxHnVI34as32vjwD495WjsQRB9gqyeR0KO9f2+bjE3qyG/SKz1MMazkY8oTTYy3hSuR/sFQm2Yn4ybD9CCbCSrxcE9HkP3ULA/wdvWfCD1oKOHIgg8/QJ+lofNBORX5d16XcjVe3mKzWmDJ+JfNw24QUOUAyfdBPwVwZxYN8AS9SKAxXRclmVU1/WJvD5ZjAowfIsYtJ8xBuefyHY6AmrrbkR1Tu4Srk7ZwZxWh1+enmf645+AlRVhtZsZmBbChAmzJNueNIb98N3j6dDRf3+ZbKHP2gaFOeB1WB98v1yvoO+FwjCRoSXQHwXQEPo5Oz3g== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com; Received: from HE1PR0402MB3497.eurprd04.prod.outlook.com (2603:10a6:7:83::14) by GVXPR04MB9733.eurprd04.prod.outlook.com (2603:10a6:150:119::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6631.29; Sat, 29 Jul 2023 09:57:27 +0000 Received: from HE1PR0402MB3497.eurprd04.prod.outlook.com ([fe80::bf65:a49a:8861:4f92]) by HE1PR0402MB3497.eurprd04.prod.outlook.com ([fe80::bf65:a49a:8861:4f92%2]) with mapi id 15.20.6631.026; Sat, 29 Jul 2023 09:57:27 +0000 From: Geliang Tang To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Florent Revest , Brendan Jackman , Matthieu Baerts , Mat Martineau , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , John Johansen , Paul Moore , James Morris , "Serge E. Hallyn" , Stephen Smalley , Eric Paris , Mykola Lysenko , Shuah Khan Cc: Geliang Tang , bpf@vger.kernel.org, netdev@vger.kernel.org, mptcp@lists.linux.dev, apparmor@lists.ubuntu.com, linux-security-module@vger.kernel.org, selinux@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [RFC bpf-next v7 1/6] net: socket: add update_socket_protocol hook Date: Sat, 29 Jul 2023 17:57:22 +0800 Message-Id: X-Mailer: git-send-email 2.35.3 In-Reply-To: References: X-ClientProxiedBy: SG2PR02CA0101.apcprd02.prod.outlook.com (2603:1096:4:92::17) To HE1PR0402MB3497.eurprd04.prod.outlook.com (2603:10a6:7:83::14) Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: HE1PR0402MB3497:EE_|GVXPR04MB9733:EE_ X-MS-Office365-Filtering-Correlation-Id: 51060d3e-b7a2-4139-105a-08db901a371d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 1V6Pn18qOTTcgd2CGW3OGsePRBjt78LkccaH2pYefjN4+0wxlLAYlCVIL89HkeUJpELFEMc5TNLfiouI037P4l3VsvsDBXWZq1l60CfS3A+bsVrClYN5UyJn1L4rTitXsGnUaS8veLhTWWL3hAFvNgq2Vk3lnqFLZbVv4mSDczDcJDVz/PQljjfT4Wg3wlTg+LKCvz/UCnhDNPRCqPD9j5jaby3ysC0dU6gGqldxQE1Q2IA02r5zUV2WP3j5dhk/temSBbrBmK46i7G7AZO8xYgw2GLcY25TT57qcc5NQlJPF4sNWnuNRiQ5bZ/m36OajaL/zCPXznNQNMJRAMi3Xj6HZ1XTTKskvRq4K51DnfUdamgPm9M61kQjg/yxgEVVKzDl44oYHOOS4iVW0yYzIAq+YlwcFV9jVqxeYfQGRiIHrmoC/rN9nfasWz4syLUunh/AN9W9wTXZeLUJNvF3lrK3OAm/cU/rXG6wOhIUJgjwnpgKsbN+m8frxukRA++qRP11tWxafowx3SvCVvQtURJx88Vgryw4Z64sj9tqh00uTEfMDmOjsNz4xgO7bje7B3MD78e5Hr0kmUkMWeZz28k+T2+g+9JO+MCAPVqPXak= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:HE1PR0402MB3497.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(376002)(346002)(39860400002)(366004)(396003)(136003)(451199021)(316002)(8676002)(110136005)(478600001)(38100700002)(66556008)(921005)(86362001)(5660300002)(4326008)(66946007)(66476007)(6486002)(6512007)(6666004)(186003)(6506007)(26005)(7416002)(7406005)(8936002)(2906002)(41300700001)(44832011)(2616005)(36756003)(15650500001)(83380400001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: NwfQMjzDi3ij7zhb75TJgkXCU5qmgxtjW5gJmj1AxAJQpNWb92imztPQKlWvqnfC2JPb97gNPC4xhekOS2Y8U5WEQ+n5T+5pjI/iNx++SOM3rWWS0T9KYm8o3LkZlr2jSNKB1fQJ3WSKKoJjtUGmcNvmyjHHWxlTqv7/ZcleeAwBBShtpn0NsguOvNxnBwE7icUjPIVPVayl4JnXJP04XvljGL21bKTfJ1hSr+YrxKtOZNa2VQldMNC8v5Ebtq4805cxBVFVsccaM9KkqZcqL+c7ngC7mBl+pVeaE/IApz5o2t2oXflG6xb7eLm8XS/uBgAcjy9qgSbdWN1wb+C5ON0ic6M7xVMiUjMhrmGMgdGbEmkBBKcVOoEEFUp1YXzGWGeRS7va2CxRUY3QOAdW0SFAip15Au0BfBVryH2glocAiydW1XpiZdGIQKc6k2Kjq+QWr4ce/tS94cVDs/Y5vFbHpp9T+KP1bNf37QMEIt/otkaLNfbwpxZqhzoAcDXr3HCypFsNrH4tGxe5sbjbN6nnwXAc4SA5RqjYwQWwbEzxVY/3C8qGKqSdvLVX/xFboHdEeVuE7BILkX14cyUI4eNNqI7KRhmt6HB3x4aKG27VCSQAuK/ytacbw66yH86ONdbL6GNYOMKwsFx2qdC0id91E7xzOK26goewG3wjtOKvDWgmIB8IxWnRFCxHjHwfLqXoXwGUOp7ckMOOFEXxfHUr427ahEM6Zasy2ANkKC22GuLusUbmIUmHH9oB4h+9Zlw4b6PR7UlGOl/KiefP7c0tz0bMI9FNMF6h9UGty9gDztBqQzUxrQy4AMdv7utEKJFS/PqUYpeYvFp4tRlrOUoVfKY4zEAUt+/yhdU7nfpSmf4x3bPF+RK7CUoAMhHjXFj8ozpVa+93EmT4yzvTMgUom1vTFZ3NwTVEflNzzfduaqnxF7SELlVeE1NTARQE7szGjEk1k7+ZMRnPUjMTiwH4hRPfb5LngSnJmHar7NmiDiX1fbBMf55EPyTu0BCrKwID3SyHZvOr3KFJzbYY35xK2Ed4jy73Oj6adKaFOzRVnVsDtfIoRdTZUs8BRltsYG2WfA19PnXHp/E1Tbl7NR4JQniHeAqFu11+V9aW5gOBk3m8gUxECBqaF/4I8SkNWZ+QIyOmes99c1vECIvTIUdHqlljFL0BfFmXSkYt8IQMH66PTrt9wow0aERzgb+3L7xpznB4ZlWPe8//Joe641roM4hxZHwqACKd6GadEeqNTKjwqNKEUCJOMpha282VfLsAIlWXFR66LUE0hOQHgm1nJ8sqAFPE8Zk6R9MSsdubz4Q8gl0nMryAw8fADOf26d2wuFlifmYxdYyEMR6pGVxrNVEvEobqzQIVseNOqbVsX7eS+JSQGFm03/1RVkXGA9yylp8lxGTxiccEaSI644Q7SFnx84xuUNXuENPIx/wBkIuNRxuQyVm2sugWzN+/H6f4uk5pcUUAciSvd6p5Jp5C0KjXRoChSBXjGM9a8t3ERmelWA5Huahdjd+E5CuaGUK+tz6vggEFBrLjXInKFVw/kdwKPpT7iGdo0GrHnHrqVfoc1FllykeHMBvc4/PD X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: 51060d3e-b7a2-4139-105a-08db901a371d X-MS-Exchange-CrossTenant-AuthSource: HE1PR0402MB3497.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Jul 2023 09:57:27.4710 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: f7a17af6-1c5c-4a36-aa8b-f5be247aa4ba X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: Iw9BOxp+zLyyEO9RqxZXCe9qtJTu4A8AIPVLQBlYMbZ9g0uNiiFQb5PGBRcw7EEYxzuaCWl3gzuCcDRuzbVxNg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: GVXPR04MB9733 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: bpf@iogearbox.net X-Patchwork-State: RFC Add a hook named update_socket_protocol in __sys_socket(), for bpf progs to attach to and update socket protocol. One user case is to force legacy TCP apps to create and use MPTCP sockets instead of TCP ones. Signed-off-by: Geliang Tang --- net/socket.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/net/socket.c b/net/socket.c index 2b0e54b2405c..6837a517ac9f 100644 --- a/net/socket.c +++ b/net/socket.c @@ -1644,11 +1644,37 @@ struct file *__sys_socket_file(int family, int type, int protocol) return sock_alloc_file(sock, flags, NULL); } +/* + * A hook for bpf progs to attach to and update socket protocol. + * + * A static noinline declaration here could cause the compiler to optimize away + * the function. A global noinline declaration will keep the definition, but may + * optimize away the callsite. Therefore, __weak is needed to ensure that the + * call is still emitted, by telling the compiler that we don't know what the + * function might eventually be. + * + * __diag_* below are needed to dismiss the missing prototype warning. + */ +__diag_push(); +__diag_ignore_all("-Wmissing-prototypes", + "kfuncs which will be used in BPF programs"); + +__weak noinline int update_socket_protocol(int family, int type, int protocol) +{ + return protocol; +} + +__diag_pop(); + int __sys_socket(int family, int type, int protocol) { struct socket *sock; int flags; + protocol = update_socket_protocol(family, type, protocol); + if (protocol < 0 || protocol >= IPPROTO_MAX) + return -EINVAL; + sock = __sys_socket_create(family, type, protocol); if (IS_ERR(sock)) return PTR_ERR(sock); From patchwork Sat Jul 29 09:57:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13333069 X-Patchwork-Delegate: bpf@iogearbox.net Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (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 826633C28; Sat, 29 Jul 2023 09:57:39 +0000 (UTC) Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05on2082.outbound.protection.outlook.com [40.107.22.82]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B07F618B; Sat, 29 Jul 2023 02:57:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ZOc9p/IPWwRIJhctMl9Ysa+SbFYs3HT6nlXgoDnvp0aSiCFrI0AedZxu7DDVL3tM8vL312hnVfz0yRQEJkVVUg7G1/VPeOlpe+3bsSi5wTMZRRIAVjy2rDvS2mFUOs5dbnLGoXZavNb7GP1ScW2l4UsK9JbSUWYrtUJPTjvgCAJYtPaKRHoI5qkuiJqi9UZvclDiw2VwGFz0Pnikx0Xc5A7XYVIukE5iG73urUXCH4Qc95L7bamZhCuUiNLSK6DXXgqPQvIKJxchD66kckfGDAWLJ95YPGGJnvx8SRsYuuP6aXBtTAEeQqY9H/unPumWXrNrkgSaLLYeNo+167ydIg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=I1Lrfk98p903e1DbZjIZ95x62tbtYnhZSKnZJfsrmVM=; b=A2Y183TQDbBzsk3qnfos6BLrMqMy3D2ATLc/1NY6r4sJcIUlZbPn2VzX8LfxWv2a5eyPsn0LjBt2LQ7ZA+7FRqKG/EFSav1c34acaIxny5MQQFn/PkZbAvZtiPA9UXbwPoIfHWLDhSw2GXGD4ZsEXGt6VMC5Ya/WFoqjv8HE9pqcXxcDPwvBRghTQBj71/UUwys/zzDb2fuoaJ+ZWJgeFzKmjXPRmUtfxHLFCUqq6WLMurCcs7ejSJ8cj3Vp9RNwRFGSsCtLqmpDaaeuBwddYM1OHinTxCCExOOGXJJprg1lE8udvwOQ5AkmptJSigDk9xbqOX1YF5fclBtzBTVe9Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=I1Lrfk98p903e1DbZjIZ95x62tbtYnhZSKnZJfsrmVM=; b=TeGUefGk886+Ddaqk0+Q+sU42Gxun6ayvLuAB6VVjlXpUqsC0f7M898Pb5dRxDOZv0XhgThZMqqojsokiyBoGwKzrL+wMIb/rDTKC6t1uwEprQXelwtPgAc7INgmKZSIo+lhNCZmT5ubz+FkkdUjuS0XA22XkgLclJG9ZPfUcC6PSHEnK/ebOFvFniV+/7NHLs/NLQ55jePqePgMfHSBDcdrSzmY53GDvuKvpX5dFEhkoCwzjMF4JCnzBMoqdydJ/GnZKUeVZj/sOxlKgnLwbw92TTNwRovKASrGbSYClZXvCKDs7bR4DgMdOO7RyDiGwWuq2DvGWJ6ZREXF3/95gQ== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com; Received: from HE1PR0402MB3497.eurprd04.prod.outlook.com (2603:10a6:7:83::14) by GVXPR04MB9733.eurprd04.prod.outlook.com (2603:10a6:150:119::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6631.29; Sat, 29 Jul 2023 09:57:35 +0000 Received: from HE1PR0402MB3497.eurprd04.prod.outlook.com ([fe80::bf65:a49a:8861:4f92]) by HE1PR0402MB3497.eurprd04.prod.outlook.com ([fe80::bf65:a49a:8861:4f92%2]) with mapi id 15.20.6631.026; Sat, 29 Jul 2023 09:57:35 +0000 From: Geliang Tang To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Florent Revest , Brendan Jackman , Matthieu Baerts , Mat Martineau , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , John Johansen , Paul Moore , James Morris , "Serge E. Hallyn" , Stephen Smalley , Eric Paris , Mykola Lysenko , Shuah Khan Cc: Geliang Tang , bpf@vger.kernel.org, netdev@vger.kernel.org, mptcp@lists.linux.dev, apparmor@lists.ubuntu.com, linux-security-module@vger.kernel.org, selinux@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [RFC bpf-next v7 2/6] bpf: Register mptcp modret set Date: Sat, 29 Jul 2023 17:57:23 +0800 Message-Id: <2aa38eaa60127fce85cd4a057db523cd200df91b.1690624340.git.geliang.tang@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: References: X-ClientProxiedBy: SG2PR02CA0116.apcprd02.prod.outlook.com (2603:1096:4:92::32) To HE1PR0402MB3497.eurprd04.prod.outlook.com (2603:10a6:7:83::14) Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: HE1PR0402MB3497:EE_|GVXPR04MB9733:EE_ X-MS-Office365-Filtering-Correlation-Id: 3b9e0f67-d24c-4d57-0e31-08db901a3be4 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: CA4ch4YIlg8iJt7lcaNMJ3EVSBJRDLbMuFgfCKnYEPxh7rytOZCmorH2vPvEaDoCQClG9EVQrqoywDM9Gw5clS/1DskTEgd+OBFU6D1q6p4TOEHU+fIMh6p3GrXTZoRSY7Gof+NUDk8zxe6p6VMWRAGFyGff+EsJcTKorcAx045alara/eKnnCe5zNJ312+vHPCXUvYwQyfQHLQrVo+sxAudAb8WA06CmN0x7mBysdeWBRR416X8jA02tp6D7+nxvrfZqPIinTe/zKiJghE+4OV0W1N9VVOnHmsfqzRJ1qVIDdKxEQRkJ2NiES3y9mf/pIPET7xk6nSCFspBIriBEMFE+1m63hquoajocXrDaR3nnlKPMWz9sbs+GYJ1m7nxSgey+JH8urLSwWK5+ZgOVMkzClP0ZcG1INUwlai1+A+xH7FRlcjBov4MvwiY08xmw2/D9pSY64aLCOrMR3doUrFms7wcTBuuVlPkJRHWIwSwf5i4ETliNiHTaxl0rOBqVT9Uvk1qqoDzG7XpcywryPgOL7eGwrhTwO1ksoFiQhJtpjdJZzjnHFx+ekqsFWVNWAVk0AukOd1krLzC/oJzoXbltHXbV61xRThMiSdMZwQ= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:HE1PR0402MB3497.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(376002)(346002)(39860400002)(366004)(396003)(136003)(451199021)(316002)(8676002)(110136005)(478600001)(38100700002)(66556008)(921005)(86362001)(5660300002)(4326008)(66946007)(66476007)(6486002)(6512007)(6666004)(186003)(6506007)(26005)(7416002)(7406005)(8936002)(2906002)(41300700001)(44832011)(2616005)(36756003)(83380400001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: MUvn0ajXH7QuK6BRwvEBncVAQDokMTiDb4I2Mm3pWaWTZdAuqTyKbMtFDDveFh9e6v3QVEnCnyTlwNgnTdashzP+DPmNX753cGcMYQhFkqorAb6bQutAOkmPXASfIaxlyCGAN5XbujEWzNAtmNvLDBIsi2qbptLy5tQRPCCQdk4v5t2wFWlCSeHIssm0QywhQsMi/KcgZ108XtcmIryQ1FT4n3bI8GHWD82vSBqqEHNc6cf3XngYzRN/szVTD2TxYPEddQ3OIp10n0pqywHoAgNcdb9W30SgfFx15vgdd7kh5VWvzOCmARcnVCpkX46ghBUyyHVcj5Ay582VXUGLMbT61YooA2EhjHvJy4sH0HEwo5rtTxel7rZCZF3RJcPBBo3BKYJZE6pdpcxUbmzs9k9xBK/bWyXeyeyv4jhQpivPBvRUe4uxezr/YogWW8mk9uOKNwb5i2uPFYIPPCvhd3rgGl95P5C/afhIDYK/eEGw9y7SJu6+iRDMuZRBjagWUt14Njxo5xTEXNDTbO85/R/myuI1/rr0RSqD3Drko4JuAj+tQp3EzWLeE6JHwtNQ7Y3PiE/fISOAOxki/syWGnp4drWAwztSa9EtRqDLPjmdonXmezGFY59qHANjX/sKuuAyAbPyAcugrWr8rKEh1m55vlPD2bypFbsTj1SHdLeXY9VaRhe+7TZMvre2PXUWi/gxcV3DsKinvsvxEETGlDrb7fxVSPRWAMFOKUz0pAQYfK5PY13vFFc2U4+6JRAi8zsZsWD3KQuwrtflLWUvx2WfDkG8GJIAcIBPl/2kz5w9JjfmpHqtZOFdFiUkgsDCX6vHAqjD4VXW3YwtIFgjjrRbZTLKU7Z5mxtRqXHqYHlwJSSmMfQtCf02YAFCiq8gdrrxgCU0rVeNbGWt8S3Uohd0N2V7RauqSxRTl1GupYlbl3MLe9y2dWyWnzOrn91C/hQ5TIyYThMNxY4HX4TNKCwFNfhZ16HDTPcQgRAYA27H4tkwGCy+SNfJLvHC+tM0s8/wNQpfQ0xiRf+/h8kSKLnMJ7XeK3znHk3oMJM6ifcxAOQUodCicKsslZN7W7PN3hEGQ1vERWqnrJUk+F07mKNKNutWi9VwlOLxeIVtoe1JosYvvxlYDI96gvMct4JMM4efi86Phh9qW+UtJWVSwUPiBVA4ce17LrGBBtYJWni3Y2u4OPD4M/26bLCPqiQQDsozbhKr2ymRFOa0Q3EfnTJTL24Hi8yq+kWcvaeCCGhICxrjcRUu5qwBbHK75IRgs9rS+s4Snf7kkHjifYli3uaZ8aek21jGgGdzwowo5iXNlPaF5If/eZnHWzuv0PX8YM0VlO7u7Jcb9PjfNi4oGBSitOl7HCZ1/6T1UAR20AsI5cJdHcRCxvQcI54iFDSHUfZbiwjn8wOSg916RyLObZ1g6FJiSG6unwgg83cmmGsgiZN0+B48YCwd5Rt1+bE1j6sTjDxsRwCQMGX6QOMyqizPB7PgjKNdq5dJDi7/HFECyu8ydNHQ2K/zrd8KxSW4qXX2YE/DOA8t2DYNZqCXwwyBpeeLyb5YMA5JpzlmOa4xRtUMLtQoxVm2tchUepjB X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: 3b9e0f67-d24c-4d57-0e31-08db901a3be4 X-MS-Exchange-CrossTenant-AuthSource: HE1PR0402MB3497.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Jul 2023 09:57:35.5044 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: f7a17af6-1c5c-4a36-aa8b-f5be247aa4ba X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: o/SeF2tILFmz3H2hf8FbMPZkBkv8V5cSjAaiIWEUGfcxPqRn44kaqH+GFeiPEkFHHKTZeNWscQt3NZbt9xQDOw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: GVXPR04MB9733 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: bpf@iogearbox.net X-Patchwork-State: RFC This patch defines a mod_ret set named bpf_mptcp_fmodret_ids, Add update_socket_protocol into this set, and register it in bpf_mptcp_kfunc_init(). Signed-off-by: Geliang Tang --- net/mptcp/bpf.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/net/mptcp/bpf.c b/net/mptcp/bpf.c index 5a0a84ad94af..c43aee31014d 100644 --- a/net/mptcp/bpf.c +++ b/net/mptcp/bpf.c @@ -12,6 +12,23 @@ #include #include "protocol.h" +#ifdef CONFIG_BPF_JIT +BTF_SET8_START(bpf_mptcp_fmodret_ids) +BTF_ID_FLAGS(func, update_socket_protocol) +BTF_SET8_END(bpf_mptcp_fmodret_ids) + +static const struct btf_kfunc_id_set bpf_mptcp_fmodret_set = { + .owner = THIS_MODULE, + .set = &bpf_mptcp_fmodret_ids, +}; + +static int __init bpf_mptcp_kfunc_init(void) +{ + return register_btf_fmodret_id_set(&bpf_mptcp_fmodret_set); +} +late_initcall(bpf_mptcp_kfunc_init); +#endif /* CONFIG_BPF_JIT */ + struct mptcp_sock *bpf_mptcp_sock_from_subflow(struct sock *sk) { if (sk && sk_fullsock(sk) && sk->sk_protocol == IPPROTO_TCP && sk_is_mptcp(sk)) From patchwork Sat Jul 29 09:57:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13333070 X-Patchwork-Delegate: bpf@iogearbox.net Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (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 ABB5D3D70; Sat, 29 Jul 2023 09:57:46 +0000 (UTC) Received: from EUR05-VI1-obe.outbound.protection.outlook.com (mail-vi1eur05on2078.outbound.protection.outlook.com [40.107.21.78]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9322B2D7D; Sat, 29 Jul 2023 02:57:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=V1NURnK9h1ZPgaf/r4aZgSJFlHxn+wO6k2l16xmCy1Fbferqua24EYYUFYIGKEXLXC1t1S3Oy63kJMpzApXpjY0AqvWQf4vh3P7gYkrL+ALGGEByGAypMAeuEHqD65GXnxFx1yxB3sIBE39tIRtg2lyCLFoUxDhCjW4BoC0j4LjPWsmB+K5s0wB/MbuG1DK0x0WFvIpLD0T3jnwkwVcm78vtJTsFRYbcYpp3Cuq+tZGTZRpjRbvtgaQ8ewaGU0kbGD1Sb6stoQDbpEBtL4zrxVM+nXJw91WDUZQeVGJrEAOGD5KU5gZfkmCkjEqsGIMfL3dZwPUEXcajHFubMOOw4g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=EcaLXZJTVoyHFSatVfwmLIU99JHoAenSWZ911ljaTUQ=; b=dXYXMfN1zq4H0SZTUtQZtiWiXXXn243d8pyOnxAeXmv75v4GJGYvDZNQhK3sBi42YFIDg7q8scZw1NAEig6o3sFTjFvn6xs22+QTmT9+ZN2jRGw7muo7wS2il/vOTZziRHGqGSz/3SXka5Xze+1oAvAwyOTwUoh8mQbIoZSDir4kIyrEdWJ4+sdDz9s3b6G8WVLysasd4XZ0RzurSd2z5QCTTRImFaedTD3MbnLGAs0gQM8BvvKxIZjrZtYHhWxTYggvaE82+Et4jT2gOuBhg79vK/nJn6DtG1Pg/oey5tSq16M7ZaJu07XztwrKvPS7INPxJD74JkLuIcLIZwdGmQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=EcaLXZJTVoyHFSatVfwmLIU99JHoAenSWZ911ljaTUQ=; b=E45pRatNZLUHrDx+Sw0n8nNA0FcN7KdC0kWYyZcy15BCFtfXBm1iLWhYV2J9ZaNX17oeuR3NdIawtuOsxla5QpowSABCFffVleg5QkhoRF3Brc0vupeT/6uWXMMfdFL/QaiRO9u1FZSBtabgMoE1H698h9w+g03h/qQ+on/mHVOGKE4c7ZcBn2HExDNgpG52DMXPXe1IDMRQygjr1P+EcFVyEZBObmGPBDZnd+YcrSZHl4E7xehiRZI+KjH5QZ3uOmTpzZvrqBI/8rGmmeaS1IBEHHm+WSbY+Ai687+hzzUXFMhk7gV7Syp0D/RLBxd0X3qREXCrA2EU22fZA+z8Yw== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com; Received: from HE1PR0402MB3497.eurprd04.prod.outlook.com (2603:10a6:7:83::14) by GVXPR04MB9733.eurprd04.prod.outlook.com (2603:10a6:150:119::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6631.29; Sat, 29 Jul 2023 09:57:43 +0000 Received: from HE1PR0402MB3497.eurprd04.prod.outlook.com ([fe80::bf65:a49a:8861:4f92]) by HE1PR0402MB3497.eurprd04.prod.outlook.com ([fe80::bf65:a49a:8861:4f92%2]) with mapi id 15.20.6631.026; Sat, 29 Jul 2023 09:57:43 +0000 From: Geliang Tang To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Florent Revest , Brendan Jackman , Matthieu Baerts , Mat Martineau , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , John Johansen , Paul Moore , James Morris , "Serge E. Hallyn" , Stephen Smalley , Eric Paris , Mykola Lysenko , Shuah Khan Cc: Geliang Tang , bpf@vger.kernel.org, netdev@vger.kernel.org, mptcp@lists.linux.dev, apparmor@lists.ubuntu.com, linux-security-module@vger.kernel.org, selinux@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [RFC bpf-next v7 3/6] selftests/bpf: Add mptcpify program Date: Sat, 29 Jul 2023 17:57:24 +0800 Message-Id: X-Mailer: git-send-email 2.35.3 In-Reply-To: References: X-ClientProxiedBy: SG2PR02CA0103.apcprd02.prod.outlook.com (2603:1096:4:92::19) To HE1PR0402MB3497.eurprd04.prod.outlook.com (2603:10a6:7:83::14) Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: HE1PR0402MB3497:EE_|GVXPR04MB9733:EE_ X-MS-Office365-Filtering-Correlation-Id: a2f02adb-beb1-4980-7273-08db901a406f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: /dQlla5zUjNowrSBJ6tuAbxeU5wlGMY7FLMoqktCc61n1GzUJD8eY/HNrUPYPkFK19o/mn2uu16V5g2tCzgWcPoHYPf+YeeMjgtENBwlgSvNa2D9enPZpYW1L8gMh4mZ/L+9KapHmF7IvM07lOYV+9RjXUV5Gl+b1nduiNzCp1U4pHLlDfUNL/7E/j0do6r8k3jPvfSKgts3+Ywlm6YjmvLtx+QSiavQosGP0Djc/0FfeQ7dXs/C6AZSI6kIGVvwE9FThzHNd2A96KmQh3PojoNOKBofUu9PURGFTEbXfEgBtt8utK3VHfcxX3SeBiRzAGJhQEV5VWD1itwGIYeCj/f6Izdkrj8vUz6BvFl/kFc0NWP/Aj6NjAbOfZA662Rywa1C+e7yB2+3tGlN1H70eoOgpFf+qgjoKaoVxpYN160tDfnVhVwQMGCGAWZ4/4S6pJH7rJ0os8LFyOExugaSyWTeeZrPSmLiKxtJirHeH4nsOikgs9pfRgP36/UPUSnVssvqpTUERJjA7fene1xDBzGtcurt3xUSH1r4gMdpEsgaIZJzawDkdx3Od+iGCjhfwFqJ55EIlS64apH82J95CjKrhxN6q5Plq3VB6SrZIgg= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:HE1PR0402MB3497.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(376002)(346002)(39860400002)(366004)(396003)(136003)(451199021)(316002)(8676002)(110136005)(478600001)(38100700002)(66556008)(921005)(86362001)(5660300002)(4326008)(66946007)(66476007)(6486002)(6512007)(6666004)(186003)(6506007)(26005)(7416002)(7406005)(8936002)(2906002)(41300700001)(44832011)(2616005)(36756003)(83380400001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Fj2w0W15bj1J2J7Rs9nV0cp0PRADn11HQ3iLReMyUJ8rVwztaRGhhkrJtKQfudYmiSesV/nByF/iCj1FNYTw9p1qFZrKMwmEUvDxhrISGcHg6BIaEkdcXCyQn+VNyoTynkYcSgLCiNwaDVejNayH4XGPxzeqm9Hljk8xInyB05vXpB0kRaaom/UAywrYZWPosO26XQBACBi5+okzxW4b+fFlgaJfQg62XkQWoQ6aElmCAYhEvsyWNPCaQ6jgNcjC6KdqqpiT9AcfQzotW8zCNl4RuBFO2n/x8e9ZofhsAT3/jtMDbkCKNNDPQMlmQEY0jkZTI18sWke2UnvnTtMzzyUJ+qZTRu3lF5JPOoCyhEKw4hFbnWAxFUXskWSiFemnf4IqXcTySSm/rjlxbe2zKLp8N3kmJg13AxQPnvHnfUvCUktpH+xwRFzhWjTOiF59vo2Gx30jKvKs798Qg3tU5L4Cblitk8UqZOqCKbE1ywmOcGs2FIbBU9LIISTuey4a7EPYBRt4cUpOV3I+OcC3XW9wmQz4Fmctsh/q4iiUC4uZiJUQVdrt8vZaC5RorRVsGQdqJYx1G2Wq4qLAzJo/PomXHalUVVDgv9cUqGZLETgW8/6sYA48/PCFKbmM80+HqC9wCnB6eHyATUqf2cpiKfcyeJ49AF2eHV8xLjtdTHhJewlmYN5c4OkV4fgLiYJspyav+EuYycQvM12x2sIwGawVDXZyXmSxwXInHPshymC6rJP+7VDltGt04eSgo5Ql4W++nXa3i1xmYyP6BkPryS9fdlmQytR1Scr55BfyGYhWsuPJbAuQjcJF1pJKMfmqORs3ErC6uCj7xh0XG7/f6BI1UI20CYlD9cUD+Tq2HcjQ+tGVFZzkW8AAfCo9S+T2A7ucrYHxQA+G8ytyy/HpOLW2iE1vFjrdhfp92xSPXM8ILXrDooPqBZ4rpQlRAp7mjhzHDqxNgb1QiUgwu/HTSEPfjglnolzva7mkRqTMDboNLqKkAYaw+fku+i0DEzmz4p+SOR9a9nunyGMv+mdrRSKFjpIv+MljtjuSfajrhzHOEdhZ5zgfdQA1yLjfcdrjPUOTKkk8kQVhVCtC1gDIckrUN6untf7iacVf0YzPWfh8y0tTbhbSRMhEwnhdnqb9RY4bhBcd22Qs2aRl8GZ0pfBx9J09tZq0W59mR2xbzMHFeeWaQi7W3+gq2RFhb/ORns4iJMtAQ+N0fUIyRKtDo8mu1LmKRVQJnu68Rz//q5hRmBh6T2aV4+tnD2D2DQaiYLb8DtLrS1JUZBXtU770869TlnajzleaHqAy5xCogdBFvnLynO91BbwLD9EvpkHQa70y+IZ1iDFY9zv3LNtuWWPFdBouk1OaW1Q9VJSJoyjvgP0cXV0PZIRw+dAfYErLSvEcS2wmSJV77nUqLmhrawFpDwzVC2TVnUI4jOo+rz4VdLyZChS4UE1LQD17pD5ri2NrnAijCXD++F5KYo9c4minCwesKlzH5ypTQ46zoCeAduKLp2upuEkmfchs/YOmBwTD8++NHacdBQqt7nvPM+9VivNAQyhU85u99VvHwIHKwFG3wgAzxOgb+FSKgsi2 X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: a2f02adb-beb1-4980-7273-08db901a406f X-MS-Exchange-CrossTenant-AuthSource: HE1PR0402MB3497.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Jul 2023 09:57:43.0864 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: f7a17af6-1c5c-4a36-aa8b-f5be247aa4ba X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: ioz81jGVZzM2YbIquirHnRj3/yburwcLc+KJh8mHxTZLI35SNC1fGd7Cl6AI1NjNxm5is1RreorLSHlyeDE82g== X-MS-Exchange-Transport-CrossTenantHeadersStamped: GVXPR04MB9733 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: bpf@iogearbox.net X-Patchwork-State: RFC This patch implements a new test program mptcpify: if the family is AF_INET or AF_INET6, the type is SOCK_STREAM, and the protocol ID is 0 or IPPROTO_TCP, set it to IPPROTO_MPTCP. It will be hooked in update_socket_protocol(). Signed-off-by: Geliang Tang --- tools/testing/selftests/bpf/progs/mptcpify.c | 25 ++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 tools/testing/selftests/bpf/progs/mptcpify.c diff --git a/tools/testing/selftests/bpf/progs/mptcpify.c b/tools/testing/selftests/bpf/progs/mptcpify.c new file mode 100644 index 000000000000..9cf1febe982d --- /dev/null +++ b/tools/testing/selftests/bpf/progs/mptcpify.c @@ -0,0 +1,25 @@ +// SPDX-License-Identifier: GPL-2.0 +/* Copyright (c) 2023, SUSE. */ + +#include +#include + +char _license[] SEC("license") = "GPL"; + +#define AF_INET 2 +#define AF_INET6 10 +#define SOCK_STREAM 1 +#define IPPROTO_TCP 6 +#define IPPROTO_MPTCP 262 + +SEC("fmod_ret/update_socket_protocol") +int BPF_PROG(mptcpify, int family, int type, int protocol) +{ + if ((family == AF_INET || family == AF_INET6) && + type == SOCK_STREAM && + (!protocol || protocol == IPPROTO_TCP)) { + return IPPROTO_MPTCP; + } + + return protocol; +} From patchwork Sat Jul 29 09:57:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13333071 X-Patchwork-Delegate: bpf@iogearbox.net Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (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 0E8B13C28; Sat, 29 Jul 2023 09:57:54 +0000 (UTC) Received: from EUR05-VI1-obe.outbound.protection.outlook.com (mail-vi1eur05on2068.outbound.protection.outlook.com [40.107.21.68]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0CF5130D6; Sat, 29 Jul 2023 02:57:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=EeU4nW1JrzOOeNqWBOQuF9hJ1mv72ebDwpAHjC/a2cmxOhJ9aUJYTB/Ta74jqdWSZIsEoZUDOIN6qTWQ7sVRwv0aTzCo3WCS24QOzLRKYcSZqI/e0djf8NiiXRoXOTKOsJ6l9f8Am8mlmhoxQtOcO3zvmaYkHK5aS64TlTMNvLt3yJXBjS4Wp+bW51a2cSCpLLnMgjsToZkvBxpyPcX05ZOevvU/GDY/9gYoq9aP9KIycrgyOoKoROlr1B5R/3V0tLu+I+rU2+HXIjEcFWEXP//DDb92QraXkOzr5VtTtZ5+AXaqQUyOkvswMMZv1+sBOM/MWpV/E2lXwcCo6sd/nQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=02iyHHjkQUGelZcQ1iDaZ+J0TmCKyxhCWbnucp6bY4w=; b=fzzwnvq1aY05TXqdnWtGSdGv96oPF3KW8WjICLR/EOvdnvKL+QQEZWLBMikcAZ51IEMC3DjTSbUwUxJaXdfOf3K543AiVZ+0G/WESkSypXJdJ2DOS7hZOQunc1tw2OBQcEphZmg1+wIZh2sMfddx/0OwOYfgV439OZWPngX1WB1fwRCp6mKPlv8ndz/kyUjcLe0wLe7ZJSrW68wmVrDLpjuMT9dF8O7ixRHfW0FC/xKdOMYFj/R6DG6U3eNaBEDwuL3h3lfF5SMw8MR/cuGIm96AsO+KbTtactQyQu2sL9AY6nicmbdnToqrjUyredsnCqLP+2dfF+75+uIuXaCxMw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=02iyHHjkQUGelZcQ1iDaZ+J0TmCKyxhCWbnucp6bY4w=; b=db+o3fSCXHo3Z1sYVvbs8Qaj8yYzGlMaI5BQhI2kh/FNIhJzbYKqKs+sASMMQUMbAiX1vBdUXC9t6xTSNQSu1NozZ5laz+I9KwO9JyQPVxwH6LMUQmlHTd2zxvyl+bnMth8nOFb5pYol7OaUB0wZgv8CvG/Os8MWUkHhVnBCj2fjsAy78PKj1JNFBQ/IMSLwHhlYgZEGiK/6s/KX1u5xrE7q6S68KRo5szHXrdAu/MDyYRrTYruabOL+gvo2AZvKBPdMRw37aLxnZEcOZo1BciyIUS6Rq6uj5ip79TzIugxCrhngQPP2uWekWqP1ZonFAfuHu3sRab6w4bEJqHmwVA== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com; Received: from HE1PR0402MB3497.eurprd04.prod.outlook.com (2603:10a6:7:83::14) by GVXPR04MB9733.eurprd04.prod.outlook.com (2603:10a6:150:119::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6631.29; Sat, 29 Jul 2023 09:57:50 +0000 Received: from HE1PR0402MB3497.eurprd04.prod.outlook.com ([fe80::bf65:a49a:8861:4f92]) by HE1PR0402MB3497.eurprd04.prod.outlook.com ([fe80::bf65:a49a:8861:4f92%2]) with mapi id 15.20.6631.026; Sat, 29 Jul 2023 09:57:50 +0000 From: Geliang Tang To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Florent Revest , Brendan Jackman , Matthieu Baerts , Mat Martineau , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , John Johansen , Paul Moore , James Morris , "Serge E. Hallyn" , Stephen Smalley , Eric Paris , Mykola Lysenko , Shuah Khan Cc: Geliang Tang , bpf@vger.kernel.org, netdev@vger.kernel.org, mptcp@lists.linux.dev, apparmor@lists.ubuntu.com, linux-security-module@vger.kernel.org, selinux@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [RFC bpf-next v7 4/6] selftests/bpf: use random netns name for mptcp Date: Sat, 29 Jul 2023 17:57:25 +0800 Message-Id: <59d5ab5d065bc35e26b31fe965c10b8c22aeae9d.1690624340.git.geliang.tang@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: References: X-ClientProxiedBy: SG2PR02CA0102.apcprd02.prod.outlook.com (2603:1096:4:92::18) To HE1PR0402MB3497.eurprd04.prod.outlook.com (2603:10a6:7:83::14) Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: HE1PR0402MB3497:EE_|GVXPR04MB9733:EE_ X-MS-Office365-Filtering-Correlation-Id: a0820d99-81a9-48f7-9946-08db901a451e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: vlktoZ/VtgeGF9MB+JBeID25VaZpDZ57qUgNd3zwraYhXM7wsWsu3h4KJGRYotOyG3IO1ysBE/B01IAC4ngjPPYJrzkilviw0EWlJjHu+Nsg05mKgSE8QTAx8t3uQNlaKut7dHsbeJDqEyxc+PgnQDmGfdnJwH/NVrHQzdu2k41OSt/fjjmIq17EGRb6eqRp+0NanyWCraj+pIlON+sEybRnPQVLNbELIm/FkguVk7EcLdSANnFr0/+uT4cFyq5FoDVVWiHIqysMjC3v9LoFJ4rHuOEvKgTOIUg1yFDIBRMONF4jdH38m8HDqAG1wRkqyh8Bkuz9ARYHAv16UcJl7DbMP/jkTtsibNAnT/iYRvnMWo+ez1BltFfqVydCBIcxYn9vOhfjY+T43B6e/5xy1y2/80FtiPI/igqGWhQh91q7kfNRNnqhioaBcMgWpI0IcSEJz7LyUER5DTEswmJsBk0cWaC7XMGy6GI9peyTMv0rdzATIgbz8+YwhS5BAy2TIGOYzHck7+P5mmeZ7W9KGVAUbS2jtwqgDgCal6xsThJlwBqg0vJFvweVNo2XD+A7n/azIdm1Z/UbpOytz24BcNaVnSJV3r3DfzlxPn+vB9NP2h0sV4PrcACRVPnLIJ6H X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:HE1PR0402MB3497.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(376002)(346002)(39860400002)(366004)(396003)(136003)(451199021)(316002)(8676002)(110136005)(478600001)(38100700002)(66556008)(921005)(86362001)(5660300002)(4326008)(66946007)(66476007)(6486002)(6512007)(6666004)(186003)(6506007)(26005)(7416002)(7406005)(8936002)(2906002)(41300700001)(44832011)(2616005)(36756003)(83380400001)(17423001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: s5MzrCSpLqzi8CdNE5+gC94L0x85wyTYOWHFIP0gR7tSrazwwQ9ALDLH3XGdfjp2biT78cvbzIVCEUVavPhQ8Jn+cf8CY9tDRYcLHSVfhx/j5b5z0/IGAOf8/w9UC0AjYmBL6yLsWQjArxOl0z3yNg7Q/vw2dDDOTS+eAmKBJR4kLVTLUZ5lKj4K+U65Xs7bvFooMPFJMTFoC3Auzkx3rIm9OZoyJyFl3L4Vnl0W0Fgw70nLS2kmELxHcNbXSr4dqMwijAe1BM5j+ne1DDdXCikvSHtBHhKDtg2f1yXxb+bIgdYG/jWRpDegXqao7oVG8HZCdBY9NZps4PgvDBCSM1SMcDLqKr6ATEVhVHF2q+IYP4fMXwPsV9nXNknpujdLJu3r5N90vt/G9yYS9l03srQN3l/wDD5spqKaqcqyoj9uh+34QakcIocyMFlD5sHmQFX7ivaN63y+97JSdZvQX78XqXaZxgJmYT4ihGlSLUT2dzKFbMGMqCsYqICcjSU47yqQ7ghX91aTEiJZw82Dqrku1o/VHlW4ZVr590EfACmpNDjnNsYct7MLP8jRDtyJvqdrST21qSr//kHQYiyjZNd5H4hML7cktgEdOREt9swigJ7RiaWfVpJvTRZLknInNp2rYmWZdI80WS6WAmIm8w+060gXubsyxETX/KnUel3Rw42WkJzf37ntUO5sKURJvqUOqaeW6cQV7yKgbFSaOqMOTXgVVCZgaT1ufetvctKh7k/YpCFM2O3GUq+zqfhzPM1pIV8KHhC/IhkTvJP1bE8B7ErpnczdfvKbsCe4GGXqet5DUXl02g6E8mSkSgVrx4ZnY+4qrDCmcDLRDAHbe+A7efn0Q4G70KIAS58Ag7YMyiZs+QvMDRSCYMoou0QKic3rnKBDLbgiQAD/N0nhK5NmoI3QDPnO9Aamvc7urC9cd9lfRi07QhzYEqJLu8VW5i+Sj/PCjgfBKrQ2xkdle2wURIQiOdOs8W98R+qqC5FmuZ6ONIQwSaqAbZqYWoYioDwEDVfReTrqGiC8qdgWU6m0qhPNLmKpDIsCWNbQvI8O346a8Pn0XFGgk+EafQShE4vnlO4narXoMz2eze2YgZb2XDO9th/I1v9xuOxhimjLoAB/xlAQNmH3wbeIs37GWZ+G4ozmI2z47XumRNP6L3NkFlZk9Nxy8H20pFl24fRCRaQR9J9dhGdDH4GP0toPyxTH1Z4cHCnODlvxGmsM/h3gSqyn1hFz4y8s7tgOmkHU/7flQeCU8RQpUjOHCwrivBRdtbz4eaX5gD8mVdXgvpaJm6kyH9sOCVTJ9++bhYRqCqx83SYsMJ8Ijim75AJnOlu+2G65jIG5/jr2j2bp4QgRxl8deQLbv7aJxo3OoP/WQrbXDnAVxg1NfTHle4aNu7PS77wNLLF6PVOo3zbEuLIpfKNvFgSmXXx54j0y/sJyGpRQ3VHMd5V2M9g2CXQljiJe084bM8CfsH5o/EgbsnA4Tfe7l1ljXcfjtEYOnpx/Cwli2z0Kryim/Opm/U/fc2LAkaSxo/NuQF2OhjOSChjaQCTryQTNJV/WlDwNYExtDWtbB1L8RrcQ1/x1ywBd X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: a0820d99-81a9-48f7-9946-08db901a451e X-MS-Exchange-CrossTenant-AuthSource: HE1PR0402MB3497.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Jul 2023 09:57:50.7748 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: f7a17af6-1c5c-4a36-aa8b-f5be247aa4ba X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: x/9AexyCJXiNo4zrg54Gy5sT4Enl+e/aSI1AH9ANMUf35mhg6VAYZvxvgY/JpKSJ/92ur2PbIxvEw6RH8QcVNw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: GVXPR04MB9733 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: bpf@iogearbox.net X-Patchwork-State: RFC Use rand() to generate a random netns name instead of using the fixed name "mptcp_ns" for every test. By doing that, we can re-launch the test even if there was an issue removing the previous netns or if by accident, a netns with this generic name already existed on the system. Note that using a different name each will also help adding more subtests in future commits. Signed-off-by: Geliang Tang Reviewed-by: Matthieu Baerts --- tools/testing/selftests/bpf/prog_tests/mptcp.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/bpf/prog_tests/mptcp.c b/tools/testing/selftests/bpf/prog_tests/mptcp.c index cd0c42fff7c0..4ccca3d39a8f 100644 --- a/tools/testing/selftests/bpf/prog_tests/mptcp.c +++ b/tools/testing/selftests/bpf/prog_tests/mptcp.c @@ -7,7 +7,7 @@ #include "network_helpers.h" #include "mptcp_sock.skel.h" -#define NS_TEST "mptcp_ns" +char NS_TEST[32]; #ifndef TCP_CA_NAME_MAX #define TCP_CA_NAME_MAX 16 @@ -147,6 +147,8 @@ static void test_base(void) if (!ASSERT_GE(cgroup_fd, 0, "test__join_cgroup")) return; + srand(time(NULL)); + snprintf(NS_TEST, sizeof(NS_TEST), "mptcp_ns_%d", rand()); SYS(fail, "ip netns add %s", NS_TEST); SYS(fail, "ip -net %s link set dev lo up", NS_TEST); From patchwork Sat Jul 29 09:57:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13333072 X-Patchwork-Delegate: bpf@iogearbox.net Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (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 D742E168A9; Sat, 29 Jul 2023 09:58:02 +0000 (UTC) Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05on2040.outbound.protection.outlook.com [40.107.22.40]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F0CE22D7B; Sat, 29 Jul 2023 02:58:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=LFYqBo1bDzNYGrjuUF84XVboTchzNyovQMeotJVFBa8JEOhGlJfJIGRHv+CV+AFDYuaB1nnJUDmH8zR2PJpZOHIpW64cIRicGlEi0L0pn0GfmfGsVjArvdcNaMProjyepprJY/Viv6HL8tU5DUtLfflrnkruuNaw+fcd2WdkwdMU8yqu3JEbnHvrMXD2uq5SNwLyd2sRG5+i1kffEn+4mxTZDXKps0o4WSu0UreEh/mJjYshUqxJCHPfww6MaIw/+DkNPS8pIFsWs+6HoAt8lDA5Bmtfb3d/noBu1qjwGNrkPqFucdYhJbx77ykWqkPJUNkQrhjFXuHU2g3sdu0KrA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=lWqMc9UT7yWdDRGAA1JFdqK94iY4Pu9Cr1Kw+TYOXMg=; b=QiYosVczsBfL0aOug+dfCqCidflNBYNIBLd0DrpWevV65kHxKc+SO0LIG8rApspTB+z7FyXSJfLH9bdNpjJlxvm+/GeOPrCOsy0i/puK5nKxogmxgx0XSEK5CRhSbAvUjmkedGvEgK9RJBcbPKo1i8poMVv0os4YDPrrcUWogZRJp7l70SdIyVdm0Rb6D9X/Yv1kPuc4WL27wtEcEIQnMBgQ4UuwWvjp51w1XXOfeus8M/BKqNDCfeskuueWyT48IjRGcOl7tKRTH+O/oSpDG9M4slalfC4tU6lFrIDdR/emVRSl2uyvXSAljow6FtkxSGuNc2iNyd1euPIbur0lbg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=lWqMc9UT7yWdDRGAA1JFdqK94iY4Pu9Cr1Kw+TYOXMg=; b=3SUSk6bg+QZpGzUapyPgsJ9BrK5az93661JfbUQRFSshDBpoJuvowc75zzVg/QZwLepoUxBwHpobuMu9G8o99JnvCEMLb81OQDhnDIjHLR0xfXKkaodPpLFQQtfy7fbtyJ8miEK4UfbWnM6EUEbzpozgzRHjDjivtTDnqKH7AJVrfbjrekIsG1cVeiAAiMlLv+gHkiStJ/OVIzN52uoS4zwTaZYLlaJGzH6xr5lDRaZ8O1BVrMNEoBkgg3wsTlgLYF7R7vmTb8X/tZCT7Egeacu8FuieC7HM4dPbpHer5mMH2orKOEvZfvEs/nRXS6GXMqYF/8IA9xhSZsPJaJWCbA== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com; Received: from HE1PR0402MB3497.eurprd04.prod.outlook.com (2603:10a6:7:83::14) by GVXPR04MB9733.eurprd04.prod.outlook.com (2603:10a6:150:119::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6631.29; Sat, 29 Jul 2023 09:57:58 +0000 Received: from HE1PR0402MB3497.eurprd04.prod.outlook.com ([fe80::bf65:a49a:8861:4f92]) by HE1PR0402MB3497.eurprd04.prod.outlook.com ([fe80::bf65:a49a:8861:4f92%2]) with mapi id 15.20.6631.026; Sat, 29 Jul 2023 09:57:58 +0000 From: Geliang Tang To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Florent Revest , Brendan Jackman , Matthieu Baerts , Mat Martineau , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , John Johansen , Paul Moore , James Morris , "Serge E. Hallyn" , Stephen Smalley , Eric Paris , Mykola Lysenko , Shuah Khan Cc: Geliang Tang , bpf@vger.kernel.org, netdev@vger.kernel.org, mptcp@lists.linux.dev, apparmor@lists.ubuntu.com, linux-security-module@vger.kernel.org, selinux@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [RFC bpf-next v7 5/6] selftests/bpf: add two mptcp netns helpers Date: Sat, 29 Jul 2023 17:57:26 +0800 Message-Id: <49e5ee337d2943a7fda9f1cf61e47c24ef78c5bb.1690624340.git.geliang.tang@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: References: X-ClientProxiedBy: SG2PR02CA0106.apcprd02.prod.outlook.com (2603:1096:4:92::22) To HE1PR0402MB3497.eurprd04.prod.outlook.com (2603:10a6:7:83::14) Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: HE1PR0402MB3497:EE_|GVXPR04MB9733:EE_ X-MS-Office365-Filtering-Correlation-Id: 9fddaa7b-1e1c-47ad-c00b-08db901a49cd X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: T32DD3baHEf9uYiXkaBsW1rYlhKekO8MQIeV9wTZd14k5bc1v9AvK8tM3kp90TSDx7LXfWi1XncVJxwI88gJD76YUUZYVHhipQtkxnpCbc2tjlsILlwVrwsBT/Fpv4wV4hf3spUR6ElmaQLg5AtlbeXQohVNXxXETWSmYEkyYrFTzw26VvHV0Zw5xHEIGqPPhIKP6mVy1EGTNUGGiBaHnq74jyJ6g/G8UrD8EE2UJwgYdtlR18lM2iPgfrKaM3Jf6IpYqGkAnD+l+OTVahIyouCAtRnuYiFA0tzemQwxsyDUmT68nAxSZLQdahyohkO8dR11mh2yB+W7Ht6jcM/4a1YSQkjC+GSX5UJXuEvmwvLrxNKEn7rQ7oc8VlABvyzaPP3jJ4Utl/NSrXX614dkYdLdCpzOKO/+9xUeAFsYsanN8fzU5b2zogJj0n1/rQTn/lEKfqsFgH4Hbp9Jl2/IYtWKUtYRdzY8Nh+SsxWMzeafaycTCrPDAa/JnIUdvYXUBGLG4FaLGl2iW6+fYc9JqCN49j7mHFZi0g9v2615wCvKBp6fEDNlmU4EiZmlE7GXWaGTFHY74eocHL4Na8A1psyGNgU1PGy2GC3LSAGq87I= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:HE1PR0402MB3497.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(376002)(346002)(39860400002)(366004)(396003)(136003)(451199021)(316002)(8676002)(110136005)(478600001)(38100700002)(66556008)(921005)(86362001)(5660300002)(4326008)(66946007)(66476007)(6486002)(6512007)(6666004)(186003)(6506007)(26005)(7416002)(7406005)(8936002)(2906002)(41300700001)(44832011)(2616005)(36756003)(83380400001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: abeUrEJrUncTovy4Xzk0bJAkaHR4Xa5Iax3hUvDwP/yVJZTj0cb/MuAFO++6LJWCXWmpWBvUurqPBXp7I06w07xzdiwzeiPb8EB3ldNIdOVVT/kvHOm85QWn5SckpKwdrQfh1OBvoNN5jg7+xgKvuiuqXthUyKZORSYik6Fn6fnxGxAS1ME2DZMVzeRioIMw+giM/ZWrd46tOkg2hu2FFruE+SCq4jAK1tWOVz+CCkuenr/CCA9pbiYgS8isrBBqoYLtjN3mofDxRTQb/IZMhZUl7uTgmJlOPqF5ClzMi1g/wLSikpHKJwrnvr17/Ht28cDAQ9Ivve8im1VQBczCe2H/2PNMzgbLgNxVZ32X5ApKhNoQ9pnRe26Le1PDZQi6WrZDYxfsFJ0B1DlRvA0dr65Jyv6Xx5XdGsDewnCWKtWJwyTDV3iyUg9F5SZ/sXf1wtH9LRD24lCUxa1zi/o4l/A+4k5jC0oewqJczMpzq4sdEt6SFFYnlnn79kRvoXlLDRjYWJ/szSqUr/9SexkjJNljyHh0mgbaTtCl7X4kNYOeCspE+VXiIUW2IFCvCXCfc7YTW+xcG3hioiEXzyzc04gslQhs60vESPrZw2AzycuUr7xCeC6Y2ZweqcsnhnoynaObLrxaNKznFp3ZRx2pKVn1ksBTqFgTaMZEWEZBmumfSxDOourVlXhiuaqCnrC3RAjCqB6ThM2O8dhk+exXeOl0qGAVBd9ISVkvK7finLn5GHUiu9opJJNk/Lzg7TYvSw9jWoNTFXkDBHPX0Xk0vHGopP/Cd64R+XekBT32D/QXAzK/WdiW+8+b/mh5wjfDxATJMT41J6nkIc84BRL0JeDTay4i4uPLdP9nqz5LwVCNtookriOK8O8Dxn1oF/CsD7536MzkQJDWLwN+98A3BR+qC9PQ4EuHeBqSfuhxMkFkgMesErHBP1avIFaNpCie6jwG9EORVkt2hb5+nF7nuBxknXgtllz6oL1t9ZE5TR8mErApYLmD2C6m+RVyxDpl7vOE4JdkbBYtht5lZhrPVqDaJBJHkXC4R/xupn7t3V2OejDbkaPCsEp1lbR5xzzIn5XYvN2BF3Y4jpHL035nTOVhz1mAX63anFdPHm7BPzD0MwEUZo5643b1l5F6jaSpNAYX7FQ09ZOBF+YbAMPTVYv8AT0gB/+I83g0rOgxgGYiGe1tKs8t0QzBE/p5E6Z1MlYJzMxFEk1949epsifzApmZ8e2cZHvvMmLrvs5+k+INDAV64SAYW/lOcNgQK2YQIgUd7OoaEAzVsxJJtGdIsr8jCKHxEM8/kY/9vrvzmqXiCwZy/fsJpB2SkFylg7YwWTueRCx9ohaOvA8y9iB1w4GG0EGk0cOsFh6lMqkg3JeB45mO52YNWulPDf572OFTBi9lmJjhn0yz7/fuPikJVQFTlqVm7jiokGkzNpt5pEcLzmKwSnLqL8O6oHpzJ4XoCRH3Zy0cznrsM2r8jwyvCluh2Dk4vb26E/+w/SPIjbPoxu+pBHjUZjpvHo3RiHek1iRmFr0paH7acgVwszoNk8sRtajelbB9+vw00eihojXM7ol88AEHTCG/y9p/Ktoh X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: 9fddaa7b-1e1c-47ad-c00b-08db901a49cd X-MS-Exchange-CrossTenant-AuthSource: HE1PR0402MB3497.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Jul 2023 09:57:58.8549 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: f7a17af6-1c5c-4a36-aa8b-f5be247aa4ba X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: IYVdwR8QqJKgh9zzSmNvlZfw41FnCjzy0d8CLFx9Ed5BZTGMsO9j0MuTkxICpS2gZkVtdVPQmty8KR/8U/nh3w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: GVXPR04MB9733 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: bpf@iogearbox.net X-Patchwork-State: RFC Add two netns helpers for mptcp tests: create_netns() and cleanup_netns(). Use them in test_base(). These new helpers will be re-used in the following commits introducing new tests. Signed-off-by: Geliang Tang Reviewed-by: Matthieu Baerts --- .../testing/selftests/bpf/prog_tests/mptcp.c | 35 ++++++++++++------- 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/tools/testing/selftests/bpf/prog_tests/mptcp.c b/tools/testing/selftests/bpf/prog_tests/mptcp.c index 4ccca3d39a8f..4407bd5c9e9a 100644 --- a/tools/testing/selftests/bpf/prog_tests/mptcp.c +++ b/tools/testing/selftests/bpf/prog_tests/mptcp.c @@ -22,6 +22,26 @@ struct mptcp_storage { char ca_name[TCP_CA_NAME_MAX]; }; +static struct nstoken *create_netns(void) +{ + srand(time(NULL)); + snprintf(NS_TEST, sizeof(NS_TEST), "mptcp_ns_%d", rand()); + SYS(fail, "ip netns add %s", NS_TEST); + SYS(fail, "ip -net %s link set dev lo up", NS_TEST); + + return open_netns(NS_TEST); +fail: + return NULL; +} + +static void cleanup_netns(struct nstoken *nstoken) +{ + if (nstoken) + close_netns(nstoken); + + SYS_NOFAIL("ip netns del %s &> /dev/null", NS_TEST); +} + static int verify_tsk(int map_fd, int client_fd) { int err, cfd = client_fd; @@ -147,13 +167,8 @@ static void test_base(void) if (!ASSERT_GE(cgroup_fd, 0, "test__join_cgroup")) return; - srand(time(NULL)); - snprintf(NS_TEST, sizeof(NS_TEST), "mptcp_ns_%d", rand()); - SYS(fail, "ip netns add %s", NS_TEST); - SYS(fail, "ip -net %s link set dev lo up", NS_TEST); - - nstoken = open_netns(NS_TEST); - if (!ASSERT_OK_PTR(nstoken, "open_netns")) + nstoken = create_netns(); + if (!ASSERT_OK_PTR(nstoken, "create_netns")) goto fail; /* without MPTCP */ @@ -176,11 +191,7 @@ static void test_base(void) close(server_fd); fail: - if (nstoken) - close_netns(nstoken); - - SYS_NOFAIL("ip netns del " NS_TEST " &> /dev/null"); - + cleanup_netns(nstoken); close(cgroup_fd); } From patchwork Sat Jul 29 09:57:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13333073 X-Patchwork-Delegate: bpf@iogearbox.net Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (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 4DCC511C8F; Sat, 29 Jul 2023 09:58:17 +0000 (UTC) Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05on20611.outbound.protection.outlook.com [IPv6:2a01:111:f400:7e1b::611]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A9355129; Sat, 29 Jul 2023 02:58:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=TK5E/NnDzEHI986XwzHzSvvNa3/ZCxnRnDK+24CfFvulKSpjG1Nnss+5Nn7GqgeVKtY+/y621I+Dde5wZnOVBrLhM/Dux12WMmk8Sqpiht1m+W9KdKVjPSXx84lVqTjikbekJ8xWIO74N6mdVGXQD35mxFeyd/gDlFdped9Gjp5YALbS4EARRS9yXx1PWy7G/9w8+UE1VzIuQcot8NfgAdsghiRT+vluQMSIb8NtEUh5JiCR3NKOPX454VYXMwJTRsyvDpbwfhAh7xAx37onYgx9QkcyW/T5ID+XXJbELVHy86FPhJ+I7hrEeYo7h+5RlqeoEkUgejhLHMlpt0v+iw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=fNR1Z0O8+imQ4xIF3S+4EWt9/8j7kXiMDTOLw5RsoM0=; b=kUkDSxU4jGQen6v9eiMJdJFj4exKUeVfKEbPWXUkREtOM82gTWzvClDMq806S5K9reu94NeKsV6HJKUiSD3MM6yb6GrZT8LICjpG8G33HbOwCplrukaodjBRe6ZPo7PonkNnhC4vSAkVRPX64PHlyC3IOpclVSiUyvEY8yFjwf3MUliJG4DFNBxbKKTg15eXunCS7OyiFunQY6VkqHla1MaoM4YPIuQFi94pOPQgj7BmqPUaWFkKsn5DWDB2LZDyiauRv8SEaagQwYzBEqySwrdk6/jai/r5pOqcVeDhX6c5KfhiCj5bTiVTGe3zkz8Zm7+/j5gNFX616iJwD534dg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=fNR1Z0O8+imQ4xIF3S+4EWt9/8j7kXiMDTOLw5RsoM0=; b=M+T/9HmucdQBGrBB7SzhoQTk3BVluLQhR9Z7Kx1ew8laMW87dlNBAfWpP55VS/r+sTvgBwjTXV8Scw3Mde6AylmknFNDHZwBCzVZVFH7Q6dibOPjaW+oYsuPFi0gR8gukEsEqQqHHnetG2BP9b3qeogT7DQ99fyTwB3UiuWaVz3VjBTHfNadiQpjgtlBP7YJDgVkRbgQUkW7+5Wnraofe4opETcwn5gxwaqm838GVukp33UfpnGxFdTHA17G3wUtKZLP2HZZMcSU/au1kp1V6QjAsRJ8yhR6mVrxNhLSF7bikoDZXYanpfUmwwcgApItNJmFl7jKiLb8LpqDV0UZZg== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com; Received: from HE1PR0402MB3497.eurprd04.prod.outlook.com (2603:10a6:7:83::14) by AS8PR04MB8417.eurprd04.prod.outlook.com (2603:10a6:20b:3f9::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6631.39; Sat, 29 Jul 2023 09:58:11 +0000 Received: from HE1PR0402MB3497.eurprd04.prod.outlook.com ([fe80::bf65:a49a:8861:4f92]) by HE1PR0402MB3497.eurprd04.prod.outlook.com ([fe80::bf65:a49a:8861:4f92%2]) with mapi id 15.20.6631.026; Sat, 29 Jul 2023 09:58:10 +0000 From: Geliang Tang To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Florent Revest , Brendan Jackman , Matthieu Baerts , Mat Martineau , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , John Johansen , Paul Moore , James Morris , "Serge E. Hallyn" , Stephen Smalley , Eric Paris , Mykola Lysenko , Shuah Khan Cc: Geliang Tang , bpf@vger.kernel.org, netdev@vger.kernel.org, mptcp@lists.linux.dev, apparmor@lists.ubuntu.com, linux-security-module@vger.kernel.org, selinux@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [RFC bpf-next v7 6/6] selftests/bpf: Add mptcpify selftest Date: Sat, 29 Jul 2023 17:57:27 +0800 Message-Id: <27a7ada7aa480301102cbe1f7ea1303bae52d705.1690624340.git.geliang.tang@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: References: X-ClientProxiedBy: SG2PR02CA0120.apcprd02.prod.outlook.com (2603:1096:4:92::36) To HE1PR0402MB3497.eurprd04.prod.outlook.com (2603:10a6:7:83::14) Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: HE1PR0402MB3497:EE_|AS8PR04MB8417:EE_ X-MS-Office365-Filtering-Correlation-Id: a4582274-8b00-4965-3283-08db901a50fe X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: YzKuQJspS18Gf5DkJegF9TSMZIM9c3BwqXZyss4vzJoWrDdv2jrKSUhWdhJ7C2np4fTSsr2TJrvvVeFU6uK+KYYIJjZYCPI6/6BCUAHWwXSkZGLRoi09PPQiyKvmJNJyZn61+dAOdjWX+Brp8OlUySUEvUjFV6VuJpGueLF63s1fMSPxe+ModmM4NH/bGNsy9VflVs7ezhwgsKi8uSnMzI6zzU/iDsaTVO4A2Sy73m101T15nvTWu5Zu24CrYiPJV9uc4RqoE62V4Bnj7/MJeTfyGdMf7mhyeA3+QPqHFZuRFw4wcttnCoW+He3beTfsphZYDG2UTi3TAWLI4vymvqomB0z59P7dE9ZzXIcyJQ1cwJtY3T4fcYwiaVgo2LwWRe+05sYwrvTfFtkNYd5gaeY7oqOHa/EaqfsVk+4MmM07UrGiq7Z4OYDXEEr1qYczGPTka8ULR+rV/BHLeWojhF38iLrkSmnkegTnWEr1akvKoLDn38EFLK1MFAnQ5LochhyE/JTMWdpL31X0wz9y1H3alU9i2z1RzuwVHvNC5M23BJHZf2Vc0cbhf73VSk9eKSQ4DHCQFO5qXZlrTYUezDsSc5kCkLFyQfOMbDpmf1o= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:HE1PR0402MB3497.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(366004)(39860400002)(376002)(346002)(396003)(136003)(451199021)(6512007)(6486002)(36756003)(2616005)(6506007)(26005)(83380400001)(186003)(44832011)(66946007)(66556008)(7406005)(7416002)(921005)(110136005)(41300700001)(86362001)(66476007)(316002)(4326008)(5660300002)(8936002)(8676002)(38100700002)(2906002)(6666004)(478600001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: fj6n3OSbb4PgC5kxdtyTQI9MN05ivysGKoVqH5mE5yQ7OeDdDoDqdHhxGYoKR3JAnM2hlRVhyMn4HotFx6JRGvGeXcAAsuWE03aM2CDe9T1g+svqPNq1b4MArq6EWBY2QdC2R7DcIQYLlvPvs6LOsiDk8kepu3r9o7DklzyKbXxfIYQ3FIua5ubUc2LVIc6lOi9CtwbXKXnLL3ZaEmtGySnDqsRWi17kFfcHYFXt/qPK6DM8j8dkNUtVwuqjeLryKEbL10zKcNivotfRHXiR2hmBvBzBjK/zW1J1MDm3Z/NgPIJoyrGK8tyC4Xggl+H8rvj7q/+dNs2RiQql2WQFk9I6YrqU8RXkQqUuKa6hDX7TbHinUM8YwtTmledhkKU0SvklXlEix8N4RNOW0AbofC+8QoedorJbtLqIVKHIpZYqJ1SnVpJpMGkF6RszW13zs3PGTbhRm5UnVozIY4yjlD9Y75qTQ1vURMynDi7re3cl3lZCNNBj6ewK3LbF/RfO/o8ARHNtyNbwTi5kZy9QASOZIUA8JkPWQUDoH4DZns3orAo7EU0NuNCjkZOeVuUjbFjtYALs46lBexmtXExSby9eeFjybR6nCuj5HmPGP8j/xIfE6k3gPz5Wr1fbtPyBZvnsXKZeQp8BYEp366Ck3bfOiQ0BDVLVruGy/nnJeBn9LWzA+Qxr81BpR5Q6L5qzUBBMPyDfdsJLXghZRwehTfoDF2bfb2d2nmHmkyVr3UZ2WN5lEB2g3gKMfvVjsbasu6Qm454oSHOXdAHi1RLIbfEigQqqGf7hVzCGuK1mdE/KRUgds9Nsbl1Z8sFH3TtPBw7I8qSnMgyaO3G0RLWD64quzNVyvr3FbtKVA4fTBWck1hz7TSu9BXa0hK7VumuBvmAysJItwL03iYMl7FF5vwmwpn0nZPFYktbg0jxKB7wCG0y43E5OfB4I9FS5lV5my6OwHDppya236KL8GyrB6LeaIMuEQnesegFl2xderWVegGNRPvPUsM7rriJLWiHfVtmISggq+FWnHfKI8SPsmTueQiQcCkFv/us5sQrXjVzAd2vJEFPZoQj/UY+hxNa/L7h7oZToJv/D/JA2hNizyFf73Hb+rR055aDYXCRwyOrtpYna/du4CI1/VADPKXoqubIhmCYC1YYPcUAG+CHlPfYbZKeQijDDs3jqC+zN6cZliOv1IJ98LqPtQC5jb3EOaGqIH7q0ArWxaJizM7wHwizcSSPAAkU7lqxtgeqFJH9csKr+1pnwv8Iuk1B8sq+mmFa1RiX59YuM2YlpaC5UusNUI5pA0sg+IiGQo+Kq1gVbRgjr2y83PbaxOqAaX+N3XJZyCHT0Boh10bh/PP/ITEOAs0F3aXH24498XodQW+X0ujdGhwfc2OgHtINDyD8FQwn7ntjJkANoZHLOiwW1/O4RjqWqvdMTwWciqV/NZDLFM+xQ2WYRytG5GraiWBo/9fdBGMQ/cNt9JUHlEmrZI8uu/ZDkMyslDylzbtAO4wuOfjfu4LPuUJ//DPiuGNf6oAV51VwtI7W3VuFb1Ev0iKuZDj8RVK6CkzwbVQLT7KprnG0ouDdC6jU/NhO9Eqez X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: a4582274-8b00-4965-3283-08db901a50fe X-MS-Exchange-CrossTenant-AuthSource: HE1PR0402MB3497.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Jul 2023 09:58:10.7748 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: f7a17af6-1c5c-4a36-aa8b-f5be247aa4ba X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: WDH64IBJT6Uqxut3kJxsdPzMXlYjjPe6hgCr1ngR6s5ItwZyy8BL+i6l61mHX1oxxfAFUne9PIbcypRx1xYNEA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR04MB8417 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_PASS,SPF_PASS, T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: bpf@iogearbox.net X-Patchwork-State: RFC This patch extends the MPTCP test base, add a selftest test_mptcpify() for the mptcpify case. Open and load the mptcpify test prog to mptcpify the TCP sockets dynamically, then use start_server() and connect_to_fd() to create a TCP socket, but actually what's created is an MPTCP socket, which can be verified through the outputs of 'ss' and 'nstat' commands. Signed-off-by: Geliang Tang --- .../testing/selftests/bpf/prog_tests/mptcp.c | 94 +++++++++++++++++++ 1 file changed, 94 insertions(+) diff --git a/tools/testing/selftests/bpf/prog_tests/mptcp.c b/tools/testing/selftests/bpf/prog_tests/mptcp.c index 4407bd5c9e9a..caab3aa6a162 100644 --- a/tools/testing/selftests/bpf/prog_tests/mptcp.c +++ b/tools/testing/selftests/bpf/prog_tests/mptcp.c @@ -6,6 +6,7 @@ #include "cgroup_helpers.h" #include "network_helpers.h" #include "mptcp_sock.skel.h" +#include "mptcpify.skel.h" char NS_TEST[32]; @@ -195,8 +196,101 @@ static void test_base(void) close(cgroup_fd); } +static void send_byte(int fd) +{ + char b = 0x55; + + ASSERT_EQ(write(fd, &b, sizeof(b)), 1, "send single byte"); +} + +static int verify_mptcpify(void) +{ + char cmd[256]; + int err = 0; + + snprintf(cmd, sizeof(cmd), + "ip netns exec %s ss -tOni | grep -q '%s'", + NS_TEST, "tcp-ulp-mptcp"); + if (!ASSERT_OK(system(cmd), "No tcp-ulp-mptcp found!")) + err++; + + snprintf(cmd, sizeof(cmd), + "ip netns exec %s nstat -asz %s | awk '%s' | grep -q '%s'", + NS_TEST, "MPTcpExtMPCapableSYNACKRX", + "NR==1 {next} {print $2}", "1"); + if (!ASSERT_OK(system(cmd), "No MPTcpExtMPCapableSYNACKRX found!")) + err++; + + return err; +} + +static int run_mptcpify(int cgroup_fd) +{ + int server_fd, client_fd, prog_fd, err = 0; + struct mptcpify *mptcpify_skel; + + mptcpify_skel = mptcpify__open_and_load(); + if (!ASSERT_OK_PTR(mptcpify_skel, "skel_open_load")) + return -EIO; + + err = mptcpify__attach(mptcpify_skel); + if (!ASSERT_OK(err, "skel_attach")) + goto out; + + prog_fd = bpf_program__fd(mptcpify_skel->progs.mptcpify); + if (!ASSERT_GE(prog_fd, 0, "bpf_program__fd")) { + err = -EIO; + goto out; + } + + /* without MPTCP */ + server_fd = start_server(AF_INET, SOCK_STREAM, NULL, 0, 0); + if (!ASSERT_GE(server_fd, 0, "start_server")) { + err = -EIO; + goto out; + } + + client_fd = connect_to_fd(server_fd, 0); + if (!ASSERT_GE(client_fd, 0, "connect to fd")) { + err = -EIO; + goto close_server; + } + + send_byte(client_fd); + err += verify_mptcpify(); + + close(client_fd); +close_server: + close(server_fd); +out: + mptcpify__destroy(mptcpify_skel); + return err; +} + +static void test_mptcpify(void) +{ + struct nstoken *nstoken = NULL; + int cgroup_fd; + + cgroup_fd = test__join_cgroup("/mptcpify"); + if (!ASSERT_GE(cgroup_fd, 0, "test__join_cgroup")) + return; + + nstoken = create_netns(); + if (!ASSERT_OK_PTR(nstoken, "create_netns")) + goto fail; + + ASSERT_OK(run_mptcpify(cgroup_fd), "run_mptcpify"); + +fail: + cleanup_netns(nstoken); + close(cgroup_fd); +} + void test_mptcp(void) { if (test__start_subtest("base")) test_base(); + if (test__start_subtest("mptcpify")) + test_mptcpify(); }