From patchwork Fri Aug 4 01:55:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13341101 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 47A11EB64DD for ; Fri, 4 Aug 2023 01:55:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232543AbjHDBz4 (ORCPT ); Thu, 3 Aug 2023 21:55:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58454 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230201AbjHDBzv (ORCPT ); Thu, 3 Aug 2023 21:55:51 -0400 Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05on2046.outbound.protection.outlook.com [40.107.22.46]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9A93F1FF3; Thu, 3 Aug 2023 18:55:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=YoLwFTsKFsDl08OVLLil++PNt0O4NMbuFplx0EgRWdt4oTuwGldEyTDv2Neq5YLj9rD2RAYcQLCSv+Xw7VoFQiDB7bw0SbwxT2grwO+EyvHCwGURx0+7IXcBCddxgvb3NZ7tn2ZozxiZ9BFaylikaedqJgzft3MkQwAA+GDHPUxbN/Un7yb/tXIpJOo4NvLSEji4MoLnx5zdK7ahcMKVkYTcetTmFErctpVbVYs1kAexKK2kD9/r8fZobCnz3DfaIhbRJh7iU4a/nbvmbbETnJVkCD1gMNJ6dP/2Q0sPwD0Ti1pQjiycs4kgj8Ng/gjSTD+qddgO77v+/Km1/eAETA== 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=YpD3bEfg+gDFZ3eM+fAhpETWevC1iCBWrGrJJSjfmo4=; b=kgSzP9xtbHJEWu8gtZ7xJJ0d71OuzoN54IYA9uMmxtw0TsXXKI9HghYnTem6ztK10l5usVLXxGzhrwDdGcGxLkiHVylBwXgqu/tWNlOGtxhvCWZfIRM6C/LUOe37jobriiMZG0m3T5HUOSuOvc8wkF68Oc8DeZEPE/nfLyQ/RKdKqL/633yeOhJi9F3OpDYXf0XOWm6L4SWyLMdyL3wkF70ohiV8+5lCUX0GRR6gQ1593aBFQ1wGBa9/33QJW/ct44VxuAf3TbBvWtB2UAoVnQUOI+Y0R3Uxc3679WQZE+vkr1fFGULuG5OG1OLDJ1IRDOA5/HVEGpy7CMx8JZDzGg== 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=YpD3bEfg+gDFZ3eM+fAhpETWevC1iCBWrGrJJSjfmo4=; b=slBDxJhMIr5pZl8RCkuOWyZAqHNHG73brJrerMe1gpb17nqs6SFmk61pR2oAkYt0EiThR132wnq+jutfAhcXJ6b4AXgl67QbhsufwC68Pxn+MLzWjUwKUZcaXvdn8mJ9b3UPuAIBQOCw1dExuCKCY0/5MJ/3gXx1ypgvXacC4Def/MlbVjcTZnld8hwxOpxOUjupwYvGEsgSdheZ9IztyIMX7FnomA7dBjUhSTywPOjmkKaqgJA1UniWxKeTcIv0XoMLXGE33SXGDzNm+dwPC1FaFUixS2biZT8hWMhuWylhmh/2W37slgFIMHrrUWeLBa7EsenxCQPNHTEMfY5bIQ== 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 GV1PR04MB9085.eurprd04.prod.outlook.com (2603:10a6:150:20::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6652.21; Fri, 4 Aug 2023 01:55:48 +0000 Received: from HE1PR0402MB3497.eurprd04.prod.outlook.com ([fe80::2867:7a72:20ac:5f71]) by HE1PR0402MB3497.eurprd04.prod.outlook.com ([fe80::2867:7a72:20ac:5f71%3]) with mapi id 15.20.6652.020; Fri, 4 Aug 2023 01:55:48 +0000 From: Geliang Tang To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Florent Revest , Brendan Jackman , Matthieu Baerts , Mat Martineau , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , John Johansen , Paul Moore , James Morris , "Serge E. Hallyn" , Stephen Smalley , Eric Paris , Mykola Lysenko , Shuah Khan , Simon Horman Cc: Geliang Tang , bpf@vger.kernel.org, netdev@vger.kernel.org, mptcp@lists.linux.dev, apparmor@lists.ubuntu.com, linux-security-module@vger.kernel.org, selinux@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [PATCH bpf-next v10 1/5] bpf: Add update_socket_protocol hook Date: Fri, 4 Aug 2023 09:55:43 +0800 Message-Id: <079989b68ddded562b9f2149cc50642072575001.1691113640.git.geliang.tang@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: References: X-ClientProxiedBy: SI1PR02CA0048.apcprd02.prod.outlook.com (2603:1096:4:1f5::11) To HE1PR0402MB3497.eurprd04.prod.outlook.com (2603:10a6:7:83::14) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: HE1PR0402MB3497:EE_|GV1PR04MB9085:EE_ X-MS-Office365-Filtering-Correlation-Id: 7bbe9310-6a70-4dc6-9df5-08db948dec5c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 0jOJL2OylNL4GvH0SjR065NAyAltY17EBfwUjY+SEjY7gOILmGv4gQSvUrUtquCBQbn6eLae2NTceXC+ZdjbFZ7xiiDUSXybKOIxGp7Wvdtli0P4G9rA4clWfR3kuzzUevfgJYycEhY9jbdr8Kt1vgt67t82J3XJYFYUVJlfBy0Nv20Z99pc++PNMMI8Puy9DkkrmT9Os5DA7bdzFaK3F03665QtqkVQ95sDzbwBrxaoB+XQHVZ8bd0iZWtPNsmeo0BogDs19j+IVYZE5W70BiwYA+6tbytVACSFqlRfz9G9hV54VgQq3IhsPnBYM1OgjYBhwa9OyfcmNBXjnhFS1jW21xHXA+zjJT1HL4WXsFI35MbOAzUnqzP7X0UTAVFobi6e/v/2CbVQ+oMQmOfh5euZNJv5gw7iIbHxXLdkf5ZspmN8lMrtZerTUc+0YaJjBEUG1cKCxmYo5ZyDwHuLbGjeeuUilXB5eMavsF4736JFLNLmXRfQONxL3E/pV1aZTRV5UNUfA+Q7pqhNTmEr6hxrqXLWR//1BDhdrvMQg4F9J5DVJiZdUgDC5m09/GtpjxaVWNRRB/8NWAI5x+Cz2KgNKvTrLEUrM/VOg1Jn4UfO9L0kFpx5baGcigGcVb8v 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)(396003)(136003)(346002)(39860400002)(186006)(451199021)(1800799003)(6506007)(38100700002)(921005)(26005)(478600001)(8676002)(15650500001)(8936002)(5660300002)(7416002)(110136005)(44832011)(7406005)(41300700001)(66556008)(4326008)(66946007)(66476007)(6512007)(6666004)(86362001)(966005)(316002)(6486002)(2616005)(36756003)(2906002)(83380400001)(13296009);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: XSo/jXZlcDmeuLuZb72mYKO3wo4RCPWd7h4CWFrWIKWlbDVAC+sKKrlNKNLef0iErvO/mDnESId1MhxipvtKhH3UtZ6AzFGONmUhpQoivJHiRZYjJdaHUx0yDlkoDROF7pUTfRgghwXDmbMz0UXQNbjEMRMoFBsrnzz8/SldcV5jVfd6MtXOotUL2H3Ch7A67XKTKKwrNWbCqLMnJVTvjBkKAjSV3LMQkzUXST+48rkeePcki15/RClBSAuHaSidb2w92nSTRPgRzspRAEul3Tm/0wyoOx7wGJP2QYpH3f1yoSNU1+FD8V3mmO3YgPrPT/4qvK1XNRV6BnaCCBl/96LMvzkZ+CecVsGbi+K+AWfEd+5JNXj6gG3GgXlswH4OHVosCiQ2Wb9DLQYEepqrwnvwML3bOs0ZUAXKHun1y/2vkm65cqxIKwKR279+Wovj0RBtxOjuin0LHX4nLJ9D4DdkhxcUkC2JEK9djdbNb6clRlztrsga7TZKpEgeh94cj3Tj3g8PiSjxBvlFT/8Qnf5u148jxk/GC0ZuEqBgCvPs6iPoAXKwlL2EjML7eeZkpobKDY10monIfJMRe+l0hGmHLpmTclUc/2R8KOh7DaNhjhGj09Le5YGCcgB5de2PshEI1OlJbUWTUcsx8fsLMOTr7P3iY4tF6qKOZdNRRXBgwz404qIpefns0MXQB6Yo6JskCxD2iXUoDyse6Wb3f0jaBTWnGEBBTKaIq0QIOjZEcJ6I6POGrS3zgsn/1qHbLllQjkhL8kxNC7cuAFRHPFzaUzO0Eg/JzoOFhqs57O8TueUSiK5OEImQ0+vYhvbxzoVYsnYdn005yU9pJ0Ab9Q1odwYx/V+lR1KX1rmp8Bg+XZcMtbS3mz64J5UESpF6+ENzAg84hw38QodNmuvK/Xtlb3GzPnwWq1O+lyUh+jw1Kk5Lh+vJkKKUn8Xm5oJtvFn9CwC4SszRVBZX0tgyuz6+9iDv5wBz4mIKcQsZv+ADz8KpmrSnEj1nVraan6/bzJvZ2papZA96DAmS5KIwxKquSJk/naJoVJ3N53+rSDrjGTZ1/NTeDiaC49CdPVA61TLE0H1ItorrleHCLkku55oP6u/APrMU8hWIfFhi/ClcEX8TdV2rt9w01hCGTL7a2AxCSNoVl72gKDDesi3mG9frbjDPqClchJZHTPP5P9zWJsIDDCpntmlhqRaja6PfI38Qv6FfIeRO5PqZ3H1ninzMeTGPe9KsRK8aohYgfxPLqm93/QwkUGYvyEwu71PBPQiJN2h5kRdru2QtPNH/RubsRRX368fUnUBke5VShasiIyJbOKJZJuGdgG0jW2x1fbuHgyjjYf0sdD8HFLYfF5edoAMPX+GDFaGsdykt+THBufRfI8djDnc4MFOI8+3e5IsvtpDnVdEKV+d42KtbvcsVgVSY8lv8kdlxcJIpuIEAhuK5IW8MuZWYwx8C6I5eQJGmYrjqtL2/MuvL8qcY+wWDi4xXjMWYPc+Kgcshovc7saBsvkaK5uBdAeI9soPF3+cd8YxzheJ5rWx0QfJWbKptM7Y2ko0QX9Lz65lPtR+NPut1yti9g8X00+ne8oBI X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: 7bbe9310-6a70-4dc6-9df5-08db948dec5c X-MS-Exchange-CrossTenant-AuthSource: HE1PR0402MB3497.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Aug 2023 01:55:48.2990 (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: ZkiXxHv1QT5LB3rr5uJYkEQdwpmnrJgotfsfD8v78MuVChIWPeJx0igckq++oBYSCgSkZ3jm8+FBuP6x1/cQGQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: GV1PR04MB9085 Precedence: bulk List-ID: X-Mailing-List: selinux@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(). Closes: https://github.com/multipath-tcp/mptcp_net-next/issues/79 Acked-by: Matthieu Baerts Signed-off-by: Geliang Tang Acked-by: Yonghong Song --- net/mptcp/bpf.c | 15 +++++++++++++++ net/socket.c | 24 ++++++++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/net/mptcp/bpf.c b/net/mptcp/bpf.c index 5a0a84ad94af..8a16672b94e2 100644 --- a/net/mptcp/bpf.c +++ b/net/mptcp/bpf.c @@ -19,3 +19,18 @@ struct mptcp_sock *bpf_mptcp_sock_from_subflow(struct sock *sk) return NULL; } + +BTF_SET8_START(bpf_mptcp_fmodret_ids) +BTF_ID_FLAGS(func, update_socket_protocol) +BTF_SET8_END(bpf_mptcp_fmodret_ids) + +static const struct btf_kfunc_id_set bpf_mptcp_fmodret_set = { + .owner = THIS_MODULE, + .set = &bpf_mptcp_fmodret_ids, +}; + +static int __init bpf_mptcp_kfunc_init(void) +{ + return register_btf_fmodret_id_set(&bpf_mptcp_fmodret_set); +} +late_initcall(bpf_mptcp_kfunc_init); diff --git a/net/socket.c b/net/socket.c index 2b0e54b2405c..9f98ced88ac5 100644 --- a/net/socket.c +++ b/net/socket.c @@ -1644,11 +1644,35 @@ struct file *__sys_socket_file(int family, int type, int protocol) return sock_alloc_file(sock, flags, NULL); } +/* A hook for bpf progs to attach to and update socket protocol. + * + * A static noinline declaration here could cause the compiler to + * optimize away the function. A global noinline declaration will + * keep the definition, but may optimize away the callsite. + * Therefore, __weak is needed to ensure that the call is still + * emitted, by telling the compiler that we don't know what the + * function might eventually be. + * + * __diag_* below are needed to dismiss the missing prototype warning. + */ + +__diag_push(); +__diag_ignore_all("-Wmissing-prototypes", + "kfuncs which will be used in BPF programs"); + +__weak noinline int update_socket_protocol(int family, int type, int protocol) +{ + return protocol; +} + +__diag_pop(); + int __sys_socket(int family, int type, int protocol) { struct socket *sock; int flags; + protocol = update_socket_protocol(family, type, protocol); sock = __sys_socket_create(family, type, protocol); if (IS_ERR(sock)) return PTR_ERR(sock); From patchwork Fri Aug 4 01:55:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13341102 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 0D651C00528 for ; Fri, 4 Aug 2023 01:56:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232575AbjHDB4D (ORCPT ); Thu, 3 Aug 2023 21:56:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58476 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232571AbjHDBz7 (ORCPT ); Thu, 3 Aug 2023 21:55:59 -0400 Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05on2071.outbound.protection.outlook.com [40.107.22.71]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9FA7C1FF3; Thu, 3 Aug 2023 18:55:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ScvC/mrSNAEoAnqWWXRL6XAjmUa7LsAln/OAJ5mAoX4vVmqGGM/5X2j8OHidv7nNROC03HVOILINjEEfHzvW35trPjCqD2qtmwWY42wiXvo8npu+ai9rj/bZeI8iAUU+wk4JE24MRR/DqEtBSQ7TM+kLD82moKG6UBpaa4H5YmWhRDI/vevQH8kdanyLjOWZKe+8fvupJpfsk6NfdslmSoiqusYdBMR24AwAS0gyYVs0Te+YCH8X3vxzkgftBcTXTx+QCL664xVVvDaXro8+J8Q5eljI4GzwJPE8yZgBxUYm1PgbeSvDpMExuuG/pMoNQjdVqoJSFzxhsPDgxoOnvQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=vHTWD5WwibfCNfatfe/o1L4JL9TuE7410T4Cf3XxDWM=; b=IxllGbCEtQ/4NOJSerQ6vLb3aoUFD0HZdX4aVjaYkBn2JRij9rAlPMvX3wSSZfUthAq2mztsjBoyDkcSopHKOgEnPq3mgSYjG+JFspKq7qmGcQVP1fq0SNxrrPLRNW+qzroEWz/UsW6RmUXwHi8WOawfFhG+juCbYI/riAfS9OSY1R0vUMDJw7e5rmU4iczzBeCFQiz8DfAKtv9AngCWvVH7dXZLPEhNq+VwqiX8XhxO2SIQKNCcYtGvBToB4eWsbZmTQJ0GwRm2m+GpDcNvAK0tbwehYEEWdROGV+RZHIKQ6IENuGS3KaxEj/8thsQvOc9h2/Fh7MlHT73MNjKb4A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=vHTWD5WwibfCNfatfe/o1L4JL9TuE7410T4Cf3XxDWM=; b=1VbAmi8bDBHDhp19EAjn+WrRzqr+K5bBH5h+twKJAyv3smssEjZZTt36DO878CyEKQbmqnMhbEapVbvzOpqf2C9Ie3ROYHdKqV+FHaIbNgoAWKiT/Xraq88Hwvvm7ZIH1D8t6WgUkOrPw3/OfW+FC6PReymnEYHMqgkhwXayfo8Tpp1QtcSPFkVrZq2RRD5UgqSEc6sx9yOt/XClJwcL1ypjPsssAd7rPy0qiMdtlJPpiUyhp22l0cmNPn6apUmDjf+RlmNVoEGPoJokuKecqWz4OXvP9azpExYvLS1fUYYTDYz0Q/AD1QcIZwfKtIqjFmJJ3dEuzdK5p7fB3NTOVA== 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 GV1PR04MB9085.eurprd04.prod.outlook.com (2603:10a6:150:20::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6652.21; Fri, 4 Aug 2023 01:55:55 +0000 Received: from HE1PR0402MB3497.eurprd04.prod.outlook.com ([fe80::2867:7a72:20ac:5f71]) by HE1PR0402MB3497.eurprd04.prod.outlook.com ([fe80::2867:7a72:20ac:5f71%3]) with mapi id 15.20.6652.020; Fri, 4 Aug 2023 01:55:55 +0000 From: Geliang Tang To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Florent Revest , Brendan Jackman , Matthieu Baerts , Mat Martineau , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , John Johansen , Paul Moore , James Morris , "Serge E. Hallyn" , Stephen Smalley , Eric Paris , Mykola Lysenko , Shuah Khan , Simon Horman Cc: Geliang Tang , bpf@vger.kernel.org, netdev@vger.kernel.org, mptcp@lists.linux.dev, apparmor@lists.ubuntu.com, linux-security-module@vger.kernel.org, selinux@vger.kernel.org, linux-kselftest@vger.kernel.org, Yonghong Song Subject: [PATCH bpf-next v10 2/5] selftests/bpf: Use random netns name for mptcp Date: Fri, 4 Aug 2023 09:55:44 +0800 Message-Id: <256d03943f4dbaa5c1d0b3b23f64efac9cda8bd1.1691113640.git.geliang.tang@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: References: X-ClientProxiedBy: SI2PR06CA0011.apcprd06.prod.outlook.com (2603:1096:4:186::16) To HE1PR0402MB3497.eurprd04.prod.outlook.com (2603:10a6:7:83::14) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: HE1PR0402MB3497:EE_|GV1PR04MB9085:EE_ X-MS-Office365-Filtering-Correlation-Id: 996aa739-f520-4134-c846-08db948df0ae X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: DP6XWYgImjRZenqJfP0hYfln1xqXM+n+DJx9chXPYIiA4orndt/SR9KXaV+zw5XNj5a8AQECmSNZoQymJJYcuSP9Aa7ZmafVPr2gbpvYnajcJyQ8Xn7bIf7BGOfE6xMq1dq9hQJewr1+LGlF5C3wijbhlj3eagjQ9WInnl474IRQS0pJCVzqcrtWUFv17ZvLCNWL14Kl1TufIFn4m2YlZck4E/ixGL8s2cpuidUKVV6rPvv2QmywnzhD8rYBttnkuDSVSAOvELqKRNWmVk+LIUEcphEJwH0n4ky55grCejJXxAo9hztm+aX14dDQlGFXL2pS9F542xvvwgjDQlz5R4UJkUsysjE7e3Nu7q4buQIGndqp+1Emz6hgxSZZvFEVmWlGJfooKCDcRaH1A//7iNdXk4A7K2uWtLguaZmCMIFaTHOWoYeg653CgiuZZngQsEMnPuo/JWcN4u7QFMTs49ILEM0BzQmX6V7LnUDR8VMWAYl3S/XcCrbhEUdZlIhDdy2E4G4kLavU96RY1v57EsoVI8PT2FKMw8+ZKeVyWngT/NU/liH0pnbQ+Ejky3hpyRU9nv9pgVrlvsVNTEnNIn6GQtxYBV8jCRSiKzjBx+rroP3LDOW0qeKbmMOvLzTOIy6X0I87rsBctpz0OfDILB96vXB+6BFHQIGjMzJUF8k= 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)(396003)(136003)(346002)(39860400002)(186006)(451199021)(1800799003)(6506007)(38100700002)(921005)(26005)(478600001)(8676002)(8936002)(5660300002)(7416002)(110136005)(44832011)(7406005)(41300700001)(66556008)(54906003)(4326008)(66946007)(66476007)(6512007)(6666004)(86362001)(316002)(6486002)(2616005)(36756003)(2906002)(83380400001)(13296009)(17423001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Y3vNWtPgufLEOUf3cl+u0GXxya4v6p/9UW1gPjn/bPLN25VMleO1Na4qdZlr/skd6+DiAOb0x3BkHxxS0AnBBTzO2yeEQdQ4G5IDIa/x5E/B892xmoeVhdGFP6WhNV9CzdmiNvWX3tSc7CBqGYMJgq2iEkHInmsaM3qGraw+1/RNjpdMmKTmkYX1rSkjHGLuVNvryKJZEvWnarjiI3YBuhzGN42y3DyqjgsuAmIeDtzV7Uhrl6nS54imVdgYQIQc+nkHZVQ4FdnyhRgFh3IFRqjw/FuVDLCz3GCm//pOHFJr5sg0jWJdKlePcZ7eQ1siJmVBHPramTCWit9ibESmGS2Xk8jNwFYRMJkDcWLUVfXf4/KUDLC1rvLb9TR8phYiBP75O6YS9VKBEu+1g6HEN060Chmoq+rjhXiQAn3RTyh4OvnfCjPRjMhYG6WaX+nKMbZtAY79ewQXIJORu2dLOYBgeedqrzYvXZ74wcnoAlHCD9W7Fz7ZMbjAj9mdAwO5FH2Cpul16/rKRKESTPJZWwE90OButtFtLQ25R5LBgxzH9f2Cu3JYonYR2bUu3MHUvs+PFvethq0917cJXR9oOIJedWX6wAhznqX3ENBki65t89RdPiUR8eiJjAVcdOkkccArfhwHW8gUpgOI+I9oSWNWk201bhQPlCWKAvAeVKO2gSZ7hLs04wxUN2xSSmjzpwp6nbIHx47b+PEuVfpPwyU6PoDSbHm6VCyfdR2PGH5du4izYzMUluLSPq4dLwgIus/GwLvIeBXSlkHq+T3h2o2xvX4EtbRSR5lwYK75EEYqg+DqpeRml6om/3OQjdkwLO6pm56UTjIEvFBkJ/WyjMT45KyOhDwhD+D/M8QgM1XAG+OVeBHakXaYKSpLXyIQwaxjYQ+DTRsIysmD5vD27kv8wF2kJMmkSpB+cbo524cbkqU3UEj8KLx2GaloQrXvqWSByg0hx1n2ceTOCsscUPKkj1ulocKwetYejlLfn3j8yuJwDCgVlwjbYJ7D6ffqR0lWI1MxAmHNFf6+pknWQCTWFx9kGWaKoJgbh/IwbPJ9g+RMF/yfQLyHnwv/BhfT6wYZQ6EJ1nrwFko7ETBgg7zxFoVdZy8dFIETG9CtLgEZTF7CLz85gQER8MFVcCAiKi2Ddhk3nc7MRyX924UUXIZQxezEiAdmM1UzZ7PpssxvigNxu2HNJtwSYif+QYl3v19FVHi7fumZtYQvFr7NnFKrKgSorQKojgUPC3FlCbvCxklrQ8/+qarqOuZuqk58VqJK2L2S8KvJbG3CA/2CqK//NQ0cUduAz6fEvnbtTJcv881Fh7qI311GZ9j4lqsg+q59yHyn9fXNDjBaD61aiBKGeuMpt120RFNuECl1wYcR2C85rGS5aK8w4QPNwX48If1VWgzXApHFkSMs4urLGuw2oe7VY76QdR3uvbT6SF5/u0k6WduGcnj72UmmF7dQcgevEIby/xakuitXVGE6enjtc/ggkbXlMZFyJhRq/YiBHrX+Q+RIb7rjQDbNiTqPgt5vrgzDLHpTXAQ2ewpHKDtyd8Ed7RjFJr2QkOFu9WWd20r3H9/P5EgKCPOfCDnl X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: 996aa739-f520-4134-c846-08db948df0ae X-MS-Exchange-CrossTenant-AuthSource: HE1PR0402MB3497.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Aug 2023 01:55:55.3884 (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: rYcKUvZ/pG2WWmsKZA8QzR1J3Nt6VILN8R4MyEW4xgQRlp4DrT4GjQSdghM0zhmsTgJqLbjYCJXRGXfOe+06Qg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: GV1PR04MB9085 Precedence: bulk List-ID: X-Mailing-List: selinux@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. Acked-by: Yonghong Song Reviewed-by: Matthieu Baerts Signed-off-by: Geliang Tang --- tools/testing/selftests/bpf/prog_tests/mptcp.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/bpf/prog_tests/mptcp.c b/tools/testing/selftests/bpf/prog_tests/mptcp.c index cd0c42fff7c0..4ccca3d39a8f 100644 --- a/tools/testing/selftests/bpf/prog_tests/mptcp.c +++ b/tools/testing/selftests/bpf/prog_tests/mptcp.c @@ -7,7 +7,7 @@ #include "network_helpers.h" #include "mptcp_sock.skel.h" -#define NS_TEST "mptcp_ns" +char NS_TEST[32]; #ifndef TCP_CA_NAME_MAX #define TCP_CA_NAME_MAX 16 @@ -147,6 +147,8 @@ static void test_base(void) if (!ASSERT_GE(cgroup_fd, 0, "test__join_cgroup")) return; + srand(time(NULL)); + snprintf(NS_TEST, sizeof(NS_TEST), "mptcp_ns_%d", rand()); SYS(fail, "ip netns add %s", NS_TEST); SYS(fail, "ip -net %s link set dev lo up", NS_TEST); From patchwork Fri Aug 4 01:55:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13341103 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 8CB30C00528 for ; Fri, 4 Aug 2023 01:56:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232585AbjHDB4M (ORCPT ); Thu, 3 Aug 2023 21:56:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58548 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230201AbjHDB4L (ORCPT ); Thu, 3 Aug 2023 21:56:11 -0400 Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05on2071.outbound.protection.outlook.com [40.107.22.71]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1FFDD1FF3; Thu, 3 Aug 2023 18:56:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=JLhqxM0FzbI6Y2DwUaXAyXh5F6SpxIvm9MYqEzaWwJDBDK5wO3dPoDtfea0m5aRTRih8dli1aLL7i+ihVOTAqHYKK6eqEBRk+TLsrbiL4ZrYRdkGTU7iE4yIhrYjKWSGCQ0TXL26H48gzbJaqhJp9sXrMVRrGN8xulmfeq9u+Nb2C5Wq4jNOAAI0sn0Z1kUJY82dErJdYXFEFioYl4O9nEbpszv78JPWWn8+Y8JRDg3Fe0JGd+N6KGkjiQpIx82Pl2EXIxt/Zm3wYlXVK29akJnWLverwDalfY81gtyegkZMfmCmmsF3mGP1T7w+BLK7SAvwTtYIEF73pWEDr6Cjbg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=67IJNZXR8xHZysLARhWEOYDwJ5zgZ1zmECZ/EfEhyXk=; b=mv9lMNUug2L09HQzGZEkBL57thMLpZ2uJqN7UrJKGSRZ58eeGfolgKBDXR/M3EXJsqlzf8KoIYLjsojpdmfBdodbX8IaO0K4jnTTaiJfjPnJY7UFSFvme4z5at1XrKiiaRxHaJ1nvkzZXzZJAnV3xz2azQm6wO67Oueja/omLnJYxNVOP5j2I5HFz3Nekyw7h1FkUmrKosWRge33935XRzsR8uZwZambej8zSlno+rSx5YZupaVQI6qMIb9ErKZcuSuCJOufhjYNTVRWk710d5YjiN4PDcdzlKWi1NQNNHlcaF+2yI4ze0dOheUVt4mLGhhotO38OmMcoTTucKu/Kg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=67IJNZXR8xHZysLARhWEOYDwJ5zgZ1zmECZ/EfEhyXk=; b=S40B4iz9iUqXGTsy9ku6U/JIdZnmeqygB84XvHQwHI0Z+HwO457To6yYLGxdQK8AAt+tj5WbgpWK/fDct6uClE9tIL1nZIitI+JYXvdV1zOlyGVKkVDzGhRxWigGNtZ4cMDAT1i39IZqLykm9b8bGAbWy4OhPMP6Xlyz9xU2isdgkrpUCneHy0MtxsFyjRlcXVTMj6NKbNnDlItp1FMdIxbNEPaCUvQco08Gi5ExxMnOZPSLOa7mNSomeXUzlTZymzuB9zAVILH6h8lDs/2LOBVAzIOLtFrGDIhUVxbbDlU+4aM2ZPcUxHbAgyokY2oaCGTPpgJ6B4VVMU+qzu7JJA== 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 GV1PR04MB9085.eurprd04.prod.outlook.com (2603:10a6:150:20::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6652.21; Fri, 4 Aug 2023 01:56:08 +0000 Received: from HE1PR0402MB3497.eurprd04.prod.outlook.com ([fe80::2867:7a72:20ac:5f71]) by HE1PR0402MB3497.eurprd04.prod.outlook.com ([fe80::2867:7a72:20ac:5f71%3]) with mapi id 15.20.6652.020; Fri, 4 Aug 2023 01:56:08 +0000 From: Geliang Tang To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Florent Revest , Brendan Jackman , Matthieu Baerts , Mat Martineau , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , John Johansen , Paul Moore , James Morris , "Serge E. Hallyn" , Stephen Smalley , Eric Paris , Mykola Lysenko , Shuah Khan , Simon Horman Cc: Geliang Tang , bpf@vger.kernel.org, netdev@vger.kernel.org, mptcp@lists.linux.dev, apparmor@lists.ubuntu.com, linux-security-module@vger.kernel.org, selinux@vger.kernel.org, linux-kselftest@vger.kernel.org, Yonghong Song Subject: [PATCH bpf-next v10 3/5] selftests/bpf: Add two mptcp netns helpers Date: Fri, 4 Aug 2023 09:55:45 +0800 Message-Id: <0cfa88a21dd907c2ab910d2c595d4ebc59bb93cd.1691113640.git.geliang.tang@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: References: X-ClientProxiedBy: SI2PR06CA0012.apcprd06.prod.outlook.com (2603:1096:4:186::13) To HE1PR0402MB3497.eurprd04.prod.outlook.com (2603:10a6:7:83::14) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: HE1PR0402MB3497:EE_|GV1PR04MB9085:EE_ X-MS-Office365-Filtering-Correlation-Id: 51bdfda3-b6b0-4a56-2007-08db948df80a X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: FWOm8Do1OrbDPUc/QqRbcp3+AcSnujK3hGDEKEe8rrpvzvHm9uNzBdVhYORQosPU/MFKZPtOJ/PZFU2r7Qn8LvLJWFDMlZQMN+rfXuZfgk77iw5QWRVgVQwqGmjbWIaF9Yp1AQjG6SNgsMesBk5zmdHWUnKolyA9NsWYJ8CaxI6+8IpeLQlWtPFkN+W2alYaj5jqTwJneHkgiZcJ0ikeUj69U7aSaROhZlIHc8HUzBrIucD9+OWx5rKvQOA0N5zORsZENIM/aCAIKT4cOe6Yx9h7bVN0IYckMkK9SexhCnMM1jlFzp2KTmMZtzruiAVtnn0TUCQWG2tPNEdBbXNTPHZ1VA3Ep7BpXG8+7H3Lac9RkCRoytMPpX7doDybWzuk44uZ8RpN1RyC1vD5neqiJzooZ01zm2ic61/n2OQqWy9NzHvspGICENm+AoIFmQhC+ZcejnRNql8JGYgysEFXLs1mR9YRv2ml1Xqn+pPdfjeTjrpyd/y/Xp626eZ2xJuhRQwT+nCx/l7WL72LBM3bL4nTE5SqYBNxIPvPH23KktNTqtyFSW/rZYT+GodO8HWc/75/xv+OU0egbGv/hP9kDI5OtOmJHIlD/64HdQ5bLP+JcI8/+us92sCMYkQdLPKw 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)(396003)(136003)(346002)(39860400002)(186006)(451199021)(1800799003)(6506007)(38100700002)(921005)(26005)(478600001)(8676002)(8936002)(5660300002)(7416002)(110136005)(44832011)(7406005)(41300700001)(66556008)(54906003)(4326008)(66946007)(66476007)(6512007)(6666004)(86362001)(316002)(6486002)(2616005)(36756003)(2906002)(83380400001)(13296009);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: UGiqfv337i3yDWBeoAf3UemlX3cNd7L/TDG1RHUxw/hH4fQytPOBTiWOZ9GZi7RY38ELZsRZzyTjxLvdiFTpWtW288jQ4Whr0DcpPNZVtnlOEAI6/imStOFa3/wb1/5sSKOjYQAa2a4Ek29oYLJkrQ9nm5/w18mr0Qb2ydc0MvN+THw38jMNQL+vtck3MlLW7KWDE/Pr3LzNtyL4EMdTyPqT/MPnuXxeSE+CLxgxLAKPKDIrlxfAkaQd5QwPgCS+tg8pMCFuED5cRle5AHNI0x7XItAqomiWh/dC3PZD8qGbY3YETZuB5gut1EQcSKpjywYCUdFijQu9e1fKW0YZT02Z2u+M8l+PllLVVItAanNc5aoafailoOfHHw1nsBrCN4kYRz0W88Rql+Y0Xs94I0Oyx5MpE26DEb0qGF20zUCh+PUtUc0eumYo3eZHb6qeyNc96sxqLg7Siqf1A29SUcxoPWXYwF4IWL3gK43b2X3bQ/tLDb614q3vAuXXmYbZa0NfEJlQy2sfXLqpkK52maFTi0nsFC90cJk2Zhf0RFc2IspV0wbsu35EO5tUssTNc4Ro9RCz3zGWXhVvfoUT37EnOEcBbOzoH0f55NSG8raix5o1pYfRlqDO3qYZ4IgG+JTl0/8Lmd+U8j5qnZ4+6RFZo0NVe5pJX7/vNKTXilfOmjRP+6q4CpB1PTKvuSzd0AleNIVE59CuKBuHxhe0vMbS6daChsvsxouEH/KrK4VwBCt6B4QUA8LkkHXGYCGqfoJ8zC3qG22hiTpWHw9WqCyYORmDQVxGz95KWEFrf6SR8cpsUF/uptv65vOTH2QpsfCDuAe0s/4ocLxauxfiYYIA+ly2/WOddaICVyfR6HXmpx6Kdoec+8r1brALsh1RbCYoJOaiA888q6wADRRgOnvdfmHWOlgCt90tGQ5GYVJrk/G1t3/0Ka463cQfYTjaMshvCAubZFfy26uxz44A/NsflhqgCE6FeSvI2Ulr9kEWqYICGOMe7Le6Dlq/NpeajSgi2abQ4zbZk+p8JDfZiYEZMaBEJy7VDT5M11kiQsJ7GqFUR05m5TjWwFgfGjo7A4adoI6GBbAJgANxc4TQA5hpcOPhEHYfHLaManMAcS56SZqtM3OzbeaoXeqDR+reiJLwxzMT1D85EzaF5RwDHI/S1v/96un5vYkIMfKoFmdslbDnZglFdSYDaiqJf4IulXd24T7f1qjOEyvtCoCPUuZvoUhBTFMyvGD0M02D/cwdCFCjDJi5/GIz8RZLv9vve2vhnuJ9F5pRixMMgrlVLBB8PqkPM8ljNMX+UcCXqAg7uo1yO93Aw07nq6BjihsWiU+pYLICqgLOt8SmjqGaaWi8xI5hu0b2hxBaSGSgbN3O3UvI9eoDo4nvmA/+DrMyPecvFRVn6rvZAXqHYyRpxg39NhyCyFXp9r51qoC18evfzPi02DHc6weHa5J04ICXVAMI658TM50djDDy6teAZiV11ctV/l9c1q0LhrLp+8SoTueXZpy+qR4kGMLBBWEIHUncgZh3G8SA21OneBWRjCP8h7FtDjers12jGlLgmnA/QnEM4xxfDi9TRsfwvY20 X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: 51bdfda3-b6b0-4a56-2007-08db948df80a X-MS-Exchange-CrossTenant-AuthSource: HE1PR0402MB3497.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Aug 2023 01:56:07.9049 (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: XP3WBoToEGQU4vsSRbUyVuEoYDEfJ25jQ8/bQKDPJx6w0YQlO+rfWpwuIkXcHuWELNC5XJvxACp+Vy7Duh5JUg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: GV1PR04MB9085 Precedence: bulk List-ID: X-Mailing-List: selinux@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. Acked-by: Yonghong Song Reviewed-by: Matthieu Baerts Signed-off-by: Geliang Tang --- .../testing/selftests/bpf/prog_tests/mptcp.c | 35 ++++++++++++------- 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/tools/testing/selftests/bpf/prog_tests/mptcp.c b/tools/testing/selftests/bpf/prog_tests/mptcp.c index 4ccca3d39a8f..4407bd5c9e9a 100644 --- a/tools/testing/selftests/bpf/prog_tests/mptcp.c +++ b/tools/testing/selftests/bpf/prog_tests/mptcp.c @@ -22,6 +22,26 @@ struct mptcp_storage { char ca_name[TCP_CA_NAME_MAX]; }; +static struct nstoken *create_netns(void) +{ + srand(time(NULL)); + snprintf(NS_TEST, sizeof(NS_TEST), "mptcp_ns_%d", rand()); + SYS(fail, "ip netns add %s", NS_TEST); + SYS(fail, "ip -net %s link set dev lo up", NS_TEST); + + return open_netns(NS_TEST); +fail: + return NULL; +} + +static void cleanup_netns(struct nstoken *nstoken) +{ + if (nstoken) + close_netns(nstoken); + + SYS_NOFAIL("ip netns del %s &> /dev/null", NS_TEST); +} + static int verify_tsk(int map_fd, int client_fd) { int err, cfd = client_fd; @@ -147,13 +167,8 @@ static void test_base(void) if (!ASSERT_GE(cgroup_fd, 0, "test__join_cgroup")) return; - srand(time(NULL)); - snprintf(NS_TEST, sizeof(NS_TEST), "mptcp_ns_%d", rand()); - SYS(fail, "ip netns add %s", NS_TEST); - SYS(fail, "ip -net %s link set dev lo up", NS_TEST); - - nstoken = open_netns(NS_TEST); - if (!ASSERT_OK_PTR(nstoken, "open_netns")) + nstoken = create_netns(); + if (!ASSERT_OK_PTR(nstoken, "create_netns")) goto fail; /* without MPTCP */ @@ -176,11 +191,7 @@ static void test_base(void) close(server_fd); fail: - if (nstoken) - close_netns(nstoken); - - SYS_NOFAIL("ip netns del " NS_TEST " &> /dev/null"); - + cleanup_netns(nstoken); close(cgroup_fd); } From patchwork Fri Aug 4 01:55:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13341104 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 CA546EB64DD for ; Fri, 4 Aug 2023 01:56:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231282AbjHDB4T (ORCPT ); Thu, 3 Aug 2023 21:56:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58590 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232571AbjHDB4S (ORCPT ); Thu, 3 Aug 2023 21:56:18 -0400 Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05on2068.outbound.protection.outlook.com [40.107.22.68]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EEC181FF3; Thu, 3 Aug 2023 18:56:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=TBn63rl8qbrDNqMdcAKF3wmjJp5ABr+oOlG1KM/5/BPbY+gEvLChZyKDyifHyE8sDVx4c2UY4R0u+AZCY3Mog0PeEcR3z6oCLLCGFkcwjQmNLNIyLMg2+48dYAEh4shulbS3rL4rFa0q2GV5Y/xT8B/B49S13mjac41KMk46Js+fTxHoStCRqD9S6BwZG9Z6SHMl3APu7hAX2+V3Jt2Jh8K0zbWUQnw5v8KOKBEm/nl7pSHXdBbFQ+LsS693uhglB3aLjUG4HdQ47fcvLk05CoTrlZwYwy9JIUUBJiEw9yB1jHFdtnihER4o5sNyexGGpOerxf+8l7OyiyQ4solEgA== 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=XHTJIrxZIXZNpiE/inZgiAPSfO6oiyUOLxGFu7G85oQ=; b=ZWodkb4FuwRhOnF31hv2NOc4m+zCFZxn2iBzAr+aYusqsAnYAUVV6zSn3tvv8tjyMjcHdEw4BubOg03+H0Cb9BMVDYygFc5bFw2JKJwrja8rYD7gNY1SSkvdj16QWO5pPDJIL3sL++1FL7SH+JroEC4I/zYVbaKq48G8achkWlJNMX2XJzmx5hJFZX3OI6wzVGCyK2nL2oVcECN52nk2kDf/QYr7R6FZugsDyCa5cA8W/GRrr22zR2W+xEY929Z7T+naOqcYctCKW29Xzo7HkcH5ffDFsSt0jkcg+JhMCusK35XDNSZS5UXKrxYizgPwZSFPbLOEiA5icm0etJCFHw== 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=XHTJIrxZIXZNpiE/inZgiAPSfO6oiyUOLxGFu7G85oQ=; b=hEV0QYne2FT61I3yzveRuogZPSIwcpOQgrvwSPRYkOENkIqj96WqCJ4O0CG8GcY9jJHA2yWLuBVFpPkIdT6RB3fBWsDRt4rdl26bLbmP0nrjw2M1I5aQHYdrfrzjPw7rp7vSeaxYwEF7vL8kzmjxMTGx+QE39i7G/QIMDe4WgK2GbDK+Ya2942SKPm5rg4lNFf/I+PsXm2QikN/ofjEPRyZvNbPH/p/YrYIMo3BLBWAVBzSR/yT1ZYXEI+wvKOLQvZ6pMaXfYBngwjiVvGImoBfqCXMFWLwsGR4UJ2l/+20ukjnffxWHYZHqkRIuhIiAVVqoSTf20ocJ2sbuv08FoQ== 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 GV1PR04MB9085.eurprd04.prod.outlook.com (2603:10a6:150:20::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6652.21; Fri, 4 Aug 2023 01:56: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.6652.020; Fri, 4 Aug 2023 01:56: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, apparmor@lists.ubuntu.com, linux-security-module@vger.kernel.org, selinux@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [PATCH bpf-next v10 4/5] selftests/bpf: Drop unneeded checks for mptcp Date: Fri, 4 Aug 2023 09:55:46 +0800 Message-Id: <5eecd03fc0eaecc19da6a40bb118690971a8a7a7.1691113640.git.geliang.tang@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: References: X-ClientProxiedBy: SI2P153CA0026.APCP153.PROD.OUTLOOK.COM (2603:1096:4:190::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_|GV1PR04MB9085:EE_ X-MS-Office365-Filtering-Correlation-Id: 3dc8b78c-ef32-4e48-e850-08db948dfc59 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: GmS4b3A6bzs2cwwL01omiq+e6fzJiodT3jtezTRP/r28zrnbnUtCnrjgM5WbinZAHmok+sPn2rvUmbx3XoioDBsx1kuqRf3Yt114uvlCdmPjkzp5BB8svKvxmA1DB4RF+C+mSfiAfTwXB6YNsQh93uErY/ns2KgfYuxgFqLVzimIGjMzgVaX/VXu0ByfVvra7Lh0rxOZFlONWgzX4ByQz6936gNOBuE5Xlv+3ACKis1MvsHqaSRus930P2HcWZGvdeKY+KoHRotCfOo67aKBJYgo1B92FZ3GSjtD+R63Kt45v+mK9InpL+29Ny/mRvuawkqenfFNecxVsW5sBlm2D935+7M/DxDOmIPZHEMAIf7FWDsjnpwPt4nmGF6XmIqRi21w4CvVPKA9jP2AtG0+G9jLbdXEMWk7/BIY6LJNvkaXDwhP9IL7K9gzNiAwJW4HBiPP8xeKhhCsEF6IRLpzWiU5/jlhfclp0/NqfwHvMROYDPmEotpAg334ByemKK+A4CnffoUFthYZ6WmBCx5j/7fpewyXwG3xxOV2fTfDvPlbb2QJW14YEHi0eqaQgd+JvOEfQ/S96sDxgSmxvSd9KCnEo5JyKe/MDV2FKANP3Eyg/+Zty5OCNmNmsUB3/K9PceoBoKAGMJidruIJ/9kRUQ== 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)(396003)(136003)(346002)(39860400002)(186006)(451199021)(1800799003)(6506007)(38100700002)(921005)(26005)(478600001)(8676002)(8936002)(5660300002)(7416002)(110136005)(44832011)(7406005)(41300700001)(66556008)(4326008)(66946007)(66476007)(6512007)(6666004)(86362001)(316002)(6486002)(2616005)(36756003)(2906002)(83380400001)(13296009)(17423001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: TeSwqpsY3PJ86nAjAoQiVrzV+wBjeQi1i32FV6073HZkTsujPRC+AM0B8xCggF6kaWoI04QpWHpTLjSD0TmIFwFxiICwa5k3SS2qi+jxw1MA/ZPhJd9Yok+ezOC0bRqa9yqXoCoeP/nYtqS+grd6JH9dQ3ceJfAmBBnx/uowR9QMQ7kL3SBh4uKe/PB9hUCMdlJfcbPhu68VXvlSYjQK5Qu00wrvwyOrDfFMjOQuTCDtDA88S8apj7DZa1n/UKVthC8DgZQb3rxw2fUOo8KtVegbEugpH92lscqYydKEiZG4UU4OiJdFjJCzcZFpaJB57geOwuzKJg4H/8Zs+C+mkxkUE6RlNM8ZZrmtBF/LkeSXmzc7ixKj9IEbWypJbBfN7D4uCWK5FdpWRLqVV7m0F47mQEQxgREej+vLhMbaPfShBs+OEQVtIfxnBqzU4byJD5hd2rB34rgzQWIcG4z8tIY9FOPShAmG9XCQIqQs3bZ+RUNU4MRu2yA3yVJZbkF30v5O5YczWg/+b5Zuk3T5SQgKXcCidwANefQvIhVkauIVZIar1oGI3HOYeu4ifXodN9vKKbOgshiTde/tPJJYvR6Lpede1CwINvWncASIYPWI+E9HBzcGE5RSu0ySANrhzjcQTMi9zbU1pafYByp2/a38OmoPfBjnCnkDWE+KNMHFWJdjmeF2Z+cER+C3f/7wiYUSmxJb/FqQZq+2tpVJs008ijRZZUU613EVrzqRzucTnElvD5NLbTvY1++epNbOp4P/q+5TaYqS/y7jdaZf3RsMwxGx0tks5JiZpV3kXY3K2QD+eCqdomv6/uKJBjQF8PRT8+5in1jkcz/Huz/+OpblL/dXGlHwUblfdyidoFKy1HS/ZM0u17Xd2Qrr+5cJranB57PuQmn7sk+WCIBFl3zXL3nMp1GGk7s2i51W1eCOJWutyYWGtpKROzmd+sPardVHHttRWi9fL4RSX6WZNqsX+vJEt1XXn4ZloACSGUEKzP4Ti+DUKY39sq/digkHa3xzzH/HlhtTOE9YeugctFwc8CbM6uQLwgjtg9OhvrSCWJwD5ivaOSUf5Gt2RD36jpPEK9ocnBImI8gkQWNSZUOpW7PEAd+gEpKo1xHZi/xGpgfMFPZ8VDzb9BbvB1J3oSgvSXXvrRk949epY5gRnhpvaryKpRZfI5tbeXU3Shfplz4dZT5yCk+XAVRdt1SZvDIWOy905jhE4VYD2UTqZOSuDfEwJsfRHgqg2bALhiqo9RppSmlfN/WUJIHJpF6/oT1dD+3qpJs2sL4x52CJk0OvQxwm9AiTt7n6/w/JgjlcWeIyKNOVx3ndZ31ACeHO49/WIue9jEicJ360JrU7SAvh8S13QdO5GrUzO2VjnP3nabTp0csLLUxzNXjmRhWKbfAQ/QvT0RMrY75Frirk8mvt7jN0zr7uIpb4i9oTMbOAooVnUkje/khk/U1HaJ9h3HfFL4vVWjqWrfcmJ+8/RHimeJMX7vP2qPhMahAQsj0zo68e/SU8jtOBCuccUfK4uwTO07tU+zv7vxHUMbZMb9O7VQHxPrBOBDcklLW+HuSBwrRcL4vg2NaNbpMBDDeR X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: 3dc8b78c-ef32-4e48-e850-08db948dfc59 X-MS-Exchange-CrossTenant-AuthSource: HE1PR0402MB3497.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Aug 2023 01:56:14.9632 (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: PUwXXrHJqekSBus3MGUd3IaN+e9MIEQyZR2hhvDXV6S7bTuwukE1yMoNdS1PpdlmN8DQMdB7uh/TgJ6G01k0Dg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: GV1PR04MB9085 Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org Load success means prog_fd and map_fd are always valid. So drop these unneeded ASSERT_GE checks for them in mptcp run_test(). Signed-off-by: Geliang Tang Acked-by: Yonghong Song --- tools/testing/selftests/bpf/prog_tests/mptcp.c | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/tools/testing/selftests/bpf/prog_tests/mptcp.c b/tools/testing/selftests/bpf/prog_tests/mptcp.c index 4407bd5c9e9a..3dc0ba2e7590 100644 --- a/tools/testing/selftests/bpf/prog_tests/mptcp.c +++ b/tools/testing/selftests/bpf/prog_tests/mptcp.c @@ -127,17 +127,7 @@ static int run_test(int cgroup_fd, int server_fd, bool is_mptcp) goto out; prog_fd = bpf_program__fd(sock_skel->progs._sockops); - if (!ASSERT_GE(prog_fd, 0, "bpf_program__fd")) { - err = -EIO; - goto out; - } - map_fd = bpf_map__fd(sock_skel->maps.socket_storage_map); - if (!ASSERT_GE(map_fd, 0, "bpf_map__fd")) { - err = -EIO; - goto out; - } - err = bpf_prog_attach(prog_fd, cgroup_fd, BPF_CGROUP_SOCK_OPS, 0); if (!ASSERT_OK(err, "bpf_prog_attach")) goto out; From patchwork Fri Aug 4 01:55:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13341105 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 7914CEB64DD for ; Fri, 4 Aug 2023 01:56:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232571AbjHDB40 (ORCPT ); Thu, 3 Aug 2023 21:56:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58644 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232122AbjHDB40 (ORCPT ); Thu, 3 Aug 2023 21:56:26 -0400 Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05on2072.outbound.protection.outlook.com [40.107.22.72]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A2EA1448B; Thu, 3 Aug 2023 18:56:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=eiL7ZnljGRyMxUp4LzhU7/r/IKLo3yE7d0crX5HqJ5h1umQUx9k2+OejXtz2jBpLA8jGHbd68CE6HPubXo2vn/1hImOmwh+BxcNVZ9ix+/jHsIJWgIoMYm2mas2RGFcoWIXNNLklmPa5+4qwFxJ06EOsjVzRoCRd6J43KW4BVekjDgaGD2uWh1mzu7x+ST/tqzOQwCjXdlE2ZyGKVTEr0BMRHc4HgYKp96eKXiaWhMHXAA6VRYjWiwhsugNms953qLiP1h3EG4TnZSrjJqulqOURBdDneQQuc8Sku1+Cz6e/jUksMMkgNS6IN8DFHu9yrEwxstlnJp9yCyy9HqWyKQ== 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=qaZlExH8xswLU7fz/Py3NIyuDYG7Admr8DChIytTejs=; b=GFPGjGfZiLC06VXcJuBwUFomT60CxCXrwl50W9tm95pklE6buJ7wJ87kAUTlYCTXHLPDSG95lfYSz2lT4kUJAFVg/ePJ2q2WDKG05mAGBUGZRH7A03A1jI/7wWOnJXROKEuS3LWqwhAFxz9iWQSsCKkk2Xn1CWPf+b7RN5urv5yB2fhhPpIijIuoKvm5iSYyaN575Dtr1gssLPQ50PH3M4rIZchI/O2VtSNiJvHVZkU1eGxpBwPwAe3iKAnO4ipbpbTHtj8nKcI1NPS2AKl4QkMGURzPYVENEFwv7U5pGkTIGex07/bpvWUeYBq6L1MpM4RCDUxYOx9cK8y6gxKxkQ== 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=qaZlExH8xswLU7fz/Py3NIyuDYG7Admr8DChIytTejs=; b=de99LX6grtoBGKbRG6O3oQCpOtg9ehlRjyPB5/JTzm+bCf3+7GyWSCX55WACaE0joIQ9InMrONdzeunmmrMUsg4mw1VSq4X9esxGpelhXNmqzS1QVSCgONX2kSvqetMhmFDL2oHXgYFFfFiPYr4rdfUcCCuDTibLop5hCc3JGemIq96buazLJA92vkBD11LkK8En1hA9Q0jiKtn1yjNtChlkUesBYTJnj52K1FRkMBQ100NlOifm00+z+ODQyaRaXMlBWkKNDiOZnWOn9GnP/B1kZHM/q1mz7vlp56rl8w2QXFe7p8k/oQlrea/HIOF+VZjQCIZIBcxsjvczdIfRFQ== 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 GV1PR04MB9085.eurprd04.prod.outlook.com (2603:10a6:150:20::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6652.21; Fri, 4 Aug 2023 01:56:22 +0000 Received: from HE1PR0402MB3497.eurprd04.prod.outlook.com ([fe80::2867:7a72:20ac:5f71]) by HE1PR0402MB3497.eurprd04.prod.outlook.com ([fe80::2867:7a72:20ac:5f71%3]) with mapi id 15.20.6652.020; Fri, 4 Aug 2023 01:56:22 +0000 From: Geliang Tang To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa , Florent Revest , Brendan Jackman , Matthieu Baerts , Mat Martineau , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , John Johansen , Paul Moore , James Morris , "Serge E. Hallyn" , Stephen Smalley , Eric Paris , Mykola Lysenko , Shuah Khan , Simon Horman Cc: Geliang Tang , bpf@vger.kernel.org, netdev@vger.kernel.org, mptcp@lists.linux.dev, apparmor@lists.ubuntu.com, linux-security-module@vger.kernel.org, selinux@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [PATCH bpf-next v10 5/5] selftests/bpf: Add mptcpify test Date: Fri, 4 Aug 2023 09:55:47 +0800 Message-Id: X-Mailer: git-send-email 2.35.3 In-Reply-To: References: X-ClientProxiedBy: SI2PR01CA0001.apcprd01.prod.exchangelabs.com (2603:1096:4:191::13) To HE1PR0402MB3497.eurprd04.prod.outlook.com (2603:10a6:7:83::14) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: HE1PR0402MB3497:EE_|GV1PR04MB9085:EE_ X-MS-Office365-Filtering-Correlation-Id: 7eead2ba-998f-458c-d9b7-08db948e0091 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: PebSSmdsCSqb6gaOSYjnT1avmhOvt1Z03zjkeU3E5yoAopKI/7cmIC/8Zyxvm6oAXqM1TPtb9kjYq8ZhbbhV9z9A2NbQRrb/4efXPax70eWlqIbMqCSm8n0h9TOLc898/DQsLG8v1+JhV491FFkckWWL9O6k8EPx1WW54l4n9bD6eR3ZAJT32I3cUNxKH85bG19o3LAzxxJBM5s5Tb62pV/xTYN3Ql584ihSSk40Lu2q+TFZ8joDyeaT+bhIiQbAdlpDSBZs5VImA7JbBEXgkjmMQAMgFMCNCBNv8D4fkcYzH6xXNz6a1c/XC8oEL0URhcasiOoNIYYYp78ginaIbdqpqIX46lsOLFa/Duo/wxSVCA0FP5qlYWOeQXCHlQOeFuhtl7bQwNwEhGZw+ebAxzu2/HwMSr8zcYOe7yKhTWe5CBa8HMV6oW88Nwl06qwDM9O4KjS6Qwb/+5q6stjHUvQTHI2tbIf8364xarnLe5zP1kiHeA2tBap6eDAVnbnurva7y5icg521kudKG+wOREvacOLJk/37PDhkClZsu6F5bJufSfwl7VXIyOFD9BwNbeVfmECpeE+kOGEURGf3GiyQB/flN/b8L/9o7Y4SJ9LwVfAGuaHlaZlsz1IrskwW 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)(396003)(136003)(346002)(39860400002)(186006)(451199021)(1800799003)(6506007)(38100700002)(921005)(26005)(478600001)(8676002)(8936002)(5660300002)(7416002)(110136005)(44832011)(7406005)(41300700001)(66556008)(4326008)(66946007)(66476007)(6512007)(6666004)(86362001)(316002)(6486002)(2616005)(36756003)(2906002)(83380400001)(13296009);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: tQVpiMVx+hnYUpVd3+9GG1vgYlL+e6T78kTiR4agfDow1IemjIw6x21GDHefGQo7SQ9AVnW7yykqqGEjl10UIZkn4MfG3By84VFtrBri7kjmKKakndTMSplo1qNocaH9gpbHn3FkF0xxee3pVu6st829KiDt/SPhvUvKmVwuoNJBN6SH+IfctaQGuihcrHqQCwyFeWTB3D/4oz6oOZ8+bgjnyBvumJe4JQXaMT71qaGRgkoVBYVqIHpO8cXVKb6IZLN3vUB6lguF02C66uJzYWYwOlzn8YaElR24s6ifSikG1qgWL1uDuB/W33D6+qTRfuwt89lZVdHHtkXeboSVaGw3A06WHYjnHDqKyouCmw2LL9/LMWHhO89thEj/zz5/hrTPSfHrQJd2/Std/ZQAPOTyRsW21Ug2VBWolUcReKxjrULvZeuPylafJBcLU//2hIYW3tthrPq1b8T/MRkRaCBWdXh8sOdSYyLBZnzHqOUfAOn2cMGrMPSfD2JeLc9TVEOEKbXqZ+dasVHETPvtfGGAs6DieFsziMIZYREKwI2gMbc7Xz2jaL3zmUG0SPv2M8rN8dSRKfF1qs+6uXkjwHC7/yG/i/TH3/7QlFHAZH6wjbKkheKuUcJcjAumqqEPRoF5/OSA3bvy8oQ06A+XnL5P/eO1yvYMZvUHPuw+Eue+NQbnbZZk/WcJYHbaerBv/ltEWrC35Tf9xrBvssSqgl82UOEgucFsBYDyDEMipulfdGGEzXM+dQs7ynlE/81HjjfIV+cehznv3q+tPcQArtWY0Bkd8ffW0Qivnkfadsj/i7b1wZMBLxzqO6OorZDCFWzx6Ko1k/QvYQCT6m7jjUcTsAFiHzG/bJG5+FiHRgPNPbzSTLTNyTCW9eFTJMicSo9KTznQ25P52Lf5n9ZcQiiSIKwaigIsSKDk6fbH+yCk0qUHCwH+390PjLcef3eqJs5Oo0yFl6cXhbkEiYh600UkDrHYUhen166sbsXjQCb0jD8rXhpCNlQR6oxm83JyqXx7wMxy9l6QXLt4zKr2IFqyB7jjcxpyRiTGoQqA1GLB5sFauuFDntvHeir2KdmU9cS3VRLm2vwrNVfwo0bCxia2spjQlrfJ5oZRYuGYsN9C61J6wmUP64i9jFTZIvOAoOjksnQmtQkYu8ErgnWRx0HwLsRJNJPWZ2v42YJaCU0tUpzp0MnoTHYHY2cQDM2QZdsPfM+7mKvwnCONe12Ds++5/j0ocBgrNcS/bBqbrkZsNkdHwZk+FK49socCBn1P8xc0JMNnE3TEP4TipAkhnom/xQQAG7oGon4S+YZAGw0tR5hrSKoAyg1EilMKp4BLcwZ452p0zn6P3U9dvkjNltFp2aknrZrhSFkFkmvyyAnrERY4x9FS4B+2oQ350o3jh3Pjis11EHHq/M1GS1J1BPW2grhMT2NI++/YmFyqONbFA9mkZJ6Ojb7cudx2rNGIPULnOdn5dDD3yKMFqkiOCOg6KUT54nn98ufK77hl28zsR1HkFPseYhoGACRD829PxhfWdCKR8DyX5JmSDM21hSZg0XM5+pDCHcVDYtAUWH9h0pY2QpgGa5vm/bPbRAeT X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: 7eead2ba-998f-458c-d9b7-08db948e0091 X-MS-Exchange-CrossTenant-AuthSource: HE1PR0402MB3497.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Aug 2023 01:56:22.2224 (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: oInnuNlV9p/BekQrprBmz/aslcRT1i3iKjN38qeV029MeXHDHrDHXx8F08j/OawRF0UhfqMN13UkyR1kIZ2bLA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: GV1PR04MB9085 Precedence: bulk List-ID: X-Mailing-List: selinux@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. Reviewed-by: Matthieu Baerts Signed-off-by: Geliang Tang Acked-by: Yonghong Song --- .../testing/selftests/bpf/prog_tests/mptcp.c | 88 +++++++++++++++++++ tools/testing/selftests/bpf/progs/mptcpify.c | 20 +++++ 2 files changed, 108 insertions(+) create mode 100644 tools/testing/selftests/bpf/progs/mptcpify.c diff --git a/tools/testing/selftests/bpf/prog_tests/mptcp.c b/tools/testing/selftests/bpf/prog_tests/mptcp.c index 3dc0ba2e7590..e5ac2c3aab7d 100644 --- a/tools/testing/selftests/bpf/prog_tests/mptcp.c +++ b/tools/testing/selftests/bpf/prog_tests/mptcp.c @@ -6,6 +6,7 @@ #include "cgroup_helpers.h" #include "network_helpers.h" #include "mptcp_sock.skel.h" +#include "mptcpify.skel.h" char NS_TEST[32]; @@ -185,8 +186,95 @@ 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, err = 0; + struct mptcpify *mptcpify_skel; + + mptcpify_skel = mptcpify__open_and_load(); + if (!ASSERT_OK_PTR(mptcpify_skel, "skel_open_load")) + return -EIO; + + err = mptcpify__attach(mptcpify_skel); + if (!ASSERT_OK(err, "skel_attach")) + goto out; + + /* without MPTCP */ + server_fd = start_server(AF_INET, SOCK_STREAM, NULL, 0, 0); + if (!ASSERT_GE(server_fd, 0, "start_server")) { + err = -EIO; + goto out; + } + + client_fd = connect_to_fd(server_fd, 0); + if (!ASSERT_GE(client_fd, 0, "connect to fd")) { + err = -EIO; + goto close_server; + } + + send_byte(client_fd); + err += verify_mptcpify(); + + close(client_fd); +close_server: + close(server_fd); +out: + mptcpify__destroy(mptcpify_skel); + return err; +} + +static void test_mptcpify(void) +{ + struct nstoken *nstoken = NULL; + int cgroup_fd; + + cgroup_fd = test__join_cgroup("/mptcpify"); + if (!ASSERT_GE(cgroup_fd, 0, "test__join_cgroup")) + return; + + nstoken = create_netns(); + if (!ASSERT_OK_PTR(nstoken, "create_netns")) + goto fail; + + ASSERT_OK(run_mptcpify(cgroup_fd), "run_mptcpify"); + +fail: + cleanup_netns(nstoken); + close(cgroup_fd); +} + void test_mptcp(void) { if (test__start_subtest("base")) test_base(); + if (test__start_subtest("mptcpify")) + test_mptcpify(); } diff --git a/tools/testing/selftests/bpf/progs/mptcpify.c b/tools/testing/selftests/bpf/progs/mptcpify.c new file mode 100644 index 000000000000..53301ae8a8f7 --- /dev/null +++ b/tools/testing/selftests/bpf/progs/mptcpify.c @@ -0,0 +1,20 @@ +// SPDX-License-Identifier: GPL-2.0 +/* Copyright (c) 2023, SUSE. */ + +#include "vmlinux.h" +#include +#include "bpf_tracing_net.h" + +char _license[] SEC("license") = "GPL"; + +SEC("fmod_ret/update_socket_protocol") +int BPF_PROG(mptcpify, int family, int type, int protocol) +{ + if ((family == AF_INET || family == AF_INET6) && + type == SOCK_STREAM && + (!protocol || protocol == IPPROTO_TCP)) { + return IPPROTO_MPTCP; + } + + return protocol; +}