Skip to contentSkip to conversation

add flush and dump for userspace pm

PATCH Superseded Geliang Tang 1 participant 11 messages Nov 2, 2023

Subsystems (3)

v1 of 13 Superseded Latest is v13 →

lore
Share & tools
lore
#0 lore raw

cover add flush and dump for userspace pm

This series adds flush and dump commands support for userspace pm.

Geliang Tang (10):
mptcp: add userspace_pm_get_entry helper
mptcp: lookup_addr_by_id helper in userspace pm
mptcp: use pernet id_bitmap in userspace pm
mptcp: drop addr_match and id_match
mptcp: rename free_local_addr_list with prefix
mptcp: flush userspace pm addrs list
mptcp: dump userspace pm addrs
selftests: mptcp: flush and dump userspace addrs list
mptcp: add addresses_ids_equal helper
mptcp: drop lookup_by_id parameter in __lookup_addr

 net/mptcp/pm_netlink.c                        |  80 ++++++++--
 net/mptcp/pm_userspace.c                      | 150 ++++++++++++------
 net/mptcp/protocol.c                          |   2 +-
 net/mptcp/protocol.h                          |   8 +-
 .../testing/selftests/net/mptcp/mptcp_join.sh |   2 +
 5 files changed, 182 insertions(+), 60 deletions(-)
Signature · 1 line
2.35.3
#1 lore raw

PATCH 1/10 mptcp: add userspace_pm_get_entry helper

This patch adds a new helper mptcp_userspace_pm_get_entry() to find out the address entry on the userspace_pm_local_addr_list through the given address. Use this helper in mptcp_userspace_pm_delete_local_addr() and mptcp_nl_cmd_sf_destroy().

---
 net/mptcp/pm_userspace.c | 35 ++++++++++++++++++++++++-----------
 1 file changed, 24 insertions(+), 11 deletions(-)
net/mptcp/pm_userspace.c +24 -11
index efecbe3cf415..69733a1a5663 100644
@@ -25,6 +25,20 @@ void mptcp_free_local_addr_list(struct mptcp_sock *msk)
 	}
 }
 
