From nobody Fri Oct 25 19:27:48 2024 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 CB751198B0; Mon, 21 Aug 2023 22:25:23 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2B6FEC43397; Mon, 21 Aug 2023 22:25:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1692656723; bh=KL6HAUlN74y/BKjFAEiuc9d9I/kw0+Ps2Yd9sgSgLik=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=OYfDdc+Z6RVmNE3x8h1PGcMSPI79LGfVcW2wiltI+R/36z8gsxtsurYwakpei3VXG akN7zeSg7LwlpXmVTD1cdHrg5ac7h48uChKLBgV/kJnGUcoTYnurLAsi3/Imj0L6XX 1T8k7AvsmHds+qNp2K0y9zKpE2s63D0KBa4PnEt9pK19D7su5bBe3cqe4hqIDAii34 kfgyFdreFHh0n9PuKyNkqofCHYfTYEoBNStoBSUvSV7QGHoWKfOLWCHK2hscTfL67a 4dxBEpU2QOCBYAEWB1+V/4VxZZw+8LgS0BZlOdn4CIxZbWuuc7HJKukYZmOLACKtmg xsHryAJzrP50w== From: Mat Martineau Date: Mon, 21 Aug 2023 15:25:14 -0700 Subject: [PATCH net-next 03/10] mptcp: add struct mptcp_sched_ops Precedence: bulk X-Mailing-List: mptcp@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20230821-upstream-net-next-20230818-v1-3-0c860fb256a8@kernel.org> References: <20230821-upstream-net-next-20230818-v1-0-0c860fb256a8@kernel.org> In-Reply-To: <20230821-upstream-net-next-20230818-v1-0-0c860fb256a8@kernel.org> To: Matthieu Baerts , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: netdev@vger.kernel.org, mptcp@lists.linux.dev, Geliang Tang , Mat Martineau X-Mailer: b4 0.12.3 From: Geliang Tang This patch defines struct mptcp_sched_ops, which has three struct members, name, owner and list, and four function pointers: init(), release() and get_subflow(). The scheduler function get_subflow() have a struct mptcp_sched_data parameter, which contains a reinject flag for retrans or not, a subflows number and a mptcp_subflow_context array. Add the scheduler registering, unregistering and finding functions to add, delete and find a packet scheduler on the global list mptcp_sched_list. Acked-by: Paolo Abeni Reviewed-by: Mat Martineau Signed-off-by: Geliang Tang Signed-off-by: Mat Martineau --- include/net/mptcp.h | 21 ++++++++++++++++++++ net/mptcp/Makefile | 2 +- net/mptcp/protocol.h | 3 +++ net/mptcp/sched.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++++= ++++ 4 files changed, 81 insertions(+), 1 deletion(-) diff --git a/include/net/mptcp.h b/include/net/mptcp.h index 3c5c68618fcc..fb996124b3d5 100644 --- a/include/net/mptcp.h +++ b/include/net/mptcp.h @@ -96,6 +96,27 @@ struct mptcp_out_options { #endif }; =20 +#define MPTCP_SCHED_NAME_MAX 16 +#define MPTCP_SUBFLOWS_MAX 8 + +struct mptcp_sched_data { + bool reinject; + u8 subflows; + struct mptcp_subflow_context *contexts[MPTCP_SUBFLOWS_MAX]; +}; + +struct mptcp_sched_ops { + int (*get_subflow)(struct mptcp_sock *msk, + struct mptcp_sched_data *data); + + char name[MPTCP_SCHED_NAME_MAX]; + struct module *owner; + struct list_head list; + + void (*init)(struct mptcp_sock *msk); + void (*release)(struct mptcp_sock *msk); +} ____cacheline_aligned_in_smp; + #ifdef CONFIG_MPTCP void mptcp_init(void); =20 diff --git a/net/mptcp/Makefile b/net/mptcp/Makefile index a3829ce548f9..84e531f86b82 100644 --- a/net/mptcp/Makefile +++ b/net/mptcp/Makefile @@ -2,7 +2,7 @@ obj-$(CONFIG_MPTCP) +=3D mptcp.o =20 mptcp-y :=3D protocol.o subflow.o options.o token.o crypto.o ctrl.o pm.o d= iag.o \ - mib.o pm_netlink.o sockopt.o pm_userspace.o fastopen.o + mib.o pm_netlink.o sockopt.o pm_userspace.o fastopen.o sched.o =20 obj-$(CONFIG_SYN_COOKIES) +=3D syncookies.o obj-$(CONFIG_INET_MPTCP_DIAG) +=3D mptcp_diag.o diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h index cbf9a9e176b2..985e8f86668d 100644 --- a/net/mptcp/protocol.h +++ b/net/mptcp/protocol.h @@ -655,6 +655,9 @@ int mptcp_subflow_create_socket(struct sock *sk, unsign= ed short family, void mptcp_info2sockaddr(const struct mptcp_addr_info *info, struct sockaddr_storage *addr, unsigned short family); +struct mptcp_sched_ops *mptcp_sched_find(const char *name); +int mptcp_register_scheduler(struct mptcp_sched_ops *sched); +void mptcp_unregister_scheduler(struct mptcp_sched_ops *sched); =20 static inline bool __tcp_can_send(const struct sock *ssk) { diff --git a/net/mptcp/sched.c b/net/mptcp/sched.c new file mode 100644 index 000000000000..c5d3bbafba71 --- /dev/null +++ b/net/mptcp/sched.c @@ -0,0 +1,56 @@ +// SPDX-License-Identifier: GPL-2.0 +/* Multipath TCP + * + * Copyright (c) 2022, SUSE. + */ + +#define pr_fmt(fmt) "MPTCP: " fmt + +#include +#include +#include +#include +#include +#include "protocol.h" + +static DEFINE_SPINLOCK(mptcp_sched_list_lock); +static LIST_HEAD(mptcp_sched_list); + +/* Must be called with rcu read lock held */ +struct mptcp_sched_ops *mptcp_sched_find(const char *name) +{ + struct mptcp_sched_ops *sched, *ret =3D NULL; + + list_for_each_entry_rcu(sched, &mptcp_sched_list, list) { + if (!strcmp(sched->name, name)) { + ret =3D sched; + break; + } + } + + return ret; +} + +int mptcp_register_scheduler(struct mptcp_sched_ops *sched) +{ + if (!sched->get_subflow) + return -EINVAL; + + spin_lock(&mptcp_sched_list_lock); + if (mptcp_sched_find(sched->name)) { + spin_unlock(&mptcp_sched_list_lock); + return -EEXIST; + } + list_add_tail_rcu(&sched->list, &mptcp_sched_list); + spin_unlock(&mptcp_sched_list_lock); + + pr_debug("%s registered", sched->name); + return 0; +} + +void mptcp_unregister_scheduler(struct mptcp_sched_ops *sched) +{ + spin_lock(&mptcp_sched_list_lock); + list_del_rcu(&sched->list); + spin_unlock(&mptcp_sched_list_lock); +} --=20 2.41.0