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

Geliang Tang <[email protected]>
Newsgroups dev.linux.lists.mptcp
Message-ID <[email protected]>
Hi Matt,

On Fri, 2026-08-07 at 10:41 +0200, Matthieu Baerts (NGI0) wrote:
> 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;
>  }

Personally, I think a single-pass lookup is better than a two-pass one.
I've implemented a version and it passed the tests:

static struct mptcp_pm_addr_entry *
mptcp_userspace_pm_lookup_addr(struct mptcp_sock *msk,
                               const struct mptcp_addr_info *addr)
{
    struct mptcp_pm_addr_entry *entry, *wildcard = NULL;
    struct mptcp_addr_info match;

    mptcp_for_each_userspace_pm_addr(msk, entry) {
        match = entry->addr;
        if (match.port == 0 && addr->port != 0)
            match.port = addr->port;

        if (mptcp_addresses_equal(&match, addr, addr->port != 0)) {
            if (addr->port == 0 || entry->addr.port != 0)
                return entry;

            if (!wildcard)
                wildcard = entry;
        }
    }

    return wildcard;
}

What do you think of this approach?

Also, this series has conflicts with the current export branch and
needs a rebase.

Thanks,
-Geliang
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.