From patchwork Thu Jul 6 07:47:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13303286 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 DF9E215AA for ; Thu, 6 Jul 2023 07:47:49 +0000 (UTC) Received: from EUR04-HE1-obe.outbound.protection.outlook.com (mail-he1eur04on2042.outbound.protection.outlook.com [40.107.7.42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8DE8610B for ; Thu, 6 Jul 2023 00:47:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=E2LqMmKNJW+UOiA0PXpSK1nJRIC6vz2TusNwEDqXw6RzwyvpzH6UqVNC9LNhz+I3uiC8WAl7n711uY+VpsPCecYumabZCL7QTac2HsFHY+gGP0YXwPo+qT5zaS0e7f0gXUyBPAC4apH+gyFXkIsFcHZpgPkJUgRwE6GiaktFvBv2ZaGMlkDmF4Sax5smI76HnRmHTx9REXweyG/grfxB8At8aAyR19X8suwdnJDTu7kBBNilnax0eARERzt4Gl40hksN0ypsEO/ktD2i2yMSFQxDUo8jSWxzE2uoskHychOtgcRMexMrZR53etj3F8BjBY4Ho5n3L8MR00dGnk2hXw== 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=Y94uJl6mxjKQjq7qysAKA5azPfEADA/uWX9/NNTWbkVRHkgfqg3lmRA+s7oTQvqi7oZ8+ode9RZGnu0CxUEo9CmOS5N903410iVPGF5Rmt9OIWL2iP6ONLQXnPXbXeQT0/n11ysXz5YiXYxqD0bmHOGZI+vxru0a8JhwIoKD2KpFlDRu0hyb5+uCS8fPI7D8BjklhNMBDc2Ec0sK/gfK2t0Z7qkDUPlT70dlejS12ElGr1T0Kcbg7m6fXRCc+UU75txhRELxuK3n+Zubw7x27okSA5Rx/N6osfuaLzp4+5cRpgZIaJb5FGZc521G27PoPGgjvjGeliJh1M9kFJOZ+g== 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=Bwx4MX8FRr80gTS/zl9lKi+B7fWsfYQ1+dgft71/CSP9Y3T70ztYSNrzi1P3gD1n1INKpw3sAsxdMUu/iBImRuZ/sPk5CutmX4NWPMTlkyMPXkBqOElGACZLWSCfPiWRK1LJdlM/e6urk1YhuT0f+KHXz40DuLKB5AgaAjuf0Bg/pBfK990OoWO5ulMb0TON/tHwcVfERBxSBDiycKDlN1DJLclhvVICHD3HGgJhf4pRKfohJjcV7zB0Fcz31c+/hIlYBH3ewNUUfresapCczFPcQ3qVKUuTRu8OWL5kuxbMD6stx1k6s5QtvKFT0hl4KjCsxHMOZsOVLJSZPiEJcA== 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 AM9PR04MB8437.eurprd04.prod.outlook.com (2603:10a6:20b:3dd::11) 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 07:47:45 +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 07:47:45 +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 v2 1/8] bpf: Add new prog type sockinit Date: Thu, 6 Jul 2023 15:47:25 +0800 Message-Id: <0880130fe8ba0d721e63f6d37bd8ff6311eed9bf.1688629124.git.geliang.tang@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: References: X-ClientProxiedBy: TYAPR01CA0157.jpnprd01.prod.outlook.com (2603:1096:404:7e::25) 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_|AM9PR04MB8437:EE_ X-MS-Office365-Filtering-Correlation-Id: 5a48dfb4-29b7-4940-153d-08db7df54963 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: YKFIMH/QyeSHgJ2DZ7n13ZFltH34RsK42Fwqwz1GyYPovw1JSDeFz5eL2wPIzsYfKPWtcsT+WbqnvuU5Wxy6/PmyreUCXHQ7uzEq7WK5X7xmSDG4iUqLbuklFXxYBnnwSfkvlhGZQqTZBvwi8YwakEZV5ixIqdUUqaXzjY0osSsGxep/VaNqjFmLYNlC955hnu3s+H/f/GwQbo3JvQhIGerSoYhBABkKRXH4VDwWTHZygdKwRBRL6UeV7LNQq6wJHkSX8SweSsEeKIt3MBhoTqDqlz6ArwwL2H9AuZg4mCMb3bUpZhISrgfMzIweSLXc1bxmSRlHpEf4rIZ3ieCHVd1VeR9cTQK9QSMmDFGqhzUC0YDUvTsCZNKQN/Lf9IyIuQ30MUIzYXZLvX0vAYICJLffp1KLQeOgtdheYQQ/1uSVU/SS6QETAUIlZr8CR4X8GNEsVHaSuaRBYp8tDQ+3aOWod81LANWRITRphzsQ1MBy76A+/ovsLCorSSqUQbee/E/GAmlwoIAVmblgmwjn0LytMnEBUkH+Btv6AR74rTEO8RR4gYeLsXzIbHuRHy+ydK1NxT326S/sP6PvmeEW8WfeoyKTgGsZiim3hQYUH09xYYFTMvOoDUB3+6JUKE5t 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)(346002)(376002)(39860400002)(366004)(136003)(451199021)(6666004)(41300700001)(7416002)(5660300002)(110136005)(36756003)(2906002)(44832011)(8936002)(316002)(8676002)(6486002)(66476007)(66946007)(4326008)(66556008)(6512007)(478600001)(86362001)(38100700002)(186003)(2616005)(921005)(83380400001)(26005)(6506007)(13296009);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: eG5FUmE+i/SbAODvh7VIgQBdB36U8kXJtWIqkyVbZF8yp1AoW4ROyjLY6gSWna9aB12raVTsWJ8K7Qw3tztfakfm2lGSOcqXlSjksLbLyhZvgALKNaLJ7HhYjmYgRXaOpxVABG9JI+s+WJ+GZ5Fj5ij57gjtxsAk3baCZ8ksRr0eMpnD/wDk0hbj/ISJJ+bDEB3a1VZs5fio8pbf7b5semKcRImNZRkHASo3GbLmUtYnP4LrPm438xYIjP641YLMyvTteGh0GjGUQcMXEoRkncWHq2zzbQzZWH6ZjhI2VaiHZ+caqnKMul/Jih8BiC3MGvrABGVwi7y464PO+s1l5keeHQoqryK8IZDL/ED2G+4c+xK61rumntgYP/x0X9XgPnLljXAJHZGy+fAIM4j8LlNrut92JwJjZB5pm+X4KBFcVu2OgyQs+aqaQMM14msomqvJPEF1MT3bdvxziIWpSQgie6ziBkftT7O7zXMvDVwMHfMTeGl8jbkkJO/RHlG2VSS797LinqpOWS8cHZZ26DCrO48STyvMEHp/DoRF08wTnvwBlafuprFvs9dzM2sCEPZdNBIQLZqwuhp8k5ZwFhOOB6e0Hi1aJaA3bxvtg2YtLq+0DFdNO2YjwR2hnhmms8+wEu57Vxt7PSXYdQjn3eRg8ybdQxHYyS/PoGyua+DBI5TBcWLYnEVSCegV8hiFOYSJhJjHWxt+dAb58sweRwOmm45Jy/3rT/ssGolep8jq0Qj8Nr1ppV4ajGWeyGeI9mD1X9bW1oo7nK6hZ5clZbwRzYWhDD4Ovvb3MuZ8w6Mt2PpMmmTiF2wwghz3Gek0lLY3a5Rv+BuEq2UyemstCUjk1h6Lg9whv07zPsamjH37vzLujF+blhzqY5xQr890tq/taOQ+UjKpnDtGOT+p9cjomKiGEsSErufSZNKvcd/9kshWm/Mr0jZNGdOjtTRaBvDWPfAsaAtY+Ml7QhACg810TT3WHvm/WvV+giBj/Ihs5Vl5BLJNVKJHg7AT2EGSwvA7KbGPqV2V4ymJUswBhLMwuVKa6YbEJLWLxz0G/RP+wr9rl3dpog5cFoqQAKT9VWbR8hC0mOlqGG0B9IEENy/gjdxxNckbXkbCgNg64xoBTfKq84pJ2i2aH3uEkc26P+253Zcplp3tTRBxD0yca3TLHpYa4ObzOLszi6ToE10gBzR3YTtdqYWFD25hNmp+vJ5SYZoTjWf1FifS5H/RZ5XeeopLUYXcpiqhK1H1UiKVTlLdSAu6eIJneLECB9T/G8pw5EI41zfmYOl4Hvuf8mJ2BxHpIDRMx+lu5AfpikFFWfr2ENdLTkucNC17FzvmyUYSlL+KYyDCZ6Flmo3f/x+CnhBj9TP85mJj3UvxC+/UsUjA/G1gbMSDr2wur2tpWZAGY14rEyQU5AnDSxeYiO/nRfGkaNllwk3MypPTt3+tLb87VENzs2MaVCuCj+TBDzNipPwKe3SP5f3Jv7V2NlYp/iHflpGUtB2YI0MYp4n2Wy7R0dOUtBTKt24+ABNBmm6hC6OWJJTqSTGDElytgknQ8X4HKmjIrmVeZzDsCvfiitNomNaZ8L7aptOM20PY X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5a48dfb4-29b7-4940-153d-08db7df54963 X-MS-Exchange-CrossTenant-AuthSource: HE1PR0402MB3497.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Jul 2023 07:47:45.8370 (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: N/mGt0X8KiS+euUyDJePOOiz5yJgNh7csjWGRvGpFJvHDTQwyhylMNUdEMeiCds7kgumqRQRHhLj4upjlKii6Q== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM9PR04MB8437 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 07:47:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13303287 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 510F615AC for ; Thu, 6 Jul 2023 07:48:02 +0000 (UTC) Received: from EUR01-VE1-obe.outbound.protection.outlook.com (mail-ve1eur01on2042.outbound.protection.outlook.com [40.107.14.42]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 051C61BD2 for ; Thu, 6 Jul 2023 00:48:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=oIdllxNbpfcnXXDqbFP9Hi0C4Pe/60IInh9FugHKJB+w5kS0t0fRRq4W0uftCcZcYmqfwabb8pnaVxLHP2OEnsEgf3ApLXsffQ8PJZq+Aa5JvnDE/OFduze34yyTgycqZXSjY4puC0FPzW4dTgXIsoH4RdKXXGZtvy54K+irwI1gzizGwcsTdoBiYSkEbMYEp9ryWKA853WKxKZ9OztcZZ9OStzuatXeBf0T42uAihUM0Par51vYC9GfjoQCyJ+bTth9VZtIKUhpBA2pkjiBQT9Ug/Pt8f6y7rfeBQ1jru+4O/3x84sgGo7TQQgvbULevyzI7Doxj6v7QXaZGZYtHQ== 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=TMahPZnsBiCHHlHyqsWVgCqa5C60nYCZ+XfBj/zJyXdyhtJcW73Fjw2pc5z/BeoWEZY9vhmyEwyfqDl9yTumMydQsbIFVzt6X5CdyVQs4ZohMMCg7V5Y3D2VmLrd7MHIo2sdz+pHq3x7iVfShIj/4uuvB0AlxF8O80lAprjd7K2hhpMFFbeXER+mBQ+vpzDNhX7xALtchWF5PiygYaWz5J9EPPSApw68pdJhvdWImc5rK3Ww9KTghgpIL7MnTXVjZ3AWjXTJ3tY03uRws7HbNQKlUY1pOoUmNThohBsOsYyQwzmLDn8OL8nw5htwzOE+I5fP6FPkMfLhOLGTvEyLZQ== 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=FVY38LDASEKIZYU4dutOpHGgW3VXm5KTca0crdw2sUqNhCmgZcrInIH5zPkwkldgTM6sXauIaZ60/BpPWMqBrBSNWBiDDgChyQzi3dgK+CDUjB3C5Gpf/T4zG2324z0FiSNSKpIbidMqLlV3I/lGSgyzI4C2ZeVDIxqfenPKf9IPqHeBoZwc+oOJMS1UX5hoKufVXNXrIwWWbp/UGtQ8o2XKY+Vre5GCyth+6eN+/A0h67mvnJ+KbFV06FoXRUdHo8q4UyaqC0yquh9X4/ccUpwyqUqMHVJezSYAV8coW4gaTrEQfGR/wVioDEVOZd0DK7fEcwYQ0r0f85xOIRy/jg== 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 AM9PR04MB8437.eurprd04.prod.outlook.com (2603:10a6:20b:3dd::11) 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 07:47: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 07:47:57 +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 v2 2/8] bpf: Run a sockinit program Date: Thu, 6 Jul 2023 15:47:26 +0800 Message-Id: <1654cf3707d93253e1891084c74894a1f535abdd.1688629124.git.geliang.tang@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: References: X-ClientProxiedBy: TYAPR01CA0153.jpnprd01.prod.outlook.com (2603:1096:404:7e::21) 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_|AM9PR04MB8437:EE_ X-MS-Office365-Filtering-Correlation-Id: ae083e39-62ac-4791-8f36-08db7df55036 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 0pVdzuGjk+pAdoU4UTTOVVybcU4+1WY9MV/v9fbFzGCWwD2mYnWnIHCr/WmoKUixJ30N4Q3pkfAKF/SBI1MBLXLMPZTnQicFc6g680Hg7R0PVq/0pOOfLHmnQHlSYClyuJkisAQso0yV5SUyBfNE8I55ZzsTAdWUCx1qmoeSTlE6y4NvAmXrPPYLZEMf8b9iuOoLVmWy1JRw0Ui05/wccnnS4SMaRfBclhyQG09HgUYM5Dm4Kbb786vcz/0+RZxgmFns8qd4NbOXTrNNFbQDD0Xwehc0xq8MjjuGgpfwQwspR+F4ncTaFSSNZV27Vmo2BCkpu5dPOcsrACkXXNwCl81TusWbJA+AIPpfMGSiDXuABzykygHzeDAKbnYh7NacOwdOz0yHG5SmnMyVLFbAamvgdDbxtq9xnhTJ9LqWnhRywotWtB30txfLbFuAIJsRxnAhVjJe2A1zNaqK3+N10p0n6v8n1kYkBY4px96ona3jAXkszd2aZEgVkS4X5OGecrnCvKDWGW/ykFm/qVvq5nsni5qmp2AMr+d5+jJFX2MKt16rJSUxXvpWgljFCJu0KP0NjUUrDuQ7WhfOsR57ETmH3nVhEdGJD75W4o3/+HpBDtu8Dqp2xo5DF1bfqhmd 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)(346002)(376002)(39860400002)(366004)(136003)(451199021)(6666004)(41300700001)(7416002)(5660300002)(110136005)(36756003)(2906002)(44832011)(8936002)(316002)(8676002)(6486002)(66476007)(66946007)(4326008)(66556008)(6512007)(478600001)(86362001)(38100700002)(186003)(2616005)(921005)(83380400001)(26005)(6506007)(13296009);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: OZObJYpFlBxRHvPPao1jqhcb0j0DLqcaor2QyYOV9oV0zV8qfasEwdEjwAd34YjN1ww59lsYBCoZWaJgEMGZcMbIQAmteiyytXNOC6haIJmUaemukOtPEEfaaBjuqEz7e+vFvtCkUCgNciPCmQKhixBK9YNU9CI4IRctxhyKbUtFAbBSnC2xYcbLdOv0J74IOOybsofrc/gci4o8afXHQEp0BBGOxwHhOCkD0MdrIFrFLWVIezLGog6tynJKKDRp16+Du0p8rYwMvTHmvlAdd1YSvI8PYPNZz6mIbyGKGGGkG9n1FsRDRrhB0CAi+mhjSZlJSgmH754OH1VrhDaQ0VeUXn4Ggx4Fiz4+aDrkwgVmBb8y7y822sMUHBNK2tnVFkeBioKmmmDY8vxxrSJ19Vl7EA7sKTLl1dTCbJ2dNFMYV35bbryXzfe2GAGpyq4say8uxuygD0my7gkVkmHk2CwBZ35EJibJ9eJTgA3+Y+jJToGqkuxEwFgvVnjQdTLBkolwRXrF7qXckWm/T/9mpd0F/K2fG869So4VoECML8woW98rxLiPCm+BmjCdyETCQaFn88hccTxVFDGLboCxWc8Ayk9/sfQYSwnNGiy1RZZAJAoDNtXyEBkylq9G/yBQY3m4yzl4TEHf9obYWrJ2kkwQXnW9lSfnMESspTr0IJ5n/rJiEE7JdmtuzVVyiwAkjsC/rq8tE5hwJYqnrgyLMNPuA0UsfltNycJKvXnpBN/hp81cwazhLvp2KSswIACQ88DQ0QZ4WjMaajhjzigzRj5wjYBehqNH56pL467dK8+1xvkrXuzdSrd2JUMmQxNl6rnEm/8LhsbbggbhasJsnJzQWdcJ3flKPvok7ecYmdhg9yWPN/jnXG7/SsPD0pM7devBEHrafrU3b8/vU9y5vCGM8DpPfLPdtYvIe9U/8lpoMpjCblgyysCWLjk9k43K61itc03YV+60M69vgMcNdSO8twOY1IRDAzb4Rpw1YncyCnDbk5ncpkMaKg2FAiy71f0BqCT30Te/98vg62SWmWgHYZ/H2xg19p/rrhzKovw/YgYyEt5LFWpIyLee/bIPZEJYAVmchuijpbY0/UYRxnlgq8943Jb8H86aRRYyWLoN1lkV81R+Fx8V59J1d9FOcQDOCLfAPIL+dw11+UncGONcOColk618/fV7n/AGTTjHex16qvKvkAs1+NoVO1slAZSJG1CnkMg0By3wSZ+svrWJ8qavjrLe3wmsutRAEGjb6mdHeIA7ASFCWfdjwSZwW+b+bUrY0oGJbsOal/TKLkAOQr+v1IbN4xLYxewiRCQ9+zZ8tC6ZvJ03ejkGA3VHnhmhYs6Zl2WzpdSGJXR3KJFp47z7dCyMuin9PrCNyeYjyMrBfyFeuxtvSzPrThd4YCKWq1gUzy85Z6/nXcTKQSncLg17N5/xozh1o5+/IZi7jhyw/EJtHn5cKl0rNPI8nFY+UPJmWxRgx/Xh6WW2aC9Vefz0AV//l5h/G6jzdektf6S9AEqvRNf6E6ArQksfbWroqNe1wdYZFgy6YZ0/d/9yvPx9fk+rxHyHnRnRVdYsm4eB57QtjUv6W8uxfQp5 X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: ae083e39-62ac-4791-8f36-08db7df55036 X-MS-Exchange-CrossTenant-AuthSource: HE1PR0402MB3497.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Jul 2023 07:47:57.3087 (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: dBLvwg5tiF4zJcm7BAp3aiitlSjc7JzLvRz6I41J0byWGDm6EDjBM5w5oeMAbfWdOG5ufgY7ZLBJlFwWRzl80A== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM9PR04MB8437 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 07:47:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13303288 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 21E4715AA for ; Thu, 6 Jul 2023 07:48:12 +0000 (UTC) Received: from EUR03-AM7-obe.outbound.protection.outlook.com (mail-am7eur03on2043.outbound.protection.outlook.com [40.107.105.43]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CFD3410B for ; Thu, 6 Jul 2023 00:48:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Edm40UAL0U9BcFCACF0CAyFMC1jBevk53H42ohEUICQ6YUMiZsH54W4KvK4hGpFZTb5Tyd3FZNLIL5730EWyAfMhKRSaGJfHmS+N6HAFzQQtmdkCZGCm1IG6BeO22mkXJKyjFE0ArBdWol8kpvt3iZtoQ83AVcf6nDnjliW2wjlzymKdoFtYpjO3Uiz9soQmvJm9UzQGgOBrWa+tE+bJYj6qeoh/EWd5Z3SCpNki1M0DB9L9gJhCjcfHTrjaiOK1GYIdvjZkB6Nhn5etzVDsywcE0kCmlB3qUCYfUT2ulVd10D4v+hEDGtN76JCckQiN2MzLnmWOZYOcP3ZlLbeB/A== 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=iWguMhKIUxkIdXbyZc251EeuK5/eycH7cRHF93njur3Q7WXwrwAboO9U+Fk2Phi/sojOr3I7yfX4Px3gYWo1DBWx0D8FmjYaXbFVNyHX5iYFOoxCaG76bxrCcopZN/Gb3Jwge0Ige8PxnBEpcGR/0Q4NP30yLrTcXUKtfIqqPh40f3/PP0YY76rDgvNfCn7DRnT5KjMIVgRO33JHmqqNdbn6q7ecFDhSkjLqqLKFuU9IUTeDEPfvBpszz7644j2joVyZ3EoP42ipXsYbsfscgtn9SoDZBqvKLDbk8hxMrkYye5WC1GYpF2UnEMCK5qBL61fAkblXqOHc7dfVFABtKQ== 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=GFiD+UCNF/p6J7jNV0X3ul+YbeMUBLhaOSEBDJ8NI3nx7/FrvZ4ygeYai0eL0Vau66bNRVqKkZwftPuwxP1Sj376kfG2FXk1nagm7MPgt5rCEjAKgkKdnbGJdO1HEGL3j6pFL16m0J/P8IhpciYi4SnCgRhPin2v9eP7ah2ZKME8en0iCsK/bDJMn1DOQe+L4JDO3nCbRcuZaDej45YWV7sZktd1Jt5kEMM8cVuCSq0C55DYaOo1iLbQ746sSoOjSVyiDDs1RlxSTLHWEMt2btiC154FjYcUXyCvD8TH96lCN7PTAoQ/wNohKOyNop3Vdcypk8L68He40Gr9vVM0EQ== 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 AM9PR04MB8437.eurprd04.prod.outlook.com (2603:10a6:20b:3dd::11) 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 07:48:08 +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 07:48:08 +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 v2 3/8] net: socket: run sockinit hooks Date: Thu, 6 Jul 2023 15:47:27 +0800 Message-Id: <5f76da0bea3453db04bb07399b4b1c9ce4859e31.1688629124.git.geliang.tang@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: References: X-ClientProxiedBy: TYAPR01CA0163.jpnprd01.prod.outlook.com (2603:1096:404:7e::31) 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_|AM9PR04MB8437:EE_ X-MS-Office365-Filtering-Correlation-Id: 08acf7c3-d227-4430-1b77-08db7df5571d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 9qzI/BVWYR10dX3h7y1I5eSHsscUASv92DSZPzKc2tFdu3M0Zz6rHmfFTua8wItuOmQgv1+puDU4rRHACp5F4/eKDVCR+XcHDzFpAPmyxqqRq5i3MQj9kzpONBXB7R0AhQqwgmrF4LSMPxA6YE877wdEqrcovLKs0M1G+Xxf2sH6fup8ixE+aqW+mFnmB2yzB4gCFpAlVisCDp15Teh3kNIRYBePXfvq8sd2pI1iCRxyhwn5ZnEeWAwJfjyuf8ypC9OOjajat8vHl9Y7uxJec4Pt8KDwRHY/zjP4d8P73BOtFN+dAr1FIQax5hhNYFAjBrWdVp/7De6L9eE1QcbSx1VbyWnCMvDzkAi7U4OuJTQ6BTeFUlQqsxC0yH3LqY2Our52TqKx1UschfXCtGwvBaQL3MDlvcDJ+GRrhvrtiAfS9OVWLVRkwKKwCy3MEJtnzOkvPx1JRTn+beBlLsY+/uf9dKJojrtNb6JrH81/YfRy5Y/MoeR47zSzWEGHzxriiVv4zlm0PJ9nQP66vQ0CAwPaMCr/wGf8YdESUJaF8utRtq4y51yJYyoug6cMkuD0u+SGKKt33naHu3EWr8DQ3LCXYEKa5/iyylC+EGVX6YXOk91oPr+eyLX+UiAa7QgY 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)(346002)(376002)(39860400002)(366004)(136003)(451199021)(6666004)(41300700001)(7416002)(5660300002)(110136005)(36756003)(4744005)(2906002)(44832011)(8936002)(316002)(8676002)(6486002)(66476007)(66946007)(4326008)(66556008)(6512007)(478600001)(86362001)(38100700002)(186003)(2616005)(921005)(26005)(6506007)(13296009);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: qSb1Ja9ErQtVzwdwbwWXqMIXV18qhANxEleRUBJvGvOXLcPAQMnNrNuTnN9q2JzCSewGZPdep/atGHQmD0yTdnHRxRK4tYBvhpNE8fQN3Krk5XfE8yE//kxGgJ9CqPel0ZYe7VaO8V7Jcpzoclk6AlWzxGQLdHJ7WGuOKxBQEmxQH5mCLs3QXgIsCi6EjBVcLytaBxfx5Ft0NioKdXK9MBdzZET5xDHl5c9OVI8gJ9i0Kro+v6vxPsBQn2X4gEBrOedLy7aiFKLDYqkEcNPCmMD4B/+naiXLF/+TqtPfuAiLgprn6Qo36cAIGgqs/rmEN2di3Rv4resbhMl/zaxbGIZVgs/hBdsFITPexBcYz0B5CAu9u6D2rHRN3ACkPQ/B7lpcKjEHqjnR7LX7TOVtOKWbT6samPTAgR2Jmt/aKvm6GrZwluZHqXk2PO8IfwGZtT1ar9Qrpsa41SpFA11ET2rNrm7/ec1fzwLkVGo2dE1y9SYIKbCRUtqk6hUysOyxEybB8tkK6BYm7g9kSVs8RxNOlU/xkouOVtw+V2qcPeUUcxnqvPvIIDkpx8yzbw+K+8Qp5nlm4Sdv4AaM0+nIU/nwrPJ0ZTLW857KEuRlKDU3yCzhMtCJLasIPRUTF85COjYHHEX9wBM9c/LqHHEqzzihS9kfPiEvpjhsGw8Rm2yUtC6XmyvI8xVXx1eumUIzJ11D2c2ueG5vOvkYG2PbwpXh3JRyoemL0IUDLkpOkiYUP+A4JTbnTZRHhG7CD3UfP1cmpCyjXfLBjmq569NrAyP5Lq1oUPg4Mfqr4MXXhXiRfykWJG1RfD4cMOZWXQ5WnA1h7AqH3kuswH4Ge32E62EMYLvqbTDzZlec6n/P8PwBwSfdFm1crfY2UnJuCkDn4MvUJhDjMCzjnv1FzX11PupabBj+s+3Vht9/lhXg855hJPbPniKv1qVWD1nsnep60tXu176mRTIYVpvm9bnettZq/FeNtRpmhxZJUCzx21YPuXyx2ec0iZlEpSRB5P4KelFQqTTHv0EiLZWOMn8NzeWAOMOcC29ZO6Y+yfShmVboedkc3Vv7MBPoLpUL9fuNBomLNQf7K2mlrFcoNFjswYVcwZ72Gc+mIicpFDUtwVlr/NDsMr8oAcQSgMRiIRwsPCWXb+kVrsOMGJ6sEeqkaIT4odXIbDFflLeWDR2ioleq+ToWn1GZ3PUBFjF+7+UQz3RABoC82ZX1WJPStFpU0fXF+Da9c3dTtsP0NLrnuN1ULc7fezyXx+OWCKJFf5B2d8/ccYzPtKo28M3cWiYDRzBTYyi2e9RCtuEE/M3ihQojWEghrBtTU8vM8MNupyxI6WM1ppUUMppM7cFr1aaB4VcSsmlyixb2t2JGTFTflfRk35jhdzfqaKRNKffsLk4+KgbttJmejkUgHRqx7AY3mKUgatTzzmYe75IlD0eAW3PhRwLhQbD8owVYxAnFXJR31EcsxuN5sXJMabwrBDMV35nxiePHRbdSsTeDF922uZs36L38lKuO5SyXxuyaVMQ0W1w0+oXeGYFuvAtKiA1qz3lAHoI5dcJuqCQyW8sXvbUStaSuWJmwx4Wtx1MU/Bdu X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: 08acf7c3-d227-4430-1b77-08db7df5571d X-MS-Exchange-CrossTenant-AuthSource: HE1PR0402MB3497.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Jul 2023 07:48:08.6540 (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: TxjYrJ79kWDYvR6fHg0oUR7krpfp1l3Cg1aBKysiLEgn7KSmlorKMM+x4Xqj3+Y7UC6ipT3z++4KVQg/1vE7Wg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM9PR04MB8437 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 07:47:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13303289 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 A37C515B0 for ; Thu, 6 Jul 2023 07:48:24 +0000 (UTC) Received: from EUR01-VE1-obe.outbound.protection.outlook.com (mail-ve1eur01on2078.outbound.protection.outlook.com [40.107.14.78]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 38C181BD2 for ; Thu, 6 Jul 2023 00:48:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=UhwgnuDRlIPA3oGvUhOhNtqNLNyB+ZhvbwZQaFjoA/Dveo3fuQPiZVAjm0RGpUUD0pIeh5n5p9M8o69nUA1m7MSRADEp3AIZT6Z9k5xwIAI1YifDhqOTOFl/a6iO+TSoVQzeNdF63VjkIsXDVM5wvFyeOn87rgWNmBLsgmKWtb3rvwItR5UxUYQlfktK+s/VASrSe80OraXxxBx4dojKj58MSlTASRONao1Hf2b7gCj7aRJzI/SF7ik+Tf9I4pzJDK+9z7HBxNbbnuXtME/ViiERy8I2jOLidlIQge/Hh7Su3oAKHYJwG6QjGV2bcfQ5fqIEhFdu8tMMEhRnhnFIAw== 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=MSpWdiFSow85rnytVBI3bk2qh1vXtFq8tUxAagfluJbHoHIvuUra6V86uSaiOeuNTPpMrBwG8Rmn/jWlEL+c07kgyBzYTWcxJi4ZXyisawFFplylr2+FMT3ANFUkmXBt3POlO/CDadZtFqzMsoPw2Xnc/2RO8y2XfPne3gQDgwatppwXlI/GBRBzhiddsHLRyV23DwZQr80zvQoVonCohOP8H1QoPVzYjITGEasDdXA76/RXk51dMNbakdzQHV1n2h3IMK4oGQj2AW4kOM6lKmnav1n1aTPmkJxJ2vXNOBOVhHroi+dwDORES3+TE2tIMpDJrvG2rlO6Bylr9uoxGg== 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=0PSbrtqMbeCbMNIXxMwNILJbsU8pBV+8bSD6ZD3XEuQCRekSGLq4BU9ZwHNH4Ky0qlA0zIGv1aRJQnDDz7lVTqzYUHTBuqAQU5FDJhhCAR7OJQ4uKbAv+JlgOzk1wH2zkr5gYtKrH1EtGBZSQF2UkBh2OIr5W4lLq7rrlwHyJOucvu1+WpasPbTgREOa+21l8AcOYiGJi5o6wZEkAgveC8OXJPDBKjB7je0Q2/EY/ETZQqUsXL3wjMp6BL/Wghwk4Uo0MgKkMK0JQfNEG45GT22b1ovmypDvdBXU+LzRezv2+Dd9bAXQviwWPLMgcn3SNzZLPxdVoaFEFO8pVENP6A== 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 AM9PR04MB8437.eurprd04.prod.outlook.com (2603:10a6:20b:3dd::11) 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 07:48:20 +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 07:48:20 +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 v2 4/8] libbpf: Support sockinit hook Date: Thu, 6 Jul 2023 15:47:28 +0800 Message-Id: X-Mailer: git-send-email 2.35.3 In-Reply-To: References: X-ClientProxiedBy: TYAPR01CA0161.jpnprd01.prod.outlook.com (2603:1096:404:7e::29) To HE1PR0402MB3497.eurprd04.prod.outlook.com (2603:10a6:7:83::14) Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: HE1PR0402MB3497:EE_|AM9PR04MB8437:EE_ X-MS-Office365-Filtering-Correlation-Id: e5cf9853-8847-48bc-0a2a-08db7df55e06 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: U3llDOyr+x9H5+71+3QevMXqlZ9BL0L1MknI0bMiKfflGb2p/Jg/K7z90sEoFVKpko0d3rLLCNCT+3mdtP9Wp2zZbhUIKaz98EmBJWi1FBKqscQRYQfzODzz3mAshPX6fASkw+Vv28j60h06plx1O153AJZfC2qxe1xxTxFupsbKtJM+/+8BTKQRT7+RDyyvMNqub+Nl8VfzDZYMgc40AxxL/9O6+jurr47PjxSy6OGw3oB3x5pe7TW9NPp64MB8iuHdTCmf72bWbWXHWSK7zKstbmGm6YD9DuR+UuWk5b1pbRpwrJIa4xZZlYx4FF+rF/T+32kxaDR6OyRbIkuYQVy8LGq6BAUlxZImF0TtT3urmh8LWtBuEsfVE8KGysLc/AMAK5BWEP2iBjCDQt6OvGWVgbepuKTu6GwSaaFzKbxIrkiPJrrAEzjf7Eadec2H8RLDSj5X7VGlkreKkq3ESBQ19g7V2xcyXsYB5h2labpSKsyYLjfKlG+ZWXyacf4R4qiHYg7/MCb7p5oTzwHy+yIJpWfEwCqclGXO9oz6e6ZTuIRnKgO2RwDEmxQasdiKr92lAjfAXHORqqm0mrT/qCnX4fy6kj9XX8XlnAU9MNycbdlk02n0b0FM32S6b1sL 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)(346002)(376002)(39860400002)(366004)(136003)(451199021)(41300700001)(7416002)(5660300002)(110136005)(36756003)(2906002)(44832011)(8936002)(316002)(8676002)(6486002)(66476007)(66946007)(4326008)(66556008)(6512007)(478600001)(86362001)(38100700002)(186003)(2616005)(921005)(26005)(6506007)(13296009);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: ZRDznimB6xhCvxDuhV9+RBO1thEw8bfmg0s1tPNngy8ZvftT4cF194E0Mix4+n9FVOAGN5tEQIpGN67pskCTvQcdqX7jbAQIyXDdZlXESt+2syM33adkjjMDQq4THlQrwtdBsXToTftgIP4ZD+k4lR815uM/zmlciKAezkiez7CXDz2KEvS6QvrHtaKpW7MayQXOtRx37IkkuTX0vCq8L5pjxP9r6LZ1ecTC49ZTdwcptM7QX8NUfu97grXa9Vub6a56AmJknu7LsuT628mFGX3XYBh12dxOGbE3q8viCQHJsKxCocx9y+3atl8sYNPybQ6O7RuqlGCdSb2bwYPUwYLkqe4+C6JKmhuE0vl6AMdVDWYJbaH7qU+t5itmktnuULIx7a6x9wh7GqRre3JK36b0gBpG15ynqLAOkLPjMxtNDKcXR82UalBw5HnLawkDp4/Vwj/3eep6E9uaMJU0mQCHFA23hVYdWhlFatV1P9b7IwyU+sCdIVpSAl3wjPLukfwm8WQAoK/P7sQQJm4mPRiFmngbnpiS8dPxIwimkbLTQ6emsUdhgPBk9ORnmaGX3/2TDYd3PvLyh6HU7IGaeNiHrkLGR6HHa+dLN9Ru5uLZQiqwdawR1paDU0mDH+d908AHQS2n7UWd2HgmHmD0YlIJtQjpqTE8RbcIXfTUxJgFwfQjxjQaHtLl0f1CwuS85lmhOgxrL/IlQD+KQLCqCEArSnb9emi7f0RiNWvBirexiCF41qTJ1LWNFFqYOCBA5Bw+/jHtVXIbCYtiDsSrI7DN5DgWluagcQBCoB3B3YoGV3QWMiOY/vxUf1d9PKAQ0K5GN72/dw3KyyP+cEFuYFCOQo+IafET2iWSPrWHYbgNcQ9/Va7rNls0L6burqLV/j0aZpXc/Mh/fWW97n26Gi/0jPjXjd/TsdnDjCYx+brVq5nFKY1pR5gYd1+TTb0B6yAu6celPgYvFKXGBQNZ8Doh4vA+YJhWR5cXtISVcm9ygBOBxDgQrPppzw7ELaF6zo0TpYxN4ZXRNLVYalfHYG66RDZgllwFQegL4nm3dUeJEb+u+cSoCmEMM46Eg26sWoM0daTy5lGgySs2wn0qIgFylfOpOS4xV7jbOnWHe6iyVE+2525JqGzpHV/IOSdrG701/T32oN/oFMpFKPcQmnGG5DotLpFYi5+1m+YAUNHZnOu6sEtPh9TydFUBVnYbMUzID7hRUe+gKBzPUtWu4x/dOhNXYQcFf+51gMNTpB9rn2n3f06EltyuZNX8Gwlt7yLb5wRn7QhQPE/HOuVaRGyerWwF2aDA+7r1DgmAQN6akSEjdjQQ8MBDy5jt+Ief10LSOvjQ58VhbCIBQPW0f5ZmDBfA61MewxAgFUWcHj3P8YMWar9rp+7+eM5+ZBlrS5hb5Fn0E0QFzrKKLDYmcMZe67fWO1gZ47lRxU6PfTkIhiWGkx/Rgn9IjwsalQBh/xk3nJfrh+rDpGybIWQuvNawQ940iseeAx1OPCKliTSl8prt574NQdIbKT+//5kYLe6ijq3/kJLBhxEIGl/s8GH4RGOYZ+wO8+6uT1SDvXRQwNELrxTbkoyysaMpwqy5 X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: e5cf9853-8847-48bc-0a2a-08db7df55e06 X-MS-Exchange-CrossTenant-AuthSource: HE1PR0402MB3497.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Jul 2023 07:48:20.4508 (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: x/0WR7U4F/LKjmCFaBwZ1cuAcEKmI8lWNwItYf+q8kPqcnCEc2m4yjkUjdeUOz/7Mqv8ahGBeITNcun9NocBtA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM9PR04MB8437 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 07:47:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13303290 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 DE0CC15A1 for ; Thu, 6 Jul 2023 07:48:36 +0000 (UTC) Received: from EUR01-VE1-obe.outbound.protection.outlook.com (mail-ve1eur01on2052.outbound.protection.outlook.com [40.107.14.52]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 396C51BE1 for ; Thu, 6 Jul 2023 00:48:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=cWl5GcqjebLEpl1AHUiDXWVzCPglH166XVb3pK7ZXmQYGzwG1VkkZ877Dd1I21PwdxiDVgBI+2D8lEHw7/aaUlEPNuAKbDukDx7F5ERoHE97QKUw7eheRT6fUeIRZ5T119JkobpRyZlfw7zW3bPUqIFT/+jKi1YWRqfQhc/te1TgQ+gym0JyR0711ehrqQGpN2a69lYx8Zi6bp3uorYQOBOnQVKGphADJN6Kh3H36a5o3fJUvOJ6rw3hUDL+lEGFGJnTAr6KpiyTk5taP1DrM++PTZavWrh03HSFrhbEeREmU22b/ZeG2AQIWvZdsLiIX+y8x1YwjcoERdtf+86sdA== 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=lXTLg+xVK2CvuXbCIWLFC1ghXE0vasMzAJ31UTkhObEs0PwHrHANEMP5w8heSlIOITyZqK0bhKt7iu2cq6ZE3U0RsfjcCrRez6U2g6Rcpp/K9DUJ62l/Izbby9D5AAbrfYTCQIdQQO2TriCRJdxLIrmQfbs1iB4VPpQ1H9Yp6mbwOXSe7I0oBHsnqsSvYXM2HNm/L9jNVUIAfV3LmPBmFxUI4GJc1vd1abt78zJvhkXlPOMBeDbr6Cm/MKF1p5viyE9qB3vwdAMDy4fJqkcacmFG/atTNFEi3pjFJdmGCRmWriEC2tCOZTY/3/l0LN91da+fIu4Mz8VYUS03dHoI1g== 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=CUmzXTOoAzuxnWUbgG/ITl4XdTZ9Nt6HReKjEzo4IcIHP/JipZxRqzWsTMIBZ+9d+0MH7nwnIYk34aZ/qKKjgpGDJD7l/QMzs+he5uuZCr8bOTUf6wjcRIXa7vQf58FRdPD+Oghdm3/TLHgQd6KEPMHeM505Za39b0G7EWR6LWdWtpRBkotaw2K2Iwckoy31grOXqMF/92FKdz4LBQVLUrY4TwYEXi5IM1zBhnvQbKwIEZ/VepKHqN8xDTbMv8y1lI8V71vZgxPh61AOXpzRILksygz20WAoTid3+rWPIevgtvX3fhG6FM6u38VPU+HUsUXWk7cxo0ZzF3akNJdopA== 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 AM9PR04MB8437.eurprd04.prod.outlook.com (2603:10a6:20b:3dd::11) 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 07:48:31 +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 07:48:31 +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 v2 5/8] selftests/bpf: Add mptcpify program Date: Thu, 6 Jul 2023 15:47:29 +0800 Message-Id: X-Mailer: git-send-email 2.35.3 In-Reply-To: References: X-ClientProxiedBy: TYAPR01CA0167.jpnprd01.prod.outlook.com (2603:1096:404:7e::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_|AM9PR04MB8437:EE_ X-MS-Office365-Filtering-Correlation-Id: 32e75ec1-b654-45eb-fce7-08db7df564b0 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: kSnx9y49D5JV7Bkgfx/7XLyQXhoWeMeq+Nznpv18Z8wd1qwVFsFZh21pCw1GeCwgNPAstqLYsd0WoQ36agHbizdNzoUsFgUUrorHBkuXYnqF61OP5jjD1AurE4ZdE+g5KAA3UeeGCM6j2k00WMfLssUOMcf36KgbZ5qxXc7K8+2mE42UHypmgDdRWNpewIFAWgC1RPrF2JS8TqPl3+izapqQNlG3Y4wtzpgQW18b4+pi8bDKU7FkDv4ZxaLIkZqZ5osVaoTujrq/2QbafzFF5MOk66W7fyOmhSkJnv0s0Cv7iyYweNF9ZwkRKJ6dE287N/RGK2YtKevpbNpkS1d7H5PYGITiolJtmFfWCfXIW+N93jwBZlvdF2FZEhPUA7k1DrA6SgPKioA/QzSan39xWArua/R/Az5XxF4EwSU4E62u0q2a533KcAr34bxWXeLWePbO1nQxHDuGyRGAEkL4exh22s11n42qVvh6T/02PEFogBTQi0dax30S8RgUMHc3Z+esGdGfeGUSylqoE9/uc52a7nMrybNi1i8xkUP99tD2i4wFkDZYdauQmERRJbypWZLIB70C82K8P2GXy4Y1vZFEj2Wufn7zHrhN47tvV77KzwJUYgKzhy9LQubIuOia 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)(346002)(376002)(39860400002)(366004)(136003)(451199021)(41300700001)(7416002)(5660300002)(110136005)(36756003)(2906002)(44832011)(8936002)(316002)(8676002)(6486002)(66476007)(66946007)(4326008)(66556008)(6512007)(478600001)(86362001)(38100700002)(186003)(2616005)(921005)(26005)(6506007)(13296009);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: cnWJzIcvktJItQqKgImLOoRa1nPB5cuqmtR9cPbyPVsTsXSvoF4HIuG7EkXgqQ+7PLemIlbGEFnk5wWUAdGTwic6v6WSrIBhEnnIVHMjQDvVl2j0uWxcYua3PqOdxT0FXHcOx3y0QRyzlixsXIX020uGTMgCPBkb7VahZWB19t+WUkxlUWR+D1YWcMPUQiUXOM5ZO5MlqqaZGjplklxLXt6wVJ13bJhoC68/yZIsi9nKlC82qicpRnpWDTRE2Pd02ux7JqeYgGnE+MtPivcNajcqmeYhgv6WboB2yO6uhGWNQ5/34n+ziK5MTK5p0T7gaT3AzndGJXkc3e4A3OMIH3RHd1kcXsTd0UxAXg1qpC5xv61H0H6doI/3NNzsNY5iOd3f/GKUrrtPBAOXztqEDi/1Ww/S2Wo1L/7FH28lksYKkaOQ7S0mjOG2/nWjM4R5Js3yUHDaY6kocvu0Swf1noBkexYPybyy4YEohvlQlnXw3gI0VD3mC/UQb0KfE0zJK7lUbgIkV9ZyM+v3ZQLSBjo201oeYY1OcazGteLSmyNNK3Oymmt2lGyEjAw8TsFDuDtQba4TNYfH4xj/3Ipw2P7DRN2gCxkKbKN/cXuo4Q20XLIvZtN3qexPizKv+p0X6t/ehk+C0pGuuI7N+WdcLJxZFafYGhhvYY09K6A0hRjNtP6Yst0G5vKL9jwvlHZlnx43vZUX0PnoBl2M7VdYvDSoo8hi8Db2gyZWzqMnHX+0lqJzycdskAhjrXczeWKqxvpDcY4lmHLIxAVbGMXH+cXpXDmQC8Eel7Y7zPPI7t5Z92T6WNpW44+fEicCPxg9QOO/gEeYhACnqvk4hVQt9OPhWiKUupPtVHLuwxQvQMuCFW/LFx7gs+WEuvhsi3wnm2vrhkvK5dcFp3k9XCa1YV8pH1KMHtJrBuEW+Dz10khpOic+bPQXdLZq7Rw12lUzyMTIe25rlzU9S/zpa4AVnflgsgYFUjz0TJPKp8e3yhFDb2nJc0K2q++SQka7pD7DhslsQG1bUQSETf/HDK8Zg3zlSbTtj4Y87+wWj6RZoHA0M44Cp7gNJzqnIez7LgbAabc+iJYdIzJyLR4qCs9blo2glMY8Sf+gtU1ci/faVTJ2SxcLFiodi2bwb1Um5P/2d2QCjpd2cManhbvu3Rdu35zcBRvOhXIxmmzHdKHprBvtgpHEkNrjvNOipHtSZQzMAeos2YcLspYyDYmADkYn/a99hVVOIyx4fiROh8Id7vuU1d9MeAqNqlXn8loU4cUD7Q/pgBt+yZYx/2XCuQIrjC9gJORHcuY34Ilv1uDMs8PeRjgbVOZ0FmvHuiBYlqQo9VxwHDsmLjAxhC4V2JHXcxi/7kJGTGqa6KOqRjrmOuZN3QrELgh/3ku8DZQm89rGrNzC4NtfhvMRFT2NFvonkICjGZtSgwldNqKZCRBbaxBO2VDbLMDUifYpufVlglXqmuNJ7b6wmNhKjePXvO0NZZyIFQMPW6eY+IM0WRmXUbv8t5kXa1xBmm+W9uifjNGD89KAFH8Akl9K1CNIOPZjoavd72CuR5DfYXms3AReR6LYmJrpwa2A128YxJvADS5X X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: 32e75ec1-b654-45eb-fce7-08db7df564b0 X-MS-Exchange-CrossTenant-AuthSource: HE1PR0402MB3497.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Jul 2023 07:48:31.6335 (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: ysMhd6K4Enu8RHv1L9wZ9UFx5IXpTYTbZTjbSt19hXLsuNk8cp1RLN97nAiZssJ2I6UR+KtuQfqU8KCSAIXKCQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM9PR04MB8437 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 07:47:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13303291 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 1C33415AA for ; Thu, 6 Jul 2023 07:48:46 +0000 (UTC) Received: from EUR03-AM7-obe.outbound.protection.outlook.com (mail-am7eur03on2049.outbound.protection.outlook.com [40.107.105.49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0A04A1BDB for ; Thu, 6 Jul 2023 00:48:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ZOeRNZIvDNZN8iY4B3l2paBT5UXDJ35TJKxDzcKly3yYvyYK/PKMlCKyr0mK0I+pN7oI7k2E5mpvCN2VwTg3sB2mtXmI4apfA0RrKXO0paVWOyTIGiWbtZ/LqVmG9os6n45DyoHPkBdoRDBTfabGL7/wn0WY4kfFrrep1ovttzdc6cbr3D/7ZKX7uQQ1H5qLMBMD0ycK5rH/AGmxOHhVmnnc/JuwDc5HOlRAEVZ1W66AU/rPQ4Ggi4+nIJieIaCWRlyK0tw3ML1MlOFGowWMYq/8ObwCGhKL5S8MREzVEBJSF3xDqYDcUU7O8QY3NwGp1dbjca/2TEQLBUdNwag07g== 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=CMTZ+8OEoblQCyN4Bmb9lT70GZRjCJF3Y8GCGyn7DRN1tXj8cD2ujnUzNAb6L1/uJiH1MnmlfJ2HNpHrwYxWsKpF3X2o/kU+tiE8SUJLb1ymuGYrVBAfdvBZy6af//JZ/5S3y4/YfP9JkzAqdIlGH0pSxp7FTedBAcZLICeO8PWf6eVaL5pLgvULdtsEOmrXW/Rk6hoUf4tsLNTW7+EuqT0gLbCKaWkjkc2dSKHwPjqczcIyslltm/KEw5VEc5FnYJwRWFcbGZ5aiSDFwLQELR4J6M2XWMD4M8TzexrDyEICDP+PAgADi0mS+gWOtihSsw1ZKkFHVaHG8yNY4nUiKg== 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=ThvbJ6+1UCcPl9EwiRs24zAqZKL3vHqqH0G3piUIGDcbZF/KfsAHBZWxUDR0qkH3ttOC6hkgStUIHCp5aLmgxfbf3ZN2jtIjgLqWSMwuHRQa5cP/aWb51n139eoV3QaWFFLkpn0O62570xL7n9TsAy0ZgRhbVzUHmiGwm9D6KbOgBgFTORResZvOzAbtFRVyhfxY14NB/dakae12pUbuHdZXCiIIJYjquZGkUMcdO6Qp51QjocJTPueMm2JyJealZvpa5DylWfK1CA/W1Tq0DLLgftMHSKJVQNM5VMACF51WJAtQVbApZbROa0QSPwX/bLczNzP96sHJhY0nQjpSMg== 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 AM9PR04MB8437.eurprd04.prod.outlook.com (2603:10a6:20b:3dd::11) 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 07:48:42 +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 07:48:42 +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 v2 6/8] selftests/bpf: use random netns name for mptcp Date: Thu, 6 Jul 2023 15:47:30 +0800 Message-Id: X-Mailer: git-send-email 2.35.3 In-Reply-To: References: X-ClientProxiedBy: TYAPR01CA0158.jpnprd01.prod.outlook.com (2603:1096:404:7e::26) 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_|AM9PR04MB8437:EE_ X-MS-Office365-Filtering-Correlation-Id: 646df88c-cbd8-4ffb-6697-08db7df56b52 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: YA3nFS0FkZSl9OKOmH5rGTrjJjdMx+JLSgZcVaV8Tuxry8N6h0Hod7uG54dKAls2DqKFPqE/EU/AVcT9GlnMaHrQrGOkHhY1S73CkuIn8xmt9jaeA2+UiM6xhLu+ZJf3lHyQhvHvzCLgMnfU1bQN/E8tugW6Ggi5BN4Jtdy/5kqSRQHhDcR2QJmLTXfqIdHJzndJkADRQgZ2eigaAIKkJ4W5ny3zss3HxBiUZl/bMPUOvO2rSrEfuZZno8AAomJExO+fDk/Itlktho2GXhLeusFFWXp+T/ydHrVORzjVrHxR54faDS11G/V4CrT8hSWe7HGSxb+ZNo/tY3q9kJ9fox0tK+ClnKlybZIIabkVkVqU7icoQZaIyayUAUXDDI8kQHRgTQfWdrM7unyjtjUO62wSXWvi/d7zekmstW2x/xoYOh7nDp7AcHBwdVsJEfQj0dSEQsSe9NFlJRNdgoyZ4OPwuwQMWbwcguF7tcyl93VqU/5zC/v3T+TgcBhapH5Pw+vMkDQjieJnchjWElB/E2Ki//J6ChSJaORGG531McSERBCr+W94UUB3LcNqnQAJJc7gwWEecStElYnIBnL/Egc4cBONJ6mGnwYaZs987Q52iM+I/XWwRAJaff9nxKv0u520IBRYWSRuGktUjrWc0pOF9vj2MGfc/BWbXyUg9YM= 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)(346002)(376002)(39860400002)(366004)(136003)(451199021)(6666004)(41300700001)(7416002)(5660300002)(110136005)(36756003)(54906003)(2906002)(44832011)(8936002)(316002)(8676002)(6486002)(66476007)(66946007)(4326008)(66556008)(6512007)(478600001)(86362001)(38100700002)(186003)(2616005)(921005)(83380400001)(26005)(6506007)(13296009)(17423001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: oATVPp+2Ooiu5zwFXxra6XwPDnU3yqjmE5pmTmAUcvsgk+tfzfJac4n4eG6CWrPOUfhFQvoVKUfd+IHSkjW/31f1fEuFrDK+83QlcXTyUTQhWjNu/wtvOJxK6NXq4q2N5l5H50rlbS3Oe4MDAXWrZ7ERT3LuASYl69p5sK/lbIPMJO54ahUT0lRYGQl+4fIttW66f4AQeCLGwnzWe5Pf2RW/lmkFfNYAmsCEaVbpeZT1LUPxyFgSlzxaXMzYoPDGTQ4k26jZa1oEllRjL+aQ1NvBHcb8WAHXrdPyrTWVRcIYcUe1Msr4yyt6uxFBq0r1W5+C2ufHun0HjsUvLVrrYZelb/ru6J0ZA5Cr45RHQevyECsvJEu9zkYKqwy2OxOT1HNXA5gfvp5Sbace0AndWLsITeuCB2KztTOOOyM6DQeaRWkCkE+Dn96IhYCgtONSqzqQmaonCAZjSsBlJfRy2N66QVZkCgduWT4mAf1LdgFJd+96T1BBdfojtS3xb6kEeQUx1fR/b3HOPbPXIgVo+CoBVrFWOyHOJm3pIGMoE60td056LZ8n7/BL9cQ0QsM+SsFSKOMKpz623u9rgpDaLFMbDRCUh54wY3tH5W66P+jJh5FMCL/DbFQcuL3nmKUWSLdLnMc2VPnPuYj64QNEPesrKC38Fo0e2YxJL/jkBpDQVuSa8mRTWTGvC2pQrlkORlEVobIKMB6RCBuCr2YxSF8Ls9IpgdtILFllG7Dj2dwLh3eOiizAbUL94eKULWiYz4bxlXx/bNsYqCr7IHfX+735HVykH3KBQOXnvnAa+7UyqU3NiWh9TPXZZMG+zWJZDC3TFLGHMBOM83YpREtSaXDrJoYxYI6NQ7u1vossFxtB83pDOU8XQZWTi6Xu+CdWr2XXtLPvT5rDihdhYduN6Z+jz3x93vIbt+mZd/gMCqmrR+wewWEpnRlvWBe5XXlGbWDto50Yjbxt1uoEnLhWLPmsBE+ezcNohBbwTlohdFP3Zm7zAKhULcZc50gwiU8UJFquZRuDvjSx/tqlKggcmL9dNDsRfaI7NR/p8FLYeh7rQONR0Z0JD1gZ8j0PsBlMWnoUWjcwrh8fUgEXu026fO2sfuJlhdQOucLQP4TskGCc8PJ3tOlUMELnVMov5VVAfucCvLsm0CN2ORlK4yVBQgrVeJrGH+yXdQeDqoyg6+jNspNCayowTbQ5hLe6TslEDyqqyDE+MJMFjk9Z3faA3Ad2W5mxSwuui578mMpyt+oO9fzMdFiOuhaHkUdFbG90+fT4/dsUBJ6CWP49yaycZkn7ZKJDah5pexMiSyrRszesbo/XXn3sD7Sfx9tBzix8FmdJWFxbw5WWCuW+BsSVhOpMDOveHkFTM67VqNDGY2UK7lZ5K3J4nccp7QvEBmyOMr5sglR0x+ZvKZSx+MvyVTsE97KosrM8MZ222nbncdz43q1wd/awhTkpS3JIrsAociXs0l6HWostaJ0/m49y6D+ZCg701JUvTQ7TfmC6jWzVmtaVQXljy26xyfF1gomHkDI7c7uaKfv/FXBURfymBJDLPLaPNqc0ccqjXMpCngp7xwkd7dcuidVgkdHnXidt X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: 646df88c-cbd8-4ffb-6697-08db7df56b52 X-MS-Exchange-CrossTenant-AuthSource: HE1PR0402MB3497.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Jul 2023 07:48:42.7755 (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: eSgO6msrKJQvmhymPOnSyF2qw3SxDeNJ7qyEnu2e6r98/9rSNaq3SA7Un0z7xYsQM80rmw4O4+U03yi1jt2JoQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM9PR04MB8437 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 07:47:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13303292 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 1891A15BA for ; Thu, 6 Jul 2023 07:48:53 +0000 (UTC) Received: from EUR03-AM7-obe.outbound.protection.outlook.com (mail-am7eur03on2077.outbound.protection.outlook.com [40.107.105.77]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0B8621BD2 for ; Thu, 6 Jul 2023 00:48:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=bmn3pVvbX7XhkQiMTqEfz0tmHinIJFxvGAVD7JpssPZAGQH1zmpeYPSyj/eUQ0PW3zpeZD6ODdrtp7LRf+kQREAjhtTVV7MHO/u9IX8DdFD588SQMasnV53G2q/jAjLeDdhCSP4ue1ir3jzwNI5QNkwlEy4GL+144yzC0a0lfoiCV4jVCNkYOIE4pvMESUGCMsS9qhRODSA6Z/i59GM0/0Vets9tV6mOfp/DGAblCJGpMdooUM4PKyKH7BBtikz1wPr3+4tgVe4HVyYGy5BGluzDz89aASkux+ukrJq5R9wnk2dXun+fEHr4WMPU+S/30nmabbsywHItglhiNUtWKw== 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=VEdhO6ft78aA05rK0bfX9AQFg6VU4qJpd9Ppzk93jCNQXTM7WlYApFOP/WyUbnINxNZrR1LQItLS/Qy8eV/7tsHmIDNQutUnfx8pP52LIhlYKbJg2CvarWbzGPnm0E9NLlsKkoJ6U6KNuHYbqG5fIvxF3hQpl1EDa7Fauk+J2+PK1VHNLtUB0jdYKN0PWEfSqUcikCLszdKFbEXK6EhkiSC5ycU2K1Bjk0JDdqm2LHAZCCRl6S89bbuR0OFO9TSZG1MO50XNpgqRKuKUfGxPzYMND9yIivGwcUVaTK0LYE2d3RY05++qH0YVpXJuHE7Ug2N018egyEWCbZJkMtY+CQ== 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=o6ZzjcLdFI6gAm4Ph9xF543geZ4zVUcks/JeXf45MtkmwujTX1UWUqPZSJWgvu2F6ZQ9rJElOUV8rbrROdUDfpMPgBYf4iPkEJNyQewifdc5Zcdji6vvVdTxawCad1w2j6NhMPVn1JO2d914PCqTO+DIzLK5zWT+JL7TNZsHz3QPz0/FI3bUn20iRPq39zADw2aRYqbKjnSRVVGvedP+uaGSXnMIt9/ey/6ZCREywVyBOOScyTt+hy9SPL5T0shAdZSZOP0UqIHSny9TST5/dyVYu3a29JxHGPPwwxYRAsqyJk47CkbY7ljIGrH/hLW2SGrmPc9wKZlZx1Di7Irwfw== 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 AM9PR04MB8437.eurprd04.prod.outlook.com (2603:10a6:20b:3dd::11) 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 07:48:50 +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 07:48:50 +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 v2 7/8] selftests/bpf: add two mptcp netns helpers Date: Thu, 6 Jul 2023 15:47:31 +0800 Message-Id: <284f75cccd4e848f17b54bec67b6889fbcde1a35.1688629124.git.geliang.tang@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: References: X-ClientProxiedBy: SI2PR01CA0018.apcprd01.prod.exchangelabs.com (2603:1096:4:191::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_|AM9PR04MB8437:EE_ X-MS-Office365-Filtering-Correlation-Id: aeb789f0-984c-4714-302c-08db7df56fc1 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: f9JtNWV/XipMqkpyfpDCkZgujtVzlBLdxCR5h7JCEqu2IJZdrNI+hotPr0HYc9rPC0Bf2Vx/uHWKKQtxQSCfOmsJ6ZKONbC8Ug8Z57DtAzB5y9x5fTKWvWFBcFSunlZUxhNbocZdp1LKMcewX/IJ0i/Vk8uaaChI5OaMojmHBFMBEOuG7qxj/AGMw6VJUVcehkRj4BYJBuYFnGZcfnIbCswgXmIPAEfpsbms6p4TTawp/cZqZoa0G3KSrs+NP7uEazBDGzjQlAm6UcIQEhw7JHl6JymFN09K+jjERzuUmRHTGJx4gZudB39Mlf3mIM27FAdY00vU804bcNn+g6L4Ila7W2XxJl/UkeAo3uCB7KNjWO1ZNCYcdWNo4SWlrm9NbVZrGLU8oPhJ5mTE817OaA7GbeKU9SU3bTuxaFd58cPLKi5MAGao2cCGz964c6Hit/37pq+xNazBK/okjKOcu28R4Ql+b8+u0FMr7VPvF7ckpRVFSxLgeyAKK2aJA08raqWWTMYQ7NZfLqdhqgJ+Ubqv63Ct2lf+ZlfPb3uQDmO4rCitfawUKfcu0DnvUIqA9gitfZFB+GHFW2TSjg0siEk2JgEGj780leeiio7PAAALiPPjOVbpcYYaIF7N7+eF 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)(346002)(376002)(39860400002)(366004)(136003)(451199021)(6666004)(41300700001)(7416002)(5660300002)(110136005)(36756003)(54906003)(2906002)(44832011)(8936002)(316002)(8676002)(6486002)(66476007)(66946007)(4326008)(66556008)(6512007)(478600001)(86362001)(38100700002)(186003)(2616005)(921005)(83380400001)(26005)(6506007)(13296009);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: +cVxcqFrTqkqqWZ1/VOtbUv6HSy0SGbCp3g4C2uA4cpRfVOOvTaOvPUK1acOXUOukIZPxJgTTonH74HDUGka2zsf4Y+ufkyZORgzF4pMHpxxVIvIWh3lrx9dbuPIzPqcaNiCzEGzbXJQ1QUloqQZvjSz2MCwKigsNA14O3p+4PthThlGYsDjKjsS7M7yPMFWjnVjMXn09s106qtEwgaSuT9Xqihx22Rdx/yzw6jW91Z6d8CTMrWS27FjUfXGCO3PQ3gzz+acUNRvFpA39rOpyArLu7Hppn0mi40p7ZLVSl1MroXmDNgvRnIvjGVJRTE1kHZ1iK779pxQJbj9aC2tgUPAXwfPxiQLT3kRpXhLPXwNbyHk6bZORn+95AVozxYK1jyicZ5z94y1lGkYC3pshMYJLn6sCFvs5x2MfMjf5gcnNf4D4E3DVP+NqB+Dl2fjvzjsVYN81gOCia8Fk+m1hOAJiC7OHnqTkbTaP1yIOGa4txBPbc19lHaRZFIE+RG7jt4D/WO0dD9DhUYsZ6E2CbWWTeqx+4ZUJ+f1asmTAO4Zg9RYrHgYiUd1+7atzQAIa+f4CPwq6Nb09u+sU6kaDN0tpALBc2wdr2JOiwJYEM/7wTCYJK6AquWCheJ8EYZWEn3BCIqR+lzmtARS8Em1I2aFin69n+Z6+3EY8PBU3RAdipcxS6hRyvpHGxN/z0yAcvnIiFdWy+f7qmQc0hp4H751Q+zm2R2Qt3ODc0sw2Aa94rD8wWukd0p2AhBng67y4j4O5ZiTuVBNBiVR1vTAOaIG6lf1u0eZvEDgKC371bSGOm8+yLP1FKvj06KNVBWf1/wNqv6MsOrT+y5QG7tQ6iuiYIYuM9izcNtGQy0Ay8A+jEcx67EI4wqYLOZ8iFyBIkJpMTM1ah7NmwNIk8ZhfV1sufyKvsrN3bHOtvYr2TIgAHYaeTBatB/zXg+H37VNLj0lnWmgeI3EPX9UbSpM/19TKVwVu4yOAnkqLhrdMj3afUUAjCLCGa6Ki8tu2MRl+ilTXm3xmNpbn40FcVK+bfdKFJiFETjgLo5IPY9NmWJkC3V0PAy7L4kQ3mmkUVGUZ40SeWNisXmFa1eVYs7VyuAwUwKJl6z16EAmQqJXh/ca3GYMJDm/3aGLeqJ9cMPamtF1E2ZtXkXklHpIrAxYu49iGf2NNAMIBcNTsFt/saVz5wW275Hh7Wkh1P8QTvJVicy6/0j+SpkPsxXTdkFCwpwpYmUGwJDhm4sSuV7Uhbh6jPpAM85iTWzF60+uSgMQw7kdzUP/DfogZ+ZVoGcsAtEdwlvCaKAZ8pZBCzb32ulJMS3K8EC3gilHiFMZmdqv9xwVNxTrMHkCEqpmDgKX1QG7Gm9EnUiAY4YEYTR6uswy2MGD9gfaatu4gtvYNS0CK8m2ti0J05IZFv7IUvgkEjypuncp8HcWfManvdssPzAaR8tCrQfTb/GHIR4G0VehcrFyh6aBI7QkjuJu/0z1CkRajdaVsyg0N9Vb2xsqOgzlDe3q3s99VjI0Bj1fJz+evHmVNkbyC++prBrIw6jLw9YjrY5Mr2ITteYbL0+ATG2BbStw5caYhEWRh3C0YaC+ X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: aeb789f0-984c-4714-302c-08db7df56fc1 X-MS-Exchange-CrossTenant-AuthSource: HE1PR0402MB3497.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Jul 2023 07:48:49.9691 (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: MXdAAwtx/tMa7tW1CI8Ns7O6W4H8eHuNZ9lY13GJAjWB1rmdYdCdJ8BFmqO32AahpXAVsI/UQ47LHce2xFFFkw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM9PR04MB8437 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 07:47:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 13303293 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 055F315B8 for ; Thu, 6 Jul 2023 07:49:01 +0000 (UTC) Received: from EUR03-AM7-obe.outbound.protection.outlook.com (mail-am7eur03on2041.outbound.protection.outlook.com [40.107.105.41]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9380E1BD9 for ; Thu, 6 Jul 2023 00:49:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=f6tOJkCTc/NJf0Jh5IpYpC7A04XObOh5MBaT93Xt3JR+SNbyamJDU6ne9N6hUlEKRaPUYqaI+ABhPaPspXD2GPFlwnBSL9SUUHI94XtYer0VC9FqXEmMmBacb8rHrR2wclpWe26ulwirpdxj0QKzw5v51vu6P9hkqxmd+brMwJ/QvIMsqca14d0tQs7gmvg9SRBNTHfurMMIpNzvPC9pSfSEOi90rO5O/0eoKPzolAFt9GlJEvxTtagEIogEqvWmVT+Q6SVynrEuw4HJ5BSwXLAgvRJ0A0+da8Akz3/DLQbIZQQ6Gdyl5WZOhvrx/+l/kfW3iz7k23tF6ESKXNHYOQ== 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=OhTecHCpsKJn/gFD/6EQBh5NMIiNalawFHaXgjAzXvA=; b=iQZXTFoMx3J8+V34k/UxEq4YR5TWmooU4MPlqpzOiYMy7MPOm3HqIrd9CC0aIV7vLiC1E4in8gnsvs89DubZJDrbUdN2TI1ctOSA7Ijn3GsSJs1A2n3jmKU5vptElZRR5PImxOQJlpKNdanGKecuUrTKAgAe1y0fJvorDukSSmsmefqVeLtTGhfx31jdwPw6JMthjnMhvUl/kJtTphQBmlNMylJnNSArom90yvybj0Zx8dsheMCqLCHLiMYHnbX6fou5/hVRz2VqAsGX8/hIz9zM0wWIMsimFbT7rSks4n8mxlVooHfubDv63BfkTyJEtvWnEx1nAw7/NSL8L2AI2w== 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=OhTecHCpsKJn/gFD/6EQBh5NMIiNalawFHaXgjAzXvA=; b=nKh6lzVCcN75T5qqu0kEsCd0cVBBgItwrcs3rCOlgCsHI/tXNzqAbJFKlDxdkYH7POxkMQ2GFUnXwBztmkrcAjsBI13i7mOmgLdeBWQYCXxBs6kzH+ZDLXPb0z8p1uctFJsW87Tuy3DmmHIag0Uyv+H23N9vbY4Qwb561PNjVRZsG26mIFEnveMqFcR7MVwseusESypjMnSF0I/xJWgf7PYSuOlsktsXdMmaylCbNxm6HoSBDkphRpB3e0LZu9CCH2fUmLQ5lK9Vu5udO+OT3UkceBcY97oYoM4fUY9ZxF/b6TO01Gyah40LXu7oMx89waYnPUSN570bruakWqVhsw== 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 AM9PR04MB8437.eurprd04.prod.outlook.com (2603:10a6:20b:3dd::11) 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 07:48:57 +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 07:48:57 +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 v2 8/8] selftests/bpf: Add mptcpify selftest Date: Thu, 6 Jul 2023 15:47:32 +0800 Message-Id: <5c88e528d4be098c2fa73ba49bc1b20615b77a53.1688629124.git.geliang.tang@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: References: X-ClientProxiedBy: SI1PR02CA0001.apcprd02.prod.outlook.com (2603:1096:4:1f7::15) 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_|AM9PR04MB8437:EE_ X-MS-Office365-Filtering-Correlation-Id: 657b821e-a167-404f-fbb0-08db7df57410 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: MI9fGyjVqZVhs3f8PREfr62bV/pbK0coU3p1TX6p3ZCOoIGksXPs3lRQ1MBEj/eVRehBFFfOpnVZ+cY1iGtr+mrlQDpgbmoaofIrI33QCVCjkInCpz2vmhO6cbYj9NvSVueB1+jmuY3Ndi4oHRdzcmo3KkOahtqE1G0jSsNnDfMU9IdWOOJ9PZgtlV8RgxLxqoHXOL5KFUh/SPoLbuPuE12F8/zljS7dpYuSlx9z3oT2S1sFpM1zVbbukYaw/DvryN6H4P6Jaj8hlduAcw9fp2QCaj3ZojTmoDkZGLTQfcr4373zIvgGYrJhTPMI1Cl0vcYSNh/TpXXzBwRMGIypM008Uh8bfa9xVXPuy2k4qW7fkt9kJbgWyJ810oWxNm3iCSreRh9hNEuxigbfCQLIACyxwHAr1Gble4BC4ZKOmvi7S4nIxdfkfDfwhaRpS8p2PXYe836ZgNdiwQgtVcx/ZWhD7psn9IdleseKCbM2jiN9i75qnHI+XOnPeYs7j2AYRRz9uc1RAkakGYW/D1w21w3veSOofaZGH+0iTEwkDn9KXz473TyTy+Wm36BrZ1CCqzzlUAhSUHOUiB9z82rLo9Y8PUfR1KVmXRUQZEoy1DWZ+38NMUIc0zOs+LXdynSr 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)(346002)(376002)(39860400002)(366004)(136003)(451199021)(6666004)(41300700001)(7416002)(5660300002)(110136005)(36756003)(2906002)(44832011)(8936002)(316002)(8676002)(6486002)(66476007)(66946007)(4326008)(66556008)(6512007)(478600001)(86362001)(38100700002)(186003)(2616005)(921005)(83380400001)(26005)(6506007)(13296009);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: ezdmpZ03wBjy0DZrPajY/ZZycKZkdy6TC0++MEdZhERQX1/sbmYJaH9oIppOKpB+Z9WdpqRga6Py9v9b3ig5zx3g6Occh8s4mF319sd6S9qFc4jvqkDu0uOgwHX0A/IbNLp8HkwZG7QGC9u841qLWos7LQucVp/mWGvazma7bUSj8aH2xig5+oMQuxn9mAoxHgxnyY8nWLlPhN/v6LqqKwKzEkiuL7XgxFpEuKsF3FL/P/zS1hYyHDW+qjUDOdqbtkrWvrFo/fTOEqOV3aV5WnfTARzx3klC1ctQKktSmf+DjJr62JjzKPl6xVZo0Q9fZkw5qafhBEHaajaStaPqnMUbODCaQ1RV/AQ3yTRE9TQsEJ8gN/mu/eiJ9MQxcF+Ln2RUH53dbaq/t2w6coVCcWNsIVUndYgD1GmKmVZXULvSoa9mM+t+M1MgW7FdD0gs2v4P/az6CwS5KoQ/qxI567yySFx0vGVjxmDaUQDPybpe35glqcnDlx7fheCq89HPWGyJhqXCvf/GOoOp00MovrQWmuQH0SAhavIeOy/PWGoFBT7/rnKXYnWNbhxEHwj4xT+DMLWIrxonYlqt8mNSZf+xiCf8EQaVDHMO2mqPJmuVEfcJW5B5NDTlimBjWSjyKqP8neWdkj0CLolyh+1nTBdkyqh3JlhQwmAqlseunrmBzSJyJor2/hZBDNYVpgxkoRRVzNKblMTn/RU+ehJ4gxABmhuJkDROMXBH8CsDRhQdgQXyk8DTmL2FwEDC1Wxvzykqa+Sw5wLocxdZKZUe/y0tjDepvIY8Ibng122RFAhsneyKbw0+ie/utcnmE6cIADXDQ8M8F1D+nc6yqcOHQNxaBLRb8670vOKtrrMFWCj3aI/D3NQ2F+VgwWNDZC7q0u9l3appB3JH4WR3utoDQ6Rz0sZLm/3/R6kaoCNEA35xFdjibmLa2DSZmXKJal+T62y7/nva5BKGmIb4MnTsazIFy92kIBM6yG2wo7dnJ6l98esRbNBg4+kOG2XE3uk5dKY/Qu0O9cW44f6ojMA2QbZdziSZStd4t7LYO0FdIGHBSf3KK4lSmviFRNfdmufLxdiokQfI/1QZtZvzLz1ISrbaWbMW7mMegTWJRsEOteTdrknovAylS9KAEMlM/bMVCXYnUwe6U8ndzClWH2fa7Kh0IWPTwUbvc2Qd/HcUBdvGHJg55P3hG0BdrARHrUbdSW88DOLtUK8lDJ7RyXKhfiuGXsHEMfzK4ZM8m1kuFgcGinzm1Q3zyeLNkI13hTwL05lRyP6X3yr6yQhdVZJuJqwGjc8zPN8BTpBWU9oO/3r5h+96ayLe2Dl7V0/e3Opg4XQSpHkPY81afWxF2vLdy9X7k/eBDGOJcdB59tXz0tGE7YsNmjmU/hlIti7Rb0ZUAko1/gPQls5hGdeJmx6MKjcmS7H/qMMrFDqealhsaBzYGCNKR6Sr6Cb1DDf9jYJDodiCfRUstIS/ALYwNsuzzXqBPyZwsmgPwJf1V72dZSkzJR07eOv2CHj40lW9CrACcWDT4jfVGZLLMPlrhu/WtqjKqpc5U/YFMKbcnHPZlQv5wzAVHKA6ZZswVv2JnYgh X-OriginatorOrg: suse.com X-MS-Exchange-CrossTenant-Network-Message-Id: 657b821e-a167-404f-fbb0-08db7df57410 X-MS-Exchange-CrossTenant-AuthSource: HE1PR0402MB3497.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Jul 2023 07:48:57.3873 (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: JpvcaSk4rbwv24KBL/1yujjFGL+RhyRDjxtg05YfQ5rZCLxB82axW9qm3vZnwU2F9qMIq2jV7QjcRnVdzWOyeg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM9PR04MB8437 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..de05140fe638 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 '%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(); }