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 03/10] mptcp: register ipv6 addr notifier
Date: Wed, 21 Jul 2021 22:31:27 +0800	[thread overview]
Message-ID: <93ffe9fbfda6d2efdbab73373b6efbbce3a36b00.1626877655.git.geliangtang@gmail.com> (raw)
In-Reply-To: <0000f0168f0d8d1cd34bbe5463aed721225446e2.1626877655.git.geliangtang@gmail.com>

This patch registered a ipv6 addr notifier, named mptcp_pm_addr6_notifier,
to deal with the events of net device UP, DOWN and CHANGE, and skip the
loopback device.

Save the ipv6 address, and pass it to the event handler.

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

diff --git a/net/mptcp/pm_fullmesh.c b/net/mptcp/pm_fullmesh.c
index 38a44ce8a5fa..bac06ddc658b 100644
--- a/net/mptcp/pm_fullmesh.c
+++ b/net/mptcp/pm_fullmesh.c
@@ -3,6 +3,8 @@
 #define pr_fmt(fmt) "MPTCP: " fmt
 
 #include <linux/kernel.h>
+#include <linux/inetdevice.h>
+#include <net/addrconf.h>
 #include <net/mptcp.h>
 
 #include "protocol.h"
@@ -41,8 +43,47 @@ static struct notifier_block mptcp_pm_addr4_notifier = {
 	.notifier_call = mptcp_pm_addr4_event,
 };
 
+#if IS_ENABLED(CONFIG_MPTCP_IPV6)
+
+static int mptcp_pm_addr6_event(struct notifier_block *this,
+				unsigned long event, void *ptr)
+{
+	const struct inet6_ifaddr *ifa6 = (struct inet6_ifaddr *)ptr;
+	struct net *net = dev_net(ifa6->idev->dev);
+	int addr_type = ipv6_addr_type(&ifa6->addr);
+	struct mptcp_addr_info addr = { 0 };
+
+	if (!(event == NETDEV_UP || event == NETDEV_DOWN || event == NETDEV_CHANGE))
+		goto out;
+
+	if (ifa6->scope > RT_SCOPE_LINK ||
+	    addr_type == IPV6_ADDR_ANY ||
+	    (addr_type & IPV6_ADDR_LOOPBACK) ||
+	    (addr_type & IPV6_ADDR_LINKLOCAL))
+		goto out;
+
+	addr.family = AF_INET6;
+	addr.addr6 = ifa6->addr;
+
+	addr_event_handler(event, net, &addr);
+
+out:
+	return NOTIFY_DONE;
+}
+
+static struct notifier_block mptcp_pm_addr6_notifier = {
+	.notifier_call = mptcp_pm_addr6_event,
+};
+
+#endif
+
 void __init mptcp_pm_fm_init(void)
 {
 	if (register_inetaddr_notifier(&mptcp_pm_addr4_notifier))
 		return;
+
+#if IS_ENABLED(CONFIG_MPTCP_IPV6)
+	if (register_inet6addr_notifier(&mptcp_pm_addr6_notifier))
+		unregister_inetaddr_notifier(&mptcp_pm_addr4_notifier);
+#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     ` Geliang Tang [this message]
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             ` [MPTCP][PATCH v2 mptcp-next 07/10] mptcp: add proc file local_addr_list Geliang Tang
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=93ffe9fbfda6d2efdbab73373b6efbbce3a36b00.1626877655.git.geliangtang@gmail.com \
    --to=geliangtang@gmail.com \
    --cc=mptcp@lists.linux.dev \
    /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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).