All of lore.kernel.org
 help / color / mirror / Atom feed
From: Kishen Maloor <kishen.maloor@intel.com>
To: kishen.maloor@intel.com, mptcp@lists.linux.dev
Subject: [PATCH mptcp-next v2 11/21] mptcp: read attributes of addr entries managed by userspace PMs
Date: Wed, 12 Jan 2022 17:15:13 -0500	[thread overview]
Message-ID: <20220112221523.1829397-12-kishen.maloor@intel.com> (raw)
In-Reply-To: <20220112221523.1829397-1-kishen.maloor@intel.com>

This change introduces a parallel path in the kernel for retrieving
the local id, flags, if_index for an addr entry in the context of
an MPTCP connection that's being managed by a userspace PM. The
userspace and in-kernel PM modes deviate in their procedures for
obtaining this information.

Signed-off-by: Kishen Maloor <kishen.maloor@intel.com>
---
 net/mptcp/pm_netlink.c | 101 ++++++++++++++++++++++++++++-------------
 net/mptcp/protocol.h   |   2 +-
 net/mptcp/subflow.c    |   2 +-
 3 files changed, 71 insertions(+), 34 deletions(-)

diff --git a/net/mptcp/pm_netlink.c b/net/mptcp/pm_netlink.c
index 052a803a7f71..40c41a0498fc 100644
--- a/net/mptcp/pm_netlink.c
+++ b/net/mptcp/pm_netlink.c
@@ -1175,6 +1175,7 @@ int mptcp_pm_nl_get_local_id(struct mptcp_sock *msk, struct sock_common *skc)
 	struct mptcp_addr_info msk_local;
 	struct pm_nl_pernet *pernet;
 	int ret = -1;
+	int pm_type;
 
 	if (WARN_ON_ONCE(!msk))
 		return -1;
@@ -1192,31 +1193,50 @@ int mptcp_pm_nl_get_local_id(struct mptcp_sock *msk, struct sock_common *skc)
 
 	pernet = net_generic(sock_net((struct sock *)msk), pm_nl_pernet_id);
 
-	rcu_read_lock();
-	list_for_each_entry_rcu(entry, &pernet->local_addr_list, list) {
-		if (addresses_equal(&entry->addr, &skc_local, entry->addr.port)) {
-			ret = entry->addr.id;
-			break;
-		}
-	}
-	rcu_read_unlock();
-	if (ret >= 0)
-		return ret;
-
 	/* address not found, add to local list */
-	entry = kmalloc(sizeof(*entry), GFP_ATOMIC);
-	if (!entry)
-		return -ENOMEM;
-
-	entry->addr = skc_local;
-	entry->addr.id = 0;
-	entry->addr.port = 0;
-	entry->ifindex = 0;
-	entry->flags = 0;
-	entry->lsk_ref = NULL;
-	ret = mptcp_pm_nl_append_new_local_addr(pernet, entry);
-	if (ret < 0)
-		kfree(entry);
+
+	pm_type = READ_ONCE(msk->pm.pm_type);
+
+	if (pm_type == MPTCP_PM_TYPE_KERNEL) {
+		rcu_read_lock();
+		list_for_each_entry_rcu(entry, &pernet->local_addr_list, list) {
+			if (addresses_equal(&entry->addr, &skc_local, entry->addr.port)) {
+				ret = entry->addr.id;
+				break;
+			}
+		}
+		rcu_read_unlock();
+
+		if (ret >= 0)
+			return ret;
+
+		entry = kmalloc(sizeof(*entry), GFP_ATOMIC);
+		if (!entry)
+			return -ENOMEM;
+
+		entry->addr = skc_local;
+		entry->addr.id = 0;
+		entry->addr.port = 0;
+		entry->ifindex = 0;
+		entry->flags = 0;
+		entry->lsk_ref = NULL;
+		ret = mptcp_pm_nl_append_new_local_addr(pernet, entry);
+		if (ret < 0)
+			kfree(entry);
+	} else if (pm_type == MPTCP_PM_TYPE_USERSPACE) {
+		struct mptcp_pm_addr_entry new_entry;
+		__be16 msk_sport =  ((struct inet_sock *)
+				     inet_sk((struct sock *)msk))->inet_sport;
+
+		memset(&new_entry, 0, sizeof(struct mptcp_pm_addr_entry));
+		new_entry.addr = skc_local;
+		new_entry.addr.id = 0;
+
+		if (new_entry.addr.port == msk_sport)
+			new_entry.addr.port = 0;
+
+		ret = mptcp_userspace_pm_append_new_local_addr(msk, &new_entry);
+	}
 
 	return ret;
 }
