From patchwork Fri Aug 4 01:55: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: 13341103 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 8CB30C00528 for ; Fri, 4 Aug 2023 01:56:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232585AbjHDB4M (ORCPT ); Thu, 3 Aug 2023 21:56:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58548 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230201AbjHDB4L (ORCPT ); Thu, 3 Aug 2023 21:56:11 -0400 Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05on2071.outbound.protection.outlook.com [40.107.22.71]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1FFDD1FF3; Thu, 3 Aug 2023 18:56:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=JLhqxM0FzbI6Y2DwUaXAyXh5F6SpxIvm9MYqEzaWwJDBDK5wO3dPoDtfea0m5aRTRih8dli1aLL7i+ihVOTAqHYKK6eqEBRk+TLsrbiL4ZrYRdkGTU7iE4yIhrYjKWSGCQ0TXL26H48gzbJaqhJp9sXrMVRrGN8xulmfeq9u+Nb2C5Wq4jNOAAI0sn0Z1kUJY82dErJdYXFEFioYl4O9nEbpszv78JPWWn8+Y8JRDg3Fe0JGd+N6KGkjiQpIx82Pl2EXIxt/Zm3wYlXVK29akJnWLverwDalfY81gtyegkZMfmCmmsF3mGP1T7w+BLK7SAvwTtYIEF73pWEDr6Cjbg== 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=mv9lMNUug2L09HQzGZEkBL57thMLpZ2uJqN7UrJKGSRZ58eeGfolgKBDXR/M3EXJsqlzf8KoIYLjsojpdmfBdodbX8IaO0K4jnTTaiJfjPnJY7UFSFvme4z5at1XrKiiaRxHaJ1nvkzZXzZJAnV3xz2azQm6wO67Oueja/omLnJYxNVOP5j2I5HFz3Nekyw7h1FkUmrKosWRge33935XRzsR8uZwZambej8zSlno+rSx5YZupaVQI6qMIb9ErKZcuSuCJOufhjYNTVRWk710d5YjiN4PDcdzlKWi1NQNNHlcaF+2yI4ze0dOheUVt4mLGhhotO38OmMcoTTucKu/Kg== 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=S40B4iz9iUqXGTsy9ku6U/JIdZnmeqygB84XvHQwHI0Z+HwO457To6yYLGxdQK8AAt+tj5WbgpWK/fDct6uClE9tIL1nZIitI+JYXvdV1zOlyGVKkVDzGhRxWigGNtZ4cMDAT1i39IZqLykm9b8bGAbWy4OhPMP6Xlyz9xU2isdgkrpUCneHy0MtxsFyjRlcXVTMj6NKbNnDlItp1FMdIxbNEPaCUvQco08Gi5ExxMnOZPSLOa7mNSomeXUzlTZymzuB9zAVILH6h8lDs/2LOBVAzIOLtFrGDIhUVxbbDlU+4aM2ZPcUxHbAgyokY2oaCGTPpgJ6B4VVMU+qzu7JJA== 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 GV1PR04MB9085.eurprd04.prod.outlook.com (2603:10a6:150:20::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6652.21; Fri, 4 Aug 2023 01:56:08 +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 01:56:08 +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 v10 3/5] selftests/bpf: Add two mptcp netns helpers Date: Fri, 4 Aug 2023 09:55:45 +0800 Message-Id: <0cfa88a21dd907c2ab910d2c595d4ebc59bb93cd.1691113640.git.geliang.tang@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: References: X-ClientProxiedBy: SI2PR06CA0012.apcprd06.prod.outlook.com (2603:1096:4:186::13) To HE1PR0402MB3497.eurprd04.prod.outlook.com (2603:10a6:7:83::14) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: HE1PR0402MB3497:EE_|GV1PR04MB9085:EE_ X-MS-Office365-Filtering-Correlation-Id: 51bdfda3-b6b0-4a56-2007-08db948df80a X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: FWOm8Do1OrbDPUc/QqRbcp3+AcSnujK3hGDEKEe8rrpvzvHm9uNzBdVhYORQosPU/MFKZPtOJ/PZFU2r7Qn8LvLJWFDMlZQMN+rfXuZfgk77iw5QWRVgVQwqGmjbWIaF9Yp1AQjG6SNgsMesBk5zmdHWUnKolyA9NsWYJ8CaxI6+8IpeLQlWtPFkN+W2alYaj5jqTwJneHkgiZcJ0ikeUj69U7aSaROhZlIHc8HUzBrIucD9+OWx5rKvQOA0N5zORsZENIM/aCAIKT4cOe6Yx9h7bVN0IYckMkK9SexhCnMM1jlFzp2KTmMZtzruiAVtnn0TUCQWG2tPNEdBbXNTPHZ1VA3Ep7BpXG8+7H3Lac9RkCRoytMPpX7doDybWzuk44uZ8RpN1RyC1vD5neqiJzooZ01zm2ic61/n2OQqWy9NzHvspGICENm+AoIFmQhC+ZcejnRNql8JGYgysEFXLs1mR9YRv2ml1Xqn+pPdfjeTjrpyd/y/Xp626eZ2xJuhRQwT+nCx/l7WL72LBM3bL4nTE5SqYBNxIPvPH23KktNTqtyFSW/rZYT+GodO8HWc/75/xv+OU0egbGv/hP9kDI5OtOmJHIlD/64HdQ5bLP+JcI8/+us92sCMYkQdLPKw 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)(376002)(396003)(136003)(346002)(39860400002)(186006)(451199021)(1800799003)(6506007)(38100700002)(921005)(26005)(478600001)(8676002)(8936002)(5660300002)(7416002)(110136005)(44832011)(7406005)(41300700001)(66556008)(54906003)(4326008)(66946007)(66476007)(6512007)(6666004)(86362001)(316002)(6486002)(2616005)(36756003)(2906002)(83380400001)(13296009);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: UGiqfv337i3yDWBeoAf3UemlX3cNd7L/TDG1RHUxw/hH4fQytPOBTiWOZ9GZi7RY38ELZsRZzyTjxLvdiFTpWtW288jQ4Whr0DcpPNZVtnlOEAI6/imStOFa3/wb1/5sSKOjYQAa2a4Ek29oYLJkrQ9nm5/w18mr0Qb2ydc0MvN+THw38jMNQL+vtck3MlLW7KWDE/Pr3LzNtyL4EMdTyPqT/MPnuXxeSE+CLxgxLAKPKDIrlxfAkaQd5QwPgCS+tg8pMCFuED5cRle5AHNI0x7XItAqomiWh/dC3PZD8qGbY3YETZuB5gut1EQcSKpjywYCUdFijQu9e1fKW0YZT02Z2u+M8l+PllLVVItAanNc5aoafailoOfHHw1nsBrCN4kYRz0W88Rql+Y0Xs94I0Oyx5MpE26DEb0qGF20zUCh+PUtUc0eumYo3eZHb6qeyNc96sxqLg7Siqf1A29SUcxoPWXYwF4IWL3gK43b2X3bQ/tLDb614q3vAuXXmYbZa0NfEJlQy2sfXLqpkK52maFTi0nsFC90cJk2Zhf0RFc2IspV0wbsu35EO5tUssTNc4Ro9RCz3zGWXhVvfoUT37EnOEcBbOzoH0f55NSG8raix5o1pYfRlqDO3qYZ4IgG+JTl0/8Lmd+U8j5qnZ4+6RFZo0NVe5pJX7/vNKTXilfOmjRP+6q4CpB1PTKvuSzd0AleNIVE59CuKBuHxhe0vMbS6daChsvsxouEH/KrK4VwBCt6B4QUA8LkkHXGYCGqfoJ8zC3qG22hiTpWHw9WqCyYORmDQVxGz95KWEFrf6SR8cpsUF/uptv65vOTH2QpsfCDuAe0s/4ocLxauxfiYYIA+ly2/WOddaICVyfR6HXmpx6Kdoec+8r1brALsh1RbCYoJOaiA888q6wADRRgOnvdfmHWOlgCt90tGQ5GYVJrk/G1t3/0Ka463cQfYTjaMshvCAubZFfy26uxz44A/NsflhqgCE6FeSvI2Ulr9kEWqYICGOMe7Le6Dlq/NpeajSgi2abQ4zbZk+p8JDfZiYEZMaBEJy7VDT5M11kiQsJ7GqFUR05m5TjWwFgfGjo7A4adoI6GBbAJgANxc4TQA5hpcOPhEHYfHLaManMAcS56SZqtM3OzbeaoXeqDR+reiJLwxzMT1D85EzaF5RwDHI/S1v/96un5vYkIMfKoFmdslbDnZglFdSYDaiqJf4IulXd24T7f1qjOEyvtCoCPUuZvoUhBTFMyvGD0M02D/cwdCFCjDJi5/GIz8RZLv9vve2vhnuJ9F5pRixMMgrlVLBB8PqkPM8ljNMX+UcCXqAg7uo1yO93Aw07nq6BjihsWiU+pYLICqgLOt8SmjqGaaWi8xI5hu0b2hxBaSGSgbN3O3UvI9eoDo4nvmA/+DrMyPecvFRVn6rvZAXqHYyRpxg39NhyCyFXp9r51qoC18evfzPi02DHc6weHa5J04ICXVAMI658TM50djDDy6teAZiV11ctV/l9c1q0LhrLp+8SoTueXZpy+qR4kGMLBBWEIHUncgZh3G8SA21OneBWRjCP8h7FtDjers12jGlLgmnA/QnEM4xxfDi9TRsfwvY20 X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: 51bdfda3-b6b0-4a56-2007-08db948df80a X-MS-Exchange-CrossTenant-AuthSource: HE1PR0402MB3497.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Aug 2023 01:56:07.9049 (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: XP3WBoToEGQU4vsSRbUyVuEoYDEfJ25jQ8/bQKDPJx6w0YQlO+rfWpwuIkXcHuWELNC5XJvxACp+Vy7Duh5JUg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: GV1PR04MB9085 Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org 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); }