1 // SPDX-License-Identifier: GPL-2.0
4 * Copyright (c) 2022, SUSE.
7 #define pr_fmt(fmt) "MPTCP: " fmt
9 #include <linux/kernel.h>
10 #include <linux/module.h>
11 #include <linux/list.h>
12 #include <linux/rculist.h>
13 #include <linux/spinlock.h>
16 static DEFINE_SPINLOCK(mptcp_sched_list_lock);
17 static LIST_HEAD(mptcp_sched_list);
19 /* Must be called with rcu read lock held */
20 struct mptcp_sched_ops *mptcp_sched_find(const char *name)
22 struct mptcp_sched_ops *sched, *ret = NULL;
24 list_for_each_entry_rcu(sched, &mptcp_sched_list, list) {
25 if (!strcmp(sched->name, name)) {
34 int mptcp_register_scheduler(struct mptcp_sched_ops *sched)
36 if (!sched->get_subflow)
39 spin_lock(&mptcp_sched_list_lock);
40 if (mptcp_sched_find(sched->name)) {
41 spin_unlock(&mptcp_sched_list_lock);
44 list_add_tail_rcu(&sched->list, &mptcp_sched_list);
45 spin_unlock(&mptcp_sched_list_lock);
47 pr_debug("%s registered", sched->name);
51 void mptcp_unregister_scheduler(struct mptcp_sched_ops *sched)
53 spin_lock(&mptcp_sched_list_lock);
54 list_del_rcu(&sched->list);
55 spin_unlock(&mptcp_sched_list_lock);