From patchwork Sat Aug 12 02:54:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13351638 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 4AB931868; Sat, 12 Aug 2023 02:54:00 +0000 (UTC) Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05on2068.outbound.protection.outlook.com [40.107.20.68]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5C73830E7; Fri, 11 Aug 2023 19:53:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=f1ggk7C+aReJfmezkzj+8Rsl1g7je4e8jS9PcxJbNJalz6grFDDORerC3uF+sd6cKfuT0uZQ01uzDy6gKhDsg+vNxI1YiBtHpRa8qhKjr2oS1IPxEVxbkTugGLUYdJSN4tQmXffsCt5wYYRXDvyfcyIXMEyI9BqbgQQ6pbctfu635feHvcZZsosR9r/JrhU3FHCknNUwXjCezIo7jFcW1kRMLWqTYyBXoZ034wvSMFEbkH5mk7teQpwAYIf7Csr6bKG/NlCFr+deKhFR9bXE0lNC2NGDDnu8PgLHgn7UwmcAWT5szzVHzcAWFdCqkyZdvy5dLhTpf/CuT5loIWYBbA== 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=DOQpg/mOsD/birCmp+r5UfomQaV3hQlEyBHRHw3kNsocY+eeN4v5BaAZu1CE1NOKXWiupBHNEXvxU4VmfKqJU7T/bbJLvRTQM8w3evu8TmnqGXA9d3GGywZYV87sgg3XIKJavAnqkuRRAHz5YxaxtgdBS5M40H8nNALvbN3dD27D+52FxNie2xM8nvYqBak7nzyi625n1RMGA6gWr5fOx2jJmq5NBBKMe7AwABZc7yjt+H8sVoVhgl8t3mMFjZNzZzFgjo0kQzZSZ3IeUbMzTJ18mMCHRUNujdMxKkY3WQzDhpxcBxNT1jrhGeOs4noFl8fW+avd20jlQBGYFChu0A== 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=AJ9oYG6Q5Dlef+gJx/73x7qMSPG3jcNCjIVj8FrpkLIEkyl+fop8uERkTxnCXYRzZeUbrDS+H9bF1+gJnrgrmLJKP+3xXyMRZS7AlSChvq3jyPdWwePSzvlf5qa6lUCjmbjj4L3N6bjgek9/VS/2glR4tXRsvgAv+kkKboxFtEmBcD6yNnmU/Zss4aP8WRKOhj+dDoEmM9d9584xqHnhyMC5DSkpKSjJzkDtHgo8Y2RdCZWkfuSam1D6l2PVzwChoozqOgRKuj7RpHl1/2m/NKwDFjlixP5xfRFryy5VF3KORGjULpBJRiGEUh1BNZbrbm4HrkUXhrVlyfzen6shFg== 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 DU2PR04MB8981.eurprd04.prod.outlook.com (2603:10a6:10:2e0::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6652.26; Sat, 12 Aug 2023 02:53:57 +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.022; Sat, 12 Aug 2023 02:53:57 +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 mptcp-next v13 1/4] bpf: Add update_socket_protocol hook Date: Sat, 12 Aug 2023 10:54:07 +0800 Message-Id: <34fef6dcda2ea460f3ac5eb426f9d821009a739c.1691808484.git.geliang.tang@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: References: X-ClientProxiedBy: SG2PR02CA0093.apcprd02.prod.outlook.com (2603:1096:4:90::33) 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_|DU2PR04MB8981:EE_ X-MS-Office365-Filtering-Correlation-Id: c01eb8f6-f8df-4cc1-f75d-08db9adf5f47 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: FcNTfTskpzMCb9fJOdwwEOoIoUxJ1+g/IU5AEPs8tMkyKI9boaOy8QvFLitGUzkCW+7a6uZeBqL1864H/bGG+Rm9RHwhv//xDH0LfsnrgLTbbdM8N2x62DRuYPx9rsGBzXD4s2Yfc/gmfdgKVcMGzmsGVSImIQQO5afYMjRUdAH9TS1Us6KQEKpfNK4jJnWpNP8fbFYMwBneElo0u7xI/T5uj/zrSUefOlOsjyymoA1XLXOQbMHk5IXSJthLygJGQMUGA4HbFPILtRER+Hd3VqYnQsckluJAm/6e7bSkQznhvyu7TokqMH6xUt/iMVtfbGJpWsb/fonID0TehHZQiWcdOuJovFGpUJc1M2BDWpsco/KCiD1QztqOMCd9gI8JFElkELrxRn9uQMMr68Laf8fHtTOvl7DiDA0b7FnTUmzp4p3WuQ+0QVdsOxZJea+rGyXggFrDavQkkVwe1ZZevB0zcf0aqtuL92s2JpGnqxwwXEtavjU2nI8E2rA/IWwk9GTMUnciaN6KRaT3GWC10jTl7htrNvf1DCt2mGJCzQwn33iL4XePasiijDvEBeWdLli9pkMIfhC2jsol0amnT+p7Be+fnVUDgMbsl0/OH+8= 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)(366004)(376002)(136003)(396003)(39860400002)(346002)(1800799006)(186006)(451199021)(478600001)(2616005)(26005)(6506007)(110136005)(54906003)(38100700002)(6666004)(921005)(83380400001)(66946007)(66556008)(66476007)(966005)(6512007)(6486002)(4326008)(7406005)(316002)(5660300002)(8676002)(7416002)(15650500001)(86362001)(41300700001)(8936002)(2906002)(44832011)(36756003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: QndmyAbKoh+pSZoFB6KrxYIENHRXXddPqEmrbeOAbFbhybPYaHjL85P3oyINMQJvAQOop9txYml3H22iGxIogU/SQxyfum88jtna0k50lLzJhBkFYrAFQsGLWzGqflAFFUlnm2PxVRPR0WS75cUqhLziWcEf6ExAZQjPXrtxGUk0NVdF9JdPUhziZwv5L4gnIl3H/vXGAVzYCsnJ6sRrpt3f1j3dHttE/GCgHHBvFYYd/I+dnGReJhIrs6I4+6EFikeW1bEQ15bzMSWp/GvILvEVOrmxmFZkDdVIV0Hh354jAoXQAALQ5TKCbZw7xUb83QSy/ESAF2OL8T23CO6AfKLT8jm9oqyol0DmEikrk27h/rbDBxrolpmGzSVWXcTtK8MaHIhz+0qfRF186ESUQUH4sdPs2F4+qsyhaDOkEeLpLYGhmxHAhSCkjcFsasnVweg9FYOku3DPWlmHpa/cEBfni3Oh3U5QKnxFJHPSY6yKmrBi4tz17NBwr9ZEppllDoQk3DLN3Ero+4kymRsWPW10C8YHr+Kzzc+bmgEYrtml+FOH1N3xmqacbP+f3MlPSVaUfKA+MoJa30OHTZMg9A2ZfSeC4vBsb3xLzMYnB5g8aN8hPdwNH7iLnOL/OgT9+CNANpUsy9PK2xCGBadMxDb1/UUv6XHpnJpEhzPO+ZNL6sGHbvMD7OcMw6bfeeu3NMdMQCRjyDy5KlvR0w7Fr3iOVnhzHB1xqFdlAG4BrLeYWyCYpxhp2U3xusY2Hbx+I257i4DCY1kPWuB/56nXeBuM3li8Djf5wnHT/wddclXL4K6LNUkm/hj7y8DQp3OBgqDuBSVFcQRRBquX0cEwOAm2i449Nd8emlqgER+4pf6bAxJQEAwN6RHAwWZccp+vHda5jtJUETeiPxrG6tpetj75TflEJVQILI8/0HPyTxeNDEy7NpJJWA/esbmu7UYyb9tO9F5BEn0ozuCig6nO2SZoS96R9fiLHEjb3hz6WQYOPjaxqqne4jKHhn7e08arXAe+FlKocIHKxCuXYLgwadCuD6xzmauk5WuyhpCzfA1jSff8McyBaM9G2hogrjeH6WbRxMZBfcEprPRFNbvJJwUtgAO1m9IqEYhbHwoIj9KsSGIMO1KwBlelBzS9svid7yW+4S1U9uS01Ak1gJ4d0o8gcXw6FzlvG7UNLYbnbW5MljT0hOGUoqpn4EsljkRkO13v/vWB5w1fALhryYExjLndC8OY1ZajZ6xUlAE1wu0L+sfaBvaqRrWoy/IKYM+mCLKmqeb5kl9sBYO8aE7DScTpf+ghBZ3kvIt2hqniW8Y5e+m6KEXQlstZMvwVlw/BcgIWViCTQeMRDg5y55YrvsesmGgD63EOZ8XFV6MYzlImCKm4D0sN3tbGvhAY9bVX4O5Xkf6Wyua+joypXWfttyoxXdz7dXzIRR/6V6b1/HDnpHC2hnTqSt5oMuC7QF+KvOMXMPKGp3yeXp8HgrxEcqVpIRV91qAQApiF075IY2AxsML7+8+vnKcNY1FovqBc3icYAjOjz+6zYPlUxuZag6l1+aVIZPs2gGxDuBHUOwupvVrieKakrvnSS3Gfzt5t X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: c01eb8f6-f8df-4cc1-f75d-08db9adf5f47 X-MS-Exchange-CrossTenant-AuthSource: HE1PR0402MB3497.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Aug 2023 02:53:57.3316 (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: C7xGTMSeATIL5z1r+LUhQlM3ts7UTuKuCJ2gjgMZnhJpcbWuOk3+QIEc3M6ewxB4R4vDubXE1oUDRi0bxKCfZw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DU2PR04MB8981 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,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: kuba@kernel.org 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 Sat Aug 12 02:54:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13351639 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 649281FBC; Sat, 12 Aug 2023 02:54:10 +0000 (UTC) Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05on2065.outbound.protection.outlook.com [40.107.20.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 316A3211B; Fri, 11 Aug 2023 19:54:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=CTX32DCiZo7iXhvWCqZ8fLz0ZPyOhLI+O2jr2J9uJ//RUxBwTQWX7aO899I/iADj6OLzMR2sN+2M7X/t4xfei1982bGGB4UQ0410uRPl1mNqqIBb9HRj5P9Pqwh0GUsGUBPUzPLwxEFM4GvuiFokyNIw4N/+ivltCInqPcn1WNgTMsNsJfNwUjolTZjXBWkB6lMdVoe5CvKLauru8Mk48aIvPp51NmXk0jBB6aBgkKWb244tP5LMAH+Jh7Hu/VaA8eyH79WACfhCDNwuyqDH774amJjfAf6WhDANkyLKkiKjn4+ImcNX8tJG2lAQ1DfCyNYnNDg6xwB3TdAuvpYWNg== 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=cr/HfnYhoODgohYoCeKKP/Lw17p+CB1o/WmlEEsaRCxMk8VbJxxNRXkXsQNTF3kdRko8kVq2nhGfZXcAYl27qs1jjkQ1snYsVE6zTGSvEdsNVqNwmF9R4VRldo/WGx75aKTpUPHbbVXDuWNjd22MpaoLzwER295sllZsvnaOJFwLFxn1fn3sLbkJgTb9P5cSpEmV1mO5GIPLmrgJIdx2MKyvrQn/XHHGAfEC1efLK8JIum94t+UwOWB3jSrcksHGKquIjnX5ObhaUnDvKtAbnWw7GnUEjZz4o7XMEHX4RK5qcTJIUvGh5qJBZbmdJ68EmXB0ISKqUD4FMEZzm1F+0g== 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=j3V6qTjSK5dJowI9XQkHcnlGNRO06C5HGdwtD/+LNzIUPq+RZUQFx05htCzHeDN5pGcuFI8KIy1MeZMhncuQNUPRnHeKIHNEKzj/TbgQeatIjTRX0G2JT/7jQkwsc/QP+BhvvraY2JqMEPHBvZaPO6jCla5To/xtAaCYFRBB0dCWKfM0HDvb2K6z0xKelwh+qmNJlw4JKRjKEzzfag6jVo0szikQxnkOZed2q6K2RdZp8SJB8GtE0PvRsWGgNT9uMSWpmOmGFnkYKmoiLJ/cnuXGYSFXX+FxLxVUNqUpTGefrNiuwnTd5QvVI76sH3I7GdWSPXr8CryFdhMfKxTvog== 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 DU2PR04MB8981.eurprd04.prod.outlook.com (2603:10a6:10:2e0::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6652.26; Sat, 12 Aug 2023 02:54:05 +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.022; Sat, 12 Aug 2023 02:54:05 +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 mptcp-next v13 2/4] selftests/bpf: Add two mptcp netns helpers Date: Sat, 12 Aug 2023 10:54:08 +0800 Message-Id: X-Mailer: git-send-email 2.35.3 In-Reply-To: References: X-ClientProxiedBy: SG2PR02CA0083.apcprd02.prod.outlook.com (2603:1096:4:90::23) 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_|DU2PR04MB8981:EE_ X-MS-Office365-Filtering-Correlation-Id: a34c7d2c-bca4-4938-1d23-08db9adf63f7 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: bQ8F6+ZjlP3OrjPzHYNw2sKfh/QEqXmV0PnQLnf2749HStROweRcaN1W53ZI/o7FHNlDjm8DOiocuP+4ZAO9iQi+dw9dRkKgUulnA3Pd29Scfpv9n4jlkt/0UU69FLV0JzDxxe2R5bX+cBedDQDe+EXoKhD8knkd5vpgKo+A7c2GGE1hw952zXcQBdPFIyuz2nCYRoZfW3uRw0z4ijpbXIeCrgUMFczhdpkwQz5YhgE9veYxi49BcEOnvT6Fhea3Z2ISxq7cxlwcFi4Pm/o+SDjNvXr6bX0naUWY9B2HTWfkSsgRusfkZX/EotF0nkk7lVZVn7eDA+Mmj3a+MKUh6MqcqFDtk+p/Ak7nOxL7UjLMoZkEgGK0YuakiIphUePsh/jVgAS+zKRL78JvVeZzH8ECbfQfzHuAVYoMMPib+Z0zrqbjVBcNgDy2Y7HcjIq0IO3LaSt6Xx7L/+SSRwPBkqnDxm71WJQTyvu+e51n3/5zJ+XdLERtT0CLjbHJaQaDaPkKKOw6iQkR4N711NQEFMt52GDYJnHs6iU6JzcVtvuFLXlePipvBjotbgbitRKo2h6V2xH+Kuz09Kbi2K39/IC14UOHN0Y0P5SXnABowVw= 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)(366004)(376002)(136003)(396003)(39860400002)(346002)(1800799006)(186006)(451199021)(478600001)(2616005)(26005)(6506007)(110136005)(54906003)(38100700002)(921005)(83380400001)(66946007)(66556008)(66476007)(6512007)(6486002)(4326008)(7406005)(316002)(5660300002)(8676002)(7416002)(86362001)(41300700001)(8936002)(2906002)(44832011)(36756003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: snkuNYnhY6YIeJnQt6kV2TYxrzLmx443ej3/QZYshewx9VCD/Xgj0/AUTxmh4TUf5UnnljrGk7Inja5P6/jgC9rKgfelExRpUHFBLkHgqultgXlTWEvlNKqXprtz3+yFVREK09+lSPqM8lSukLdra/ctF/rF86YSlfqlC+Dvb0FZFqRScM3ReJUjqQu4UWv3haICd1TEcnBUAGdun1BddnS0PTJY7qCoKkI2x6CHdAW4QR7iCjNycv1hq7ZLAIOndanUF6KZZ/8LJKx4HFbzeliwf5wUWt+V3QldWoSqEic892y+iQ45zhYcUUgtKWB5GlVt3dJGDDLjYmqe20ErSg2bKSmPaVlb6nurOI1asHB3SuDO+CqjQVUK576cYddMsOff+f03R5z8dSJ6ix0JQHqP40nJodvEAehzXw55TF96keFm3rCpPiqvERDKdS9wcnttsiceRIW/fohcDOD2EQlkR90PGfDl1VQI1nqw9ZsifwsN72RhvQgs+QXs0CowrIClgFYs16jLH1UFtKwJ4YCfr2S8e8O2j5wDvMKvOmONA6vcCK64ekoP/vGgjZC93N4ji4ueff0quGLmIrs9PuWSdsUoEoHdOoSM5NXyvZkBv2OtAHenMIhaTRGpFpjM0GKbHx3Dw7Z5YDNORG7RA/yfD3dJK5nKmK0qKyZT7y+4+YZi5p9iUl4RuKWFC+Le2tWwdyHQuKGYWiSRHAOgke3Yo/jpt2uSE1Rt7dA5Q1ybbnPsR/Co5jfaMvZ3KbDIB/fcidD1lcjqFXkJ973GbMIATRHkpM0AsoBFNrxnzdQ2b0MMajz0ZGRzhbXSbDFHJ8ffj0Wk/gBtfE/v2TDr4c3gvUJ+7DigddE+9wAuNBnw08l1buFSfWzrnABIL1dPrFPC1pyo7gvbtuF8CNJUeqowihtDgADyZOvZcc/cX00+BfN7plEka9ONNp2j+SOpD6IUaEi+tO7zsWip9iVBQufGm/r9OLnBTTCQvhIcc3tfkbi9eeQ6QxkEbQ8Czjh3uUpuGGyXbr0ubIOd9zbF7OuQFE5OYx09WDJIR/UacjhdmZ/A+Z6j1dfNCaEYBd9gU0Q5rAE7U8X88cbJ/Pqjzo5ElX9HHESgSFSYHR1xg4WPT/O3H5GFLDnjvuouh/za18iJdoL5Avx6NbLMxRXec6PIPPikejmaQ2m1/EXsNkBIHafqA6gav1sP2R85wI023m2qek6bJhqZuefBvQ+sxfpDStQC5Y4mbeRolMFTcwK8S5zzg+T5m8tMyZbmzrrNDkyBzXUlhn6AAtM79TfxMwKCfDw8y4DmYDBeoJzyqj1YS9iEs5NAzIzOpmfcxDCvVRYfQq0CH85bWcCnXqr3wz+JVuos1M9TYdMGEGgC9450S3US6JzpVY91UgH8OPMo4Kqlpbhfi8OqMvOFSI5xVpUe1q7Hg/DZ19XiJkhLx651YoRpuqmSrVxO+qr6J2jgAVs+qyWRhtTdrlqZbQaxn16TVNQYzakzyxNPMcMY9kDgaeXK3FZZFfIXQPhR+105gfjwJHLE/Y7BjlszlM96LTEfmsap+aFuU8AGHxq31wnAf7sVm3lDSc19MpiNHF6x X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: a34c7d2c-bca4-4938-1d23-08db9adf63f7 X-MS-Exchange-CrossTenant-AuthSource: HE1PR0402MB3497.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Aug 2023 02:54:05.1826 (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: pPMucEqu5L6Sbp7rgOM/+AZV+WkuNgAtbDjB8XXTNx8/VKT1qmOOhpbjLzUhtdWbLBZBQ31zZ+WKk3iQ3Bcf9g== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DU2PR04MB8981 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,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 | 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 Sat Aug 12 02:54:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13351640 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 2341315CE; Sat, 12 Aug 2023 02:54:16 +0000 (UTC) Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05on2044.outbound.protection.outlook.com [40.107.20.44]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3BA1F30ED; Fri, 11 Aug 2023 19:54:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=LrqSIEIZvEH7ssGfH/wUGbNKkRocpC0iKC5hv3dtGgZ6C/BAPcP1U+gpoL/TXa4VqGh5r4X5OTfz7vLY8cFzR51CoudpwbHq0SK81os8kQKk2IBo6nxElsvXAJ7+Pf5DWZX3JlXBMcirytt+B0S5Kw44g/w/WQ2oWL4Loa2ovOjKj41FH+6G0CLMiNq9VRq9wxfVNMGrK9xDYokJAoeiig29C3JZ711Z34bAZ+y+9x2xnPvZ1s+sGfsq0B0RPFfyiKgXITTC7qiypCMb/F9uC2cDJeQsjugq41nWNBXcStppM24ZekPMwT7tlqU5VsiGsxJCASyji8RtZx84hNFJ+g== 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=Xy5gzaQ+XQKO1Ky/O2m1RloXaoe54hpZOJJ+8cxbs4iG9z6Qr0bn12Ch/4MCOB4MMZPPxHy6ywnCuT4/LqRcbFjK04Y+p9anWiZ2XvsY4Puz0SucgIgfeQJXe/YQ3y/eP9nLQI/YFBG/eLZ4Kt9r/VRnR/Im/0+/zyJqj9vjvRv5QWUE451DQlGO+GLDHWA7DZVqqkLwxg//2rYuTLItwjDik5xJochfaCWz+FO2MD3R6+fagfBEJS5jR5RvMviTQq67HmnB8tImE6zu7vHGrpeozMVGi4pmR+nAMsG5Wz/uRdIsfDiND3t2ON3yTfsGFeByorYk+0k7qC7o61/uVA== 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=GBKJ34a/NaykUKqalbZzP6kfLDZ+6li9xmjAJBOJKUm1QCZfSijLiGK2QUEbJBCZnEJHURVhXrnWMsdFll9D8FwVijIccodb8qzYRVgAMOhmTBvBWBg3P9izXnTJoExB8P0bD6Cafbn5fWzzUZvhgSkVRPGqUNCIx/FS+cWL4nMo7LKv75A/QO7VAAl4NFLz9VJBdEkllXAtEPU7cTkuHD9Hon9xpHSTXysMrViCbxKF8r8d+x2odojpakJ+1Jgdx/svPTAWsYRzVVj47fcwnYABJizjYFlpnp29FCQkW2kbAz5clsJrPtnsBEiEfAg8G+0++GA5yncQRIat8jndHw== 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 DU2PR04MB8981.eurprd04.prod.outlook.com (2603:10a6:10:2e0::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6652.26; Sat, 12 Aug 2023 02:54:13 +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.022; Sat, 12 Aug 2023 02:54:13 +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 mptcp-next v13 3/4] selftests/bpf: Fix error checks of mptcp open_and_load Date: Sat, 12 Aug 2023 10:54:09 +0800 Message-Id: <05671ff1dffababeab21aeb6a18093dd9ec41c47.1691808484.git.geliang.tang@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: References: X-ClientProxiedBy: SG2PR02CA0084.apcprd02.prod.outlook.com (2603:1096:4:90::24) 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_|DU2PR04MB8981:EE_ X-MS-Office365-Filtering-Correlation-Id: c7c42c59-3037-4a18-2c7d-08db9adf68d1 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: +CT9lnS1aELT/PQqe6oxAMFjo/zeXY65WLWjOf12i7bG6AJWBwvhEtWoFRuV4xkB8a+oMPO0YqLGeg+9sBTRMDvI1iHOy6JHYheEL8fyXnWoEigzuL6ulLuZLGhtpQNaXpsKJh5BG6c65K0xgsHZjzKfyNxleCFwsnRCoi3fRBmXB1NsoJv+AQzMmD6WkK8FDQ5nMeqaLZ9gBOTf1NkD2r/Ipfw261TPv2GEQLXPvSvGeZZEC0cf+R1XtRr+8bLX6hJWiiWGwbjbIyoHPdYJdHYg3+jKpDpqBjdfNeL6M+a6bLF3pp9OVCir4uPiegBevXBralM55hc3x4YuZQOFO+78tl1tM5eQ4SxmAaHuzV1gylkFCnvP+/U5IEgI/dqRy8zyJ37Boij1nkajNOsw5lhdMgsr8T8S7ByNIJYtg6EJSNknna3VRLIX5fOy60pc6fIDVB7Xok6+9/1zbNwYJkX29MVeTepAPBT5IGXFDJakTKggKeN/WG07KXudGWj3ttYt7DO81+vUERpX8i/8hw14Q+wcXOc/eihvCqq6CAJc7B/2HCXx52FRUGt473FfCSIV6HuP7Ao7yChCKdG6MP8lC1HD+gPUGA8iuqDQqLk= 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)(366004)(376002)(136003)(396003)(39860400002)(346002)(1800799006)(186006)(451199021)(478600001)(2616005)(26005)(6506007)(110136005)(54906003)(38100700002)(6666004)(921005)(83380400001)(66946007)(66556008)(66476007)(6512007)(6486002)(4326008)(7406005)(316002)(5660300002)(8676002)(7416002)(86362001)(41300700001)(8936002)(2906002)(44832011)(36756003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: VJ/QPGnXhwTgQO3yk61sPvvn4+URC5my+cMLyKf3cs0W17iGHvyGdbZ9xWwZJ0yvFujWr20n66YUEMHPFtuLcXZAeeSp1z3CkmCbGAZF5tjztXFx81MXxjl8YkMOiKmIoxUBH60+rr2IVhKXZF4vucHrwlkL5MlV1WQGvA3n/p/R1tyjfRvyKMYjabFIIHK55n14A8v8Js9mpG6PX6vYj5r/q+QOG/U9tU68e26Xv6e+Sk0ht7B4lHdqOT47+08ZvyuNIH4VLzOXv78f/Ak36hnVCd+IK2quXWKPPWW5aqjqGdFa5dCH7a5p1cwuQ0u7S8z5SeiaMV92eYM6Jgs40ICpOJNdRBAtBv+3rFY+4kOyR6icCXQ4Teo4ezsYhYgODv77Nv+Nma71gvfcqiWv3hEI7L/b6zghWZLF/z+IFH4gMutSYX0rdVcAW2VO2mMuEBEFjNipNhb+cSX3cbgLCc38/Q9PDjrbKJ8g0FnwpZBjYwgQU7WU1ssuKE4HD1qWPbGwqmoQLYRJ6aeMIv77e1/XaXa+wPx3UJEObySTxo/6TDaTlEC26g257oKXob2ALBtK3rkCCU4Fxs81udod2unSofpinzibYw8XP3grRNaFcsxSO9eUifTovUh2OJDeDWoEXzIHmSQM0hcRV3J+ajlfLQJlFX2edT4dd0i1U0NxMIBovaFJv2JOeeeEGtrOnEXX50EIDvEE4xf3WlFToN/j86oSVDmdONKJl//oqExxJa8Nx+y0kspvVykriIVXnWAWaQ3vUI1h+HLSngGQ/n5ggXWNrQg4kyMA2SjdvsZpT3RtGCJ6kemxUDF+H3wicTXzrrTNMmd/0n17TPGvZ3JPWnen/Aiyi1bU30CQdsvykTl1ifOec5lcYO7COvWYBdAmOld6UfPH01Ko5fHRGHRPHpHx9+VHVOGiw4gyT4+ePuOPLwE66f5BpE9RD6IwceUHHnzo+cuX7mo88P6YytPH6HxGEQ39i65509uqPIJMl8UJr5aqtz5gJrBG136+R3YaYslfQyaKmpfhd0Jc58cwFgl6IkEONj2/GlnFuG0gvQOowx175VOrs9dgYlQ0ZeabEpD6YwwjXRBia9iK6nrpwgsGvnvSpI78MQ7/YMMod5uuW+SxJ5kEOlqBCjQxm39R3z6ut6sjC1eRTWxnmnag+7EY9BezU5KvUrrva6mBxD3CI+l4+ntVrPcU5H+IoplAbR/3oK4zd+zSCWloGNDQSgyurUQ8DP3FemNsXrK/Il3JssjSaMZqOcj+75/AEGeKHKlgZweWq9CGWDjpwkCyGTxO/2eIB7sa4hlMhJXWAGhj0/ibWxx0uAvLRQIsGr8KV4PEtLx7LfqiQy2Iz7rRp55fgObVeA7e6RZS9zs5W2Z+zGbSOyM/STRst0OZxCiVG2RTuYh2xMDj8X7ao3WBfA805+e1tOCZHEKKShEXWu+i2yDGS5HirizX7mxRvGkQnV6P2tI6m17OxKkhZPHuyShaySoszP8a1arL7tb9Zn9eIWxxu1Wf/7XSMc9M8CqGkQp1fGZ/sogv6nXJG64HWn65sbY9qwK+L4qAwbgc0yEcEJCjNt0xp94L8nms X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: c7c42c59-3037-4a18-2c7d-08db9adf68d1 X-MS-Exchange-CrossTenant-AuthSource: HE1PR0402MB3497.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Aug 2023 02:54:13.1938 (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: /m4UL4+1lxU4NdyLjSurlIXl9Ech3WX7WH2/bB2WxCB33049m3LIscp8vFQTd7acaQFBPyMnEAUIELC9pbMurg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DU2PR04MB8981 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,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 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 Sat Aug 12 02:54:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13351641 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 DDBCC46BF; Sat, 12 Aug 2023 02:54:23 +0000 (UTC) Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05on2070.outbound.protection.outlook.com [40.107.20.70]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C565C30E8; Fri, 11 Aug 2023 19:54:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Jw77lHjaZOAENjE9iXnoYQ2OmQRqP2ugD0D+VoL11qfe+OQAUejH4F3OC1Dcz4c2ENcmmpU3dbRJIVAtq3ZhRUGal2GgvG6JoOAteznq+HcmwoQiAPukTgWjnoBgvjMJ5WCIB7liImx4bQ4oIhcv3RaPg/UMY+5lmCCF5htCqvja1KHV9EHdVN6rTtx96pKa1zor4M2aoGhurGW3uahvzXPFp2TjTSaXoasFmgnusjogD9rlaIMwpW7xfaL1OALz3HZGHIGbBvajMXSzCTUGlkxWsjhC2i2QvaGUAJCVh0zZK01ScnW6uDO4nkGtWLq5nB1rWQANSVoaLfmIXyOS1Q== 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=tnMhbEiHpGTh3Pv5z2ZWBnzhoqLmwMtcfsxsfWMp5CA=; b=jEGWdsx4/R5vlWMwnb/B+cW6pRDbYihO/pfmowjfjK44aH0RE2+rAPwVRkiFnxl/MmOXIp4iykj97Ive2+n4LOaRSN+Je3SThbbckzk/lSSGr3XpBhgMWg1OvPzzU97IaPSHsCHFMNqnB73QREBVKv1QMe5q0dKS0E1pVBhh6akrB4n9vq7E4h50Oeo6lKBA9xtfnng0ROutlLvAsTYd0lWy74w/0QggXwGLWwbLX6FqQwsXRl/xCVVlToTc8naNl/NUHSoKjdXDgVLKqnt34PAeLXwq/pd9dD0Xnw4iZd0sCP95nXmN9gpEFBUW1VO7Yvb4qJLqJSFr1i2Qr+gniQ== 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=tnMhbEiHpGTh3Pv5z2ZWBnzhoqLmwMtcfsxsfWMp5CA=; b=B+HFFbS+hPC7ke7xqXRySxZau7ir151wD+ISY04qIROFGhpNx0BW0vagJ/0BpV1dx1zl3F1e5qG7/RyJP8Icm/X9lypQFSQK9NpML9Q30DNXaMYzsCYd8wLL410u/B7SojdgdX3BmiDBSoJgRRY9qSmpn5XULunZfrUGhkdrjYSf9qqos3H5KmSvsqpyIsNQ8TJnFp0/O9vthCnpANtAIm2WP9sZBSrqSKKzNpXmTwvb2tGqF2Oh1v96JPS5/QOmC3KsrxLLqkOoNkwS5ojg63pUcnTKbJoWbA0B13/GbwNIKsirrfXcfpq/deQB0r3NmvvDcrL+jQsnJCOTgyhHPQ== 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 DU2PR04MB8981.eurprd04.prod.outlook.com (2603:10a6:10:2e0::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6652.26; Sat, 12 Aug 2023 02:54:20 +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.022; Sat, 12 Aug 2023 02:54:20 +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 mptcp-next v13 4/4] selftests/bpf: Add mptcpify test Date: Sat, 12 Aug 2023 10:54:10 +0800 Message-Id: <15a618b03f65177166adf2850d4159cd4b77dfb1.1691808484.git.geliang.tang@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: References: X-ClientProxiedBy: SG2PR02CA0089.apcprd02.prod.outlook.com (2603:1096:4:90::29) 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_|DU2PR04MB8981:EE_ X-MS-Office365-Filtering-Correlation-Id: db2e6c08-6360-43be-a473-08db9adf6d50 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 7a2Jowu9D+GB0yHh0yEFFd2LpslidT0zGA47Jl3wxSqkaWFxC69IfGiQ19HyJEgilTGlEgFlDfBtlW1UFjBCoPanRifUEamO8f6eO6A9W9QJgyLEpzDbYYrNNWKNpJuk+c+TWScoBZ4guyVWirfRajeypLXHtozgwEjIABuLaANZxipHio3SmqmjRo7SF76kYfS0mV2zZL/zj/UkRPZvwvxLPMB2GQUSo4eiI6hcfgz+mu0pDWMoFvCUNcKt8PjcZjwu/HASMEIOCHDOEH/5JX7DRz3bLFnA8tpGJXvKW1szRydnTmsVd6aG0gJRnETcBFeLPOAenus/ZxSBxHj0HlwPkOgRXiinO/2X6TXF6tF0qH31oreYxGCAk5ehiE7j94VL8kXJQkQe5xnCnZ9kLIwGpjv7l9Vrsn3pckJv4bOG22oNDPDUI6eM/GNIAPiv1EA/U88ZzByEIZBCLL2fFLZrAxmrzlLZds83dPxs9q08uBYOeCD9/clf1hmWfdSFbUOiHxptciOAinFO6r3KmyI65vDE0d/qi7baJq66nV2Yib495Yv3xZEdfYxXTJ2rV8+Sw3qXcehNgxnJNQ3wB3Hq5VfQ7RmTU4A04pPqoMQ= 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)(366004)(376002)(136003)(396003)(39860400002)(346002)(1800799006)(186006)(451199021)(478600001)(2616005)(26005)(6506007)(110136005)(54906003)(38100700002)(6666004)(921005)(83380400001)(66946007)(66556008)(66476007)(6512007)(6486002)(4326008)(7406005)(316002)(5660300002)(8676002)(7416002)(86362001)(41300700001)(8936002)(2906002)(44832011)(36756003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: szNb0pezRyGgb5/UJNe3uveSUziSlzJ9rQOQY/xBBfAcu/zoae0jY789wgXRSkmuWkJ/1dvXDpvkZVYV1xc3cqENwGiq0lbVMJDX02T9B8Kyf2tsF/Kno1n64/v8hj7emGdJR35Yxv9HMA1kvm39dpz2SazaT1ulPJ5jcdFqxvB3yAB+PNLCgcOF+74t30qDoeKB3qAuOTabqkhYfC93Aw85hLmDAjGtwa+p0tZkk4N8Q+S6qwoiXsbftYoA995RA8VBOx5HWw7DYDuDWrKhUOfzMpHnyF2vTR3CpE4+hNQ3O4/GLouXhPT29gQrmr17SXCDXnmWYgVwkmZk4+RziToQhugqlmtEWo6LXH+QieH0ylIaqmcZDn+2q9EtVOUXhFfPJNs4Nt8oEymUbL324+v6m4mnP53c/wGRcbuErKx5Z1A2CVeQ8v7t+rUHsDelYb5pG5GSgF+s462ErJ616aVq3dluduV1QoIREwdRyhgDNdziXGrt/w4o6rhLnT8G4uJzZyX+vIhRjjbbPHvpZ13c0C/XwxD8qr+koBOotCAgJBsTu+vDil9DkDc121XeEhe1eAIkbqsEamnCHjaUyfBJpfgLfgBYzWVIemger06pi2I50h7venkvJrTv0npvIXjJ5ELRJPY2F3bCUe+Bn6DicvBNYHzo9RknI4tBQIQO6mIb68Hq5mm7h4wcXOVqVZIa7G9+gnEgVGVZG09B1TCaWco9YNMwFc7hBnbcjngUf1YFd0YiDwW14oFuaM7MPqU8Jw7ris+wr6Ev1SsjGkmycBWPx/ih5btX8Efun3cdqULTVSeTKLysglfaMrZJPaxYIeiHNyWFDFQheQuvYBgZu2rEfw5uwxrdpvSIOQxpfjC8ItqxGjecbgYK6197tUAGbnEh0PuR3w7wxERj8OS0oghT5pPzKCk6bf5QbL9jj65EnXvXnwInoIlPYrVQVMKpv3wsL7yW1ZVYpitoaF70BFfAciL7GmO3OiSFYexkNKkB/U7UlDcHEEUZbIT2bQoZB19RepCKKgFFoP2++ZGBMfDY2mtTcARqM5wcZvjwVlyK5cBn29DoZbwPdTJHQtETqCEbEwY0+2rryf0lGk0+IGZTyiBsZAtxhRA0LXh4kxFK/9tXPTzwm85iRfr++QUoI9LxnQ0M0VSek3KD9k5130aWdhEVnCArY5H9BL/8A9wcnoVPRSsEGc5cK0id4K2tbOUg8hHnHkSFfcR7bVoUp9CMiaeycXuMof+VjEBvNCKDaLKM+1FWHQTQkua7TqCE2ydh6ZMjF9kviPxz4A/VPnvCykujWN54KP61ivx6ZVmRfn+iMkujgSCgQfYxHclpZhjU5VwFVr76vUQpEDB3Aj/DF0WWQtIt3K8nVPeRvInp9tba7SbMtRpGR0mGzU+feE7SyGKTm1mYOJYsKBkAJNVQIpNmrByzKfS+vQu2LAWIWZQLYd92/C1KlsT2w84TiGnvKsF3vPeKBBawOxP7XY2UjxEiF/++CppaOENSaSbvnCc14ybP52ZULcn7zjthXMZkDghcn9OvS9de84gKfyrdpSZisiE7GKbM1xaxLI0JLuTRMxJW2XOYjGHd X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: db2e6c08-6360-43be-a473-08db9adf6d50 X-MS-Exchange-CrossTenant-AuthSource: HE1PR0402MB3497.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Aug 2023 02:54:20.7590 (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: ko/Oy0hNfubouJnwrU/+0d5dptbp5FtzVt8RSEWBLIVeoCLBLO52cpmj/8efiILTr4t2wBVxPj8gaPWi6p9lBg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DU2PR04MB8981 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,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 'getsockopt(SOL_PROTOCOL)' and 'nstat' commands. Acked-by: Yonghong Song Reviewed-by: Matthieu Baerts Signed-off-by: Geliang Tang --- .../testing/selftests/bpf/prog_tests/mptcp.c | 102 ++++++++++++++++++ tools/testing/selftests/bpf/progs/mptcpify.c | 20 ++++ 2 files changed, 122 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..a6bbc734a876 100644 --- a/tools/testing/selftests/bpf/prog_tests/mptcp.c +++ b/tools/testing/selftests/bpf/prog_tests/mptcp.c @@ -2,13 +2,19 @@ /* Copyright (c) 2020, Tessares SA. */ /* Copyright (c) 2022, SUSE. */ +#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 TCP_CA_NAME_MAX #define TCP_CA_NAME_MAX 16 #endif @@ -183,8 +189,104 @@ 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) +{ + socklen_t optlen; + char cmd[256]; + 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++; + + /* 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 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); + + 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; +}