Skip to content

Commit 786fc12

Browse files
Paolo Abenikuba-moo
authored andcommitted
mptcp: fix connect timeout handling
Ondrej reported a functional issue WRT timeout handling on connect with a nice reproducer. The problem is that the current mptcp connect waits for both the MPTCP socket level timeout, and the first subflow socket timeout. The latter is not influenced/touched by the exposed setsockopt(). Overall the above makes the SO_SNDTIMEO a no-op on connect. Since mptcp_connect is invoked via inet_stream_connect and the latter properly handle the MPTCP level timeout, we can address the issue making the nested subflow level connect always unblocking. This also allow simplifying a bit the code, dropping an ugly hack to handle the fastopen and custom proto_ops connect. The issues predates the blamed commit below, but the current resolution requires the infrastructure introduced there. Fixes: 54f1944 ("mptcp: factor out mptcp_connect()") Reported-by: Ondrej Mosnacek <omosnace@redhat.com> Closes: multipath-tcp/mptcp_net-next#399 Cc: stable@vger.kernel.org Reviewed-by: Mat Martineau <martineau@kernel.org> Signed-off-by: Paolo Abeni <pabeni@redhat.com> Signed-off-by: Mat Martineau <martineau@kernel.org> Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent 3021dbf commit 786fc12

2 files changed

Lines changed: 7 additions & 23 deletions

File tree

net/mptcp/protocol.c

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1702,7 +1702,6 @@ static int mptcp_sendmsg_fastopen(struct sock *sk, struct msghdr *msg,
17021702

17031703
lock_sock(ssk);
17041704
msg->msg_flags |= MSG_DONTWAIT;
1705-
msk->connect_flags = O_NONBLOCK;
17061705
msk->fastopening = 1;
17071706
ret = tcp_sendmsg_fastopen(ssk, msg, copied_syn, len, NULL);
17081707
msk->fastopening = 0;
@@ -3617,9 +3616,9 @@ static int mptcp_connect(struct sock *sk, struct sockaddr *uaddr, int addr_len)
36173616
* acquired the subflow socket lock, too.
36183617
*/
36193618
if (msk->fastopening)
3620-
err = __inet_stream_connect(ssock, uaddr, addr_len, msk->connect_flags, 1);
3619+
err = __inet_stream_connect(ssock, uaddr, addr_len, O_NONBLOCK, 1);
36213620
else
3622-
err = inet_stream_connect(ssock, uaddr, addr_len, msk->connect_flags);
3621+
err = inet_stream_connect(ssock, uaddr, addr_len, O_NONBLOCK);
36233622
inet_sk(sk)->defer_connect = inet_sk(ssock->sk)->defer_connect;
36243623

36253624
/* on successful connect, the msk state will be moved to established by
@@ -3632,12 +3631,10 @@ static int mptcp_connect(struct sock *sk, struct sockaddr *uaddr, int addr_len)
36323631

36333632
mptcp_copy_inaddrs(sk, ssock->sk);
36343633

3635-
/* unblocking connect, mptcp-level inet_stream_connect will error out
3636-
* without changing the socket state, update it here.
3634+
/* silence EINPROGRESS and let the caller inet_stream_connect
3635+
* handle the connection in progress
36373636
*/
3638-
if (err == -EINPROGRESS)
3639-
sk->sk_socket->state = ssock->state;
3640-
return err;
3637+
return 0;
36413638
}
36423639

36433640
static struct proto mptcp_prot = {
@@ -3696,18 +3693,6 @@ static int mptcp_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
36963693
return err;
36973694
}
36983695

3699-
static int mptcp_stream_connect(struct socket *sock, struct sockaddr *uaddr,
3700-
int addr_len, int flags)
3701-
{
3702-
int ret;
3703-
3704-
lock_sock(sock->sk);
3705-
mptcp_sk(sock->sk)->connect_flags = flags;
3706-
ret = __inet_stream_connect(sock, uaddr, addr_len, flags, 0);
3707-
release_sock(sock->sk);
3708-
return ret;
3709-
}
3710-
37113696
static int mptcp_listen(struct socket *sock, int backlog)
37123697
{
37133698
struct mptcp_sock *msk = mptcp_sk(sock->sk);
@@ -3859,7 +3844,7 @@ static const struct proto_ops mptcp_stream_ops = {
38593844
.owner = THIS_MODULE,
38603845
.release = inet_release,
38613846
.bind = mptcp_bind,
3862-
.connect = mptcp_stream_connect,
3847+
.connect = inet_stream_connect,
38633848
.socketpair = sock_no_socketpair,
38643849
.accept = mptcp_stream_accept,
38653850
.getname = inet_getname,
@@ -3954,7 +3939,7 @@ static const struct proto_ops mptcp_v6_stream_ops = {
39543939
.owner = THIS_MODULE,
39553940
.release = inet6_release,
39563941
.bind = mptcp_bind,
3957-
.connect = mptcp_stream_connect,
3942+
.connect = inet_stream_connect,
39583943
.socketpair = sock_no_socketpair,
39593944
.accept = mptcp_stream_accept,
39603945
.getname = inet6_getname,

net/mptcp/protocol.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,6 @@ struct mptcp_sock {
297297
nodelay:1,
298298
fastopening:1,
299299
in_accept_queue:1;
300-
int connect_flags;
301300
struct work_struct work;
302301
struct sk_buff *ooo_last_skb;
303302
struct rb_root out_of_order_queue;

0 commit comments

Comments
 (0)