From patchwork Thu Jul 6 04:08: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: 13303162 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 4890EEBF for ; Thu, 6 Jul 2023 04:09:06 +0000 (UTC) Received: from EUR05-VI1-obe.outbound.protection.outlook.com (mail-vi1eur05on2045.outbound.protection.outlook.com [40.107.21.45]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BE4461988 for ; Wed, 5 Jul 2023 21:09:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=BDC5lScujW5KbH4XAkEQVGBsriSpbDBDfgbVE7RAPPORAesbL2byyd3VHa6HRXsyZlaH1xpOH1e2IuijppZR/rpw0qAJe8/Wh8yn31S1jaGY6PEHi4VojMcZ6LVf+7lpjzo6sPQoWwAFHVXH3SMcf09UipSQfZVe+BanarJ3Wq0zWvi4VL4SSdj15/sq3LHUnoyCOjriTyWoz794OrxQldXsDtT2o36b2DAmqGTJIfxKKer3ciwYRn11GFDOhuEIUnirJkZp2+eBqhfP6jx/B+YihRchUGbaY8PKxT6xi8FGsJxY6SMvIlsoE7PXpGQpEGa4m9EDXexUITnrL/92pA== 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=bqD3w7ZY5VFG/sjgJrF7MFTWMvDUoiWM/n+U031hCR4MCRWQh76mqHFNz16aTFemDg09g/Zw+0/m2ZRvz91fnKMv2vBsTKjGllQ7m4+ipclooch+4F7cog271C4JCS7VIP2xwLg0i/uL3O70XeIL8nUtI/10WwCEZSw9nXAh8m6WstHw8fTB2RTbxfwFf6qQEUvNRI2sQHxxSyB6Lrj7momG6Mx0rlC5ieW5BPCFsPIn9iRq/tleD6POOfYV25REHZl0OxnZUpXyIJ1J36y+a9gIVZHt43S9KFQ/AphxAi7daT51IXrSjETBP11t94YfFON9chiz7G/JbjrU2yONDw== 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=fA5Mnf6JtQXyvfgVz1HRrjGvy9UMf2qSUW2iYI/ysf8FXqcPYI8kEajlGSGPyXDdpfdNFeAbU9u8ElhAW21RFCSIuBAHQGYQbLF3VVdVMLkVBOylbJdmjurQNKPFte0jMfL73IwPjj1waEknNp2Q3zRimZxV9VRVH5Ev9kPgBgXdISHn7uPiwDtXGdfs+d35IaWvptZ0xjWqOLb28Sg1uo8J+10Dm5TSzg+dzeCJTlQRyni4FAMRyUktU6RWn36+RguVYMTQciTBFKHBfr2KGFdObYlFvXi93VRHvRvmFx2p/3y7f2kBZC9e0z3imCciZSio05BSb3xJRh3c+/megA== 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 AM9PR04MB8828.eurprd04.prod.outlook.com (2603:10a6:20b:40b::18) 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 04:09:02 +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 04:09:02 +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 Cc: Geliang Tang , bpf@vger.kernel.org, mptcp@lists.linux.dev Subject: [RFC bpf-next 1/8] bpf: Add new prog type sockinit Date: Thu, 6 Jul 2023 12:08:45 +0800 Message-Id: <0880130fe8ba0d721e63f6d37bd8ff6311eed9bf.1688616142.git.geliang.tang@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: References: X-ClientProxiedBy: SI2PR01CA0040.apcprd01.prod.exchangelabs.com (2603:1096:4:193::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_|AM9PR04MB8828:EE_ X-MS-Office365-Filtering-Correlation-Id: e40689b9-a91c-4d2a-41b0-08db7dd6bb2a X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Yt3xNz4wyB3mUOHgy7/ubA/6H9MPB9or6xJdGZuuTN6EYUcpXUfyaTStqCo3TCp9gyZVgpRHUDDiLB0LNbvDPJyYzkdhsrofvgfxJ2MaHyBGfi3AyGCzZ1tUtxDjCo15NoqVpJu9gRAP7nvPGFUH8ri5UQK8zXQGETBK9EahwomyAspMrETXjy/6O0egkdY8VLAoXLMhxPn7+RBtaACk0dY0GfKUIC3fd1Xtos7URO35F1V+Y5NxO12u8T+G5LDDAtVPrhDjBQ4JAqzy1fXFr3vM3lemUmmsExLoEE7AXAJsjA6iXwmm6d2vF/rhQxHXB+RTtEt/0QEQ7f96BFDYs+iDCpQdU57kbVOoKkHjIKXp2hFyyPznXYDNOxux5veIWCtaH63zsrsJQ9d+fUovyKVimnd/dZiKf9NZaFtUSzJR1+FkeTmLqwQrgVvOp3np2jI1sH9TiY15A0m10A1EwOMGlB0Hp6aVS99hoyTjkBkzjKZHo+HGbaIlZFeRbFbPoSG+PsxEcLS0FI+4Ec6ifm4m8Sq3CLUikZu7HbakfkEvl2vBkbWwql9ypCBWWenA8CWd75RlL+MQl5Rg6CC/D7kjw7LCHgRV8h3+dnkbyshXx3JcnCdDSVm6Mf8f8rj0 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)(136003)(396003)(366004)(376002)(346002)(39860400002)(451199021)(2616005)(38100700002)(66556008)(66946007)(66476007)(4326008)(921005)(186003)(36756003)(6486002)(6512007)(6666004)(110136005)(6506007)(26005)(478600001)(86362001)(41300700001)(8936002)(8676002)(44832011)(5660300002)(7416002)(316002)(2906002)(83380400001)(13296009);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: qj9vo1YAOyE3WlDsDKfuNvd3w/yWlfIolb1hlTQXLvlowUFRz+QwB6HnqN6D7Y/L0jAK8o8eEQ73XRrwKviroz9QG36GrVzBxWrHOVhpUQBmDG/Q3NA/IOxz+MxHJmu+I0cqiFSzQH9SZbIYBV06PGdkrqZhRlkWTFCl2SN7fM9logSGP0+X+m0nvoIPajUTsEZVke9BjjL8IQuDflu5Pp+KCf73IPYUbDRCMg12zP7hFVdxQPbs1rWDuiMqLWQSnslRZxoEmQuhmMN20o+tcJ4zuHdCWsaRj0wte975KsmWHuz4QpRhxPOyzObykxUsR6xWybjy79oGAGWKdM/diJD6wVSPnw7n7ZRjJIHDJ9j0ZzL6LarWXkxJgIBrN8OhG1HhSgjM+AVi5/AMQcRdS46P7aJcmxo9LT8toE+zlmRJloRSDvpkO0m2OO5EQNAgn+Jopm5XBubUvMOYk3NPTkEte7GfKaghjGvjVVuMsMD/2lAACcl5ATlS7jBOSzksYmwqsnq6OczvaZELijtvvS+nIzk+nvK3qDTUPXkTn6gSkOjEh0sEDN6TW3eZiZRI68q8rjqX0kKYpJyOXdASpfgrEMSVk0yEvTphA8RSxMvn6YyuWSMG3j0SuV+hM1p7L8zhPVRvJ7unLESsCwhPSfR+tEL8mfif8pLVRBOhXHATWIUCP+xJrtX+NYyc1Cl7gflhKAPJEUmJHX86o/WhTUIWwN7jBAIvPWOfo/Xh4UgTMUfLBJx4s3m5jElb4Hthd3DMmWeNpa6eMmUP9W/eHqxAyzy9E9cFuUIlS3cOB1Wh69sEdd3PN/j+0UcJ0ax2HcFPhUsSqxVKMd77HA7Q4CUy1WeRj46FIno2dJ/c/XTSYPB+Yg55wPY40hMe1YeuxNt48fmGB1Z9TFxQLs4q+kMxnatBB7rNy5L4TS+xagA3njOwzmDvwyGIaAAfkny5RBrpvhtD/6EXsC+3YTsubQn764q0x0yFBBYdthM/bT0Monq/ZaDxbwVTWxPR+UwRGCo3LpM5gKaWR7g+5KDps2fUTFrx4Ki2a6oeFs1/Vp7l3rlhICD31f1SnbqYyHBjaTcNteNAfg51nAfPjcLqPH8XUfcyGZvFI87S3C0fEXysH0pUwCbX+/VRIqpN51C6fuMHzxTmbm9ualTBSgv8rtnlgC5z8BHNF8RKyD8/hH/i0Rlqyg47jUVEqJSJ9pFVH0ETYAnd6yc0ILr8oggiIzefW2SmSFjNVaZx4qoQRLT7d8Z7au3lz5ONcr7UkyJ+IH+joA8ePjI6fDKuUrm1BerEz1ta4LwMdpJAGPmgHTwEijT5Qc2m3LTNT9zgZbWpTnZ5K3mGiNq5g5lq5YNb7LEBF3kixjRy21v9B4pyaCBJqALKjpBGI4XzWNGsy0nrIUoEQcaeIGPsAcXKuOcvh3fz8hOK5oQtN0lthwThCVnVn/vYy+zpj3Wcpmz/hd/7x/g1oQBjz4BNnPiXoykfkHqcZyGOQfT4Dk3ID+3VQHtJNGY766Byd6aewQNwZDWgNPIYcdp3C3znOVfOStIGiqzoWEWV8a9dPnk8pVrgA1/hZx/XkgaHbZjcuF4c4S8E X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: e40689b9-a91c-4d2a-41b0-08db7dd6bb2a X-MS-Exchange-CrossTenant-AuthSource: HE1PR0402MB3497.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Jul 2023 04:09:02.2487 (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: L15xtwvTyEpNdtCZ0YXdANBT/O6gc6bThvTnDUsaiWtTve9DmF8ahGiUJQXa1RUm+M0kVI1X8UsHKLexzeg/mQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM9PR04MB8828 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 04:08: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: 13303163 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 F34BBEA4 for ; Thu, 6 Jul 2023 04:09:15 +0000 (UTC) Received: from EUR01-VE1-obe.outbound.protection.outlook.com (mail-ve1eur01on2083.outbound.protection.outlook.com [40.107.14.83]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3548F1BD6 for ; Wed, 5 Jul 2023 21:09:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Xt3AaSzxxLfxYYU26Y8WEVZyHSrS3bls4sd7CoK3XnMSL+1xKhAyczNj6J1kCHiTXmfcHCQuzuNqbHant21qH0XsF8ZqQSWYmCiSghOeyJ7LEF6ybIOmYLvGF4kIqcfg1Du/w+nH7/yiD9aTVX+t9iCn24oil4zjIO9rocb+PgrY0hfNY7USOp3S0LDXyiYCXqbPR0HszeJM/WapHIsPQpPji59H1SVqCV9Do91c0BZ/1YJZIKsCtb854QmZXEyoVhWtOcBBC5oi8wCHX8+fQHc4ZQgna99FzJdYC+0+sxuWyRm6YnEIt5oeF9TAYlfDXijV+QhJsZppJLryycRWPQ== 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=QqzLn13YZlG2zp9FBXYyd/lAm9DGSG7pEXQp2cWwx9wC2rkK49qSlkUAfJbEA0kaA/NhM21XE59Mqw48ikS3NTDU5tlI4/bSkJtY/cVQxUJL9sTeDnBoAH9gFO+cNPGCjJWq1JDxr6omy9el1aZg32tH/+J53Vpy1J10b6NhzEJTjD9YUXbBzmc5d4PyT0DHb0EvadU9Oia2sEWLFLn7e7kA9CoqyDkLtEASYO4l6BL7SG0ZjnQe2GoKUtLcA85K9oRwI2DWaCxTsFY71GNv30O2rAtGc1CWA363bGyD41is9zbzL+Bq5oEUQXHXYLJB25LzfeQnV2+kubP8l14Rtw== 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=TAy1CT5Mb3We4ZJ8mal/WToEISdn6X8IS+6E30Bxn2xB9LmbY1GDaGfxlVLy7+vyr8HkSxI8ifV/l86sQx0Uk27BXHgoOgJu1aeItMtNqYGL41ttBoMGXubGMP7SncAu0Z/FVyAINqlj8qHE7jhN6Om+pqVpYcPa2qZfhBAyoPeqsbarpl+zVTru3JdjVXirThrJOsPz+Z8KYT7fRMeAwe8hDBuh3mjbraZlt6aXtI1LPPoatMRnh5qjbi5I+6BweeXocz2CKmr/te/teeRsRTmMb5dHTpVjuLcrjq08ktLlWMHiyTb0bGsq7pY4dWTabjvA6cJH9sggj2XxTm7ZDA== 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 AM9PR04MB8828.eurprd04.prod.outlook.com (2603:10a6:20b:40b::18) 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 04:09:10 +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 04:09:10 +0000 From: Geliang Tang To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , John Fastabend , KP Singh , Stanislav Fomichev , Hao Luo , Jiri Olsa Cc: Geliang Tang , bpf@vger.kernel.org, mptcp@lists.linux.dev Subject: [RFC bpf-next 2/8] bpf: Run a sockinit program Date: Thu, 6 Jul 2023 12:08:46 +0800 Message-Id: <1654cf3707d93253e1891084c74894a1f535abdd.1688616142.git.geliang.tang@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: References: X-ClientProxiedBy: SI2PR01CA0051.apcprd01.prod.exchangelabs.com (2603:1096:4:193::6) 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_|AM9PR04MB8828:EE_ X-MS-Office365-Filtering-Correlation-Id: 0df549fe-a423-4fd6-78ac-08db7dd6c02a X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: S7pcFZA4yej74WdPo53fL4HcgQjhw1VUx5vpCDaoSGdwf92PfsoSbzvxKcLfSouC+R8yIA4PJt67omNppp8Gz9fU+ShsXGpgMDeI6xSKYz8TBxTdzAf9oVjtJbCkp40hMgoKNXAPL19f/2W6njDlL3YNPOnnht58Jc4Cnucp1KFUpHoPUEfarRE4Q++laOTCZkFrGVITqFLC2kQfp0BvVQwhQB7lJ4WkMLs+vQVz8YHxFvqi00EUdCE8ddcQCoqCAmsH3/ONggM8kJpeWN0GHnXqr1fNGkbpt4KgvMniRQa9ibRpTmvpwBGN5QUN+DCbl5hfgUEsVMHymqviSEHTZ46EU16VjUAIRuCTWa1P4B5G9nsKE+9fbGp3MYeG7QKmQfggP7VBwDqV+gI4XjL4FkT6BBZJxD82antACqhcbUY6CYT2T80ilmkjMd7/H/tD7b2dGue7zhOSoy+/CR9zWgxJO84wvRCphDkuRiY1S9oTkOm+jrkU6iKuN1mGQqwFEXfjZSXkxtp3DDCvqqPXXZHM1SI5x3LOz+dX3A40ODqbPRZuu46sYfS+rhLR/UF4d9bo1nxawhP514FaffV6nOWzmK2CfXZ8StZt4ldS31rvxYDcy1dMM04wbUCUB6uc 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)(136003)(396003)(366004)(376002)(346002)(39860400002)(451199021)(2616005)(38100700002)(66556008)(66946007)(66476007)(4326008)(921005)(186003)(36756003)(6486002)(6512007)(6666004)(110136005)(6506007)(26005)(478600001)(86362001)(41300700001)(8936002)(8676002)(44832011)(5660300002)(7416002)(316002)(2906002)(83380400001)(13296009);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 3KDsbsv/ERqtBWT5xgxiE+iZ+S6ZmklK6GloWyZ6KGgXBeR3fRrdgC9pCPaEdAR8PJ22QYXtvhqvoOY9W7ievXGuMgSTGnG+eRZl3oK1Da4wPfs66SrN1zU57nG9cNL0KinufXTxKOTAO4twZo8yE9W6VCLE0+2q8pfjlVp6TNRwBKXbcgFaw43kYKEU86Uu9SiUljVBQmFH+L0sDv72+ArCPn4KnYO9okXawf38Gb7lpaff7/KjE1FEnRx5ambUnBEqpiYBMUEQtJD0QQMyTRBlcS1BgBGpRW6DuFIlBiwQUnOJ0Mo8PkB3QE3zYem//0cYYkyo0Y+eCnc5pUdliDIvsnrMPLza+c9A1m0POjCm3xOLCTrWzUlxkvb8ZghfSUIijxbOsK7/SoFMEXdrLS5A2oR2m6gXYiN7MwS88BBVYEOf5gCO+OQVQPA3jU5y6dfkyDVTAHmGy/vLHEHDs5dpNZRH0dAN8F3gIoBOF79/mB2ef+EaaLtRv30K0ohylY3zW1fOph563e6gpQ4kY7js2uoZBBDHlapIOMboeEKw95Jhp+Tl6Han8sv2dITTVvJQbvmFfDOt9WPcS/nIjCH0ywudLQ0LJMqz5IxZFHBvfSVgz8npwLnsDAT8ZOLSNFkUKoPKVhFccWb6FQrvR86GOYhFvuGbMyB5ObRII6SGYbzaQh3ZfrOrBfh3KcPkRkDax4gHyigJlFOrnalUm+0yQkY/6EqSE77PeaFtx4rvv2Ycwl2Jc2Zcz13Xqd39qmirq39sXX4F6FRg/uyUC7mkfjdfu1AXUHKVowwQEeNkUOoTF2dgyMBXvNUNuGBatB6gZKzYQJe7Y25RuITtwg+BtfVS/3/HFOSVaKauhjZ9mOEFsIPZjqrI/LJznIRkchsvMQcY/zSCBxmnl8Pcyfd8HDs3tsJ0h5wh25WnifWyBC9qU9zDNjAhRjAUsfeAsWuZzGI45dlxS51M8e3nh9JRSsexlnp4iQg3L7+vC4EIpLuwCJIkgpn9KhyqMTUPpKeUMkk7D24e8J9HUxkwxr7kFyVsTsJkD1+7L6vkJhnVH+1PT3P6UxzX+gVIesNlxke5GO8f/6oAbdfxlE6k90tFh2QTG9T1uauwkBGBjqWe0Q27HrwEDDjbjxTEvzlAkq4mUpyzlW1zC/KMouEhMDu75YD5DeQrunccZsDQkxIjhLgI8SkdvFpdCTfhvhXlH8DvRtzkES1iy9IHEBu0yXAk1fbpup2N3KWM/6o2K2Sh5jWJuxci63wUktQmfThEaXuBEr8Is2SO3h5pwdfzcuWBoHUwCG3f9hENKbBssHchhp2d+OCn9NtliTSDNi0xbw5/cIXQpDXHv/2WEomRkMghtivJ7HnlYRgXNL1jEsDtdpmPaGe6TWQ1lkDwNF6ObUpEkHTXxvJJsN4c4svZsAyrJVVtUgoBGuIj3Q7TSGxO7H57yoi3XZk9OMZUCQYD9gpkTVtwle2EXoJYLxO89BE/vd9SaWBkzSGvRRMRNK+O92qBH8m+hRgboQKD5GvL8oyhPcrgsDuEXOzxe3JUvVM2b7MUd6SgQ0f+ZTq/Cb10kb9ePdaWAn+aacxvMAUS X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0df549fe-a423-4fd6-78ac-08db7dd6c02a X-MS-Exchange-CrossTenant-AuthSource: HE1PR0402MB3497.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Jul 2023 04:09:10.6514 (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: ZR051gTT01oXuUAxHyorozsXE0XPkXZraPfmlbQLG/QgSd0KClt9t3OE6ErOKyL4/LlnuvoejW6mYxrpnBZpQQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM9PR04MB8828 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 04:08: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: 13303164 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 5B42AED7 for ; Thu, 6 Jul 2023 04:09:22 +0000 (UTC) Received: from EUR05-VI1-obe.outbound.protection.outlook.com (mail-vi1eur05on2062.outbound.protection.outlook.com [40.107.21.62]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 688BD1BCB for ; Wed, 5 Jul 2023 21:09:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=d3PMZ+I0UP2pmupyTVdhCjqarvifdsG9JRfRyro47rGVVUkLwbfgmIhPHoc+RTS+0TrDZwuQoC3ngBh5DOSM/Lp5DHNGeiodHxufZI5Up9FJ1iBKJX8If02B2tcipbMn0K9E9/KJZY3kZzaSw2UBqvGb26cG3uIDWZLbqY0SRr1xdgGneGTFI89c1+hGOaFTh0+SBHvt/6wp44DYqY4m2ictojMIlQxqW8bBsVD1v1GCXNNszNQOimWKeNBj9eJJuf7QW7gqIfqvybY8S0VD/eJ+Fonyic19t5yl2rAKlkWOdeN63W+Kn/ekuSkehOlQ2PE0w4wXjKZivFJHqJ4Nqg== 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=icXieuQW1ol7a4sGY2tDvz8i/Tstgea4O3Uq3veqpPFbOYVb4PdLp61zhriK8UI9XtqBkMu738YFUqr59NMGT9ci82GoV++05EJfsyutgy208kZLTdS3MbTD0drPk4ADzQh7UwdXfVcXzcGoRph9yLITM8oomVXxQCvvkUyl6drmDcHO0j19q4TLl7V4SG2T8S2sY6zB8KbPxA99e7v70Dhqa1hagXSumLcFoQlfo4IO+/2Hau8h2tpu3Isj1udVM9KjSSNDT8h2hiqgwbv7SQnStj3Uuofyfu6eIHxGpMBsAZhbAlTHcIUWRT/qfXu3gg5BRJuIhmnTO7b3SAqvAg== 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=cIiFRlodTxi8CbZ5wfU2/pGOAZi7hZQxBu8AMZI7R+fqj5fky5/GstpA+4MDlLsV9/3OANcYSn3xIFmyx+PCTrANBXDAY+seEMjKb3Q1q2csBjEH2D4//6KK+JuzMyd8yrVcSkHr4Z9Y8kUHNcYk8gbJwLqbKRU0CJp6AZW4v9tsZQLcTt8tF4gMGJXGIsBeq3MRtuW137k8fu6tu8glblkZA2/lFr83vgrRPvqYpdRdhSVuqN6QI+tfGNh++kBpROP1SyxzqCZo4pduKqbC38V1JZtkFgJ5RZTWD155EJv5g3YXCZfJCLYxaIn6eOGyDQzfK17e9sdSO4cvDNUZ/g== 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 AM9PR04MB8828.eurprd04.prod.outlook.com (2603:10a6:20b:40b::18) 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 04:09:17 +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 04:09:17 +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 Cc: Geliang Tang , bpf@vger.kernel.org, mptcp@lists.linux.dev Subject: [RFC bpf-next 3/8] net: socket: run sockinit hooks Date: Thu, 6 Jul 2023 12:08:47 +0800 Message-Id: <5f76da0bea3453db04bb07399b4b1c9ce4859e31.1688616142.git.geliang.tang@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: References: X-ClientProxiedBy: SG2PR06CA0249.apcprd06.prod.outlook.com (2603:1096:4:ac::33) To HE1PR0402MB3497.eurprd04.prod.outlook.com (2603:10a6:7:83::14) Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: HE1PR0402MB3497:EE_|AM9PR04MB8828:EE_ X-MS-Office365-Filtering-Correlation-Id: 608c740e-f5ba-4537-4ac6-08db7dd6c41d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: dRSuJYurGFtB/5wXoJdXHEuPtuNXDwZHUjrZvJCklhJ/kmkpmJHV////+6qT2ZDNLDvph4akJHWC66OFPEwkFuzJMtS+gq3+tdr4qiRxTkJk8BGNrRfouPhLL4lQPiKMlzMWQI+YiQanoYvbZlmIqiHBYfRrS41wAOHKXeB6ZIkV/vw3BwMBraJnjAS2YI85DahOcBLMpmf8aGR49ta7G/aQD3gpOcsAg30CKLG5okQUi+k5SFUu2ad4xcg+hep+r6urY+rOohZo0Xecx9q4Rp4eQrrYcTGn2Ip/5Rtmrh6RG1sPpIzLR2HcqsoZGHj2onUl/WqW85H5lokn/AaGBJbt0eNpU+l6hWd/VYDrrpr3m6FZX6/dUmY8k/sTJAcJQ0xNMHmo+Ccfiny7Sd81gxfsE23Tw4JtMpb4cIQnvKp/b6NVk1vxGpkMzAvtgrfH50BbdyhPFLQr/2YPqjuYzNDBVQ9nHWcOoPxhTSFhV6Ap2b+6UaOyNsiIcRfndi/fr1pozxGsz9ZxVg45zdL9OkA6YoyboKXofuHYSz1R2IMQDzvGQGK+k+Cz48/iHYtjlxcsXsborPqlzuBj7sht7N64aaybNyZeC6QON214rG2+ZPhyVCXds5rMw23B/xyK 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)(136003)(396003)(366004)(376002)(346002)(39860400002)(451199021)(2616005)(38100700002)(66556008)(66946007)(66476007)(4326008)(921005)(186003)(36756003)(6486002)(6512007)(6666004)(110136005)(6506007)(26005)(478600001)(86362001)(41300700001)(8936002)(8676002)(44832011)(4744005)(5660300002)(7416002)(316002)(2906002)(13296009);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: AcBj1x2O1hgkB4Rdc+hIV1R7OQhdvOeu/jh53tSDY2B2sMSAHny/O6q7HKIKr6kEmZv3KeWOTOtOa1dQArNc4bZA8nOvvUWMLG5Cx5KQJ/AMxdg6jjLNQttl2S5NbW/V8cTBwOxGcjjrXnXpxWm/GPq4DtFmDFNedjhb9fVrZ4qg5vCYZ2rUp3SN32SpxUbiNzCMzz8LDgBDra7FAcNGatGipX21LnBGd3g2VUQAaU5OjA0syy/87pFhi0W4ckiOFERDaQhry4guz+54wMRRepWUt7wb8UiGVnoHgFspuTOAbZBXWRlTtFpHar1yrPxV6iBi6sNqRMugAbb+OX1aNvjSHAMozrB3rSpJVvPpmfBk07p4bswuvIgsJc1DOLpzdWEwdK2HzFbGYhzsdNRXvuVZzyfFpOlrogi0p9I2E3kwQMU0LtMHK8LZ3DzDmavlNJ7r1CqfjRyygsOmI9zkzOvVwZlZY53cDeef6t7kGpAOydpxDIPjeYxeDT7ML2D07y4p/Wzfu8x0oWBHZ2wa9FEoEGU9SD8dBA9Hl8MHPXJ/0LLp3sDiP83zjxRUUO7K7dhHWY3Myc5CE+Y2yTJPh55s8z4n7vL58NBjkx2E75c/0SF77S/sADaONVv8eyFTy7pBw7vjvp6NXEcpwSQ05+9Obz3TwZSUVkdGFqnwxm5vAX7eB8srYvBDC/ZimVcPbHwfPRt8ex+XUHwSJP6d42BjHL6rf10nsUqZbh4IcNYSVh3bf8FDqKNQBgCR3ej0OHSna6dHoBXUAPIJaJedjdtkkVIK/nHPfPTGCU/+I7IhMj4iytB5z28rVvOQ+PIKZX38fX4B4/WCmS+t+qiGKDJTrFzCeSohR6eTyS/VrGsQL9YdTTGSLeWsrU7HuUUqzkyfILWM7StCTBRAyuX/VLQBjQf202R//CCgRohw3axLda8Ks0ju0tSR/8AQ5R0U3zM7IkS+lBfai8KLh3MGcUWAOvZoWSt+0iDIcNTr6G8e7IWMIwAkxNZ9qT0H99WeQLFz+zuKWDz5KkAH4hf02zPQcZyTCD2w6/vK1UWsSK85/txtApH/koo3blHoiEXBmGsqyJ8bMphPRHHVPOz0SulBm7rcIl++fksizqXOnNH3Zya0OrhRDiAnkWJmdZhBCJVTat0VOrA9huFdkuWA9GK91NCiDP3EGj9w7s0Feyzasu6FXt7jDz9U7dfUag0XwNPcHehW9EVWrQsKy1f9xpF49j96fJmfSLlVIu19GtFdE/TbTRfy4Img/uBZt2bZ2nHRoAMnoleonvnjd6zLq9PUP9ian6XgTa7joEAZY0Lc6zeVRb3NgzFdMuWWOioT2hudph5U3sHhtbEuyaxkWAU0VoDo5k3guRPHls/Tu5RWApsBZ258niG59ibCfLbpr93GVqEpKOf4swA5wapWL3hSMEGiQB/ky3ePdjInFkvbTqG2AdH9tqRxRuDzwt+v5y4eSd/lODxPDb63VnCuxnCaYQ6LVBxgBbyG7rpItD2sOsKJ+TgnNMHdIB60Bn7OdOu7Ab3KrEqIpPNnoM0+RqvdWrRX045xGAypVRPqrSORcywuAx0yYEFe4y2vn5Tt X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: 608c740e-f5ba-4537-4ac6-08db7dd6c41d X-MS-Exchange-CrossTenant-AuthSource: HE1PR0402MB3497.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Jul 2023 04:09:17.0788 (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: hD22LYQOGSoDzdRnWJZVg2JXORYZPzTwz20g0jGy9nuFBSJiU93WPPsFyjsSMbesd9ZFjN/wUXaWpKfGvp7bdg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM9PR04MB8828 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 04:08:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13303165 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 3340EEBB for ; Thu, 6 Jul 2023 04:09:30 +0000 (UTC) Received: from EUR05-VI1-obe.outbound.protection.outlook.com (mail-vi1eur05on2041.outbound.protection.outlook.com [40.107.21.41]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5A83F1BC7 for ; Wed, 5 Jul 2023 21:09:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=FhK5M/GbAfx2pVKtsjPmDFmCYfrOD32SWLbChF/uUkObWcf9g6Ge2OPh9HzxTZ/LyWs5ztUOvqr1B+4i16PhCvVRF/HitjBapBoWVniIXUaWpKqfgIsjkqa1qReEPjiv8LEzrwrY0cAHVru1lKIx6RZqxSTPPwGMxiAWPa+lEhvvXHB6zulsk5PMH+WfO7VayTcFfNS1CIuSyoxmdI9b5JfpTRRCAU1RtjpFvO6nP22KaCQSQwvrqv58uytxgnz2ohipnsXAuayVtbH2T4qpk1S9RZr2HV6a8PKjA4aVjycioIajcUy9U0u6D0LgDbj8Bfr/2FsRKHvwxq9lSADL1w== 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=YVAPbvnDPclmFhD/rmfce9WpPqLqF4sKKD3cDknRsWzSir65Sc8BWKlxjzQuH/GzOFiKcJfiNSoZ8YT2GHrTZRHRbMoqS8T1IXTPOFx/V2baPvY6rLcNE1KPfHNVdyog2J+eB82627ms7OfPCUMstdhhJnA4b/zhXJN3Ppr9AfB1bWImv5qvtCBWevXNFjgars4f5+v2ABlpHRmwvWouIPyLp+hQOUZow/lozz0X3SlNRSxVqQBjCA4hntWFqXZz6CkSIu8OxTf0zIyxoqPmRtvsOCzd+KQR9Leq5mTQE6tx5CPh2SAEJUR/Hy6zcw6LztUVrFNWdJ9HCoqDkZBw6w== 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=vi99ia0gv7wftHu8TtHEB/g1SnW5b2bqgQVzJimYThq9Dmwna/ZauvUb5KTEimfs9aOLZp9mjo6INWTrL6HauaxlIoTLBr8iVP14tCBpF3qiXfGuQt2O4xWTHbUd0iF6qITPr1Ww3lkHk1QAXMfJAB/uxf2I4pPsN/iacTAVU+kawn3qKQRv+Gcx7kWqqVaaaLr5Q+TXbqNWvW4v2RRKBL8DXC4JKR+K9aEQExBr+IxRxqVSLi/eFeJlMJ+ja0nH1LH2rTk0fuQlnTpSZlSDPhMae7k1qL707cXO0X0hiunQSTHqza8X2KjoLgTEH3TTG1+k9xCCdNfOadBQufk9WA== 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 AM9PR04MB8828.eurprd04.prod.outlook.com (2603:10a6:20b:40b::18) 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 04:09:25 +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 04:09:25 +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 Cc: Geliang Tang , bpf@vger.kernel.org, mptcp@lists.linux.dev Subject: [RFC bpf-next 4/8] libbpf: Support sockinit hook Date: Thu, 6 Jul 2023 12:08:48 +0800 Message-Id: X-Mailer: git-send-email 2.35.3 In-Reply-To: References: X-ClientProxiedBy: SG2PR06CA0251.apcprd06.prod.outlook.com (2603:1096:4:ac::35) 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_|AM9PR04MB8828:EE_ X-MS-Office365-Filtering-Correlation-Id: 85e443eb-e438-412e-4c4c-08db7dd6c8c5 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 30aYU20yDRxMKsla81KSylKBPqVfeGf69mQ5xLN32wve1+8QMszIn8em++GI8Zf3wydsNYLlY6Hn8nahTkBuDYNMDbQCWcj4BVJ2DXFNcSSAkrhN0l4lyQuoM0k4/ZZoGvDfrHvdzCRUF+qYA2Qp6k1nxBocZqiqtkRnDXY7YuJWsX0Nswg6AsvfSprhN2KHb1cl7lRmxK00xo4qDgbfsm+rEZDwo/yMJCqjQMiAs6tTRhEhw2lQp+8zjN9yQyZCJNIVmYfrDM42EtE8FSOBmcHI4YE5SNpFkxTNc/kbInWjmHXd3nWwrRwHtqL35GtsVVrf2TyfwIpLkjVzh8gCbox2Y5QqsppwadoiNOZTnyVetVGYL+2HGzEQRxM+7sYBJj6mvJSVcwUcbzG2fUw7kx42P0/oNcaZ1Je9pe3Pi7foz3/3vpyxtezctq7eTtqyRa3NNIsPsKo04L1LS+OR8XIPHZMU3eLd+uvcnsDzME+ZWL/E7C8qwcQT1j9ab+DSYH6x6MhgrubYIS8LStcnJmJevnmsrQ9kr0uUe+HL9Us9UF6YAmUlHM9U4h2birBlEE+GyqsZLLzDqpkRsSDYWbC9lfeIcEOteCFjYRvgFzToIJ4Ka/kxwdqixZQZElbE 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)(136003)(396003)(366004)(376002)(346002)(39860400002)(451199021)(2616005)(38100700002)(66556008)(66946007)(66476007)(4326008)(921005)(186003)(36756003)(6486002)(6512007)(6666004)(110136005)(6506007)(26005)(478600001)(86362001)(41300700001)(8936002)(8676002)(44832011)(5660300002)(7416002)(316002)(2906002)(13296009);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: KWl3xbH7WvdqOgzCREeOopRgtmT+oSeUViDt5GPgX9Rdt1ovTmO2HO7StWQgsrSFj8sT8Y07V0nXvyk6EEMqgphICjNapHXLrjoGNBfegpiDM36c+z+Rh3+2gBaW1U6NPKAnDg9pTLqIAHA8YlZfryHdLcAoSkkMMzJm2LwFNrCbJ/tjU9L+9HlIymN8PLbSdgzU7TLxVYpG45Ui0u+QdHhsV+5Qo1VrBTHwqqLXeDslsCvNYlwA7fY31E1c9Xmi7mOa+yMwFznLapP6Kv6VOiz1NZ5qwl3bU4P8jKHPxmYynnQAH38BT2m0XEoH5u5PRg9tlRb6Td9sJ3jF3wdP99Bxv17r4x6ClUvtX8GXESXr+ly9UQyrlNsxgaT/xnjl3eGxXg16SsEf0gA4U8th5cDYAMqyk0D26AhCsabSr1t2PngnVHe0mebeW1Wy2ULTXZoK06UM2c3x1EYyuzg5mX44LUzF1IHOy+GmhEzlU1cPS6mzK90s8eFpeyn5XxQ7b4sTgYjzVB+FKXaz9150RlDaWZTH7eoxj9+SZ8Zc42YyX3Ox12xf1VmWIWqwajYbjxN3HjuEErVydluBhNIgPOpJ3gTlAaHPX8ihDrLPgSfXvapDrsM1lbyUnQHrGp84tQheKoxIR9NDj8936m90LPX0KowsrVFtCGAJHItwiwG82VB4K4OmrE/LnIszNLrudD9G4/f9MnRJvbStvYr1eGgHnTyyGBd81ON2HlD/UTmv65jjmpeWr1AbHUQ1zqfla0ltd0gC/b6/ggtGW3CBc+BhtcD0rxq0UJsFqX034EIh71wFeOPDUo1wCEkFT6gdnspVGdQL1dd1HcHZPqZ3ef2ATN94NTe6Udq+B0PgnI12Zx1zbPYPEd2ps9njyZCopAlFEEh7tnO2yIwCSr5z80Oo+vgwb7gy3iN07FSTF9s6mX2vgoozRNacjVGCNYPogHnOsLelhapJCb7D+xyWyW0q4t7Dl3xYckCN9CxBYkPBVduLLTjrcYlwi/fz/tCzwMwmaKUJUWmb+uehaGvvS4b7tL7IiHHwsTfVagVgMcG/W327rUUau92iqty1SwDlxARS1hywMsgbOnSh2av/Vv08sf2dglGmrFNkZMQUSAuacpmRaY6q10yPyEOjVI8pN+Vb2FQeXPqjwce7OaK5l1AquuisOzHgMdTTizz1ZF4vp8JuZcyf9XbOPp0/i1l+Wc03Dvm4wrvQD6NCs/lbH7RpW9BhSL4S0U9cDbcHfPehAjDHQYVI0X9fM9cNJRx4Qxs22SGILE6PfIfZdkFLoJwuUAOcPGGQjQ5ZqOq9e/NEStm6aG+G1c3HhLkqjz3itxUJ64ePkDHELbXWEhyOBwpjMpf6wCqwdyQC81QR0B4SQH1YzuhAw/GjftMrnAPTN3f95Fqjck7GBbJrG/PWJd4cZz1TrIC4C4vRLk1l5evvvqsOJzpR47HdeQuAQSr8Z9T8wvQ8DcZm7nOe/wXW0OMh47Y/YOwSmx7z4KuTWzFqEk0wM3lCYj+siBEHAV1yzczsfBcaZT/+kbQYZZaDYA186pyYAzFrsJViLGB5JKBst2jq1l6RxIjYeNlZ1gH2 X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: 85e443eb-e438-412e-4c4c-08db7dd6c8c5 X-MS-Exchange-CrossTenant-AuthSource: HE1PR0402MB3497.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Jul 2023 04:09:25.0913 (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: OhN4ZkWUhh7Tdidp5yW36bUBvBL30Q3kzyDTSoFgb7krCzT0/hQ+z228dtkySc+PiXAMwRYWCboB5ncqJJaGGA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM9PR04MB8828 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 04:08:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13303166 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 9BC2F1109 for ; Thu, 6 Jul 2023 04:09:36 +0000 (UTC) Received: from EUR05-VI1-obe.outbound.protection.outlook.com (mail-vi1eur05on2073.outbound.protection.outlook.com [40.107.21.73]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 426EA8F for ; Wed, 5 Jul 2023 21:09:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=de5N3+K5+n0DrIdv+2jkg9irqmYWMYSnmYnSw1miUJLJd2Lpm/tXDVh14IgRtUizMQuyD6KQQgezv4k8i5DmMv9JdZ1mr6+MoVgUJD3cEqly6GCjaSqv5b7zA3LV2lLNUhxIoAh1rhlcHpgocz5YS8SqlEmfHcU8d0vyqLFaf1GUmcr1vXoN4IkEWKy0ESRKLdXZ18yJfQ2GV7n2GNGIeHG48Mpapo91b1I/CjpAWiCeV0QwuyI8CHCAPc+4Jf+W1F+oEOcTLi+7Qek7M0qCP3vJyv/WQlTYJm0E5+lS/a1tkVB4EwdWTpU3WaspQyN1np8OVblFAMTARk4xQmR1xw== 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=FsHv5x71R11W6zUikeN8bQDfsg2t300OOrQI/wYzkKTBMG1OXaDfSpALjeEe6rQ2/nIJD7RV9lC3191bGUj7nMz3eG2bZ2VsFu/TiIoLS45BrZz1qBEXNAbAT/+1Bf9hy1HFfmanSDGYQuQbK59KPSWm0BHyD8IWwwBZpEvc3+QlhaVmLM3fpSDbi9rzD3LLkD1QGOKsGeKuECrgcSpWJMWexflc3Cyz2UB+hMpmVpuRYF89NJmEUsa0dNHLl3LjLC3e8gpl31RCyGfjV2mWj1ycdT2IDaZdz6DRl2AZ1B0o0vQtyE5Ycn34Y4//SYp4HitJ2GzOTl6QWtvUwV9/iw== 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=k6kFYCwgi3Z/HiVA2yAJIegHAY4QDfd4R7wV9jHSJzwZTgn4mFntVkMOFvW5rsewt8yzyQopHtBJEtT/z28smKbGoh+PC4tf6AoT9tQVGBh4knt/Ut618OUOxHRLrNVeIfjp3XjGGlGetvI+uJYaPZssCQjxorMoIakYsdIl2dBa456pmF+pgDDDdf9cULcaKvf7bZJarckfD7x/2OF1bVIZQ+vSoNpWuHSGlCC5+g+Al2t0TQdTOZL7VIb1iTT3pU2tLAGoVA4V+b5Vq2SjxpsdoGyzNV9Fb1xNv7GsT8wyY8AFtqF/uuYalO6HS9hdQC9/JzR4LnzX2k8R8ngXDg== 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 AM9PR04MB8828.eurprd04.prod.outlook.com (2603:10a6:20b:40b::18) 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 04:09: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 04:09:33 +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 Cc: Geliang Tang , bpf@vger.kernel.org, mptcp@lists.linux.dev Subject: [RFC bpf-next 5/8] selftests/bpf: Add mptcpify program Date: Thu, 6 Jul 2023 12:08:49 +0800 Message-Id: X-Mailer: git-send-email 2.35.3 In-Reply-To: References: X-ClientProxiedBy: SGAP274CA0022.SGPP274.PROD.OUTLOOK.COM (2603:1096:4:b6::34) 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_|AM9PR04MB8828:EE_ X-MS-Office365-Filtering-Correlation-Id: ab90c3d7-3ca1-4d30-3973-08db7dd6cd79 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 7tSQDHZ10lYb9ZNY1dV9lckPBruQcVFzPXgJ9I39MxW7FotPShnlC4MOIRx3b2INXjd3hHx8616udGaO7HXuZLdJ+a6FiLeKwkOxdj/j+2PBnn6hXLz27rGPG5fu1WQemAYfhvZroqkaf8VnPeWLBbKRor8K/KIwNRKZitD4Hxynxyw2+sPsFJYgbvq9k+Vn8w1XSLXDCh/3y5oA+PQqeSHmKVy/trg7TwqtFjKBC8ciVBEtyUhyWJujBINigQu3zGKQ7GSjCS5h7hBeJ8BK3+FKL9UlSJ7fOSwsqZqtTi4Y5HQegpZLDJyQCM0wlxuQePFoOVtq+hSwsnn/lJfCbOqiAA0xZUPbm8CjMsrBKFmQ5zpvqr12MVI+uCK5LSiU/ul9vwdPo3ACgA6l7I8Dx2q+xiBt0RvpKwmzcNjMROJQHIzTjFbGr8vEkYRCOYsvlYQcuoIvpGETvRXwCDMq6EKsATnyUy+ve6sHcD0BsXAqlK7MBEnJRbA22eBKS+4HMHdwhZy4fgmWi56zRUzQyke+Wo+E4rxL8279ZG6f8ItQhK36lcvR0cZpPZ/KlpvfhGhPbIGdS4OCs+Xf+0sigZFHbm1N0vu7HjU4i3JoJzXFp3IFjmgk1N9dWcE3eJt8 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)(136003)(396003)(366004)(376002)(346002)(39860400002)(451199021)(2616005)(38100700002)(66556008)(66946007)(66476007)(4326008)(921005)(186003)(36756003)(6486002)(6512007)(6666004)(110136005)(6506007)(26005)(478600001)(86362001)(41300700001)(8936002)(8676002)(44832011)(5660300002)(7416002)(316002)(2906002)(13296009);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: q4RKLxcLU5PzFA1hGvH0p15qxqa7ae3W66HUwp841mOJIiS2iEpxHXIJclHRLF5BZgrgAGWfuCci2OSl28X/yOGMF5OvRmqPwrtz+W7aZBbk6G7b39l81It9Oo5MK+Jk0VYv0lmRtHsJBUCRhTjSR/MEt/FNUDCBZFBFH2RRF+k3w5VukJTSeRTaxo5MrRxemKonoaF9tknf7+OmuBRtc5PAoff2MCBgy8GUtzvUmU0D4yKew/cfya1t1UBOLEDuTRqKWa5OvMltTKcxP0M92u82bgRqVfPtYbPRjCgmHZ8g+x8zYj0ZrWGRnDmEQY3+ihK9zbOfVlJntjjvRcDHnbycvQffhalVs1j1/L17KItnXM0EqEia/z7jtXoPy9YQJYDi2OG+3EIe52Rd7TVhX6/31McRXiFme0UC+XPpHebOEb4FwcE1+UbJrnvyf/PB6Sc86DHL+LR1EU98FFacT/AI4+7B9tyYZr18bw63QSmBSQPVuCtFHO6zhhEddqPmPqrpEGeFqdGsnQWo3UZ9jafJjelLRFo/E6+2y2OQVmLQlHcjDuhvQswNLPSXjgcFhNwqs4lSlQb2BgFOW/BhHpLEwWDr7vnzFhyrWtioEU470ZH7xHcI7tBzecaRhEvrdHfCpvu0SgRLGslFuh+CTDsv0G8BFfKVy7nw6FowD64i9UfhRXC+oSHwoxOfbPzbAgElujRHjO3S40hQuCj9z/ustRmQDQPZUGSwUs3Mu7sabORfZw4IT+PjiTfTMOH/3472W8LYLQIEJHeSvtxqq/Q081Ypk9PaZAPYtFvGhG1nwi0bOoZz5PP79+bM1LfA4/CaHJZ+wm7cRyQS/agmTMXCJDtx5PWNpB5kH1JHTWAAIQUKMpxgQkvTJo1P6aocLimvNACkBf7Sr0R4tr3HHbLohH+QNeHlNrPIoznKn7xmwOhj8qUijMReAb6CCfHkWhuZmnUD08WVBUdvNmLvXWtkfDGEkYWN4OBKCOufNUscF3DtPITZEVTEpFTlWJcmEIiv3RmenJyne1GgGzPO4Y+ALGNFhQDFFUvQweERnE/4CAytWdHAlOlCjOaFml+5JLTe2Ot9QFJ9xl52A+cmFAMMyEdtFtph9TVMfXWgeUyAGzk4aS+LhruwpITiz/qMlI3fOO11fZtlyyTg2Y4rIOYIA5WhhGrmxfWA/MpSnJgdzuS6nuCywPPKe8CffeC1CbpQHj/vwaHHxnDTOGGfNPot1YDx1ncdnj6NsMdAoU0P935qe7KyleLHj6YFjyz9p58WP8i5R/f6oOUvGHpOncLtzgo8e57Jh4jksm8PSWk/+mf96zjyKeArLmZOa785GgP+z6YJqPFWNzxCqJFqS2n14+YdWOxu/s5TGqwlzUhoBas+Fn6zdRmBanz3CfGLgBYhi8BBXy8E5jYNFIRxemFKzHZPRIb34KhMKEGm9pV1WlO+lSG6hgC0IsMQWkenJPxQQg39M88aTdP7rflcMH6/POP8/YfCw6IBI00DFbG9u8ubq53BiLzekFUNMNav1HW29PUpsWVGbdDUAgZMjsBwo97oF9c8e944wzAKlJRxWX3TykS+4vc8GKdA0zm+ X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: ab90c3d7-3ca1-4d30-3973-08db7dd6cd79 X-MS-Exchange-CrossTenant-AuthSource: HE1PR0402MB3497.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Jul 2023 04:09:32.9574 (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: jvaneF1eP+lKinLUa/h8HakN+4Edlb3Bir5T+yU7UwxqMjV9E072DyiJiPuvIQRmnr5++nzgsi2PVunywjDfwQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM9PR04MB8828 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 04:08:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13303167 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 AB77C110E for ; Thu, 6 Jul 2023 04:09:42 +0000 (UTC) Received: from EUR05-VI1-obe.outbound.protection.outlook.com (mail-vi1eur05on2055.outbound.protection.outlook.com [40.107.21.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A5E9A1BC0 for ; Wed, 5 Jul 2023 21:09:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=QYx/X2LnS12lPuuvDz2p2iRIgv00rauLhLaQ8qvrjqaINHmGOSS8PA5CJWQsSSKLmzM3Cutxc1dV1POF2ch6FJ5wwyfDp96bScUAtKOWZMfPW/l2EpmkIfdlwFMTmsV9s7/e23zljrgXnyNpOo7aLREufC53pVrQxbY8MR+oQ9mhj6SumCxA9+LWGZP+RUchoVocQdNQQYh1aHiOevvA8GPSsdiD0PtM09gvSntKQc87OS3GrKV4ZEUwcjlyzIXBGdtHfcNwRPCvsM4IRF+chC2x+9SfXjjRHEb/YF0WCENM3nYxVFhBnXTS4UFPUj6IxVVUWfln1MivxKCSkV+qfA== 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=QvzA3KwHDvAcuP82OSZ5O3vhPHtVwan/UUbHKEI3Yeqm0qOLQ2bzJ92ekEDMuFw0t43AQMff8OmtwgSMuhmJpxLLHoBtEgUlexm5DcXbrXMFfbP+nAaUxsi8TNW5OXRdpc93MfYc1ciFg0dE8y90U/WCJ1pCG1Cf4XmIAajEkS9Yy67h01I1tKVLhsdr/6u+H77Bzs6prONeZZHNDtq2Nw3QLpz9S9whSaPiYKgRaRn9ll4TD0SR7xgAWfMSyISU+lEVs4Nmn4nB48ji8GPQSfS9WmnVoRhamdydkr0eI7HiodS91A5O7w3jeykJ8rUOVWBhVoumXUThUrLofpmX3g== 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=VIsmd9nH+8y5X7881Isj916d2FdGyfFGhKkKuhRJnGmi6Ysv04MEt+JXHh5svohXAXqfPvfdQL2BXBN+ydeub+FD66o46xq0cGpg95M9TcAntkGiW3CFfptCZeI7vorhofb5H2fciCYhG94+xgtMXtQerNHERkNjYKOrLcY2GkIC9fnjftSzDvzh6g3Gk2BfrNCH/wlAKiEwbB/9qKViFam4qGOmOvRaGQqexOATaKDNx1Yk+yU9SIxNKSFGey+HT2PnkuNco4qsRm31zz+Z+yU4cbkxaykIOXdoow832ZMrlT/Sc4ZoRdeM/R0YAOfKLBf3bnjylP4/8zLttWgpGw== 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 AM9PR04MB8828.eurprd04.prod.outlook.com (2603:10a6:20b:40b::18) 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 04:09:39 +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 04:09:39 +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 Cc: Geliang Tang , bpf@vger.kernel.org, mptcp@lists.linux.dev, Matthieu Baerts Subject: [RFC bpf-next 6/8] selftests/bpf: use random netns name for mptcp Date: Thu, 6 Jul 2023 12:08:50 +0800 Message-Id: X-Mailer: git-send-email 2.35.3 In-Reply-To: References: X-ClientProxiedBy: SGAP274CA0022.SGPP274.PROD.OUTLOOK.COM (2603:1096:4:b6::34) 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_|AM9PR04MB8828:EE_ X-MS-Office365-Filtering-Correlation-Id: e71a5b59-fcdd-4a48-5d7f-08db7dd6d13c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: wFG8gWdRYI8JS5TTN9xHIs3FsvYoMgafJzaorzToszSoaLrupNWL1CLOLP036LSQYdODnw+sT8sK95ghxakRTDxb2JbFQ9Mlf3pMFMmbMYIA0VO0h6Xin1Lo4IQ18+oxhisO8vZdYzmP5UlJdg8BBsyalNaHQHoPTupast1AEYs+mOrEDaAgPYhV0DS1SL0YKEj1cwT1x/vdqpDCPJA+rjuYGLKrD5rmH7Acy33Wwjs9SJ83edw5pymC2rd9PNjP70WXIcBNedAOL1t8UV3iVdmn1n+qIa/k1vKeo+TSU/Wm2bG4k9kcPJLIh9v+OUSoJxeFE6MKJ1O6jU/wY1LGph/K/G0QXhQmITz1MN1i2k+V7QwQlloxjWOGhMkMb8DmyHYuWQDFfS+bxtFNrtQ4g4Uz8nXZ9vlz9gFBEIYwveXvVzIbinxqAcjS2ozoQ6fKUzaV8E8FymSoKjfP84oh4/yi1zHqgLe/0LBEMEaJZD1fuKpXyLQU7DoGQU4qK2S+RteQOeIWZXjfTtEChhAkt8wh+52Ft3jNf4n8a9BXmlarFmENoqmCFtTGRZ9SyBYTE5ZJEPU/9V1bEuj5JE9g9X3bLLBW6Fvw6ogvRSqqoE2slonm+TkEiZXOpZKmjB2aaeESEVV7Ihme0U245l6OjU80VVOHpc3+u28u1ax0FaY= 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)(136003)(396003)(366004)(376002)(346002)(39860400002)(451199021)(2616005)(54906003)(38100700002)(66556008)(66946007)(66476007)(4326008)(921005)(186003)(36756003)(6486002)(6512007)(6666004)(110136005)(6506007)(26005)(478600001)(86362001)(41300700001)(8936002)(8676002)(44832011)(5660300002)(7416002)(316002)(2906002)(83380400001)(13296009)(17423001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: ggDc2/nP74jXq9XLtgu4IEy9YgnxAJCo0HKhDagYwsU/teUijc9kuLvMpr5ZtB8UUyZGFxTHigu/ZG5rsejlz6SJc7n9Tg6ej4bPp7rSrAHX+yzJ/fLLK6+WL84Zvbss1T8DGSjXS5WdfAabERIgf0TE/E2XklXgwNDZcE0rdImd+QL7fMJOv8SC9CxaDqECigb+AWI86bpYagsv+cFGyXWNjw+nJPU+RXTFVr+UOX/49HsVSFfaFbhQBspXgarT6Bpjxsri8liBLNZl9bti5qHx/IQ8jCpYxPl31JabT9Q7kNHsTAxsm8f8/yf3JZpOkaQZH9imJ6p+wvjM4R0DfkyvN8QaJnLzmvOHVP51H0978SVacOmSmKQKrr0tfyE7q9oQ9U4KkOU/Ps7UAySDoDlITIQm6wO0rBsBCf/mXyDQMXbwD7mZHL7zSLnc2NBK2Jf2iz8ENFTxuYi/xlGeG0q5oMChMAr4zhTva9+eHKOXDIkRkH372kb//51UgMw0VCDc78BkH5CxL0T5qw2XbfSanupnluG9/9svNwMFjchOAwDFH3ddvwf3+SADWpEK9tmczXMdXEjdsFSUmFfwJfXctJVbTU6DiPPrEX+GVhT3eR3IXzH67gv1y8AX70OicbtiGK/hFZGbzcla5wT9rSYFBGpLf1rZSeg0Th7nXQbCejb7LwOv9/WfsfLKIIFI+EDGAEzjXnEp/eUI1oIoZ2PYy2t+i1Kal14mIkgF7MTcxKXVcDJ4RSf1Thp97yHO+/05PELbjz2Anl0wTlmzGy4iaKVCvTV3HfCOx3wo3YKHwW5JuyAEwPNHgfG5GcrI0t/0DlJcJZtLuFL+uS3AHUAo1zmFj28j2O+rqucupfT9EWTFS7AUwNnv178ch8z0VljEuNi38mCtSgKQ6XJobcEISsPooE5zrd8lXLgwTYTOCaUalRu3sadXBFA1UpSxc0e0ps9/sOTD2c+3xYYq1pJYRWfv/0szOHQ0SUpLfEgoBoZOOnflP9uoJFiUzNwgyvpI0g2Me2iVZg9jslT39YK1q4nW/rfS4vlGSG/+qmoynOB89109kV9GdaKDjPWpTPMBcVNcgB4GqtRjz8N8EPSM/rNfeEPTrT1GKhn9GkxkQSQSQG7JSNCZ2E3KAUb2ymMRCrhx3IXP1fwkIKc0TPwXH5nXUT7TiJMlM4p30G9tco0q/9hUqqHV5OqPcERy5WQAkby2Fo694zyS2OyswvnUbS9jJd00hYttfyqkk+mk9YjSnLXktsvMX0BtReon1khJ/vAugDpX5npZCti9GQ8StNNRCEYsAJgDaeJXBn/ff1A0BPKrRxUYVRvZG8ZTjEP1wOaSxuaLN4/BEumzO92PBvOOG6Fjf8W2nYm9eudpcRhUOR8PvAlxwupqDSg83l8Es7p/Ox+in31JN4F+MV/JHbtTEoLJXKMm59xBmjroGRSqrSl8h+PBjfOi1wp+7ggUnK5sFOxHc8tVW+glMJaa6ljn8u+RNuI/gCBBspys3USWCwwa1tUuMj8vBSILsnxYr24cgD/YSoiyidGfTiCM0hk4zIoXpkpQpWcsbLUjTdPKwNghczd/8amEFZEN X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: e71a5b59-fcdd-4a48-5d7f-08db7dd6d13c X-MS-Exchange-CrossTenant-AuthSource: HE1PR0402MB3497.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Jul 2023 04:09:39.2875 (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: VoiT8Gz2qjaShftcLI8Seom7kqaxqR/obiYC/5hiQ5Fc1r5xDbSxBPjs0ir9Za3ve1vSEpqbQ0jfcWqdYtIY4Q== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM9PR04MB8828 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 04:08:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13303168 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 A3E2CEC2 for ; Thu, 6 Jul 2023 04:09:50 +0000 (UTC) Received: from EUR05-VI1-obe.outbound.protection.outlook.com (mail-vi1eur05on2054.outbound.protection.outlook.com [40.107.21.54]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5F3838F for ; Wed, 5 Jul 2023 21:09:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=mVm9mu7N8E6rr2GRU29IClc3xRHv5cANQyrNtNIHYa4VNRh9sWVThEVZeUA9AAJKO2649z9CV+J225iXGdD4huuvoY47ztB+mowMtGSLr0YuvING1ywP9f19qMeeGj2snxC1PwHNggag57FaC+iSKKXW53Wql9H9eL8aaWOublVOYlksQj3ScI2Elp2yBAqrriRUeiB9k9a/+9sMaVpS39Ui1DRf948VOsP30It/rHMG6nrdLbo5HObEoRcVgT94lYCv/R1Uu0VxzuaN0Lf3q96UjQtsqo+rjhjY2IkJXxp/Z2LQlv/sCw5DiXOa6CfZ2tm49nfFN2NEJkF9Le2BZw== 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=mCaakKo0/F3nqR1GQTPiLVuUWyUzWcH3OCwsPzTANBXG8An6nG1SOCnZ7SWEVRVjga/AwmAO22Qd7r9mP1tYi/BraLG0A5wRGOvCprU5DBJ+tCE2f8l+yuSsnF+R9YqVibmvo8vHKTYCdNfoV1EM8i/NPgR82XbQxVkPe0R4KQNA5LeCEZEpjukfwDtWlgUpNAFoKtUewJb9I1aDadvU0XPA7iKFkK6R9eHd2FI1ipIDgqNT0hDv89iUEYiBBIrQ1R0IpbyKyCIoKiMekP/+q0Lv+y/qaz0aNdWJdLaMPYPi9l0pqfdj+txh9wuwuJP1mz3ynF0i8uqBJwl0wxSZWA== 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=bsuy4OaldULSmlZ1yldhLzzul1g5YujY28j+X3SaIXrdnXlC7JhGucZmKHWrnUeN6xqU416aGrRzVGlgk7yO5DcHCGvvNY0BNWHgkOZSC3YKvmD8/mByvLcTLI3uXWTQRvM0DrCSBpizuD4afh86gVvp2j97P9dJZ6EfMmfLmH8pBJltrRRJwBQh5Q60tnQK/77vnUSTjqERSOkWSiC3kHTgN6gHnr8sEemcrvvzN+RxQeCH2GqmO+QvOwE3m5E3WP1lQi2LSLGGmOoJw07I4Rq8ACctWz+nBJlfOEfInwdYyu55hwSmDexScSJoxbXu2v7Lh/BxGFay7SbTIkMBgQ== 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 AM9PR04MB8828.eurprd04.prod.outlook.com (2603:10a6:20b:40b::18) 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 04:09:47 +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 04:09:47 +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 Cc: Geliang Tang , bpf@vger.kernel.org, mptcp@lists.linux.dev, Matthieu Baerts Subject: [RFC bpf-next 7/8] selftests/bpf: add two mptcp netns helpers Date: Thu, 6 Jul 2023 12:08:51 +0800 Message-Id: <284f75cccd4e848f17b54bec67b6889fbcde1a35.1688616142.git.geliang.tang@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: References: X-ClientProxiedBy: SGAP274CA0001.SGPP274.PROD.OUTLOOK.COM (2603:1096:4:b6::13) 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_|AM9PR04MB8828:EE_ X-MS-Office365-Filtering-Correlation-Id: 1d46d51a-f308-472e-0d39-08db7dd6d614 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 5lD3vnzcWz03PdIiDSmlp4hD7chRFUwmn0QMa5FsKYT66cMlAX8HWc9p1xyeI+sFVp3fAtG2MEwMMI/9NpFJptiC6vp3OtV0gbraNgryd7xLOXKOjX+SH9EaU9WK81+BcbmEf41xs3WScuHwMOpbUD0CIhkqu6Wu1bye/fYw8HwdxK+OXhgXqpKJuqadx376Jfves0vd11np56aELEMDd0yfUzLDTe1Rg7l8dJzvV/ocnlgK6mtA+z5ugjwsk/rzBh0tDV4IFUncGYZFTrhpsrgEMcaT+zkCJrlnM5mBgvP/aezcfNlgAQiyv6/xU8TuruLGjX9B6TQ3h/+kN3XOtXvY9zFnfNQlO30vT/IEp3ysS5m4ZCExicya4tU6z3wzXxoAb90DVCYXOHf8FabxLZylcN1M40TxDEBFuNyNgsEYxobxAzwzSAoj0/R8cw6HzTE+IUmshOAae5CjjpINMT0Hd46xrOu4cCAlFipbmnuvhS69q48hW5KDzW1JQQnHM6VMZtex6Lpv/DIklEtWIDg1vypBLjFBoU+Gpxa6Pu7OgYVVzGEPY7SMepi1gZhYn7JpwEWRjfJCEWvBhINuMw/8t55urgh60c8mCgu+EgM6mQpSkjnD0t/9juqMisXq 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)(136003)(396003)(366004)(376002)(346002)(39860400002)(451199021)(2616005)(54906003)(38100700002)(66556008)(66946007)(66476007)(4326008)(921005)(186003)(36756003)(6486002)(6512007)(6666004)(110136005)(6506007)(26005)(478600001)(86362001)(41300700001)(8936002)(8676002)(44832011)(5660300002)(7416002)(316002)(2906002)(83380400001)(13296009);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: IEHyKbw5dO/VTQckbSRqudHjx18KzFiwfRafcI1oMmADplo11pvdzTGyuf8tuboYIu+WhO6Q2PJltWlC+dUVi5MBFv1YO+3A8I0KXUYd/m8y3cq9LMQoFrVMmRsRPlBFyGzHtgu8475VSnv3dpUibdxPCa8uVx80j+SJeWDbUIWZAY9VnMrQLS89tM+TFSl8b5NWjodqKAXepvpm9s8yjihTYasbwy9KwBBVJC55pxoqQw9YgH4kQeE6KOFUXJ5L722EwpIfAk/2TzvSJhnCtBQkQrFHwUYyi8VEyGh1gnfsJWTi55RHjkJMit2Rh8f9qDWIDQ4mgDmrnFzSjGg96KLRRbLkJYbZFtlWAHfk3JnShoKw8xEn3B7IPdN4MIBmqSW6HlAWMhSIkxhPfehVlgPvUyqgHdjV8i3nenlmWmzQclmfOpfpXPQy+dPdkkbKLhBqfNFD2G1k9Pavj37JFRgvdySaAqNfMjc7vJcob75XG4b3yo2uURipVDj1gLvvlOFhD66jYxv85iVX9LGbQxRMfE3nJ6HUdJXRWARumtdJX/KqHt1dwCZ7V7zmCma97oNdC65OcMFIzDU7G1zNiI5gVN8Nbuw+jvW+3BcbuBH4MlLND141eJkp6PBES/yxC5Qxj5RE+Plh71Pe6oazpG7R06n0cLV1JH5G5lDK7PNCMKw34CdbZ7sYVSZ5QQ9scMVtUclXgOoYnXPsw1L52kc+NXyWCM66M93Xl+ZqsYy4ljYsF0VFYpXAaYoPGJokrJ/ojzhoRdi2AlWgt2RPRtQbSoqtn1FjwQc+kHA2cd6KQrTHGkua059TSq6RWdVvV0Caqs4EHJ0uv2udV8j9Cbn9Rq0ocYO7n5n+LDQsJRc2ek/YPwSjbDKsRs61Y9PdjFhngMFqqS3ngPIi5EUSM2847jgmcd17njqhg6wOSCT9Fn76UXre+98+rXOVpG3Gf+U09Lqna+wwLxluN88zxeIs1yBOEqVE5xyhTW2ffanSWe62LIM9fdzwoDCE53BqyDt8bCZj9oLhYWmj+OFFOPxU/OgIb5xrjRnlx9pTnVKb2wCg9IDMvihSBPykPL4ZTmd2QSEo5MviwPCpYVVgZP8T+zEHxXUIShbIi4FQhPyKW4XtRpbmMXDWXMGAYB13kLOIZlS6B3Vro2HFcaO4A/7zGZj3l2HHrXB5UWchwgy7EXtFJl1FHPSbQzNX5Ypd+5+HM/xBWCSX7f07GchrEke7DRkrwVNpuy2Rpiszj5uNXmI5xpna0+mtHlh5fODaq/IBVmc+d1FZic8t5QOV+fZSOghROn+I58dYVqOZcPD5iwAhrgrIkU0eIYeYmf62wWbVLBCcdMYfUUtCPbgilTMw5nYMHZaT6RJUuBDg52xG2EOAHlojI6yoDNlLAMD7xywsW4V1K7klQ/q3owq+F64U/GpIf7AOozd6Q7Z+xhE4RzVlNuuLPZZ6HAW7QgRHCCTh98GzNoGADg5QpBOxr2aoG+/4iZjTj7QE+Bf9bNknrWdN/TFBc/vlH54/csXnf94N5GYEcgamkz0OvDpQ5lLd6uEJEBfeMuQ7mwCkxuR0UtO6sP/0kqWI7onp6FvX X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1d46d51a-f308-472e-0d39-08db7dd6d614 X-MS-Exchange-CrossTenant-AuthSource: HE1PR0402MB3497.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Jul 2023 04:09:47.2226 (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: xaDZWfWVFL2nz++/Dst7bxv7gxNDxKgT9yMQ+PpHcWgTRAcOVfZa47XjXhUrzfBsbX39ROqLKzjHDZmck4R5oQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM9PR04MB8828 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 04:08:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13303169 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 E4070EC5 for ; Thu, 6 Jul 2023 04:09:57 +0000 (UTC) Received: from EUR05-VI1-obe.outbound.protection.outlook.com (mail-vi1eur05on2051.outbound.protection.outlook.com [40.107.21.51]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1B9558F for ; Wed, 5 Jul 2023 21:09:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=QGCQei9lJolNZ+VFGtr8wNGSRSlvrfsYR7jly3hqYrXKOmpIEW92queF7b1vJxGuqZ6ruiwL+w0BVExQG0u2+xNbVw7Cb+PI8F0WqNZTBuzF6OdBnxpNuwC3/0/c3ax8Z8pZmKS7RKnrXtZ60UdDuzWmysp5BcABHTP2myHrd7zxyI3jkTgnqASCywpOxGDsslfm4WdxE+wLME243fvgyGlUamMCaQLBU/3NQcY03GdIVXcXqusLwHOFglv6SI9E6OSsMlllNLRC/JZIKdm9su6LXwwHyAy4WFH+uUh3wHeutvIIUmoykEYijefsmcln/W7wEZ/2ysuWUA+GuFNSoQ== 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=rAoLV0/ShaQD0lsodA0VEYtnk0wEI79EpLya41uQHjg=; b=jP4DgzavzVutvxBziG95CGUD5GrvnxyMpEyhxUNrvQ1Yqeof14+WdMLJz/C9k0Mv34QBbc9TRR3hRAKa5P89b9ZR+6zUZmG1WPpZ2G8XdHiNEl/AYLaM3B/apVIjcYDNW1l34P0maUeS81RBIVNAVDQzTEuPDLPyEO9SuhZbuFGDGpnVh5ZaXy6thsq16WWXpYhcstkfBH32QzlqrmhX4AHfH0hs/m9JaVsOV7s3dnXaUSwXCuqYAphAay5yIIw1xmALj66oDNNr2zuO97cSksXxD4DuDO8D11xlMi0u3orL8Zufii3FnZ5ADyHw1A7RBstp3KbVVlZAVRmAUBX4jw== 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=rAoLV0/ShaQD0lsodA0VEYtnk0wEI79EpLya41uQHjg=; b=L0zgq0DOBOkP7nfJJoDCbeOBCdYricW10fClySrIrWECw3vZ+MbDULFSfdqsv4rU0X0CULvJX3ekwgKDR2urIFxdrFKsbwVfMjA1VeiFGBdLun0V05a9rloD//kIyOCGkhJor4wXrumZ1odLttkkmXfENxlvHMYDjjZCPXlNGFFCmMzB/GnggnWc5yeyS5WjixN7bRg+g5cUFKykq/p+5NBqIyxJ5DuMnqx9EqC49d/8JPG/55rAvvgI8ZFilGPnIqt3I3r895v3DCSyUtPziphSrqaC5xAS/7BX4h21bgfHBcFpvTgB6UMt60apiUAsgz1YCYXKszmBXut5C5H0IQ== 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 AM9PR04MB8828.eurprd04.prod.outlook.com (2603:10a6:20b:40b::18) 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 04:09:53 +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 04:09:53 +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 Cc: Geliang Tang , bpf@vger.kernel.org, mptcp@lists.linux.dev Subject: [RFC bpf-next 8/8] selftests/bpf: Add mptcpify selftest Date: Thu, 6 Jul 2023 12:08:52 +0800 Message-Id: X-Mailer: git-send-email 2.35.3 In-Reply-To: References: X-ClientProxiedBy: SG2PR06CA0181.apcprd06.prod.outlook.com (2603:1096:4:1::13) 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_|AM9PR04MB8828:EE_ X-MS-Office365-Filtering-Correlation-Id: 6f69cddb-10a2-4e1a-1edb-08db7dd6d9c4 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: tnAqPoJbplN53XYSDhrlBxT9fEeh1AmFPu7cUPiNMghkL4fKg7QWFoRaYS41IyjEGmKRnL+IeESlcU+EaFIf9+b5/vSW7fEPAAUPGp53WzIiKtTDT+hcIv2E2UlUL427JFzhABtueWaFLSq2X9aq160VKkkOCBDN5J35hvMD3Im8NULkLpXlub7XvzT8S8498eOtmpcMORjQ9+ebkS4ld/1iaN/XrXHRUfvR2kV2vSlAovvPfPYJPe6bYxOXZO/SAx0B5diRDdx2pE5fPZM00lFhSxUuP5Z54YkH7oWFrGic+bZHiUftOrxkynuHUyowZ3gEPCWeoBLAnF5IV8aCk4WWm50Q3hCEZJfo1UNn4XzLe00ZFE1TEYbJFbZvHYW92ScgTHya3ayRKK3CZ17UdKH79PGaqdz0lDIJm+aToiUqjGvk2DReLLcvQrgzN+rvclR4jQhRJJ8h34JeM99d2G4kdA3shDgeubZicXrQU1UPKApFNSpKoQKtGZChoX8S1GDh2i1bJ9vAuhtTXQ7E02F6Z2pWLhKACDdnsHfakaI/YkKTNa3FcSEoifrdMWHf9u5a1SUsUbjXPmRlW5A7cNzMB0UijYsTyRVcP/mVufIq2YXlVBq5fPiz/uUaL7vZ 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)(136003)(396003)(366004)(376002)(346002)(39860400002)(451199021)(2616005)(38100700002)(66556008)(66946007)(66476007)(4326008)(921005)(186003)(36756003)(6486002)(6512007)(110136005)(6506007)(26005)(478600001)(86362001)(41300700001)(8936002)(8676002)(44832011)(5660300002)(7416002)(316002)(2906002)(83380400001)(13296009);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: hf2TD/GDF3+VkGGEl49NGfS67B8HHJtko6c5lvDZ6tMNptQSDVnQuElGlpMHzuwU3vso9BjoObJgoUXS2pBRAYnd8p4cLKteZNEGkb4g8+1WabZfwJ+9sqcQcT1P/Qaa2Ro2nVfK3fK61xsYHt7Ou2p7CRQbx/XJyEYnUsarDCNIS1Bxe+KyVJfQxm4CMhmlYtfw5qRam6DW5oNxLX1Vw72M/qlSXSDPDHJfoDaoE6+7aS9fkTAETF8ltuGQat+AKgmazWtZ3hw+HOTZEmJgck4cEjWfOG1Tf1HwjMgTR2ZQa3Rwb+Yt7iYvga5xFHYjwHHCAZb51K0/45whEJV+UVdRkGNJEN4EHnpybTz1J29L+K2NCydPJM4hhDgOQz7u+OiJMzWsXEBBEiemcm98hHd/hx57vAcSd0VM75nm9d7q+xHzfIqXzVGF4S+LTzraadFVVqruqWkkG/zcwkokhC4GeHSEl9Qc0PQ7xeHvhbaEpCrhDFBOwlDreweHWMHs3UI1T6sGNayQS1jTL3Nvuz3fKLYkLhg9vsXq25oA37/Lxx98cXxmM+sBUn6sfJudB6KRKiSIbxxJNb6ayUPvWS1AXFWsv+8BQEzONBj2Vl29NpRHSnlDjryUljy0PzJ8AdIsuq7feMgbiie3RDlBmOs4xoP8BSttwYz46beEUMt/L0/kI9Elya02pcAKVQHwEFdA0YgjNHWgx+Wo9DvgadLz0fDBE3OtDuEPi2lZxSkAnPPyRPfggSB8Sebldqn7HdOfc6Jpb8kOEu10BNaJ40JPdQz8kdkaV8KTwG940KSL+Ll/shYbMlYbiKSiADhsIuWpsRbMY9ao4oBvVykFlo1tDI6j2JaJVRYPlREx0gjcCA1OnbzbXVzlAxWdi3e6s9rk1KG8KjGavSVBVh2tK7TLculp6S3Nht8F7+Ezr6N1Bdxi4tKh2EMZUXnZd65xTm8krLfNSxJ8kNaP2/Zc2M5z660xHFSt+VneMaO3oe4lLawANhdycj6QNj2SO7kHqhryQ2VNkj1JxNOxpFPpI6sKtrfxjCcVeYyE8R0+Ng66B132fEWRCzzPjYvFjdRRZGxjhOSYaE1sS0mUDDqy3AC5gCb+0HHVEYAtwljpqkB6vKlpXVB4cDZi6UuDXaH2cL3j3m5KOjfFK6d6LPqrgmJG6tgCdllMlobKLuxAeqvITNVwIITfOf60DUD9jMYhCeCxreaGbh3rJ+mEJAEV41DZm3yEL7oEO8ViyKXl0rNRk3vDzVgpPCc3oVM0oh7MnYIp33IBYCLh/1N84m9tqIr+j9+M+3ggdEJnHnFKNrCdrC3lDpxDSb687edcy/agzW712KmawUdDbwoDFvplX8qxYDItXf9xpPBCwOKpu0spAtZe/ru+ArcpldXCH16xDdRoB373AvPNoJslBAcmPiYf2/AjXpqZdWBog0j8DceKOijbc7rtc329qouGm0llKXBThNtPJbt/7TRodo5Y/CJNMs4qz2ZA65F2mn+UpG85VmeEqITXUlA3zVUs/gC3OHiFZk+89OzbmlBoPnDaKatS2pZbG12tLgfw0QZ9m4xkT9aVVPhAGrBWe5zAeiQ2 X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6f69cddb-10a2-4e1a-1edb-08db7dd6d9c4 X-MS-Exchange-CrossTenant-AuthSource: HE1PR0402MB3497.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Jul 2023 04:09:53.6004 (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: pfpzaOB/Nit8KzD4in7Rea3GffXqSmTyEGjWmJI/gafKfZePJhoHZtjsUwUN9LsjDqIEyyRVBTMPY5Ftkdon/A== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM9PR04MB8828 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 output of 'ss' command. 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..186270e058c7 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[128]; + int err = 0; + + snprintf(cmd, sizeof(cmd), + "ip netns exec %s ss -tOni | grep -q tcp-ulp-mptcp", + NS_TEST); + if (!ASSERT_OK(system(cmd), "No tcp-ulp-mptcp found!")) + err++; + + snprintf(cmd, sizeof(cmd), + "ip netns exec %s nstat -asz MPTcpExtMPCapableSYNACKRX | \ + awk 'NR==1 {next} {print $2}' | \ + grep -q 1", NS_TEST); + 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(); }