From patchwork Sat Aug 12 02:54:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13351649 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 3D091EB64DD for ; Sat, 12 Aug 2023 02:54:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236246AbjHLCyK (ORCPT ); Fri, 11 Aug 2023 22:54:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51364 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234296AbjHLCyJ (ORCPT ); Fri, 11 Aug 2023 22:54:09 -0400 Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05on2065.outbound.protection.outlook.com [40.107.20.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 316A3211B; Fri, 11 Aug 2023 19:54:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=CTX32DCiZo7iXhvWCqZ8fLz0ZPyOhLI+O2jr2J9uJ//RUxBwTQWX7aO899I/iADj6OLzMR2sN+2M7X/t4xfei1982bGGB4UQ0410uRPl1mNqqIBb9HRj5P9Pqwh0GUsGUBPUzPLwxEFM4GvuiFokyNIw4N/+ivltCInqPcn1WNgTMsNsJfNwUjolTZjXBWkB6lMdVoe5CvKLauru8Mk48aIvPp51NmXk0jBB6aBgkKWb244tP5LMAH+Jh7Hu/VaA8eyH79WACfhCDNwuyqDH774amJjfAf6WhDANkyLKkiKjn4+ImcNX8tJG2lAQ1DfCyNYnNDg6xwB3TdAuvpYWNg== 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=zd/8kfPIc8VH4juBd//fMuAR8mCKogVt2f5lxjDZThw=; b=cr/HfnYhoODgohYoCeKKP/Lw17p+CB1o/WmlEEsaRCxMk8VbJxxNRXkXsQNTF3kdRko8kVq2nhGfZXcAYl27qs1jjkQ1snYsVE6zTGSvEdsNVqNwmF9R4VRldo/WGx75aKTpUPHbbVXDuWNjd22MpaoLzwER295sllZsvnaOJFwLFxn1fn3sLbkJgTb9P5cSpEmV1mO5GIPLmrgJIdx2MKyvrQn/XHHGAfEC1efLK8JIum94t+UwOWB3jSrcksHGKquIjnX5ObhaUnDvKtAbnWw7GnUEjZz4o7XMEHX4RK5qcTJIUvGh5qJBZbmdJ68EmXB0ISKqUD4FMEZzm1F+0g== 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=zd/8kfPIc8VH4juBd//fMuAR8mCKogVt2f5lxjDZThw=; b=j3V6qTjSK5dJowI9XQkHcnlGNRO06C5HGdwtD/+LNzIUPq+RZUQFx05htCzHeDN5pGcuFI8KIy1MeZMhncuQNUPRnHeKIHNEKzj/TbgQeatIjTRX0G2JT/7jQkwsc/QP+BhvvraY2JqMEPHBvZaPO6jCla5To/xtAaCYFRBB0dCWKfM0HDvb2K6z0xKelwh+qmNJlw4JKRjKEzzfag6jVo0szikQxnkOZed2q6K2RdZp8SJB8GtE0PvRsWGgNT9uMSWpmOmGFnkYKmoiLJ/cnuXGYSFXX+FxLxVUNqUpTGefrNiuwnTd5QvVI76sH3I7GdWSPXr8CryFdhMfKxTvog== 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 DU2PR04MB8981.eurprd04.prod.outlook.com (2603:10a6:10:2e0::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6652.26; Sat, 12 Aug 2023 02:54:05 +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.6678.022; Sat, 12 Aug 2023 02:54:05 +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, linux-security-module@vger.kernel.org, selinux@vger.kernel.org, linux-kselftest@vger.kernel.org, Yonghong Song Subject: [PATCH mptcp-next v13 2/4] selftests/bpf: Add two mptcp netns helpers Date: Sat, 12 Aug 2023 10:54:08 +0800 Message-Id: X-Mailer: git-send-email 2.35.3 In-Reply-To: References: X-ClientProxiedBy: SG2PR02CA0083.apcprd02.prod.outlook.com (2603:1096:4:90::23) To HE1PR0402MB3497.eurprd04.prod.outlook.com (2603:10a6:7:83::14) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: HE1PR0402MB3497:EE_|DU2PR04MB8981:EE_ X-MS-Office365-Filtering-Correlation-Id: a34c7d2c-bca4-4938-1d23-08db9adf63f7 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: bQ8F6+ZjlP3OrjPzHYNw2sKfh/QEqXmV0PnQLnf2749HStROweRcaN1W53ZI/o7FHNlDjm8DOiocuP+4ZAO9iQi+dw9dRkKgUulnA3Pd29Scfpv9n4jlkt/0UU69FLV0JzDxxe2R5bX+cBedDQDe+EXoKhD8knkd5vpgKo+A7c2GGE1hw952zXcQBdPFIyuz2nCYRoZfW3uRw0z4ijpbXIeCrgUMFczhdpkwQz5YhgE9veYxi49BcEOnvT6Fhea3Z2ISxq7cxlwcFi4Pm/o+SDjNvXr6bX0naUWY9B2HTWfkSsgRusfkZX/EotF0nkk7lVZVn7eDA+Mmj3a+MKUh6MqcqFDtk+p/Ak7nOxL7UjLMoZkEgGK0YuakiIphUePsh/jVgAS+zKRL78JvVeZzH8ECbfQfzHuAVYoMMPib+Z0zrqbjVBcNgDy2Y7HcjIq0IO3LaSt6Xx7L/+SSRwPBkqnDxm71WJQTyvu+e51n3/5zJ+XdLERtT0CLjbHJaQaDaPkKKOw6iQkR4N711NQEFMt52GDYJnHs6iU6JzcVtvuFLXlePipvBjotbgbitRKo2h6V2xH+Kuz09Kbi2K39/IC14UOHN0Y0P5SXnABowVw= 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)(136003)(396003)(39860400002)(346002)(1800799006)(186006)(451199021)(478600001)(2616005)(26005)(6506007)(110136005)(54906003)(38100700002)(921005)(83380400001)(66946007)(66556008)(66476007)(6512007)(6486002)(4326008)(7406005)(316002)(5660300002)(8676002)(7416002)(86362001)(41300700001)(8936002)(2906002)(44832011)(36756003);DIR:OUT;SFP:1101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puGGyXbr0ubIOd9zbF7OuQFE5OYx09WDJIR/UacjhdmZ/A+Z6j1dfNCaEYBd9gU0Q5rAE7U8X88cbJ/Pqjzo5ElX9HHESgSFSYHR1xg4WPT/O3H5GFLDnjvuouh/za18iJdoL5Avx6NbLMxRXec6PIPPikejmaQ2m1/EXsNkBIHafqA6gav1sP2R85wI023m2qek6bJhqZuefBvQ+sxfpDStQC5Y4mbeRolMFTcwK8S5zzg+T5m8tMyZbmzrrNDkyBzXUlhn6AAtM79TfxMwKCfDw8y4DmYDBeoJzyqj1YS9iEs5NAzIzOpmfcxDCvVRYfQq0CH85bWcCnXqr3wz+JVuos1M9TYdMGEGgC9450S3US6JzpVY91UgH8OPMo4Kqlpbhfi8OqMvOFSI5xVpUe1q7Hg/DZ19XiJkhLx651YoRpuqmSrVxO+qr6J2jgAVs+qyWRhtTdrlqZbQaxn16TVNQYzakzyxNPMcMY9kDgaeXK3FZZFfIXQPhR+105gfjwJHLE/Y7BjlszlM96LTEfmsap+aFuU8AGHxq31wnAf7sVm3lDSc19MpiNHF6x X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: a34c7d2c-bca4-4938-1d23-08db9adf63f7 X-MS-Exchange-CrossTenant-AuthSource: HE1PR0402MB3497.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Aug 2023 02:54:05.1826 (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: pPMucEqu5L6Sbp7rgOM/+AZV+WkuNgAtbDjB8XXTNx8/VKT1qmOOhpbjLzUhtdWbLBZBQ31zZ+WKk3iQ3Bcf9g== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DU2PR04MB8981 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 | 31 +++++++++++++------ 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/tools/testing/selftests/bpf/prog_tests/mptcp.c b/tools/testing/selftests/bpf/prog_tests/mptcp.c index cd0c42fff7c0..76afb5191772 100644 --- a/tools/testing/selftests/bpf/prog_tests/mptcp.c +++ b/tools/testing/selftests/bpf/prog_tests/mptcp.c @@ -22,6 +22,24 @@ struct mptcp_storage { char ca_name[TCP_CA_NAME_MAX]; }; +static struct nstoken *create_netns(void) +{ + 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,11 +165,8 @@ static void test_base(void) if (!ASSERT_GE(cgroup_fd, 0, "test__join_cgroup")) return; - 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 */ @@ -174,11 +189,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); }