From nobody Mon Feb 9 09:33:42 2026 Delivered-To: wpasupplicant.patchew@gmail.com Received: by 2002:ac4:a898:0:b0:4b1:af33:c52d with SMTP id z24csp2372905pid; Wed, 20 Apr 2022 15:25:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwWEjUC95zsagGgOp4ed0iFXQAjLfqH659IaJNP6Ew8id9eJ4+1HiZ29zvwrAYP9sCuq7Wm X-Received: by 2002:a2e:320f:0:b0:24d:cd53:3bc6 with SMTP id y15-20020a2e320f000000b0024dcd533bc6mr5793799ljy.516.1650493522397; Wed, 20 Apr 2022 15:25:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650493522; cv=none; d=google.com; s=arc-20160816; b=e/kQHyFSBn6GRoHlBgSGWd0D8hXMI23YpLszvV4JelFv/q9/vrNSrYI1OdwaX9Rb25 lgwUKssB6A+HnHR+lmACx6aA0/CwE5ALzlsScuYNjXxnJ9pKn7K6v6+VQDN+S6DNy7pS rzN04XkooVS3jM7s6xxKwx4fkAPpGNCgN233/9TUPncx4DYrmMdCnJ8XbojCZFVtq7gd 5uQFOtCMDwnKShucmLUsizMMpZzJKosHKuMDqkw5Q27m01A44MR5HCv4R1DvO5pmon0j SSOkw/e07SC+c2r3fyj0Itb8tQbvB4KCnMTxvUSXzjTYKfSCGb/5+C5U7dYXCItD1wMM rodQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=NIqk/8lQ3aA1b/X0wOjWJ5z6hkibG+fGq0BKWwJ4mtA=; b=kNTnr02BXI8N40LOqSb8t7wSQCsmjTwd5qjIBRk+7xgHgO8T1aL5t56Ma9YYu+2NLJ QguVl60m0QP5ZSZet9t0IgWCJEZNYju05tSVf269dd7b+cZmdScTO7a5BnRNC03G6hNB tNMHeZ4q75h++rxNPr3g25lG9LJBomEycx4KTBdBOiNqHJ1bgW+zzd/ECFSzB400+U4Z DBMANM2CBH2l6mXWnPsh4q5kdqqHznEjlECVhoDrUvmnNw6eEd7oJp8/so+Kp8ecKYdN KR0Yx97kUW38v6Omkr8/scSiGiDLS3ZH9fgj/Y0NmJYSv1YkdwvU0pG162xu5U9Rg6NF hNOw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=lj3LOF+G; spf=pass (google.com: domain of mptcp+bounces-4812-wpasupplicant.patchew=gmail.com@lists.linux.dev designates 2604:1380:4040:4f00::1 as permitted sender) smtp.mailfrom="mptcp+bounces-4812-wpasupplicant.patchew=gmail.com@lists.linux.dev"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from da.mirrors.kernel.org (da.mirrors.kernel.org. [2604:1380:4040:4f00::1]) by mx.google.com with ESMTPS id x7-20020a2e9c87000000b0024c83e314e5si3289775lji.130.2022.04.20.15.25.21 for (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 20 Apr 2022 15:25:22 -0700 (PDT) Received-SPF: pass (google.com: domain of mptcp+bounces-4812-wpasupplicant.patchew=gmail.com@lists.linux.dev designates 2604:1380:4040:4f00::1 as permitted sender) client-ip=2604:1380:4040:4f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=lj3LOF+G; spf=pass (google.com: domain of mptcp+bounces-4812-wpasupplicant.patchew=gmail.com@lists.linux.dev designates 2604:1380:4040:4f00::1 as permitted sender) smtp.mailfrom="mptcp+bounces-4812-wpasupplicant.patchew=gmail.com@lists.linux.dev"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by da.mirrors.kernel.org (Postfix) with ESMTPS id F0F5F2E0CE2 for ; Wed, 20 Apr 2022 22:25:19 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 307433D6D; Wed, 20 Apr 2022 22:25:18 +0000 (UTC) X-Original-To: mptcp@lists.linux.dev Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) (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 4F9B67A for ; Wed, 20 Apr 2022 22:25:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1650493516; x=1682029516; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=7JGsPMfEIizl3uiYOkvij3X2qHRKl3rpmk92jGiEIgA=; b=lj3LOF+Grbbd4asy2dZxYczEopn1qC+NzFGx59xyFws/tSwqY9tzwCfM 9cHSK24zsEYuIKXLfPrd3c+AkidKGI1rhNY9FfFy7ekXDWWVICZIKpoTP yppA7KFZyiJK5d4kcYCuo+jAyT49A6qZE0Ywa/0xGkn38LEf/6+Pr7xJL x3Bd8bc4OrxN/AiOq1QIa4M65lNFuN+jFjsALVWcRmf2Upyv25bT7g5mt U0tpvDR0xoQipTBJ4/+5N1+70Y9Az5OGW9S9ncihVt1qfXx+kLwXd7+Ba g4OIvwWloOYKK+6s8e6CQ3Z/feK0yxKfkRtdVo91lo29L9rbDBr4VaaD5 Q==; X-IronPort-AV: E=McAfee;i="6400,9594,10323"; a="289277586" X-IronPort-AV: E=Sophos;i="5.90,276,1643702400"; d="scan'208";a="289277586" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Apr 2022 15:25:15 -0700 X-IronPort-AV: E=Sophos;i="5.90,276,1643702400"; d="scan'208";a="555422587" Received: from mjmartin-desk2.amr.corp.intel.com (HELO mjmartin-desk2.intel.com) ([10.209.100.38]) by orsmga007-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Apr 2022 15:25:14 -0700 From: Mat Martineau To: netdev@vger.kernel.org, bpf@vger.kernel.org Cc: Geliang Tang , ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, mptcp@lists.linux.dev, Nicolas Rybowski , Matthieu Baerts , Mat Martineau Subject: [PATCH bpf-next 2/7] bpf: add bpf_skc_to_mptcp_sock_proto Date: Wed, 20 Apr 2022 15:24:54 -0700 Message-Id: <20220420222459.307649-3-mathew.j.martineau@linux.intel.com> X-Mailer: git-send-email 2.36.0 In-Reply-To: <20220420222459.307649-1-mathew.j.martineau@linux.intel.com> References: <20220420222459.307649-1-mathew.j.martineau@linux.intel.com> Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Geliang Tang This patch implements a new struct bpf_func_proto, named bpf_skc_to_mptcp_sock_proto. Define a new bpf_id BTF_SOCK_TYPE_MPTCP, and a new helper bpf_skc_to_mptcp_sock(), which invokes another new helper bpf_mptcp_sock_from_subflow() in net/mptcp/bpf.c to get struct mptcp_sock from a given subflow socket. Co-developed-by: Nicolas Rybowski Signed-off-by: Nicolas Rybowski Co-developed-by: Matthieu Baerts Signed-off-by: Matthieu Baerts Signed-off-by: Geliang Tang Signed-off-by: Mat Martineau --- include/linux/btf_ids.h | 3 ++- include/net/mptcp.h | 6 ++++++ include/uapi/linux/bpf.h | 7 +++++++ net/core/filter.c | 17 +++++++++++++++++ net/mptcp/Makefile | 4 ++++ net/mptcp/bpf.c | 22 ++++++++++++++++++++++ scripts/bpf_doc.py | 2 ++ tools/include/uapi/linux/bpf.h | 7 +++++++ 8 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 net/mptcp/bpf.c diff --git a/include/linux/btf_ids.h b/include/linux/btf_ids.h index bc5d9cc34e4c..335a19092368 100644 --- a/include/linux/btf_ids.h +++ b/include/linux/btf_ids.h @@ -178,7 +178,8 @@ extern struct btf_id_set name; BTF_SOCK_TYPE(BTF_SOCK_TYPE_TCP6, tcp6_sock) \ BTF_SOCK_TYPE(BTF_SOCK_TYPE_UDP, udp_sock) \ BTF_SOCK_TYPE(BTF_SOCK_TYPE_UDP6, udp6_sock) \ - BTF_SOCK_TYPE(BTF_SOCK_TYPE_UNIX, unix_sock) + BTF_SOCK_TYPE(BTF_SOCK_TYPE_UNIX, unix_sock) \ + BTF_SOCK_TYPE(BTF_SOCK_TYPE_MPTCP, mptcp_sock) =20 enum { #define BTF_SOCK_TYPE(name, str) name, diff --git a/include/net/mptcp.h b/include/net/mptcp.h index 0a3b0fb04a3b..5b3a6f783182 100644 --- a/include/net/mptcp.h +++ b/include/net/mptcp.h @@ -283,4 +283,10 @@ static inline int mptcpv6_init(void) { return 0; } static inline void mptcpv6_handle_mapped(struct sock *sk, bool mapped) { } #endif =20 +#if defined(CONFIG_MPTCP) && defined(CONFIG_BPF_JIT) && defined(CONFIG_BPF= _SYSCALL) +struct mptcp_sock *bpf_mptcp_sock_from_subflow(struct sock *sk); +#else +static inline struct mptcp_sock *bpf_mptcp_sock_from_subflow(struct sock *= sk) { return NULL; } +#endif + #endif /* __NET_MPTCP_H */ diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h index 9ef1f3e1c22f..785f2cb15495 100644 --- a/include/uapi/linux/bpf.h +++ b/include/uapi/linux/bpf.h @@ -5143,6 +5143,12 @@ union bpf_attr { * The **hash_algo** is returned on success, * **-EOPNOTSUP** if the hash calculation failed or **-EINVAL** if * invalid arguments are passed. + * + * struct mptcp_sock *bpf_skc_to_mptcp_sock(void *sk) + * Description + * Dynamically cast a *sk* pointer to a *mptcp_sock* pointer. + * Return + * *sk* if casting is valid, or **NULL** otherwise. */ #define __BPF_FUNC_MAPPER(FN) \ FN(unspec), \ @@ -5339,6 +5345,7 @@ union bpf_attr { FN(copy_from_user_task), \ FN(skb_set_tstamp), \ FN(ima_file_hash), \ + FN(skc_to_mptcp_sock), \ /* */ =20 /* integer value in 'imm' field of BPF_CALL instruction selects which help= er diff --git a/net/core/filter.c b/net/core/filter.c index 7b1867f1f422..4081c55f6f78 100644 --- a/net/core/filter.c +++ b/net/core/filter.c @@ -78,6 +78,7 @@ #include #include #include +#include =20 static const struct bpf_func_proto * bpf_sk_base_func_proto(enum bpf_func_id func_id); @@ -11279,6 +11280,19 @@ const struct bpf_func_proto bpf_skc_to_unix_sock_p= roto =3D { .ret_btf_id =3D &btf_sock_ids[BTF_SOCK_TYPE_UNIX], }; =20 +BPF_CALL_1(bpf_skc_to_mptcp_sock, struct sock *, sk) +{ + return (unsigned long)bpf_mptcp_sock_from_subflow(sk); +} + +static const struct bpf_func_proto bpf_skc_to_mptcp_sock_proto =3D { + .func =3D bpf_skc_to_mptcp_sock, + .gpl_only =3D false, + .ret_type =3D RET_PTR_TO_BTF_ID_OR_NULL, + .arg1_type =3D ARG_PTR_TO_SOCK_COMMON, + .ret_btf_id =3D &btf_sock_ids[BTF_SOCK_TYPE_MPTCP], +}; + BPF_CALL_1(bpf_sock_from_file, struct file *, file) { return (unsigned long)sock_from_file(file); @@ -11321,6 +11335,9 @@ bpf_sk_base_func_proto(enum bpf_func_id func_id) case BPF_FUNC_skc_to_unix_sock: func =3D &bpf_skc_to_unix_sock_proto; break; + case BPF_FUNC_skc_to_mptcp_sock: + func =3D &bpf_skc_to_mptcp_sock_proto; + break; case BPF_FUNC_ktime_get_coarse_ns: return &bpf_ktime_get_coarse_ns_proto; default: diff --git a/net/mptcp/Makefile b/net/mptcp/Makefile index e54daceac58b..168c55d1c917 100644 --- a/net/mptcp/Makefile +++ b/net/mptcp/Makefile @@ -10,3 +10,7 @@ obj-$(CONFIG_INET_MPTCP_DIAG) +=3D mptcp_diag.o mptcp_crypto_test-objs :=3D crypto_test.o mptcp_token_test-objs :=3D token_test.o obj-$(CONFIG_MPTCP_KUNIT_TEST) +=3D mptcp_crypto_test.o mptcp_token_test.o + +ifeq ($(CONFIG_BPF_JIT),y) +obj-$(CONFIG_BPF_SYSCALL) +=3D bpf.o +endif diff --git a/net/mptcp/bpf.c b/net/mptcp/bpf.c new file mode 100644 index 000000000000..535602ba2582 --- /dev/null +++ b/net/mptcp/bpf.c @@ -0,0 +1,22 @@ +// SPDX-License-Identifier: GPL-2.0 +/* Multipath TCP + * + * Copyright (c) 2020, Tessares SA. + * Copyright (c) 2022, SUSE. + * + * Author: Nicolas Rybowski + */ + +#define pr_fmt(fmt) "MPTCP: " fmt + +#include +#include "protocol.h" + +struct mptcp_sock *bpf_mptcp_sock_from_subflow(struct sock *sk) +{ + if (sk && sk_fullsock(sk) && sk->sk_protocol =3D=3D IPPROTO_TCP && sk_is_= mptcp(sk)) + return mptcp_sk(mptcp_subflow_ctx(sk)->conn); + + return NULL; +} +EXPORT_SYMBOL(bpf_mptcp_sock_from_subflow); diff --git a/scripts/bpf_doc.py b/scripts/bpf_doc.py index 096625242475..d5452f7eb996 100755 --- a/scripts/bpf_doc.py +++ b/scripts/bpf_doc.py @@ -633,6 +633,7 @@ class PrinterHelpers(Printer): 'struct socket', 'struct file', 'struct bpf_timer', + 'struct mptcp_sock', ] known_types =3D { '...', @@ -682,6 +683,7 @@ class PrinterHelpers(Printer): 'struct socket', 'struct file', 'struct bpf_timer', + 'struct mptcp_sock', } mapped_types =3D { 'u8': '__u8', diff --git a/tools/include/uapi/linux/bpf.h b/tools/include/uapi/linux/bpf.h index 9ef1f3e1c22f..785f2cb15495 100644 --- a/tools/include/uapi/linux/bpf.h +++ b/tools/include/uapi/linux/bpf.h @@ -5143,6 +5143,12 @@ union bpf_attr { * The **hash_algo** is returned on success, * **-EOPNOTSUP** if the hash calculation failed or **-EINVAL** if * invalid arguments are passed. + * + * struct mptcp_sock *bpf_skc_to_mptcp_sock(void *sk) + * Description + * Dynamically cast a *sk* pointer to a *mptcp_sock* pointer. + * Return + * *sk* if casting is valid, or **NULL** otherwise. */ #define __BPF_FUNC_MAPPER(FN) \ FN(unspec), \ @@ -5339,6 +5345,7 @@ union bpf_attr { FN(copy_from_user_task), \ FN(skb_set_tstamp), \ FN(ima_file_hash), \ + FN(skc_to_mptcp_sock), \ /* */ =20 /* integer value in 'imm' field of BPF_CALL instruction selects which help= er --=20 2.36.0