From patchwork Thu Jul 6 07:47:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13303292 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 1891A15BA for ; Thu, 6 Jul 2023 07:48:53 +0000 (UTC) Received: from EUR03-AM7-obe.outbound.protection.outlook.com (mail-am7eur03on2077.outbound.protection.outlook.com [40.107.105.77]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0B8621BD2 for ; Thu, 6 Jul 2023 00:48:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=bmn3pVvbX7XhkQiMTqEfz0tmHinIJFxvGAVD7JpssPZAGQH1zmpeYPSyj/eUQ0PW3zpeZD6ODdrtp7LRf+kQREAjhtTVV7MHO/u9IX8DdFD588SQMasnV53G2q/jAjLeDdhCSP4ue1ir3jzwNI5QNkwlEy4GL+144yzC0a0lfoiCV4jVCNkYOIE4pvMESUGCMsS9qhRODSA6Z/i59GM0/0Vets9tV6mOfp/DGAblCJGpMdooUM4PKyKH7BBtikz1wPr3+4tgVe4HVyYGy5BGluzDz89aASkux+ukrJq5R9wnk2dXun+fEHr4WMPU+S/30nmabbsywHItglhiNUtWKw== 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=YoV861M//CggYMx/ntigXt1CYAXI6xhNp+GNJSoiv9M=; b=VEdhO6ft78aA05rK0bfX9AQFg6VU4qJpd9Ppzk93jCNQXTM7WlYApFOP/WyUbnINxNZrR1LQItLS/Qy8eV/7tsHmIDNQutUnfx8pP52LIhlYKbJg2CvarWbzGPnm0E9NLlsKkoJ6U6KNuHYbqG5fIvxF3hQpl1EDa7Fauk+J2+PK1VHNLtUB0jdYKN0PWEfSqUcikCLszdKFbEXK6EhkiSC5ycU2K1Bjk0JDdqm2LHAZCCRl6S89bbuR0OFO9TSZG1MO50XNpgqRKuKUfGxPzYMND9yIivGwcUVaTK0LYE2d3RY05++qH0YVpXJuHE7Ug2N018egyEWCbZJkMtY+CQ== 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=YoV861M//CggYMx/ntigXt1CYAXI6xhNp+GNJSoiv9M=; b=o6ZzjcLdFI6gAm4Ph9xF543geZ4zVUcks/JeXf45MtkmwujTX1UWUqPZSJWgvu2F6ZQ9rJElOUV8rbrROdUDfpMPgBYf4iPkEJNyQewifdc5Zcdji6vvVdTxawCad1w2j6NhMPVn1JO2d914PCqTO+DIzLK5zWT+JL7TNZsHz3QPz0/FI3bUn20iRPq39zADw2aRYqbKjnSRVVGvedP+uaGSXnMIt9/ey/6ZCREywVyBOOScyTt+hy9SPL5T0shAdZSZOP0UqIHSny9TST5/dyVYu3a29JxHGPPwwxYRAsqyJk47CkbY7ljIGrH/hLW2SGrmPc9wKZlZx1Di7Irwfw== 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 AM9PR04MB8437.eurprd04.prod.outlook.com (2603:10a6:20b:3dd::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6565.17; Thu, 6 Jul 2023 07:48:50 +0000 Received: from HE1PR0402MB3497.eurprd04.prod.outlook.com ([fe80::423a:a30f:5342:9d35]) by HE1PR0402MB3497.eurprd04.prod.outlook.com ([fe80::423a:a30f:5342:9d35%6]) with mapi id 15.20.6565.016; Thu, 6 Jul 2023 07:48:50 +0000 From: Geliang Tang To: Alexei Starovoitov , Daniel Borkmann , John Fastabend , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa Cc: Geliang Tang , bpf@vger.kernel.org, mptcp@lists.linux.dev, Matthieu Baerts Subject: [RFC bpf-next v2 7/8] selftests/bpf: add two mptcp netns helpers Date: Thu, 6 Jul 2023 15:47:31 +0800 Message-Id: <284f75cccd4e848f17b54bec67b6889fbcde1a35.1688629124.git.geliang.tang@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: References: X-ClientProxiedBy: SI2PR01CA0018.apcprd01.prod.exchangelabs.com (2603:1096:4:191::7) 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_|AM9PR04MB8437:EE_ X-MS-Office365-Filtering-Correlation-Id: aeb789f0-984c-4714-302c-08db7df56fc1 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: f9JtNWV/XipMqkpyfpDCkZgujtVzlBLdxCR5h7JCEqu2IJZdrNI+hotPr0HYc9rPC0Bf2Vx/uHWKKQtxQSCfOmsJ6ZKONbC8Ug8Z57DtAzB5y9x5fTKWvWFBcFSunlZUxhNbocZdp1LKMcewX/IJ0i/Vk8uaaChI5OaMojmHBFMBEOuG7qxj/AGMw6VJUVcehkRj4BYJBuYFnGZcfnIbCswgXmIPAEfpsbms6p4TTawp/cZqZoa0G3KSrs+NP7uEazBDGzjQlAm6UcIQEhw7JHl6JymFN09K+jjERzuUmRHTGJx4gZudB39Mlf3mIM27FAdY00vU804bcNn+g6L4Ila7W2XxJl/UkeAo3uCB7KNjWO1ZNCYcdWNo4SWlrm9NbVZrGLU8oPhJ5mTE817OaA7GbeKU9SU3bTuxaFd58cPLKi5MAGao2cCGz964c6Hit/37pq+xNazBK/okjKOcu28R4Ql+b8+u0FMr7VPvF7ckpRVFSxLgeyAKK2aJA08raqWWTMYQ7NZfLqdhqgJ+Ubqv63Ct2lf+ZlfPb3uQDmO4rCitfawUKfcu0DnvUIqA9gitfZFB+GHFW2TSjg0siEk2JgEGj780leeiio7PAAALiPPjOVbpcYYaIF7N7+eF 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)(346002)(376002)(39860400002)(366004)(136003)(451199021)(6666004)(41300700001)(7416002)(5660300002)(110136005)(36756003)(54906003)(2906002)(44832011)(8936002)(316002)(8676002)(6486002)(66476007)(66946007)(4326008)(66556008)(6512007)(478600001)(86362001)(38100700002)(186003)(2616005)(921005)(83380400001)(26005)(6506007)(13296009);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: +cVxcqFrTqkqqWZ1/VOtbUv6HSy0SGbCp3g4C2uA4cpRfVOOvTaOvPUK1acOXUOukIZPxJgTTonH74HDUGka2zsf4Y+ufkyZORgzF4pMHpxxVIvIWh3lrx9dbuPIzPqcaNiCzEGzbXJQ1QUloqQZvjSz2MCwKigsNA14O3p+4PthThlGYsDjKjsS7M7yPMFWjnVjMXn09s106qtEwgaSuT9Xqihx22Rdx/yzw6jW91Z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DfogZ+ZVoGcsAtEdwlvCaKAZ8pZBCzb32ulJMS3K8EC3gilHiFMZmdqv9xwVNxTrMHkCEqpmDgKX1QG7Gm9EnUiAY4YEYTR6uswy2MGD9gfaatu4gtvYNS0CK8m2ti0J05IZFv7IUvgkEjypuncp8HcWfManvdssPzAaR8tCrQfTb/GHIR4G0VehcrFyh6aBI7QkjuJu/0z1CkRajdaVsyg0N9Vb2xsqOgzlDe3q3s99VjI0Bj1fJz+evHmVNkbyC++prBrIw6jLw9YjrY5Mr2ITteYbL0+ATG2BbStw5caYhEWRh3C0YaC+ X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: aeb789f0-984c-4714-302c-08db7df56fc1 X-MS-Exchange-CrossTenant-AuthSource: HE1PR0402MB3497.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Jul 2023 07:48:49.9691 (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: MXdAAwtx/tMa7tW1CI8Ns7O6W4H8eHuNZ9lY13GJAjWB1rmdYdCdJ8BFmqO32AahpXAVsI/UQ47LHce2xFFFkw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM9PR04MB8437 X-Spam-Status: No, score=-1.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FORGED_SPF_HELO, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=no 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 X-Patchwork-State: RFC 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 | 34 +++++++++++++------ 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/tools/testing/selftests/bpf/prog_tests/mptcp.c b/tools/testing/selftests/bpf/prog_tests/mptcp.c index 4ccca3d39a8f..b2a833a900c2 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,10 +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); }