mptcp: pm: define struct mptcp_pm_ops

In order to allow users to develop their own BPF-based path manager,
this patch defines a struct ops "mptcp_pm_ops" for an MPTCP path
manager, which contains a set of interfaces. Currently only init()
and release() interfaces are included, subsequent patches will add
others step by step.

Add a set of functions to register, unregister, find and validate a
given path manager struct ops.

"list" is used to add this path manager to mptcp_pm_list list when
it is registered. "name" is used to identify this path manager.
mptcp_pm_find() uses "name" to find a path manager on the list.

mptcp_pm_unregister is not used in this set, but will be invoked in
.unreg of struct bpf_struct_ops. mptcp_pm_validate() will be invoked
in .validate of struct bpf_struct_ops. That's why they are exported.

Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
Reviewed-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
Reviewed-by: Simon Horman <horms@kernel.org>
Link: https://patch.msgid.link/20250313-net-next-mptcp-pm-ops-intro-v1-6-f4e4a88efc50@kernel.org
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
This commit is contained in:
Geliang Tang 2025-03-13 11:20:55 +01:00 committed by Paolo Abeni
parent eff5b1578e
commit 1305b0c22e
3 changed files with 67 additions and 0 deletions

View File

@ -14,6 +14,7 @@
struct mptcp_info;
struct mptcp_sock;
struct mptcp_pm_addr_entry;
struct seq_file;
/* MPTCP sk_buff extension data */
@ -121,6 +122,17 @@ struct mptcp_sched_ops {
void (*release)(struct mptcp_sock *msk);
} ____cacheline_aligned_in_smp;
#define MPTCP_PM_NAME_MAX 16
struct mptcp_pm_ops {
char name[MPTCP_PM_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);

View File

@ -5,6 +5,8 @@
*/
#define pr_fmt(fmt) "MPTCP: " fmt
#include <linux/rculist.h>
#include <linux/spinlock.h>
#include "protocol.h"
#include "mib.h"
@ -18,6 +20,9 @@ struct mptcp_pm_add_entry {
struct mptcp_sock *sock;
};
static DEFINE_SPINLOCK(mptcp_pm_list_lock);
static LIST_HEAD(mptcp_pm_list);
/* path manager helpers */
/* if sk is ipv4 or ipv6_only allows only same-family local and remote addresses,
@ -1015,3 +1020,48 @@ void __init mptcp_pm_init(void)
mptcp_pm_kernel_register();
mptcp_pm_nl_init();
}
/* Must be called with rcu read lock held */
struct mptcp_pm_ops *mptcp_pm_find(const char *name)
{
struct mptcp_pm_ops *pm_ops;
list_for_each_entry_rcu(pm_ops, &mptcp_pm_list, list) {
if (!strcmp(pm_ops->name, name))
return pm_ops;
}
return NULL;
}
int mptcp_pm_validate(struct mptcp_pm_ops *pm_ops)
{
return 0;
}
int mptcp_pm_register(struct mptcp_pm_ops *pm_ops)
{
int ret;
ret = mptcp_pm_validate(pm_ops);
if (ret)
return ret;
spin_lock(&mptcp_pm_list_lock);
if (mptcp_pm_find(pm_ops->name)) {
spin_unlock(&mptcp_pm_list_lock);
return -EEXIST;
}
list_add_tail_rcu(&pm_ops->list, &mptcp_pm_list);
spin_unlock(&mptcp_pm_list_lock);
pr_debug("%s registered\n", pm_ops->name);
return 0;
}
void mptcp_pm_unregister(struct mptcp_pm_ops *pm_ops)
{
spin_lock(&mptcp_pm_list_lock);
list_del_rcu(&pm_ops->list);
spin_unlock(&mptcp_pm_list_lock);
}

View File

@ -1050,6 +1050,11 @@ int mptcp_pm_remove_addr(struct mptcp_sock *msk, const struct mptcp_rm_list *rm_
void mptcp_pm_remove_addr_entry(struct mptcp_sock *msk,
struct mptcp_pm_addr_entry *entry);
struct mptcp_pm_ops *mptcp_pm_find(const char *name);
int mptcp_pm_register(struct mptcp_pm_ops *pm_ops);
void mptcp_pm_unregister(struct mptcp_pm_ops *pm_ops);
int mptcp_pm_validate(struct mptcp_pm_ops *pm_ops);
void mptcp_userspace_pm_free_local_addr_list(struct mptcp_sock *msk);
void mptcp_event(enum mptcp_event_type type, const struct mptcp_sock *msk,