[PATCH mptcp-net v3 2/8] mptcp: pm: userspace: lookup: match port in priority

"Matthieu Baerts (NGI0)" <[email protected]>
Newsgroups dev.linux.lists.mptcp
Message-ID <20260807-mptcp-pm-userspace-id0-case-v3-2-de9088549924@kernel.org>
In the local address list, there can be entries with the port set to 0
-- corresponding to the source port used by the initial subflow -- and
others with a specific port.

When performing a lookup, it is important to compare the ports to pick
the right entry: when a specific port is given, then try to match it
first. If no match is found, try to find entries with the port set to 0.

Fixes: 24430f8bf516 ("mptcp: add address into userspace pm list")
Signed-off-by: Matthieu Baerts (NGI0) <[email protected]>
---
v3: new (Sashiko)
---
 net/mptcp/pm_userspace.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/net/mptcp/pm_userspace.c b/net/mptcp/pm_userspace.c
index 663cbeb79548..3f1471ec3fc7 100644
--- a/net/mptcp/pm_userspace.c
+++ b/net/mptcp/pm_userspace.c
@@ -33,10 +33,22 @@ mptcp_userspace_pm_lookup_addr(struct mptcp_sock *msk,
 {
 	struct mptcp_pm_addr_entry *entry;
 
+	/* Compare ports when set in addr */
 	mptcp_for_each_userspace_pm_addr(msk, entry) {
-		if (mptcp_addresses_equal(&entry->addr, addr, false))
+		if (mptcp_addresses_equal(&entry->addr, addr, addr->port != 0))
 			return entry;
 	}
+
+	if (addr->port == 0)
+		return NULL;
+
+	/* Check only wildcard ports if no exact match with the port */
+	mptcp_for_each_userspace_pm_addr(msk, entry) {
+		if (entry->addr.port == 0 &&
+		    mptcp_addresses_equal(&entry->addr, addr, false))
+			return entry;
+	}
+
 	return NULL;
 }
 

-- 
2.53.0
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.