From patchwork Wed Aug 16 01:11:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13354458 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 65D50C07E8D for ; Wed, 16 Aug 2023 01:12:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240972AbjHPBMT (ORCPT ); Tue, 15 Aug 2023 21:12:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35526 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240962AbjHPBLz (ORCPT ); Tue, 15 Aug 2023 21:11:55 -0400 Received: from EUR04-VI1-obe.outbound.protection.outlook.com (mail-vi1eur04on2085.outbound.protection.outlook.com [40.107.8.85]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C4B721FFC; Tue, 15 Aug 2023 18:11:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=VGqtS0HZa6bi2SRl4I/pSSRI39GeH0TFQ6Gzy3XDCJqP4M9ygVYJRMumPKw4vKYNPHmaqBA/xFiU5MXJ8bDbWMEebafGqyFBsezU317Ok8F/PFsQR/34l5CFTcdVM3S5JEgtBrXky27GWNzonYtujlENrPNpN2dLHHBkNM97Y/EkXxaWYJRGtCkmeAh4QVtcBXxdcCV/deRdFiYZ/PRNoBM3UZNyxy98cXZOLc/NP4o3rTLWZlVpV+3EeqgXPT4GWZHKQEI2fPdwIV4bJBYBhG3pr1VTCeo4lUPXZv2Q9KysEvZTqXDK2tQONRhQo6B7RqgQSUxmHWsmJFIvSJo0Fw== 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=frsRNrxXxqJadeOymcQavUtRjGEgKb5wlejqmgRLXig=; b=XDFxnp70F4BcbxvGxWX9uFYYxN4zxsX1xjRNHd46XB30UIceiEyghvz8bhdzwHn5bzdTqxlj/0xulqbDIPT7Xmji6Asy+aacZfQMP2/kZEpVctRJVvu8tb/9o/B9enp1JbRgIAZKjHcYhbrDgTKHPbQKrJmzJ6MvJZzkgt3W3ulOS4KdJmD2BnWFxpAR+aLx19q+Yc1poxkkx3IiY/E0iWINDwnx3KKiWC/aRXpbD6VjhwgKUSnHX4Y6q4q2QtVq8+Gqa1d+ioRfMrE+2DEmx/gN3iOm2s+Xz/HEbin0xkh3Ze174mM74hjeNAbyRfjipeJYmM/OqtocCK5AnY64iw== 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=frsRNrxXxqJadeOymcQavUtRjGEgKb5wlejqmgRLXig=; b=qiCmgTQ0BZdaIX95uXj/eqviUP2InTX8DF1TxDee7vHQmnKifpEphFOv/joMVaiUiiw8DZd+fTUJHFKQudf+9ILcIQ8fQ5JrLck230Jzv8jSV4GfU6qJ7xM0U+tTTBspdzEiENtlrMg8l66FqLsDW5oKv8/gXOoyyBEWT6mtJ7oKIQ05PWXunxESj3yvvyB0I6khkIZXP4zMLpCsgr3CW0e0GiE5FZnqjy8ZR82+4gL6fOt+lGy2T7XjF3Fm4VLXvlzHA5Tl6k7E8UolXNZznxPzUICz4j3xhFoe4tDZzPK1pzjmgrrmioVHNg7kGDKchLf+YuJ+UgUmLKD1innyZQ== 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 DB9PR04MB9915.eurprd04.prod.outlook.com (2603:10a6:10:4ec::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6678.26; Wed, 16 Aug 2023 01:11:51 +0000 Received: from HE1PR0402MB3497.eurprd04.prod.outlook.com ([fe80::2867:7a72:20ac:5f71]) by HE1PR0402MB3497.eurprd04.prod.outlook.com ([fe80::2867:7a72:20ac:5f71%3]) with mapi id 15.20.6678.025; Wed, 16 Aug 2023 01:11:51 +0000 From: Geliang Tang To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Florent Revest , Brendan Jackman , Matthieu Baerts , Mat Martineau , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , John Johansen , Paul Moore , James Morris , "Serge E. Hallyn" , Stephen Smalley , Eric Paris , Mykola Lysenko , Shuah Khan , Simon Horman Cc: Geliang Tang , bpf@vger.kernel.org, netdev@vger.kernel.org, mptcp@lists.linux.dev, linux-security-module@vger.kernel.org, selinux@vger.kernel.org, linux-kselftest@vger.kernel.org, Yonghong Song Subject: [PATCH bpf-next v14 1/4] bpf: Add update_socket_protocol hook Date: Wed, 16 Aug 2023 09:11:56 +0800 Message-Id: X-Mailer: git-send-email 2.35.3 In-Reply-To: References: X-ClientProxiedBy: SI2PR04CA0017.apcprd04.prod.outlook.com (2603:1096:4:197::15) To HE1PR0402MB3497.eurprd04.prod.outlook.com (2603:10a6:7:83::14) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: HE1PR0402MB3497:EE_|DB9PR04MB9915:EE_ X-MS-Office365-Filtering-Correlation-Id: 2e47aa61-29ab-4641-5c1b-08db9df5c56a X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: VmdO1CSLQ8WKnjv6qGVt/rkZjawcQkjrE/OKcNtN3RjGGW7OYJUKUoXY9Zr15T4cRmij/b1BQo+hD3tnxzMbqX2ySh1WrAhKGEDe5Zn6tNOaPG1rrOcFyl797XSyZjqN0i28LQaYKSukLavvJIBhh/ZAMAKJDyCDcJ3NhCyQFeRyJ+97FrahWM1vJzkYee5DM/qds72R2uSDE3bQbw7F8Ycccseym5ducC3l2+EyudxvkVGUhJg+l5PPuYsUoRD3a2TFsKv5F4Xp3H0rWijr7ocZaDeLVupPesA5l/xIH9Va+WCLHSoYnYtxBC0jVS4U2OGt2X6IpozWUiimBwsTeIt+ZLrIZ525fy/vZxQgtyf7cZWcjFhKkKeweWpFMpRkdeqDcDuitH3xNIuE1/q817H8bZ5HDEkte4AH/By7xHwH6gB9KVjcbRXog8n9j7QJnkORgrx0KeuJyoM4LnkWPo0IPZrT2glyhhXgWIYo8o9012h/JVlt6NUCBYvcehfn/B7m3O5bEkS6fdKsNWJFZ8hqkAxRvpNUDooXDO0x/8H9rJV6HvwvqsUvnHHUIq00IJqmM28N+QdjZ4CFWindE+XRZdUDpq06TUUqp+xgq7nUpJ9OuHJNs3SZA1jIrY5s 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:(13230031)(39860400002)(396003)(136003)(346002)(366004)(376002)(451199024)(186009)(1800799009)(38100700002)(36756003)(86362001)(921005)(6506007)(66476007)(41300700001)(44832011)(26005)(316002)(4326008)(15650500001)(8676002)(66556008)(83380400001)(2616005)(6512007)(6486002)(966005)(2906002)(478600001)(110136005)(5660300002)(7406005)(66946007)(8936002)(54906003)(7416002)(13296009);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: bOIZE0GkhjehdedE7GcJLJhMcDIWftwAm8Bde/DJkYFEslckHNeP7UwPf5JWU1J3Vrfo4NRLcYMJC8UjeRrwMBf7ACPpBaZlthc8zoclSs3U73UwfMx5xL7RFp2FBi2wEyhkBLo4oWEm/wpwVsKci+OQtR+0A4MQdlixXy8m5cdNxb95f/0lo6PNGdOVzeeliOOiJpgRtqZL7trx+gI6mc/FlwLibM9onAmQROK1tHLKyuqTqLvsKMwsUldteoRA6KZz7v+pVtPtfqezU9q1bqOkz6OmgyX3VRe/cKHrvJN0wXh2UFzGU5o/yb9lUwz0xptE9aK6eJ0MzmLc9NVe1AOnRFP/ItD3ynqNhul+Q/u46fxSDnLLnR8O/2iiJZ88uDspJvynEhmSwATDwAR5mq+rwn1kU1wAmkkJtScPHkiG8phLEfH5aT/bUT/EBSIH/hbsnVW2kuyqxdhqGpWQfnBakMbeES3cTm+iJjqWdCfNRbGQueeZjQVjln7fFtRIkhqZt64gXMyDBK8LKAXJtD1ibVxeN4xHjq6+BGbB9ivDoK6WV7mnxec2+pDVmSk0UDMtoOYDwPDEc+NK8GVygtpBZWad0Wzit8ZNzekBYXZWATMtXmy5TTILy250LyRt76UlbwBKDxH/0EXj6hmmFVaq2RMr35ERqeYqQwfmtEQcLqd/2iKz3qQ/ffPFlukGaWPcUKqDBX+HEgK7DOgc8N7oRngvn/OrtOrSZ8U76ATyOkPnUQAQ1Va9FACHnoIY2+5B4cO20IfxlPwvBaTHBu0+Tly/qauODWOy+HCN5KZbR/Js2HJ+zcMAQwdxRabCAZgvK9wJRecot+Xk/pph8pVl+yisj9eR6cmfrEaYG8NPohuIU0tJG2Lp5N1IcqhDj4UF1dI5XU0X+2KX61wRC1HAG4wICKFqEX2ofaIs6U6EwQ8mn2KJ9xc1PmUxb4nXqOsO+hALkIn9Uofl4UpGidQ7jyMSlLgbi8UP9/arfVu2xgC+0Cmt1iDCfkG5hxGcALK3q3XLgDZtKkJPtuGOdGj/HSE0KlnFkYYEeTx4P9vv1PqKQyJu7f85SToIU1WdKjEan+2oex2L7Wsn7AoGa8BpXfzqaO1gFX/bYG6QStbea8mTdPzXemgk12cji5+EenxU+AMtBD5iDG9IaVMr/IA0Q3Pderd4OWd1rOv4J3Zl1n4dIhPEAhqFZ3b6TRKEQPYuu+BjNfg9T7qeX/bw24G66jLWqN5J+s1pi+1lIrncqH8/r+yHYXMa8mUXucMsox3ke/8f4H8yW8cuO1SOBEdiFcC4pyDa5ctDoIOlDDuHYQSu+94vJpqLu416CrM/BuQJGbgr89EE3XNRG0xOCsdv1vVvJKiqQTcPjzKvGqX3Ym7KN4V9t5q+5U2oOw8oxslZa0Kdhai3k5zgjJ6gxzL6hN6LAInEY/r1zxtaQ/azruq5BWFEuMqxj/T5YhaQQwYh+SeL7yfID5Fj6PBdM5ViFNGIE5A35iJbG9P5dFtR+YA3aNC+Ztqee/4yMQ6IYX4ZSW2pGDw1olvGMbZBkgJ8NMxgq8BAyAt1CtlI10Zciu/qV8KMF9X2Vgwtd2gh X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2e47aa61-29ab-4641-5c1b-08db9df5c56a X-MS-Exchange-CrossTenant-AuthSource: HE1PR0402MB3497.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Aug 2023 01:11:51.1031 (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: oqnN1y66G4BSx7Pk3mUW2rsKjN5HUTi5UuAvjERoA6VmsX/ZJfN5xPv2SU8LGaWRdSmkGkREWN9iaewyP0KMnw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB9PR04MB9915 Precedence: bulk List-ID: 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 fmod_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 | 26 +++++++++++++++++++++++++- 2 files changed, 40 insertions(+), 1 deletion(-) 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 5d4e37595e9a..fdb5233bf560 100644 --- a/net/socket.c +++ b/net/socket.c @@ -1657,12 +1657,36 @@ 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", + "A fmod_ret entry point for 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; - sock = __sys_socket_create(family, type, protocol); + sock = __sys_socket_create(family, type, + update_socket_protocol(family, type, protocol)); if (IS_ERR(sock)) return PTR_ERR(sock); From patchwork Wed Aug 16 01:11:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13354455 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 86A26C001DE for ; Wed, 16 Aug 2023 01:12:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240966AbjHPBMR (ORCPT ); Tue, 15 Aug 2023 21:12:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36200 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240972AbjHPBMD (ORCPT ); Tue, 15 Aug 2023 21:12:03 -0400 Received: from EUR04-VI1-obe.outbound.protection.outlook.com (mail-vi1eur04on2040.outbound.protection.outlook.com [40.107.8.40]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E8B0B1FFC; Tue, 15 Aug 2023 18:12:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=GaRFiw0+7fIeCxPPwp8VBHhL+Pe+OcaSOH0JKcjzrBVQvuVOybw3AUykxkErzjXYOJrtEktyQD0R328eWUs+IDYFrkf61ASlVRCfnNuzJdbbHPPcxaJJDOXRyihIT5QPUC9i4WHCaqvJBO6dITvc12Yv3hWwmKIwi47M+szychSrruZDOsH2mg+Yc80tGqibWBFSPyxgRE+wX2+mNQqPD89KxjlvjENUnFwQci0FWNbXQ3Gf+ngylvmnPmpFBkXJDMAiNt9ZWhkQjkwV79Et/tbTlshe1+aDpUzVDlk6ar/vv25KCSlToyqSGK99WFl+WTEGyiCS278IlWni5ZyVIQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=zd/8kfPIc8VH4juBd//fMuAR8mCKogVt2f5lxjDZThw=; b=mQ6/VdBzMvbHFAI0uvz1KkfVt82kAUQpsATc0S8rdKbq5UVysc89LgvjctabJqBbjeOGQFqfbSiORbmvd9//v7EpYOcZwe6iHbzAJgF5M8IIcFtbDadd8N+fGjXUccaoVD2i+RTgd9iscPAvINNenXTjCTJA7E1H6SIkOu5TX2noLaIPh88nDwgvz25RJahOZCGR9t2GT2IYJBM7v+cYTupNRUZEsGhpyCEo8141DKvaP88eSC187EFfymHtDh+wMHhERZOAD6AQE/dW3foB0A+CTaCToZuWyjdjjdqW8KkbI60hrQPhLfAe89nTHA3xzJH9Cxn01o6DnAHmzim/fQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=zd/8kfPIc8VH4juBd//fMuAR8mCKogVt2f5lxjDZThw=; b=U0CKiJDJi8IUCb30s4gCdx0t98dGzPp4NT/UMYGZYb+mBMMxeYxH2iZ+57Y6AIQZiJdLRHUhljWmmJICee4egOUQb9nP7PKhoXQxqCsVB36nuLKhAnhwVYzK42GQ6EqlQGVIdBiXpsWx0pVyPfXuB5QxEExtt1HtjT3tgfb8v1rEFc2PFP4i8tsBQSEsgehuQP65G8Wa36G6bY/IVZW2T7uTC213dM37cBwtqlIhOw15hDzhW0pCRynkcgMt20dwpkbpadtc5PjUVOR8GaXKanXIeb0sAKrJi5fSPIdTX6O4MhH1rd7zCRb93pmQCROAAX4ku6t4PirL/gpr0NdT3Q== 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 DB9PR04MB9915.eurprd04.prod.outlook.com (2603:10a6:10:4ec::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6678.26; Wed, 16 Aug 2023 01:11:59 +0000 Received: from HE1PR0402MB3497.eurprd04.prod.outlook.com ([fe80::2867:7a72:20ac:5f71]) by HE1PR0402MB3497.eurprd04.prod.outlook.com ([fe80::2867:7a72:20ac:5f71%3]) with mapi id 15.20.6678.025; Wed, 16 Aug 2023 01:11:59 +0000 From: Geliang Tang To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Florent Revest , Brendan Jackman , Matthieu Baerts , Mat Martineau , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , John Johansen , Paul Moore , James Morris , "Serge E. Hallyn" , Stephen Smalley , Eric Paris , Mykola Lysenko , Shuah Khan , Simon Horman Cc: Geliang Tang , bpf@vger.kernel.org, netdev@vger.kernel.org, mptcp@lists.linux.dev, linux-security-module@vger.kernel.org, selinux@vger.kernel.org, linux-kselftest@vger.kernel.org, Yonghong Song Subject: [PATCH bpf-next v14 2/4] selftests/bpf: Add two mptcp netns helpers Date: Wed, 16 Aug 2023 09:11:57 +0800 Message-Id: <7506371fb6c417b401cc9d7365fe455754f4ba3f.1692147782.git.geliang.tang@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: References: X-ClientProxiedBy: SI1PR02CA0033.apcprd02.prod.outlook.com (2603:1096:4:1f6::14) To HE1PR0402MB3497.eurprd04.prod.outlook.com (2603:10a6:7:83::14) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: HE1PR0402MB3497:EE_|DB9PR04MB9915:EE_ X-MS-Office365-Filtering-Correlation-Id: 4fce2d63-8188-424e-0a43-08db9df5ca42 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ukqh0EsrO1oXRvz47m3jObHQ4HatP3bWi9R7WBM2wJHs7yIp+0dmFhmzls79xylhi9sMRof5QXPn48pHRiUhv7xCmBbgPF9gS7Nc+0FyYbiyRe3fwdC/WjZHwjA6TKgfbn7NQSInKufkbaj7n7gzgy9486tdVFf6M+o4PJLGvKzsbpN0P3kEX3A10Alf/YazEZ8AxWV7i2L29VBj30M3L9lxkJhAO7A7A3PHBkLD5EOqmO/FIeGy/mmSHq0rgAK2Ss4wAs2ypzIYfglgjEGN+JI8i/5O0L9h5VAdpfIAYBM8BUqP5hEsvh0ssjjYZzdcJS5peL7+bIJx9VovOvw5+ae9zKZVJ+YLUOGcj6+Vftyschp+x2K9juP10LEzy9BlVP7alDhoOk3pJBvorIz5YEx1lkL6Zjgva1JmfR/zVPiROBQNBXuwBQ1w+7F6pF2bsHXLcCwK3y+Zz81OhAN0S3ER3rip0qHTy5vxy6so0xcyCGutpUv6TkoFdsn3pFD14w1Dfqb4agcvl4UhQOdAh8gT01KCESdsoVd9Ewfo0751THXBYqbHb8h6bxFec5yIk6kYOjesPfB5iRuWhQC1LmktHhPippWkQaQagDm+ilxQtd9EoPi2AjcLV9s/ykaM 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:(13230031)(39860400002)(396003)(136003)(346002)(366004)(376002)(451199024)(186009)(1800799009)(38100700002)(36756003)(86362001)(921005)(6506007)(66476007)(41300700001)(44832011)(26005)(316002)(4326008)(8676002)(66556008)(83380400001)(2616005)(6512007)(6486002)(2906002)(478600001)(110136005)(5660300002)(7406005)(66946007)(8936002)(54906003)(7416002)(13296009);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: F+fic9LDECCub3swJ+HSR5nncVIhON3QTG5EgO3AGAKdc7l1t5JEgi4E5AbIlJBXNUSSnrp5/0JJTcSXGKA/KHRqy9ibETSWB8ztY5XeMyPGZ/dGEcbplMhMjyM9YRS8YVWBFkgMKKnDYm0fAgNvwOAycOcE6VaC6U5za9aK+F00uNfgnpTvPu1ILilqAtcmyIzdjzFKAx+lXGZkU+rrkAw59GO/Vw/i6ZCKoMcKyGmlcmBPypx0Q1VM1zsFRLgqT+PY5WL7uhwnx+4rW3Tl7B38VRxpO2m1wapZE8g/ZAhODCvQg9f1oAOYNWL+LYP7M30wcIWJxFBFmwNVfvUaKanv6gQnU9jQGP/h0FfJZDMD5MV4Tj0Px90fPzPWDPTyvDUo/aM8OVAnk2dck/KWCsgy6DMLiarymUCTdWmqb2xUDxVgiEAiLgkAgArsG0WcT36BM7jim03BuuKVtNqvuex84BIEn30vn+AEwTpPmNzC0ymn64yDL20vSU7hR2rxEe9zwxFCGRqTg1Y/lQtYkDZbg7HbeFmeiWq3eE3iSpm6QiOz7Bb/llmikiJtUZWk6uV07MhvSoFk663TqND2R3TwQUAZMTtL+Bvvxw7Xe0p4mmwUT47aoJBRCNp9NmsLXwe9xPhmtQer96SCGbXctwtJwbFDV1d0nltdPTx83I+ZHcCPCPDtyGi/T8RMHKODXnXXvcRHNNRwod/bk8gc9N5d3z6Q/fPTirbwJ0KfohFCFKVK8VUB2gSZn1jMtBezJ01ymaL70CIZajJOso0E1vGW6q+VZFThNn6aOFW3ILu1ICfoh26s8NmfoR4g0p9HtT7GILaGCdp+xD9wXJSOb5hIXPtOOHlqTEk/S7WukOCQOxAlDLN9cC/FeUzcoawEfXMqlW3PNZTlPyduz3mOvt+ZmKL2kr5FDMvn+TzXPLt867vENbSieXdX5gbHO6fZ5bfBFRTihy9uhS//V1qtL6QgJYnbIZWcHmIjkn6WDBFJ5zUzTOzFwdwyfotI1R43HXnek/Pc6BG0KNjbOI/Tlol04hNYwst/hwe++//3HL9vaYTDpKtscZOKup2yH46MzlmHyE6ooZbqw4cGRH+uo8xNmcGBhzXQvBlZFpPidlPrVdiZC9UAHwZy7oExCYehhomMP6h4yb6C1Gwv4OZsHeEgvnKASNAzmIEDyyUBTwJscRloGWW4no5BRUep0SJx4o6Uc9DLZZC5McqlGyxUyE3cGvsAOIc357j/wmATan6opV6n7dD2NfX43C1ZuGex6wAqPWqyD3IMrxyk26gVHW6DODY12O52KV+u0sh60nMQ4bY6IT+34nl9Rg3hI/tXVRMF9TLVITKoSQqUZZKJG4rl6Mr3GWdARuaB8V+BOF5xijA7MnwqMGVd4Zi79G45rLZ8EuhNSoUbwhsdwjDrZvVxwgwlzEVt3WFsdB1hZxNiIiHT0s3x/EpnLYWR9X1zAixY2uAUD7ykEwiLXdci+F4jnAnxPKetQ4U8bpko78Yu303y02C6sqDcMErJCTK8Kfg6G185zGSrL2fikn0sjGpEFtOJs8AaKpkwQ0/SnH+eGBZGfdzy6r7ZydXVYykg X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4fce2d63-8188-424e-0a43-08db9df5ca42 X-MS-Exchange-CrossTenant-AuthSource: HE1PR0402MB3497.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Aug 2023 01:11:59.2941 (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: aaup3K1y4gv50yDvdmg07aDCH6RZQRuDRyAo5hoNMacwQAdQ5CuiLA6FwXRHiH1KgQ8UKMKllMFnADxcSJzv7Q== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB9PR04MB9915 Precedence: bulk List-ID: Add two netns helpers for mptcp tests: create_netns() and cleanup_netns(). Use them in test_base(). These new helpers will be re-used in the following commits introducing new tests. Acked-by: Yonghong Song Reviewed-by: Matthieu Baerts Signed-off-by: Geliang Tang --- .../testing/selftests/bpf/prog_tests/mptcp.c | 31 +++++++++++++------ 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/tools/testing/selftests/bpf/prog_tests/mptcp.c b/tools/testing/selftests/bpf/prog_tests/mptcp.c index cd0c42fff7c0..76afb5191772 100644 --- a/tools/testing/selftests/bpf/prog_tests/mptcp.c +++ b/tools/testing/selftests/bpf/prog_tests/mptcp.c @@ -22,6 +22,24 @@ struct mptcp_storage { char ca_name[TCP_CA_NAME_MAX]; }; +static struct nstoken *create_netns(void) +{ + SYS(fail, "ip netns add %s", NS_TEST); + SYS(fail, "ip -net %s link set dev lo up", NS_TEST); + + return open_netns(NS_TEST); +fail: + return NULL; +} + +static void cleanup_netns(struct nstoken *nstoken) +{ + if (nstoken) + close_netns(nstoken); + + SYS_NOFAIL("ip netns del %s &> /dev/null", NS_TEST); +} + static int verify_tsk(int map_fd, int client_fd) { int err, cfd = client_fd; @@ -147,11 +165,8 @@ static void test_base(void) if (!ASSERT_GE(cgroup_fd, 0, "test__join_cgroup")) return; - SYS(fail, "ip netns add %s", NS_TEST); - SYS(fail, "ip -net %s link set dev lo up", NS_TEST); - - nstoken = open_netns(NS_TEST); - if (!ASSERT_OK_PTR(nstoken, "open_netns")) + nstoken = create_netns(); + if (!ASSERT_OK_PTR(nstoken, "create_netns")) goto fail; /* without MPTCP */ @@ -174,11 +189,7 @@ static void test_base(void) close(server_fd); fail: - if (nstoken) - close_netns(nstoken); - - SYS_NOFAIL("ip netns del " NS_TEST " &> /dev/null"); - + cleanup_netns(nstoken); close(cgroup_fd); } From patchwork Wed Aug 16 01:11:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13354456 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B5FDEC04FE0 for ; Wed, 16 Aug 2023 01:12:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240960AbjHPBMQ (ORCPT ); Tue, 15 Aug 2023 21:12:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44528 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240973AbjHPBMK (ORCPT ); Tue, 15 Aug 2023 21:12:10 -0400 Received: from EUR04-VI1-obe.outbound.protection.outlook.com (mail-vi1eur04on2070.outbound.protection.outlook.com [40.107.8.70]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 97A012117; Tue, 15 Aug 2023 18:12:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=NZQtMumjOHm+UXx4dlpzP82l7oNpgAXdkQw4/mw6PiwG1O1q0O/jiROMw8qSRjnfFvfbbfZHPY+pM/0mBMkcyaO2C/8UaMr6DZmyFeNMclYgl7U/hlQEmZcO+r6X7FvH29KsZ+oTTRHsar8u8zy/Iz51xb+WlA20I57KE6+zCTowGOsrFePTP4IUB9//2jLyXv5rb07VP5IzslveLffx/3lonrpuzdiSXSDR6XuaI2/nks/9kay6mW9Bqhkt2kJFXcQTETjNSicBzlHET0hdfWRow2m7thC8gC5fm0KAe1Zbst1OQRCqXww65kQs2lqULjJx2BBdGiPk2MKhSUXumw== 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=uGHSej3ss2wDAQRc9IvguNqyne65KXqEapCB3K8Frws=; b=X369/m2Vj47nWgP8wZpoAUvri5pP7tWRDg2bKihxGYd+Qbq3YHEAfqIJpnSNI3insU9SJOF/IZbU1wmYzbit0/RzX4kJdq4Ud8hmPkvJQc8MexRY953nBpjBRejZwGHsDoVMFd3agn+gODOI4OSfWnFF72CMaXn7EjTBXc+x6z/V6ylPsQt45/coS6F+cyCVdOHSHKmgxKXZPMxoLYZYs5ZH3kgkySR9qQbIJiQe5TS7XZoFZBKFyp7YljgNaFAcWBxhIq2PKYlAvtm65l8pOS6UcaU1Y4u1D8nrtEwrDapF621JcjJAB8VTdiY+ntXDcBvd2tw7O47uz9du+vfH1A== 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=uGHSej3ss2wDAQRc9IvguNqyne65KXqEapCB3K8Frws=; b=pUy3/yh9UtZ4ChueRiwYNwnxKhNV5q7cD8p8uswY/gF1dWkd/au19B5GKCa/2H5nCKXc4FwRpoLUJd9NNHb6oP07Kx+j0l8h6ddtyrW7PJpbphCTmWDZzutHTLApWxva53W2jM0C74nULvJxLfp7tugd4c1SwOLCOsYuvezn7iGtVXa8TTmdi91Xp1KvQYZMwFGfRG1k5dXzwZ+nL55o+aBRdtWI3/lMdSTkUzhDTKXD8o3c8aXLRlB1WRc3FqtWcFKsRYlBOcxc5YWW1MPotl+3JaEG76BWS6ruZBfEKxZ1JYoPzwQ0bQl1cKLSXSDtdlzL3k3cQogtJywbJc05xQ== 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 DB9PR04MB9915.eurprd04.prod.outlook.com (2603:10a6:10:4ec::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6678.26; Wed, 16 Aug 2023 01:12:07 +0000 Received: from HE1PR0402MB3497.eurprd04.prod.outlook.com ([fe80::2867:7a72:20ac:5f71]) by HE1PR0402MB3497.eurprd04.prod.outlook.com ([fe80::2867:7a72:20ac:5f71%3]) with mapi id 15.20.6678.025; Wed, 16 Aug 2023 01:12:06 +0000 From: Geliang Tang To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Florent Revest , Brendan Jackman , Matthieu Baerts , Mat Martineau , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , John Johansen , Paul Moore , James Morris , "Serge E. Hallyn" , Stephen Smalley , Eric Paris , Mykola Lysenko , Shuah Khan , Simon Horman Cc: Geliang Tang , bpf@vger.kernel.org, netdev@vger.kernel.org, mptcp@lists.linux.dev, linux-security-module@vger.kernel.org, selinux@vger.kernel.org, linux-kselftest@vger.kernel.org, Yonghong Song Subject: [PATCH bpf-next v14 3/4] selftests/bpf: Fix error checks of mptcp open_and_load Date: Wed, 16 Aug 2023 09:11:58 +0800 Message-Id: X-Mailer: git-send-email 2.35.3 In-Reply-To: References: X-ClientProxiedBy: SI1PR02CA0035.apcprd02.prod.outlook.com (2603:1096:4:1f6::8) To HE1PR0402MB3497.eurprd04.prod.outlook.com (2603:10a6:7:83::14) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: HE1PR0402MB3497:EE_|DB9PR04MB9915:EE_ X-MS-Office365-Filtering-Correlation-Id: 8042bbb3-973f-4f51-811d-08db9df5cee0 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Q0NIlUodZQmT4iM2b5+6+JhLvW/kOLORXqqJuDGahw2xDg0luivYvgidbB+C4Gv684ZqDLDqKCCIsg3926GZuL0pQ0iEj64Rarn+yX7jRTlca+u5yPvYLuhMVPWsT93fmjsVRPkqJaJjbLbEy8NoEMrS78UQpb/XkPBPvoUynP0UtLF/I3V/VIkatCW6rlSu6JiYRYgED3Lhs7f7/lZgpGD4EeNyiJMk5YWHXzTlcEERJAIngN4PmRQ9gODtoIHfH7rnf5Ie6MC9bJkxOPfex+xwmuyTmstmgNAVG9TmYy6yx0WSkahjJNkhwhU05giUQ45+vhamjCHJNPMiwtPmEmfms4HmZ6EvgP6eUyYxuyb3ZOcoXZa3VMQqI5YsaiVETWrqxuP+hy2IgKxwJpbMqP7ESA/RMXj7SVaXzpVzX+lBtpNYhiMoPkDmbhdWZjedQkh/vx5dKTAj2OmUBym8euu7K7n003wsFM5dwXGIgC51kJKp6zyyEDRUvlNGAvQIkjwrQCud2SPNrhK+YGWeSQPY+RS//iy1gWAfyn9dDqUdj6STwaOC/S32cM7TALzdkWPKVlgaFM0psQtBa0LSF8up9a+v7Jrf35z87JY0qx6Q3LwaibGbRkz583hgxWKT 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:(13230031)(39860400002)(396003)(136003)(346002)(366004)(376002)(451199024)(186009)(1800799009)(38100700002)(36756003)(86362001)(921005)(6506007)(66476007)(41300700001)(44832011)(26005)(316002)(4326008)(8676002)(66556008)(83380400001)(2616005)(6512007)(6486002)(6666004)(2906002)(478600001)(110136005)(5660300002)(7406005)(66946007)(8936002)(54906003)(7416002)(13296009);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: hMZGV3I66ztkUju+VRoHMFFzzip5LxO151JK1JQQawkfvinIC106Vezcooe7IDenJrfCc45cEOTaobI1Q5MLG/wYrYtd31f+L3gm7rzXuLmtWpWOWWrraiQHBuQppCJyfMO5FQdHLhkbiCxWQ0AmZk/PZnhZSYqg4ga5YRWi1uClNpw+VdD+J6MsmVkbcAVuDg/JGbgvZnVbeoCOWCeyE38oRHRYqg5/DybRfhujSw75JkaZkGyghr9l8G3XjRh5D4kOIEQHMBCan53Ip6R4LxVVgosEXHo2p3r0RxDCG1Wou3Um9WtsI72GIdDjQPGOQdZNEK1yaaEZS+Xz4vprqh4sodwCii1BMeVmITB66uuNIgwrb+1IuyWbkRuzQTeKhnxDQMrZpW1YFSaEhR9J2tj3aOSfYMKy8ePsO2YFbruRHMt+GV6xEirQQ+5fgC6iSk1A53ZTv6Ry4NhlOEjGt65eXw3ApTAjr+iLY/OJhKCRk0LjaG3RYmzXeBkiVAYZPRZTLciYX2RordUTzVQ6KtdsL3QS1bta1dcJkIQEq3CMBJNyFb174fXxnZI4amw+e0ES/yFYry0gGkOPsyG3xMeOU5bvW+82Jt2w0x3ATyShJ+skc88N5QNu8Ld23C9TT+P6cM/FIeOhWu+VltiA4Kl53K2FAcSG73GLpKhgtmJgr9EKWm4O/L2n6W85Bchr7JxToOkaecHf8AOazkqPRl8bO0KPfkrQ5UOh0SMMu7Q2TBO0dKam59e2LxNrW//2LS2og7qk/sqx5Cgux7qSWkMBVqOzW6+f16dKCDIQ0wP3agM3LEVp6sJMNlfy0t+RdlNZL0RSbKaE6g6lcKlZ0Uq9PpKBAI2jtmOOppN/6gWYpyBU1RjqjvjwWNlWlAepmzQboc0rrpoVlk0FYqXDAiWgHnUWmv781s9OohfIugvbTuImmzAQCVCmkDisbs8fVrQDFVP/a7Cc2OzzM4hZeP3/N4TZ9Ik94C08CEhnzuWm5K6YXKvw5YJO0Tc+7tcsvzbOxokrCO6QrqHBC6Q/QaPtvwmokWIv2UFBdF8TQhpuE7352NnLR2s4dhRJgk4hAJSBS+9wLWPZC3fUoFPHnyRME+LUAbO0XPST81lL9cKJsYtvFOK+jydyazOU8Lrg/i25IHQ+W3iI2rqQzIvI4kUmhO4vWVPqPgdgzNxgH13/HQndpPLt4LOv/Ap4lVqfLvhBvVszXmuGcWswa/LIgl85hY3GwOl8ohiCH2YzliJyt7SNOAt3zsmwnAbmtMfBUgu6S/DO6CvHl56clzT6TZd1B23tS++Hy+2OLHcO3ULN652JQIliUIQIXXxGmisHoTu9r3+H/IN2+zLGzXhafZ8TGvoWtP6BFAIfwIhkpbIXGQI5qWqSHNmVeVyaq4aqqiCGiMvHc8nuvJ6JB8p8uFcL4SIX3DGA1U8wF6HU0mX1cj4zq+HIiX+EXoK4thk15GqdUucglO1WBMlCdEl+UcaONewppj04JsftLrGoipppiU3Lcgv6XHc7nUMv7oPLoqLNUJU4JUyfwPpSPUTACdk2Wu6mBCRJcaKH3aXWzUYbrU/q7vs9ryegECfwvY86 X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8042bbb3-973f-4f51-811d-08db9df5cee0 X-MS-Exchange-CrossTenant-AuthSource: HE1PR0402MB3497.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Aug 2023 01:12:06.8024 (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: qoBchx/DMiIBRZnD2rT9s2tRTbIg2w+l2FK4QpjVVoAKychjZ+pL6rpaNrPqVE2wgg81g+2rNVNtvPX8WfcIrg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB9PR04MB9915 Precedence: bulk List-ID: Return libbpf_get_error(), instead of -EIO, for the error from mptcp_sock__open_and_load(). 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 | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/tools/testing/selftests/bpf/prog_tests/mptcp.c b/tools/testing/selftests/bpf/prog_tests/mptcp.c index 76afb5191772..3d3999067e27 100644 --- a/tools/testing/selftests/bpf/prog_tests/mptcp.c +++ b/tools/testing/selftests/bpf/prog_tests/mptcp.c @@ -118,24 +118,14 @@ static int run_test(int cgroup_fd, int server_fd, bool is_mptcp) sock_skel = mptcp_sock__open_and_load(); if (!ASSERT_OK_PTR(sock_skel, "skel_open_load")) - return -EIO; + return libbpf_get_error(sock_skel); err = mptcp_sock__attach(sock_skel); if (!ASSERT_OK(err, "skel_attach")) 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 Wed Aug 16 01:11:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13354459 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3E069C04A6A for ; Wed, 16 Aug 2023 01:13:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240969AbjHPBMr (ORCPT ); Tue, 15 Aug 2023 21:12:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51354 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240990AbjHPBMW (ORCPT ); Tue, 15 Aug 2023 21:12:22 -0400 Received: from EUR04-VI1-obe.outbound.protection.outlook.com (mail-vi1eur04on2073.outbound.protection.outlook.com [40.107.8.73]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AE1362121; Tue, 15 Aug 2023 18:12:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=K9Yvy9kgrwTZ8s5SUD6WAzECtfCpaMjq7KBWetpax2ik461OqIW/Zx2LB5u+dBzLX8wVrU2zpw7+gHoydTGGqLTltIh1rfnxAejW05H7OtKHmkyOcEsYfHkr7bZ1OkbvgVXTzR1/RqvB8IQxbLZgJilBUpjtyC11M99kfya0fYeIeSHxqaQdrhsE9MO38cpVu4JFn4Xt+5Gf+oMoIuhURqqcIEhDTBOfUTKn8rr4ht9BjWCxGLBvkPStgAIobaHY3sDYAh/nATlbRAD433QShRp0QRfuycMoUaazifPC3gYsS63z2Jzw93NYXdL178fzd8IRumaH6fcHJlkcMexjBQ== 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=nf1V/AFdtZNNUo5XybdRlY7HYjxRFoa3VD8beyqYfcU=; b=YxtsgIH+ESmtR+ZcmKXSYV/QzByHZn6koYK2OvShQ0t5wcbcKrhfwNJFTE03kvXtB/tYL/GObhgwdGaBvGkBemrAX50anKT6Nqevbgq3ZwYnmEGlsp2GKiOdZFK1UNBY4HpOeJ3j/Y8vxCphaHt78so0YJLgo4GL5inJQ3zBTYy/3WKATyw7KIRsYLE4nFfmsyh6SfRjKPOIC/Ifot+7itgGoiUFT9sd2bXTMeHylsF67+szCNlgp9QzxCBywrKcZOMqhH6o6e5+LgHbaeB9IUJp874YpmVVh+UxwKbV4DU7bw2nTYszsJJR5bL8Q2VNkfk73VicLrlk6FWFnoD2Eg== 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=nf1V/AFdtZNNUo5XybdRlY7HYjxRFoa3VD8beyqYfcU=; b=NBRbhswRY5wc3z8Q5RUvlihFApv/7IObHpxAr5XdoksbLFJqOLIMTZUve4ZaWk9OkAN2sxCqWrvg4QU8h76JxGcx/PbNfXI1dF91bhJ4qdUS1QWdBAlGOLwCuSdfmBTKxHxJhIAux4aArVfBBi5vP7+xtH7d08keGVAnmkbiYLILNaroMtPxFdyOCsTeDW3SudX6Ir+pYYTw1R3SwnaFzaSrobuUyRe/Px5xA6qjB1QaLHeXgOkYcuRdfYChUCPIAkgtLvc/oxbeVTu9zznlW5ZfVgflejl7RESs9yAsISqDxf1OtARA74tBtpGwBKkYZ+U0duhtaXYNcdkh2xZv2A== 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 DB9PR04MB9915.eurprd04.prod.outlook.com (2603:10a6:10:4ec::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6678.26; Wed, 16 Aug 2023 01:12:15 +0000 Received: from HE1PR0402MB3497.eurprd04.prod.outlook.com ([fe80::2867:7a72:20ac:5f71]) by HE1PR0402MB3497.eurprd04.prod.outlook.com ([fe80::2867:7a72:20ac:5f71%3]) with mapi id 15.20.6678.025; Wed, 16 Aug 2023 01:12:15 +0000 From: Geliang Tang To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Florent Revest , Brendan Jackman , Matthieu Baerts , Mat Martineau , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , John Johansen , Paul Moore , James Morris , "Serge E. Hallyn" , Stephen Smalley , Eric Paris , Mykola Lysenko , Shuah Khan , Simon Horman Cc: Geliang Tang , bpf@vger.kernel.org, netdev@vger.kernel.org, mptcp@lists.linux.dev, linux-security-module@vger.kernel.org, selinux@vger.kernel.org, linux-kselftest@vger.kernel.org, Yonghong Song Subject: [PATCH bpf-next v14 4/4] selftests/bpf: Add mptcpify test Date: Wed, 16 Aug 2023 09:11:59 +0800 Message-Id: <364e72f307e7bb38382ec7442c182d76298a9c41.1692147782.git.geliang.tang@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: References: X-ClientProxiedBy: SI2PR02CA0018.apcprd02.prod.outlook.com (2603:1096:4:194::18) To HE1PR0402MB3497.eurprd04.prod.outlook.com (2603:10a6:7:83::14) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: HE1PR0402MB3497:EE_|DB9PR04MB9915:EE_ X-MS-Office365-Filtering-Correlation-Id: 0c390344-fc33-486b-f5d9-08db9df5d39d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 8KGxQ83QrUbZ+wGaHCB99ODW0XzsrahW395FWP8lgEZZdiRJKfscq28FG2lntBBWgUgwsWtLcJwxVt3imVuQ31wfKGkSsr953Fmqtez+jYSyHxwfQmXqg8dv3apJVg6mYebkBeOT4Xktiogj7W3E9QQgUWnqVZAjwkh/X00bIbHL5K6vmxD/HUAeg5M3Nk+ayDp1sk2YQoLSfoNLKgDL9CyHbx63v+NTeHthB0cKEYHwO7r/DCfuvleGeouiisNOLIMKhu70sMYzMJiYXt8A60wY4xcbSwG3tMY10xRfe8aaDZGkPTuRYGs2MzXjUfpCxIGq/5ZnZgpLE6PXIJuZu2JZRbomrMOZ30pzjjlgXWowssER61pVKCGpDUIzmqm0IreHNzqmQP82s5jt0GsaZ3wrzkTxO7eupRUsYw4xY+Tsr/09RHa5O/K5Al6LQmxWzs+SpToX+/2tw95WSLUILU2J5wts/+cfYAh+wq+i/0695dffeCmc6z329gP8jzN3yjo0N32SkewEIttWJrX/1wXKVx3Sb0LGN2V/9/HiBN3J7xUp1CznLNs6GJJiFp0l5TIB9PQIRcmxGKw8JgyxuXE6f8T8DMCM0kcyKPX6LzVSeKXtMXqtQXf5iIJgrM3L 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:(13230031)(39860400002)(396003)(136003)(346002)(366004)(376002)(451199024)(186009)(1800799009)(38100700002)(36756003)(86362001)(921005)(6506007)(66476007)(41300700001)(44832011)(26005)(316002)(4326008)(8676002)(66556008)(83380400001)(2616005)(6512007)(6486002)(6666004)(2906002)(478600001)(110136005)(5660300002)(7406005)(66946007)(8936002)(54906003)(7416002)(13296009);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 4orGl9lKQYDOu1BCKdSunhiFg9IseS9Hf73gJjGJFGc/HHXCv7RK3muoEJnfVh/cdME2899fpOT4w98bjCjcV8ISRsD/vqSoTHPQYVFiNyquQeDLNy8HvP9/OjcmN0al8SF5CGkaq3ICxa/OecIi46bJ1BRnoooVWAxkSuG6UDiAWwKZFebfQLRRqeunCRtpnxgmkLWiwZsisYzNOVC0x/YlZaFrNk0smKLvjNOotluLS8bQQG3Pd78gkxNEVtDGFl6ufWHOJHbAncVO4/ZKnrTH8sH+pqXDRQGMq4aN9PyOGxWNSSLm9mr9V7sUhEFJSXlkTk8QA5ggei8SiyGbKCAc5ThrvdulYFxO+4iStX0a+IpLB6m/yQG+Dm/J53esYdFz42PawT1vBbcG/MmzjGC0dgKfHIgej20xS2ALL79Yw4AQVOBPPCX3bUuoOFOgHVWy5mTyyUoIewDjP9+Fr2A/ivhdYeV+tA8kGMIu6uCEN/VFYuEoBuV6lZSWiU1nAAsJ1faBSZ1Uxzg/JO+FZe0Sz51BQdwq2EghXPcextYnLFFOo+3XZ4uMYKMQVJwG27oq1RY1y97pX3rXkt7UMqLwbjpjDH/FXW8K/Vc3jgHuo4fy5jeYU/2DEUWpXz+ICHq2k9arZ3DvhKRn8esidsrFezRV2WQRYWPC+TowbiFoTlWYiTQDI2ZVsIe3wQmQHz2sXTf/pmAHyU77C3vQ0NbZz0iBySftuJOgi4kfV5sTwVyTGdMgAbpQhVi+rOjhVLBRoxheWkj+znxg6IYjgMxSaGdgr+5PYKrxY+iCafZV1nyuCZyRdDeUKymBnTpRzNkGkJ9XtiLLgmx9Y1TPNAA7FWPck4SSVULWwO2e1QopHHr92jeejznRSxN3/TY2Ly7Q8oR2+0LJTm7PxLUMTlZJ4Rf6+Hnde5Sbbr5kjd9yaGGDtdGrICyksTi99smtlPkeOcfazr/Rc4YBhJFHJhtEx9WMSIedPofUfzL3S72rXlFiBcw5/koZ+2ILT7GgSmgg0ooWolHp3DfVyHmgYw8/95Jmqt8f4hugcFQG7j7b1eRawZLSqYZ20hw/MUf4RaSqQey3JhHEz/h60tnFGauA7ft6OSgc3WCQyExdIrJLH663ZYB1ONj3yuV95eUuKbihepYNa/xTDGXwJl8rZzmpKG6LMFLqkaxe7xkekPCM985dQYyjPUFoaT4IMweWEq5oqh8ikRObnEztkIF5SexJKR6UID4RtYkW4jfVUCp3ng8Oe4dkxjlqmBqK3oiUCxn2tWKmyzm26qoSxpSTroDH1Oa+1grPo6EeCpKf+j4Xh+1xQ4ix0ceJiLAE+hpc1C/1khVFoecXkGg58SYVOVo/x8Hbq0RaZh9o0G/WN0V80rP1BJZ8gjSgMyedBHmYRpeHctN2g1kTdgHP/piDBcXWtGvj+7JHD33CkllDujnY6fgm1Ngl79J0LmFMHMZSj8QKcWule35KwKSIi+ZJqHVC9rcsX6OJJ0YBu9cJhhxRArChvUmIIi+Rn5DutDGyqWC+mN/HMXusaELNf7rB1lBxpi20tO3YOOuHyaLVABVlL6k1IwekHi2sS5KNF8II X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0c390344-fc33-486b-f5d9-08db9df5d39d X-MS-Exchange-CrossTenant-AuthSource: HE1PR0402MB3497.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Aug 2023 01:12:14.9441 (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: SN50zyUr/gle8bCzlZF1EpdIHVzuWE4bmqktV7l/ge7G8uIchgm7wqI3lh6eIDJFAKKVF5h9kvhBUmI3PuRhfA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB9PR04MB9915 Precedence: bulk List-ID: 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 'getsockopt(SOL_PROTOCOL)' and 'getsockopt(MPTCP_INFO)'. Acked-by: Yonghong Song Reviewed-by: Matthieu Baerts Signed-off-by: Geliang Tang --- .../testing/selftests/bpf/prog_tests/mptcp.c | 116 ++++++++++++++++++ tools/testing/selftests/bpf/progs/mptcpify.c | 20 +++ 2 files changed, 136 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 3d3999067e27..68ebf9735e16 100644 --- a/tools/testing/selftests/bpf/prog_tests/mptcp.c +++ b/tools/testing/selftests/bpf/prog_tests/mptcp.c @@ -2,13 +2,30 @@ /* Copyright (c) 2020, Tessares SA. */ /* Copyright (c) 2022, SUSE. */ +#include +#include #include #include "cgroup_helpers.h" #include "network_helpers.h" #include "mptcp_sock.skel.h" +#include "mptcpify.skel.h" #define NS_TEST "mptcp_ns" +#ifndef IPPROTO_MPTCP +#define IPPROTO_MPTCP 262 +#endif + +#ifndef MPTCP_INFO +#define MPTCP_INFO 1 +#endif +#ifndef MPTCP_INFO_FLAG_FALLBACK +#define MPTCP_INFO_FLAG_FALLBACK _BITUL(0) +#endif +#ifndef MPTCP_INFO_FLAG_REMOTE_KEY_RECEIVED +#define MPTCP_INFO_FLAG_REMOTE_KEY_RECEIVED _BITUL(1) +#endif + #ifndef TCP_CA_NAME_MAX #define TCP_CA_NAME_MAX 16 #endif @@ -183,8 +200,107 @@ 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(int server_fd, int client_fd) +{ + struct mptcp_info info; + socklen_t optlen; + int protocol; + int err = 0; + + optlen = sizeof(protocol); + if (!ASSERT_OK(getsockopt(server_fd, SOL_SOCKET, SO_PROTOCOL, &protocol, &optlen), + "getsockopt(SOL_PROTOCOL)")) + return -1; + + if (!ASSERT_EQ(protocol, IPPROTO_MPTCP, "protocol isn't MPTCP")) + err++; + + optlen = sizeof(info); + if (!ASSERT_OK(getsockopt(client_fd, SOL_MPTCP, MPTCP_INFO, &info, &optlen), + "getsockopt(MPTCP_INFO)")) + return -1; + + if (!ASSERT_GE(info.mptcpi_flags, 0, "unexpected mptcpi_flags")) + err++; + if (!ASSERT_FALSE(info.mptcpi_flags & MPTCP_INFO_FLAG_FALLBACK, + "MPTCP fallback")) + err++; + if (!ASSERT_TRUE(info.mptcpi_flags & MPTCP_INFO_FLAG_REMOTE_KEY_RECEIVED, + "no remote key received")) + 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 libbpf_get_error(mptcpify_skel); + + 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(server_fd, client_fd); + + 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; +}