From patchwork Thu Aug 3 07:30: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: 13339405 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 A08B1C0015E for ; Thu, 3 Aug 2023 07:36:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232328AbjHCHgJ (ORCPT ); Thu, 3 Aug 2023 03:36:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47164 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232386AbjHCHf3 (ORCPT ); Thu, 3 Aug 2023 03:35:29 -0400 Received: from EUR01-HE1-obe.outbound.protection.outlook.com (mail-he1eur01on2047.outbound.protection.outlook.com [40.107.13.47]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 82AF446A4; Thu, 3 Aug 2023 00:31:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=RnRMk1GYPmY7F0oTYnODCjuHXThHKnb1EoMurBOQLrnjKmTglaR/6koqAdOdX+STMqEECxX90922LSupgZl88ISzJ36ltZyUQ8kCx2LmClXuc4xo570IROOGKJhdu6+ZcbWRwyJTmslD/4npAgd8q+TpfgFRwvfIdltWERkQLaf1NTmFtGPWgj1upEMye3Ph/E7PaYuCNYUHkWAgr8NmlKbq6wcLWWmzEqNInKuIpV8iFTpJzN99FxsQ+o5x1IHMdWNZL7ZLS4NrqAxzGSWwWtZxw/9bn9teL7tmoXmXUAApNI+Qwetle2iINC3p127gLqfhhYrjJnXqZ3CBb9XhPQ== 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=ne9w+SASlk/Lv95MbMWhAhkQTdsdNtw+2FU2WFehqL/H2PkVTqdFZ+sJlHKQbYdDc218G7AD7Urtujlht0sKh89tjz4TC0jBdN2+aNHeO3GO1wdghplI+rPM/tNYvr9jFXvxXBXZ349lVpyf1pVtgQb0RFgy2t3m0PrAK6hDg+eCH0kBP4Hx1pgpBV+XcGJhh7XdV52oRmH/NjvcvkKz6G3J5bM46vxgISRmu+UG3mBRAoMjT8x17lSZkgzYn6zhq/+66QuhJgCrbvYYHYog/h+SfQ08zE5f4G0Elqe5tIHFNjXC5FhUdU9YpRXhFNQbOrXnHhfpOWPiKcz7cCusgw== 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=JPj0Irxqq1r9Z4qcZJMIEjW97dKK1EB9SHMvK0HSm1oWGMXkTH9IeFBGvmUeH4b03r2WoWZSYAbBjXJbmHZJr0h3K2otKGjWJaejLrAon/5jT/7cZd9mRDL96HHkVkrJfzOjN7JZ+DrqfyJkVrPy7ZX1VruFvafFrPhCXti5ZmJ6spt8uRMjJ4lND+Oel9qhX9WqC6e6EDk5nJqMYKdQRMIDRUTC2RsHM7eUjx49pGLm4Ur2y6QUhdOScFX3bG2CrKgvrb1dZlzxjv9cElButnqetmHG67MXmCos3ZeNr0v+ZyqePui9chuDE/+jqG/dU4lYbWmaq6aJi9e/5eHJ4w== 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 AM9PR04MB8571.eurprd04.prod.outlook.com (2603:10a6:20b:436::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6652.20; Thu, 3 Aug 2023 07:31:10 +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.045; Thu, 3 Aug 2023 07:31: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: [PATCH bpf-next v8 3/4] selftests/bpf: Add two mptcp netns helpers Date: Thu, 3 Aug 2023 15:30:41 +0800 Message-Id: <72b924b35bdad2a598534e32869cf3a19516bace.1691047403.git.geliang.tang@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: References: X-ClientProxiedBy: TYAPR01CA0030.jpnprd01.prod.outlook.com (2603:1096:404:28::18) To HE1PR0402MB3497.eurprd04.prod.outlook.com (2603:10a6:7:83::14) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: HE1PR0402MB3497:EE_|AM9PR04MB8571:EE_ X-MS-Office365-Filtering-Correlation-Id: 3ddaec91-cb1e-4855-9409-08db93f39bee X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: +0cIk9khNadvbKoMJRK2f2q66fY2HhXaEtUzaKCuZukaVuwrVmOxpM5dyV1pOk5gMWgyVlF629wzODfezF0SImwPwJmN708RYzVZrcMktv+PtZ92uY9O71/biE/fckEd4elCJnEI7f/9C5Go3hjLrOIqBXMcI4d7+DqQuf5zNg8fGz+gOD4TARufI15Hllr0ghZ3vRAUFyFCf+E58L2qx+sjXmOP2NksMUm0o2lnsSVGJWjPK1m6XmSXQlRlus/KeDw1Gq6pJBFxjRjOLCVKYiECuGqH/vi4AU6ZJCh1FDRyg+imjRE1N56XfP5uhv6FQtim9uzBbyitin5WMzT/pumzPBe9Cthabhl3x+19DtqHt2LAbovIoiEcBaReA/RQ8A4K8IAhp1xvJL5zTLb9W1HywCt2wbfJD3iU/Jd1JoIXBUxC3/SnV0nOXn1xl9NKbTzRS6QxmKvkMw6f8UooRCnyab3eElJCL/6Lb0P1dPqrLEZMpLro/89nk3XQ3djukWn4Bxkibj2ZAGC1QVfMukXaQYawDwGiHkoc7TnM0841YHNfwl0dHyP8Hqlrddl8sWUmhn7ArRS1JQisD5A67grCoW9QZH0bZ/za87rxzIPD6Z+40baY/Nix0xi6Yj6LQBZLHQuLbjLJquVR8CZ5+mHyxtQ/EVwNrcshfCzaymA= 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)(366004)(39860400002)(396003)(136003)(451199021)(6666004)(110136005)(6486002)(41300700001)(478600001)(7416002)(5660300002)(8936002)(8676002)(7406005)(186003)(4326008)(6512007)(316002)(66476007)(26005)(6506007)(66556008)(66946007)(2616005)(2906002)(83380400001)(44832011)(36756003)(38100700002)(921005)(86362001)(13296009);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Ke5w8LaLcVypwN/7PZcZa0AVvIYi4dXbOUneqMMuTYjRJbEkCwzj/tF9ctV/W3MPQjEUsKSO7WuwwfSnKeXYcqKDFnrHdhWwMtNkv+ll0XjjSaPa8atXICy7Gb6V7d1VT5SsV9KtOekXhS5erIO29MzGf3dO+D2B3N47FZLFPVii7AHQx0LvTrYfWxvikcGjpzqDYHLZGgAJ7a4IdeMAtasabrjyMsGwncGJ7VEvkxpVC4IURKwDE9Ds7GoX9W6Wgk+MAdGqqCclY1J6fiVJ9qd0Veh93WGWTDeXJBa57k6zZUyQwm5aIi2Nay1Xxf2wRnJi7LkxDnj6gUd99XX86t5RzCZRu8Hj0zP40naGgpftLnS/ofDjAZB0E0iXn8KjJuE+nv8ngD3w6UQvsbnTOGV8y8onTcF3YWZFoZ14sEWiNp0i+HwwogV3jsihi5TDTZMDFu5UQYXusoG10r1PFlXtF+N9anygYUFOWtCxOzMuam8LNAR02Nxv1ECzIZbcG9g3D8TnbZKifR9OVKEDNi/zbL/uLv6cHgFNCJSvp8urUAt264kQ8BEGNvdXEoEDyQVkA0y1MLJWVuPK0mAJt/b9oyq1fdCb6vvGRDx/ha5FLvcxIiDPpNrd3IPN8D+1XhHhW0aR1I32V1AC0xIsPi/wJeDJdWXWK6lAHcmakCFzCh5ZeQ1UhDALczp+9S+o4erpMLv+2PFh7uAbf1Ao/rMAhHmZ+YR/DRV1dO/H+u7UV8312UGeiQgq2s89YSX+nvmnutJG8Z2KqqHwydu1842ON3qBhKzDvF6KOqla7J0QkDwmE2lIiQsbfV/enWSiHITQhICUZz2Hm46jHtYos/BOQQZs4xWVNQ99GfBtzXDDKLa/qjMC8Fc0SQn2z8OEj463bP15xxCbJLppdO6luV4ghFFgY6vQ6hdvpRgiLBEHn3RgXqEpB/w+gNjq1MZ9RW3prvgdCH+NPLnZam+/gkBgsZZyRHXJC/vBTSs3lx894oSdW1v+uMi0ysLW2Cp9O23FBaFSoD0yRTTdNs5U9XPmQJG50tP6ngSD63K2f/OKEYz2QymPg+qZmnCaNVOQsIzqzS3WE9tWDDkCzJhqmJVZbyOq0TO+bUzv+eTEvmkg5Recla36cmRbnKicA7oZIHz5x11S5YNU77OnS1+Os4/0ITayUZzm35f2c1gPaPV/lnXmmctUzw5OD+rbiRs6dNgripQzpObvTFVUxq1+1+RWsqHLf1P9AQv5VNOX52D3ZhT8H/ggk3nJn9aRbVCaQkt4F45zH7sM13VejnnhUr1OLRoOX8gFZh9s9nzmMZVpRBfHLXUAUJkztXbqZ9u4IBfRbVBCIHpY5hbiwn+C6C9Bs/4E569dELJOSNqD5N0h2SAYw6rVZh7GEGygYjBfWU/gSBKaze73jMtyrS93yoKl98JU5QCnF1lGlRVG3q/1GeR8ak/ZcoHJe6AsL+UzEhOg1BPS0806ir/nznRVlgSGwnK2W7KyZyJ0xbw+XHucpQ9xDbRK2V4ELc0Y1BA5e8s2RicJ4KU7ZG637ewpGDvNBsURDFwnvDNQV3TuX4k3PyYLAVTpELnVVttPYa4o X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: 3ddaec91-cb1e-4855-9409-08db93f39bee X-MS-Exchange-CrossTenant-AuthSource: HE1PR0402MB3497.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Aug 2023 07:31:10.7469 (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: +/QxLbbnPi8s1WSrUEKD2rJbm8uimYnGGtUsGWQ3IwL9I598JD6uZSJ7iD33sWIdUQO6ioFLLe+zHVyiBKwVYA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM9PR04MB8571 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. 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); }