From patchwork Mon Aug 7 06:22:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13343071 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 1A1DA1844; Mon, 7 Aug 2023 06:22:46 +0000 (UTC) Received: from EUR03-DBA-obe.outbound.protection.outlook.com (mail-dbaeur03on2059.outbound.protection.outlook.com [40.107.104.59]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E1D4F170A; Sun, 6 Aug 2023 23:22:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=KIUi28ZkGXmEjg1LUdm75eZ8mSS7aTXNTaYps3YJn5yGs5UT6qI3wXj/qU3RlBYlTD7gfPIqqDaD9LxSN5KF+XqN7WvtgQx53BYR8RKD437DraSxVQ10kJoCuburFANtynTKKmbv6Jp4Gz50wznxBf8iPJaiqzFJ1Q+u8JSyEWzilnZoBSapZOwqdH0JMN9iIm8IIQ6fmY+80DfNXhBCNOw4/m//oUWvoSCxlzkd5eg62Pb/xh8qEMNke8XHxFzl/0LYcmVLkWsWZCh6371PeZtB3gqk81T/oPujt0L0Ht4UyXMbB8ImPMbjEglRpPE3DKuwsNqjBvH0rfC0EuRYEQ== 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=KAxFzr7wfHCtuXtb1bDExLdi+n7W+c1rboqRkQMU4L4=; b=eZRiDVZ+WMAXf2YW5e5acekTKoSiNXzc6+wmkfjKHdr5d3B9pZfqX7bbGpbcNITzvGitGqshUIE6cpKMPBhHJwIhb9fzB4FbqDX1YvquOubrTK4IFNXinnFs/XoO19umnM04uHRvFBqU0+o0wHE6Ld347HZgvn5V8Q3bch2V6zg0BNRCPkzmkYJlOIwcDBLtHT3ACIQHVtzokywavEtCitMYN0Bfd/T+VBNpeUQoyjESsZ0gvCWuo6hqOqpcLgOyYkERGjDV5icohQS/KB90vraEzZj/O9+DQNI4UN/ZA6BrioakxDECxhEL02dyMdaPM6FO6+4bBvAOwfkaCvAIcg== 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=KAxFzr7wfHCtuXtb1bDExLdi+n7W+c1rboqRkQMU4L4=; b=fLHPgrJt8Qjl+ibIQzoafiKvu6t723IwiyI2/t8SFN5LUP5YuvlqAikeeM3yWjatPtmyywLUgLfhPEXRa0mGJnv72EdznfizOeg8vHwCsLNIXR4oS4zj8IgqaKmNLl/kQP1USDtUrN7QUJ9eb0V0P7WPpgBepzj83fNjXV6toq+n6mRUkTo15aMwiphsCc5UxRB7ST/MIODmVHBI+Fe2krfzppwk48EY2BmbsfwGAgdU4diWSfWAmQlwzU5b/IPpBo4gKwlQTuYYlwgJA6+exjQTUFea4bSFUX0EGlwALVzU5emeC3Yim/WWxbZDoJ/bmkvajMoZN/x1RdQX5EBjzg== 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 AS8PR04MB8883.eurprd04.prod.outlook.com (2603:10a6:20b:42e::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6652.26; Mon, 7 Aug 2023 06:22:40 +0000 Received: from HE1PR0402MB3497.eurprd04.prod.outlook.com ([fe80::2867:7a72:20ac:5f71]) by HE1PR0402MB3497.eurprd04.prod.outlook.com ([fe80::2867:7a72:20ac:5f71%3]) with mapi id 15.20.6652.026; Mon, 7 Aug 2023 06:22:40 +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 , Simon Horman 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, Yonghong Song Subject: [PATCH mptcp-next v12 1/5] bpf: Add update_socket_protocol hook Date: Mon, 7 Aug 2023 14:22:41 +0800 Message-Id: X-Mailer: git-send-email 2.35.3 In-Reply-To: References: X-ClientProxiedBy: SI2PR06CA0010.apcprd06.prod.outlook.com (2603:1096:4:186::6) 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_|AS8PR04MB8883:EE_ X-MS-Office365-Filtering-Correlation-Id: 03609ebf-4f75-4503-c760-08db970eb35e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ZWLizeJIR5KwtgzWCpUQVETN1RLi4kK3BllMsWMT+ZvLqYRX0BV+ne2Ab0TvhgsufgJqKNHBrifNFfvZxBz/FJ6eal6xeIBPWeVo2iab5sFIcs+dSMAV40fC+YTzHS/kzlEC6qVKQH1VXHG6if27o5Rnf0wKr36WQNBK20Peevti6zLVyyrdsoQ8jbaVkyJlVH2p8fwsruSibJLQGYfryak11S6IyuTBhckEXEzMZbC3ZL5FWnCanYPekaxlD7aTuUolCZtTSlGe+7S05I8U8gd8qbHQXw6MBnhdn8ypftiWmi3DBI4YyU7GO+BEtGyVYUtZf/SS+JXTnh18oQWHbYF4lP29M/MLcOfBCqg2jnYZUTiYjELedEGRSQ4xV80Flgip+8xqsnXbFN0/JVQASMVoMjgTRFJFAFo4T5jnuWf/r9jCcq+KZ7bJ0Td3y8lxgrlVyai0dvMJfF07pkhNfPyr1GWgFBfjcj/XbiQYLacpItw+aSe8dvuREbZyOPwivMZ3WEglfM6MjOnTFAeZMI46avjGbrpF46n1PyYIhGddLmATUGPqejBYlBre3sHIcVfxtRJG+nH7uJ1Tyu1cNeLVlT1NTTYUUq95xg11Txo= 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)(39860400002)(136003)(396003)(346002)(376002)(366004)(451199021)(186006)(1800799003)(2616005)(36756003)(966005)(6512007)(4326008)(316002)(86362001)(478600001)(921005)(54906003)(110136005)(38100700002)(66946007)(6486002)(66556008)(66476007)(6506007)(41300700001)(26005)(15650500001)(8676002)(8936002)(2906002)(83380400001)(7416002)(7406005)(5660300002)(44832011);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: BK/kiIqZ51p5zuBkLazjcctuB2N9CD8KwFutpwURfNT/8o/EWb2ao8qPU+GUyVylOAG1WreXZ4gCHHnXhIx/i3bSySD8oM2KT124yxRw2+s0+vuwuVHmQveYBHOfgPtoZL8f5P+gByx/FEIlg/DX3wxbSw+EuVZp89ojga5tGY3QmOZ6jxHYPEgjgugaO/x7sJ/ESMQsXB5HYiPwgtiCNhAC6JWlFRRPfAO40U/HG/f4+eoDPgwpnsd0OvXS+9vILUHQVb/cB8UqQVsLBoeijiCprz/aIp1ws/q6o+jODoZQXZUAT5PbXrH474t6nDfQaD5wwGh8Wj9CFKGNWbj5ZroTA74CIpwATSpnXTzN9X8F4MlnpcTTr6ew9TFkqOcp3a0Sf0LAGpdvZ6lQufLghQd3UGZvp7efRs3sfE2DxncOshOuW1hTLdEz7O3NGVVh6hKHwxENWiXX2A5dSHVb2kC+Agk5sfskmF08xpAK3A0xVzC+amZQet8cWY6W/QOAUCRUNhPzYSGM+9nIosyQUVvO6ZwaeLunl6XQ/XZNvIwR37dfy6bDmXiRp9PlgqUZwxXCmwrI02Tm1qPu2plKvB1b3bFHLt7XVaQBQX4KcLsNtGLyVDW24tQdryC9VOCXC+33BL57tophJjvzrkAzrlpqep/kGqC6+5XlUOV5VVIVnGeL51d1jL+RfgHq5VP4tPl5urzg0GDMX8fDyKDHUpOy3DVzc/6G8G53h3zdQEeq5DO3Ij0qG4qQ9UtFD9GX/AL6KXvChUQXw6CuUwLppG587+qINUbfA2I4q6FxY32MdaWwE9swsKpjSYnSEkUyQ+tIGzvYz9qSy37Yb5Bkvy/ux36tYrzNOj8Gn/qo6XLbAC7ijDvOtyMkMTILXBJIVShGnBccOFftkH6eY4wQOGoz2zN/XBcmRuqo2MYoqyzV5MvOxjJ9TgO1W6IGICFzv/9bF0CkyZk7wrUGkgNNtHJOWL5xsHB+erPL9BPxTFFe2B4LmKesxPPzE//5/SVsS1WVC0uDLXZlESon7I1a0SmDzThh+2JqJ3xg/Aq5GVzkgtcsMVVNLFPjhkk7OOHQ0G5VZ6LIvyMzoLHTfal3TwpqdNIO5HE9G+o5yEXrNM66s/khgCjFURaMORrqAB/vJ6r22wnsMaN/qXoSN4zudofR/hdxzc5URRcz2TqfJFn1bbALJ3Ri8tgfiBtNgWdqVAX8fkuPsGda2S7lLxWem3zBXn1cZ3LpjlW+PV2bFJI2AzRl221Cluaw2FRoixEbjY4XQ+TKoT941kLvkncmnTKp+kHdXlSwDGR3Ni9GJl7a9lGEZMfdZL1KSlSBJv3PXmX5gMCheTjkKaqKl5ar92NxhJZ0GTs+JiDkX5aa1a2Yj/db+w4uXwbu0AR5T/pSS+nSPNaU8STUsz4HYGBvriaAoYP45TfhxJ1CXuQVhblWMmBfKpvXWxYiyOpyCMfb1Uo2oqaiUn22qZ5Ah5NB3QJbw3NHTUnucgzIY8leuO7JcMyWD/99LGbhLOp5GdStK9o/AV212CCecx7AIJqtwYMBSWnvMSoI6wCVK59CebaATygF+woJmDToeyMU1UZM X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: 03609ebf-4f75-4503-c760-08db970eb35e X-MS-Exchange-CrossTenant-AuthSource: HE1PR0402MB3497.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Aug 2023 06:22:40.1315 (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: 89gonnVRTxvFMxXg8HTNnHLU75bVV/RAk5mRTjYtjmJe+PoCDwTSSXGBNzAiT70mWiyF7T1UqEH2OEM8U0zaGg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR04MB8883 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_NONE,T_SPF_TEMPERROR 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: kuba@kernel.org 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. Define a mod_ret set named bpf_mptcp_fmodret_ids, add the hook update_socket_protocol into this set, and register it in bpf_mptcp_kfunc_init(). Closes: https://github.com/multipath-tcp/mptcp_net-next/issues/79 Acked-by: Matthieu Baerts Acked-by: Yonghong Song Signed-off-by: Geliang Tang --- net/mptcp/bpf.c | 15 +++++++++++++++ net/socket.c | 26 +++++++++++++++++++++++++- 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/net/mptcp/bpf.c b/net/mptcp/bpf.c index 5a0a84ad94af..8a16672b94e2 100644 --- a/net/mptcp/bpf.c +++ b/net/mptcp/bpf.c @@ -19,3 +19,18 @@ struct mptcp_sock *bpf_mptcp_sock_from_subflow(struct sock *sk) return NULL; } + +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); diff --git a/net/socket.c b/net/socket.c index 2b0e54b2405c..e9b2e754a103 100644 --- a/net/socket.c +++ b/net/socket.c @@ -1644,12 +1644,36 @@ 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", + "A fmod_ret entry point for 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; - sock = __sys_socket_create(family, type, protocol); + sock = __sys_socket_create(family, type, + update_socket_protocol(family, type, protocol)); if (IS_ERR(sock)) return PTR_ERR(sock); From patchwork Mon Aug 7 06:22:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13343072 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 1C91D3FE4; Mon, 7 Aug 2023 06:22:50 +0000 (UTC) Received: from EUR03-DBA-obe.outbound.protection.outlook.com (mail-dbaeur03on2063.outbound.protection.outlook.com [40.107.104.63]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2089110FD; Sun, 6 Aug 2023 23:22:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=YeoOf4zIx7b4TrxApMra4it9tvrAPOZx/pZVt4Xa6sRbPSiQlDQ9z1JoB7aJXGju4UBh9Zjk7Q1G3NEMOXuC1Eua1sEbQmmAP+TCx+ajSgk73Ma5bcToDI3v8q9I4mz0uq3rYce1rlbyqL0Nmv85wsViFUSle3hw04M/7rL+X0hIBK9BPsdh6qbZoZGfnadctAnJxP1+JkBbcSbL++JVxsPohkN/QEDN85Rhaq7KE70aJ7FanJeBf+pK+PZ6OZDDIBlNpuEJgwXamAYM1zjoMkXnlLHzA+IfXI4VBgdq4FmfcTvJ0v+ixLQ5BcdmDR6aXvY9C0QMpYj1uH1J640eUA== 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=ClwnafzNNy3wWv3I3Y7MoT2F6aS/XaHX7aTcGzrpsl8=; b=XYLso0LXynokEFtpR+A/riYIMHdiqB2iNZsM9nxLyx9jdK8BvOD02kfU5qs9mmr95OPDOVZ/ia4LAi2ZY2v02HtQqmNCA0uHE6oSnFncQi9LQqtAtt5QT8TprM4VxkiKH2Sm5RRwbLgmREVvrkRS9UiL2kjngYODGAT3mKRfvSw3ceBcMCjgtD40RLPXu/QTrC5lb6+XwfI7odxvNJMZLJfHBRQuhez49421dW79HfeDwzSRowpVbK8hQEsWYTMDpmOxI0VEyKO0+ZfV5lVvwQxYqlvFAYXDIpH120DGrUrqriW32RlP+WwB2erPCz23zXqLCVsAzj9R25//ardZzg== 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=ClwnafzNNy3wWv3I3Y7MoT2F6aS/XaHX7aTcGzrpsl8=; b=IARpDRcqId7FjEMle7KAifSiz2gip+1i+WL/UI/j2ZOYfYCEfRkw6yFq7lfnuTH1f8oQWJwRABI5CiZdMM5yYz069r6HkQiFQw9w5+y1JJ56cVEK16FUJS3RjCGMmvGtEtfJLWb/fCLBAphXoLapwA6vlxp0se+g7TfxzTQ+lG4dTW3XQgG5jEnr3XTP3SlJLzW0BEvk8M6SYaken+tOCLkMYF1VKrmx2gpq34Pe7jgprmbzoIy/vx53PqeHFjm3sPwfPeRJVU/9bMeTU6DIkW03XZJGXCO4223r6svwahAsJrhhISDXuZ83FmSTzVQpcGO93Bx2mDdPMLyeRtPavg== 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 AS8PR04MB8883.eurprd04.prod.outlook.com (2603:10a6:20b:42e::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6652.26; Mon, 7 Aug 2023 06:22:47 +0000 Received: from HE1PR0402MB3497.eurprd04.prod.outlook.com ([fe80::2867:7a72:20ac:5f71]) by HE1PR0402MB3497.eurprd04.prod.outlook.com ([fe80::2867:7a72:20ac:5f71%3]) with mapi id 15.20.6652.026; Mon, 7 Aug 2023 06:22:47 +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 , Simon Horman 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, Yonghong Song Subject: [PATCH mptcp-next v12 2/5] selftests/bpf: Use random netns name for mptcp Date: Mon, 7 Aug 2023 14:22:42 +0800 Message-Id: <426ed18fcb9adb39bfc96cb444cc56636377c5f8.1691388735.git.geliang.tang@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: References: X-ClientProxiedBy: SI2P153CA0019.APCP153.PROD.OUTLOOK.COM (2603:1096:4:190::10) 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_|AS8PR04MB8883:EE_ X-MS-Office365-Filtering-Correlation-Id: 82f9c0c8-4587-4906-a86f-08db970eb783 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Qbx6crfozXx14iENjQv/Af5Pdp8wT9ADuCXmeNHWXLPHtw6qmQ7fmIafXTARTwkuVX4dw6ZiiPVxU+z3cHHWzUiXN982XCoLLbenlxIKLQpeErvrqEithTqmOCrydK/FIK8vTJtcLSCX5YbPzE6078zxWcD4shm/lYydbZy/wr2/u4cqPueu8WCDm+YobDptGNLqxJQDbVKJWnZldePeKyI0hK+n5h4FuiIuXvKMYgQ0yG2R/ETRsNO9S//F85pelk00pyl3U9tDawA/2vKsfWsyTDMZxAZds97UGAJ5Rf6+LfE17m2H4pJsSeeBDgeCI1Iok1NGSzeTxgwK3R3JvUsPZVKKqvxLmRlJoWIlzk7pHu/EXLfJ73NGTKee1t1rYZvpdZ7fxT1OSeMDQiZWLC4Mp7d9LE1ZTcD1vclUO7RF7hKEY+3aFLmlOJv5eMIqRvdX1h0ptZwSe8RaVdHfo6ndH/cN1yhLt9xn1+CUXIEm+mDidu0yq7WCgGtXEAXPZJOIPsteZCXdNeg+vs9/bP9+TQNS6f7Q5x9MryYRtssUX+uFqKjdaK9wvDqXKt1ZPECqpwFKYGPx38SrPRwcogeKiDCm6W1aK8Xo+qrVrdHrY3OPfyGHmQfaBcqn6wPz 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)(39860400002)(136003)(396003)(346002)(376002)(366004)(451199021)(186006)(1800799003)(2616005)(36756003)(6512007)(4326008)(316002)(86362001)(478600001)(921005)(54906003)(110136005)(38100700002)(66946007)(6666004)(6486002)(66556008)(66476007)(6506007)(41300700001)(26005)(8676002)(8936002)(2906002)(83380400001)(7416002)(7406005)(5660300002)(44832011)(17423001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 5AE/pGc8td7Hsw/hMI7IZUfhsO64GdXxCA9ekDZv6WRUz7239zKpu86XFq4VrScbT7oI6eaOBXTt/m7bjbHVxw8XQYPILNhh+StepVu7wyBLeMWBV5FDcrLoiBqClIv+qh2K34Qk+2vdUEus5s7CNdwiP62SJQUtZwrixCES4/M6U+eYbl4PIVTT5U+qd81cZIsiKhGbAKEa75ZmBNEFH4aCuGNu1Z56s8hzGtR1QxzYD8NpBLNiSYuyw2oxf4Gvgm5X90F1lKYChkL/b4/hgWwKSWa5XCA8Uw0QrNsm/Rd6iZD6key63QrKGf45J7p5UT71/zO7QjzS7LUAgHDGc4TQ/8oy9xZWGvGGUQ88/sKtxti0i9ZzN3Fee2Py+zf0gyxq470osb/2QtKTSyMyXRiOB938oaDItiaGqyc5542Nr87l/Zmmy91Ysfr+N4SKXgLipjr6svdj2RTooGQxpJQg/2oZ9QZ1lfU1e5pA0WEQzpiU4Z+/54TahbUc0GBzogbcBjM8iBWxhM1FpOIjanXpEu84KZmCGU4QVW0Pg8GXFGic/hj5C1spISK5kbnIo4VKAy3oZzqsRAR0JypjpBAhtqKiVnZPosFterr3dpaPgPSG11hFCBdAiNYkLHDfywCz2lmvlQoF03mKTouKWkLOXteGHZhtxuc5gffgTz3NgQD4TVmkHN0NSsG8ItlZF0Tp37dXeuY4s+MfrF0NAFwxu+/C9elAd7RnYjjE7pGGPDZ4yimZ9jDqRPtyoXSNvbW8IcXOTRPp1CbFnmLewhQD2LXuWsAmG5r9YQRzBtawfHL0FPglqFk0dCGZLIEDACAdpJM0h+gggyuQdSHptM5e+tBQqlAv7RMY1wgm5LxsgkrBvpSKJad4WUJVig/lEGJ6nrYpRGaiYjoueoqT7/r5+gZZjIi2xqwO3zu6fy8bFL2En7kJdAs/bgRZrsxvjeE6FT7CnqTBbyc8i55r/btHtNfBITQtkwdzgJGmJAp95Efh2QV8NRNVaLbyaowHnaWyWurEtEBb9uF+LucWK0+wKaKD9qdfuky1vOoDzfgoBIq6kUEW9IA/myIvmtp/f8GCw/7x5e4TDkfgkkvLM+azLVVVVac2ZBhpbtVhEIHqQbmuBS4kcXvIjESnZdKKOJ2RhHVWr8xMoL/rV8efbJT8k+kdye3LVnBV+H3sdE8uWyE0Nn7O2Sd5UlRc0jFkuZrW9Bsgy1GsDKJMy9GIhT1kwk5GTZQrVzKXcgEzT2vILo+KkOgXxpv6I+nR/AoMHipwGdaPT8rVjCtYZC1xMKQNL7jCdOAYb6TxXjWCjtNz+QJCrv4zibYqBKqeiQfDdnKZ2Wd4z06VuWR3MkjdevQ9HH6X3B9nTm1QNGyejzAuNtnKfCPXLVG9KrQETIpaNvxwdZjyBQ8ToFv5uLVEIAS7YqHPkphI0cWgwMbY2l+YDobULXA04K1ip5Hy5WBsEdaOIt95ryzcFGDjwYcm0qCbswMhhu2sF7tVFu2To7coP6UtH28koW94Wl0FabqWcIlCzLGr7iMRyvcczn7biDZOKyMRFa9tfmQW8k3WkRBfiJ0UZCVHKdIWI/m+nAJ1 X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: 82f9c0c8-4587-4906-a86f-08db970eb783 X-MS-Exchange-CrossTenant-AuthSource: HE1PR0402MB3497.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Aug 2023 06:22:47.0041 (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: 9RrXzD+ajJkcYzcwihSV+jSdwjPmAX7Slh0Yrq4vrZ30w+lG9tdBKiNVYM/GuZRmPiuGXN5oTNk25R3OrPhdjg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR04MB8883 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_BLOCKED, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS 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 When running mptcp tests simultaneously, it fails sometimes with "Cannot create namespace file "/var/run/netns/mptcp_ns": File exists" errors. So this patch uses rand() to generate a random netns name instead of using the fixed name "mptcp_ns" for every test. Add "ip netns show" after "ip netns del" to check if there is a test did not clean up its netns 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. Acked-by: Yonghong Song Reviewed-by: Matthieu Baerts Signed-off-by: Geliang Tang --- tools/testing/selftests/bpf/prog_tests/mptcp.c | 5 ++++- 1 file changed, 4 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..b2d41024c6c2 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); @@ -178,6 +180,7 @@ static void test_base(void) close_netns(nstoken); SYS_NOFAIL("ip netns del " NS_TEST " &> /dev/null"); + SYS_NOFAIL("ip netns show %s", NS_TEST); close(cgroup_fd); } From patchwork Mon Aug 7 06:22:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13343073 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 7F0D1443D; Mon, 7 Aug 2023 06:22:57 +0000 (UTC) Received: from EUR03-DBA-obe.outbound.protection.outlook.com (mail-dbaeur03on2082.outbound.protection.outlook.com [40.107.104.82]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5BB41E6A; Sun, 6 Aug 2023 23:22:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=QtU2Ify5+ud1O7hDdFkJbunTMa6qySmfEmZ255E0ZeoWi8L7sPyx4o8L28UQiZcx0xFCLq4S3dlg0SR+optNVkeE1CQPCk1fUPXap9N05DReNOFW8fmRGHedC50WEaXsDVuFhgobmhrZLx+TMo51raaNjHhzIEgsVvSlsh76rw0kxpdlHARF815fGdqGgWb7U3B8D9zJSsi7NuiFisZEjQL1RCvxttl51mtj/vae7w+6zd9w8Oht8CO64Jx1thnBEsXApQEdTguv0g1mGjfGnS+jLr6kt1oifwY2xluOoxcrQbt7oQgzaw1ri+g1lhCfcHW6dPI82XE06h0DXq+IrA== 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=c3QLe55sxMKOTG1LihSp1XbvYAXqx23AByNcHSv+SYU=; b=GKGg/Hqz2vQfnN19+GHP/Hgt1CS/rU/nc54JWcyRyxUdcFUjy2IX8DYKrS7sPiE+sfI1qrL+XtA6C5ApKnym36/ak4M/Gvcd8qckjgYWo9MTwnKu7HSiNF7nwkFhynubPMeFhcJUX+vj5rhAC/7qTSJQHgjXXtfSQ6s/pggu4xMQFQFNbSQr7gNToYOQMxl9qVhHrB4D6pFChLEcICqysT0WEYE7SBZOm4DDGBObdKRlw0LAewJv2zzi6lu7DUspqk+3lNcatMhDp2vhwdFcWMvm2hf1+MoByy6o8ODWgzAfUN4dwF5y6oILW7aia5ihosnmOLPsdcq62Hs3LwK/3g== 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=c3QLe55sxMKOTG1LihSp1XbvYAXqx23AByNcHSv+SYU=; b=aUk1IZ/9tcpcbUno/iz/KrwCh6yqBxbe/IBGX+8AIWqCy58XGHYNC0dnISg1Vx48nQuhv9J4pGZvPC07mcJYU+NhoS+AUfvZHcTEzYArVhEwV2Bp3HXuiHX6KhS+SmDJyHpYc2V5Ibh1TN51lqfjbJ7sP+6nmCtHQr9Jnm7nd8KjiOzRrT/TC6l8VYX9cjHYTG3sJCnxfwr4+DzUIB+JmrFaTxfOA8YAwjcF8MV504IfILZ4nO7dS/17buoWtsOiOrCI/5hjeJEcKIChlFxwksPhiqiPrR5P37r8eWXtjUT/zeBmh9d2d4wIPs/C+BPTP5dlx15Ldm2zDNwSu+mgFA== 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 AS8PR04MB8883.eurprd04.prod.outlook.com (2603:10a6:20b:42e::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6652.26; Mon, 7 Aug 2023 06:22:54 +0000 Received: from HE1PR0402MB3497.eurprd04.prod.outlook.com ([fe80::2867:7a72:20ac:5f71]) by HE1PR0402MB3497.eurprd04.prod.outlook.com ([fe80::2867:7a72:20ac:5f71%3]) with mapi id 15.20.6652.026; Mon, 7 Aug 2023 06:22:54 +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 , Simon Horman 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, Yonghong Song Subject: [PATCH mptcp-next v12 3/5] selftests/bpf: Add two mptcp netns helpers Date: Mon, 7 Aug 2023 14:22:43 +0800 Message-Id: <0fcd7083ecfbbbcc7a3e83b2b140f332772c0b44.1691388735.git.geliang.tang@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: References: X-ClientProxiedBy: SI2P153CA0032.APCP153.PROD.OUTLOOK.COM (2603:1096:4:190::23) 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_|AS8PR04MB8883:EE_ X-MS-Office365-Filtering-Correlation-Id: bc0512aa-7e3a-47a3-877f-08db970ebbc7 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 3/dzgunzwPUXDmILyrKM8lcQ8tNA/6Eavlfox4THpQdVVOh2DEx2FeZuFRKrHSthPNNiFshsGUCgla4yrd3EsN7dVWl1xGpVdx34HTn+lLQFHsp1ehkNl8Y0lfhaFUF1stHhDTpd2xeP7q80dQYnNEPlkBFZKqR4iP4DtxA1J6AUYYFs/WjFb07GPRrZTPU/AQJEivi4htXMr0OOzGuDmeKUlWA/m7PCaj5apeaXcEHo/6GU+MDJsFGWQo6VaDQba5bJpHjjcAqWvhdfKZ1zLmmQqOtrycC/ni/p86kCXg92PZnXckObHbCeSnX0XnmAAAiXDR0ULCWWDss5hbSaBizrAE7gu9L/ej+Z8Ol09M50ZfkmSPw19tGWVIrCKXdnoVH6yhXTpDdAsyIO+a4NxzmF7+qKxxHBSiSURb1FkHTVSYzR4SuNIf2wGnBiIUdWj4d4VQNy/kaZC0FTzq6eLchX9n0IP3GyfjtvXsZ+g+8HRH3HC9l9TYdC8pOizKsY8rggTIZpxJlM+8exoGAAjVNawaEEmi9gjt2BeL0TmUm5dY1gf8C8m7VakriazFsHDjC4Qqoo3h2FqQvnEfdh36v/JC3wzOegZmsgw3kjlRM= 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)(39860400002)(136003)(396003)(346002)(376002)(366004)(451199021)(186006)(1800799003)(2616005)(36756003)(6512007)(4326008)(316002)(86362001)(478600001)(921005)(54906003)(110136005)(38100700002)(66946007)(6666004)(6486002)(66556008)(66476007)(6506007)(41300700001)(26005)(8676002)(8936002)(2906002)(83380400001)(7416002)(7406005)(5660300002)(44832011);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: xqHzfAWDSKQH2zAgn+AuHmLHYMFL09ETCD8XJpEPH6ltxJMXkjyx1p8imvG/V8PmLXhyRG2Iza+CUe4p0stb+SgT8rdywao01IX5+8a29FYBnK0sDKuQDhaAAduleE0t0LK+ziebavmZ1FCLI72ZbcZrCyFhCOmfPh6KPxNnQbual/wUEyudIXihW321ZhQBRvJ3APECXENlhfNDBEGY0N7RvQ0nm/EbTWia3sqs4KYsI1p34nrRmWtvfrObWufIuEqZU7zKhdzalgwdJ4TMYde2LTpb6qTnM0CZE7QO+LdO0clRiJl/LLd+LsbBsfTrxRI1JjDT4Nyx/HvGHwcXHrjCrq/ar2pMNgj59ZT8QlFwIPLCG23pxIAvKAFRuNrXAfdU4p37y6kem2k82oB4aCDGIQRFDd9hKbPSlYGBbrLFM1ktHfzvRM+g2CAz3MbnYQMeiBTuZ3yendP+fBHWtBGzZq5bfSvbkXXUDUFDHUhuvO34U0RTH/vWdVnWITCLZXOLyKwBlYMCJeavH9+0Y3Y85VJt+twDhDoYHV+y2EQC+OeWLXr4tjdevok7+U5dqlxXflW2YzByucsTqt/L0XJQfq61Xm3axC8KDzlxlIvf6HK9JVRiJTsWwkHaWk3a7NgaS6XRryimN7IPwoNSx7+UexR0BWNKym0Qsq5NDFMh28Vr32AE9JEU/Cl4yTRltPxDNTfopxYamX4s0amycFQqLmHPS1n8dQ8bU9RwfRNnyrUEixFlQfaHidzOOd4Sbki9eZPTHaQ8doewV3sPpkPNExrHXOGOlYUxelM/eGgwPQM7Wt1XB0xN5uJ0PsIci1hJE2tAsuaQbws7n8/zUyIXIAu0tWuRnUXKwq4kd7+Euk2Q3/jy9Cq+mCDVLBXHQVaZNjrHxvVVvicxsDgO57ScQX3QxYgoQVQOQ7Ag5fpioWeccC0At03H2OFEpQ1EVMAO5EJeUQ5xKOYlJjCHbI31vdGD2g8rdKWRUasB/A+sypOwNw0bGQ+h83mVqMIbLkeFzSPIWDDVmOQZ79uYl3gqBQlJ7gHZ36rcszWFYW/5LOdL90eA6qnLW9i3dEiuC4HRCfm5i3TE5WANoAYLUqhsd2B9wJ0+1yYpcNINMMMF1DHfCyEhzSN6QxJgJCYGXLV5z97DfZoKbWvIRMNgO5In0EoENSYFf01RbHn12qCxfGcwsB0lDIryFuOKEeX9xIacBoPNTp3Qd35SQicVgJ4DPlBMBQJPTOZ17T8W1N8v3cgXJ970p7f5lo/m7VEgbYNd3XC4zRdQJTCnOpZ9x8gd511d4I3Vh01+SeaE+fVZJx5CPyEwh3MWTtM7ddixmPgeVc9LSG+65hAt9Z2pTau0qVwWmuMA/OHIKlFq0pPwaF8hinKfZhcltd018rkOlJirUaRmjC2pBOb16qKeE9sa1ltS9J37ppah2L9kg+wbwpWaSr9YwLYBmJkiRIFr+/Wb+6witEdbnceK7yM8MoFdEuQsaqSyErIBTsVeX1sekjadTskL5pzidhoQO1j2e2UB643RevsKurHgJcShvEXi3C1rPKLTXidYai4FVK4YXQ4nZC+srU3hKokRMRdV X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: bc0512aa-7e3a-47a3-877f-08db970ebbc7 X-MS-Exchange-CrossTenant-AuthSource: HE1PR0402MB3497.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Aug 2023 06:22:54.1651 (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: 0gT3ici7A1YIyuQk8XO7ZOKSznjQlwX2MeEQhod/Z9TJ7bezt9VD1Tfbm1EOP+mgaBWD9gsZb5nCD/5ss+ddog== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR04MB8883 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_BLOCKED, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS 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 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. Acked-by: Yonghong Song Reviewed-by: Matthieu Baerts Signed-off-by: Geliang Tang --- .../testing/selftests/bpf/prog_tests/mptcp.c | 37 ++++++++++++------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/tools/testing/selftests/bpf/prog_tests/mptcp.c b/tools/testing/selftests/bpf/prog_tests/mptcp.c index b2d41024c6c2..51cbd1e14156 100644 --- a/tools/testing/selftests/bpf/prog_tests/mptcp.c +++ b/tools/testing/selftests/bpf/prog_tests/mptcp.c @@ -22,6 +22,27 @@ 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); + SYS_NOFAIL("ip netns show %s", NS_TEST); +} + static int verify_tsk(int map_fd, int client_fd) { int err, cfd = client_fd; @@ -147,13 +168,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,12 +192,7 @@ static void test_base(void) close(server_fd); fail: - if (nstoken) - close_netns(nstoken); - - SYS_NOFAIL("ip netns del " NS_TEST " &> /dev/null"); - SYS_NOFAIL("ip netns show %s", NS_TEST); - + cleanup_netns(nstoken); close(cgroup_fd); } From patchwork Mon Aug 7 06:22:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13343074 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 066401FAF; Mon, 7 Aug 2023 06:23:11 +0000 (UTC) Received: from EUR03-DBA-obe.outbound.protection.outlook.com (mail-dbaeur03on2052.outbound.protection.outlook.com [40.107.104.52]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D7A8EE6A; Sun, 6 Aug 2023 23:23:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ghnpdobVPqYMkBAUPvuv0XRW8p+qNUSg0x88nYCpjfCxWp43Al3iyBsh5AQZ7VRxfbx44xKjn4RjyWU8EuyaqfKUJsdpyrvktx5scNiijKqeBBnihfpzybCcHTXXe8OCubJlQPJr36JRDn0UfzX3bsrQtHw5QfGdF10PVMM24Q0fwKRqENv3I/tEJcTk8f6QCkTZk4i9YVBrLMugwZxT/jgUQ0IhR3bgcWPTsUkfqIjZR45oeWf5hkrUe3PCXmGi9uD9t96P8wJCUVwO6qPhrotschPINyxFHKkgvuK/Ch/0XDTjokxfjMHW3fB48ZdNuThmcZ1Vqp4hzjmw4gDlbw== 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=kMzMMYli6Tss/9lN983QT/qa8A63KreMsNTPMOxM/6M=; b=ibCVEotjH7l/jwXzcBjwmUULLJlPTsDBicB/xgI0gqB/8PwKUh51YaUEgw23Cf/XrrxaUkpi4RzOUmrVMqnzcXRRdCJ/OrxXH26sRrH+FxGYhbBcu0lWhMjndMPvdtX7HAiEpoGRJcfr9L78tbrXLvlgmQxUKSNG+2td8T2qjmk914fS2ca5kxxiiwTQziTmh6tFkiBVNa7v0SAYsNyWqDwwPfINLS37JeorVrD0L+vX1dyCJbj0TifthPPXUuNP0UheXOm/ZpkEgOBQBLsAelkA2QytLXerLMd/Q1Kt0cnZLAIPYLp3Q8ECcMnp+XoDOWs/7RFR09VQTGRpZ2egqw== 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=kMzMMYli6Tss/9lN983QT/qa8A63KreMsNTPMOxM/6M=; b=QXVKINim3g6cpJmXHMKy8eEp0hQ7llGiq23K5bhTOxNDVSlotm4G9SmbYYxr+jVgFAJYvsww88iZgFJy8XHJNc8ARrbbOsbpJ40z7AykeVi/AXoOFv/K/nuGhJQa3cp3P6q65jNa5UtdZzSikT/thrQAqbgmbY+kenQoPt2/8e6RRTPmeIMVKzD1q/slI8RCtvHO7wv9MiO4OFVlcaOZ+tyGCkhVnpKpgbpcB0kyAdMldZldn/hv9iKcfVh7RRrBxqeXGfV+7OwP+fA4288hNmYth/SSbKGJAxH5G60d2DUF3ww9NfVotAQRvIfA4iCx7twRW4y+45Ylx+XOTB/PfA== 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 AS8PR04MB8883.eurprd04.prod.outlook.com (2603:10a6:20b:42e::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6652.26; Mon, 7 Aug 2023 06:23:07 +0000 Received: from HE1PR0402MB3497.eurprd04.prod.outlook.com ([fe80::2867:7a72:20ac:5f71]) by HE1PR0402MB3497.eurprd04.prod.outlook.com ([fe80::2867:7a72:20ac:5f71%3]) with mapi id 15.20.6652.026; Mon, 7 Aug 2023 06:23:07 +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 , Simon Horman 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, Yonghong Song Subject: [PATCH mptcp-next v12 4/5] selftests/bpf: Fix error checks of mptcp open_and_load Date: Mon, 7 Aug 2023 14:22:44 +0800 Message-Id: X-Mailer: git-send-email 2.35.3 In-Reply-To: References: X-ClientProxiedBy: TYCPR01CA0031.jpnprd01.prod.outlook.com (2603:1096:405:1::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_|AS8PR04MB8883:EE_ X-MS-Office365-Filtering-Correlation-Id: cc9b4bef-847e-4932-fbd6-08db970ec402 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: JRN8dw0MLyPWMVzJZfgyYBI/dYKQuKIFjCfNCwQDbCDMl5OtBMntTjkBN/LazbgZuOSptlYN+BR7n6vTZJqaKps6URNy+AquUq9BFavzJky1pE+O7xe2HiLv5WuUjxwW3XbBxMsyP0iFy8+F3M1O5HG7qa7m3my7ELQH4ufHkHgQ5ydLYhYjP4HE7qGwfsHcMjeTQ/Q9F7yuRrJFY6rCrfz1+g51nSPmzVjJ6HFq36RoBfk0m+ODhGHMxJeMOr/Pv+YdfcQ6f6jTf1ZQLnu0aazXxgti0RNbhCqvoI5o9cnf5MdcslF9L7rmaNrvM9iDG/KZP0wGpT6AgxfF2ahcEbnQGefwwW17hURfCb7SAAZd0di8veFToFY+4qGSWWU4iLLqC9+GWhBCvMKpQgp3XLwikCic0hpsSf7LXHb2X8TRXlt9xzvSsAShG0+/HLrTM4qAT79Cqyl1GugJaksIzHu+iwUV/EIWOhhScM1GjFsmtIYDRjCQzcsfTZY5YYW0U7j3kxh2OjbQSRHdrG+Is6vLy22IcSrAanyOIGlpTXJzyvxgg+PDu5ki9jQmhgkbhcPm5BEkLc7sE/P3RjUKGnGCFYC95TwjJsaldx+0QNA= 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)(39860400002)(136003)(396003)(346002)(376002)(366004)(451199021)(186006)(1800799003)(2616005)(36756003)(6512007)(4326008)(316002)(86362001)(478600001)(921005)(54906003)(110136005)(38100700002)(66946007)(6666004)(6486002)(66556008)(66476007)(6506007)(41300700001)(26005)(8676002)(8936002)(2906002)(83380400001)(7416002)(7406005)(5660300002)(44832011);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: hWkcT88wZpVze3M51c1IEla/OGZPmdzgP95vpeUqcaJEAnGYjUmgOvmPEnX6vMKa2PLFqbkLeRy2FFXvWk3rbo359tU9rVUR8cRBSR6+hzo7qDHunORRz0M+EGWFKv+dAXHSxEmk7cYrs4rDhTcPVaDU7w43dIXw1HZsMLEzq2Tr+6rq1yVnNRp/Sa28OWAv8r+PjwEwlg66toxeDR0W0IJ8hWGlHW5y+qSSGf5rgcVIoGVBB1tStFf+i4mZunEDTsBGOSsyNViBOCxMfQnkp7GxZGcntOsJS9TPV1utSnadGwsTq90Ovb3cfA132Dmk8x8CX484hnM8M5lSjt/DvPEOuPwtsOUounskQxQBjdiaaaPjwx0uHbxbPsqqB3husANr8IN8ogBlzojqreFG5ssiVVxtKYCjNesJo3GyaMmtCCzJA/nIookITNeDg5wPQRkzbJMJzzWkcB1WxdWSLHLU4fWWEI4eQJyRjy6h478lKBv2ZK2h+1gvqs8fNh4fFe2s/aT4OKuB4zVbcB8T+poix0IWO0hTt2xhOUlrbjtgvXv2Bmla0oRMeMPp3bGb6KbIYBg8lVruUJAMD7rQQPY/Zxqe1wdIVZj0oAYG/QQRIjsi1xk3n3X3wGeCKzSpqVcKUTTfuXLv6XgQ5hQkz6NS4OcH6NYsj9H0TPfgGtTOgTto67q4jxp1WHXKueVDRzF4LvmPjJTKawOU9DlCEXLjPryqVasUZRKNFLb053eFxsKzu9BxV4XJ7GHDcUssc8Y0fxi7q5RCQMiKoBwJn+UAmkKyQQ9cx0jgtkx2gIZsSZYxTEdxcw7CBll7uBqGP4053Tcdk4UFP5AdsZvUanpp65Y3kn2F9pZFbSO7jOeluSfSwwC7FMa/dMHXwioffdMN23d898KGYeSHuVqVpkyC1Kb5VyuzH7SaZezdtV0pivrn+j7WC/5ptCMvq7X91xOQJNjlnguFaT9uBBUXITtbH1QFnVj9VS5J0ZPYN/l8h9RJS66sbv8T0+PfoRNrlSSn2X4MiTxUqV/nHwbcGiwsnNRijtTpaZBXUpGKJC8pb/Er4rWp5IskwYaca6DGxdlVJgwqMi8rNn++y4pvaOlEa5d/u5skAguzcvbhJ1Fvge8jLbOmt9/K+Xkbf51sSF0Ae2OCgecdC8b8k2OfWMKfiQmAhQMVeI3ilMk4zo24n2KXUP1N1ECmJxsziBJ8jfwJhz7AdL14L7K7OB5PupceWFJ5CgzhvGxuo/BXiOAqvVz1SgQimvb/DSnVJOfdGieavt8qblYCK4i/Tw74ORsNPjI8lgIhfQBJ/5+tzCxh6dm5zCb15ulHobl1CL/S8hlSrjGzMPrtQ+Hx64z5kjNhz1q7Zs6jaE5xVsnoat7T99z/ogw6bi1KmUNHUkq0XKPfwX/vzmsLBjMlJMFcrSxdWBy1aGZKBYWPqhuCyDiP06U7WWhnQqfH9R3JDzkzeruro2yyv6NgymG298PPWFKSgL/MI2LJrCMraittqUzA3ESN7AKYBFqQh4bpQj1yAVJfq6Vgs84nSsJcGDTC1whxahNaqnlKf+gv8udiQR9IuawMftKuqmIZAfNcnvKH X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: cc9b4bef-847e-4932-fbd6-08db970ec402 X-MS-Exchange-CrossTenant-AuthSource: HE1PR0402MB3497.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Aug 2023 06:23:07.7986 (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: 7VaGFAMMrYBwgwmXYcesBUeqQXyVHHIVMeaYHsU7npvRSgxSWNYVzfEEgfTPq+2Eqa+oWg1n7uqnwpO6PS1Gwg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR04MB8883 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_BLOCKED, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS 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 Return libbpf_get_error(), instead of -EIO, for the error from mptcp_sock__open_and_load(). Load success means prog_fd and map_fd are always valid. So drop these unneeded ASSERT_GE checks for them in mptcp run_test(). Acked-by: Yonghong Song Signed-off-by: Geliang Tang --- tools/testing/selftests/bpf/prog_tests/mptcp.c | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/tools/testing/selftests/bpf/prog_tests/mptcp.c b/tools/testing/selftests/bpf/prog_tests/mptcp.c index 51cbd1e14156..8cbd72981a01 100644 --- a/tools/testing/selftests/bpf/prog_tests/mptcp.c +++ b/tools/testing/selftests/bpf/prog_tests/mptcp.c @@ -121,24 +121,14 @@ static int run_test(int cgroup_fd, int server_fd, bool is_mptcp) sock_skel = mptcp_sock__open_and_load(); if (!ASSERT_OK_PTR(sock_skel, "skel_open_load")) - return -EIO; + return libbpf_get_error(sock_skel); err = mptcp_sock__attach(sock_skel); if (!ASSERT_OK(err, "skel_attach")) goto out; prog_fd = bpf_program__fd(sock_skel->progs._sockops); - if (!ASSERT_GE(prog_fd, 0, "bpf_program__fd")) { - err = -EIO; - goto out; - } - map_fd = bpf_map__fd(sock_skel->maps.socket_storage_map); - if (!ASSERT_GE(map_fd, 0, "bpf_map__fd")) { - err = -EIO; - goto out; - } - err = bpf_prog_attach(prog_fd, cgroup_fd, BPF_CGROUP_SOCK_OPS, 0); if (!ASSERT_OK(err, "bpf_prog_attach")) goto out; From patchwork Mon Aug 7 06:22:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13343075 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 57DEF1FB0; Mon, 7 Aug 2023 06:23:23 +0000 (UTC) Received: from EUR03-DBA-obe.outbound.protection.outlook.com (mail-dbaeur03on2067.outbound.protection.outlook.com [40.107.104.67]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BB1EF10F9; Sun, 6 Aug 2023 23:23:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Diw5fNLug4A90ji9r+lqVcuAK3WgIPfQfz9nnOn+iMBhGOPHa/XF3SChUtdEU6QeytQMvlfYR9uVd6Nbt7uduGRSVgejLTO0gAcewlAszGzv4Wwf/ORI4Jr/fjFlMOJKWkVY/0vcm4TB98PZHM4KQywOl0spKuLi1A7odVDD7807Jj8rJiqhIYJXRk2IrGitiMbRn5Tg31fA20ZnG8Hr586mLFibQePLu3ouD+kqclEa7oJHpOq15skZe6izFf3TtrsZnqEvM09AZuVJCtXKE0QQPwDhpe7Dv2/hiOqUEPZHpadmABHK+csPwqRyZVf3c9caKAhP6cA8Um9YCqTr2Q== 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=XjvDefk6SgiQC4Qg99jZTVvTtpr7OsvgN+ma0j+6pY8=; b=OZ+3orlUvEvTxVz2TX+B0nmhCFTYwavihEw76RfFHZB8U02CeGwmKmsGlt/3SLF2i6DUOmv6E/SrVIyQS1k+lokcRTvQxh9n/P0re0l9PN8H1mDQB2Q2zZv2QyKLq9mMXpIsG0agrRA4f+yU6NyayOlwSOyAQQ3HU5RqZTo91Nt9V7HvB4W7jk4wrMrRaMbp8rJwd0mi9PcDHiBXkTGYbvvPBtV7QnURPWreoCymGJu0ywOaBvtO+kryi5+ZYos1mY9ZNpulxmhZFaezMAe0AEKjsN1hfrpks57w0fy0j+3QQJNVX7UgDUoe9ghHKALWuWIS05u4jS2pRmr488QhPw== 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=XjvDefk6SgiQC4Qg99jZTVvTtpr7OsvgN+ma0j+6pY8=; b=xcqoPT6zsVl92hY4VRwQcgFHzCarrpRTSKXXAVfIQ6hPMYsKJKBhgKTBFqos1UfLg6TmZ4mZLbmV8YUAUVwBOR9MQzyB8HdE6xQQMtR4CRZ7YLsIX7bimO8nCwBbmTZ8q7ZRUVGV6HVHzzcOFNj0FexwAYe8y8JEvRcerKY5HWzGuzv7jNShbgaoFNDs6R7OYMU9BykTBcYPkPylvycm022M4KATcUURE1B34WtJb4nOdU1Y0pBJ9J5IlXZsa83m6MycNes1o0VIAJ+pMB/c6DDYt+obtiP5TDiNxSVvN319Kh2UrT4VKJllaDTqWkkTbdIbLMKG9KnMA/xlvuvcVQ== 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 AS8PR04MB8883.eurprd04.prod.outlook.com (2603:10a6:20b:42e::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6652.26; Mon, 7 Aug 2023 06:23:19 +0000 Received: from HE1PR0402MB3497.eurprd04.prod.outlook.com ([fe80::2867:7a72:20ac:5f71]) by HE1PR0402MB3497.eurprd04.prod.outlook.com ([fe80::2867:7a72:20ac:5f71%3]) with mapi id 15.20.6652.026; Mon, 7 Aug 2023 06:23:19 +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 , Simon Horman 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, Yonghong Song Subject: [PATCH mptcp-next v12 5/5] selftests/bpf: Add mptcpify test Date: Mon, 7 Aug 2023 14:22:45 +0800 Message-Id: <631531b093d54fcd0c4b33bd28b7387f1af174f4.1691388735.git.geliang.tang@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: References: X-ClientProxiedBy: TYXPR01CA0045.jpnprd01.prod.outlook.com (2603:1096:403:a::15) 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_|AS8PR04MB8883:EE_ X-MS-Office365-Filtering-Correlation-Id: 936c257a-c540-42b0-b1cc-08db970ecab2 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: paVBQPchcssr4WpWQZUonQS3D9OA0rF6/Qdb7M7aEuRvs+hRdmqta5kMhoUzqSWhCDrhi0/VVSCyv0YJpO0/Pv3Dv66Uw5Z0cSXvIXxJJISyh/TmSZTbVUOgjcnc8QGRbWjQj4rdVIJ7XymmCJZM2MTn8qa15iyQB2MQbcWMOoMBFP21/WRPJVbehelIURgzZbzuVlhfw0/D5MCRS70FB+oEXVkQHucGWdcFVP6lR0foCwyO2NKkuAdbjFoa4Boh0K65M7xWM7kwLYLxVql00n6QPttt/BdBlxR0eFZ6Dg1wmoP7vvBrSSkKbvxTlSM1WvTsgxu4sr+Hcl5GWvU4mjz+36fXHpY//zSevLAgkLC4grFfCsjPfOyBk6pA6si75THz0M8JphHU8k2NEvvZK/ye8sleSeMXfesE5qkNAGWR0cfXOEwSsPckfn8P5qXE23J3p3MkRFkeCuQ+qyRYDODrVhye2I3CX8P67uE40b2Gfv/oA4aGoWeybg21ZTpdmOnTO6ZmgzWJbLicWKVBLCffSabhZvgzjE88nM1PhG9eKgN7skganKYZ2JI6pHPV0/+aNOL7t8fQZOGMVOcMHip57k5Snn5nh2VuKFSWBdY= 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)(39860400002)(136003)(396003)(346002)(376002)(366004)(451199021)(186006)(1800799003)(2616005)(36756003)(6512007)(4326008)(316002)(86362001)(478600001)(921005)(54906003)(110136005)(38100700002)(66946007)(6666004)(6486002)(66556008)(66476007)(6506007)(41300700001)(26005)(8676002)(8936002)(2906002)(83380400001)(7416002)(7406005)(5660300002)(44832011);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: CTeboawSQpXP162iwjU/Cyl4fIMJ+yiiir8LKXL85Q7gvcfnk47+58uOfg0XdNM4xiiosCNXovvyrV6LclibjWkwIVwKq5KazqQ8v1b4xVB5fpMflECNDcuA7BoFO5nBkViT4ayHqfSHIyBRYvg/HguajHhqW2v2QpKqqffm+G2s0pn0or/HIJwZ2005+DS5xBE6m/E9FT+InrmL48V20P0WFD6GMii+Z27DJoEngEvFtN8ImDLRPiBzq22EWYnMOodysbXnq+cM29NWueh4ig2piNLoROISwL4Jer8ei6p6ifGwq5km1ii0Hnw8Jk9DskuaeUAueTXeokCIj25GrlQXEa3cq0DmWwvqAf7BL/ZI2guzDQDEo7OA+Vwkv6u8Kl+Epf8k/3LwtcVQN8Pph9YpaZkm4s9McediV7q5cdTDqThVwYB9KlVHyaHEWq6Y2aWjvw5M44snB8+fqfZMSJ/uI3i2SM+p8y8S0MGj7dRWPYnh9IUlmwmunthzz83FTnn8dEc3Hi0znUSkz0ig1p7M0ct336oPVq6vqUZvVlICj2hXFplhYD8ae3NdviAiQ2uW98F+siKWSw4vWXtEH5pXu9E0UixaR0d8nECDfqt7zcE2YBdCedIp0TQIWZpKP78QfBAGzX1+LJ8nLsck9WwTjAqb14vabEcfqZWIQgO7C2GDeSk0cdoFCO2rgEpLUJ7OJuiCFhtvUSbltf2v0tqQBOiiTcqhQsvI5jNwN2KVc87TSuEgpgXv8mkm9Y8blM6ZkGtAAJsmGqIyR61PKlcrSNLF1MgG/swlqGDKTG2HbeCGliQi3zW+P5CRrdfSPuoUVFqEWRfj0VYX3SQjF8N4rqTySKbolTeBynbiYWioyqF1N/YilRJelXaVgRcmEfxqKFUa01al7uhu1pZlQVutWv04UKD3qxpseHdhm9vN9mjW3hlT4y0AkAfbzGWmF8iwaIHv48W9vsM2oDPQV1PpsFwsSHpUx9xm/v23GK8EUaZ8jMaXO+T56jfrhHsV4tQeXk57N9Mfoqi9zmF4Bz1j5zpIPhT2eW5SPEoYHuoRw91bCNL1MwObYBrQx05tsfJuBy8RmWZe0gK/aabclmb4U8qFWWsrpLLPqUV0yANUf2zvitEMdh3L6YqT/kxRxBotGnTiC7NbPmIzSf97YcxtGl/vpiqi64SEtpLmkzF5TmlGvL1ZLnUOBwXBD5kXBUuAmhlETMREuaumwjZm7B/9OdgQIIelxCW8FNH4ZrQbARNIljH+p5TuDb4S31YP5Sbf6Yit3JUoyIM8zqEBN+/9jWZiuig2/v9fSX7onVnFw9jy/Qw6eVTyp0NDvPeMiAkAI5euTOWQiI1XSvGphNG19BgMwEGwmjXc0m8arhebnExMuZsjBoB9e1/d6qg+AFkqcCOgBnK7RV3jUufFWVbUr19+mGtatd6k3YBlld9Dg+R7jzUVZ+6qVhNBmujoB3eqy31eqWfKynsPda2SRyKa21SUXk3bPpi7N6kIBR4+NXVzJSVArSqxvGOEhGzBtu0z1BWwJ6XOzL8u9KFrsMs1zZkN71+YCpW9HyAt1o4BdWUiU12u63iQhCiob6Yo X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: 936c257a-c540-42b0-b1cc-08db970ecab2 X-MS-Exchange-CrossTenant-AuthSource: HE1PR0402MB3497.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Aug 2023 06:23:19.2724 (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: nRNxlGoBUeEcYIAbwhnI8zgHLxYxfHWB+69CCDNBt0OgEzzIcqeHYTtpIs+dg0VubiDFqBG7T2kBfalKyRIsBg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR04MB8883 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_BLOCKED, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS 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 Implement 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(). Extend 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 'getsockopt(SOL_PROTOCOL)' and 'nstat' commands. Acked-by: Yonghong Song Reviewed-by: Matthieu Baerts Signed-off-by: Geliang Tang --- .../testing/selftests/bpf/prog_tests/mptcp.c | 102 ++++++++++++++++++ tools/testing/selftests/bpf/progs/mptcpify.c | 20 ++++ 2 files changed, 122 insertions(+) create mode 100644 tools/testing/selftests/bpf/progs/mptcpify.c diff --git a/tools/testing/selftests/bpf/prog_tests/mptcp.c b/tools/testing/selftests/bpf/prog_tests/mptcp.c index 8cbd72981a01..16353a35d288 100644 --- a/tools/testing/selftests/bpf/prog_tests/mptcp.c +++ b/tools/testing/selftests/bpf/prog_tests/mptcp.c @@ -2,13 +2,19 @@ /* Copyright (c) 2020, Tessares SA. */ /* Copyright (c) 2022, SUSE. */ +#include #include #include "cgroup_helpers.h" #include "network_helpers.h" #include "mptcp_sock.skel.h" +#include "mptcpify.skel.h" char NS_TEST[32]; +#ifndef IPPROTO_MPTCP +#define IPPROTO_MPTCP 262 +#endif + #ifndef TCP_CA_NAME_MAX #define TCP_CA_NAME_MAX 16 #endif @@ -186,8 +192,104 @@ 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(int server_fd) +{ + socklen_t optlen; + char cmd[256]; + int protocol; + int err = 0; + + optlen = sizeof(protocol); + if (!ASSERT_OK(getsockopt(server_fd, SOL_SOCKET, SO_PROTOCOL, &protocol, &optlen), + "getsockopt(SOL_PROTOCOL)")) + return -1; + + if (!ASSERT_EQ(protocol, IPPROTO_MPTCP, "protocol isn't MPTCP")) + err++; + + /* Output of nstat: + * + * #kernel + * MPTcpExtMPCapableSYNACKRX 1 0.0 + */ + 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, err = 0; + struct mptcpify *mptcpify_skel; + + mptcpify_skel = mptcpify__open_and_load(); + if (!ASSERT_OK_PTR(mptcpify_skel, "skel_open_load")) + return libbpf_get_error(mptcpify_skel); + + err = mptcpify__attach(mptcpify_skel); + if (!ASSERT_OK(err, "skel_attach")) + 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(server_fd); + + 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(); } diff --git a/tools/testing/selftests/bpf/progs/mptcpify.c b/tools/testing/selftests/bpf/progs/mptcpify.c new file mode 100644 index 000000000000..53301ae8a8f7 --- /dev/null +++ b/tools/testing/selftests/bpf/progs/mptcpify.c @@ -0,0 +1,20 @@ +// SPDX-License-Identifier: GPL-2.0 +/* Copyright (c) 2023, SUSE. */ + +#include "vmlinux.h" +#include +#include "bpf_tracing_net.h" + +char _license[] SEC("license") = "GPL"; + +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; +}