From patchwork Thu Aug 3 07:30:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13339383 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 230BFC0015E for ; Thu, 3 Aug 2023 07:35:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233921AbjHCHfs (ORCPT ); Thu, 3 Aug 2023 03:35:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44930 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234048AbjHCHfQ (ORCPT ); Thu, 3 Aug 2023 03:35:16 -0400 Received: from EUR01-HE1-obe.outbound.protection.outlook.com (mail-he1eur01on2047.outbound.protection.outlook.com [40.107.13.47]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 685FF44B6; Thu, 3 Aug 2023 00:31:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ItgGjcowWbAZFs+pzozMm9FpHyjt96cCK7Rt+NNOQTPTfBhUQlZNqOmC9O4s1p0HP/Lid4Nmc4y2F8mZ2FPGV/cVwFx8s8PrD/WoZuWOo1BZalNVnUHE+GiLwgbn7Ck9hqbGv173+lrCAEnmuM5vO4qWjTwOuNIQl36sqQ+zJBCfiG6GY2l/ey6I0WVDa6STGiOFPN8g2q9Kh6yPxER0FzoLGv40WnOMGwSSJ1mGi1KBBeb5pMWY+mgAqgIrwMCRbAbp8jGWReZsC+Qi8X0Hn95MS4cjjLNsXklxlaRukqRLHlwNgZj4dgw/PuNau+tRsrkl8WSSTzbIZIMDPHgDkQ== 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=7ytRqdk3KEB9d6aj4yqz0u8W0I4u0l3uPJT5jvEkMqs=; b=m/d+4nPH1JTFQdjLb+/ivpX7vK0QnJ57Te0KHMkrU43rnWlvzuGeqJaVXrHamZ1gt0gIMcLNw3eRBlUry8mse/g9uWbjDywa2bDvpJOs0PU4K5wBfYUGKUlLPkSc50Lm4o7zXl59jZYC4HVSZT9ilnJl9/vBNJ/jO59/L2gNhrQAdwDegoxHNYuI6e74mnVBGGosSD09ZqatvyLlA9t8L9EyDQSqLyzL6R2hcK2wlyAiitHs8tV5nLrncdQV1SCLhvQn6vIbN9AVTAMv5OreyHSYZWqZwNGzPOBKkx4xKMe6Xu4LX+RoiXVSBDFgJvC3itC5foopSKr5APtVzVqWKg== 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=7ytRqdk3KEB9d6aj4yqz0u8W0I4u0l3uPJT5jvEkMqs=; b=ZOFQBJRC5PuUUwmr1DYNO2oaw+YUhn7O2iRFoR6dDZ1biRBu6GJ34W592cjy46gJylSvi9T1Hgt7CFGTP2wzwUiezsLX4dQhh0wmnLQ3hIRkgpveKqETrc4b/B+Dx+om5syeOGY+CTho0Foza4DHNWqzFTNL326PS3UR2QHNqEqjHXt+DodJ1+Lr58XYa6AYfzCHoQTGEjiTyHB2gR8tyb8F404aNntw4gVPV8+/8+H55NnyfFrUBF1MD+5LHuy/s8bYVEvGm/9P5MBXkF35mwEJw1HD06a34BL4NRoiki/RSkdXP4W5IxwjbFKT7hUISIJyxcIHFUzk1qdFhWyhmg== 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 AM9PR04MB8571.eurprd04.prod.outlook.com (2603:10a6:20b:436::23) 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 07:30:49 +0000 Received: from HE1PR0402MB3497.eurprd04.prod.outlook.com ([fe80::bf65:a49a:8861:4f92]) by HE1PR0402MB3497.eurprd04.prod.outlook.com ([fe80::bf65:a49a:8861:4f92%2]) with mapi id 15.20.6631.045; Thu, 3 Aug 2023 07:30:49 +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 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 v8 1/4] bpf: Add update_socket_protocol hook Date: Thu, 3 Aug 2023 15:30:39 +0800 Message-Id: <120b307aacd1791fac016d33e112069ffb7db21a.1691047403.git.geliang.tang@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: References: X-ClientProxiedBy: TYAPR01CA0090.jpnprd01.prod.outlook.com (2603:1096:404:2c::30) To HE1PR0402MB3497.eurprd04.prod.outlook.com (2603:10a6:7:83::14) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: HE1PR0402MB3497:EE_|AM9PR04MB8571:EE_ X-MS-Office365-Filtering-Correlation-Id: 602f81aa-90a5-4ff5-e34d-08db93f38f2e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 5lNkwWiVe5D/uNZCyQ49nX0gkNC4IsG7FAGRy8KjLmweVM9YZukGQZZR1obBt2i8alOpEAquBPppJwlq4n3LxWvkKwFkWhtlw16M2+4qSsx6X9W23GIf0vEpF0yDacPdaTTc48jwC7wmv15ojbi1/dAcPpQZPswONL+3R6P4qa6R9DRnKAhLfaxmlw7Val39lfn3UfxyTvRk4JyEFnZWTf29k0PgHyTGEw5fMEfm38OjwwzcbjH4I2/Yl5AmtzfDS3L4Hd8AR1wV/Bj+uKct/2kizS6M3mCX3+a+qLnrpwdAHZKVyXait/bPp91kG1/E3QJL8dodkrK+udYsV768+hL/K7jsuxVkgpkmtV5k9c8a1g+OamrN+Y1zKrkoyn1Ih7W+6Mxqswt+LaahZDWWWAwAWyxH6PG2LAJUXawyjGg9U00ZH4S7dYo6qQKzmZsKEqnbd7i41ZcHXpVISb3lxs+eRAGI88WQloQ2UiQpa0Zvkt44P+7J/17SI6pr/vgm7vQ8c8Ets3pLCm+QQd/WC5aNCDSxDo88LNdUOAWEGamm8ZXZhQx7Hj0Vb0t/g3Wjx2Km6M/nTt0L1rr3d2C0ME/p27UbDwy8oXAIm1cMg0A4nzc24SgI94U9I+zGPBPih6+NtRvv/txA2BH0xwixGw8l0VMTqMFFGMLXcRTme3itvZXks6+LglZ6mAXRoiq/ 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)(376002)(346002)(366004)(39860400002)(396003)(136003)(451199021)(6666004)(110136005)(6486002)(41300700001)(478600001)(7416002)(5660300002)(8936002)(8676002)(7406005)(186003)(4326008)(6512007)(316002)(66476007)(26005)(6506007)(66556008)(66946007)(15650500001)(2616005)(2906002)(83380400001)(44832011)(36756003)(38100700002)(921005)(86362001)(13296009);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Uzj8iTRFp0bP2Z6FMfAtyK5O091SPllwMsvRAvp0yDCaK6YXXzE28oRB/tCVcgFCJ2cHvNGzlwgvJi1FSkdbVXIovFp8yNsIoKZCRtrkJnEx9U7LO9X70RYZQSOpL/AiNyxRlhtOX8y6MuN0G3kCsyvbo362t/pP9GqDTf/eG5VxD1q6xMJ2BTlQXWTV8VU52u9GlAsO6cQLKZEaDfNpJM1piDx8BOfQBWxXHaaJm/JqHdNv1jX+EpSDJPPUYz+nZtFZspu1dqA5jG4OvsIqx7MVj+VAAmAy0HWIvjWznaVZ8LvT/NmI0bA6wM39xKC9Z+GVcP/9PEEPF/6gSvBCQWX69ywRXoqcmFdBk76zdoNoocDDrNNcRXwXeCduRCxqiu2DaTKhwSJed6KnpSk2SV/CJNdkw09/Sz+VwC7PFV4fVX9/7nhEXZzpu0n5JeSc3s3qoxhiAhEHkC86u7io5CRTFK8oUUu1/pPF2Ti8XTDuxVO65NtfjYb95cxvDay6xUwOMT9MU/IhydnFhxFDNEqKdooVxj9JS73Qz3OwvS2cxscglZtCDHjkXpzeWecP6UA1B7SlSWQIU0L9wY8UBornDMQvIISl2p8LSdB2B+9UEYrQcp6FFXisSU2musQPuybuI7n5Dd2hK0RBO+1TB+syVuJoDC/PdAWOWQrAM1Aj+V/D5qyWwZiukI5iaStzKTONNnARQVIJxkOK/cdy5sn6AlJyhdchXTtGLxt+et+Pz7Z9xgROxklH4v7/eeT4ku9Ze8wk3WKGZiQNYPst5kIDGAcfb9zlTH95V/o4hIwS83Eh/Kx5j8qXg2wQbfbS9ogbXNpl5MMw3lMGWm5Zo+MGLnuea8+lUI0d3qe6QhTis4SoQLPjlg5k/qHYMzTc05yIZ0Eq6czYoUDD2cn5oPGbcBb/2X+95anca7h98IVE0865bZ4b8W3jy9pPdWEWNU6uTjjURuOS4NA0FwkRfgi8/gSB7MDoaxtYjXlEf9c0TpwnvW9QHBCh0/hkg2od6O0TXPnnLZa5zKsHs+XzAZQ2VDxy8kWP+ZNzavD+CQH/Qd+I0JsR28vBidqTzHr1ATrQv27UZSWugVg/GvVX50KON5ogeIq9cUIoLM5TDNCEiG4ukUXVlGqi3hGk1aTi/zTFOFXa+/XriBezRwSMvzC8DLdB8Eo8GYuZjIugAeXIHGVC/VqIG7BRlxBBWbVoFTtp/yRYUMHK6FZ7kahcMlRhRkkSRG8xhxAmMoVhAGOrWmH1ML0jOmL4hB9hdakjx1EADEv4fjQZSHPYO77YYVGzKKU4xdzlljjHZ65v0gQF6iuwl73YlJR1LQNgOlNW8U8/D2NuRAcQx1R662e13rbPHHEE3czejTLeatA7LBAcysR3LoIESbUSlCUZWzt8DdVVJDj8mih/e01ipsuTVzFh9/WGhiwaesfyn4BQ7B2QCFxW+nj3tcYGBqnVtH/niFiMfk3lqbujVMPQHdA1ioM3Yhgev1IiB1CVZ/6bEr+n/xi2OCbW6H19D4VKb3T6gIeNX0u/piwXkz3W+xmoDrbg2/ghdJyJMoEIBzUsj9mMbOZiwl+9LDzWLZXW/VAy X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: 602f81aa-90a5-4ff5-e34d-08db93f38f2e X-MS-Exchange-CrossTenant-AuthSource: HE1PR0402MB3497.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Aug 2023 07:30:49.5182 (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: BAxDRXM23xoUk1SWG0V5X7EKJBqjTW2D3MqeZ6VZcm6HyaiPEx8CO418m8TpzOLx7YLfJxSzKKHxU8CxjAA+QQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM9PR04MB8571 Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.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 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(). Signed-off-by: Geliang Tang Acked-by: Matthieu Baerts --- net/mptcp/bpf.c | 17 +++++++++++++++++ net/socket.c | 25 +++++++++++++++++++++++++ 2 files changed, 42 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..586a437d7a5e 100644 --- a/net/socket.c +++ b/net/socket.c @@ -1644,11 +1644,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", + "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 07:30:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13339384 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 96409C04A6A for ; Thu, 3 Aug 2023 07:35:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233970AbjHCHf6 (ORCPT ); Thu, 3 Aug 2023 03:35:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47030 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234066AbjHCHfQ (ORCPT ); Thu, 3 Aug 2023 03:35:16 -0400 Received: from EUR01-HE1-obe.outbound.protection.outlook.com (mail-he1eur01on2057.outbound.protection.outlook.com [40.107.13.57]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1AA0D4684; Thu, 3 Aug 2023 00:31:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=l5cRq5D+CAPbQtUn1JTTiKTOqmdc3duOxZdEmkGRMkYuFHITT20jXx+I0IpHz37I8f4D9GZ0QAqyzB0WdglHQa2s7iKOJ1QdXlvrQuYX107niUG+e68Y2M+T1eaLKefUBkw2Il9rGIhtdKgaSvQXsGoA+g1StNMBXmj6mA1hX8NVNr10R1RJOTcnDR77FxKtqHqwuQKJFJE5NtqqNY8zpPMmz6fYgmXaDDYNLuycnw4hAAbaAVbxZyQqTc3csNBX9fP8pHcnP2fNm6vywZGakXfzQhHTGuYTc3j/iUSAjB3TjTWWExFsHsj7YH6CL9CBJn7IsMDk+neZAb6mY+TWDg== 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=oZLlyHZeQwhV4dSA1vvPz0P3Ny0lqbqI4S32w/Fw8f17wYFdHWPoLt9ITgYq67Y39zTQVXXFnsfH2Y5zKqntWKGzyo4O/m72fiMPjb5Zpx15N6esFvBkt687qNOT0USQnQTHny7N9u6zb3qIJZfpF0+xFKjLlp0DMicmVKbweh6t2BgvzwZcUYjpPGEnh6/3rg1IwNlVRI1iO7dGOq3vduHdK7pOSmFnvGhmPO7C1xLa1Eg30QYc5rHr3GPaH7V5HPa5Ck4e798S23pYiR1AhRjaGivZh36xdlbVVngYveH4JCMQBWfwXbFGzHkxqtbrHBPvPbHVliotf2dLQ2eYrQ== 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=YkfwD3gUFybQbEbtdCXHqomaeIvVkbI6aCMFirkTF6/TNhe27caGV+1pXzCXzU0zQjIF+UQwDiKxRHPAR2cpWqYFPmm52korAIuPw1aAW3kw7T2GoePJrju6sveYjbH76y4f3btd8kWsXlT6UUrtCt3T/7EUPG0sUWJ2i4UCotZaOI4AGTp8mN95YbKclQR/MVvmE9cPo6ACY+bp46mxo9ZmLpBTWZ9xIXb46LJ7PC48ekkqJyLqfaotA4RxDmk/Iv2z6aFf55dKjYJEZqOmeiQiethjFekuvmXl5EWB8xMoeX5flm1LFaEX0NQZ9twHutf6VgNdjH2CS69OKqMXSA== 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 AM9PR04MB8571.eurprd04.prod.outlook.com (2603:10a6:20b:436::23) 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 07:31:00 +0000 Received: from HE1PR0402MB3497.eurprd04.prod.outlook.com ([fe80::bf65:a49a:8861:4f92]) by HE1PR0402MB3497.eurprd04.prod.outlook.com ([fe80::bf65:a49a:8861:4f92%2]) with mapi id 15.20.6631.045; Thu, 3 Aug 2023 07:31:00 +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 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 v8 2/4] selftests/bpf: Use random netns name for mptcp Date: Thu, 3 Aug 2023 15:30:40 +0800 Message-Id: X-Mailer: git-send-email 2.35.3 In-Reply-To: References: X-ClientProxiedBy: TY2PR02CA0070.apcprd02.prod.outlook.com (2603:1096:404:e2::34) To HE1PR0402MB3497.eurprd04.prod.outlook.com (2603:10a6:7:83::14) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: HE1PR0402MB3497:EE_|AM9PR04MB8571:EE_ X-MS-Office365-Filtering-Correlation-Id: c66755ac-99c2-455b-11a7-08db93f395b6 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ugDKzDAwMAxqprQWu5SU6yb55i8AykT7mpCab+ds6p/FitNsEvBgQsTUNGxHRN4i1a8GSg+EEVLls9UA5cpAgvbRV21zm4dxodLXFAwca8kFAsppYmpopNxzPLmsPxBxs1X5yLLqD8tmQgjLMJznD7QOxgBBHpa4f0XWWwVUg0rWLtEbsGz7/TFAtZma9ycbt+bEOR6g7uRIiNEeM3AmndMmYbMZKwBVtBk6Vrb4uEP9df9Sjo/TQXKC0tPuGIoqqIMzFf+SyD63A1PqDycWi0HLqMUI2Tavxn7u6GsjbUeYuJFSMZFFo19WNEFCbiTrFLLzMyqVHXMc1jvgQ89M48o7DWORu03TM518SarQq3PLYVn4o84Toa46BivAu/+BpnatCi1KhoCv0/EFZBjhhOiQhLW7lAOfE5MtnDze/S4j6uobzkeupi0zjbp14f2lItEcPqvALLRAJRrt/ZbGQFNdgUmSQqV4SttkAiU2eaSFzEPAqyOdLomL55OUiz36xWLbVE0MkQDinatEx/Ac8d795nftc77samMWfXnggn4fSyvBeq5fJ5IE33TyYynBFUBwoZJUz/9aHoTCD+UBq66h0Sy0JQXhbh9BLx4qPwy+QolHgcj6Wtfu9433c2kVbIPE8N+DxofYY8ULV/HgW5FDEOpChZiWgNahJIVqG1aGtmkQoC9eNuzNo+0DX88z2AWJ+m1W0OFNROd7+lCKUw== 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)(376002)(346002)(366004)(39860400002)(396003)(136003)(451199021)(6666004)(110136005)(6486002)(41300700001)(478600001)(7416002)(5660300002)(8936002)(8676002)(7406005)(186003)(4326008)(6512007)(316002)(66476007)(26005)(6506007)(66556008)(66946007)(2616005)(2906002)(83380400001)(44832011)(36756003)(38100700002)(921005)(86362001)(13296009)(17423001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: eKqzwrrEp/VDRUpNNg0SKHkeqWfMj8SxTg8WlDWUeEv6HDCHilgrJw5nHzyOOVbdK5HGncs9sYiu4mJQAgTeRjLopd/QEOVy+3QTFY9qmkWzVXD71jH5vqXaWp+Zo7W/K4j0jYLSFViJ9RoMGWT5xelTvEVl38VUOU6mRiNDpb3LzWhwO3SyztkxKgb/wWhEyE8qfw1aFfZvwFA6gqRmLQLiIhwLBeghBYO/eSvuTkZi1E4hCnx3de2zZ4Al+jXdaNIxkA2q9/peREZgVDzktYnA2jj3beFsgggsrM581wO7PV/aq2vbPrhAsd1C/nQpQ8hvXxiedqz5LpZBr1bPft2Me5g+Emyyy2NDFV0vxuwJKmVNULuTgZv3QfH9bC/O59fRs4WqsgLDM13oksxVchAQwtv/bCmKFjoHhuctJgEhx8C35wrVQiMd+mPRuKd9PmjmQHBbBBFReUEPUsnFy7B6gP/vTK0PIULtLTGIsWyipH7XDPye+wa5oBT+xN9VkHMXlTQM0GbqoIpJnfXDYcMDM4l7pkRmE8vPL2785gZP4kc2ueRrgMeUrtmbQ/RaPpl6oFCyovOo34DDKqGcVTq4yiUNNZ7q9jmQMx4q2oYTTted1s3XS5+75kFX398y7BXpUVB0ekTIdpl/7z6Fj+7npG695r6Dy8AtgeSRs64oYq5MOYU4jkX2HPhXWbQqZpClNqUTe88FyIjBKLLiMFLujTWdggz3GVzuMNCUBZJvwJ+2enBL2/D3yRZq32jlEJbHKJXtej2n7Nlx8UtHtmMdUEgvyplgdjgunpY2BZ7MfF/cdgfU6qkC/Ft4X9rlq9Np6vY2ATlCs8IaDHNkbdGEbs0UaCWBdObVxVCDTAGSR+e8sa8/jevDLKC6OJ4bDc5ulw1nmVtt2pEJ9Q0uzU8pwphQpHkcKZoTrv2+l8bNu3jVrPqX7IqecizoRvp+aUbLFG722idboPjMXtWGWrBGRkTlK+s4HRrpN/N6N/H/+841pa5/KxjTkjPgQMwlnty2JvobS9Lj6ge4GGKTv9uhv9Dy6aN1VLEeZaj6YYn1/jxc7/wuCr7G6INS85MSn3Ep3QYuU/KJPREwPv9EvWvOY+omyIzf4wkK5vQwlh+fYRvr9Bir3tXD+Dsr2BvTUW/RDOtUHsNvTbKNj3QPp9y0xFP4Rq16Lrrz2Qpb51z6vaAew3Av40h0KGqoXOVTkCed46JraKU5yMzgzaoWk2hlkodow8yyDY9DVR/TdHvGbDKFqOEVNqJLsc1Do+hvwhSP0pHMhc4Cahnz0O07OFO4FwJ8Qjbi64rVyQs0QLRebT6T97yYa4uEL3Oz9cj3A62fw0bONvFQGwJIG3bgATX3Ho6IMcExwizrDMEi1z7WhGedLyON24bWaJy6RIJgQZpnd2oK9Llc5HYhmlIyigKrKcXbz0FkkVsBKRut7P/Q+NyMIvDZp7aX8HAFaUsAHhDIQelPvwyTAlO56QzGKy24PV0FjcXqT4tQmUXK6QwlLsbzoh6muIYqhVDSa6XI3cLa4DhrDQwTIk3IkJ2vcr8e6fenijOpIFx+GwMrHLg+Ezn/IvA2zEDcmGFCPwcW X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: c66755ac-99c2-455b-11a7-08db93f395b6 X-MS-Exchange-CrossTenant-AuthSource: HE1PR0402MB3497.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Aug 2023 07:31:00.2643 (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: Iq7ZrgMpv4GE/ykGPBn3RJasBrRbC8yB1FL4uSMt9KkwhTCck6AnpHgFHDYY+ypWasrgQDAncVF/3yNsHWWDUg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM9PR04MB8571 Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org 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 --- 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 07:30:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13339385 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 1B504C04A6A for ; Thu, 3 Aug 2023 07:36:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232235AbjHCHgJ (ORCPT ); Thu, 3 Aug 2023 03:36:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47164 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232386AbjHCHf3 (ORCPT ); Thu, 3 Aug 2023 03:35:29 -0400 Received: from EUR01-HE1-obe.outbound.protection.outlook.com (mail-he1eur01on2047.outbound.protection.outlook.com [40.107.13.47]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 82AF446A4; Thu, 3 Aug 2023 00:31:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=RnRMk1GYPmY7F0oTYnODCjuHXThHKnb1EoMurBOQLrnjKmTglaR/6koqAdOdX+STMqEECxX90922LSupgZl88ISzJ36ltZyUQ8kCx2LmClXuc4xo570IROOGKJhdu6+ZcbWRwyJTmslD/4npAgd8q+TpfgFRwvfIdltWERkQLaf1NTmFtGPWgj1upEMye3Ph/E7PaYuCNYUHkWAgr8NmlKbq6wcLWWmzEqNInKuIpV8iFTpJzN99FxsQ+o5x1IHMdWNZL7ZLS4NrqAxzGSWwWtZxw/9bn9teL7tmoXmXUAApNI+Qwetle2iINC3p127gLqfhhYrjJnXqZ3CBb9XhPQ== 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=ne9w+SASlk/Lv95MbMWhAhkQTdsdNtw+2FU2WFehqL/H2PkVTqdFZ+sJlHKQbYdDc218G7AD7Urtujlht0sKh89tjz4TC0jBdN2+aNHeO3GO1wdghplI+rPM/tNYvr9jFXvxXBXZ349lVpyf1pVtgQb0RFgy2t3m0PrAK6hDg+eCH0kBP4Hx1pgpBV+XcGJhh7XdV52oRmH/NjvcvkKz6G3J5bM46vxgISRmu+UG3mBRAoMjT8x17lSZkgzYn6zhq/+66QuhJgCrbvYYHYog/h+SfQ08zE5f4G0Elqe5tIHFNjXC5FhUdU9YpRXhFNQbOrXnHhfpOWPiKcz7cCusgw== 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=JPj0Irxqq1r9Z4qcZJMIEjW97dKK1EB9SHMvK0HSm1oWGMXkTH9IeFBGvmUeH4b03r2WoWZSYAbBjXJbmHZJr0h3K2otKGjWJaejLrAon/5jT/7cZd9mRDL96HHkVkrJfzOjN7JZ+DrqfyJkVrPy7ZX1VruFvafFrPhCXti5ZmJ6spt8uRMjJ4lND+Oel9qhX9WqC6e6EDk5nJqMYKdQRMIDRUTC2RsHM7eUjx49pGLm4Ur2y6QUhdOScFX3bG2CrKgvrb1dZlzxjv9cElButnqetmHG67MXmCos3ZeNr0v+ZyqePui9chuDE/+jqG/dU4lYbWmaq6aJi9e/5eHJ4w== 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 AM9PR04MB8571.eurprd04.prod.outlook.com (2603:10a6:20b:436::23) 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 07:31:10 +0000 Received: from HE1PR0402MB3497.eurprd04.prod.outlook.com ([fe80::bf65:a49a:8861:4f92]) by HE1PR0402MB3497.eurprd04.prod.outlook.com ([fe80::bf65:a49a:8861:4f92%2]) with mapi id 15.20.6631.045; Thu, 3 Aug 2023 07:31:10 +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 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 v8 3/4] selftests/bpf: Add two mptcp netns helpers Date: Thu, 3 Aug 2023 15:30:41 +0800 Message-Id: <72b924b35bdad2a598534e32869cf3a19516bace.1691047403.git.geliang.tang@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: References: X-ClientProxiedBy: TYAPR01CA0030.jpnprd01.prod.outlook.com (2603:1096:404:28::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_|AM9PR04MB8571:EE_ X-MS-Office365-Filtering-Correlation-Id: 3ddaec91-cb1e-4855-9409-08db93f39bee X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: +0cIk9khNadvbKoMJRK2f2q66fY2HhXaEtUzaKCuZukaVuwrVmOxpM5dyV1pOk5gMWgyVlF629wzODfezF0SImwPwJmN708RYzVZrcMktv+PtZ92uY9O71/biE/fckEd4elCJnEI7f/9C5Go3hjLrOIqBXMcI4d7+DqQuf5zNg8fGz+gOD4TARufI15Hllr0ghZ3vRAUFyFCf+E58L2qx+sjXmOP2NksMUm0o2lnsSVGJWjPK1m6XmSXQlRlus/KeDw1Gq6pJBFxjRjOLCVKYiECuGqH/vi4AU6ZJCh1FDRyg+imjRE1N56XfP5uhv6FQtim9uzBbyitin5WMzT/pumzPBe9Cthabhl3x+19DtqHt2LAbovIoiEcBaReA/RQ8A4K8IAhp1xvJL5zTLb9W1HywCt2wbfJD3iU/Jd1JoIXBUxC3/SnV0nOXn1xl9NKbTzRS6QxmKvkMw6f8UooRCnyab3eElJCL/6Lb0P1dPqrLEZMpLro/89nk3XQ3djukWn4Bxkibj2ZAGC1QVfMukXaQYawDwGiHkoc7TnM0841YHNfwl0dHyP8Hqlrddl8sWUmhn7ArRS1JQisD5A67grCoW9QZH0bZ/za87rxzIPD6Z+40baY/Nix0xi6Yj6LQBZLHQuLbjLJquVR8CZ5+mHyxtQ/EVwNrcshfCzaymA= 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)(376002)(346002)(366004)(39860400002)(396003)(136003)(451199021)(6666004)(110136005)(6486002)(41300700001)(478600001)(7416002)(5660300002)(8936002)(8676002)(7406005)(186003)(4326008)(6512007)(316002)(66476007)(26005)(6506007)(66556008)(66946007)(2616005)(2906002)(83380400001)(44832011)(36756003)(38100700002)(921005)(86362001)(13296009);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Ke5w8LaLcVypwN/7PZcZa0AVvIYi4dXbOUneqMMuTYjRJbEkCwzj/tF9ctV/W3MPQjEUsKSO7WuwwfSnKeXYcqKDFnrHdhWwMtNkv+ll0XjjSaPa8atXICy7Gb6V7d1VT5SsV9KtOekXhS5erIO29MzGf3dO+D2B3N47FZLFPVii7AHQx0LvTrYfWxvikcGjpzqDYHLZGgAJ7a4IdeMAtasabrjyMsGwncGJ7VEvkxpVC4IURKwDE9Ds7GoX9W6Wgk+MAdGqqCclY1J6fiVJ9qd0Veh93WGWTDeXJBa57k6zZUyQwm5aIi2Nay1Xxf2wRnJi7LkxDnj6gUd99XX86t5RzCZRu8Hj0zP40naGgpftLnS/ofDjAZB0E0iXn8KjJuE+nv8ngD3w6UQvsbnTOGV8y8onTcF3YWZFoZ14sEWiNp0i+HwwogV3jsihi5TDTZMDFu5UQYXusoG10r1PFlXtF+N9anygYUFOWtCxOzMuam8LNAR02Nxv1ECzIZbcG9g3D8TnbZKifR9OVKEDNi/zbL/uLv6cHgFNCJSvp8urUAt264kQ8BEGNvdXEoEDyQVkA0y1MLJWVuPK0mAJt/b9oyq1fdCb6vvGRDx/ha5FLvcxIiDPpNrd3IPN8D+1XhHhW0aR1I32V1AC0xIsPi/wJeDJdWXWK6lAHcmakCFzCh5ZeQ1UhDALczp+9S+o4erpMLv+2PFh7uAbf1Ao/rMAhHmZ+YR/DRV1dO/H+u7UV8312UGeiQgq2s89YSX+nvmnutJG8Z2KqqHwydu1842ON3qBhKzDvF6KOqla7J0QkDwmE2lIiQsbfV/enWSiHITQhICUZz2Hm46jHtYos/BOQQZs4xWVNQ99GfBtzXDDKLa/qjMC8Fc0SQn2z8OEj463bP15xxCbJLppdO6luV4ghFFgY6vQ6hdvpRgiLBEHn3RgXqEpB/w+gNjq1MZ9RW3prvgdCH+NPLnZam+/gkBgsZZyRHXJC/vBTSs3lx894oSdW1v+uMi0ysLW2Cp9O23FBaFSoD0yRTTdNs5U9XPmQJG50tP6ngSD63K2f/OKEYz2QymPg+qZmnCaNVOQsIzqzS3WE9tWDDkCzJhqmJVZbyOq0TO+bUzv+eTEvmkg5Recla36cmRbnKicA7oZIHz5x11S5YNU77OnS1+Os4/0ITayUZzm35f2c1gPaPV/lnXmmctUzw5OD+rbiRs6dNgripQzpObvTFVUxq1+1+RWsqHLf1P9AQv5VNOX52D3ZhT8H/ggk3nJn9aRbVCaQkt4F45zH7sM13VejnnhUr1OLRoOX8gFZh9s9nzmMZVpRBfHLXUAUJkztXbqZ9u4IBfRbVBCIHpY5hbiwn+C6C9Bs/4E569dELJOSNqD5N0h2SAYw6rVZh7GEGygYjBfWU/gSBKaze73jMtyrS93yoKl98JU5QCnF1lGlRVG3q/1GeR8ak/ZcoHJe6AsL+UzEhOg1BPS0806ir/nznRVlgSGwnK2W7KyZyJ0xbw+XHucpQ9xDbRK2V4ELc0Y1BA5e8s2RicJ4KU7ZG637ewpGDvNBsURDFwnvDNQV3TuX4k3PyYLAVTpELnVVttPYa4o X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: 3ddaec91-cb1e-4855-9409-08db93f39bee X-MS-Exchange-CrossTenant-AuthSource: HE1PR0402MB3497.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Aug 2023 07:31:10.7469 (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: +/QxLbbnPi8s1WSrUEKD2rJbm8uimYnGGtUsGWQ3IwL9I598JD6uZSJ7iD33sWIdUQO6ioFLLe+zHVyiBKwVYA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM9PR04MB8571 Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org Add two netns helpers for mptcp tests: create_netns() and cleanup_netns(). Use them in test_base(). These new helpers will be re-used in the following commits introducing new tests. Signed-off-by: Geliang Tang Reviewed-by: Matthieu Baerts --- .../testing/selftests/bpf/prog_tests/mptcp.c | 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 07:30:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13339386 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 F2DFEC0015E for ; Thu, 3 Aug 2023 07:36:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233397AbjHCHgX (ORCPT ); Thu, 3 Aug 2023 03:36:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47070 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233483AbjHCHfi (ORCPT ); Thu, 3 Aug 2023 03:35:38 -0400 Received: from EUR01-HE1-obe.outbound.protection.outlook.com (mail-he1eur01on2057.outbound.protection.outlook.com [40.107.13.57]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A181D46B5; Thu, 3 Aug 2023 00:31:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=TcfNmCKG00gaZ009jvHNpqgk9gmRdZLucdjbUaw0GFEgMUT2wSMGPnQYVL1gqGSDeFtRE3zs0r3ldOcS9tI6bBA5F23L6OHxxwMFW3qSw6rlXpL4z0fnr9txF4MykZdnvCw+Ah2qIl5lUufNmThp5yZI5P69Oz0S+hus7+unJ7kK+ZuRe71bPZaVZV5S4p6Awlb/QpRKvcMCCQOPf75nobB/Io/G18YB0BqDa9tKj3/TBCAfgTS9RmhjlzWUFSGqS/hk8sn6UMxoSdHRN72IAGzs+syqJL8Ia3qwaQydi1HA6YwUZ6VdEGdVdauq5ACEwb6uMU4hhETkbjpuXvBw7w== 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=IxXqoum9NhQcoERuGhzIEPoRQjesqfpaFmgm/mh4i4c=; b=Zq2SZ6ZwMvgOdsH506kgZtm9sx9xT8nZOS7Z6ACyO1StWGOHzAfwDt1NFvIRolsTzHvXjt9WwjJeSK6L+gcGAcsYmwA2wsKqdTBV9ssDF0t8KxWzUumMHMvkcifsbxmfUIwcrocfkt+JmkpnimWJogBJ2w9nBQ5hRlqV0B7F+vYoh3aIRFnJNaDkZcODIZVMdT40l3tLcrA4aDTl54wOlXspZAJQ/zNLJU4vEBsx62OuT+HEWqNc1FSpHP7JCR5hWJRQHyzFgud3OKKvqSH8klxIlC69kvfKquvOc6A/R3c7qtw/mEhWGrdtTemR8CUzwnAVhAVAr8GKZPHzaaiBaw== 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=IxXqoum9NhQcoERuGhzIEPoRQjesqfpaFmgm/mh4i4c=; b=Id97hJRs9LRUvdjvjvgnzM3zJlWekemCMWlaJt8ZoT/1nIYcptjkwFlvMeksMXsgD7t1+ybYk8gggkEOZp6Wkl525eQFOBfHNjB+gSbTqxHnvIVCtnE15SPtblUI0t/lNKgjIEUuqbiVf1K+14Z4EBNv0Amb2nWxpTSOr93u39ZzE8jEi+orDNKVNke2QkBeg0z8VtroY76WIFgCGt7sxIyjC9waocvoL+2s/hKCwTxqdzk+OJ0514mNm/G5QkrA3UQrkBWI1cfyzb8lqavHkkXTIH0NW+yAxWVWBvvgEIzfc07tvY80qpJixCfL5/3Qqo/itPgIFkTnoAF+vReUmw== 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 AM9PR04MB8571.eurprd04.prod.outlook.com (2603:10a6:20b:436::23) 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 07:31:21 +0000 Received: from HE1PR0402MB3497.eurprd04.prod.outlook.com ([fe80::bf65:a49a:8861:4f92]) by HE1PR0402MB3497.eurprd04.prod.outlook.com ([fe80::bf65:a49a:8861:4f92%2]) with mapi id 15.20.6631.045; Thu, 3 Aug 2023 07:31:21 +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 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 v8 4/4] selftests/bpf: Add mptcpify test Date: Thu, 3 Aug 2023 15:30:42 +0800 Message-Id: <4b95511da1a9dfd1a55734e32b7b6510739a7ab7.1691047403.git.geliang.tang@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: References: X-ClientProxiedBy: TYAPR01CA0036.jpnprd01.prod.outlook.com (2603:1096:404:28::24) To HE1PR0402MB3497.eurprd04.prod.outlook.com (2603:10a6:7:83::14) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: HE1PR0402MB3497:EE_|AM9PR04MB8571:EE_ X-MS-Office365-Filtering-Correlation-Id: ca065f5a-b85f-498e-7cd8-08db93f3a1eb X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: obDaF79jR3fErVYYvkxiHpwtIa7G4N3LFe0LEkAwxpmBIXOLI5bdoHMz95M/RValjz9BR4g7NQpy2mY3p5XcRV0a3vjFooW/3rusHffypxjYIaELyqPV7IHrC05iawGZO/VGVlAcFyr4mHKyEWvK95kKOFJ/dD2SGEIAZVTevspbbqgh0ynD+hKQjbn/ARenW0d7pS2Ax9PtN3U0FSp3HLEbHTK8eVuWRVz9JLZD2IZLWGLztFMWeJEmrJ13tu3P9XXz/u9z2FHMsbhCZKWwkAzJ78KT4+HJ+F0LqPc9XIRIpmkyBHpkRNIyRsxSdE4j2pbIAeU9rbYGVhnSPuOZPqynrWCNIx6cKT9h8iCo5Cdn7l8GLUdJUiLmahsVGvxpFkEKEZEnu+mlDOKTUC5XFEu+eiewF/qXzjidGXCH2itBm07nXHlUQKC8miztgeAXONBqU9fpMujYtHxMRmMnG4Obte7nI+OMmB2TTqaJfyGR7Hd4MsiEytgyT2kNDlUwt67qRN84V9cb0FgVhK4LUStIzIQcEALautCXGYLMEmtAaJ8I97DNwKk5+t47JKXDVH6aFFTLfcAm8vNx1eDWpZ8l6g6JyMz6Sk+HBQhZNxEDrhI81aPIEJW9ZNuvh8OeHOQdCJcbIDHhF3WaORydR80o4RtQBPzcevypr0HV2Tydigqz7FMhytA1yl7BMBCF 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)(376002)(346002)(366004)(39860400002)(396003)(136003)(451199021)(6666004)(110136005)(6486002)(41300700001)(478600001)(7416002)(5660300002)(8936002)(8676002)(7406005)(186003)(4326008)(6512007)(316002)(66476007)(26005)(6506007)(66556008)(66946007)(2616005)(2906002)(83380400001)(44832011)(36756003)(38100700002)(921005)(86362001)(13296009);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 93xKlZa/wwapV+1dspy1fJhHV7ciQskSQVIep2rWEkHdnTGYZu7qqyx+ZLu07ykBZj4Ohm9foEmaUOyyBLTych0LB+tT11+QHjmocB7lP50D9jAqex/2B3Bl8WT7mwvfdgAIu0jRnKPk085kfatEcnty/9VrbwF9a2MXOrBLAiffHa3v6JYWHYEqp4CcziHF6MGtjUFCjGb2P62AGxA8JpeuuaOGaq7l3BYzd3XYwYuiyhbWiipF5uMD3osoB0xNmzeYGXOoRcyIzKyg7a9FVm2iIVa9PmrphsMcR6fhQLCqgYODR1TFe/vMFWt7T86MuRrhlhgmqwuBuBMEwKlojaKbGk+3GrxGDvmf1y4YZ+qrG0dAGu5aZNLbpdLh9/icEHWuuqzss7zKvP9jbDsfDnVo4YZezOYRSIgdDJ11yK449Gq8lpydo8U2h1bw4/CVEbFAjWVVbxifBHGlWoVqZpRjAPdfcZrJ105GLOVIAa7nj2/KF5BAj44WTOViAlnM1KFdQktPYj4yEGQ1Nr/8f5Z4rWaDxVD69DpfCctAMZ074sP6ZRk47LARv1JkiPw/nVhVZiIDI6j/MMDGoo6JgHUKh5NT3yLpTh4fpLytO1QkgQYnetKYyz6JjhvhSpQ44sID97+ag7oi8U2tcH9pZgL/fV8ylWKLGc6knzW7f7WgKKRYw8pvs/scmElkhQXJDLQiyMRsIvD+6MFDYtAqV2Ud6EWUWJfLr7/hqjXm82bjWDa3/kWZAS2M64swEP5JMvEE4gtFqjdsjgb1y3ZsJNMwsb5dxNpzy76dZz3vXR9WiBAaiCqpqtT5k7PbOINUVRcHXAwVuHiSJscTa6EjDwtJKaWYzKZru4p2xNrVAvog+mHh0Y9mTINTGKKV+Zs/ySaqr1RcOEvxVBcVmBUMTKrWsnfd0OcwykNGXhDQXFd4jJ6rEqmAIeJwmii2K5JjwZSP/rxGO2ZlTnaXDtZLecDo5n+CJ1VzfvrvBCHbLUI75sidUL+2merGjLTfSZlZqkXv3gNbDp5CHSxaH2pxHIfwaJ2eibQeNSP7tXjvgrO9ougW5TmzGhOPA+A1cAIZHsXwtp052AW219cXtyQ9ieXnuld1jfA1agaPv4ajVSnfwP+BSwX/ldkV+/CuIgs70qRkgRUlunMtXqcRq5HdDxUsB9QyDH+VDUOY7TtnVu3Qt0QlsWF8gAAKkEDdA7eaM8xQ09S4EpHwdkGeqQvtAYrwIoj/qYVHhzdxY4dOKuF6vm08PeB7Jw64xGg/s7BB3Smil2lwcCjUczrcNMhH3r+F9yr9ABEL7Rr7v8OFmPaep4R2iHOXiyXU939Tmfd+48kXFt5Oaenju1D213qo7ukTJSdnDitcdPKDzm7P5hfvVzatI9656Yzl0rn/K7u8aYTJbuWowRPwj6ktsNeHLvXgS45l9+rJCiXT1Ri0pqpqmZokuWWBJF1hT9lPr8pd7AFZ9AqRN52Lqw6KewBLutXYJMNC+POJPpemffpza0ZUl7n560TRagbxI/kbP1s6Gi9qFpzXjUDECKAviuf9LMq7fqFSdJDO02mMAEQTFeyUPhYEQmPVEPB00zHEy/Zy X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: ca065f5a-b85f-498e-7cd8-08db93f3a1eb X-MS-Exchange-CrossTenant-AuthSource: HE1PR0402MB3497.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Aug 2023 07:31:20.9640 (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: 2OMMfRJ1e9oC13G1Dof9Ec5krmXNHTlf3uODEaJ4CKNq0to9jdy2dlf11n3XAeAYKuJC8N+lNAY7oTvShdkdWg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM9PR04MB8571 Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org 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. Signed-off-by: Geliang Tang Reviewed-by: Matthieu Baerts --- .../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; +}