From patchwork Thu Aug 3 13:41: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: 13340046 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 D9FB91F935; Thu, 3 Aug 2023 13:41:51 +0000 (UTC) Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05on2045.outbound.protection.outlook.com [40.107.22.45]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3FA8D44A1; Thu, 3 Aug 2023 06:41:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=bXUNnsCQV0iSqJ75Jq7K+suRfbUtSktLrNAO8xNwLXO+ygGOmbuztXvq5r6xAoCp2KmF+LiSGXe7aOU7lsAvixGu0x+v8RdGcswELFIGhdgKwz6T5O1grNcmE+fttYGHmtn1QzhEV/WJqsdPwRI8HCeBR/ab26rHAVlE0nlfSVeIOu0w8zZbuSSlTTOm+klRZG4zNPSRFfz6h3GnqGx70t7ep/L+51Jfnrtr3T6WvN/2ZgszE5ZGbznftq8GjZOx8a7tzl8ORL3V9wNKm9Xg5EX6G44ZaSuOpKltmsXTRuc6zrKinMSzVhjUdggUhuFLKoT8NfQrPm2UAp5jNnYVCA== 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=DD0kw2+0/ffqwVvqYQuyKv0x7CGp4nGi8nyUCwahJ5M=; b=OXdWovl0KgbMFS4s4HInC2ZBSLix5kOt5zG8ovVtCk8xzl6BCsBCUrg8jWqlk3ONyqY3hdD3rH6i6s6Eb/j8NzBNlzanijm71gD+PzBX6WEqVenOG21Ot8jiXstnT4dwMU5PoOS+rDEbV0ASJYA0p26gSjku8YXQDxMnQxTOxiBMaYztXi0xOIg0BIFa4mUqH3/YOpqmqZ+G/grqDGie2G2iiRrOzrw1mSEHMspKdbdFgYxm4VBJBqbObAYEMh8/pBgPjBj3vD8L8n6RXVbhM17Zn3Xd0amyn4+c9PKNYsLbUHym5XM0aljQ6QXAmokGbF1QtIf7+5N3YIWLHKELCA== 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=DD0kw2+0/ffqwVvqYQuyKv0x7CGp4nGi8nyUCwahJ5M=; b=2RJriGX74msZ353XAvRx+ytouBF/p+81nbcl05QQ++/gZ2YEVbql289i8GWVl+7J2VyXZi1xONvizVgfbguH7cfDiknLNCVnqFu6rwnHm9VnxuCqAhE+1sH3BYhjZxWwDwyjWUVhAiroSQQSX2pOsmgiEzQizlSjmEEk7mfv/IAAt30mzWwWdHOfcIWUg8uR72jAy0PZk613FtT7vEwUB9f8+1IPsMcB0fSJnh0lR/D7eydCrO0TVk4oEp9owKB+LP7zR9vBuqefNIrnudlnlnH0OYoRWjcQoAQgZFcXJdHZHUe4h78YWgq135izTkNZb++VT2mxbSPasXOLZHCE5g== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com; Received: from VI1PR0402MB3503.eurprd04.prod.outlook.com (2603:10a6:803:d::26) by AS8PR04MB8580.eurprd04.prod.outlook.com (2603:10a6:20b:427::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6631.47; Thu, 3 Aug 2023 13:41:47 +0000 Received: from VI1PR0402MB3503.eurprd04.prod.outlook.com ([fe80::6480:1775:c36d:b797]) by VI1PR0402MB3503.eurprd04.prod.outlook.com ([fe80::6480:1775:c36d:b797%5]) with mapi id 15.20.6631.046; Thu, 3 Aug 2023 13:41:47 +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 Subject: [PATCH bpf-next v9 1/4] bpf: Add update_socket_protocol hook Date: Thu, 3 Aug 2023 21:41:43 +0800 Message-Id: X-Mailer: git-send-email 2.35.3 In-Reply-To: References: X-ClientProxiedBy: SG2PR03CA0099.apcprd03.prod.outlook.com (2603:1096:4:7c::27) To VI1PR0402MB3503.eurprd04.prod.outlook.com (2603:10a6:803:d::26) Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: VI1PR0402MB3503:EE_|AS8PR04MB8580:EE_ X-MS-Office365-Filtering-Correlation-Id: 569c0b44-6c0f-4114-5db7-08db94276238 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: r6p/IXflHlT4gD7oJp13einpP78p25kze6EgC37WDaFYH8ilpl3x2o4FF6utntCZwQFoGeON/zopDCbW/E/9Th1Vj9Gi1L82UpWpAQkanrpsVpW0gdJo0yepha/kI74TjvwpTsk6fNwee85DTLJkFN6MIPNrASi7Bj4J3A0Onw02rPp0NzHD+VKlVz+NLydl1zosgc3h/ZtdJ+vHv7nw+nb8+E6s/43lP2TDmbLjGrodqZDqVJ4XrXmkdIBo/LdlQtzBrOs8LYdv23UH1fal6Mwk0ocbJ63gTXBAjApjw2DkrgqyFbVQfll9OSVqTF4+1+MlUHYbRM4Pba2fqhK3LD6kuq45LiI/q1e3Cglk1WcM3odgg00hDdfoeyMEbgbOZh8FM71R18JmMAmfURbe3OpYwxcLyp847oOp8n6AQTdgasuge26D/miHNyH4odpGItZskyog7QHnyLrwTeP0vFttyABvXgqPfQPKmmxwRc7K/KUgyx90Oi4yGuNSRerXUjn9ebbaEBfHyRXvQwIyhpDMcjwLg/LSjvUYSJH+cOXhqP1qQz+9/86LmWC2AVuj/GB+FlZ82GV+zuThcXZh4QGYtKc0T16DEkZ4L02QlKI+iym44Ytniwnu64Kl/7Bx X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:VI1PR0402MB3503.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(39860400002)(136003)(346002)(396003)(366004)(376002)(451199021)(2616005)(83380400001)(6506007)(26005)(186003)(41300700001)(2906002)(66946007)(4326008)(66476007)(66556008)(5660300002)(316002)(44832011)(7416002)(8676002)(8936002)(6666004)(6486002)(15650500001)(966005)(6512007)(7406005)(478600001)(110136005)(38100700002)(921005)(86362001)(36756003)(13296009);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: JBCTRUDswJgzTVxgvJxdDXnWa/+vbMTl02HauuLnsU5t766L4apK3AkUjeSstzWWlAPCCd/X8HhiTcq4ov4LrpSZYv6Sn0IEL+s0aD3nHew2fd93IuFWx3Y8JIG8En8+fns7w7MJMfFWwob+/gc/48iD2Ca5/ae9mZ5yNaLfLZ4d0YfD5frelZN70PwQHljn4fUJaFNc4s+F2yvTGloBRGS4+sPpp1jSYpCSBKcfKyMH9+tzUpcdJXFRswBq5s54w6JNWqSlKxJkngg5NX1siINwhCd6pttOTzZ/Yr7zbe5OubE5uiHXXtftYHPLsTYF2yZMIuC/poaJ+L4bkSzn30HzYJWwLRs5ynQj2x4s9bT187vToyGEhF4O/K6pHODOAOdMl8SbJ2Z1lDC802oLE7KpHppNcQecZwgS9mKMGoZPenbc4hM7KNopUI6jhnV1C1GXldGYSFQS644K3tbqQKRcwMnlm9iSBcAUZDQZiQZWyJZckpOJSKHw69aaB4Ye0iR9ql9+tD/VXNAWYkfVA6W9kVH3oTgwkA5iOwYC1Lgm440hiAw59q6wYMWeEii7F+vIqe9/r1JGK2uIcXyz28Qy8TH46dHK2ABYxqjxzoD9Blbd13S/8qn5zCBs7+d+2L1QB3YsIKmrO+VbOSb7rFBmWWnCQGNHaNGmW2JULg3NGjK+dwazxC1K+er/ih1a70eRlyMKV3BlJ+FfRPlR1y3LpCc8afsmvbjC1XFm/8Td7U35+o1Ga8gzAVKGeLCpI/6jnTC2/I/eIyDWXWfrP6BOAIZjBajb4tRK3764abBW4I4uUHKt+JyMJhejVY8XCppmCJCHlzIPX+DuEUQ17rks0S+7wTCUlLNod1KNBJmqzaUDXHADlGVPoWVm/JAuDlAM71mK65Qvp4BBfjq03aBTt8X5Tbhw9md4uZ4asduVE4fDlMXh2nVOKKxGvK/f4RXZ5gu7h9hYhMvjWiGYDDfHVHC9VV6TJYILHsuTyJm+qtCS1rzbr0cAUR+PsZGpZAMq6OLNUYjOVX0xQimiycXUVnWpPDM1xiE+7zgsVMQ0y28R7UErNzTIA59Oks+XQXlXTpGcWixXqLRjrtGd6u60hR2yqHA1z5HBoTGk27t8mW7xH/mbNG6Rz1vnlRKBafSf1gFa/NEdohO61NwWM55Qdg4gokkTR3oxrtDEQHPXFniO9WOmfGR4Xemz7BwcJ30jE7zLpOf+vY5IenRFoRKKc8VdoCuKE2UOdrgsMwcvO67JqlxWj+OKxBFv8LmOuIpkfI4kYrQt8XGZM8nl2Egcdakh0iwWmZeCFd3f3QlPIyIYT/RaSkMyDRVCRw6bIfghD5fLbiRypeGAqpIyp+lnIpRas3ix4VGjuR30i3G7Mynh09lv1TA54hodlXTEzKDPQQ46SucK/qVmbjH9tRqF7Rwr9g8XrHsaw7vU7v0BoFLWWuW7wapnLO5yTnHGPJ6LI1zeQdB58yqf5C1KJsBFcByZYDT78O8MNeEszjxEv8CKHFJDtVvCet20vGuDVi1ylHkZUDdQNUa/jZDBPMeihP2iMC9kmaGb9KJ/nMBHyKSr9JazE9cDiZy6zh27 X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: 569c0b44-6c0f-4114-5db7-08db94276238 X-MS-Exchange-CrossTenant-AuthSource: VI1PR0402MB3503.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Aug 2023 13:41:47.8092 (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: lwJ8ovNZW1Z19b5fZYDs4twvOT9dIEIE0luDZM5MY6r9XbyCJsSzhMgOTLKnJQ/U5NbL/6XTx1Bb1Mo8q97mIQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR04MB8580 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 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 Signed-off-by: Geliang Tang --- net/mptcp/bpf.c | 17 +++++++++++++++++ net/socket.c | 24 ++++++++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/net/mptcp/bpf.c b/net/mptcp/bpf.c index 5a0a84ad94af..c43aee31014d 100644 --- a/net/mptcp/bpf.c +++ b/net/mptcp/bpf.c @@ -12,6 +12,23 @@ #include #include "protocol.h" +#ifdef CONFIG_BPF_JIT +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); +#endif /* CONFIG_BPF_JIT */ + struct mptcp_sock *bpf_mptcp_sock_from_subflow(struct sock *sk) { if (sk && sk_fullsock(sk) && sk->sk_protocol == IPPROTO_TCP && sk_is_mptcp(sk)) 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 Thu Aug 3 13:41:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13340047 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 341EC1F19C; Thu, 3 Aug 2023 13:42:00 +0000 (UTC) Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05on2059.outbound.protection.outlook.com [40.107.22.59]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A916544AF; Thu, 3 Aug 2023 06:41:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Q1+8J4Xty0D26GxpMgSM7ikOQr8mj4k9jdE06HoO1+gXg+Uihh2lkileEAwxzHJkTcyNUknpH1iPtuR3YWbCUjrs4jpX/0ecgw2I8P41ZltXGGkO1+aA+fOg4wC/QPoLX4t9EwLX8gBhmLFll+0NlDljDy9DuSUwJ40p58/tvpBiyfULyJF7peQvjxrA58zGTs2LfmqGOkNOWDBeeTg+tCzWnxoS/r4hdSOzgMLrsiY5T1Cj4edMaU9bFd+KYT6CuulycdScoqkMx7gyi47CJzpbiDL9J4FmFjvj1FTSb2bcnHuE/PelUaIO2L/PALHKBKPLlZ5gbRUJsMIz9VEqNQ== 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=02iyHHjkQUGelZcQ1iDaZ+J0TmCKyxhCWbnucp6bY4w=; b=fttcYwfjV3bwpK2LXnXnZkcyXlFJAOYsw0wWyZbrgx93f1h9NgnmaHikzuBMY6qkdhEkz5bUEhpqMRN5XR3hIT+Gc7WEqyb0uavQ/zWXgnJ/KPgkEcLfe1sV+4BJgguMBv3mzwt4OW6MN087lKpnKIQU+2I+bS0CbjP59U1CFiLsZscFIQqfM7zeh9OGn1YOERWMB1pR5J7kRZl9Zvr9ixk3MmZdy4gxkadPg2OdfKTq+Zm4MHNsFwtAibdXodz/Et0yj57wYO8/abuodLT5jf6OSN0ZkzKQuYJamwyRJvC6HYLdF0okatna3vvYwMgQzFNC0/N0S4isBmS1OguU+Q== 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=02iyHHjkQUGelZcQ1iDaZ+J0TmCKyxhCWbnucp6bY4w=; b=jUSyGbb/0xngYWavV3OdfrMohiKmVur0eV9Xo1MfzTJ5Gd1pnIxwzhj+kQ6cmf/WBtRxyunvhm+cioqZrOgikgDjeT94FNrkcfRBwv7vRU2D5Q24vWXp7sI1vcFgoGOSfoRDjhurFbYa+N0SrfTD4bw2BR/NUxbl5ED4NV3lVubDanWWZzHE5RUnVDkKcriv7bQpC3BBoiCSRUUhLq8642Nsmr62GFdPBopHbIIoTv1mnF4nkCzetpDzD01FWpVrzjJP/SbScib1KAjNofY5D/FLDBGKkfrkZS0FbJHjlCLoLUnV+AMXW330j3BpcWCEjrFtabcoZEtYLKFEtUqyXQ== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com; Received: from VI1PR0402MB3503.eurprd04.prod.outlook.com (2603:10a6:803:d::26) by AS8PR04MB8580.eurprd04.prod.outlook.com (2603:10a6:20b:427::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6631.47; Thu, 3 Aug 2023 13:41:56 +0000 Received: from VI1PR0402MB3503.eurprd04.prod.outlook.com ([fe80::6480:1775:c36d:b797]) by VI1PR0402MB3503.eurprd04.prod.outlook.com ([fe80::6480:1775:c36d:b797%5]) with mapi id 15.20.6631.046; Thu, 3 Aug 2023 13:41:56 +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 Subject: [PATCH bpf-next v9 2/4] selftests/bpf: Use random netns name for mptcp Date: Thu, 3 Aug 2023 21:41:44 +0800 Message-Id: <54307a065383fd3171a6306ddf30395b686aaccc.1691069778.git.geliang.tang@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: References: X-ClientProxiedBy: SGBP274CA0015.SGPP274.PROD.OUTLOOK.COM (2603:1096:4:b0::27) To VI1PR0402MB3503.eurprd04.prod.outlook.com (2603:10a6:803:d::26) Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: VI1PR0402MB3503:EE_|AS8PR04MB8580:EE_ X-MS-Office365-Filtering-Correlation-Id: 592c70b2-073e-4a19-e5c4-08db94276746 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 9PpGBH/rrDQu6td2smlAiduRmi3wR9x7qU0spzPfiHXsxy42Fu6NsfymZNIwOxqi+URSC/gnp8EjCGsLji8cVNUHrEK6/fztumnVQJ5f3M/LYb36NbvoDEavIfM1QzaHCUJR2iJJU/T4u0q57MRxZD8b+H5Q1gjyDzG3z1731q+Dhdw0J/o9MF/+qSAIcbhyRmpthY6iFH9JT5NlhN6CPn7RGyhysMQnaNTiv4yEuf53Ak8WGzy3s+hGXNFk083qIXvDPfEgd1+MB7eP4MQrvPD5r02pEOTdfXnU5uYu/xTXeKFbYue8rWKE7KtJ0qJIhSUDwzufHqba5hntPjBl1NhEnRGC4t/y18yKA+Mkl4EMkGrG7Zmdi9p6nHd8Pm+EM1WQrT3Yb69bnDPspoPIyNpoiM6daK4TFY5CTMSBd6u8vGnJuzkpEGYvgvpRNVBI3ohqYET1XY3bvjvcuR4WPwgBxWAQLfGDwh/afSlHk2Sk44AlFreJVWXl0eoEUqulOmPR/c3osAT43qGwcbLNqQ0d/5dJIbfD4NLZy84HT0+8XAQfUMChliDurD4qPyadPEJjm5szwjke8Zei5rKgBysgL7qCEal4Rh30NF8/SoPeJfvAsZmY3bswEayQAGn5h4bAk9VW2pgGvu2U2oDl8cL7QjJQgJBiUTV/TPbPY/M= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:VI1PR0402MB3503.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(39860400002)(136003)(346002)(396003)(366004)(376002)(451199021)(2616005)(83380400001)(6506007)(26005)(186003)(41300700001)(2906002)(66946007)(4326008)(66476007)(66556008)(5660300002)(316002)(44832011)(7416002)(8676002)(8936002)(6666004)(6486002)(6512007)(7406005)(478600001)(110136005)(38100700002)(921005)(86362001)(36756003)(13296009)(17423001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: U8lvmSX6mDFgHAnFIz7KzWVyZCYbdWnokzduOMTYnOuPd9sFO4VTTBI/b8iZuYOB0BTfML2sHxEH4z9fF0b6AnbkGxSPeooIXF4/VfyG/c6XcEbPmFwxy6eROy4w9ZuekWyt0JWMMknH7Z4zkjvji0s079fEs8iWzIMA0e+M+S31FnL7uMGhi48IKOwkinW2RC7lWTao0Gc8JYJq5ux8o98ihq45dbV/UHofsulXdvQ2cUnaKNTFBNYSA1dwWFnvJMNDtvAGL1YfiJMqK5uoeYPZa9EO2UvNWkDDRa8m110cmDYeKRyxhsGQxAMZ6Pein5/s+AcLgw3xa/RXXoE17kvYNtT2D4s8M40yLVkENZSRJsbm9GpnBtMbqxbyG9VtgWc/vwwirktEwsRn0c4tBr9HFOt/iWw06OQAUeKusiEYfsPTupwdLGE0XAV1CCPz3MDYMIvMwS/TNPRnqP+eGClxQ4mdm9bbLlUENFz3YEF0GrZ2B5CeR+qJs9/lK/Oahx4jbLFIprnOp/bB4Rp3I+ukp1/2zRQQ4mbk8X97x+pOkCyLCgM/LSbR+ijezDkoT7oi0F0BefkbZcYXEmkAt5csxmUrKd94JlpvURzjkIosfHht0YyaUXDjjUyt1RSeC8dYw+KwqCo7zHCu7du5/3FMfw8Ty+78Unlxhu84GYXBBK/HxHY3BKiqjItbsDIDfTwXhLl0nzsDrqKnlJHuUALpb7nEmzDKvu5GISYLlRPsJEObw5sirQjFNrTZqzuSFxI7364QXSVWzuYRGAWPn/Tm8YSeekM/2FLKeFZ1MBM6Cvh3nGmrDwZI3tYCcBiNa5H87rZlnx/Lbgsq4PF63SD/NNCwq35Sh0xEL4r7kpfXT64e6KgPIhv87GDCdobqhHDJ6JZohmVlHHJrrhNumRnAP/cwb3aFWOFbQKL5SLdhhgWgLf2k64h1itvEkhInPf+8l3d083QrvHQ1jjMQiAtZzEd2uPPqYhZlh0rc0y1Lbk8Aig7zwcTgm/9Jl54HFofrnIkDk5Oh3MhrRjCGG3vNhzueplR3fd6AwKmXzFUKzUrgHNKs+6IZx5qhIyxT1J1xqlvXWZ9JGt1lwY93kAL1chxyQz2oataUbCDmVu/b/6ZK49bUuQ0qHQ+9ruIbNJaIi4uAP5Hn2PUaHDYxanRt/bT8ywsYkMhghq81QFPNIDORDDlQlF6bJD3iqfSYigyecvYPnKXEEl5cUFBIU7VBSdJ1kZwz58SwsxRGvO4P1DkW3keMa2NIZ9Mmaj3E1sZHTRfSD/ppdKzvyW0/7JHk8djQH2R5+3APOUh6lR4YUal0NLQoG8W9cDAmn15EqpmYK5FfG/zWvYytL1LyCAeEgEyeZIbkD+icplfuDVMFpLHgRYtjQ1639j1R1Nn+OsjCSWuSaWvPO3UCvNNSl3/q9V5FHCL4QGVOzs4dTbY68ttUzGUu2bi+LtkFsuKbNTXz18uaqjZGCXfHQLRRpFQUcjmzjCjtXt4XQLMR+rvSWzv0N4aLG/8JayvYurwv4EVujNj1z7FpG2Hb8+brnW7rTtvCRTcGOJNbsxCnVD+Wm+l3Bzfyb/jd3+vzPKbf X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: 592c70b2-073e-4a19-e5c4-08db94276746 X-MS-Exchange-CrossTenant-AuthSource: VI1PR0402MB3503.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Aug 2023 13:41:56.4241 (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: EIrs8EpwfIA905RX9lHHk+G1QJRrgMiPoc8zbebzD6iuT4ShVQOU2ngaUGduAdZQJ6d3CpIveyWE6m5w1jUnuA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR04MB8580 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 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. Signed-off-by: Geliang Tang Reviewed-by: Matthieu Baerts Acked-by: Yonghong Song --- 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 Thu Aug 3 13:41: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: 13340054 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 8EFBA1F197; Thu, 3 Aug 2023 13:42:08 +0000 (UTC) Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05on2050.outbound.protection.outlook.com [40.107.22.50]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C614744BC; Thu, 3 Aug 2023 06:42:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ITkku8WInvNHtFCPJA/1IjHXGbwenSjM/iMS3iKSXqrU1jzKJjhjL3yypGHt1XJ9WCJZ1JvFfTASjD+72UfV+Bbv26YmpvplOk0/gZByCEpFgHdPD1J42NrZZYDKI7iSO9YdkMls/exZKbN245cTjKL6cllCh6yqP380EnslUHJY16BLmRwK88rdbK39Z47uWS2H2M+JFyHqVw0XWjak2lloPMqL/9XkvWV3pkzZpph0L8IgpS0LNsivSf0gkX4ya+N0RbQOR/W+bEGB3/EkCsSiiLrKQiWyMLq7hwF1SM6DpPGPJM2phb21AFEj0ekZS4fgsYW/3+CZ3s5wxSh0qA== 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=Dx+M8Fqse0oYKa9o3jp8WL/D0Da6I9hj1pMPDROAPV0NxomzbpMo1k/BKrVnPhrUW1/Dn3cmF9Ja1t63pW00rP77AQGJBGqY8mV/8knL9JA92j8RejEPx0QZek3iZpg2VyM1zui4LkQoBSFPji9x6iuu8l1nVObimuLEZ41RttT8S5JEjnbsA2YVIKrYfjUPUH5gWUcZKpoKTnEQ49Fr4yOwP1Ug8xcYjvoGwHbwlygbRQJ9Yg5PC4R7IVefkH0fKvHxwtrcG1xomea19ONBDcI7iRqJDKxvtiCMNeVVqMI4Cokp4TJAgSfskHNb1MZm/akNuXo557gCeMLWpznbdA== 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=3X5nvhhNjDhU26tGLl8KCmM8o1+vLP7FnQVbjegRdnuAcyRIPWQAamVLTPx1AyOtykufm5o5xjtRDRDgFOnb0JiGUC0f0w92AjVGOlje/immkM61MnerUDnwWU3kiWKqElewUoNjMYsbWVvJIT0d4siN7AuUv8eCKISpWc+cX5Vx751XEOYZ2o3VMX8WAcX3tsFPKSLYDv6B5tkFLndhmhtxtfT+5h3eq0E1pA9BFPfO8KMzoitwqNMTOzR5b+iUql9nReZv/skQWdbwUHzXd2+hv12oacYGM9kpA9RI8av/D9woVcykGW2bKmK1BuX95ytAvUYwQv/zrear/MTlNQ== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com; Received: from VI1PR0402MB3503.eurprd04.prod.outlook.com (2603:10a6:803:d::26) by DUZPR04MB9725.eurprd04.prod.outlook.com (2603:10a6:10:4e0::16) 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 13:42:04 +0000 Received: from VI1PR0402MB3503.eurprd04.prod.outlook.com ([fe80::6480:1775:c36d:b797]) by VI1PR0402MB3503.eurprd04.prod.outlook.com ([fe80::6480:1775:c36d:b797%5]) with mapi id 15.20.6631.046; Thu, 3 Aug 2023 13:42:03 +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 Subject: [PATCH bpf-next v9 3/4] selftests/bpf: Add two mptcp netns helpers Date: Thu, 3 Aug 2023 21:41:45 +0800 Message-Id: <27d3ccd2d762023b4829ba54e16a3e11925ad75d.1691069778.git.geliang.tang@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: References: X-ClientProxiedBy: SGBP274CA0011.SGPP274.PROD.OUTLOOK.COM (2603:1096:4:b0::23) To VI1PR0402MB3503.eurprd04.prod.outlook.com (2603:10a6:803:d::26) 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: VI1PR0402MB3503:EE_|DUZPR04MB9725:EE_ X-MS-Office365-Filtering-Correlation-Id: d56cca4c-3cf6-493a-d9a8-08db94276bbc X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: oJ2VoOYri/nwzygMAWMhIE7OYHSnzYwlFvvMEfqSqomtrrlik+mUyOzSfgOjzIl3wi3/O5z48JsJZUYzODFfaJxddS9zCtPDwv+spZhPMB7VhYH3STH8RnS2TTdx52LnkAhTj359CoFSX69dRW0OvDapa4elSGI3/s/lEIDBp3edHPuQmbqetA0h06+EodhgZXSTNJZAiBgAFUOsb9mBW2fwIXHlkrzBI0KGXHEbPG9SnvVd0N34RLNeXT1ts5Rdxtwh4Ns+ayFnd8W8Vafq6WUY0GUNMbNY3ybrtgTmR42WriWPYdzmVWuxje69oHSp4+deYI59AHR2sz39rtOg0lQxbMT94kKw6FL8RuUoxhdjh4ebfaR/7Tj6Hr6uWfwflWlR+VxOCr4NgK4tV4p5IoxxGWxhTL0F2bMMGymtAa7dc0V9HV/Ojyve/H0Txc2sq5EnyEpK3LPvjy8KzoH1LFJpoSM/Vz+B10QnPxxj6fm67eSs3/sBzW5BFsePXZlCuuuvfXNCU0lYlwHjy2ZplXM6Q7G6COkAe4Zkid9oGZIMa/e4NACfXxaAjyvsnfVmfc+c6/p9UAf0zRtCiPyDUmFrnSDd9xgN7SxPPGBzg2clLMpecVVo3VBq68E+ygaf X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:VI1PR0402MB3503.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(136003)(396003)(39860400002)(346002)(376002)(366004)(451199021)(83380400001)(2906002)(44832011)(2616005)(86362001)(36756003)(38100700002)(921005)(41300700001)(6666004)(6486002)(110136005)(6512007)(66476007)(316002)(4326008)(66946007)(66556008)(26005)(6506007)(5660300002)(478600001)(7416002)(186003)(8676002)(8936002)(7406005)(13296009);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 5U470G6gR1tesQBYZsOstOMh7CpdWaRMOAPcbEmbDbKT2CKG5H8589BEMbDmUFYazi9SAIDe0evutOktRW7ejAZsMGpEqjJRzhuPvoEOMfGd8/If7IiW41xuiXsVeamdG3lxsbOHX8TZob0nQHNYMbFNaoDVTHRZRxuIZ4+8g4ww9yJoft16OSxeJZnoqB5+XQTBIsDykQbZ+0W8RPL08ipGy2L/qa5JegYrgxZkHQqtWJ/QcN66MJ5rdU5PV9vuV9ocUPIAAFVeP0id89H0kekAKoIXATvo+BP2WGjZJsWXTVvYjGqdKUqMqKS7Exv+r8dc/6eLg2UCxsTmF7/lsaXZvjxSgiWiRRDlZpyOXiiD84QQWW/SU4dgu2Js/tY/2aqcberPXu9H+fVJzAuQkKAAV5YGh86eyL2QR5Z6eHDeB+CvP5iCSetHVZeScz05/t4Wr5AUpSKcfgGB84becRRO49IZVXK0gMR3fcEodyphufX4JB3HiUB/OP8NyIsvIhgwNgQ06oYaN1KzZQII+mUlFtLJoKlZiS4qV5+GKQ7PkZi6dMO3CRyigj4YHElDrKHY0uTTmqgSdN4QqkF9U5f+T+31bBZwgS5z/kl93BaKs/9wkKbpvNXAaUR9u/6xfpPPY6wcRxNeXzDY06n+jX02gtwYgwl6JbTics1tLeUywg7QJIbHqAEHoCg/HW6Iuss4e1znIT5J6BsMK4Kf4WFAbENVXWP2bIAF1D7uho8lcdmb01gEMUGdS31XKxiRFCyX18UPv6K1keeg0BxRSYwZUgaBNl9vTW8yauOudxYiy7bHVejhrapaWqYSFqYJBChxzqValQnhozdYkd6X3d0wvbS9aJ5GvsUVpt28Cnk1NJM5673gCgdikc2kUrV3Z7CNSFhRw9/WKVFjCLUAZe76pLyo9joYss8x2wk7TLPJ3yAJoLmnIn5psQjBIDVKDPU3gGG76ftk9SUkDyf1vOLIJx8+6RcJs4/3pPzOoExZpxLfB9sCoodBDAvBkmZ2Lp1JQ+EQ3Jr3pCO5y97a19AlniMaDHXXjsr5RvUmltlTc1cI5nAcS7gQHSkQjdhJH4EBnu6Q8mxkN994/SAGKp1Eqd4pfZoquDzB+uJvUEQQkS9bkOz0DFqMMDXzN0fRe7bRcYq7RpcA2kjObzN9cuoFSW6w1Kqo2u2bvT7eFxEP7x41QynB57RTPzUW8dLO6OXrMUrX03dZQ0ariIcm5kQJ91QxIyEuksIYHlsQ8BRhl4SEOmRY3jHJ4GsbtlpvnMlgVDk1iJsRuOCMBHymjsuPHqGYq84LB7EzKZ+X8PlOFSibhSoRS9drsiVTArcQOG9moDC0TU7FZZWji/KqVgHOvYX6NDqKJkaDjENNU4jSHCHgTh4QZI6yuu/yDz9PzFi5YFjyChWz4RT5JflOKXD30W09ihTHKT+sZ9ifqk923zvkweI7PBq26zw9PgzAfGDhjHwcxjR/LlpQ40Lu98Wr/gfeI/lYVSo5lvNu2uczhBJuZpd1g6hyvNONRHR4dWk8+1wSq8R1XLQASJfP0ZRj8bdMSAQjiMXcFH430YBce55USsh20kfsqv4Np3/3 X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: d56cca4c-3cf6-493a-d9a8-08db94276bbc X-MS-Exchange-CrossTenant-AuthSource: VI1PR0402MB3503.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Aug 2023 13:42:03.7900 (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: 7q/A8R96SQP56qvWbO5q1EnNMJOonfoUPFGLCalSMIZxpmOtbSE9uMqpx+QmY9Z4RYB3dBWM2ryyd4Cw2yQFRg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DUZPR04MB9725 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 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. Signed-off-by: Geliang Tang Reviewed-by: Matthieu Baerts Acked-by: Yonghong Song --- .../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 Thu Aug 3 13:41:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13340055 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 81C371F930; Thu, 3 Aug 2023 13:42:15 +0000 (UTC) Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05on2049.outbound.protection.outlook.com [40.107.22.49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C81BDE69; Thu, 3 Aug 2023 06:42:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=c1R9x/GY4VImCVetYDf3lmu1EGmWQe3rkXm5FD+BGaLyG5yGCD23HsSLj9BBpZsm5oUDAT/WZCotArLa07YJfk8mA97tOrRzyLFrRE0knHTLQCfjL5ujbKvm4MjsTMQB9aYMpRz8IpXHrub1USXE+tBk3RI6+dDpkShMgWftrP/IdPgunXDuePWu/EjESvQfGbTsMvAmUvvvbo4D6ZOTlcUp+yGKqmj9xxETATFQIoiooVIhBMIucZ/5Uatj/se/9UztjIA/ruOtR8x0QEFkzkriIHzvqD8ZblRSQstgyfIBp8W4J1jSkqT4Dazu96l1UUsNKPhaL51L/HRhIolaMA== 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=M1VBt/JAhAhmI+Q6YmiMxzFmwi+dFZb4ProetOfhOEI=; b=J3OWQE6h8YLe2htfX/1jlvCfAyv4D57813jY7y3/hbFR/olzT8sqM0bG39TCTsTogqxLIVju++Fyx6bE8WI8SO4ftGu1jYTnhjiG5jaDJIObnyg70BqPaYIR5j7VaQoRbhMAioiYtnKCoH1hxO56g4r/nRABfu1jTkWkKU4EaYufAeEdzaUee/vwQv8C5Amnp7vLhd/Hxp1qEK+54W0SVOoHR3ZqtO0EGJd6aXADJjklZdY9h7mMKTAgTxtU8gE+VQ40mGxk308VawNtDs9+eVSwzxVPcUlES+BYIjMjAO48xjDyxUkASuDsE8HeWyTS1naQIurrxYTskhJJTrxtoA== 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=M1VBt/JAhAhmI+Q6YmiMxzFmwi+dFZb4ProetOfhOEI=; b=0I6MdQ5+KrPPAX4kMZp9UjTyDNLwOfAe1ZjQmt5+ROrttRu/EMRpVp/dt7fmkaVPtwE+ij7Wc/AEzoIpaRuCmaZKWJgF0XkE/Ll4Wl7XYvYph6Xqb2rYGN6EenFIRXDX01vjiqAeAdq1ShDk7k5MZFvgKv8BFWpB0vOw1mQ+qFRRDbxJduPLXanU+v2FtzrzvKOIJsxnwEzRxWt9h61Hrq2lhE+Cv8+FcqiwozGzqM8vRg+FlTL/SS/za57BzG3/DcaVlwx11MYQ1VPPYUfGTJIXM3BQLFL71R8GpLBKuhRaUZe3UqBtNpARWsHyY2JxX/Rvda0XKNxC4i0OgLL8eQ== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com; Received: from VI1PR0402MB3503.eurprd04.prod.outlook.com (2603:10a6:803:d::26) by DUZPR04MB9725.eurprd04.prod.outlook.com (2603:10a6:10:4e0::16) 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 13:42:11 +0000 Received: from VI1PR0402MB3503.eurprd04.prod.outlook.com ([fe80::6480:1775:c36d:b797]) by VI1PR0402MB3503.eurprd04.prod.outlook.com ([fe80::6480:1775:c36d:b797%5]) with mapi id 15.20.6631.046; Thu, 3 Aug 2023 13:42:11 +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 Subject: [PATCH bpf-next v9 4/4] selftests/bpf: Add mptcpify test Date: Thu, 3 Aug 2023 21:41:46 +0800 Message-Id: <92ee6be5a465601ff3a2df29b6a517086e87ca3c.1691069778.git.geliang.tang@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: References: X-ClientProxiedBy: SI2PR02CA0025.apcprd02.prod.outlook.com (2603:1096:4:195::21) To VI1PR0402MB3503.eurprd04.prod.outlook.com (2603:10a6:803:d::26) 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: VI1PR0402MB3503:EE_|DUZPR04MB9725:EE_ X-MS-Office365-Filtering-Correlation-Id: 2aba6b0e-e3d6-4cea-c9c3-08db94277070 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: jbM3AFGtLekJ0htcodtwRDk3ZCytajzQsAP0GS2YLI+pmFc4kEXyI1uiHUcbUYBnPFIyk4EYqx/XqQhvAWp/HPDR14Q/YzxEO29GVU+VXNv+EJCkLzJi6SDyvefBMKb4FaqSOnTFtgXUqqeutf0MEG9yFvXl/jALMPLN7Cp+QZBl7nL0Ent5UezGD8gTjnRoy4sRigG0PT7MMiSTeFnUEAxmBSt/baGlIcQddoXxaYqH009IDttMWHK2b84qs3w0iZ/WSt2dTAJSKUy6QLGUOecy6+fa8DWjYBFA383CAD9treZMdbqDHy+hVVYIU/aJZZCh8zKZq+jznlvXka6Mz0dvGhWG9q3RezzZ/oA3n5uw+VP0zhF61dvKPf6TP35Vq/wJgmzYY2dQiLntsy5FZbdPCziOiYkQ5hsJB0UsSX02FPCwAJX3R2dvh25+xOpccK2b9g2eOfwN30Tg9qVGwD/DA8wcgF0QP5jAP2pL2c5hO3mk9IB4x+MgxrRvSmYzubAbdCUqpIoWcVtkAmX3MjSfy0+oOVG7GuyC5XoTVYnXxpUfNJiun9nuHTxCauUktXfVUAJe4BlQVrYFWh57Q9N5zcItT08ZId6Q/QvV5/2jQFTYEFM68ELS3Q7/ehev X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:VI1PR0402MB3503.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(136003)(396003)(39860400002)(346002)(376002)(366004)(451199021)(83380400001)(2906002)(44832011)(2616005)(86362001)(36756003)(38100700002)(921005)(41300700001)(6666004)(6486002)(110136005)(6512007)(66476007)(316002)(4326008)(66946007)(66556008)(26005)(6506007)(5660300002)(478600001)(7416002)(186003)(8676002)(8936002)(7406005)(13296009);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 3//oaDnJB4diOXcxtTTwf9G/K3YcmnxsTGsXLTBmFO5htHKPJP73CTziTp9Aazp0PnorWn0Vw70xaCHt1UlyVvDABLpREyRku3HIbXSBGBGFObVaQYxm9BPCQ+f07jiIWDWz/+6I+fiSqitcnYlzXFfGi3l1uUhH1CfBacIYdD5p9lKXY9/Im1YHiwqDhZQsAy9qHCrNYGcvuiI+fiTVSkiKM7cLYUx7y6y4FpJhGwNSxqPpaUiV8uKNiu7tts0ygKNuGVpg/R1LMlcKc54ZUik21T/Ik+0rwuGepsxWEB6M6Q5H5QYLdmt3GGd/FAC3Mho3iPbdpP1cfofexCv1RchUn1PLvfbf441peqTkunEOtxJMg1CzNX3jdeSNmRkjvQPfrpmx+QT4qsVg77zRLpuhAi/AiilOSxMzP+y7pM4wq6jlOJTaRD8t6K3/kahtD2Qm69MjRNuo3Rnz2FNfKYPwnIntNNcwJ64YaIS6XT7dfCqUq9i0YzfuIB7rVsT0LXkLxS/ej9pVIBWqaHr8BpOdhlrLRGylGeJDn2KzSvS6OoBnpwTAkahLi/g4hmOmxh+ck+W5gP9y8/tKnPqKlZyCBAggtU0v5MsMu2QhJd31oWDmwM2xBVHpZF1LYF2Ib1Ux7fjGHVM7xcAhRLj9qMLwfWSEkYP4wbsy533q3pgkQXSMvzOaZ2RVeWPBlqPiPyo8G6NxJBrZtJTkS6pZYslanyCUISsMhZDFjcOuPKdNk+y6mXuQ96UO+kPTUOcelii4KHpOSw/cgv99GPp4Sz7fBG6kwPuhmRDFVIVIzOLZdQ9MJHVG5Bw8GPguWo17O531tHKaBMk5wI2Q6rvZrRnqEDiXXjSmx6AtgISvpdx/P+L6zUnNr4fG+8X/TGWT74/GRNtcqTk2750Aua+zy6wReV1xP0UsQ9TojOOAyxYVjZiK/qLRuR1NAL8xIWAHEoxCD1E42wTQsOerfFR7dDwJ3U7gRRepLxPE77jznTUF6L8DDPYSlAGKM727KR+VWg/fLvmM0zBdpalWCawcqs4sXys9ZnDKzzzqmPN+iueI9YR4Gn+DLWs2R2VX19B1RBx0qR1JoVtULsT2xSrYEXTuhD+wI38D45RkMKtD6dcMEmrUuCHU/MCoFTTp82cqsr38bnspLosaZpMZPK43QPI9ChoAJbPnOOFdCNO0S+BULKbPpoM/OvtV41uhOfT5Tb+aSueMTli5qF8DFHntLJ6EgvPJTMdFMkxPpTAKNxPyvN2jWeOG/Z9srGqZiUZMtfFPOkCv6irC8Jg4H1pfwxvvvjXQKmPh6KBSW0+DtFUb03kjI5wBc9mE4ZYlFYcH6obfmYf9GfRNKBTjMpm3K5sCbBPJn2AhgY0X1Ryk1YzU8wrVnLmK4msQy2c2YBBlqAp5fbPSJuo5NMpe6gaFgZM/VXSmvBtlKpPrwN805Gdhl52rYl2oqOzMvPeiMLiWkpzbZeeAxKj8Gg4WfmYAd8ujft/SuA5Ko4dAMkFlgjcAkC9SPx/Q2j2RW7251tbfOL0YW0yf5/9kiUYm3KawXTFxuxPtI/FmQDmnO5QCKP+kZNJ6wtVhYJ/fHu0N6Quk X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2aba6b0e-e3d6-4cea-c9c3-08db94277070 X-MS-Exchange-CrossTenant-AuthSource: VI1PR0402MB3503.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Aug 2023 13:42:11.6981 (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: n0Qg+wTLKzG90CW2so01IrLl5nXdfIFazhfODvIUCxGYMqadPuqnDmMVgVoRhfipKnG7EhVM5rQVUwPdMxpRkw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DUZPR04MB9725 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 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. Reviewed-by: Matthieu Baerts Signed-off-by: Geliang Tang --- .../testing/selftests/bpf/prog_tests/mptcp.c | 94 +++++++++++++++++++ tools/testing/selftests/bpf/progs/mptcpify.c | 25 +++++ 2 files changed, 119 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 4407bd5c9e9a..caab3aa6a162 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]; @@ -195,8 +196,101 @@ 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; + + 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++; + + 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, prog_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; + + prog_fd = bpf_program__fd(mptcpify_skel->progs.mptcpify); + if (!ASSERT_GE(prog_fd, 0, "bpf_program__fd")) { + err = -EIO; + 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..9cf1febe982d --- /dev/null +++ b/tools/testing/selftests/bpf/progs/mptcpify.c @@ -0,0 +1,25 @@ +// SPDX-License-Identifier: GPL-2.0 +/* Copyright (c) 2023, SUSE. */ + +#include +#include + +char _license[] SEC("license") = "GPL"; + +#define AF_INET 2 +#define AF_INET6 10 +#define SOCK_STREAM 1 +#define IPPROTO_TCP 6 +#define IPPROTO_MPTCP 262 + +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; +}