From patchwork Thu Jul 6 08:19: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: 13303333 X-Patchwork-Delegate: bpf@iogearbox.net Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E965E1FBA for ; Thu, 6 Jul 2023 08:19:56 +0000 (UTC) Received: from EUR04-HE1-obe.outbound.protection.outlook.com (mail-he1eur04on2059.outbound.protection.outlook.com [40.107.7.59]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3B9351988 for ; Thu, 6 Jul 2023 01:19:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=hSIn4ZfDD72mfllZi8g36HqmUGybZ93dhLXbSJHxRCXyJJdYGODnHcoQfEt/JmrOHsPIuIV6dIu2ahXqal+zFngyUninpfxEAvIXKs4PKEGjB/apSzBXKWQG6VRA+8td5Obb/UIBzULo/pH7nxnoRLCFgVA819duh4FfXGSD+pvJfN/VNAtz3SWNUpZwMtaOavcQYzDvKAb2J7dvy3BKVEWpHXMRzjP3iXHaYV2EFmL7jTSWtBi+5SrEA9wYI+WAtvJ43Xs7ujzGQncGaB4ck6X6I+8S4yid+v1qhfotS//6+g5D/FlxY8zE+IOWjoaEUjnRomFeps2tE8kcn01dIg== 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=oWM3md3G+KvRxqHdGU4Y07ll+NwhSVoOjfCi91FN6Zo=; b=hgkbrywi4xbZf9u+EA6b3rDLsxI1vcm4x7XRBQHSinNl8Iem8QIKq4uZ6f/EOEEzyG0qZigyybmKXKBN/T4cqpmWaHfZOGTOqJR8UWANa2mLo39hW5uaQUMtn3qyGD62yTdynFy0EGpaotVTPKWYBvRDkhkfcrwF3YXlLKzFw+wFQs/a8ECEee42ahLYHj55tlYgl+gHxSeUgrsvVzv07YsVbPHsA9vhreu7vw4U6yM1o9XJsZPjUbUnzm84DKrbu7XWxWVXYjkhRBEpGIZWGasodhKHKuuDJThNRbLjfV2UWqzPvVHiSpGP3OgArw3dcuUQ1EYdl+GTFzcnvtF/ow== 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=oWM3md3G+KvRxqHdGU4Y07ll+NwhSVoOjfCi91FN6Zo=; b=r9HzSEiN8mbcAV1PKLkIToEZBHxuu0wfKj7C8dnRIuVB5tO1axF6cdCUKQ0sS/0WI0ozHMS9T3QcNPFMr9U4+eUO40/7tzXxh8/ocz4qxovvW+IL8BH+Hsp+sev2CSRCAfaKCNOaVEaUvoR4ub9r3rmyHuyCpSj3MJXQO0epdU1grm9fDGe9kEvAz3rE2BuTPYozHYBYcIhCmltjP1K9jy0sA3Om73wIZD2VREmnA32ypjl+9FuoBPbTyg83HHGS1azh80+uyTmHUAHSGT2IpR3asRhfmNW/CSWI/t+kUg+lAAoQbUs52xSV53PUGHJ+VXYI0wD+zEYihvJv+BUpag== 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 AM0PR04MB6897.eurprd04.prod.outlook.com (2603:10a6:208:184::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6565.17; Thu, 6 Jul 2023 08:19:51 +0000 Received: from HE1PR0402MB3497.eurprd04.prod.outlook.com ([fe80::423a:a30f:5342:9d35]) by HE1PR0402MB3497.eurprd04.prod.outlook.com ([fe80::423a:a30f:5342:9d35%6]) with mapi id 15.20.6565.016; Thu, 6 Jul 2023 08:19:51 +0000 From: Geliang Tang To: Alexei Starovoitov , Daniel Borkmann , John Fastabend , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa Cc: Geliang Tang , bpf@vger.kernel.org, mptcp@lists.linux.dev Subject: [RFC bpf-next v3 1/8] bpf: Add new prog type sockinit Date: Thu, 6 Jul 2023 16:19:40 +0800 Message-Id: <0880130fe8ba0d721e63f6d37bd8ff6311eed9bf.1688631200.git.geliang.tang@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: References: X-ClientProxiedBy: SI1PR02CA0016.apcprd02.prod.outlook.com (2603:1096:4:1f4::17) To HE1PR0402MB3497.eurprd04.prod.outlook.com (2603:10a6:7:83::14) Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: HE1PR0402MB3497:EE_|AM0PR04MB6897:EE_ X-MS-Office365-Filtering-Correlation-Id: 26d2a545-84af-4cc2-ae16-08db7df9c51a X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 2N3NzmYxNRng7Q1PKVX/IKe9FMWlA7mbEDsHitLtZZb5+5pPNmpmZz8DWbl1aWzgdHVo7a6f/AFJEhBDnEJ5nFNkDDZRQ+fFwjhc7brS32gzgUobF8Gkh7l1gi4AFTaINS1XpBYmZgOpib7rcff8+A33boAS0vOg5B4Z1awUvo0ZdHX7aN3LKkCScG6fOzGjJkTHPdIub8i8oVZh+F2fPazYAJ8wjbcHE9RzN7KECLYvCmkTFH38Vujg6rUNIWbeE+0TqTDEQudz3Lwx2JTGI8McBXm0319CTzBEsC0LnsnVDUqWq5dzGAeFTzxhaZeYusGaRhvUFU1Rf7i/JQAB6axf/gaVH/+4z4b3BYjy1zDZSzRXk1Iox6b1c8GAJiin6O6vupCdnMToOQVqtthR6TfdjI9wH0LJvVgR8Ws5+AGKltuDE7MwbsxsA9xRHpoAqwtVGy+tc2jnyfMs9oIt0iywUF/FSdsBvXYl5BZvmqiY2rZNIdNwPbJ2fkGvR3ZhkGQG3U+aKXF6wEeaqqHWFKAIFXugaLcJjFNfw1xzB0I708g3G8cOtTMfHbiT0KBuXD11bcL/jwRgLCDldm1oaTJMrxW74AHjTuXSdLHMU1/f4YlqpmeEzO9pGFtaqydN 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)(136003)(396003)(39860400002)(451199021)(7416002)(8936002)(8676002)(44832011)(83380400001)(41300700001)(5660300002)(2906002)(316002)(2616005)(66946007)(38100700002)(26005)(110136005)(4326008)(921005)(66476007)(66556008)(6512007)(86362001)(186003)(478600001)(6506007)(6666004)(36756003)(6486002)(13296009);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: glZvqbYbVyZ/xxavHSDqp5JAz7CixYL8HeQYJ5NaJ5wk30BGLP2r7HA5OE4HJ/lPw/71HGb01mXoTdGlSSDpzdxb4c78rLJojTnzngZBvYEBr/hvIkfo+MJOP9gQ+ZONU62chm3AY49Z91P885vCsyI9jUM8wTcLJFz6/axFNvetfi2hKFl7JBnbqxpXskXvOz3hckXkks7X2BXLawEo5msuqS0YVgObM/eMNVSG+SvLHyDgvEHP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se9i5mk4SCFXPhGt/tX5lM40O7YU4ZvTxSKuAOQKNBbvftx1PZKiYsDfsZme9zXjg0OmH6fEkfz7eaybFxO7Q63Iitivul1o814mDABsI6O5m9lgC2+fQLWxhS5dk3Tm8/R9dMZ6z/g2N5PWvmHkTr+Lp31qITG12/m2HmHXecL+kmftw6n5R1RrdwsYfI+OgFY4oApzP/hrR/mFbbdrIDGfq1pMH+pjEcp24kumV0yh2KtXed57WHHDa+q++fUK2kksBgyz6yonCUQr6 X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: 26d2a545-84af-4cc2-ae16-08db7df9c51a X-MS-Exchange-CrossTenant-AuthSource: HE1PR0402MB3497.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Jul 2023 08:19:51.3715 (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: QmLtQ3xybGZnsfiptJhjw3oioVURIVueDGtWQa4vgMOr2ID1a8KFlwHd8ME1CMiZ5eP5bAV749IKaF7dv02xLQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR04MB6897 X-Spam-Status: No, score=-1.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FORGED_SPF_HELO, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: bpf@iogearbox.net X-Patchwork-State: RFC The patch introduces new program type BPF_PROG_TYPE_CGROUP_SOCKINIT and attach type BPF_CGROUP_SOCKINIT on cgroup basis. Define this program by BPF_PROG_TYPE(), and implement two operations: cg_sockinit_prog_ops and cg_sockinit_verifier_ops. Signed-off-by: Geliang Tang --- include/linux/bpf_types.h | 2 ++ include/uapi/linux/bpf.h | 8 +++++ kernel/bpf/cgroup.c | 66 +++++++++++++++++++++++++++++++++++++++ kernel/bpf/syscall.c | 7 +++++ kernel/bpf/verifier.c | 1 + 5 files changed, 84 insertions(+) diff --git a/include/linux/bpf_types.h b/include/linux/bpf_types.h index fc0d6f32c687..07e1f21e82e9 100644 --- a/include/linux/bpf_types.h +++ b/include/linux/bpf_types.h @@ -56,6 +56,8 @@ BPF_PROG_TYPE(BPF_PROG_TYPE_CGROUP_SYSCTL, cg_sysctl, struct bpf_sysctl, struct bpf_sysctl_kern) BPF_PROG_TYPE(BPF_PROG_TYPE_CGROUP_SOCKOPT, cg_sockopt, struct bpf_sockopt, struct bpf_sockopt_kern) +BPF_PROG_TYPE(BPF_PROG_TYPE_CGROUP_SOCKINIT, cg_sockinit, + struct bpf_sockinit_ctx, struct bpf_sockinit_ctx) #endif #ifdef CONFIG_BPF_LIRC_MODE2 BPF_PROG_TYPE(BPF_PROG_TYPE_LIRC_MODE2, lirc_mode2, diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h index 60a9d59beeab..cb882ab8065d 100644 --- a/include/uapi/linux/bpf.h +++ b/include/uapi/linux/bpf.h @@ -980,6 +980,7 @@ enum bpf_prog_type { BPF_PROG_TYPE_CGROUP_SYSCTL, BPF_PROG_TYPE_RAW_TRACEPOINT_WRITABLE, BPF_PROG_TYPE_CGROUP_SOCKOPT, + BPF_PROG_TYPE_CGROUP_SOCKINIT, BPF_PROG_TYPE_TRACING, BPF_PROG_TYPE_STRUCT_OPS, BPF_PROG_TYPE_EXT, @@ -1013,6 +1014,7 @@ enum bpf_attach_type { BPF_CGROUP_UDP6_RECVMSG, BPF_CGROUP_GETSOCKOPT, BPF_CGROUP_SETSOCKOPT, + BPF_CGROUP_SOCKINIT, BPF_TRACE_RAW_TP, BPF_TRACE_FENTRY, BPF_TRACE_FEXIT, @@ -6829,6 +6831,12 @@ struct bpf_raw_tracepoint_args { __u64 args[0]; }; +struct bpf_sockinit_ctx { + __u32 family; + __u32 type; + __u32 protocol; +}; + /* DIRECT: Skip the FIB rules and go to FIB table associated with device * OUTPUT: Do lookup from egress perspective; default is ingress */ diff --git a/kernel/bpf/cgroup.c b/kernel/bpf/cgroup.c index 5b2741aa0d9b..93b9f404a007 100644 --- a/kernel/bpf/cgroup.c +++ b/kernel/bpf/cgroup.c @@ -2505,6 +2505,72 @@ const struct bpf_verifier_ops cg_sockopt_verifier_ops = { const struct bpf_prog_ops cg_sockopt_prog_ops = { }; +static const struct bpf_func_proto * +cgroup_sockinit_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog) +{ + const struct bpf_func_proto *func_proto; + + func_proto = cgroup_common_func_proto(func_id, prog); + if (func_proto) + return func_proto; + + func_proto = cgroup_current_func_proto(func_id, prog); + if (func_proto) + return func_proto; + + switch (func_id) { + default: + return bpf_base_func_proto(func_id); + } +} + +static bool cgroup_sockinit_is_valid_access(int off, int size, + enum bpf_access_type type, + const struct bpf_prog *prog, + struct bpf_insn_access_aux *info) +{ + const int size_default = sizeof(__u32); + + if (off < 0 || off + size > sizeof(struct bpf_sockinit_ctx)) + return false; + + if (off % size != 0) + return false; + + switch (off) { + case bpf_ctx_range(struct bpf_sockinit_ctx, family): + bpf_ctx_record_field_size(info, size_default); + if (!bpf_ctx_narrow_access_ok(off, size, size_default)) + return false; + break; + case bpf_ctx_range(struct bpf_sockinit_ctx, type): + bpf_ctx_record_field_size(info, size_default); + if (!bpf_ctx_narrow_access_ok(off, size, size_default)) + return false; + break; + case bpf_ctx_range(struct bpf_sockinit_ctx, protocol): + if (type == BPF_READ) { + bpf_ctx_record_field_size(info, size_default); + return bpf_ctx_narrow_access_ok(off, size, size_default); + } else { + return size == size_default; + } + default: + if (size != size_default) + return false; + } + + return true; +} + +const struct bpf_verifier_ops cg_sockinit_verifier_ops = { + .get_func_proto = cgroup_sockinit_func_proto, + .is_valid_access = cgroup_sockinit_is_valid_access, +}; + +const struct bpf_prog_ops cg_sockinit_prog_ops = { +}; + /* Common helpers for cgroup hooks. */ const struct bpf_func_proto * cgroup_common_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog) diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c index a2aef900519c..2952dd88c614 100644 --- a/kernel/bpf/syscall.c +++ b/kernel/bpf/syscall.c @@ -2513,6 +2513,7 @@ static bool is_net_admin_prog_type(enum bpf_prog_type prog_type) case BPF_PROG_TYPE_CGROUP_SOCK_ADDR: case BPF_PROG_TYPE_CGROUP_SOCKOPT: case BPF_PROG_TYPE_CGROUP_SYSCTL: + case BPF_PROG_TYPE_CGROUP_SOCKINIT: case BPF_PROG_TYPE_SOCK_OPS: case BPF_PROG_TYPE_EXT: /* extends any prog */ case BPF_PROG_TYPE_NETFILTER: @@ -3574,6 +3575,8 @@ attach_type_to_prog_type(enum bpf_attach_type attach_type) case BPF_CGROUP_GETSOCKOPT: case BPF_CGROUP_SETSOCKOPT: return BPF_PROG_TYPE_CGROUP_SOCKOPT; + case BPF_CGROUP_SOCKINIT: + return BPF_PROG_TYPE_CGROUP_SOCKINIT; case BPF_TRACE_ITER: case BPF_TRACE_RAW_TP: case BPF_TRACE_FENTRY: @@ -3640,6 +3643,7 @@ static int bpf_prog_attach(const union bpf_attr *attr) case BPF_PROG_TYPE_CGROUP_SOCK_ADDR: case BPF_PROG_TYPE_CGROUP_SOCKOPT: case BPF_PROG_TYPE_CGROUP_SYSCTL: + case BPF_PROG_TYPE_CGROUP_SOCKINIT: case BPF_PROG_TYPE_SOCK_OPS: case BPF_PROG_TYPE_LSM: if (ptype == BPF_PROG_TYPE_LSM && @@ -3682,6 +3686,7 @@ static int bpf_prog_detach(const union bpf_attr *attr) case BPF_PROG_TYPE_CGROUP_SOCK_ADDR: case BPF_PROG_TYPE_CGROUP_SOCKOPT: case BPF_PROG_TYPE_CGROUP_SYSCTL: + case BPF_PROG_TYPE_CGROUP_SOCKINIT: case BPF_PROG_TYPE_SOCK_OPS: case BPF_PROG_TYPE_LSM: return cgroup_bpf_prog_detach(attr, ptype); @@ -3726,6 +3731,7 @@ static int bpf_prog_query(const union bpf_attr *attr, case BPF_CGROUP_SYSCTL: case BPF_CGROUP_GETSOCKOPT: case BPF_CGROUP_SETSOCKOPT: + case BPF_CGROUP_SOCKINIT: case BPF_LSM_CGROUP: return cgroup_bpf_prog_query(attr, uattr); case BPF_LIRC_MODE2: @@ -4717,6 +4723,7 @@ static int link_create(union bpf_attr *attr, bpfptr_t uattr) case BPF_PROG_TYPE_CGROUP_DEVICE: case BPF_PROG_TYPE_CGROUP_SYSCTL: case BPF_PROG_TYPE_CGROUP_SOCKOPT: + case BPF_PROG_TYPE_CGROUP_SOCKINIT: ret = cgroup_bpf_link_attach(attr, prog); break; case BPF_PROG_TYPE_EXT: diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c index 11e54dd8b6dd..d0ade7759123 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -14316,6 +14316,7 @@ static int check_return_code(struct bpf_verifier_env *env) case BPF_PROG_TYPE_CGROUP_DEVICE: case BPF_PROG_TYPE_CGROUP_SYSCTL: case BPF_PROG_TYPE_CGROUP_SOCKOPT: + case BPF_PROG_TYPE_CGROUP_SOCKINIT: break; case BPF_PROG_TYPE_RAW_TRACEPOINT: if (!env->prog->aux->attach_btf_id) From patchwork Thu Jul 6 08:19: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: 13303334 X-Patchwork-Delegate: bpf@iogearbox.net Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C30901872 for ; Thu, 6 Jul 2023 08:20:04 +0000 (UTC) Received: from EUR04-HE1-obe.outbound.protection.outlook.com (mail-he1eur04on2040.outbound.protection.outlook.com [40.107.7.40]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8D11C1BE3 for ; Thu, 6 Jul 2023 01:20:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ATKtQAyGDz/OS2YQ/gMV5hOw5FTvIujL9tPGcc6IvMsPA15hDpm1zVWh0VsFrrNsBdAJN3wu0f/rQmOwa/t38Y+xR1pN0vKWAptpPRtALabJHtxA1c1iuen6kewoGHLm/LNpdlRPs5iZK0NsdxKBsI8/ENpnZc2PJFPu5zmbxRVxKxRSd2+js8BYoBmmetHzVVu4VV8DYDxHSGZej+PFwIi/6fLO+D60Kb1dykZP4HcCc2UrjIa7kzh8j8lpfrEU+s7Hy4ibe3+KA2r5R6ZcfeJhn5dBf5K8p/TSJqDayBeVSV7SDFlMpBuWvogtJKXuZtuuIUFpmoj4GyTsIzyBFw== 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=wCbo5XqEqbC+uIC16R9lbl1b4dXbL9eVmWQcvZ28mp8=; b=GoleiZ8f6UWw23TpEijS/c4hdGmtrXyOHzFROm571m7lmx5JUHjdJNDgUP+rYVqOrvYFFn44ghuYVXiq1X20/OkWyjrv+Jq2KJYNaJ4ztzg9RM3Bo7xkbHuLhmzR7WS1pbTeIJzd2FS8nlFz8uf1IrX3vRDo333Ml2ObT+mIaTN+ISNdC8YepE2RHLNiKvmLKeAoZv+vVxKfUdJhbo1UPoFnXTK55dr7gQpPMbhQviMYCuFjRVDg/GvwhpCKCB4ORO4ypzf/LzCdHH9FlTJIEuN2gKYYA+A8AyG7BdTKsPFINKz9DX0Ue4ef/bc0US+ym0F0gX/a4tlqa0DEKsStNg== 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=wCbo5XqEqbC+uIC16R9lbl1b4dXbL9eVmWQcvZ28mp8=; b=Y8tw6p3D3aPYVUXjS6Z4gRrbJJzhssODtxJ80O7X4zTK5tpnjuQ+0ntZS9/Ifg/4VFxuPOYk6cWWS0ZvPQsQ8g2CufNWBr5pvjoRTXXjg75EywnTvEGv0u0fOmL6Q9l7wyoOPNP/nWjUbyG9zczi1B/Tqx0vmvjUOlvr3bsu7JkgXp4YipblBAgfNYMPwG4YVQoVCaKREg/jYyj6RDX8fLFOAOGSqt1o1zejUnKsLLZ6d+PBL7401gLRUQpjZzRj8apXXZnKLOXeMr2ceW5Po1+x2cuy/3nPAjVFow8EqkIKMUjNcjd8Le0qeiW4nwqG/8THZmTiZSgYPEzU5jk2Lg== 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 AM0PR04MB6897.eurprd04.prod.outlook.com (2603:10a6:208:184::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6565.17; Thu, 6 Jul 2023 08:19:58 +0000 Received: from HE1PR0402MB3497.eurprd04.prod.outlook.com ([fe80::423a:a30f:5342:9d35]) by HE1PR0402MB3497.eurprd04.prod.outlook.com ([fe80::423a:a30f:5342:9d35%6]) with mapi id 15.20.6565.016; Thu, 6 Jul 2023 08:19:58 +0000 From: Geliang Tang To: Alexei Starovoitov , Daniel Borkmann , John Fastabend , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa Cc: Geliang Tang , bpf@vger.kernel.org, mptcp@lists.linux.dev Subject: [RFC bpf-next v3 2/8] bpf: Run a sockinit program Date: Thu, 6 Jul 2023 16:19:41 +0800 Message-Id: <1654cf3707d93253e1891084c74894a1f535abdd.1688631200.git.geliang.tang@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: References: X-ClientProxiedBy: SI1PR02CA0026.apcprd02.prod.outlook.com (2603:1096:4:1f4::11) To HE1PR0402MB3497.eurprd04.prod.outlook.com (2603:10a6:7:83::14) Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: HE1PR0402MB3497:EE_|AM0PR04MB6897:EE_ X-MS-Office365-Filtering-Correlation-Id: 9ec314ff-fe2b-48be-43b1-08db7df9c912 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: UvB61uXXTZGxuRuuMhYkO8m6sOwWUXNl3WV8b9iRlgq4OkmWBr1OY/pwWNMC7VGvQC9GtiaU7ltMqjarkaPPQ8jKvB7JWiQvvExGrwx1zfLj0zlq6+CMiIX7DhAnf1RpiseRkF48cv+GI2SHkMKRzTd9usOTpOCmWNW0S1Iq5SEBPeRclbUPc8WiyDEIqnKPM/MxYaZM1iWMNpiZLqIZH5/5FKMDuYApo5yfeNAVVXuZ+VvPAAMnhK823gCL5YEF3oHtI+MYKm/H80D928F/BF0Uf8rSE0a0QoUOv8MuxRjAaeTg2v1YF3448xCVIxW27Ah0Xkjqohq4aDHIFt36bSN4uXC/FceI0u2upUCxM0MZ6btr1TNDflUjzNa8WLUzo/a6XggmFSababsRzLJSIw8HLZyfcIw8JgGXo3oicWlALyr7AaoaI2E0GH6bQ+r3bCswjw+nWwPDmrTPL4sku/OpK2lMs2RgsT+B54RBmq+PcayNGF+3peUL7feLSHkGrKJTR3SrgfRpgBrI7acqM1ww7WJ3UZAK05l78iPWE7aJZxKEZFSp287qGBYT2GRKqFB6tLSaJymZdVfTKRJp3Y3CMQZAHsmQb+LKccgucokBWjxojsDfvWeiLlAPy8PX 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)(136003)(396003)(39860400002)(451199021)(7416002)(8936002)(8676002)(44832011)(83380400001)(41300700001)(5660300002)(2906002)(316002)(2616005)(66946007)(38100700002)(26005)(110136005)(4326008)(921005)(66476007)(66556008)(6512007)(86362001)(186003)(478600001)(6506007)(6666004)(36756003)(6486002)(13296009);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: wrJgdSsunfErFRC6cK0b+AM2cJjZ6eUHP7bz6EVNA32sJ0KKac/q1hoPQu78Rj/5oYIeT+3fmZOxjtUw7yCXYrtkIFuy8heI5uUvc+esgTX1lHKOAFZ9EIc3rIQx36HTNgjkuBve1GUsmk0Q9A1WYFGvUcS1/vNf9Dh1DAksXCUVxFOwEIdPqB1asKt5RQndP+oQA6kSJUejoojk7wXzNaJYy9keP9vn3OlxNX1R6+sBpEcGNDrR/l9lmaIDg4L8KXTRzM3IGdapbgf4S9FqcTbJ9/p13Q3EcgKRKwt5IfSoVniAwzmMf603bhlbhyzhoDlZa61TsHXqHextcy9Hh3DCS6bdR01AhQOE/PDJA3OnEGiNk6iaAu4YK9OuRRPgbJXBDvk7JuIiyfK9BFHfgRTfwU0uLA25UsPVU+zSJClF+s0lCgU1VZLSAVLKLzWAccNtSJ9WrbnRA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Pd5d2GhDjgecxMEr0mNFVFxr8LxApA156lhPVrCD2KPgPE4rfDGWpOa6uBFP4v7bhJ/6D5 X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: 9ec314ff-fe2b-48be-43b1-08db7df9c912 X-MS-Exchange-CrossTenant-AuthSource: HE1PR0402MB3497.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Jul 2023 08:19:57.9719 (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: OEn+bbrap+GxLdyB+0PIS0eS5qUBRQANGBjoSbJfxqOnNMvx/rTlRuLmYoYhL1uZhF/Y7lqmzPDXriXs+gG2dg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR04MB6897 X-Spam-Status: No, score=-1.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FORGED_SPF_HELO, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: bpf@iogearbox.net X-Patchwork-State: RFC This patch defines BPF_CGROUP_RUN_PROG_SOCKINIT() helper, and implements __cgroup_bpf_run_sockinit() helper to run a sockinit program. Signed-off-by: Geliang Tang --- include/linux/bpf-cgroup-defs.h | 1 + include/linux/bpf-cgroup.h | 14 ++++++++++++++ kernel/bpf/cgroup.c | 24 ++++++++++++++++++++++++ 3 files changed, 39 insertions(+) diff --git a/include/linux/bpf-cgroup-defs.h b/include/linux/bpf-cgroup-defs.h index 7b121bd780eb..aa9ee82f5d20 100644 --- a/include/linux/bpf-cgroup-defs.h +++ b/include/linux/bpf-cgroup-defs.h @@ -37,6 +37,7 @@ enum cgroup_bpf_attach_type { CGROUP_UDP6_RECVMSG, CGROUP_GETSOCKOPT, CGROUP_SETSOCKOPT, + CGROUP_SOCKINIT, CGROUP_INET4_GETPEERNAME, CGROUP_INET6_GETPEERNAME, CGROUP_INET4_GETSOCKNAME, diff --git a/include/linux/bpf-cgroup.h b/include/linux/bpf-cgroup.h index 57e9e109257e..a2f58f0d2260 100644 --- a/include/linux/bpf-cgroup.h +++ b/include/linux/bpf-cgroup.h @@ -57,6 +57,7 @@ to_cgroup_bpf_attach_type(enum bpf_attach_type attach_type) CGROUP_ATYPE(CGROUP_UDP6_RECVMSG); CGROUP_ATYPE(CGROUP_GETSOCKOPT); CGROUP_ATYPE(CGROUP_SETSOCKOPT); + CGROUP_ATYPE(CGROUP_SOCKINIT); CGROUP_ATYPE(CGROUP_INET4_GETPEERNAME); CGROUP_ATYPE(CGROUP_INET6_GETPEERNAME); CGROUP_ATYPE(CGROUP_INET4_GETSOCKNAME); @@ -148,6 +149,9 @@ int __cgroup_bpf_run_filter_getsockopt_kern(struct sock *sk, int level, int optname, void *optval, int *optlen, int retval); +int __cgroup_bpf_run_sockinit(int *family, int *type, int *protocol, + enum cgroup_bpf_attach_type atype); + static inline enum bpf_cgroup_storage_type cgroup_storage_type( struct bpf_map *map) { @@ -407,6 +411,15 @@ static inline bool cgroup_bpf_sock_enabled(struct sock *sk, __ret; \ }) +#define BPF_CGROUP_RUN_PROG_SOCKINIT(family, type, protocol) \ +({ \ + int __ret = 0; \ + if (cgroup_bpf_enabled(CGROUP_SOCKINIT)) \ + __ret = __cgroup_bpf_run_sockinit(family, type, protocol, \ + CGROUP_SOCKINIT); \ + __ret; \ +}) + int cgroup_bpf_prog_attach(const union bpf_attr *attr, enum bpf_prog_type ptype, struct bpf_prog *prog); int cgroup_bpf_prog_detach(const union bpf_attr *attr, @@ -505,6 +518,7 @@ static inline int bpf_percpu_cgroup_storage_update(struct bpf_map *map, optlen, retval) ({ retval; }) #define BPF_CGROUP_RUN_PROG_SETSOCKOPT(sock, level, optname, optval, optlen, \ kernel_optval) ({ 0; }) +#define BPF_CGROUP_RUN_PROG_SOCKINIT(family, type, protocol) ({ 0; }) #define for_each_cgroup_storage_type(stype) for (; false; ) diff --git a/kernel/bpf/cgroup.c b/kernel/bpf/cgroup.c index 93b9f404a007..fe294e4d618c 100644 --- a/kernel/bpf/cgroup.c +++ b/kernel/bpf/cgroup.c @@ -1996,6 +1996,30 @@ int __cgroup_bpf_run_filter_getsockopt_kern(struct sock *sk, int level, return ret; } + +int __cgroup_bpf_run_sockinit(int *family, int *type, int *protocol, + enum cgroup_bpf_attach_type atype) +{ + struct bpf_sockinit_ctx ctx = { + .family = *family, + .type = *type, + .protocol = *protocol, + }; + struct cgroup *cgrp; + int ret; + + rcu_read_lock(); + cgrp = task_dfl_cgroup(current); + ret = bpf_prog_run_array_cg(&cgrp->bpf, atype, &ctx, bpf_prog_run, 0, + NULL); + rcu_read_unlock(); + + *family = ctx.family; + *type = ctx.type; + *protocol = ctx.protocol; + + return ret; +} #endif static ssize_t sysctl_cpy_dir(const struct ctl_dir *dir, char **bufp, From patchwork Thu Jul 6 08:19: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: 13303335 X-Patchwork-Delegate: bpf@iogearbox.net Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6FBED20F3 for ; Thu, 6 Jul 2023 08:20:10 +0000 (UTC) Received: from EUR01-VE1-obe.outbound.protection.outlook.com (mail-ve1eur01on2080.outbound.protection.outlook.com [40.107.14.80]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D481A1BC2 for ; Thu, 6 Jul 2023 01:20:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=G0UcrgCf5TbrIhqNZJ+560nO6eX2wruh6EYkfSX+dULmDE3QntPc2T5RbXQvWxDf/BcubInw3MAmVUzoXCcQueYtnpwmJ34ZKsI1lN+gE32tArVQvRlcmecXpPjE4YZV6h9c5X8oL12Su6nXkzcBmphSaX4BXUXMBjYp0J5Znu7o45mWXkcmc25QoYypO7m2Akv9QB382ZNdVtHomhgZU28mpJKp1WV8WWbLf6N+L3Jpbv/y8QF1XZfv6+QSoBBCeIzF2FbD6bGlm8Jmnz5tZCR06jKstJ3fgmxgE3KSj1TlI3Q3YXdfMgwsOMWPsh04WiEUY31eezf4DnCVsyCsHg== 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=lY3Pgk1uh4FXkQ6a+2ml9sNjR4idpzfAMSUu5Wzp0tY=; b=I9RwIJHUaA4EuLiaqadVCUHl0z4RqOJJxaMoVIzhNpQ9x5Xdg8KY34W1UFx9GvmDqRYtvth5Dpzc4GjSYEFQikq8NsZ5Hl32eeykbTbU/GMs3KKNxC+96qKrFw8r7WfvkdHfjo0u1yc0ff3P/ll5NVKTNHd+J2OswiscY0KAXlVhUTmdsWnBeG8iXMoP3b7Hji+6TG9Ddompby1kiLk5bRyuM5L8uAgeRiMtBGs/HgwDNyJP5DqmdocM5U6hfBjM++9PjWvVOXaSHUVoJsCVd5x6HIrmCW1QfS/h6kbjXXTIF/zxUAa5HjmdH1/egga32yX0S7aO32gNIXVZtAgwXQ== 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=lY3Pgk1uh4FXkQ6a+2ml9sNjR4idpzfAMSUu5Wzp0tY=; b=KTPSN7sc/GzPMq/nSwjn7pSePSrwtBZlWC17Rr02bRwiW+sJzWbvCBxz0YIvA8IeKCQRuxIlV5Jb/x00mZBJpszDUq1bMwBW+FLY935gOtJwqgSm65Kvu/tItmzJSwlkcrjxfzOPDlgjVeZkPEcutsDxLcv8hIfoCd0f/E+dIoYfRpHw8uVDyNP0Y645F/5TykP0r6EISc2PR7a3x79zs/u3GVHISayyz44GOogfB+raq9FsnKT7i5tCr6qcy2nX9rYJ6DkRf4vcHuxcFoppmgVPx5Vg79gfHrZAYwJ2Y4CTBhXFVL+Lw8ZYc8jSgUO0XQeCIusNUwS7HxKG0l+3eQ== 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 DB9PR04MB10066.eurprd04.prod.outlook.com (2603:10a6:10:4c1::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6544.24; Thu, 6 Jul 2023 08:20:06 +0000 Received: from HE1PR0402MB3497.eurprd04.prod.outlook.com ([fe80::423a:a30f:5342:9d35]) by HE1PR0402MB3497.eurprd04.prod.outlook.com ([fe80::423a:a30f:5342:9d35%6]) with mapi id 15.20.6565.016; Thu, 6 Jul 2023 08:20:05 +0000 From: Geliang Tang To: Alexei Starovoitov , Daniel Borkmann , John Fastabend , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa Cc: Geliang Tang , bpf@vger.kernel.org, mptcp@lists.linux.dev Subject: [RFC bpf-next v3 3/8] net: socket: run sockinit hooks Date: Thu, 6 Jul 2023 16:19:42 +0800 Message-Id: <5f76da0bea3453db04bb07399b4b1c9ce4859e31.1688631200.git.geliang.tang@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: References: X-ClientProxiedBy: SI1PR02CA0022.apcprd02.prod.outlook.com (2603:1096:4:1f4::16) To HE1PR0402MB3497.eurprd04.prod.outlook.com (2603:10a6:7:83::14) Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: HE1PR0402MB3497:EE_|DB9PR04MB10066:EE_ X-MS-Office365-Filtering-Correlation-Id: 1f32d51c-8195-40f5-1f07-08db7df9cd94 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: oj0WtYV/ZXW0s9xWrj8vI1S/eEEHOIEeGmRMGCeVPtBsqrdCVI62h1FUaAs7ZddR5R194xOXLCb2Vde+olY4nlSFpx+YBnwjvdpIf3e2ywR8566lA+pTQODD7kjsf/CQMXUbZpj6ELIBuk1anwvQbsWnbuTAHFrJ6wDasLK0V6tA5foIqHSL0NWeqNPjehb6tHxRzpos3iqMOAoCRMVRSztISS+Adw6Eoc5pZIOiASz8qb1iRjaZWyBTI081ZBn9RxPji9aQmTaLeCk0ChtwkxQJSxQSI6VnINS6nJpzCYG2UDPpmWITXpHYR0hnwp0g/jzHP08EtS75yzTmKav6y/fDIyZzNaxvNMi9y65TonCxEXtQBek/YZIEt/7D8mYeN9YzRXlw+ru/r7Fn46pk71ulyn5GpRWQw8HcpOLoPuN0Zx3dbgQrzT/+4n6ofz9rUPKo4K2mliU6OFOMctG+aLs/bYeYZfQZoA2bdPGQ1VeyTURwPpw5Jr7gqm4lxgGYknnO5Q5Vo3DnUb/b3hDQ+AQMEEuHw26QkZ6ds3i1ej7p9qBE/CGT0G3eyBmJjhJL78N/Dx8Litq9NCbqOovjdalKRYmbZ6HuUzsDeWfi558ZbWVZHjp/inGAw5stLgTV 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)(396003)(366004)(39860400002)(346002)(376002)(136003)(451199021)(4744005)(2906002)(41300700001)(7416002)(44832011)(8936002)(36756003)(8676002)(2616005)(186003)(6506007)(478600001)(5660300002)(26005)(6512007)(6666004)(86362001)(6486002)(316002)(4326008)(66946007)(66556008)(38100700002)(66476007)(921005)(110136005)(13296009);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: B1qGycjNVUZ8CnTTLmVoj8F2qV3k2kI/L2LvgxjD2etLMQW1PUj5hSDA0Uc8Oe+5Vyo2EgNo9X5uhTIzXVH9w1pE6xE6Bwipru2Uta/4euifJtxvT4eT1cwaj/jvoYzBv88Rbse/bA/7XKeAW64Qr/Q+Z+rCIgJ/MgusRdRNGK8PxADZNk8IAJ4TufNZKeRWxEZe2i8yUYDcjZsUtnsmEvFRU3NqkqAv02skyg4ZpdZqRUB4/z2xmYZNfBsx9yr11OWydizBgAESy96DxxRjrygSvhxEXZUA8G59V39qrH4Mm99MxCoRm+iCthahzbod8aWhHMF90AXMSiDtLJzF7ZUz9hiw/GZeqYdSW0xpU3JtZOfCJQA0O+RX/Ov6wX09r88GCzq93XNQUf8NP8ZKYoCJVNlaz2bsDQdjjmrkQf3xpV3jB1jTCD4mCDiGP02F9ZqXlLpFGCrGeTF1LXjaIvGu+hNSmxa24IE+FPjgfyhWycJutQZxgrgYzNzO6Ao8V2JaYF6QPt2Q7YCRr53t/UUP3jS61ZlQuB3BxT3k6ACcuxOkybHBP6OFcMzeIxL6kgwnywLo7Oj/TJYlWNQ7xc2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CrossTenant-AuthSource: HE1PR0402MB3497.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Jul 2023 08:20:05.3623 (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: Xl4kq0Po7J5WVH4wHHZHWZ0r+cTvEItrNKokS5hsum7TRdV5C3WYliXIzUtPs9QLNmyp/qIXk2TKhScMLJS/ag== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB9PR04MB10066 X-Spam-Status: No, score=-1.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FORGED_SPF_HELO, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: bpf@iogearbox.net X-Patchwork-State: RFC The arguments of socket() need to be changed sometimes like the MPTCP case in the next commits. It's too late to add the BPF hooks in BPF_CGROUP_RUN_PROG_INET_SOCK() in inet_create(). So this patch invokes BPF_CGROUP_RUN_PROG_SOCKINIT() in __socket_create() to change the arguments. Signed-off-by: Geliang Tang --- net/socket.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/net/socket.c b/net/socket.c index 2b0e54b2405c..27b423e1800f 100644 --- a/net/socket.c +++ b/net/socket.c @@ -1469,6 +1469,12 @@ int __sock_create(struct net *net, int family, int type, int protocol, struct socket *sock; const struct net_proto_family *pf; + if (!kern) { + err = BPF_CGROUP_RUN_PROG_SOCKINIT(&family, &type, &protocol); + if (err) + return err; + } + /* * Check protocol is in range */ From patchwork Thu Jul 6 08:19: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: 13303336 X-Patchwork-Delegate: bpf@iogearbox.net Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 581CD2112 for ; Thu, 6 Jul 2023 08:20:16 +0000 (UTC) Received: from EUR04-VI1-obe.outbound.protection.outlook.com (mail-vi1eur04on2084.outbound.protection.outlook.com [40.107.8.84]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 955571988 for ; Thu, 6 Jul 2023 01:20:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=mJUE3MEVUCmTuiBn0yuXbjsHXLjUWp9JOXTC/pmdIbDndaBB5R5HOFam4Snoqh9Baw327C8uPflRizuYe55G3/hAnnkWB/vJes3788DBFsg2TYhtl4w33kXJBkGUXr2xAMfaQ480SvluKbzHkOJsxPO6GNa8qbWFmf6HEET4iRJTtzTXWwUd1fRO+ISmA9+YFOwzqWzQP6F34+pADDCx4UU+tOqaCoMJ6jvfxrKzw7B0MdT0aKToFIIaibAJAT9H2482n1aK3ztv8F61GN/WtycUa5OYe5BmRaA8vyY5lKWkJ6QTnz4y5wLkMWizYzyb4JuF/cumtwTRCP0ak1nECQ== 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=hFcnVtBZ8UP2TGfsabD++11bnT8sUFM686NQ5RYwVgI=; b=WBS4Kg01R7dylAeS72B3BC6q8rlZyYQb4BPTgQb3ZJZQavD3+Z5OSggvm5Vgdcey473CdT3gIALSSrqB3zV65vnDTno3Mjnt/YWif9rUIzemElEmNAV5Igu6ETjzKaBRPmP5rFSXeWaacBglrsd300PJiQ7YxLIu2kKNlHOtHaVmh746wsoIC7JIfUnuRgmOrAJ0BVhBRSk/+MwmOKoxklYybFL9Ey8zlPOwewUWbq7d1O2xI8fvQmuQVuXiZdgCZDEkX5PPMNs8te3V5JExCUUlZPBls7nNSJO0fzVU+zxt3Xi7tNQMKIP/+HlFvnakP6wuWiRHcX46I0PFlPOqtg== 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=hFcnVtBZ8UP2TGfsabD++11bnT8sUFM686NQ5RYwVgI=; b=xji9IJjztbKJWA99cFjb+E7TIPVpJasFno2z7WvWJsAUlquNPVwYueBUZHO6Rje1iMTUvGk1rxVUHh8kE9GQa213szafUBpcIZ7romgLN9HzCSi9aTJSWWLvtM5RI3uAbWaN8Jv9XhF8tfJsC5v/wVx5ERQEIL4NVojT3mPQcT0VvXqMDEWfoIBvDg9IkzA8BMpJoLtYGHbqIMniuo4wIcgQJJd9bjxiePQscWpJVLJHE94L6fV6CzbOd1/wSC9hC0oTFUr5LQy+exTyzwoKyHCupP8aNDAj9b3Ni6Hds/asq8mSZqr8hfAo3MQabxOfEkwRi515312hcV3WqF4GWg== 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 DB9PR04MB10066.eurprd04.prod.outlook.com (2603:10a6:10:4c1::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6544.24; Thu, 6 Jul 2023 08:20:11 +0000 Received: from HE1PR0402MB3497.eurprd04.prod.outlook.com ([fe80::423a:a30f:5342:9d35]) by HE1PR0402MB3497.eurprd04.prod.outlook.com ([fe80::423a:a30f:5342:9d35%6]) with mapi id 15.20.6565.016; Thu, 6 Jul 2023 08:20:11 +0000 From: Geliang Tang To: Alexei Starovoitov , Daniel Borkmann , John Fastabend , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa Cc: Geliang Tang , bpf@vger.kernel.org, mptcp@lists.linux.dev Subject: [RFC bpf-next v3 4/8] libbpf: Support sockinit hook Date: Thu, 6 Jul 2023 16:19:43 +0800 Message-Id: X-Mailer: git-send-email 2.35.3 In-Reply-To: References: X-ClientProxiedBy: SI1PR02CA0022.apcprd02.prod.outlook.com (2603:1096:4:1f4::16) To HE1PR0402MB3497.eurprd04.prod.outlook.com (2603:10a6:7:83::14) Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: HE1PR0402MB3497:EE_|DB9PR04MB10066:EE_ X-MS-Office365-Filtering-Correlation-Id: ad08d958-ee3f-4c29-cd63-08db7df9d141 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: dmlFfNr2fADZcCyrvCP84PW79AQxCzzOuEuuby90HtP+2RqV3ZqYF974NrT7vn4uUvOAGtAwiO77/1ksHukAlDGAo7O44ikF9vKZOnHd68JA5flZ27nQz9+yj1HN5u3ZBw4K+xlhMd1se7TIwi/vfxKzhXhbIXRa3h68Ri8Bg0EjrR5aIPvWZmwdL3jpMKgokhQt1FGu6HUk1UUq1ucfiqnZEcXcTFguFAfI3hr6bGqkI9ujjAt2A1JPskaaP6utjLIQZoCaTS9AKhdmaFsfxBTwG4HpAsbC5zWRq8Z341GbSdcAzFQL7vOFQX5vGABZv5oVhn+/jxPcQ4y3CsUZaZ8C6ls8xKK8wH7Udbvcfg9NcDvf5BekJonhrayuo+WfdrwfzbRLY6NJ4Fu8DTruNcQhq2Ezqza/j1ej0pkGGLQMCCpsN00OGFB73UyRvWUbL/3eZO72xfRUTAnwOmDgWR59lh5YOP+xATGosTyXvevOu1qiYdZUXaXLjc36R1P+IRzo7crMZNx/GIphLoGnTgMp6eJmZGzc+hg4GbErp1hT0PTTxnLXKtiKArvmSVEH4Nbm0IaiytHUCLSHrfgOXl+nAxtnHoD2rBoHdPqcMjqp+yTnHpqEJe+JO4qniqI8 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)(396003)(366004)(39860400002)(346002)(376002)(136003)(451199021)(2906002)(41300700001)(7416002)(44832011)(8936002)(36756003)(8676002)(2616005)(186003)(6506007)(478600001)(5660300002)(26005)(6512007)(6666004)(86362001)(6486002)(316002)(4326008)(66946007)(66556008)(38100700002)(66476007)(921005)(110136005)(13296009);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: W91sUyzrYZpyy/4WOS/YT+9EjQuaX7FhGZbrBrza5oM60ymSK9lcLIZF9lOHFDaVFVCHoCLNq3bU04AS3sP1SCRrQh1DvSur16xedmOgeLJpF72hXyOFLlaVlPeez/U1hFJIGBCpaatG7xYQrJRf7cc5aAp6pZPHfQjksi6+aLgC7rUDbYlED6RHgJBieGNiw4GXEXx0WPLOVso4crUfTkuyQ3z8FJmfw84h+JoFbSy5muSa7Ytrd0ulxP3tiwf3b2WfdObVIPYz19tnld1ReqO+Ua938SoFNXddziFI6EqSubV4+gIooByZG6jiv6EGdranvPfvQcO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xQTZ8pyC15LMxptfxvVSaXsN3D/koDPVJK3PKD+EaJJSLdfu1zmkeUTxqIVXD0L+QBX71eR55zuyr/7BtEnDbHEbgmv9O+zgscpuwlCWhGzoHt4/uZ7ei0eEfletN6a+iTNSn24L946CGxXKD+y5jw3swtpIqvjwUUS6zwva9oPf1lZk6apht X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: ad08d958-ee3f-4c29-cd63-08db7df9d141 X-MS-Exchange-CrossTenant-AuthSource: HE1PR0402MB3497.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Jul 2023 08:20:11.7064 (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: ReuiOdeFslM6XvGwCkEVtuwWPRSjlkGGS8sEydT6VcNQaYObzQjvXjIKzgu1h5J8MucIrQMKwGZpw21DRDIzVw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB9PR04MB10066 X-Spam-Status: No, score=-1.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FORGED_SPF_HELO, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: bpf@iogearbox.net X-Patchwork-State: RFC Sync BPF_PROG_TYPE_CGROUP_SOCKINIT related bpf UAPI changes to tools/. Support BPF_PROG_TYPE_CGROUP_SOCKINIT program in libbpf: identifying program and attach types by section name, probe. Signed-off-by: Geliang Tang --- tools/include/uapi/linux/bpf.h | 8 ++++++++ tools/lib/bpf/libbpf.c | 3 +++ tools/lib/bpf/libbpf_probes.c | 1 + 3 files changed, 12 insertions(+) diff --git a/tools/include/uapi/linux/bpf.h b/tools/include/uapi/linux/bpf.h index 60a9d59beeab..cb882ab8065d 100644 --- a/tools/include/uapi/linux/bpf.h +++ b/tools/include/uapi/linux/bpf.h @@ -980,6 +980,7 @@ enum bpf_prog_type { BPF_PROG_TYPE_CGROUP_SYSCTL, BPF_PROG_TYPE_RAW_TRACEPOINT_WRITABLE, BPF_PROG_TYPE_CGROUP_SOCKOPT, + BPF_PROG_TYPE_CGROUP_SOCKINIT, BPF_PROG_TYPE_TRACING, BPF_PROG_TYPE_STRUCT_OPS, BPF_PROG_TYPE_EXT, @@ -1013,6 +1014,7 @@ enum bpf_attach_type { BPF_CGROUP_UDP6_RECVMSG, BPF_CGROUP_GETSOCKOPT, BPF_CGROUP_SETSOCKOPT, + BPF_CGROUP_SOCKINIT, BPF_TRACE_RAW_TP, BPF_TRACE_FENTRY, BPF_TRACE_FEXIT, @@ -6829,6 +6831,12 @@ struct bpf_raw_tracepoint_args { __u64 args[0]; }; +struct bpf_sockinit_ctx { + __u32 family; + __u32 type; + __u32 protocol; +}; + /* DIRECT: Skip the FIB rules and go to FIB table associated with device * OUTPUT: Do lookup from egress perspective; default is ingress */ diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c index 214f828ece6b..03f62d163030 100644 --- a/tools/lib/bpf/libbpf.c +++ b/tools/lib/bpf/libbpf.c @@ -95,6 +95,7 @@ static const char * const attach_type_name[] = { [BPF_CGROUP_UDP6_RECVMSG] = "cgroup_udp6_recvmsg", [BPF_CGROUP_GETSOCKOPT] = "cgroup_getsockopt", [BPF_CGROUP_SETSOCKOPT] = "cgroup_setsockopt", + [BPF_CGROUP_SOCKINIT] = "cgroup_sockinit", [BPF_SK_SKB_STREAM_PARSER] = "sk_skb_stream_parser", [BPF_SK_SKB_STREAM_VERDICT] = "sk_skb_stream_verdict", [BPF_SK_SKB_VERDICT] = "sk_skb_verdict", @@ -197,6 +198,7 @@ static const char * const prog_type_name[] = { [BPF_PROG_TYPE_CGROUP_SYSCTL] = "cgroup_sysctl", [BPF_PROG_TYPE_RAW_TRACEPOINT_WRITABLE] = "raw_tracepoint_writable", [BPF_PROG_TYPE_CGROUP_SOCKOPT] = "cgroup_sockopt", + [BPF_PROG_TYPE_CGROUP_SOCKINIT] = "cgroup_sockinit", [BPF_PROG_TYPE_TRACING] = "tracing", [BPF_PROG_TYPE_STRUCT_OPS] = "struct_ops", [BPF_PROG_TYPE_EXT] = "ext", @@ -8734,6 +8736,7 @@ static const struct bpf_sec_def section_defs[] = { SEC_DEF("cgroup/getsockopt", CGROUP_SOCKOPT, BPF_CGROUP_GETSOCKOPT, SEC_ATTACHABLE), SEC_DEF("cgroup/setsockopt", CGROUP_SOCKOPT, BPF_CGROUP_SETSOCKOPT, SEC_ATTACHABLE), SEC_DEF("cgroup/dev", CGROUP_DEVICE, BPF_CGROUP_DEVICE, SEC_ATTACHABLE_OPT), + SEC_DEF("cgroup/sockinit", CGROUP_SOCKINIT, BPF_CGROUP_SOCKINIT, SEC_ATTACHABLE), SEC_DEF("struct_ops+", STRUCT_OPS, 0, SEC_NONE), SEC_DEF("struct_ops.s+", STRUCT_OPS, 0, SEC_SLEEPABLE), SEC_DEF("sk_lookup", SK_LOOKUP, BPF_SK_LOOKUP, SEC_ATTACHABLE), diff --git a/tools/lib/bpf/libbpf_probes.c b/tools/lib/bpf/libbpf_probes.c index 9c4db90b92b6..3734fee60d2f 100644 --- a/tools/lib/bpf/libbpf_probes.c +++ b/tools/lib/bpf/libbpf_probes.c @@ -180,6 +180,7 @@ static int probe_prog_load(enum bpf_prog_type prog_type, case BPF_PROG_TYPE_SK_REUSEPORT: case BPF_PROG_TYPE_FLOW_DISSECTOR: case BPF_PROG_TYPE_CGROUP_SYSCTL: + case BPF_PROG_TYPE_CGROUP_SOCKINIT: break; case BPF_PROG_TYPE_NETFILTER: opts.expected_attach_type = BPF_NETFILTER; From patchwork Thu Jul 6 08:19: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: 13303337 X-Patchwork-Delegate: bpf@iogearbox.net Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 101091872 for ; Thu, 6 Jul 2023 08:20:23 +0000 (UTC) Received: from EUR01-VE1-obe.outbound.protection.outlook.com (mail-ve1eur01on2051.outbound.protection.outlook.com [40.107.14.51]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1AA45130 for ; Thu, 6 Jul 2023 01:20:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ffXqvlL9l2z1K+yPeY5s3JOS8sGIlDjCfW7UGw+xs8XUZZbzvrScfEBkBVbTAt8TsgOdLsHCeZZzmUd0ezELk+NLKHLwMNv6iptQ8ZXMS6cYmtttUL0J2nv5OqZdh38Z+A05Rw/T3D3ulqdFmbgheYZW8Q4BeSO6XLAWm+5ctyPdrfRTCl9e3hHR6TmMMWO+32k+nBjtCyeBfd/HX3A6yXRspFgpaC75rT7MD24hnlQ06cydUP47g+Am7ErtHWYYRJEjXaFeTkwPqt56ts4IDHGFPLhClm1XnUcOxCz9r659FI+D5swZ5dF2nwnIiPcAIsceUeu6fsicpHsDTi2D5A== 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=SPH4bwg8shk4a7dlucecBOgYz1Xs3eVluKKT5Ey3zWY=; b=i9F3GCQPaJQTir0GbgHYoldCkPHTiSXHaZ78lYD+99wKGk14gDGB+e7pnGhYabbZiCTWY5WQwFnD15I5IeZsL+OBasU+hLZtvxeSYQOve+kYk3GxmZqB+zv29wmVGt7sjZp3GVaIyExgOprLbodEtPIgSBpughWFr/s9EIR8qDjphl2uiKGZ+DXeiW0UqDeUiszATphFWyJrmN/tAi1hkJtSnnfUOB1Wm2XPceTgPSX3fTbFJUzhArAHpnR85rfsHojfCEPyyVjyuM4fEogasD7C9OdvcqlGYyUtn8YbcDAAV/uwVWCTYlDnWpgT4mJpFxl0tE1aXgubzH54aCyGaA== 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=SPH4bwg8shk4a7dlucecBOgYz1Xs3eVluKKT5Ey3zWY=; b=UgorSuIFzH2JqApwQkMPLCghFpbV0igdfBn8OQIX9pZOvwJqi16UMG0hXZVv9FXT6cpHTDHnScAH6jhVQPqthCkxzQeEMsubQhzjGKuzZaC9GqWhlngMIFkiqM/w38Rem7+idXMCKzlc2xtiffToq/nxjCPRIaRbzADKpv1VCs/AptmAo+ov3acL9pOkWIXhLFEpQaqi+BcvsDjclOb+FYWa7Yc6NWIkCwiZu7gDDy/ieG4zrPJoBCu+MICyEgYRJoIjXyK7IUWl3XdGJc10K88r7ggWraqUD232t7tln25nishoDzXTK/P0nP676VTNutqX2LF00pnbkb8W8/5CtQ== 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 DB9PR04MB10066.eurprd04.prod.outlook.com (2603:10a6:10:4c1::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6544.24; Thu, 6 Jul 2023 08:20:19 +0000 Received: from HE1PR0402MB3497.eurprd04.prod.outlook.com ([fe80::423a:a30f:5342:9d35]) by HE1PR0402MB3497.eurprd04.prod.outlook.com ([fe80::423a:a30f:5342:9d35%6]) with mapi id 15.20.6565.016; Thu, 6 Jul 2023 08:20:19 +0000 From: Geliang Tang To: Alexei Starovoitov , Daniel Borkmann , John Fastabend , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa Cc: Geliang Tang , bpf@vger.kernel.org, mptcp@lists.linux.dev Subject: [RFC bpf-next v3 5/8] selftests/bpf: Add mptcpify program Date: Thu, 6 Jul 2023 16:19:44 +0800 Message-Id: X-Mailer: git-send-email 2.35.3 In-Reply-To: References: X-ClientProxiedBy: SI1PR02CA0027.apcprd02.prod.outlook.com (2603:1096:4:1f4::18) To HE1PR0402MB3497.eurprd04.prod.outlook.com (2603:10a6:7:83::14) Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: HE1PR0402MB3497:EE_|DB9PR04MB10066:EE_ X-MS-Office365-Filtering-Correlation-Id: 27f7881e-565e-435a-7fd3-08db7df9d5db X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 7JV9R2Kw/JX9AXWNtLM0Bpi5l/J20lJdvqqo5YWNk061Hw7QxGl/cLDYRYXd1J6+9A/02ex2zUJ6jtMWN5F4zsOT5wtiRWghfSZSTSaf//dNoIPoZP5BxRyAxukQsGAJpazAiHGHSSWUCWVFeAN5EBfzNWPEz5/io+oTNszLkZzyayQoi72v5rwdqEHeIzBgu+c0miuY3T5lgf0G1QvcnwS1GEkf8Y1QbhDpaD6i//hBbj20kpGCaEndMdKlMazSLDfrQ/GCI5KM4+HZeD5lTaF0tfnGoppyMY7U0L/v+mP95Z+6EX/h/ydh0QvwiLuFtvL6BZyOjiePhCwbGXMEEwC6e5XJfxF64bejZc0dZSZeGNbxzdEvDSBViMsT60kuDQZdjviVxJygeWJMTs2r7YCEaqdXjotkIFZKcVdyminIe9ME463bR34IPkwDbf7ACews0BPbSWwxIUAXblWEvQbeNDzYet6ZB8ipIYTfrN7fYWeTLmBRHiIOW8JU/YM67FBDZefPxu5a9B8X1eC9LKO8XowA015IQJkq625gVEb4fMoVhFWu/ABQ/5ugg9icLI4c2QPJRLaaLBmErPeuFHCzM4zuBqmyii9/v5aqcquKEo7Z6gY+JlxlraYyemM2 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)(396003)(366004)(39860400002)(346002)(376002)(136003)(451199021)(2906002)(41300700001)(7416002)(44832011)(8936002)(36756003)(8676002)(2616005)(186003)(6506007)(478600001)(5660300002)(26005)(6512007)(6666004)(86362001)(6486002)(316002)(4326008)(66946007)(66556008)(38100700002)(66476007)(921005)(110136005)(13296009);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: C1jrseHKuAe8SHrkvoKaPHBZqiGr65qgIGGrM+dKhpPZn0WwYGKtxVs/OOit7DqwU4yN6Ta3f6lpASrinukmWWszAK0SpuXcqCGeIELf8KwX+gdQJqfX0WobKV/PBQZGuk4FkhMgoUocPuwJqeDW9nxMAB5Iy7+4X7GpBcYIiQCrPe75a8GU97X7046AzipaIB3Ry4MrM6xb2qoHnhwoBzkJF7Edxnsjml1LXcl2xFgssvK4K4jKBNkvmU8yMT/k2mpKyHYE5MuTU7xqOqoRgGxadcx3+ZLlCZ6vw2JxKiWwxnh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r6Ik4a7Sg3vb2rxdQ1+V1GSgnqRq6vjDonrhfbugKggBe4vP2LqmmtblB0fQffvFxDGks2R26Pr0+ygAM13KM9cyhSLx1xt+zrDBQQTvMnHv3/iCsXqMXCtj4GFf55C+62AdADdTC6uWtwKo4HVfnEZkDl/lJgNvmf6W0zCYFuokiQB5GPsSlK1WXU1rs6MD0X4bUQDgfJX3j0MvDyMc3f4YN/VyDXRB4j3x X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: 27f7881e-565e-435a-7fd3-08db7df9d5db X-MS-Exchange-CrossTenant-AuthSource: HE1PR0402MB3497.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Jul 2023 08:20:19.4012 (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: Fwx62AUjP/4YPoOVZHltufHOaGtZ5abmS/cXsIyE58RE9Lbk6lobVDUcf8rkgHqlmda4xzg2TMb6TUcmFOzClQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB9PR04MB10066 X-Spam-Status: No, score=-1.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FORGED_SPF_HELO, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: bpf@iogearbox.net X-Patchwork-State: RFC This patch implements 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. This is defined in a newly added 'sockinit' SEC, so it will be hooked in BPF_CGROUP_RUN_PROG_SOCKINIT() in __socket_create(). Signed-off-by: Geliang Tang --- .../bpf/cgroup_getset_retval_hooks.h | 1 + .../selftests/bpf/prog_tests/section_names.c | 5 ++++ tools/testing/selftests/bpf/progs/mptcpify.c | 26 +++++++++++++++++++ 3 files changed, 32 insertions(+) create mode 100644 tools/testing/selftests/bpf/progs/mptcpify.c diff --git a/tools/testing/selftests/bpf/cgroup_getset_retval_hooks.h b/tools/testing/selftests/bpf/cgroup_getset_retval_hooks.h index a525d3544fd7..0ba09e135df3 100644 --- a/tools/testing/selftests/bpf/cgroup_getset_retval_hooks.h +++ b/tools/testing/selftests/bpf/cgroup_getset_retval_hooks.h @@ -14,6 +14,7 @@ BPF_RETVAL_HOOK(post_bind6, "cgroup/post_bind6", bpf_sock_addr, 0) BPF_RETVAL_HOOK(sendmsg4, "cgroup/sendmsg4", bpf_sock_addr, 0) BPF_RETVAL_HOOK(sendmsg6, "cgroup/sendmsg6", bpf_sock_addr, 0) BPF_RETVAL_HOOK(sysctl, "cgroup/sysctl", bpf_sysctl, 0) +BPF_RETVAL_HOOK(sockinit, "cgroup/sockinit", bpf_sockinit_ctx, 0) BPF_RETVAL_HOOK(recvmsg4, "cgroup/recvmsg4", bpf_sock_addr, -EINVAL) BPF_RETVAL_HOOK(recvmsg6, "cgroup/recvmsg6", bpf_sock_addr, -EINVAL) BPF_RETVAL_HOOK(getsockopt, "cgroup/getsockopt", bpf_sockopt, 0) diff --git a/tools/testing/selftests/bpf/prog_tests/section_names.c b/tools/testing/selftests/bpf/prog_tests/section_names.c index 8b571890c57e..52319c45de57 100644 --- a/tools/testing/selftests/bpf/prog_tests/section_names.c +++ b/tools/testing/selftests/bpf/prog_tests/section_names.c @@ -158,6 +158,11 @@ static struct sec_name_test tests[] = { {0, BPF_PROG_TYPE_CGROUP_SOCKOPT, BPF_CGROUP_SETSOCKOPT}, {0, BPF_CGROUP_SETSOCKOPT}, }, + { + "cgroup/sockinit", + {0, BPF_PROG_TYPE_CGROUP_SOCKINIT, BPF_CGROUP_SOCKINIT}, + {0, BPF_CGROUP_SOCKINIT}, + }, }; static void test_prog_type_by_name(const struct sec_name_test *test) diff --git a/tools/testing/selftests/bpf/progs/mptcpify.c b/tools/testing/selftests/bpf/progs/mptcpify.c new file mode 100644 index 000000000000..f751e6f65eca --- /dev/null +++ b/tools/testing/selftests/bpf/progs/mptcpify.c @@ -0,0 +1,26 @@ +// SPDX-License-Identifier: GPL-2.0 +/* Copyright (c) 2023, SUSE. */ + +#include +#include +#include "bpf_tcp_helpers.h" + +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("cgroup/sockinit") +int mptcpify(struct bpf_sockinit_ctx *ctx) +{ + if ((ctx->family == AF_INET || ctx->family == AF_INET6) && + ctx->type == SOCK_STREAM && + (!ctx->protocol || ctx->protocol == IPPROTO_TCP)) { + ctx->protocol = IPPROTO_MPTCP; + } + + return 1; +} From patchwork Thu Jul 6 08:19: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: 13303338 X-Patchwork-Delegate: bpf@iogearbox.net Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1CAF51FBF for ; Thu, 6 Jul 2023 08:20:33 +0000 (UTC) Received: from EUR04-VI1-obe.outbound.protection.outlook.com (mail-vi1eur04on2088.outbound.protection.outlook.com [40.107.8.88]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 31261130 for ; Thu, 6 Jul 2023 01:20:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=T5Mihk6AwsAXISsdAgO41osS+lsYa9MlZHYWPvE+QWKxNgXeoePO0wFP5dcXIR0rONTXg2QpOtEZNXfwN6rbYmfexLJAmNuRdw7dqWjOMzdxX4wDC1k3iCaU6P35bKLckjKGFW1ctsZoDBLddrEIlvIyU+UCDOYWI19LZyjdex5fR4FIhLDN7x8the4ctyBlmgTt+qstRFmovfldo3LGHoy/cIyQUs+mI9wbcaZ54ch1jBSwAuVtHugLtawsEmACakB6G1OdDm/obDfRR597QwwiuLOmdEHgHEnoNgMXSu/MQGxSiLpkGObLLRXlMThFTTMo/h5OfRmSxlqSr+HsNw== 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=NzID4LfvkVOcdRHC6j4qWFHPHTCZOQAdpNHzRFHPitr2xLviZz9Zsd2QTfEK0pTEgOGCil3rz/L1ba5GNA3hv4lJB8l2I/MWPd0Df0QtBRBQDn8fHJpaWGMR1wm1Nc5l6Q5C1v4u3REh+gQUwamDEGkF8E3up/O0kht+waOYq5H1NZXb8egwfN2sXoEN8wLVnUspSBxADgnxDBxODsc4zV4zoHca8KGsT0tILrGuaH187ftIv0rUzY7f3FUFWvEaIzEDp7bv6TYpQxq67F0NfUgpmFZ4TtLJWMDX/3p/9vxXgIR2fCLiePWDZtXXMbEOdivpVAPd7EwaniA8dvF0kw== 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=RyWoVuU48TCUzkW5Sk+OqedM3wi0ovR//XF7Kn8ECC1S/Lq54BrOwEITwBHmn4fh+1eXDazYoSexTm4FukuInYOdAc9V2dI/XkpTbQzpWiNUsYklcYe0J75CIG4ihbW9rwlqQzPS/A45XO17lowVF6kcaDRrGzU0esJ7EatSaRPJr1/+sw/RybiaUSBvmw47SuUSd96NJ6aEdrWEYNDFa3EEAcJ3hOxq4UrL2HcodRpK03r994hd21EOXbz098kNNhTWxaCLNIDrw/mgGoxroi+uLRiLFbj4HHQeXRdxyrPfJX210ZroIP0PEeZVNhI49ZzterBCQjBq9uDhm87O0g== 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 DB9PR04MB10066.eurprd04.prod.outlook.com (2603:10a6:10:4c1::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6544.24; Thu, 6 Jul 2023 08:20:27 +0000 Received: from HE1PR0402MB3497.eurprd04.prod.outlook.com ([fe80::423a:a30f:5342:9d35]) by HE1PR0402MB3497.eurprd04.prod.outlook.com ([fe80::423a:a30f:5342:9d35%6]) with mapi id 15.20.6565.016; Thu, 6 Jul 2023 08:20:27 +0000 From: Geliang Tang To: Alexei Starovoitov , Daniel Borkmann , John Fastabend , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa Cc: Geliang Tang , bpf@vger.kernel.org, mptcp@lists.linux.dev, Matthieu Baerts Subject: [RFC bpf-next v3 6/8] selftests/bpf: use random netns name for mptcp Date: Thu, 6 Jul 2023 16:19:45 +0800 Message-Id: X-Mailer: git-send-email 2.35.3 In-Reply-To: References: X-ClientProxiedBy: SI1PR02CA0021.apcprd02.prod.outlook.com (2603:1096:4:1f4::14) To HE1PR0402MB3497.eurprd04.prod.outlook.com (2603:10a6:7:83::14) Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: HE1PR0402MB3497:EE_|DB9PR04MB10066:EE_ X-MS-Office365-Filtering-Correlation-Id: 51594e7f-0d28-4cc3-dc55-08db7df9dae2 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: xEsGdsMrLYQmWaLlWnaPAz7YKl5KklSTE1n/fOk/klw21rlvBRF+ntCUiDqZPaFtTibnMkWzoAYW7SCEk0IzIdWXilr5k+7oX7tNS0xonGzYP05LdJL7Br9Bo1aykj8ZxNrUadFurwilYpwqYtf/LEjp4FkCLNdrDLXN6ob7xbIQD+qB1Fdxc78ej/Zi1PnYg0ocFDyotCW20+lhR7qO+VMi/CbJ0ZyYKRkCXbjiK9yeRQbZLF5EQXMYQz+hEl0dKfMUOdSIrHQiTl89VSiLJmWCAvIYKNmSvzbKoTFjmmkMsDejoQ/TU8Jndf+JpBq245x7RLcCDcBS6j7ach7zNj1rQ42YW+zPjyVmyzPfWiuVmK8USmfyMN610PyjtA91L4pHXzE3ZWshbI19AyGYkvl4CXk+RB+8UNhLCFYq/hqiNMA1k3bH+Sm3JfE4Mqm4MXfij02JbD5I6yh7NjB3JvK2aYd+8BoMgGIV09DNN8UDqrm3dWaMlEXx43cwUn09CfCe2ef/x6edA/zmh89PojextbR6H4eW7a69kyOqrk8mYzklMS9ag+rquKGnB/JXZHOgv+ChfwpC3CDolgfXI7M7r4iGc+NooDv0cL0eaWKc8sh4EvSagzzC7Rl/2hKLjxQo4xX2zwygxgt7gaMOYayDwLKuPIHSWkI4p2eCc6k= 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)(396003)(366004)(39860400002)(346002)(376002)(136003)(451199021)(2906002)(41300700001)(7416002)(44832011)(8936002)(36756003)(8676002)(2616005)(186003)(6506007)(478600001)(5660300002)(26005)(6512007)(6666004)(86362001)(6486002)(316002)(4326008)(66946007)(66556008)(38100700002)(66476007)(54906003)(83380400001)(921005)(110136005)(13296009)(17423001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: VkMukqPkW+hxXcxkNp6vYxBFY0D+8IlK+YMhhWdV43RYNEEgwo8W4C+zW6/syQIqPzfJoQxvRcqzIqPcjSjHwRUtxdxKtbfeZcxiRu9ltHkM0J5Z4TSEfEPxCp+pRjSQPcYPTVJPIvPcjBT1qHlbBzM49UEXNSjiW6baalt5NIWyjvfl+RteZyNkPSx+skU5mRYF41v2Xk3LXgI3MJZAXnwQDpJ7qkvG2U/jklbHo6pDYJsIFpx+DhTUhQs/VnLsjVegimilbNUtsZxRd5mGNl5gr9kpI5KyIbxiHiB4FaKI25DPJsmE5exD40pxX7dmNsUFcdlcVMlYYtBIUuqha5vthcIBFumOVrA8iVV7anU2X9xUq8KAmZL7XVw3OxcZ2mH+Y5/EAvZFfa4RywRSrgOS3973YfZJld/Cs0tNHIXcueGqfrKotiln3GdTdciTI+OFQq4iHMPB5UV/jnSwhfjEzGxAqUjdrOLx43ZZjQ6PUp9BVajLtd53NcxUOEpXQXRVhrJwC39nQm4SEd89CGDfS1gD8MBVMbhS0Muode080yi88rK4Jd8xg6v00VIgPR6NAzK3qv1VQ4Ho0IFBEtdUTvMn5z77t8YkaftCiDCnMWtldFfYKB5N6/mz2guF+0nKJst5ot+IihwMmfw/GbGXkUMiUTA2Gt+Tz5j792geD/9pPH9aSpCiFtGAIAuBRmYhZKzx/+dnIx85Le8xKZ2yAmTCIZABO4ZnuEHUKJVSCMuaF52QZEWzla7J5RAyjgxAh0JXILQbIdliHvl8z0OvIiGCCdWsuOTO0HX88aJv1ojSKREqCqI/mQJGgTFpPCbRlwup67+DNXBtU09R7hgLhzyQ2QdHgnAxIQBNis4ZXBsIF1F3iFJGNlrqQq43F96b1UJQqm806Qko50OPtvqxEPn/sF9DL+VhYg9vlOFb3UQq497GHDy+7Kw2LH5hSlvPGhsNHh18jokWpSSU69G9iv1DmRNVTIzgtWlLr2BDVUJ6MTyCVORCo8lJRnoQPCIXMEkbE6+ZAvl1un996KX5Q/XfwoXOtQ4f42OuJiyPPLqLrQTHW0wS/IoHhETEsAh3UFOyulKEzVNonKOJeyA/7Uw+g8CoxQ9QfJ7O7skGiKgkqxko0mRg98gol+CSfosmIxWCbIPL690GGUo1h94S3bxSdZVIsF1nuhqlvOM47z4SiBXmgWEsl+A3dJViTkMqQlXOEiMcKUv058rL+konZLJ/Emx/7YbsCfBYTW72jfccn8pG/FcsfQlIVjyDbes0Pq0Ql4Wx/Fbs5nai7HqVRy6i587jfEbmBUhNVAeMlAasV0i2sRyAGt0qAYghViu1kaF7L/Qbr77ec8LFT2SgaFMCC+R5BDydwNiSdGv5ywXH1hM/hTLDv1hZfVX3hFE3ZdqR6RaoJ9D5KIhIgW/r7n0oXoYnBj9Pz5XRPifWxoImJhlWIo0/ITwxUkgMWWLRdPquNUFxEuQX9VVOysII3vO8FGZ0lHQMWrl7ghbhAdsTPcQNnzZlb0UfQ21PsJlK9Tdk+2+wfp6kKnWkaXEmAXqZKfBymin6J+fRsy0+c+DXg6kvfzIbP4AidBYa X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: 51594e7f-0d28-4cc3-dc55-08db7df9dae2 X-MS-Exchange-CrossTenant-AuthSource: HE1PR0402MB3497.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Jul 2023 08:20:27.6973 (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: 5sTPok3AC3m9O4Arp08ock2z2o3kJjMPARGuASfi4/sDx0IvhMHXSvGcY2R4iBHwLRNEpyVHDivM/OGP2dZxfQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB9PR04MB10066 X-Spam-Status: No, score=-1.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FORGED_SPF_HELO, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: bpf@iogearbox.net X-Patchwork-State: RFC 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 Jul 6 08:19: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: 13303339 X-Patchwork-Delegate: bpf@iogearbox.net Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EB5881FBF for ; Thu, 6 Jul 2023 08:20:37 +0000 (UTC) Received: from EUR04-VI1-obe.outbound.protection.outlook.com (mail-vi1eur04on2071.outbound.protection.outlook.com [40.107.8.71]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 98729E6E for ; Thu, 6 Jul 2023 01:20:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=gkJFMY4H7IVCH/SBdF690gq7PFI9uOItLKR379euS/LgeeAWsHhCZSgpG/+o+stcI63gsypP8KR5o+AdmzUPym9L87W5zcoeddMbuHrvUOR8H29vRdTXWdDfsHeAEcur+/eFcpJyXBjhL/Lj3Cel9AC/5//rbADEqUlWlUlMcH4T7j2SdVcG00k2XT8JJPoPwPrBZej8eurQjNi+UY4CgCJdjzUEwd4pVOEPNKH+VlEE01orJtl9CeM2padDajDanCQDHT7sFerz3sbQPMjeZ6KZGVd9emwPJxoQzhmrbDgaDAV8zNYI+Bn/uKsdx0mW3qXpJjtm6EEXfxBHM8AcxQ== 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=YoV861M//CggYMx/ntigXt1CYAXI6xhNp+GNJSoiv9M=; b=GUbEkMA5eI/KvkH0zYEnxgLijyGIJknNWEtsJxKa225YTzuT7L7grsxVVITkRt77bPgaM6cTiBw9H5XC+nEdnlOxlmR6x0mYJ0zOdhNIFzTcunoa26FmlifRmB406jlCQcdZcCkJZkQ4wLgLtUttWEVyi5oepEwuFl/yiSI5+oOIDQZo1FKpSqV4WeKq7PhTAU/mWcH+DHLsnlRACmsts23BCr+RkVmi7FGH8dbCw8mJWGHbd/Ng4UURM7Jo6PNLr/brp56pG3IYeZ0dQMpknd9yS4D2WodRf9q25iz2GhH4Lk04e+wJ+HwlKNzoV5N7uDxLQCS/Gw2UgyJZwQ6FZQ== 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=YoV861M//CggYMx/ntigXt1CYAXI6xhNp+GNJSoiv9M=; b=0JfEdGLmo15W190JuJtnLWk45MRxRQZFGm6Qih9rSHbdd0vawE9EInKoNdFTw1izhGgmWRcZcUm5yup7AZ7wiEccyOlsSLrh4TmIAYfBZKpOydoby7VfgQxBLJ4G78U23gYDnXRTLa8BqnL7URYWbiPPCcO3rgLZ+/sSRdcBG0BMEAk7F8RGzsoOcifaXbHxBdF8aF4af+tsSLfb6bKOFgrB0S1rK1k9HCNwErF6u3ehzRR+FGVM2BCKa87IZm2QzNVaT1te1Sr70o4zhqNYu+hV2zDy0KToiQAFebRtH5SfAc3mxylO/fLO6Oa7Hk382+8VUo+JAjxQzhxM+smiIg== 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 DB9PR04MB10066.eurprd04.prod.outlook.com (2603:10a6:10:4c1::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6544.24; Thu, 6 Jul 2023 08:20:33 +0000 Received: from HE1PR0402MB3497.eurprd04.prod.outlook.com ([fe80::423a:a30f:5342:9d35]) by HE1PR0402MB3497.eurprd04.prod.outlook.com ([fe80::423a:a30f:5342:9d35%6]) with mapi id 15.20.6565.016; Thu, 6 Jul 2023 08:20:33 +0000 From: Geliang Tang To: Alexei Starovoitov , Daniel Borkmann , John Fastabend , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa Cc: Geliang Tang , bpf@vger.kernel.org, mptcp@lists.linux.dev, Matthieu Baerts Subject: [RFC bpf-next v3 7/8] selftests/bpf: add two mptcp netns helpers Date: Thu, 6 Jul 2023 16:19:46 +0800 Message-Id: <284f75cccd4e848f17b54bec67b6889fbcde1a35.1688631200.git.geliang.tang@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: References: X-ClientProxiedBy: SI1PR02CA0022.apcprd02.prod.outlook.com (2603:1096:4:1f4::16) To HE1PR0402MB3497.eurprd04.prod.outlook.com (2603:10a6:7:83::14) Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: HE1PR0402MB3497:EE_|DB9PR04MB10066:EE_ X-MS-Office365-Filtering-Correlation-Id: bfdf3401-b54e-4b4c-7c57-08db7df9de3f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: KwYJLjlI7gKwj+39smJblv26K59qzSlHkhJW9ktKfDzhjSD5yYMQVfNkb2s/9k4R5EkGX6il4tGCy22R6ZVROB80h0WWipYvEaifaubRPmlWFxStg4jmFqNCKueyBrKqi+UbYZUiXAXrdXy4yO47e6aS90BNRsTGD7xKnEc6oq+5bl3jzCZm4FxEX6U0OTi0wv0E3QM53av5DtVPJMNF/LRxYneYTpfmrIG8hq2qEYw6ZX9oxzbpJLkL53SVuW2oDQW6vsMjnFT5uG6c81R9Ujv8f88B/AnpmT2eqNBaxLuSCPpCNetqeSMbSXwEnCImzCOwUPJpS2M2xI1xIpvUztHF8Culyj7L1EAxxtOu7XCtdKjYCePy8MDs9Nf5NwyX/33rY2s7Cbm0YVW1TdQI40fsv9oeD+lGo57z/UJCwD6gJXGD3NW03hHHVRbACvq9I1ZvCa0c4LeveqGYRgvN74e/0mHuii24F4/e/k2MBg5zftiNhSVowiXjx11eA0voHbI8/jCcBLrLrtrqURF+tY04hUFnEe+81vVaICe+1A6zTnHPXGtwbLuOX2bAJMlm7bzk/6l4BmBAJu+lRQUEVaz3NpF6fLn+uZFWFRIUMwFxDo5tsze2hAsS5nBiatIa 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)(396003)(366004)(39860400002)(346002)(376002)(136003)(451199021)(2906002)(41300700001)(7416002)(44832011)(8936002)(36756003)(8676002)(2616005)(186003)(6506007)(478600001)(5660300002)(26005)(6512007)(6666004)(86362001)(6486002)(316002)(4326008)(66946007)(66556008)(38100700002)(66476007)(54906003)(83380400001)(921005)(110136005)(13296009);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: p9JMdtEeHiui+I24XlEIQ4eER9BzlTugYZDjtAhNfbKEn1j9qCA9GQSEeIM8vIBX0OWBeP8ua0DKYJsXexwrLelYk9yR2ric29iT/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JgeGaDCFn+qrvYSuF5liqBSzZD0+NgFPMLscwOL8BLIhYIr0Cn5JIP5tXoMunw7w12httgUxx7tx8qkFVE6bCuENvH5G0yPXflSFwqhPnTDIgpsDDesBHb2HT8QnNxfqW6/s3HuXA+ZtlZu/XTdgG3l7g0vZKqxbmEaMfLTJgKWMh67+uE8gLmI19an5cikLbNupXTvq9dpORWZWRlWMt3nWJ8BpwftEgx+BD0bSuEk4rN6k5v07iUnLG1OGIbW8QkzDwk7asOTQbmO4eNJ0bjRxX/brzil0mVhmnOe7QCfcvbWXi3ht5JwlmPcv1RqfZkhGuFIzJbCs4S5fdsCnJI65uxkwW8OsPq/cqX/MrEKhD7ca9v14S6B39rv4p5wovU8L/JlNmuaDZOkZB6KUUzUHZmD23 X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: bfdf3401-b54e-4b4c-7c57-08db7df9de3f X-MS-Exchange-CrossTenant-AuthSource: HE1PR0402MB3497.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Jul 2023 08:20:33.3139 (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: jKlO69uUdPYqZFNoiy8iMXe4Oud7U7uk73x4YuPzM+1vomFAGzuXcGj+P2qDvpOeyrOYf4F7n1U3Yla2KuugwA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB9PR04MB10066 X-Spam-Status: No, score=-1.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FORGED_SPF_HELO, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: bpf@iogearbox.net X-Patchwork-State: RFC 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 | 34 +++++++++++++------ 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/tools/testing/selftests/bpf/prog_tests/mptcp.c b/tools/testing/selftests/bpf/prog_tests/mptcp.c index 4ccca3d39a8f..b2a833a900c2 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,10 +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 Jul 6 08:19: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: 13303350 X-Patchwork-Delegate: bpf@iogearbox.net Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 504852112 for ; Thu, 6 Jul 2023 08:20:46 +0000 (UTC) Received: from EUR01-VE1-obe.outbound.protection.outlook.com (mail-ve1eur01on2058.outbound.protection.outlook.com [40.107.14.58]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A52D91BE2 for ; Thu, 6 Jul 2023 01:20:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=oazFhdQ/7E6893WWPLBAqeRy/71NaNpYrAwlBI0G5bOkwjrbEeRn36Ca4OrICwhqpCe9A1m3jZCNzifo9BkqhxfZe1Dxdu2eKdc1AyiSWHL49jyQ6jDU0vzEy94u1T2AUWR0QMwVrZVSG7vsi1YhnvlMmHTWN/d8v56/zPdFnOmnv4jFMHS2Bd7mMacTQuyGMsKlQ6Ez4moeV3fwgjTJ+OXggDBi6pPlhlzUX6ujJTe+jhf+87J58Z1p6AdRYC6MIB8uEo3cCiYKmEmQsFm/ztpgLgfb7oUB8qbCqHvJDMTocUn+cnexbEj2mxzYolWTCf1j3mWKoEpLFJ0A8hUP8g== 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=SsSYoVTG5aWN1RB+BtJakyrG0agQSne+82NpSdcxne8=; b=nSBCLZskjCSXZaGm9L7Otc8Kwu9Lt3cWfJxpZjVOllmn/8e7296w+p5Be+VdOiu0qMZvR42tSILGlfH8y/fet+W4icXNrM9stSC/pZQyqlM9Bqm7PA6Lz6OlyoCIFvoMIj2vO7RVCXmw4mG2CRxLJM9mzPi6M9KiwHRGNjTQ7Hfvsq2f+/OF/nPKPRTAy+Drc20i+XI0VjcFOpCTfdlVMVpcONCO1QJIr481m+KlLZQmdWlI5CU5k12r3othRx8qSKJcU0oQmse0vJ2W8Hjq3Tvgb5UC2G3z4utFeICLbI2eT7nrOC7n1brWk+0CMssQkGeSuBrzwI4PAr61lJgddQ== 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=SsSYoVTG5aWN1RB+BtJakyrG0agQSne+82NpSdcxne8=; b=WL9iE5hySud+NV2s0d1XTKBnvAzZnRhFyoglleaEKvjkuzwz4p/VewVJts6vegkfP97EB7MoiiPZw8WTKQkvYu2ICHDKb/7TIgiZ+6GCzs4iTLy90XkMJJTfy5TFgOK4GFUUAQXo/1cBzBUTPH0VnN3udN/X9JAlVEE24pKOIrjvG7pn47BoW67Pl5geDGVRkKIKu1WM1CBLaE/V4Hvt8nLPKORWgjDQYjKuUYT8YeMri/un9aDodZJkKMoyBTZ9hbwRXHXuj83l3ePgG6p/pFlT7C9WYCewpRFTSJGXJcpw4VA2bVDVTCblpC6P7t4IAdb000TUo/PbtkIjjOmJuQ== 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 DB9PR04MB10066.eurprd04.prod.outlook.com (2603:10a6:10:4c1::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6544.24; Thu, 6 Jul 2023 08:20:41 +0000 Received: from HE1PR0402MB3497.eurprd04.prod.outlook.com ([fe80::423a:a30f:5342:9d35]) by HE1PR0402MB3497.eurprd04.prod.outlook.com ([fe80::423a:a30f:5342:9d35%6]) with mapi id 15.20.6565.016; Thu, 6 Jul 2023 08:20:41 +0000 From: Geliang Tang To: Alexei Starovoitov , Daniel Borkmann , John Fastabend , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa Cc: Geliang Tang , bpf@vger.kernel.org, mptcp@lists.linux.dev Subject: [RFC bpf-next v3 8/8] selftests/bpf: Add mptcpify selftest Date: Thu, 6 Jul 2023 16:19:47 +0800 Message-Id: X-Mailer: git-send-email 2.35.3 In-Reply-To: References: X-ClientProxiedBy: SI1PR02CA0018.apcprd02.prod.outlook.com (2603:1096:4:1f4::7) To HE1PR0402MB3497.eurprd04.prod.outlook.com (2603:10a6:7:83::14) Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: HE1PR0402MB3497:EE_|DB9PR04MB10066:EE_ X-MS-Office365-Filtering-Correlation-Id: 4e6e60af-6176-4780-663f-08db7df9e312 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: HOClAb98E6znjQlJIVmxhP5BbheKM8klGHPAvVZ+7UFYQ5g9iTA2G4GgkO8KYU2J7vGn0p2WfkW2QPRq/bEU22A8n2CQOaxXYJGOM/lecldOEVBkO42wfy6xRXjKzkdEHFQ2JjsWNkoKIRFuymPbbTzmuQokYpRpK8IFH2rtUltlaElSQhnivne3djWmd+lGqKrIRPI5/6XckL06E/No7vmQuP0Rej0rAUOrfnZW3Br4s4inPfo3XLt62ZxAg6CEaPpxGJOj5supafr9xKNkt6F3fKJG5vAhp4ByzkRZcD0EqW47wXsxqMwI5Wd4Hy87OL2m62rgAFzW6s79nyr9DQmgDQqEwJtERsGiAnMRWu2OMPYTsFi10MSz70AxcZba8EaRoN5bqpJPtD5I1bSVoq9iaCZUvg6fWxX3oGeuydncOx5sHzHVTzcRmDfgPk9KNwKssG1srIL/Y0CZOy+6dD0+/kbdje9pv2oQj4ZTCbiHEHLWsVOxoBHpy2TJhBft7o/2LmeUfGdv+BsbMfqwzrsQkrPD7Fp83jqwwwdpYQwg1G1Yt8LxUGrlnq0sJNBIbs2tnQ/EgWeGEKlbl2CDqIifEfvARbSCTE4aQaeofpUji7YuiXKB0LUE2seeradn 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)(396003)(366004)(39860400002)(346002)(376002)(136003)(451199021)(2906002)(41300700001)(7416002)(44832011)(8936002)(36756003)(8676002)(2616005)(186003)(6506007)(478600001)(5660300002)(26005)(6512007)(86362001)(6486002)(316002)(4326008)(66946007)(66556008)(38100700002)(66476007)(83380400001)(921005)(110136005)(13296009);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Q8uVEOjvjJWiZU9zXTdDZnWHdV45Uh3ydqESdXU35U4mTEczQ2K9i3MAM1ODAviNM1iqyWwLdiu5Fdc+KH3v1mgRZW6xWd70+cXzbXYjTodE/gX3M7RHzSqRBVk7MgYuPtscBXcAAAokgis+j0txz15xjJVXgwSvoo0GoOXvFmzenFi+nDv/oCpWNd4xu1N9FzpgocXcCYNcsz8BjdJUI0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LG5tH24FyUuTwBKBIhIGSATfgpqilK+ACsZc8dvArGOiYlEDma13PXfD1mAdAugS5qdUGZszMUbfSlHICK+9NN4jkKA3GjU+LoyiIqgtX3FRbdaqIQktlYBKiG+1oSDHZbRDgGCZY+5XdYsoWyBxmuGtFQ2U6nqxffnbB9XumRy/TpE73qljHO+tfRvyQdeHVfdNiZuxZcZ0AHKOFxfKjGb6mBAeYqapjxlYGvDGS5NjexuvfI9zFCWd5VpYwe8dkBHRKy/O5/BqLzev8NJpV9iHeGweDu+xKuEQzNxayP1gpc X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4e6e60af-6176-4780-663f-08db7df9e312 X-MS-Exchange-CrossTenant-AuthSource: HE1PR0402MB3497.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Jul 2023 08:20:41.6355 (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: ER6BeuBK0LK/Nbu4f/2EbK8wjYOsKCc/QAJj99FGCdracHjQSWECPWhDFwQdZv9EgHnWV2xIzX0VTBAyiKQLbA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB9PR04MB10066 X-Spam-Status: No, score=-1.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FORGED_SPF_HELO, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: bpf@iogearbox.net X-Patchwork-State: RFC This patch extends 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 --- .../testing/selftests/bpf/prog_tests/mptcp.c | 91 +++++++++++++++++++ 1 file changed, 91 insertions(+) diff --git a/tools/testing/selftests/bpf/prog_tests/mptcp.c b/tools/testing/selftests/bpf/prog_tests/mptcp.c index b2a833a900c2..39fef907cd3e 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]; @@ -196,8 +197,98 @@ 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, "mptcpify__open_and_load")) + return -EIO; + + mptcpify_skel->links.mptcpify = + bpf_program__attach_cgroup(mptcpify_skel->progs.mptcpify, cgroup_fd); + if (!ASSERT_OK_PTR(mptcpify_skel->links.mptcpify, "bpf_program__attach_cgroup")) { + 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(); }