diff mbox series

[mptcp-next,v6,10/13] mptcp: sysctl: add available_path_managers

Message ID 6d1a4f40c9116c66d96486c8e56adb37cc659d5f.1740320007.git.tanggeliang@kylinos.cn (mailing list archive)
State Superseded, archived
Delegated to: Matthieu Baerts
Headers show
Series BPF path manager, part 4 | expand

Checks

Context Check Description
matttbe/checkpatch warning total: 0 errors, 2 warnings, 0 checks, 94 lines checked
matttbe/shellcheck success MPTCP selftests files have not been modified
matttbe/build success Build and static analysis OK
matttbe/KVM_Validation__normal success Success! ✅
matttbe/KVM_Validation__debug success Success! ✅
matttbe/KVM_Validation__btf-normal__only_bpftest_all_ success Success! ✅
matttbe/KVM_Validation__btf-debug__only_bpftest_all_ success Success! ✅

Commit Message

Geliang Tang Feb. 23, 2025, 2:26 p.m. UTC
From: Geliang Tang <tanggeliang@kylinos.cn>

Similarly to net.mptcp.available_schedulers, this patch adds a new one
net.mptcp.available_path_managers to list the available path mangers.

Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
---
 Documentation/networking/mptcp-sysctl.rst |  4 ++++
 include/net/mptcp.h                       |  2 ++
 net/mptcp/ctrl.c                          | 25 +++++++++++++++++++++++
 net/mptcp/pm.c                            | 20 ++++++++++++++++++
 net/mptcp/protocol.h                      |  1 +
 5 files changed, 52 insertions(+)

Comments

Matthieu Baerts Feb. 23, 2025, 4:53 p.m. UTC | #1
On 23/02/2025 15:26, Geliang Tang wrote:
> From: Geliang Tang <tanggeliang@kylinos.cn>
> 
> Similarly to net.mptcp.available_schedulers, this patch adds a new one
> net.mptcp.available_path_managers to list the available path mangers.
> 
> Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
> ---
>  Documentation/networking/mptcp-sysctl.rst |  4 ++++
>  include/net/mptcp.h                       |  2 ++
>  net/mptcp/ctrl.c                          | 25 +++++++++++++++++++++++
>  net/mptcp/pm.c                            | 20 ++++++++++++++++++
>  net/mptcp/protocol.h                      |  1 +
>  5 files changed, 52 insertions(+)
> 
> diff --git a/Documentation/networking/mptcp-sysctl.rst b/Documentation/networking/mptcp-sysctl.rst
> index 454ce87bc1c5..ee0b553b51a1 100644
> --- a/Documentation/networking/mptcp-sysctl.rst
> +++ b/Documentation/networking/mptcp-sysctl.rst
> @@ -89,6 +89,10 @@ path_manager - STRING
>  
>  	Default: "in-kernel"
>  
> +available_path_managers - STRING
> +	Shows the available path managers choices that are registered. More
> +        path managers may be available, but not loaded.

Spaces are used instead of tabs for the alignment.

Also, please keep the alphabetical order. So to be placed before
available_schedulers.

> +
>  scheduler - STRING
>  	Select the scheduler of your choice.
>  
Cheers,
Matt
diff mbox series

Patch

diff --git a/Documentation/networking/mptcp-sysctl.rst b/Documentation/networking/mptcp-sysctl.rst
index 454ce87bc1c5..ee0b553b51a1 100644
--- a/Documentation/networking/mptcp-sysctl.rst
+++ b/Documentation/networking/mptcp-sysctl.rst
@@ -89,6 +89,10 @@  path_manager - STRING
 
 	Default: "in-kernel"
 
+available_path_managers - STRING
+	Shows the available path managers choices that are registered. More
+        path managers may be available, but not loaded.
+
 scheduler - STRING
 	Select the scheduler of your choice.
 
diff --git a/include/net/mptcp.h b/include/net/mptcp.h
index 689926d1f39f..bcddaf0a588a 100644
--- a/include/net/mptcp.h
+++ b/include/net/mptcp.h
@@ -123,6 +123,8 @@  struct mptcp_sched_ops {
 } ____cacheline_aligned_in_smp;
 
 #define MPTCP_PM_NAME_MAX	16