@@ -1461,22 +1481,39 @@ static int mptcp_nl_cmd_add_addr(struct sk_buff *skb, struct genl_info *info)
 	return 0;
 }
 
-int mptcp_pm_get_flags_and_ifindex_by_id(struct net *net, unsigned int id,
+int mptcp_pm_get_flags_and_ifindex_by_id(struct mptcp_sock *msk, unsigned int id,
 					 u8 *flags, int *ifindex)
 {
-	struct mptcp_pm_addr_entry *entry;
+	struct mptcp_pm_addr_entry *entry, *match = NULL;
+	struct sock *sk = (struct sock *)msk;
+	struct net *net = sock_net(sk);
 
 	*flags = 0;
 	*ifindex = 0;
 
 	if (id) {
-		rcu_read_lock();
-		entry = __lookup_addr_by_id(net_generic(net, pm_nl_pernet_id), id);
-		if (entry) {
-			*flags = entry->flags;
-			*ifindex = entry->ifindex;
+		if (READ_ONCE(msk->pm.pm_type) == MPTCP_PM_TYPE_KERNEL) {
+			rcu_read_lock();
+			entry = __lookup_addr_by_id(net_generic(net, pm_nl_pernet_id), id);
+			if (entry) {
+				*flags = entry->flags;
+				*ifindex = entry->ifindex;
+			}
+			rcu_read_unlock();
+		} else {
+			mptcp_data_lock(sk);
+			list_for_each_entry(entry, &msk->local_addr_list, list) {
+				if (id == entry->addr.id) {
+					match = entry;
+					break;
+				}
+			}
+			mptcp_data_unlock(sk);
+			if (match) {
+				*flags = match->flags;
+				*ifindex = match->ifindex;
+			}
 		}
-		rcu_read_unlock();
 	}
 
 	return 0;
diff --git a/net/mptcp/protocol.h b/net/mptcp/protocol.h
index 63b4ea850d07..c6f7c22d0e11 100644
--- a/net/mptcp/protocol.h
+++ b/net/mptcp/protocol.h
@@ -772,7 +772,7 @@ mptcp_pm_del_add_timer(struct mptcp_sock *msk,
 struct mptcp_pm_add_entry *
 mptcp_lookup_anno_list_by_saddr(struct mptcp_sock *msk,
 				struct mptcp_addr_info *addr);
-int mptcp_pm_get_flags_and_ifindex_by_id(struct net *net, unsigned int id,
+int mptcp_pm_get_flags_and_ifindex_by_id(struct mptcp_sock *msk, unsigned int id,
 					 u8 *flags, int *ifindex);
 
 int mptcp_pm_announce_addr(struct mptcp_sock *msk,
diff --git a/net/mptcp/subflow.c b/net/mptcp/subflow.c
index b75b7b186d34..29e51986c985 100644
--- a/net/mptcp/subflow.c
+++ b/net/mptcp/subflow.c
@@ -1419,7 +1419,7 @@ int __mptcp_subflow_connect(struct sock *sk, const struct mptcp_addr_info *loc,
 		local_id = err;
 	}
 
-	mptcp_pm_get_flags_and_ifindex_by_id(sock_net(sk), local_id,
+	mptcp_pm_get_flags_and_ifindex_by_id(msk, local_id,
 					     &flags, &ifindex);
 	subflow->remote_key = msk->remote_key;
 	subflow->local_key = msk->local_key;
-- 
2.31.1


  parent reply	other threads:[~2022-01-12 22:16 UTC|newest]

Thread overview: 45+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-12 22:15 [PATCH mptcp-next v2 00/21] mptcp: support userspace path management Kishen Maloor
2022-01-12 22:15 ` [PATCH mptcp-next v2 01/21] mptcp: do not restrict subflows with non-kernel PMs Kishen Maloor
2022-01-12 22:15 ` [PATCH mptcp-next v2 02/21] mptcp: store remote id from MP_JOIN SYN/ACK in local ctx Kishen Maloor
2022-01-12 22:15 ` [PATCH mptcp-next v2 03/21] mptcp: reflect remote port (not 0) in ANNOUNCED events Kishen Maloor
2022-01-12 22:15 ` [PATCH mptcp-next v2 04/21] mptcp: establish subflows from either end of connection Kishen Maloor
2022-01-14 22:43   ` Mat Martineau
2022-01-17  8:59     ` Paolo Abeni
2022-01-19  1:26       ` Kishen Maloor
2022-01-19 12:01         ` Paolo Abeni
2022-01-19 17:59           ` Kishen Maloor
2022-01-19 18:59             ` Mat Martineau
2022-01-12 22:15 ` [PATCH mptcp-next v2 05/21] mptcp: netlink: store per namespace list of refcounted listen socks Kishen Maloor
2022-01-12 22:15 ` [PATCH mptcp-next v2 06/21] mptcp: netlink: store lsk ref in mptcp_pm_addr_entry Kishen Maloor
2022-01-12 22:15 ` [PATCH mptcp-next v2 07/21] mptcp: netlink: process IPv6 addrs in creating listening sockets Kishen Maloor
2022-01-14 15:27   ` Paolo Abeni
2022-01-14 22:09     ` Mat Martineau
2022-01-19  1:25       ` Kishen Maloor
2022-01-19 19:14         ` Mat Martineau
2022-01-12 22:15 ` [PATCH mptcp-next v2 08/21] mptcp: attempt to add listening sockets for announced addrs Kishen Maloor
2022-01-14 15:54   ` Paolo Abeni
2022-01-14 17:47     ` Matthieu Baerts
2022-01-14 22:26     ` Mat Martineau
2022-01-19  1:20     ` Kishen Maloor
2022-01-12 22:15 ` [PATCH mptcp-next v2 09/21] mptcp: allow ADD_ADDR reissuance by userspace PMs Kishen Maloor
2022-01-12 22:15 ` [PATCH mptcp-next v2 10/21] mptcp: handle local addrs announced " Kishen Maloor
2022-01-14 17:11   ` Paolo Abeni
2022-01-19  1:24     ` Kishen Maloor
2022-01-19 19:20       ` Mat Martineau
2022-01-19 20:27         ` Kishen Maloor
2022-01-19 20:44           ` Mat Martineau
2022-01-19 21:30             ` Kishen Maloor
2022-01-12 22:15 ` Kishen Maloor [this message]
2022-01-12 22:15 ` [PATCH mptcp-next v2 12/21] mptcp: netlink: split mptcp_pm_parse_addr into two functions Kishen Maloor
2022-01-12 22:15 ` [PATCH mptcp-next v2 13/21] mptcp: netlink: Add MPTCP_PM_CMD_ANNOUNCE Kishen Maloor
2022-01-14 17:04   ` Paolo Abeni
2022-01-19  1:21     ` Kishen Maloor
2022-01-12 22:15 ` [PATCH mptcp-next v2 14/21] mptcp: selftests: support MPTCP_PM_CMD_ANNOUNCE Kishen Maloor
2022-01-12 22:15 ` [PATCH mptcp-next v2 15/21] mptcp: netlink: Add MPTCP_PM_CMD_REMOVE Kishen Maloor
2022-01-12 22:15 ` [PATCH mptcp-next v2 16/21] mptcp: selftests: support MPTCP_PM_CMD_REMOVE Kishen Maloor
2022-01-12 22:15 ` [PATCH mptcp-next v2 17/21] mptcp: netlink: allow userspace-driven subflow establishment Kishen Maloor
2022-01-12 22:15 ` [PATCH mptcp-next v2 18/21] mptcp: selftests: support MPTCP_PM_CMD_SUBFLOW_CREATE Kishen Maloor
2022-01-12 22:15 ` [PATCH mptcp-next v2 19/21] mptcp: selftests: support MPTCP_PM_CMD_SUBFLOW_DESTROY Kishen Maloor
2022-01-12 22:15 ` [PATCH mptcp-next v2 20/21] mptcp: selftests: capture netlink events Kishen Maloor
2022-01-12 22:15 ` [PATCH mptcp-next v2 21/21] selftests: mptcp: functional tests for the userspace PM type Kishen Maloor
2022-01-12 22:35   ` selftests: mptcp: functional tests for the userspace PM type: Build Failure MPTCP CI

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=20220112221523.1829397-12-kishen.maloor@intel.com \
    --to=kishen.maloor@intel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.