From patchwork Fri Aug 4 05:07:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13341254 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 0B3335228; Fri, 4 Aug 2023 05:07:42 +0000 (UTC) Received: from EUR04-DB3-obe.outbound.protection.outlook.com (mail-db3eur04on2063.outbound.protection.outlook.com [40.107.6.63]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 73B594226; Thu, 3 Aug 2023 22:07:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=XXZfdhlssHsvNFQypnENJI8ufnm2XnI94XRop6+RtD/moryiYZR+umbKHeaSdSyAhxEUpqIoMh43TvcfTvDv3hK3M4drvaEfSFL8EQAbmV1PWp5EcbljmHuVqHdVMznbpIms7ZguB8IrkoHpqo+pNBCGo5HZ3aoQ3/xkTbHRREbLJuPtPWiwQslQMYn1t+Yh/ErdwKGBEIUf+QATshgi2fF+oL8m1MXjF/ZVkE4yQeym5ieSHdGgjPkYcC8VR1zNzDj4tD9US3xSb1AroQPW7uK84GtUM90IHa5EXCmeCfO9Dt6IL/nAh2bb0goxY1CSUuWE5LXrLK92C3su6AkgMg== 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=CqQC7wtcem5w25ikCspTa0HnuFuf5IRIq7RQHED/ZEY=; b=HmBQfAohHe7DAoljvx6iZRdkljlQMZxZ5BgR8Ivnit8SaaDRzniOt5jgTwPvmQX4NNAwHvVfhnKq2wrrXK4jdwoyrAmY6n5VcjzxJDsSRJ97M99OWVVDcDRKj6JXftxc0s9yN/eDmq6BYJogpYCZk4dFfwPk9B36z5hSyMbqAS/zSqFI2ZfS4wi+o1ZmPLDtBE8hPImCT85pMTT1/F8DHBZ7zU8Oz0qwAOQrcsC5vRy6puEb2kBHViS/zZ+vqetF9VP4Pnj6N3B5LR99cTf6tesGzXAlrmuLTPhFEAMw51YstEVLhBE/C4Qclf5IFbee0hVNnfOwu97l6yvGJmjtpg== 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=CqQC7wtcem5w25ikCspTa0HnuFuf5IRIq7RQHED/ZEY=; b=1GvAhVrVpIxktJeajVVvYXzLrKku15VGR0D6U37lbAib7uC+J3yW1nBMgYbpqBT7tzzgJfckgumYs+vgnee4A8FOVSB4Pq60ooZqMpnKk0/+TkTnJRfPmUstLYG3j1aKQTAcgyfHsTDumTv0n0PDhYkhRO80DOhSvFeMV7TMKe7ke3+YPjWqYTSjs2DKhSMwZU5TVeSCyF0kvqqXgyufFBYxbCheg/5jGUUH5p9Dbh3pUCyjK0Xgg/483HWbcNQPI21I2tuHqY6XhzdmCFTTIf0VwyvaaEKPkTuWoR28TuJM/zaxWekLlmvH9cQOOrgiXaQNHVtu1H5yBlw4wjjleQ== 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:38 +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:38 +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 1/5] bpf: Add update_socket_protocol hook Date: Fri, 4 Aug 2023 13:07:39 +0800 Message-Id: <5155cc5bc678564fcc4e0f6d4a4f82f646c66beb.1691125344.git.geliang.tang@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: References: X-ClientProxiedBy: SI1PR02CA0051.apcprd02.prod.outlook.com (2603:1096:4:1f5::6) 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_|DUZPR04MB10061:EE_ X-MS-Office365-Filtering-Correlation-Id: 92fcfff0-56a4-47cf-5673-08db94a8b8c5 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: BaLHE1LwLlzY7p4aU/AEJKrDJnHELmucfQ3tiQvQzfkCVN+Xsvmw7EJWP9g7jrEpYlCChhwulqnVbh4AmnBh5G3BigXhd/eMVVwQhS9FB8fYcOjgDRJv/cu6/2zrsopUvdxjkKPsJ6C6TUSEFkBjFbn6tjRcAComZH6PtyrkzVyU7zklRvwolfYYOUB2L+pXpAypq+NcXn4UiRQA6y2PdVPirmvXLfT5lyAVJ7yecB/3eDtKa9L+UWLwoHIlHNJGHQ4XclsAMjfdvdyfVhl6RIut8tRkY6BsBSMoLNoFPhb5WDx8gJaImJhrvCpTTYR9kPckuGT+JmyL5nMRS4XlWRDJPZlKNjQdFbJ4Q+iJEnKAwxS3t7aOFHL0juMNiQrPjXICcJ4K08z49+6IZpgP+CUnr/JvoZqeAgZ649ANWRYop5l8u3GLrE1R7xdUPfp8mPCBWuYJWWUfI1TiNAaRJc057mxbfVgyLLhBhcL0c3f8Rmqy92M0e0du0GEFjH+4lKc35/iAF17ot/sr6xFFjBWs5hTzY5tBGsHrCBnKjkJn6c4siFF8Xx3I+p/Y7apCptZ5B6P8B8Ee59XShkws2+l9yfEq5ZvUPAQzgN886tM7OdVBjv/AIOWrEqfIrt/k 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)(6486002)(41300700001)(8936002)(8676002)(15650500001)(966005)(6512007)(4326008)(66476007)(7406005)(66556008)(44832011)(316002)(7416002)(5660300002)(66946007)(2906002)(13296009);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: lHXxGiJ/OmZKuCSO4pA8LvWah7rS2b7eYmeg6i6b/0oqNPInA1Db1BEg+xgHkm6eONxzK53JwgHmFITH7dqwLUjSuz6UkGCNpqL3EfR/wk4YTZ2oKqDmb/6M7SdYJCTMi44ibWeoxF4cR8jqQdGkmg3767VtEH4bkDXl+IAmetnO6dxLzFT15ag96jPU47ad47RVnHmdb4Mroqqy8KOudt6jyEyrc8zTk6EOaGVJ/rsrqG5crBYIHLFzKE4rQ03fEVsSqlPeMAmRnUrCkO8Olk/jnpiQc24RHA+Luh7QPh9+GKSMAK38TFrADB5u50SWOwQSDaeB/o7wlXz0d8PhAJ3x5gK95YFQYDepjoMUefWcNh07k4OOGf9SB08xFSh7/k37yuI3xiuFgQ8PxNnItl/MJpeif2uw94dYvk7UMgZH01GWNGlT1eirJS2WLNi4UUAJt8CqED12dojP2GT8XA/I90F+flCz6EtLNdumPAlHRjnIBMeBE0Wx4ijSmbjYWBIWhSc+WNSSFrevTEcxs96D23aikaqa7y4kIIf5JKqADhws1yh8f3gd/O9thv9jKkM/LLGT8AAcVZoHtYuQ3L9B++xjmR7UDNOqQBzB8sQCb/KLoCPhNTqJYKJWAXkAWz0K0q4Nq9Z9sZHGJga9ATEJLarQdI7erfakbuE2J3tcAIqVPIHxJuaWtDGW5EX1dK5ggCO1fmeytlQsf0hJnOzEtVVxryislrH+phLjdhOS9+5dMue5K4idcg7jj/Rj72hCF48x9Ur2b/WPFblyZF7z0NNj/t39vOb5I0neZNswuOUlmD/DUM+yZwFSPpdWRsjqEDO4OCIuV7ZB52CYrEGKwtvKvbdsiwf3vyAAflSUb7sxH/FxdU9J5HZhqYmA7y7Z68IGHI4CqCqBFQcGXrxWE8UrcXYN0Olk/RclZEN526vSwYiTRwvDw6OV2DJHBJ2FnAVUR8H0p5u30Cz8rxL4coebYuaDRGLCobcWg27GsULxhChShvGS3b2UY3ws2oBkscSfamS/p7C3L3V2uBi+IDzGo0sFCJkY3Qlp7glK+Wu61AsNGoE3CBoeQ/ZgmwfGKZB5ZvsSBszcDOcIf8PfF4VQtw3Z2qhRfPAeOs8mFJ7CG+VyyQgFdOgY5tj20WninrDkg7O5QOKJiKxJ6S3YMgOmKe99WfuUW1b2VmbcQpcWfT0/5AlroaHxcV9kXA0ATpL0DRpNLpox3AiVrzgyHwQbUemLgai4fIY5TzZAy6R4q1k5kYoJLvFJteXF8+xUTGjpgo+dbHIEjpJvOLT3lT8PzqeH8EzzSmR6WWLy273K5wZ7+RUAP7Q2VNzoxLYCB1EksC+GT3nP7jndgCYfq1Tdqqg0eeGlSWAr65jBbYWGJoJPprUkpJg+eitomOGEytB9ZXkBFbRZAFBr+EPhVN31Er6eVeqggeUlhFBVYZrXb6OhAg23sqrp/kuKxyo/CH++kOJtvcM0HASha16zNXvFJKhc+cCmCDQurt/6TjT+Pcylb2ArQHITzRVTRq8qf1cVhwmRS/TYDW9SEVJqS5QflXUucKRIFcZUCrObe2OsuT0jThrtiaYqu+RE X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: 92fcfff0-56a4-47cf-5673-08db94a8b8c5 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:38.1228 (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: FpBmmYCkebPHfVYQf+8oXtYGPloS6hlSe7tZWXSwvLoAuSp+nQE1I/UkTBe7o7g49K+CTuSUuXlRWr6k5w8IEw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DUZPR04MB10061 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE, URIBL_BLOCKED autolearn=ham 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 Add a hook named update_socket_protocol in __sys_socket(), for bpf progs to attach to and update socket protocol. One user case is to force legacy TCP apps to create and use MPTCP sockets instead of TCP ones. Define a mod_ret set named bpf_mptcp_fmodret_ids, add the hook update_socket_protocol into this set, and register it in bpf_mptcp_kfunc_init(). Closes: https://github.com/multipath-tcp/mptcp_net-next/issues/79 Acked-by: Matthieu Baerts Acked-by: Yonghong Song Signed-off-by: Geliang Tang --- net/mptcp/bpf.c | 15 +++++++++++++++ net/socket.c | 24 ++++++++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/net/mptcp/bpf.c b/net/mptcp/bpf.c index 5a0a84ad94af..8a16672b94e2 100644 --- a/net/mptcp/bpf.c +++ b/net/mptcp/bpf.c @@ -19,3 +19,18 @@ struct mptcp_sock *bpf_mptcp_sock_from_subflow(struct sock *sk) return NULL; } + +BTF_SET8_START(bpf_mptcp_fmodret_ids) +BTF_ID_FLAGS(func, update_socket_protocol) +BTF_SET8_END(bpf_mptcp_fmodret_ids) + +static const struct btf_kfunc_id_set bpf_mptcp_fmodret_set = { + .owner = THIS_MODULE, + .set = &bpf_mptcp_fmodret_ids, +}; + +static int __init bpf_mptcp_kfunc_init(void) +{ + return register_btf_fmodret_id_set(&bpf_mptcp_fmodret_set); +} +late_initcall(bpf_mptcp_kfunc_init); diff --git a/net/socket.c b/net/socket.c index 2b0e54b2405c..9f98ced88ac5 100644 --- a/net/socket.c +++ b/net/socket.c @@ -1644,11 +1644,35 @@ struct file *__sys_socket_file(int family, int type, int protocol) return sock_alloc_file(sock, flags, NULL); } +/* A hook for bpf progs to attach to and update socket protocol. + * + * A static noinline declaration here could cause the compiler to + * optimize away the function. A global noinline declaration will + * keep the definition, but may optimize away the callsite. + * Therefore, __weak is needed to ensure that the call is still + * emitted, by telling the compiler that we don't know what the + * function might eventually be. + * + * __diag_* below are needed to dismiss the missing prototype warning. + */ + +__diag_push(); +__diag_ignore_all("-Wmissing-prototypes", + "kfuncs which will be used in BPF programs"); + +__weak noinline int update_socket_protocol(int family, int type, int protocol) +{ + return protocol; +} + +__diag_pop(); + int __sys_socket(int family, int type, int protocol) { struct socket *sock; int flags; + protocol = update_socket_protocol(family, type, protocol); sock = __sys_socket_create(family, type, protocol); if (IS_ERR(sock)) return PTR_ERR(sock); From patchwork Fri Aug 4 05:07:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13341255 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 36E03538D; Fri, 4 Aug 2023 05:07:50 +0000 (UTC) Received: from EUR04-DB3-obe.outbound.protection.outlook.com (mail-db3eur04on2087.outbound.protection.outlook.com [40.107.6.87]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3B8C42D5F; Thu, 3 Aug 2023 22:07:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=B3gd2y1usb3YXK7gICPMAlQ7DTsi00yexxbTyNKTKSxH0sqTv6bhsJfUrJe1qo78RIRaKU5cnVkpJkemDwiWqMND3FLK49n12P3/nr+8y9XEQQjf2RrdsNbZiWRkazyJBaopSorhrxevNb0KJmRy1w2va6slRo04WS/wa25LezwIGuRO0EVMphcKE4hbsMTME3nkBOgExvGQ+AGXNwD8caNgoLizkRlMh82t+TlNqPiisjR028cyFTjLiR+deT8oPaw4C2yhyKlNfRMm1F+Z6OyL1FK2Qo5g4DT18q/IW19uPWI1PKMSxBvPh3SZydnGacsx8TeA1ilPuEL5V8+J5A== 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=vHTWD5WwibfCNfatfe/o1L4JL9TuE7410T4Cf3XxDWM=; b=VlIYxWbDawp7wVlfzFNkOnb6FbZVo4RI36w0sqqA7ivS8VQh7P7GFmka3qCQCJjfIngDZPgUcOYSULXKrbr2iKeAt6uIl5Vv652swz15CnqKdaWdtzJn5H3kqix2ic9DJq4Nlz29kafBmYewMoPtAEZa0dleDFjAfZNpmPROm6g1nO3iMUBK15OvDNvz+OodpdfzOOgvYFbHvfygv8URCURYjbMq+jgdwXGiWVU2L3GHFnNuTqMbalNs87A2hcUdfYg4LdHGefDlBCA2Xbe6wDmVodDBLPYejh6OCRjV7yO1Y/EvH+05dWOE9cXBh35HfNIYDMYqIJmESF7pzG13FA== 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=vHTWD5WwibfCNfatfe/o1L4JL9TuE7410T4Cf3XxDWM=; b=4BPVTGACN+f7H+gcmaL8EY71sVKIy8Qj7HJQDJ9jsz1qAG1gjPjDaAuV6RR6GirNxxubXTvNE5yyOGdVHsGjOs4I+IsMtN0KFuoppIoaYMpxqsz7eigv6lG+JnaLUCG5qiQku+o0CUNJEaDtvW+iPKiEstD+gDp6l3fZGGuydc194LMLW7y6OeoJ6Q+rQ91eD6cThbeMcYGTzbkKChUa2ZJT7RAGpakyXKPxsZZnq/rDOYcwprVelVcaSQbT09+qbdfic1xIemqT/tCeSZ86ujETJRglLHP6w5XIhTvRbqExkmqjaxWWbx9ZXjyEM+cBa6K5hOYS9KrPFGIZWivnhA== 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:46 +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:46 +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 2/5] selftests/bpf: Use random netns name for mptcp Date: Fri, 4 Aug 2023 13:07:40 +0800 Message-Id: <15d7646940fcbb8477b1be1aa11a5d5485d10b48.1691125344.git.geliang.tang@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: References: X-ClientProxiedBy: SI1PR02CA0053.apcprd02.prod.outlook.com (2603:1096:4:1f5::8) 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_|DUZPR04MB10061:EE_ X-MS-Office365-Filtering-Correlation-Id: 6457fef6-5076-43df-2ca3-08db94a8bd85 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: pSbN7Bb/c2CcQBz9mNCGpAzVJOwL/jv8Obp3ue+/xqSaTazURwomoMmYBoMj5XryW/fqyvpqoVzG7cxDJXysr4JScyyXIeLKSYhOWCZMSas5QmSXq7LLOJC6taUCG4oy57+Ewts5HQOmhl1FO/h5v5OoPQkCo9bM8kl3tfqQRkeS2IHdyh4w6+KrO1q0s9OtuULWHC87BiCTS7XK40dqxcNy4D9jpklHzOAf8Zn50rm5HiV4i0j71JLtq8dJz3CrQCiSVChn3HEYdB6QEDBnKc6yZZNm1NCTEGd0YHrsmoUcDd/2MPlHS5SpIaJJzERITGsJGw9Y7cLQ/4CU2Yi3SphGllnUlFteE9alxx44UKH1NK+mJHddM8h1Ji5UWG5Xm4M2KSXbINX8IobQS9WCqjdRubdcf7l8UlsLnDG/lttqqFn3CknpyvfhUpZFB3OWXICFpVu2rBqWcmpzGnqgUWeZzBC3K+b8QCaysgA8sgQLUb7yFEFYgE70lKOZnHfTlld7ivajkGCS5aRmChr7BrkLWKRz/3RfhH9BvdvpQnpBpjwYmB7LkDg/lIJLGyV8U8UJ02HLT86p8opT/k4eBqf0AXATF35GCMSZ7rxtVdoWmjtu5ObfXlM9ReyTSRjPgTsmWtqyR39FOolWfjeH4vB1lVMhMHASjemVUB2mDvc= 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)(44832011)(316002)(7416002)(5660300002)(66946007)(2906002)(13296009)(17423001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: HhEUx/lGqelC1GhAyxJBmSdZtfyu5oNyUtqJ2Hkvt0m+LJH0XRBxbiPvQVHNVwve2vs+2N/u57YZsOh1kUaLUaHA7HdX28Vz85zB8CbRpaIN81IXM0nHeN2Eai0PO6oOXfvTfIBtbKhM2FXNc4kLYgzrEd5IKcXA8iosyRuDRZNkChwxIHxuS1fTI4R3vkAg63pqlDaFBGATrPjpiHRKpJWR6Tvs/hB+tpA4x7/om0hRHBpkFFPoqhBX6n0axA5NINvZTvaj0keua34KdHSrHIKsj2w7TSUOPfTNNqCRMImyo8bzzFahUE1n/SS8OjPuugza4HuZEp3RlTJo4ZU7jJmflEOH1wiBal7AQ5DoKYRrJi2t3gpu7PzCfn2uQVjQLr8faeR45/hzvCPwlei7z7yWiaz8O9Bc9120FgeJ/h+XMPORRI8ankJFN/5svZVI1j+xOqLzSD/WbM/RAMKixhswS5ourwu3nKWiBATRJGs4Z6yNIEVF7W6KbFeH8ctJd/h+2Dvl5U+2CSAf6d6n4o853GSFuwUKdCcw+jMwGEwxu4BwndlCNzwDqBDr0ZLtWsjwxNgZ3QcM+lO6cH6V5QXOc6vdax1YFZay4s/0LdEFk/1Lq7lNhBgq41zFmUUxYH6vn2Ia1GENEd+/RFjEUM39Sg8KmbRnUaawzI3EH8zxE47iBJIJe/d3oIoZLhvdKPPtTrNLfKRVoZEwtwuyUa/YlsEDbNpRBi0OV9HBl1z7cVwUUQRz1iZrPmUXAy7oBHQOHWjeM4u0QAgtaXnvJFLycaf1lS0LfWN1jQxwhBt18xc2pqewV5CsmzgpCZ1iH3biyjMWpb65y2HysYNQjzgJafxoxPISTj9QrGeZIf5DY9FxJn2InLg2afmlrT8/UnT29BrLOFIvc2fBWbRUWzvQENzOEl9i/NJMjt2PjtHuZdVY+7f8hqCo9HWkmwnKXhaLtAK0AuTTs1WRhYBYxqiOWy0kgrR1evNn+OY9k7dNtgsycwTdm1qSCmlE1jlCNNgl8tGJ7lrM2eUzGrwAJIlIzLlIasqx5ecOddvBbISLneWFid4U+wi1FdMN8B/PRVmIs+/0LpxXryf9rgmrOQIu+L2n6Rht8pwwRaYLssd5sPgOTI0n6Bf8eD5Fk5IvQnWNGgqNYz0TvQSMWtePs8kF586RgGE8A3UKfuCHJkigsTMmqt7ZtCFOo7EkDvKY9j/JEqQTJNEE4ImW6KNQD5QVG3NWurdSjAoRVWtLKd2e/dHmYPrLXXIfzZtxbt2EIIVL016fKdL6+5439juCCzM3COeeommYW3Hw3wAo/78r84yyKd5a+qXGXSXc8qTTaVnyMscpuUaQDdPMKYVxjezTcxIUj1ZAsDp5wGBvE48F+S7jT6EZ5jxw/qL4FHneRHkIMyaBNwC9V0XuUDV3qUKsZ8mpMklDnDsxk6m2ruqSxyA6NW0nPmGqvjaf/gF/r9m7gvrPrYMfpKYVeYKM2y8T3FML/crpl7+N+UTdDKWZSIC3BM+4BJ0e7CVtP402R1Ne8gsql9Y1QJSGK377GWd9OzIiiOGjjU/Oi3G7G1vEVPFV4PVBwViViSIQtBXr X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6457fef6-5076-43df-2ca3-08db94a8bd85 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:45.9074 (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: HmnQABBxMK1bA+PdiJkaP/PpAp90HghE3WaOvZ1NaTROCC18dgzFWo+FQJ8vluo81Jt3ECTmW0BcVJx1lOUlBw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DUZPR04MB10061 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE, URIBL_BLOCKED autolearn=ham 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 Use rand() to generate a random netns name instead of using the fixed name "mptcp_ns" for every test. By doing that, we can re-launch the test even if there was an issue removing the previous netns or if by accident, a netns with this generic name already existed on the system. Note that using a different name each will also help adding more subtests in future commits. Acked-by: Yonghong Song Reviewed-by: Matthieu Baerts Signed-off-by: Geliang Tang --- tools/testing/selftests/bpf/prog_tests/mptcp.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/bpf/prog_tests/mptcp.c b/tools/testing/selftests/bpf/prog_tests/mptcp.c index cd0c42fff7c0..4ccca3d39a8f 100644 --- a/tools/testing/selftests/bpf/prog_tests/mptcp.c +++ b/tools/testing/selftests/bpf/prog_tests/mptcp.c @@ -7,7 +7,7 @@ #include "network_helpers.h" #include "mptcp_sock.skel.h" -#define NS_TEST "mptcp_ns" +char NS_TEST[32]; #ifndef TCP_CA_NAME_MAX #define TCP_CA_NAME_MAX 16 @@ -147,6 +147,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); 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: 13341256 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 11E0A46A5; Fri, 4 Aug 2023 05:07:56 +0000 (UTC) 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) 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_|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)(44832011)(316002)(7416002)(5660300002)(66946007)(2906002)(13296009);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 4yOlmeqdDzXjx3iJH/TN9wd9bbnfyVCzVvURINyGnM60GXPC5HP/AzuL5XGAHV/3yOHRiCO4hRmFCNDQ1QUbNTSxIZ3D/w6TR8EaaTHv92uR67u6Xkie2fHgSQ7nvPQcrgGfBpP17jdu5ZYi9sXQTJyxpd74XTdAOCKORo4FX4Orgrfox2gCdSR3XQxrlHihnQQdMH0LOpvAIg9uyWFq/6udKKEv1QRNcMD0m6yu15NHSNmhQhjZp0fitvaeAe+A7kFSUOwqm9F0QlbIdKt/oCz9tEcK3ZQT2Jb3gfMUv2IikDFOiG1VdqMd5or0Gl5CZDBpAYHZSkiRROdufu8mS45bRhX+t4G+ilx6DVQKcrBWRuM2ulvXqFJ7VqyueFTNBDYAAJ4r7dIGr/8ueHqF/nptBm3GgYq70B/YHxgZSbn5ed2ZpGo/Ku7/GPK3PB7P7uZc9sT4O2XcmsKRhOwHNdlDQjR362iJwQIQkLX1Y74YEfq1OUrRxaF26JgkjXetCPbE8Up+LYClAY53gHQzfGiJ1IG3SZ7eWvvTDlxAGRkdKhr4XjI8u+HvVgbw1YoKph45JaZM/8k4OmhU6FlQMnfnaPnOmSc0m/W5+Ma5xb75GUsRJrA0d4eFYJF6IyiduJ4fK5N/rRzZW9jqMsjPucyIGonj8+MIEKkg9l9XMDouOnjsVJsZg0Ti1sIG1G5pg4H0h5aiCAq1Sw0qAQffPbPptXw5Xu4z7vqAVEgZr8hvnVgqDiQCo3xRdn4P+r+dk6S9KVPbMeasvnELkeMVACJRhLvrb+tyn/YMY7kqrZvDn4ta5BMYzPeuWHPpw/2LkaHl6tGjIcxEUKzEXHsAqYuTzFBIbJBfsaK0/KHz7gGMpLTketx7Qne7LoPYEfTFVFYHk2kYHwOKBtwIaoKWQ1Yp4+6LE6y+688RPgGxk30UF7d4LN8JXc4faaPyuGEjZZfsEhi4r5h9Kiib7tQK7VzpE7ekROX6tO5gsV6IfgDHQ68cgjXYi7woLvIjE0N9NCZrCVrfejWBKB+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 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE, URIBL_BLOCKED autolearn=ham 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 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); } From patchwork Fri Aug 4 05:07:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13341257 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 2B63215C4; Fri, 4 Aug 2023 05:08:02 +0000 (UTC) Received: from EUR04-DB3-obe.outbound.protection.outlook.com (mail-db3eur04on2056.outbound.protection.outlook.com [40.107.6.56]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 75C694236; Thu, 3 Aug 2023 22:08:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=R1zBpnFxUIfDDMpQDDyGDdizSqQ6fS2zg4puTaXkvka5z/fZ57mqQfNy6Ao0rnTeMY5JYH5St50L8PR9mb8v6QUUBresWTMr/JsR8YxcXDlL+LpTFnT7gbKeQvR9rF2qU7GyJx4tmsAHACPDqrMz5JTj2LHGVJEiPM2FVbGPtBh+8tsSq1UB4oexfLrasVirRifcjXMlaevzEcE8g7BmNTjTGQibop8VyRPPHBk2MZYsunv/M9Ml63Qc/U8vq6EAvIlh5IpoGKkgMn1UY4SCRRSA25VWHT1hFhTqSDnduOm7HPOLNtAAYFpte4nXZfRAcW1oqkL0iXE1NU4dhVHn0g== 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=U3hcBDUWz28H0tCgLnSThh4rsFQW8jpBW7vkhQIC+F8=; b=cGscQ4NnU0zIZbLHok/b92VWtbh9OvymBR94yVn6rzDVe0X9PcIJRCs7Y4fP+A7KGhNWSFuUh5IpNMmOf4s/nBCgdEdJm+LCpYPHLKsOKLfv9oQoeF4r7zdGAdA3Guu1H362XNCI+atnHaNIjy+hOL3oQPoXycHsBwaEQFZRFDd6AQ6W4aStZCcQ++mj159nDYB21SqLdmZTaFNKexDblRq6f4we6XqU99toFTgxWBbo+pEJdKYyEsXNUNIQl5jmMGz0aJoL6n+WxuGGbK6uktP+O2REO/4NEvXa0uVGvENNY/8REo9rkLAe3cHI0Osw9yHXhV9h4Vex+Lk5+v0dwQ== 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=U3hcBDUWz28H0tCgLnSThh4rsFQW8jpBW7vkhQIC+F8=; b=HqhsryO9jWLNVvNcDNWPxg6f83yoKxE8NLE+MT5MfYPmlcubRsU3+RbZJDyQVA5M1jkhgD5toR/dCCQyjcvWjv7Ty8bOXP/OkyVuFORQt16fT/LNy1KZODSw0FFD/RvTS1xgs+pJcxN5USxLPXjAk1EnqmIvt3+d430Z2JMlAYgSQYBsYUITan1p8d1WZ8kXSS/5G7BMb0Nk9IVgQrbUphc72s+Kz9ox+diQu18Gx+MGzIdH60cylQwPrUtyMjJSuClY1bXfFLtOsTuVbsKqAgJ6Omrkra5Prd/7Rim/DIGh0NjtAKBBbieVJhbzn1O/qBOk6cosDb4bXbjm0SoB6w== 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:58 +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:58 +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 4/5] selftests/bpf: Drop unneeded checks for mptcp Date: Fri, 4 Aug 2023 13:07:42 +0800 Message-Id: <69c9cb050deeca1bbc54d97070ff5c0d5dda16e4.1691125344.git.geliang.tang@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: References: X-ClientProxiedBy: SI1PR02CA0051.apcprd02.prod.outlook.com (2603:1096:4:1f5::6) 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_|DUZPR04MB10061:EE_ X-MS-Office365-Filtering-Correlation-Id: e3bbac02-b12b-4391-ebf2-08db94a8c4c3 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: gHbZnINj4KjNJBw42dlLpNqbbO4GVCZ6Syf92K3hHhgpHKSmMhfN3PdTSR1TaXkwG7Yldm4vRlkJ2TMiAs6FXYdM6FcE+32Kb1Gjyqabi9wi1C5BX+jLpzInYJ4skzACl3YsO7VQYBbja3iJ+/dV8WEJ2cOMu0Efh0k8R3/bAGZGYSQsVVuqAQboDxzWJid2FleE4SUsRKoCdh6sudW3QZFNxjuFS+8cjUWNZGrjPA5A3QXy+XUij5Ry/qqQhYcVc0C1owThrcNhZMNnqORRgGg3jrMAqodP29feamVDigWfqvUt8yB62EFdeylvYYxLjbJsf3F/VaBtGpiLKWLwdQLmf5wXIo46Za4KhVx+TtQv7zXdjtnvhm+Ou+TEBX5/ujuM6k2X0unqjZRQa0lV/MHFwpzh29CKVZo0/pAopBDJq5Ln3brrOtnhDHrNSLSJDN30OogJoNOgJqQXqM6Nai479y2TRpMPCVxMzpG0i+Er3SV0Q0ryB0M6yeI6aZKgv8FcojJX7hFnxX8ffmhnlyXR+TU6NO+K/iIocpuzkPk8TiR5H+4c8wIzt2T7vD+zUfKPCVPPNNTI/9wTmgCMmGZPCS249JfzN5dGsjoirUUlRblwYmha0diJd3mfSeYwyb8TPuye2DRO3mrl5j2yVQ== 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)(44832011)(316002)(7416002)(5660300002)(66946007)(2906002)(13296009)(17423001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: e8o6yP7qnrFTeXdS7mJwpW/ksP4pHBFjHlB8zmMcKpQKhfxgWoa2O58QDJ/qb7VTtOAsTJnVDB80Hj5988mC9o1KYLYrGCdLeIwfAo/5iv1+X9cfPgNL9iFt+rCwyRdpLfKDxkBl3ikeVXSsLixf2hoypahlS6zQthW9y7CAsgc345M5vftmwbbILKmTCEnzZMtaPHrjMTsCPT0JRepAjLA1n698ajBhHPW7TMW4ouGw26K7S0CL2pf11W4uJG1a1NU7CqUUqUGlQyA6IUXsoxX9HRZdYkFSvGiOLNATuWve95awqbJ4+MeQHG5no0f5OIT1Rsuvub9jmATKhj1qcDmNoOQOVhxLHvoA7+eheNllpAFeA5OIbCEXRS5ObVYbYAVp3424+N5Cg8ZvI68xJEEwwij8gM8h0SvH6Rg3aHQGwfpAMHjX0hBypYHTuW6TbakObsJCd2OCL9NqMOGqewSI9kD4zvINNTL/YEehcVXucEPSwA1MyowgmomWlQxsQLQaRxJa1XCDMqXVpfRvj29gZRIpIQi0HKPNhe8q9fOD0syj2PecC0H5xxcf4Nhsn0FqSkQiXWjnbREzSUlsZFvFcjZNQqoZ+Q6bkZpQ3oZtzClUCrD3ErFU3JNyWGsDM5iR0HFUGwJfnuss4IC4yNGsPtq4JoG3EQIKsFFSHDbFKZvV81ZSeB2kXRZsUKgyU0q2WRc2PacSfNlchpXejm3LUpuenGLNWthTbQNt9SeB6YBr0Np9fGeF5a+VUXGWoKANWcT+AON3I2VZ15ojg4yK81NM3Lv09iq/qocowAUYjgHkpR+IpT4IxahRiv/nGOPaJ67MKeC4msfxVLHj3WSZB6pElvOVSx1CxFGZd250i5ZWY6tjJl5fuDiY/bxEqLGqo42OHFW9A+64OT8PQwEkS6DuAJoLTwZLtLU32uZsXAdJ1J2fT4C028KBzAMelw1K+5n77XeL+m5eiQEYRKvI3EJtFNu+HX2gBFmsUGmvrPZ3tUvMgtN7l32iMKZezr1vp5ptSECHPLcykaNJW+7F3d8DSV9i8wg79UHUgpQyXlTuw8txOjnvSvVxuEvC9N8chHdulUqJ3Xu65niItsIg4tKXKVfenIL71HnK9U393EGBgqehsXbjr/sed9RYxyyN4nDjEjR9WFVCcv3QdJ4rLTnZlAMAeTlLFfBUKTOAS2Z9XQgyf2iQCt2YaeUhco6qaVbeEl4digLDcKpl5wpujVjHIHx45RcqxWcmPxfrEykXRjEXGnhVpqP9ReDpuhIJ612eG4W4irankVMmLFJnlpXJ7c1bNGEUiyccWYve1NgKv8/dkXeN6ILURwuCJN+2Abaj0w1b6NlLoYAufAi0poafm9FBmCK8rKQZVFQDvQ48F+Ml+8VjloNSvuUnxvyDN8jIOT7I3V4lUrmpUSUczhdXHJMJ/jqMX9v4kSFZoVeAv4GE9Al8DFDox3g9YY2eV0ceupbJE1aD05heZBoEBaL7ZG4lH7Ob5keV7YobK5mJ8mYJUMj2OGQutTfOne1Kb6xsHsvEECyrs73pAJLtieHouFBmWDH2A0vDcoK1JcSsDfZ41cc4YwLjI1Re X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: e3bbac02-b12b-4391-ebf2-08db94a8c4c3 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:58.2332 (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: whoTZNN7Njm9RDN2w1ToFdX8FOa+pb8yvLGtKbYZfEJhwP/4V0sx++TbOIje2wGo+G12e9BlQR2AaPW/4Q+p+A== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DUZPR04MB10061 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE, URIBL_BLOCKED autolearn=ham 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 Load success means prog_fd and map_fd are always valid. So drop these unneeded ASSERT_GE checks for them in mptcp run_test(). Acked-by: Yonghong Song Signed-off-by: Geliang Tang --- tools/testing/selftests/bpf/prog_tests/mptcp.c | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/tools/testing/selftests/bpf/prog_tests/mptcp.c b/tools/testing/selftests/bpf/prog_tests/mptcp.c index 4407bd5c9e9a..3dc0ba2e7590 100644 --- a/tools/testing/selftests/bpf/prog_tests/mptcp.c +++ b/tools/testing/selftests/bpf/prog_tests/mptcp.c @@ -127,17 +127,7 @@ static int run_test(int cgroup_fd, int server_fd, bool is_mptcp) goto out; prog_fd = bpf_program__fd(sock_skel->progs._sockops); - if (!ASSERT_GE(prog_fd, 0, "bpf_program__fd")) { - err = -EIO; - goto out; - } - map_fd = bpf_map__fd(sock_skel->maps.socket_storage_map); - if (!ASSERT_GE(map_fd, 0, "bpf_map__fd")) { - err = -EIO; - goto out; - } - err = bpf_prog_attach(prog_fd, cgroup_fd, BPF_CGROUP_SOCK_OPS, 0); if (!ASSERT_OK(err, "bpf_prog_attach")) goto out; From patchwork Fri Aug 4 05:07:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13341258 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 1D4B379EB; Fri, 4 Aug 2023 05:08:08 +0000 (UTC) Received: from EUR04-DB3-obe.outbound.protection.outlook.com (mail-db3eur04on2085.outbound.protection.outlook.com [40.107.6.85]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D4A412688; Thu, 3 Aug 2023 22:08:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=gp1stQ0qRXhZ5WM8s49srNKcpJF+DMtKny7Vs7qIoDKaTBLNyhOkeaDuftbfoAQjH7xuhOn7uRZMqF7twiyOiad8yEnu421YL/WqmOhkijkZL789eBrpAARCmB7RJrTArhKcvSMHOBH8XOraswaCdXn7ufoJdxDFkUioYQjEB2WWiqEzmcEss7aVkUIV6Fi70l1BjxUabDKz5jENoPpyFQirhG+5Ko3XXA6P9ywAK1KUCYBuvLYDRHjftzH7ua+5IFMvDtADt8LzGJQc+NabvUOjqYmPSxCQ6kMnqQP2BKXr6rkbAVWV/CGXrfdU8VO3zojt9oSuVdI+n3h/6cyWsg== 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=13wKlekbfF8LLe8HDSW1X/4CtojDqgveqxTtDofm7Nc=; b=SlYIHtMmpHrQc7+betHc3RPdDLBDrUHsU85QURegKdJb4CP4o1zzRgbg8ffeVd26qRgi+di+AbRLhIkiCo03rdHwN/8GjxNSweW8mibbe2h0W6M6v7IcsDjX2xt4dvWup6SF8RHx3MCcYP4RH4RqXSM9Wo4Gh5VSu0mJbgGX2MY6/YDubL4VU1HaTHv2s/1vNd9wX5YIf9y47aJAymLpEJBmv0ApQJefF6QSDYYB9FdSaRiJ/Cos9+71/4CZOYBiCyNWX1TFG5BO5eafIcARahQvylo+fIxk3B5rcvV56qKDL3U0xYzg92Ayp+/sXkuysX+uNH2RBhebbOsa7sV6yA== 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=13wKlekbfF8LLe8HDSW1X/4CtojDqgveqxTtDofm7Nc=; b=0ayBoEc/z4HU86pWIaCBHvGUQ75s7e7o6xvq43Jg3bZ93Vz1+//BBavtMU0o/LW2UtRaFNN6l95mDxV0AfO//SWLKS5ruii7EKtIgqH0qSytWL5KFiZ4PqwpARQklpFDnHGHbKgnuoq4QNBM4yPCgGcQuFU77yd/SZmr1mnGkz6b1YfijHTH09VwY2RizgAFZXhyImHX+XcSGp/uMek+VaQiyurq+Ll8qiVlvm8SPRgjLFicvBBPmrWhUqJfJuixSIvVfxPbPotmWxR3X14a31rtfQ5tI1/GlJ/abrRBzeYwfk1LE55GnoYeErfY3+HS7eHMw/3Slw+Y9uYklsHCkw== 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:08:04 +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:08:04 +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 5/5] selftests/bpf: Add mptcpify test Date: Fri, 4 Aug 2023 13:07:43 +0800 Message-Id: <1effb0a793140532be749aebbd7912798245745e.1691125344.git.geliang.tang@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: References: X-ClientProxiedBy: SI1PR02CA0054.apcprd02.prod.outlook.com (2603:1096:4:1f5::13) 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_|DUZPR04MB10061:EE_ X-MS-Office365-Filtering-Correlation-Id: 36d99d15-374d-4a51-4978-08db94a8c882 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: pCaWEUj/MudoTB/hh7j1DwnGjzPFOXbwweOONlRNfOZt0oa2mcAXYed068KzeStwWvknzPT4VZKvulK0ViQ+Z2fxxKz2md7wBToMDTX4AYNas+JrklGudJnTDiUcAI1Pc1GpP5Qqxwq4BfPA9ixxpf8/vth3JLqNchlmAwPQaZLID9ykOnFejMO29MVcNuR0+ZGJcf1KjEjSSZFFyDipLspnjiPSl8E0hlHColxQfg6mQCDKr4QmxhucrqZamKX025SyGqBe9RkrKHVBXSmiFjHwG021t/0BnfWFBeyp9LRIVBt5TkknUSC2/YJMKwlSewwGVlbR6lQzinQmhi8O3x2PQsJM6RL/LRNDG9oWOc69L+fjbnK22tsKdveK1kDtHXzoKUcsrGfL4EAS58QY1XFqN6PF6rtrQRiBJaziaUlerbINOxFYWnYR4dKpmUWKcAltfTG9zD3FeiUAkKlxlJXyncWXJknvIDMsePqdkqShSTQnb3W3sNWUwNAERP43YyuGlVpaYcx1AjShgD8Fu2n7rc/gWi1K7HL/HGTDl2JFp0eDSDWuXXx3zvZMhX6pGJFRvI12VZoQ8Z3E+C6dGwpQIW5mqG8tg0RHHYp4dgVvhOPWeW06RGYgzcoR3m+e 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)(44832011)(316002)(7416002)(5660300002)(66946007)(2906002)(13296009);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: y6T2eXF8lVUZPGelLEUZp5Rzt6rt7DTE1cXpCLIg85ZO1uc4zOkHHBl0auIIylhPZ4p4Nc2D5jJ1SXVFp7adJuficV+Ts4LRsF+tOA+kxjGsPS4qS3/00Ee6gNOI68Y1HVlmMy84iZkYtBYF16IltFDJELGi+kmtrpBpXpsJ5b0hUZRMS7CpQDsjWNQRah6+7j9H654LH5iPVWY7u9p1UQwKfGF0M13wP3aLA0J4mafvKVm5yUuWi7/O22m4ilfA5kTrG9ZzGoqoYUsI5UzmBa9+aQULLuNYmE4PJN6bB5TP7iHFVX5ItnofMpG1+m2uGMMksb1pF13X8RIR4xcYW7+FT3Ap07i0dx9qEn4/JRZgQTykMYKJUwOjmFD5Mz77zxBzi4Zsza+wEQLYU372SShDRGvR72kp470cPbyNJHTt7cD3S2gf4h6ULWyXrmhDHnBhuzzeEsGnonjNQF8ejAUwsaZKzCkDGdzQbk7LWeP4PiKhXxYTGMGbb/QDlqQtkDtHj1UT/zYE3zRKUEAVD2iz9FzwLxTD+qMhBgf+XW+fs/jbDam+JL10uVBXf0txAgLrqBDBmzF9xI1TjabKOLjXhXFDhSwIz12r8Chl/0fV2pRczdgsKdBnlx7RUZZ6HoO6dbEoz3pS4IQFpihQlL1lhfQ4bTM0eIgqPZNAvhiZVDzT4Vjq2jdXI+S5hbkjICmkPw+Z8lh8l9UvEZV49PUX5z4P6Kvbb+afQgJKdBF/E2LA1yh+3YqGRhpjyK/jMP0DjFdJUt43LbvhPC1etP2IQo2JmM9D14oBmVosVN6c4GV9XcE0DwN0vCgE3EBYkpb55Ahi0Cr0gAsTZ75b7/DSadG2NfHPx0r98gPFk3IHRqhzro3cg9Ik7fbxB9GfO3iH1gu/S3TFCrmwNdgQmcCeGCg4vaQ1bu8mZZdWwLsHDm0uetkClNzN71NGNIoYiP9SApG8fJesZ/ZB7OWqp6vJCgd0AAeiK8B/X/edny4ujQkU7XkrWE3UOvq60p1H9CcqQY+7VYFgyq13Kmg435A1L1d8qmSCAKlI+a8uMUzF9Xv6r9G2MeX0rIDXeMmTiQVqwply8nwcCtT6ab/bu0gCNytlOqwONtqsdzEnzp7qKbupkM/1grNgPpGf61Of6LvTxz+3LwrYMO2VZ80MLbKKHK0iw3t3XcB11S0bE4c1i3v0yh7rm7Q1DL6b1PzbJ7rXIcaTuQoySk2411nhGFbw/sufuRQ+gGlmYIrfD0wsZO41xYyTMT3f7M5UYCUCJmBqhZbzrdFY3MvMxMaYvYDcEHXoTCpHsJia3h9oyydSb22ViIuhhKUZ/aXM3b0BRoHauyr44XEpD2vRdhIX/wMvbpP5wBGm24RuSk/eWY/lGsUSyuSEo/lyPEuRzZ1J+i6a23K52ry70Xu2PwL8rsx+Xw0XOnYtCoOrhGsfa4ormf2+CW7UabTwhEW9y3WoLhC9kQvmnUAg/BPHq8FP3S9SyBq5N8BGuHj7ACSuMiKuJDEhInr7GdCgo9lc+7ERnj5sx61109PMwnlebTuzhom6fXYvQFBMR1r9EomsMwdHFZ48jWCQpc8gk9m8j1PD X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: 36d99d15-374d-4a51-4978-08db94a8c882 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:08:04.4943 (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: NPTjeTyQaJ8QqMokVWIqgTj3v+UDF67SlaLvcAoT/JRZBPMnhV4ADguSxAFmwaPXTfoODBHVzCTskLIOV7qYOA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DUZPR04MB10061 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE, URIBL_BLOCKED autolearn=ham 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 Implement a new test program mptcpify: if the family is AF_INET or AF_INET6, the type is SOCK_STREAM, and the protocol ID is 0 or IPPROTO_TCP, set it to IPPROTO_MPTCP. It will be hooked in update_socket_protocol(). Extend the MPTCP test base, add a selftest test_mptcpify() for the mptcpify case. Open and load the mptcpify test prog to mptcpify the TCP sockets dynamically, then use start_server() and connect_to_fd() to create a TCP socket, but actually what's created is an MPTCP socket, which can be verified through the outputs of 'ss' and 'nstat' commands. Acked-by: Yonghong Song Reviewed-by: Matthieu Baerts Signed-off-by: Geliang Tang --- .../testing/selftests/bpf/prog_tests/mptcp.c | 98 +++++++++++++++++++ tools/testing/selftests/bpf/progs/mptcpify.c | 20 ++++ 2 files changed, 118 insertions(+) create mode 100644 tools/testing/selftests/bpf/progs/mptcpify.c diff --git a/tools/testing/selftests/bpf/prog_tests/mptcp.c b/tools/testing/selftests/bpf/prog_tests/mptcp.c index 3dc0ba2e7590..e6aafb4cfa8e 100644 --- a/tools/testing/selftests/bpf/prog_tests/mptcp.c +++ b/tools/testing/selftests/bpf/prog_tests/mptcp.c @@ -6,6 +6,7 @@ #include "cgroup_helpers.h" #include "network_helpers.h" #include "mptcp_sock.skel.h" +#include "mptcpify.skel.h" char NS_TEST[32]; @@ -185,8 +186,105 @@ static void test_base(void) close(cgroup_fd); } +static void send_byte(int fd) +{ + char b = 0x55; + + ASSERT_EQ(write(fd, &b, sizeof(b)), 1, "send single byte"); +} + +static int verify_mptcpify(void) +{ + char cmd[256]; + int err = 0; + + /* Output of ss: + * + * ESTAB 0 0 127.0.0.1:44180 127.0.0.1:42225 cubic + * ... tcp-ulp-mptcp flags:Mmec ... + */ + snprintf(cmd, sizeof(cmd), + "ip netns exec %s ss -tOni | grep -q '%s'", + NS_TEST, "tcp-ulp-mptcp"); + if (!ASSERT_OK(system(cmd), "No tcp-ulp-mptcp found!")) + err++; + + /* Output of nstat: + * + * #kernel + * MPTcpExtMPCapableSYNACKRX 1 0.0 + */ + snprintf(cmd, sizeof(cmd), + "ip netns exec %s nstat -asz %s | awk '%s' | grep -q '%s'", + NS_TEST, "MPTcpExtMPCapableSYNACKRX", + "NR==1 {next} {print $2}", "1"); + if (!ASSERT_OK(system(cmd), "No MPTcpExtMPCapableSYNACKRX found!")) + err++; + + return err; +} + +static int run_mptcpify(int cgroup_fd) +{ + int server_fd, client_fd, err = 0; + struct mptcpify *mptcpify_skel; + + mptcpify_skel = mptcpify__open_and_load(); + if (!ASSERT_OK_PTR(mptcpify_skel, "skel_open_load")) + return -EIO; + + err = mptcpify__attach(mptcpify_skel); + if (!ASSERT_OK(err, "skel_attach")) + goto out; + + /* without MPTCP */ + server_fd = start_server(AF_INET, SOCK_STREAM, NULL, 0, 0); + if (!ASSERT_GE(server_fd, 0, "start_server")) { + err = -EIO; + goto out; + } + + client_fd = connect_to_fd(server_fd, 0); + if (!ASSERT_GE(client_fd, 0, "connect to fd")) { + err = -EIO; + goto close_server; + } + + send_byte(client_fd); + err = verify_mptcpify(); + + close(client_fd); +close_server: + close(server_fd); +out: + mptcpify__destroy(mptcpify_skel); + return err; +} + +static void test_mptcpify(void) +{ + struct nstoken *nstoken = NULL; + int cgroup_fd; + + cgroup_fd = test__join_cgroup("/mptcpify"); + if (!ASSERT_GE(cgroup_fd, 0, "test__join_cgroup")) + return; + + nstoken = create_netns(); + if (!ASSERT_OK_PTR(nstoken, "create_netns")) + goto fail; + + ASSERT_OK(run_mptcpify(cgroup_fd), "run_mptcpify"); + +fail: + cleanup_netns(nstoken); + close(cgroup_fd); +} + void test_mptcp(void) { if (test__start_subtest("base")) test_base(); + if (test__start_subtest("mptcpify")) + test_mptcpify(); } diff --git a/tools/testing/selftests/bpf/progs/mptcpify.c b/tools/testing/selftests/bpf/progs/mptcpify.c new file mode 100644 index 000000000000..53301ae8a8f7 --- /dev/null +++ b/tools/testing/selftests/bpf/progs/mptcpify.c @@ -0,0 +1,20 @@ +// SPDX-License-Identifier: GPL-2.0 +/* Copyright (c) 2023, SUSE. */ + +#include "vmlinux.h" +#include +#include "bpf_tracing_net.h" + +char _license[] SEC("license") = "GPL"; + +SEC("fmod_ret/update_socket_protocol") +int BPF_PROG(mptcpify, int family, int type, int protocol) +{ + if ((family == AF_INET || family == AF_INET6) && + type == SOCK_STREAM && + (!protocol || protocol == IPPROTO_TCP)) { + return IPPROTO_MPTCP; + } + + return protocol; +}