+static struct mptcp_pm_addr_entry *mptcp_userspace_pm_get_entry(struct mptcp_sock *msk,
+								struct mptcp_addr_info *addr,
+								bool use_port)
+{
+	struct mptcp_pm_addr_entry *entry;
+
+	list_for_each_entry(entry, &msk->pm.userspace_pm_local_addr_list, list) {
+		if (mptcp_addresses_equal(&entry->addr, addr, use_port))
+			return entry;
+	}
+
+	return NULL;
+}
+
 static int mptcp_userspace_pm_append_new_local_addr(struct mptcp_sock *msk,
 						    struct mptcp_pm_addr_entry *entry)
 {
@@ -88,18 +102,17 @@ static int mptcp_userspace_pm_append_new_local_addr(struct mptcp_sock *msk,
 static int mptcp_userspace_pm_delete_local_addr(struct mptcp_sock *msk,
 						struct mptcp_pm_addr_entry *addr)
 {
-	struct mptcp_pm_addr_entry *entry, *tmp;
+	struct mptcp_pm_addr_entry *entry;
 
-	list_for_each_entry_safe(entry, tmp, &msk->pm.userspace_pm_local_addr_list, list) {
-		if (mptcp_addresses_equal(&entry->addr, &addr->addr, false)) {
-			/* TODO: a refcount is needed because the entry can
-			 * be used multiple times (e.g. fullmesh mode).
-			 */
-			list_del_rcu(&entry->list);
-			kfree(entry);
-			msk->pm.local_addr_used--;
-			return 0;
-		}
+	entry = mptcp_userspace_pm_get_entry(msk, &addr->addr, false);
+	if (entry) {
+		/* TODO: a refcount is needed because the entry can
+		 * be used multiple times (e.g. fullmesh mode).
+		 */
+		list_del_rcu(&entry->list);
+		kfree(entry);
+		msk->pm.local_addr_used--;
+		return 0;
 	}
 
 	return -EINVAL;
Signature · 1 line
2.35.3
#2 lore raw

PATCH 2/10 mptcp: lookup_addr_by_id helper in userspace pm

In reply to Geliang Tang

Corresponding __lookup_addr_by_id() function in the in-kernel netlink PM, this patch adds a new helper mptcp_userspace_pm_lookup_addr_by_id() to lookup the address entry with the given id on the userspace pm local address list.

---
 net/mptcp/pm_userspace.c | 31 ++++++++++++++++---------------
 1 file changed, 16 insertions(+), 15 deletions(-)
net/mptcp/pm_userspace.c +16 -15
index 69733a1a5663..b5687578e6ac 100644
@@ -25,6 +25,18 @@ void mptcp_free_local_addr_list(struct mptcp_sock *msk)
 	}
 }
 
+static struct mptcp_pm_addr_entry *
+mptcp_userspace_pm_lookup_addr_by_id(struct mptcp_sock *msk, unsigned int id)
+{
+	struct mptcp_pm_addr_entry *entry;
+
+	list_for_each_entry(entry, &msk->pm.userspace_pm_local_addr_list, list) {
+		if (entry->addr.id == id)
+			return entry;
+	}
+	return NULL;
+}
+
 static struct mptcp_pm_addr_entry *mptcp_userspace_pm_get_entry(struct mptcp_sock *msk,
 								struct mptcp_addr_info *addr,
 								bool use_port)
@@ -122,15 +134,10 @@ int mptcp_userspace_pm_get_flags_and_ifindex_by_id(struct mptcp_sock *msk,
 						   unsigned int id,
 						   u8 *flags, int *ifindex)
 {
-	struct mptcp_pm_addr_entry *entry, *match = NULL;
+	struct mptcp_pm_addr_entry *match;
 
 	spin_lock_bh(&msk->pm.lock);
-	list_for_each_entry(entry, &msk->pm.userspace_pm_local_addr_list, list) {
-		if (id == entry->addr.id) {
-			match = entry;
-			break;
-		}
-	}
+	match = mptcp_userspace_pm_lookup_addr_by_id(msk, id);
 	spin_unlock_bh(&msk->pm.lock);
 	if (match) {
 		*flags = match->flags;
@@ -262,7 +269,7 @@ int mptcp_pm_nl_remove_doit(struct sk_buff *skb, struct genl_info *info)
 {
 	struct nlattr *token = info->attrs[MPTCP_PM_ATTR_TOKEN];
 	struct nlattr *id = info->attrs[MPTCP_PM_ATTR_LOC_ID];
-	struct mptcp_pm_addr_entry *match = NULL;
+	struct mptcp_pm_addr_entry *match;
 	struct mptcp_pm_addr_entry *entry;
 	struct mptcp_sock *msk;
 	LIST_HEAD(free_list);
@@ -299,13 +306,7 @@ int mptcp_pm_nl_remove_doit(struct sk_buff *skb, struct genl_info *info)
 
 	lock_sock(sk);
 
-	list_for_each_entry(entry, &msk->pm.userspace_pm_local_addr_list, list) {
-		if (entry->addr.id == id_val) {
-			match = entry;
-			break;
-		}
-	}
-
+	match = mptcp_userspace_pm_lookup_addr_by_id(msk, id_val);
 	if (!match) {
 		GENL_SET_ERR_MSG(info, "address with specified id not found");
 		release_sock(sk);
Signature · 1 line
2.35.3
#3 lore raw

PATCH 3/10 mptcp: use pernet id_bitmap in userspace pm

In reply to Geliang Tang

This patch adds a new helper mptcp_pm_get_id_bitmap() to export the pernet id_bitmap used by the in-kernel netlink PM. Use it in userspace PM too instead of using a local bitmap when appending a new local address into the userspace PM local address list.

Also add two helpers to lock and unlock the pernet locks.

---
 net/mptcp/pm_netlink.c   | 24 ++++++++++++++++++++++++
 net/mptcp/pm_userspace.c | 11 +++++++----
 net/mptcp/protocol.h     |  3 +++
 3 files changed, 34 insertions(+), 4 deletions(-)
net/mptcp/pm_netlink.c +24 -0
index 1529ec358815..75be7182181b 100644
@@ -228,6 +228,30 @@ unsigned int mptcp_pm_get_local_addr_max(const struct mptcp_sock *msk)
 }
 EXPORT_SYMBOL_GPL(mptcp_pm_get_local_addr_max);
 
+unsigned long *mptcp_pm_get_id_bitmap(struct mptcp_sock *msk)
+{
+	struct pm_nl_pernet *pernet = pm_nl_get_pernet_from_msk(msk);
+
+	return pernet->id_bitmap;
+}
+EXPORT_SYMBOL_GPL(mptcp_pm_get_id_bitmap);
+
+void mptcp_pm_pernet_lock(struct mptcp_sock *msk)
+{
+	struct pm_nl_pernet *pernet = pm_nl_get_pernet_from_msk(msk);
+
+	spin_lock_bh(&pernet->lock);
+}
+EXPORT_SYMBOL_GPL(mptcp_pm_pernet_lock);
+
+void mptcp_pm_pernet_unlock(struct mptcp_sock *msk)
+{
+	struct pm_nl_pernet *pernet = pm_nl_get_pernet_from_msk(msk);
+
+	spin_unlock_bh(&pernet->lock);
+}
+EXPORT_SYMBOL_GPL(mptcp_pm_pernet_unlock);
+
 bool mptcp_pm_nl_check_work_pending(struct mptcp_sock *msk)
 {
 	struct pm_nl_pernet *pernet = pm_nl_get_pernet_from_msk(msk);
net/mptcp/pm_userspace.c +7 -4
index b5687578e6ac..6856bde6c74c 100644
@@ -54,17 +54,19 @@ static struct mptcp_pm_addr_entry *mptcp_userspace_pm_get_entry(struct mptcp_soc
 static int mptcp_userspace_pm_append_new_local_addr(struct mptcp_sock *msk,
 						    struct mptcp_pm_addr_entry *entry)
 {
-	DECLARE_BITMAP(id_bitmap, MPTCP_PM_MAX_ADDR_ID + 1);
 	struct mptcp_pm_addr_entry *match = NULL;
 	struct sock *sk = (struct sock *)msk;
 	struct mptcp_pm_addr_entry *e;
+	unsigned long *id_bitmap;
 	bool addr_match = false;
 	bool id_match = false;
 	int ret = -EINVAL;
 
-	bitmap_zero(id_bitmap, MPTCP_PM_MAX_ADDR_ID + 1);
-
 	spin_lock_bh(&msk->pm.lock);
+	mptcp_pm_pernet_lock(msk);
+
+	id_bitmap = mptcp_pm_get_id_bitmap(msk);
+
 	list_for_each_entry(e, &msk->pm.userspace_pm_local_addr_list, list) {
 		addr_match = mptcp_addresses_equal(&e->addr, &entry->addr, true);
 		if (addr_match && entry->addr.id == 0)
@@ -76,7 +78,6 @@ static int mptcp_userspace_pm_append_new_local_addr(struct mptcp_sock *msk,
 		} else if (addr_match || id_match) {
 			break;
 		}
-		__set_bit(e->addr.id, id_bitmap);
 	}
 
 	if (!match && !addr_match && !id_match) {
@@ -94,6 +95,7 @@ static int mptcp_userspace_pm_append_new_local_addr(struct mptcp_sock *msk,
 			e->addr.id = find_next_zero_bit(id_bitmap,
 							MPTCP_PM_MAX_ADDR_ID + 1,
 							1);
+		__set_bit(e->addr.id, id_bitmap);
 		list_add_tail_rcu(&e->list, &msk->pm.userspace_pm_local_addr_list);
 		msk->pm.local_addr_used++;
 		ret = e->addr.id;
@@ -102,6 +104,7 @@ static int mptcp_userspace_pm_append_new_local_addr(struct mptcp_sock *msk,
 	}
 
 append_err:
+	mptcp_pm_pernet_unlock(msk);
 	spin_unlock_bh(&msk->pm.lock);
 	return ret;
 }
net/mptcp/protocol.h +3 -0
index 8529b3ae55e9..cf72a57e6c54 100644
@@ -1030,6 +1030,9 @@ unsigned int mptcp_pm_get_add_addr_signal_max(const struct mptcp_sock *msk);
 unsigned int mptcp_pm_get_add_addr_accept_max(const struct mptcp_sock *msk);
 unsigned int mptcp_pm_get_subflows_max(const struct mptcp_sock *msk);
 unsigned int mptcp_pm_get_local_addr_max(const struct mptcp_sock *msk);
+unsigned long *mptcp_pm_get_id_bitmap(struct mptcp_sock *msk);
+void mptcp_pm_pernet_lock(struct mptcp_sock *msk);
+void mptcp_pm_pernet_unlock(struct mptcp_sock *msk);
 
 /* called under PM lock */
 static inline void __mptcp_pm_close_subflow(struct mptcp_sock *msk)
Signature · 1 line
2.35.3
#4 lore raw

PATCH 4/10 mptcp: drop addr_match and id_match

In reply to Geliang Tang

This patch uses the newly defined helper mptcp_userspace_pm_get_entry() in mptcp_userspace_pm_append_new_local_addr(), and drop local variables addr_match and id_match to simplify the code.

---
 net/mptcp/pm_userspace.c | 21 ++++++---------------
 1 file changed, 6 insertions(+), 15 deletions(-)
net/mptcp/pm_userspace.c +6 -15
index 6856bde6c74c..b7fa9481e3b3 100644
@@ -58,8 +58,6 @@ static int mptcp_userspace_pm_append_new_local_addr(struct mptcp_sock *msk,
 	struct sock *sk = (struct sock *)msk;
 	struct mptcp_pm_addr_entry *e;
 	unsigned long *id_bitmap;
-	bool addr_match = false;
-	bool id_match = false;
 	int ret = -EINVAL;
 
 	spin_lock_bh(&msk->pm.lock);
@@ -67,20 +65,13 @@ static int mptcp_userspace_pm_append_new_local_addr(struct mptcp_sock *msk,
 
 	id_bitmap = mptcp_pm_get_id_bitmap(msk);
 
-	list_for_each_entry(e, &msk->pm.userspace_pm_local_addr_list, list) {
-		addr_match = mptcp_addresses_equal(&e->addr, &entry->addr, true);
-		if (addr_match && entry->addr.id == 0)
-			entry->addr.id = e->addr.id;
-		id_match = (e->addr.id == entry->addr.id);
-		if (addr_match && id_match) {
-			match = e;
-			break;
-		} else if (addr_match || id_match) {
-			break;
-		}
-	}
+	e = mptcp_userspace_pm_get_entry(msk, &entry->addr, true);
+	if (e && entry->addr.id == 0)
+		entry->addr.id = e->addr.id;
+	if (e && e->addr.id == entry->addr.id)
+		match = e;
 
-	if (!match && !addr_match && !id_match) {
+	if (!match) {
 		/* Memory for the entry is allocated from the
 		 * sock option buffer.
 		 */
Signature · 1 line
2.35.3
#5 lore raw

PATCH 5/10 mptcp: rename free_local_addr_list with prefix

In reply to Geliang Tang

This patch renames mptcp_free_local_addr_list() with the userspace pm prefix as mptcp_userspace_pm_free_local_addr_list().

---
 net/mptcp/pm_userspace.c | 2 +-
 net/mptcp/protocol.c     | 2 +-
 net/mptcp/protocol.h     | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)
net/mptcp/pm_userspace.c +1 -1
index b7fa9481e3b3..86f3809c0b28 100644
@@ -7,7 +7,7 @@
 #include "protocol.h"
 #include "mib.h"
 
-void mptcp_free_local_addr_list(struct mptcp_sock *msk)
+void mptcp_userspace_pm_free_local_addr_list(struct mptcp_sock *msk)
 {
 	struct mptcp_pm_addr_entry *entry, *tmp;
 	struct sock *sk = (struct sock *)msk;
net/mptcp/protocol.c +1 -1
index 0ad507ac6bc7..3bbccb53eb29 100644
@@ -3317,7 +3317,7 @@ void mptcp_destroy_common(struct mptcp_sock *msk, unsigned int flags)
 	WRITE_ONCE(msk->rmem_fwd_alloc, 0);
 	mptcp_token_destroy(msk);
 	mptcp_pm_free_anno_list(msk);
-	mptcp_free_local_addr_list(msk);
+	mptcp_userspace_pm_free_local_addr_list(msk);
 }
 
 static void mptcp_destroy(struct sock *sk)
net/mptcp/protocol.h +1 -1
index cf72a57e6c54..2d9e8a78625c 100644
@@ -943,7 +943,7 @@ void mptcp_pm_remove_addrs(struct mptcp_sock *msk, struct list_head *rm_list);
 void mptcp_pm_remove_addrs_and_subflows(struct mptcp_sock *msk,
 					struct list_head *rm_list);
 
-void mptcp_free_local_addr_list(struct mptcp_sock *msk);
+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,
 		 const struct sock *ssk, gfp_t gfp);
Signature · 1 line
2.35.3
#6 lore raw

PATCH 6/10 mptcp: flush userspace pm addrs list

In reply to Geliang Tang

This patch adds a new function mptcp_userspace_pm_flush_addrs_list() to free the userspace local addresses list. Invoke it when flushing addresses from netlink commands.

---
 net/mptcp/pm_netlink.c   |  2 ++
 net/mptcp/pm_userspace.c | 24 ++++++++++++++++++++++++
 net/mptcp/protocol.h     |  1 +
 3 files changed, 27 insertions(+)
net/mptcp/pm_netlink.c +2 -0
index 75be7182181b..de2026f10cd3 100644
@@ -1634,6 +1634,8 @@ int mptcp_pm_nl_flush_addrs_doit(struct sk_buff *skb, struct genl_info *info)
 	mptcp_nl_remove_addrs_list(sock_net(skb->sk), &free_list);
 	synchronize_rcu();
 	__flush_addrs(&free_list);
+
+	mptcp_userspace_pm_flush_addrs_list(sock_net(skb->sk));
 	return 0;
 }
 
net/mptcp/pm_userspace.c +24 -0
index 86f3809c0b28..f5676fd3eb55 100644
@@ -558,3 +558,27 @@ int mptcp_userspace_pm_set_flags(struct net *net, struct nlattr *token,
 	sock_put(sk);
 	return ret;
 }
+
+void mptcp_userspace_pm_flush_addrs_list(struct net *net)
+{
+	long s_slot = 0, s_num = 0;
+	struct mptcp_sock *msk;
+
+	while ((msk = mptcp_token_iter_next(net, &s_slot, &s_num)) != NULL) {
+		struct sock *sk = (struct sock *)msk;
+		unsigned long *id_bitmap;
+
+		if (mptcp_pm_is_userspace(msk)) {
+			lock_sock(sk);
+			mptcp_pm_pernet_lock(msk);
+			id_bitmap = mptcp_pm_get_id_bitmap(msk);
+			bitmap_zero(id_bitmap, MPTCP_PM_MAX_ADDR_ID + 1);
+			mptcp_pm_pernet_unlock(msk);
+			mptcp_userspace_pm_free_local_addr_list(msk);
+			release_sock(sk);
+		}
+
+		sock_put(sk);
+		cond_resched();
+	}
+}
net/mptcp/protocol.h +1 -0
index 2d9e8a78625c..9b00eb38b2c8 100644
@@ -944,6 +944,7 @@ void mptcp_pm_remove_addrs_and_subflows(struct mptcp_sock *msk,
 					struct list_head *rm_list);
 
 void mptcp_userspace_pm_free_local_addr_list(struct mptcp_sock *msk);
+void mptcp_userspace_pm_flush_addrs_list(struct net *net);
 
 void mptcp_event(enum mptcp_event_type type, const struct mptcp_sock *msk,
 		 const struct sock *ssk, gfp_t gfp);
Signature · 1 line
2.35.3
#7 lore raw

PATCH 7/10 mptcp: dump userspace pm addrs

In reply to Geliang Tang

This patch adds a new function __userspace_lookup_addr_by_id() to lookup the address entry by the given id in the userspace local addresses list. Invoke it when dumping addresses from netlink commands.

---
 net/mptcp/pm_netlink.c   |  7 +++++--
 net/mptcp/pm_userspace.c | 26 ++++++++++++++++++++++++++
 net/mptcp/protocol.h     |  2 ++
 3 files changed, 33 insertions(+), 2 deletions(-)
net/mptcp/pm_netlink.c +5 -2
index de2026f10cd3..657db778a084 100644
@@ -1744,8 +1744,11 @@ int mptcp_pm_nl_get_addr_dumpit(struct sk_buff *msg,
 	for (i = id; i < MPTCP_PM_MAX_ADDR_ID + 1; i++) {
 		if (test_bit(i, pernet->id_bitmap)) {
 			entry = __lookup_addr_by_id(pernet, i);
-			if (!entry)
-				break;
+			if (!entry) {
+				entry = __userspace_lookup_addr_by_id(net, i);
+				if (!entry)
+					break;
+			}
 
 			if (entry->addr.id <= id)
 				continue;
net/mptcp/pm_userspace.c +26 -0
index f5676fd3eb55..8166d733569f 100644
@@ -582,3 +582,29 @@ void mptcp_userspace_pm_flush_addrs_list(struct net *net)
 		cond_resched();
 	}
 }
+
+struct mptcp_pm_addr_entry *
+__userspace_lookup_addr_by_id(struct net *net, unsigned int id)
+{
+	struct mptcp_pm_addr_entry *entry = NULL;
+	long s_slot = 0, s_num = 0;
+	struct mptcp_sock *msk;
+
+	while ((msk = mptcp_token_iter_next(net, &s_slot, &s_num)) != NULL) {
+		struct sock *sk = (struct sock *)msk;
+
+		if (mptcp_pm_is_userspace(msk)) {
+			lock_sock(sk);
+			spin_lock_bh(&msk->pm.lock);
+			entry = mptcp_userspace_pm_lookup_addr_by_id(msk, id);
+			pr_debug("%s tgl id=%d entry=%p", __func__, id, entry);
+			spin_unlock_bh(&msk->pm.lock);
+			release_sock(sk);
+		}
+
+		sock_put(sk);
+		cond_resched();
+	}
+
+	return entry;
+}
net/mptcp/protocol.h +2 -0
index 9b00eb38b2c8..b503f8192341 100644
@@ -1022,6 +1022,8 @@ bool mptcp_pm_rm_addr_signal(struct mptcp_sock *msk, unsigned int remaining,
 int mptcp_pm_get_local_id(struct mptcp_sock *msk, struct sock_common *skc);
 int mptcp_pm_nl_get_local_id(struct mptcp_sock *msk, struct mptcp_addr_info *skc);
 int mptcp_userspace_pm_get_local_id(struct mptcp_sock *msk, struct mptcp_addr_info *skc);
+struct mptcp_pm_addr_entry *
+__userspace_lookup_addr_by_id(struct net *net, unsigned int id);
 
 void __init mptcp_pm_nl_init(void);
 void mptcp_pm_nl_work(struct mptcp_sock *msk);
Signature · 1 line
2.35.3
#8 lore raw

PATCH 8/10 selftests: mptcp: flush and dump userspace addrs list

In reply to Geliang Tang

This patch tests newly added flush and dump commands for the userspace PM. Add these commands into "userspace pm create id 0 subflow" test.

---
 tools/testing/selftests/net/mptcp/mptcp_join.sh | 2 ++
 1 file changed, 2 insertions(+)
tools/testing/selftests/net/mptcp/mptcp_join.sh +2 -0
index 995280882428..a14381c94c56 100755
@@ -3453,6 +3453,8 @@ userspace_tests()
 		chk_mptcp_info subflows 0 subflows 0
 		chk_subflows_total 1 1
 		userspace_pm_add_sf $ns2 10.0.3.2 0
+		ip netns exec $ns2 ./pm_nl_ctl flush
+		ip netns exec $ns2 ./pm_nl_ctl dump
 		chk_join_nr 1 1 1
 		chk_mptcp_info subflows 1 subflows 1
 		chk_subflows_total 2 2
Signature · 1 line
2.35.3
#9 lore raw

PATCH 9/10 mptcp: add addresses_ids_equal helper

In reply to Geliang Tang

Add a new helper mptcp_addresses_ids_equal() to test if the two given addresses have both the same address and the same address id.

Use it to define a new helper mptcp_lookup_anno_list_by_saddr_and_id() with a use_id parameter, to simplify mptcp_pm_del_add_timer().

---
 net/mptcp/pm_netlink.c | 35 ++++++++++++++++++++++++++++++++---
 1 file changed, 32 insertions(+), 3 deletions(-)
net/mptcp/pm_netlink.c +32 -3
index 657db778a084..e900737d549b 100644
@@ -346,6 +346,35 @@ static void mptcp_pm_add_timer(struct timer_list *timer)
 	__sock_put(sk);
 }
 
+static bool mptcp_addresses_ids_equal(const struct mptcp_addr_info *a,
+				      const struct mptcp_addr_info *b,
+				      bool use_port, bool use_id)
+{
+	if (!mptcp_addresses_equal(a, b, use_port))
+		return false;
+	if (!use_id)
+		return true;
+
+	return a->id == b->id;
+}
+
+static struct mptcp_pm_add_entry *
+mptcp_lookup_anno_list_by_saddr_and_id(const struct mptcp_sock *msk,
+				       const struct mptcp_addr_info *addr,
+				       bool use_id)
+{
+	struct mptcp_pm_add_entry *entry;
+
+	lockdep_assert_held(&msk->pm.lock);
+
+	list_for_each_entry(entry, &msk->pm.anno_list, list) {
+		if (mptcp_addresses_ids_equal(&entry->addr, addr, true, use_id))
+			return entry;
+	}
+
+	return NULL;
+}
+
 struct mptcp_pm_add_entry *
 mptcp_pm_del_add_timer(struct mptcp_sock *msk,
 		       const struct mptcp_addr_info *addr, bool check_id)
@@ -354,12 +383,12 @@ mptcp_pm_del_add_timer(struct mptcp_sock *msk,
 	struct sock *sk = (struct sock *)msk;
 
 	spin_lock_bh(&msk->pm.lock);
-	entry = mptcp_lookup_anno_list_by_saddr(msk, addr);
-	if (entry && (!check_id || entry->addr.id == addr->id))
+	entry = mptcp_lookup_anno_list_by_saddr_and_id(msk, addr, check_id);
+	if (entry)
 		entry->retrans_times = ADD_ADDR_RETRANS_MAX;
 	spin_unlock_bh(&msk->pm.lock);
 
-	if (entry && (!check_id || entry->addr.id == addr->id))
+	if (entry)
 		sk_stop_timer_sync(sk, &entry->add_timer);
 
 	return entry;
Signature · 1 line
2.35.3
#10 lore raw

PATCH 10/10 mptcp: drop lookup_by_id parameter in __lookup_addr

In reply to Geliang Tang

When lookup_by_id parameter of __lookup_addr() is true, it's the same as __lookup_addr_by_id(). Drop this parameter.

---
 net/mptcp/pm_netlink.c | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)
net/mptcp/pm_netlink.c +5 -7
index e900737d549b..0e10ff1050e7 100644
@@ -555,15 +555,12 @@ __lookup_addr_by_id(struct pm_nl_pernet *pernet, unsigned int id)
 }
 
 static struct mptcp_pm_addr_entry *
-__lookup_addr(struct pm_nl_pernet *pernet, const struct mptcp_addr_info *info,
-	      bool lookup_by_id)
+__lookup_addr(struct pm_nl_pernet *pernet, const struct mptcp_addr_info *info)
 {
 	struct mptcp_pm_addr_entry *entry;
 
 	list_for_each_entry(entry, &pernet->local_addr_list, list) {
-		if ((!lookup_by_id &&
-		     mptcp_addresses_equal(&entry->addr, info, entry->addr.port)) ||
-		    (lookup_by_id && entry->addr.id == info->id))
+		if (mptcp_addresses_equal(&entry->addr, info, entry->addr.port))
 			return entry;
 	}
 	return NULL;
@@ -593,7 +590,7 @@ static void mptcp_pm_create_subflow_or_signal_addr(struct mptcp_sock *msk)
 
 		mptcp_local_address((struct sock_common *)msk->first, &mpc_addr);
 		rcu_read_lock();
-		entry = __lookup_addr(pernet, &mpc_addr, false);
+		entry = __lookup_addr(pernet, &mpc_addr);
 		if (entry) {
 			__clear_bit(entry->addr.id, msk->pm.id_avail_bitmap);
 			msk->mpc_endpoint_id = entry->addr.id;
@@ -1932,7 +1929,8 @@ int mptcp_pm_nl_set_flags(struct net *net, struct mptcp_pm_addr_entry *addr, u8
 	}
 
 	spin_lock_bh(&pernet->lock);
-	entry = __lookup_addr(pernet, &addr->addr, lookup_by_id);
+	entry = lookup_by_id ? __lookup_addr_by_id(pernet, addr->addr.id) :
+			       __lookup_addr(pernet, &addr->addr);
 	if (!entry) {
 		spin_unlock_bh(&pernet->lock);
 		return -EINVAL;
Signature · 1 line
2.35.3