+#define MPTCP_PM_MAX		128
+#define MPTCP_PM_BUF_MAX	(MPTCP_PM_NAME_MAX * MPTCP_PM_MAX)
 
 struct mptcp_pm_ops {
 	int (*created)(struct mptcp_sock *msk);
diff --git a/net/mptcp/ctrl.c b/net/mptcp/ctrl.c
index b8eaf1f58ab2..b61778c51706 100644
--- a/net/mptcp/ctrl.c
+++ b/net/mptcp/ctrl.c
@@ -136,6 +136,24 @@  static int proc_path_manager(const struct ctl_table *ctl, int write,
 	return ret;
 }
 
+static int proc_available_path_managers(const struct ctl_table *ctl,
+					int write, void *buffer,
+					size_t *lenp, loff_t *ppos)
+{
+	struct ctl_table tbl = { .maxlen = MPTCP_PM_BUF_MAX, };
+	int ret;
+
+	tbl.data = kmalloc(tbl.maxlen, GFP_USER);
+	if (!tbl.data)
+		return -ENOMEM;
+
+	mptcp_pm_get_available(tbl.data, MPTCP_PM_BUF_MAX);
+	ret = proc_dostring(&tbl, write, buffer, lenp, ppos);
+	kfree(tbl.data);
+
+	return ret;
+}
+
 static int mptcp_set_scheduler(char *scheduler, const char *name)
 {
 	struct mptcp_sched_ops *sched;
@@ -252,6 +270,12 @@  static struct ctl_table mptcp_sysctl_table[] = {
 		.mode = 0644,
 		.proc_handler = proc_path_manager,
 	},
+	{
+		.procname = "available_path_managers",
+		.maxlen	= MPTCP_PM_BUF_MAX,
+		.mode = 0444,
+		.proc_handler = proc_available_path_managers,
+	},
 	{
 		.procname = "scheduler",
 		.maxlen	= MPTCP_SCHED_NAME_MAX,
@@ -304,6 +328,7 @@  static int mptcp_pernet_new_table(struct net *net, struct mptcp_pernet *pernet)
 	table[i++].data = &pernet->allow_join_initial_addr_port;
 	table[i++].data = &pernet->stale_loss_cnt;
 	table[i++].data = &pernet->path_manager;
+	i++; /* table[i] is for available_path_managers which is read-only info */
 	table[i++].data = &pernet->scheduler;
 	i++; /* table[i] is for available_schedulers which is read-only info */
 	table[i++].data = &pernet->close_timeout;
diff --git a/net/mptcp/pm.c b/net/mptcp/pm.c
index 9f9e9cf18847..103b6b205dca 100644
--- a/net/mptcp/pm.c
+++ b/net/mptcp/pm.c
@@ -673,6 +673,26 @@  struct mptcp_pm_ops *mptcp_pm_find(const char *name)
 	return NULL;
 }
 
+/* Build string with list of available path manager values.
+ * Similar to tcp_get_available_congestion_control()
+ */
+void mptcp_pm_get_available(char *buf, size_t maxlen)
+{
+	struct mptcp_pm_ops *pm;
+	size_t offs = 0;
+
+	rcu_read_lock();
+	list_for_each_entry_rcu(pm, &mptcp_pm_list, list) {
+		offs += snprintf(buf + offs, maxlen - offs,
+				 "%s%s",
+				 offs == 0 ? "" : " ", pm->name);
+
+		if (WARN_ON_ONCE(offs >= maxlen))
+			break;
+	}
+	rcu_read_unlock();
+}
+
 int mptcp_pm_validate(struct mptcp_pm_ops *pm)
 {
 	if (!pm->get_local_id || !pm->get_priority) {
diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h
index e5917b9ecd74..809611125c5e 100644
--- a/net/mptcp/protocol.h
+++ b/net/mptcp/protocol.h
@@ -1050,6 +1050,7 @@  void mptcp_pm_remove_addr_entry(struct mptcp_sock *msk,
 extern struct mptcp_pm_ops mptcp_in_kernel_pm;
 
 struct mptcp_pm_ops *mptcp_pm_find(const char *name);
+void mptcp_pm_get_available(char *buf, size_t maxlen);
 int mptcp_pm_validate(struct mptcp_pm_ops *pm);
 int mptcp_pm_register(struct mptcp_pm_ops *pm);
 void mptcp_pm_unregister(struct mptcp_pm_ops *pm);