From patchwork Fri Aug 4 05:07: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: 13341268 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7D86FC04E69 for ; Fri, 4 Aug 2023 05:10:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233743AbjHDFKM (ORCPT ); Fri, 4 Aug 2023 01:10:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42068 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233879AbjHDFIB (ORCPT ); Fri, 4 Aug 2023 01:08:01 -0400 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 4EAF74234; Thu, 3 Aug 2023 22:07:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=HFEO51NbpC68S9mkqAomZx7zylOvrYJz7Fc5BcVud0ciQ0tkggIN1E2TKuMSoL7cz3Wuj6ln69HiCk4AL8XdttCrRts8E/TaZlzXCdq//q+OddYkcep2eJNyS16g/LCD/7hWiMegqByQbfaAibGcYOnmO3yuLVd/hqJ06nWu4L9lGQQruu98AOpCyT9ga63rti9SfEwnVXkt/I3fUz+g17bG9igyEVZGOKXd8yYlc3oiqWHdfs+MPS0yMqgCvE1+uTNROggSPD/waID3y1pqvWWtVX10/gcqvH2PStqdju4jPTAJHh+ucw7yzEIqTKs/hlK5VhqgNPTXq7mbkIT43Q== 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=67IJNZXR8xHZysLARhWEOYDwJ5zgZ1zmECZ/EfEhyXk=; b=a5zOxnr7LCS1oLbIJsMXafHgRBe2BbeFGu+h12I00HKOk8oLRu2R0FdOHkEHzUfVUYee2dXzbsEW1jQVonF1Ek1k3Ub9VgHEFXW9Ga07As4g0AXL0DOzxfYHfNEAvNuA0xDKtOp+7AnD4/ubiH9O17EGP1C75iB7duPQHqTmLZEeAVxnDHzU0i+51k2g1KZJ3PMHvmz7fGSMh8nnM4Toj3tmqy7BQvhL4qlb+oMKo6kuPeIzmyAfo/7ALAGxbxPVyswQvBeDAOrqXYwRJKXDonmiZ4YJFghhOgjM3kqKZnv/Uf6lkztgH8MjPSYo6cvsFssJziKQkxs7+Nf/yn2Gjw== 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=67IJNZXR8xHZysLARhWEOYDwJ5zgZ1zmECZ/EfEhyXk=; b=DqiehJikZz/gkcTtiSgu9EqpOScQ0rUWcvPHnxn0c4wSt6HKYooCy5ql4qIOwWRkkspJZePwJzQStAsHKJCRpyUuXTMmNKy962JFAXI0I3+5jhEpoWSa0plWiPAO9rAGhsBEif7xzoFiFJ+TU7Jfwi+4H4z74yTJTw3E9+lz2mh9Y6LbbO0pH4SPpT1+Q7X3yAm74KrNNDmo5K0ADrzdBZ1uPgrKuycvV2fu5rtt56vxRVaG+agDVPxNPxdmPDKzPLavTSymU3ZFYscJyVd3EYB7XS1ufONWV8oPXg0QwHR8G6eI8agRG9/BbOP2vAM7T+moyJJ5GuRmxaMltZwNXg== 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 DUZPR04MB10061.eurprd04.prod.outlook.com (2603:10a6:10:4df::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6631.47; Fri, 4 Aug 2023 05:07:52 +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.020; Fri, 4 Aug 2023 05:07:52 +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 bpf-next v11 3/5] selftests/bpf: Add two mptcp netns helpers Date: Fri, 4 Aug 2023 13:07:41 +0800 Message-Id: X-Mailer: git-send-email 2.35.3 In-Reply-To: References: X-ClientProxiedBy: SI1PR02CA0046.apcprd02.prod.outlook.com (2603:1096:4:1f5::14) To HE1PR0402MB3497.eurprd04.prod.outlook.com (2603:10a6:7:83::14) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: HE1PR0402MB3497:EE_|DUZPR04MB10061:EE_ X-MS-Office365-Filtering-Correlation-Id: 1ce2885a-0c94-4661-c79c-08db94a8c11f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: n/G0frIpQkTV0g0BVLzv3//UtigOMEhieng4P1b2OvrIj+qteM3tExICEOR8gc6lbQ/GySFfSnPVETSvb2b51mqq5qfz2OYB8JNUlSf+6Z1yaYg7YP/ZDEaOb7bKJcFR4ralLK2CKJIo8AC8O06XFOPQ0tKjlfdkd9Vol6onz1c2zDJcKG8BP+fDR4+xIvDkUDo6Xd4Xn6FDlaBFv3VIQ2GN7vygSVopEJoHw35UEGZJidhtpn+eIehjOGaSt4ClSk4BfrCErTfN8X/YJEbVK36NwjydL9U+GTCJb+ViFsaIRf3OvDKGnH6ChzF2UfvQgOxGXTLg5gkcI8RF7xEfMJsaRSeYUEnzsBYUZKbxv5RVzDMweylpvmcCUVwMB2IZAjBZ35HLKMlT7bUaj3jupHFt9WVLxeoOJCC5YfWlWpNDj6RpUB9u81VlbLhmsOcDSS3UMGIC3ZfiQpMTgBg0twUaI8HGPD3/epojT3xOp1iP7H+sLoZ9X4bqigTkdN+z/Dfdlr3Q4rZnap7LEIApmYI4TJOlbdLGE2VhWvQhdrXZqyMo67psEUOjCiqheV5cmdZOCwJs11uczW4ZxnQNhlD3PkorCIBqKPIAf75K1YVmVYknAQgFAoIV8JpamD8W 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)(396003)(136003)(366004)(39860400002)(346002)(376002)(1800799003)(186006)(451199021)(86362001)(36756003)(54906003)(478600001)(110136005)(38100700002)(921005)(2616005)(83380400001)(6506007)(26005)(6666004)(6486002)(41300700001)(8936002)(8676002)(6512007)(4326008)(66476007)(7406005)(66556008)(44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4LN8JXc4faaPyuGEjZZfsEhi4r5h9Kiib7tQK7VzpE7ekROX6tO5gsV6IfgDHQ68cgjXYi7woLvIjE0N9NCZrCVrfejWBKB+fxHu9hEkkEr4Rok9eXD7grDjLThIqSSsEHpewyNTWUIP5RQhcwvIS/9BqMxZQyx/28/EiwJxaA42NkOAOlZ68FgnXeoLkG2HKeezGzBMUOLuTLfNCcpWKM6pw1dNKPBZxp6uGeWph1oY41rDeF+wtVXmnJ8QwLWqRIeanZhWHJh/O7qUxK6mnBbQ+EKIiR7nx2Pm7ZEwnNsPufMbiMa/X4lzN9YdeffOjs6zCpqG1a6xfFHhzhAOlwOaeu6Knljohd3ofMAjmvD8pZ37DLNCcZ2bJivYPgWBjWHVWDfQwjwUJsj5FA1MUeKo1kgW5yPYidhyKC0nd38+m1lsqjlasnh6AXl/KcejdTVC8plI+Lok31ODPmLN5OsW5HDZGaPR+9Rsu/wwWp9NUafpDgOz7/35THvw1YN8r/kWBTfaXXa26IOJOdn7yeNmFUvE+nBd1d+teSeX/WCgII93NO0C7hUNMDiYVP9ZBSTNnnqnHXkSG2zWIwkA7AeYG0AqamJR3OoKP4eXfCv+WlydiSeXKkwSoEJg+ns2Wib3mtTZT54wrqm07 X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1ce2885a-0c94-4661-c79c-08db94a8c11f X-MS-Exchange-CrossTenant-AuthSource: HE1PR0402MB3497.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Aug 2023 05:07:52.1020 (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: 7197Wu9YeuH0a/gEp89jIhXcQHL2brTr40DlvWtIV51Q2hfqghOBfsA1rRiQ906Bh24tlt/16D4HBysp9mqoCw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DUZPR04MB10061 Precedence: bulk List-ID: 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 | 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); }