Skip to content

Commit 41be81a

Browse files
Paolo Abenidavem330
authored andcommitted
mptcp: fix unblocking connect()
Currently unblocking connect() on MPTCP sockets fails frequently. If mptcp_stream_connect() is invoked to complete a previously attempted unblocking connection, it will still try to create the first subflow via __mptcp_socket_create(). If the 3whs is completed and the 'can_ack' flag is already set, the latter will fail with -EINVAL. This change addresses the issue checking for pending connect and delegating the completion to the first subflow. Additionally do msk addresses and sk_state changes only when needed. Fixes: 2303f99 ("mptcp: Associate MPTCP context with TCP socket") Signed-off-by: Paolo Abeni <[email protected]> Reviewed-by: Mat Martineau <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 05aa69e commit 41be81a

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

net/mptcp/protocol.c

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1712,6 +1712,14 @@ static int mptcp_stream_connect(struct socket *sock, struct sockaddr *uaddr,
17121712
int err;
17131713

17141714
lock_sock(sock->sk);
1715+
if (sock->state != SS_UNCONNECTED && msk->subflow) {
1716+
/* pending connection or invalid state, let existing subflow
1717+
* cope with that
1718+
*/
1719+
ssock = msk->subflow;
1720+
goto do_connect;
1721+
}
1722+
17151723
ssock = __mptcp_socket_create(msk, TCP_SYN_SENT);
17161724
if (IS_ERR(ssock)) {
17171725
err = PTR_ERR(ssock);
@@ -1726,9 +1734,17 @@ static int mptcp_stream_connect(struct socket *sock, struct sockaddr *uaddr,
17261734
mptcp_subflow_ctx(ssock->sk)->request_mptcp = 0;
17271735
#endif
17281736

1737+
do_connect:
17291738
err = ssock->ops->connect(ssock, uaddr, addr_len, flags);
1730-
inet_sk_state_store(sock->sk, inet_sk_state_load(ssock->sk));
1731-
mptcp_copy_inaddrs(sock->sk, ssock->sk);
1739+
sock->state = ssock->state;
1740+
1741+
/* on successful connect, the msk state will be moved to established by
1742+
* subflow_finish_connect()
1743+
*/
1744+
if (!err || err == EINPROGRESS)
1745+
mptcp_copy_inaddrs(sock->sk, ssock->sk);
1746+
else
1747+
inet_sk_state_store(sock->sk, inet_sk_state_load(ssock->sk));
17321748

17331749
unlock:
17341750
release_sock(sock->sk);

0 commit comments

Comments
 (0)