mptcp.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
From: Geliang Tang <geliangtang@gmail.com>
To: mptcp@lists.linux.dev
Cc: Geliang Tang <geliangtang@gmail.com>
Subject: [MPTCP][PATCH v2 mptcp-next 07/10] mptcp: add proc file local_addr_list
Date: Wed, 21 Jul 2021 22:31:31 +0800	[thread overview]
Message-ID: <d40b7b32bc427e5d43fce298b60e1040398977ac.1626877655.git.geliangtang@gmail.com> (raw)
In-Reply-To: <149236d46fe59a177a2f36a5c6e45941a1e0c2fd.1626877655.git.geliangtang@gmail.com>

This patch added a proc file /proc/net/local_addr_list to show all
the addresses on the local address list.

Signed-off-by: Geliang Tang <geliangtang@gmail.com>
---
 net/mptcp/pm_netlink.c | 52 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 52 insertions(+)

diff --git a/net/mptcp/pm_netlink.c b/net/mptcp/pm_netlink.c
index 765d59dd2a5d..3bf7467af74b 100644
--- a/net/mptcp/pm_netlink.c
+++ b/net/mptcp/pm_netlink.c
@@ -8,6 +8,9 @@
 
 #include <linux/inet.h>
 #include <linux/kernel.h>
+#ifdef CONFIG_PROC_FS
+#include <linux/proc_fs.h>
+#endif
 #include <net/tcp.h>
 #include <net/netns/generic.h>
 #include <net/mptcp.h>
@@ -2006,6 +2009,46 @@ int mptcp_fm_cmd_del_addr(struct net *net, struct mptcp_addr_info *addr)
 
 #endif
 
+#ifdef CONFIG_PROC_FS
+
+/* Output /proc/net/local_addr_list */
+static int mptcp_addr_list_seq_show(struct seq_file *seq, void *v)
+{
+	const struct net *net = seq->private;
+	struct mptcp_pm_addr_entry *cur;
+	struct pm_nl_pernet *pernet;
+
+	pernet = net_generic(net, pm_nl_pernet_id);
+
+	seq_puts(seq, "ID, Family, Address, Flags\n");
+
+	spin_lock_bh(&pernet->lock);
+
+	list_for_each_entry(cur, &pernet->local_addr_list, list) {
+		seq_printf(seq, "%u, ", cur->addr.id);
+		if (cur->addr.family == AF_INET)
+			seq_printf(seq, "4 %pI4, ", &cur->addr.addr);
+		else if (cur->addr.family == AF_INET6)
+			seq_printf(seq, "6 %pI6, ", &cur->addr.addr6);
+
+		if (cur->flags & MPTCP_PM_ADDR_FLAG_SUBFLOW)
+			seq_puts(seq, "subflow ");
+		if (cur->flags & MPTCP_PM_ADDR_FLAG_SIGNAL)
+			seq_puts(seq, "signal ");
+		if (cur->flags & MPTCP_PM_ADDR_FLAG_BACKUP)
+			seq_puts(seq, "backup ");
+		if (cur->flags & MPTCP_PM_ADDR_FLAG_FULLMESH)
+			seq_puts(seq, "fullmesh ");
+		seq_puts(seq, "\n");
+	}
+
+	spin_unlock_bh(&pernet->lock);
+
+	return 0;
+}
+
+#endif
+
 static int __net_init pm_nl_init_net(struct net *net)
 {
 	struct pm_nl_pernet *pernet = net_generic(net, pm_nl_pernet_id);
@@ -2015,6 +2058,12 @@ static int __net_init pm_nl_init_net(struct net *net)
 	pernet->stale_loss_cnt = 4;
 	spin_lock_init(&pernet->lock);
 
+#ifdef CONFIG_PROC_FS
+	if (!proc_create_net_single("local_addr_list", 0444, net->proc_net,
+				    mptcp_addr_list_seq_show, NULL))
+		return -EINVAL;
+#endif
+
 	/* No need to initialize other pernet fields, the struct is zeroed at
 	 * allocation time.
 	 */
@@ -2033,6 +2082,9 @@ static void __net_exit pm_nl_exit_net(struct list_head *net_list)
 		 * other modifiers
 		 */
 		__flush_addrs(&pernet->local_addr_list);
+#ifdef CONFIG_PROC_FS
+		remove_proc_entry("local_addr_list", net->proc_net);
+#endif
 	}
 }
 
-- 
2.31.1


  reply	other threads:[~2021-07-21 14:31 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-21 14:31 [MPTCP][PATCH v2 mptcp-next 00/10] fullmesh path manager support Geliang Tang
2021-07-21 14:31 ` [MPTCP][PATCH v2 mptcp-next 01/10] mptcp: add a new sysctl fullmesh_enabled Geliang Tang
2021-07-21 14:31   ` [MPTCP][PATCH v2 mptcp-next 02/10] mptcp: register ipv4 addr notifier Geliang Tang
2021-07-21 14:31     ` [MPTCP][PATCH v2 mptcp-next 03/10] mptcp: register ipv6 " Geliang Tang
2021-07-21 14:31       ` [MPTCP][PATCH v2 mptcp-next 04/10] mptcp: add netdev up event handler Geliang Tang
2021-07-21 14:31         ` [MPTCP][PATCH v2 mptcp-next 05/10] mptcp: invoke mptcp_nl_remove_subflow_and_signal_addr in rcu_work Geliang Tang
2021-07-21 14:31           ` [MPTCP][PATCH v2 mptcp-next 06/10] mptcp: add netdev down event handler Geliang Tang
2021-07-21 14:31             ` Geliang Tang [this message]
2021-07-21 14:31               ` [MPTCP][PATCH v2 mptcp-next 08/10] selftests: mptcp: print the fullmesh flag Geliang Tang
2021-07-21 14:31                 ` [MPTCP][PATCH v2 mptcp-next 09/10] selftests: mptcp: add fullmesh testcases Geliang Tang
2021-07-21 14:31                   ` [MPTCP][PATCH v2 mptcp-next 10/10] selftests: mptcp: del uncontinuous removing ids Geliang Tang
2021-07-22 13:34                     ` Matthieu Baerts
2021-07-22 13:33               ` [MPTCP][PATCH v2 mptcp-next 07/10] mptcp: add proc file local_addr_list Matthieu Baerts
2021-07-22 13:33         ` [MPTCP][PATCH v2 mptcp-next 04/10] mptcp: add netdev up event handler Matthieu Baerts
2021-07-21 17:08     ` [MPTCP][PATCH v2 mptcp-next 02/10] mptcp: register ipv4 addr notifier Paolo Abeni
2021-07-22 13:33       ` Matthieu Baerts
2021-07-22 13:33   ` [MPTCP][PATCH v2 mptcp-next 01/10] mptcp: add a new sysctl fullmesh_enabled Matthieu Baerts
2021-07-22 15:30 ` [MPTCP][PATCH v2 mptcp-next 00/10] fullmesh path manager support Matthieu Baerts

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=d40b7b32bc427e5d43fce298b60e1040398977ac.1626877655.git.geliangtang@gmail.com \
    --to=geliangtang@gmail.com \
    --cc=mptcp@lists.linux.dev \
    --subject='Re: [MPTCP][PATCH v2 mptcp-next 07/10] mptcp: add proc file local_addr_list' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).