mptcp: pm: skip connecting to already established sf
authorMatthieu Baerts (NGI0) <matttbe@kernel.org>
Wed, 28 Aug 2024 06:14:28 +0000 (08:14 +0200)
committerPaolo Abeni <pabeni@redhat.com>
Thu, 29 Aug 2024 08:39:50 +0000 (10:39 +0200)
The lookup_subflow_by_daddr() helper checks if there is already a
subflow connected to this address. But there could be a subflow that is
closing, but taking time due to some reasons: latency, losses, data to
process, etc.

If an ADD_ADDR is received while the endpoint is being closed, it is
better to try connecting to it, instead of rejecting it: the peer which
has sent the ADD_ADDR will not be notified that the ADD_ADDR has been
rejected for this reason, and the expected subflow will not be created
at the end.

This helper should then only look for subflows that are established, or
going to be, but not the ones being closed.

Fixes: d84ad04941c3 ("mptcp: skip connecting the connected address")
Cc: stable@vger.kernel.org
Reviewed-by: Mat Martineau <martineau@kernel.org>
Signed-off-by: Matthieu Baerts (NGI0) <matttbe@kernel.org>
Signed-off-by: Paolo Abeni <pabeni@redhat.com>
net/mptcp/pm_netlink.c

index ed2205ef72089a2174323cfe9501e356d5e90730..0134b6273c54548c22c39cd2580755c0e90fee7c 100644 (file)
@@ -130,12 +130,15 @@ static bool lookup_subflow_by_daddr(const struct list_head *list,
 {
        struct mptcp_subflow_context *subflow;
        struct mptcp_addr_info cur;
-       struct sock_common *skc;
 
        list_for_each_entry(subflow, list, node) {
-               skc = (struct sock_common *)mptcp_subflow_tcp_sock(subflow);
+               struct sock *ssk = mptcp_subflow_tcp_sock(subflow);
+
+               if (!((1 << inet_sk_state_load(ssk)) &
+                     (TCPF_ESTABLISHED | TCPF_SYN_SENT | TCPF_SYN_RECV)))
+                       continue;
 
-               remote_address(skc, &cur);
+               remote_address((struct sock_common *)ssk, &cur);
                if (mptcp_addresses_equal(&cur, daddr, daddr->port))
                        return true;
        }